14a8e43feSDavid Howells /* 24a8e43feSDavid Howells * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al. 34a8e43feSDavid Howells * 44a8e43feSDavid Howells * This program is free software; you can redistribute it and/or modify 54a8e43feSDavid Howells * it under the terms of the GNU General Public License as published by 64a8e43feSDavid Howells * the Free Software Foundation; either version 2 of the License, or 74a8e43feSDavid Howells * (at your option) any later version. 84a8e43feSDavid Howells * 94a8e43feSDavid Howells * This program is distributed in the hope that it will be useful, 104a8e43feSDavid Howells * but WITHOUT ANY WARRANTY; without even the implied warranty of 114a8e43feSDavid Howells * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 124a8e43feSDavid Howells * GNU General Public License for more details. 134a8e43feSDavid Howells * 144a8e43feSDavid Howells * You should have received a copy of the GNU General Public License 154a8e43feSDavid Howells * along with this program; if not, write to the Free Software 164a8e43feSDavid Howells * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 174a8e43feSDavid Howells * 184a8e43feSDavid Howells */ 194a8e43feSDavid Howells 204a8e43feSDavid Howells #ifndef __MTD_ABI_H__ 214a8e43feSDavid Howells #define __MTD_ABI_H__ 224a8e43feSDavid Howells 234a8e43feSDavid Howells #include <linux/types.h> 244a8e43feSDavid Howells 254a8e43feSDavid Howells struct erase_info_user { 264a8e43feSDavid Howells __u32 start; 274a8e43feSDavid Howells __u32 length; 284a8e43feSDavid Howells }; 294a8e43feSDavid Howells 304a8e43feSDavid Howells struct erase_info_user64 { 314a8e43feSDavid Howells __u64 start; 324a8e43feSDavid Howells __u64 length; 334a8e43feSDavid Howells }; 344a8e43feSDavid Howells 354a8e43feSDavid Howells struct mtd_oob_buf { 364a8e43feSDavid Howells __u32 start; 374a8e43feSDavid Howells __u32 length; 384a8e43feSDavid Howells unsigned char __user *ptr; 394a8e43feSDavid Howells }; 404a8e43feSDavid Howells 414a8e43feSDavid Howells struct mtd_oob_buf64 { 424a8e43feSDavid Howells __u64 start; 434a8e43feSDavid Howells __u32 pad; 444a8e43feSDavid Howells __u32 length; 454a8e43feSDavid Howells __u64 usr_ptr; 464a8e43feSDavid Howells }; 474a8e43feSDavid Howells 484a8e43feSDavid Howells /** 494a8e43feSDavid Howells * MTD operation modes 504a8e43feSDavid Howells * 514a8e43feSDavid Howells * @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default) 524a8e43feSDavid Howells * @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas 534a8e43feSDavid Howells * which are defined by the internal ecclayout 544a8e43feSDavid Howells * @MTD_OPS_RAW: data are transferred as-is, with no error correction; 554a8e43feSDavid Howells * this mode implies %MTD_OPS_PLACE_OOB 564a8e43feSDavid Howells * 574a8e43feSDavid Howells * These modes can be passed to ioctl(MEMWRITE) and are also used internally. 584a8e43feSDavid Howells * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs. 594a8e43feSDavid Howells * %MTD_FILE_MODE_RAW. 604a8e43feSDavid Howells */ 614a8e43feSDavid Howells enum { 624a8e43feSDavid Howells MTD_OPS_PLACE_OOB = 0, 634a8e43feSDavid Howells MTD_OPS_AUTO_OOB = 1, 644a8e43feSDavid Howells MTD_OPS_RAW = 2, 654a8e43feSDavid Howells }; 664a8e43feSDavid Howells 674a8e43feSDavid Howells /** 684a8e43feSDavid Howells * struct mtd_write_req - data structure for requesting a write operation 694a8e43feSDavid Howells * 704a8e43feSDavid Howells * @start: start address 714a8e43feSDavid Howells * @len: length of data buffer 724a8e43feSDavid Howells * @ooblen: length of OOB buffer 734a8e43feSDavid Howells * @usr_data: user-provided data buffer 744a8e43feSDavid Howells * @usr_oob: user-provided OOB buffer 754a8e43feSDavid Howells * @mode: MTD mode (see "MTD operation modes") 764a8e43feSDavid Howells * @padding: reserved, must be set to 0 774a8e43feSDavid Howells * 784a8e43feSDavid Howells * This structure supports ioctl(MEMWRITE) operations, allowing data and/or OOB 794a8e43feSDavid Howells * writes in various modes. To write to OOB-only, set @usr_data == NULL, and to 804a8e43feSDavid Howells * write data-only, set @usr_oob == NULL. However, setting both @usr_data and 814a8e43feSDavid Howells * @usr_oob to NULL is not allowed. 824a8e43feSDavid Howells */ 834a8e43feSDavid Howells struct mtd_write_req { 844a8e43feSDavid Howells __u64 start; 854a8e43feSDavid Howells __u64 len; 864a8e43feSDavid Howells __u64 ooblen; 874a8e43feSDavid Howells __u64 usr_data; 884a8e43feSDavid Howells __u64 usr_oob; 894a8e43feSDavid Howells __u8 mode; 904a8e43feSDavid Howells __u8 padding[7]; 914a8e43feSDavid Howells }; 924a8e43feSDavid Howells 934a8e43feSDavid Howells #define MTD_ABSENT 0 944a8e43feSDavid Howells #define MTD_RAM 1 954a8e43feSDavid Howells #define MTD_ROM 2 964a8e43feSDavid Howells #define MTD_NORFLASH 3 974a8e43feSDavid Howells #define MTD_NANDFLASH 4 984a8e43feSDavid Howells #define MTD_DATAFLASH 6 994a8e43feSDavid Howells #define MTD_UBIVOLUME 7 1004a8e43feSDavid Howells #define MTD_MLCNANDFLASH 8 1014a8e43feSDavid Howells 1024a8e43feSDavid Howells #define MTD_WRITEABLE 0x400 /* Device is writeable */ 1034a8e43feSDavid Howells #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */ 1044a8e43feSDavid Howells #define MTD_NO_ERASE 0x1000 /* No erase necessary */ 1054a8e43feSDavid Howells #define MTD_POWERUP_LOCK 0x2000 /* Always locked after reset */ 1064a8e43feSDavid Howells 1074a8e43feSDavid Howells /* Some common devices / combinations of capabilities */ 1084a8e43feSDavid Howells #define MTD_CAP_ROM 0 1094a8e43feSDavid Howells #define MTD_CAP_RAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE) 1104a8e43feSDavid Howells #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE) 1114a8e43feSDavid Howells #define MTD_CAP_NANDFLASH (MTD_WRITEABLE) 1124a8e43feSDavid Howells 1134a8e43feSDavid Howells /* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */ 1144a8e43feSDavid Howells #define MTD_NANDECC_OFF 0 // Switch off ECC (Not recommended) 1154a8e43feSDavid Howells #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode) 1164a8e43feSDavid Howells #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme 1174a8e43feSDavid Howells #define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read) 1184a8e43feSDavid Howells #define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default 1194a8e43feSDavid Howells 1204a8e43feSDavid Howells /* OTP mode selection */ 1214a8e43feSDavid Howells #define MTD_OTP_OFF 0 1224a8e43feSDavid Howells #define MTD_OTP_FACTORY 1 1234a8e43feSDavid Howells #define MTD_OTP_USER 2 1244a8e43feSDavid Howells 1254a8e43feSDavid Howells struct mtd_info_user { 1264a8e43feSDavid Howells __u8 type; 1274a8e43feSDavid Howells __u32 flags; 1284a8e43feSDavid Howells __u32 size; /* Total size of the MTD */ 1294a8e43feSDavid Howells __u32 erasesize; 1304a8e43feSDavid Howells __u32 writesize; 1314a8e43feSDavid Howells __u32 oobsize; /* Amount of OOB data per block (e.g. 16) */ 1324a8e43feSDavid Howells __u64 padding; /* Old obsolete field; do not use */ 1334a8e43feSDavid Howells }; 1344a8e43feSDavid Howells 1354a8e43feSDavid Howells struct region_info_user { 1364a8e43feSDavid Howells __u32 offset; /* At which this region starts, 1374a8e43feSDavid Howells * from the beginning of the MTD */ 1384a8e43feSDavid Howells __u32 erasesize; /* For this region */ 1394a8e43feSDavid Howells __u32 numblocks; /* Number of blocks in this region */ 1404a8e43feSDavid Howells __u32 regionindex; 1414a8e43feSDavid Howells }; 1424a8e43feSDavid Howells 1434a8e43feSDavid Howells struct otp_info { 1444a8e43feSDavid Howells __u32 start; 1454a8e43feSDavid Howells __u32 length; 1464a8e43feSDavid Howells __u32 locked; 1474a8e43feSDavid Howells }; 1484a8e43feSDavid Howells 1494a8e43feSDavid Howells /* 1504a8e43feSDavid Howells * Note, the following ioctl existed in the past and was removed: 1514a8e43feSDavid Howells * #define MEMSETOOBSEL _IOW('M', 9, struct nand_oobinfo) 1524a8e43feSDavid Howells * Try to avoid adding a new ioctl with the same ioctl number. 1534a8e43feSDavid Howells */ 1544a8e43feSDavid Howells 1554a8e43feSDavid Howells /* Get basic MTD characteristics info (better to use sysfs) */ 1564a8e43feSDavid Howells #define MEMGETINFO _IOR('M', 1, struct mtd_info_user) 1574a8e43feSDavid Howells /* Erase segment of MTD */ 1584a8e43feSDavid Howells #define MEMERASE _IOW('M', 2, struct erase_info_user) 1594a8e43feSDavid Howells /* Write out-of-band data from MTD */ 1604a8e43feSDavid Howells #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf) 1614a8e43feSDavid Howells /* Read out-of-band data from MTD */ 1624a8e43feSDavid Howells #define MEMREADOOB _IOWR('M', 4, struct mtd_oob_buf) 1634a8e43feSDavid Howells /* Lock a chip (for MTD that supports it) */ 1644a8e43feSDavid Howells #define MEMLOCK _IOW('M', 5, struct erase_info_user) 1654a8e43feSDavid Howells /* Unlock a chip (for MTD that supports it) */ 1664a8e43feSDavid Howells #define MEMUNLOCK _IOW('M', 6, struct erase_info_user) 1674a8e43feSDavid Howells /* Get the number of different erase regions */ 1684a8e43feSDavid Howells #define MEMGETREGIONCOUNT _IOR('M', 7, int) 1694a8e43feSDavid Howells /* Get information about the erase region for a specific index */ 1704a8e43feSDavid Howells #define MEMGETREGIONINFO _IOWR('M', 8, struct region_info_user) 1714a8e43feSDavid Howells /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */ 1724a8e43feSDavid Howells #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) 1734a8e43feSDavid Howells /* Check if an eraseblock is bad */ 1744a8e43feSDavid Howells #define MEMGETBADBLOCK _IOW('M', 11, __kernel_loff_t) 1754a8e43feSDavid Howells /* Mark an eraseblock as bad */ 1764a8e43feSDavid Howells #define MEMSETBADBLOCK _IOW('M', 12, __kernel_loff_t) 1774a8e43feSDavid Howells /* Set OTP (One-Time Programmable) mode (factory vs. user) */ 1784a8e43feSDavid Howells #define OTPSELECT _IOR('M', 13, int) 1794a8e43feSDavid Howells /* Get number of OTP (One-Time Programmable) regions */ 1804a8e43feSDavid Howells #define OTPGETREGIONCOUNT _IOW('M', 14, int) 1814a8e43feSDavid Howells /* Get all OTP (One-Time Programmable) info about MTD */ 1824a8e43feSDavid Howells #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info) 1834a8e43feSDavid Howells /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */ 1844a8e43feSDavid Howells #define OTPLOCK _IOR('M', 16, struct otp_info) 1854a8e43feSDavid Howells /* Get ECC layout (deprecated) */ 1864a8e43feSDavid Howells #define ECCGETLAYOUT _IOR('M', 17, struct nand_ecclayout_user) 1874a8e43feSDavid Howells /* Get statistics about corrected/uncorrected errors */ 1884a8e43feSDavid Howells #define ECCGETSTATS _IOR('M', 18, struct mtd_ecc_stats) 1894a8e43feSDavid Howells /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */ 1904a8e43feSDavid Howells #define MTDFILEMODE _IO('M', 19) 1914a8e43feSDavid Howells /* Erase segment of MTD (supports 64-bit address) */ 1924a8e43feSDavid Howells #define MEMERASE64 _IOW('M', 20, struct erase_info_user64) 1934a8e43feSDavid Howells /* Write data to OOB (64-bit version) */ 1944a8e43feSDavid Howells #define MEMWRITEOOB64 _IOWR('M', 21, struct mtd_oob_buf64) 1954a8e43feSDavid Howells /* Read data from OOB (64-bit version) */ 1964a8e43feSDavid Howells #define MEMREADOOB64 _IOWR('M', 22, struct mtd_oob_buf64) 1974a8e43feSDavid Howells /* Check if chip is locked (for MTD that supports it) */ 1984a8e43feSDavid Howells #define MEMISLOCKED _IOR('M', 23, struct erase_info_user) 1994a8e43feSDavid Howells /* 2004a8e43feSDavid Howells * Most generic write interface; can write in-band and/or out-of-band in various 2014a8e43feSDavid Howells * modes (see "struct mtd_write_req"). This ioctl is not supported for flashes 2024a8e43feSDavid Howells * without OOB, e.g., NOR flash. 2034a8e43feSDavid Howells */ 2044a8e43feSDavid Howells #define MEMWRITE _IOWR('M', 24, struct mtd_write_req) 2054a8e43feSDavid Howells 2064a8e43feSDavid Howells /* 2074a8e43feSDavid Howells * Obsolete legacy interface. Keep it in order not to break userspace 2084a8e43feSDavid Howells * interfaces 2094a8e43feSDavid Howells */ 2104a8e43feSDavid Howells struct nand_oobinfo { 2114a8e43feSDavid Howells __u32 useecc; 2124a8e43feSDavid Howells __u32 eccbytes; 2134a8e43feSDavid Howells __u32 oobfree[8][2]; 2144a8e43feSDavid Howells __u32 eccpos[32]; 2154a8e43feSDavid Howells }; 2164a8e43feSDavid Howells 2174a8e43feSDavid Howells struct nand_oobfree { 2184a8e43feSDavid Howells __u32 offset; 2194a8e43feSDavid Howells __u32 length; 2204a8e43feSDavid Howells }; 2214a8e43feSDavid Howells 2224a8e43feSDavid Howells #define MTD_MAX_OOBFREE_ENTRIES 8 2234a8e43feSDavid Howells #define MTD_MAX_ECCPOS_ENTRIES 64 2244a8e43feSDavid Howells /* 2254a8e43feSDavid Howells * OBSOLETE: ECC layout control structure. Exported to user-space via ioctl 2264a8e43feSDavid Howells * ECCGETLAYOUT for backwards compatbility and should not be mistaken as a 2274a8e43feSDavid Howells * complete set of ECC information. The ioctl truncates the larger internal 2284a8e43feSDavid Howells * structure to retain binary compatibility with the static declaration of the 2294a8e43feSDavid Howells * ioctl. Note that the "MTD_MAX_..._ENTRIES" macros represent the max size of 2304a8e43feSDavid Howells * the user struct, not the MAX size of the internal struct nand_ecclayout. 2314a8e43feSDavid Howells */ 2324a8e43feSDavid Howells struct nand_ecclayout_user { 2334a8e43feSDavid Howells __u32 eccbytes; 2344a8e43feSDavid Howells __u32 eccpos[MTD_MAX_ECCPOS_ENTRIES]; 2354a8e43feSDavid Howells __u32 oobavail; 2364a8e43feSDavid Howells struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES]; 2374a8e43feSDavid Howells }; 2384a8e43feSDavid Howells 2394a8e43feSDavid Howells /** 2404a8e43feSDavid Howells * struct mtd_ecc_stats - error correction stats 2414a8e43feSDavid Howells * 2424a8e43feSDavid Howells * @corrected: number of corrected bits 2434a8e43feSDavid Howells * @failed: number of uncorrectable errors 2444a8e43feSDavid Howells * @badblocks: number of bad blocks in this partition 2454a8e43feSDavid Howells * @bbtblocks: number of blocks reserved for bad block tables 2464a8e43feSDavid Howells */ 2474a8e43feSDavid Howells struct mtd_ecc_stats { 2484a8e43feSDavid Howells __u32 corrected; 2494a8e43feSDavid Howells __u32 failed; 2504a8e43feSDavid Howells __u32 badblocks; 2514a8e43feSDavid Howells __u32 bbtblocks; 2524a8e43feSDavid Howells }; 2534a8e43feSDavid Howells 2544a8e43feSDavid Howells /* 2554a8e43feSDavid Howells * MTD file modes - for read/write access to MTD 2564a8e43feSDavid Howells * 2574a8e43feSDavid Howells * @MTD_FILE_MODE_NORMAL: OTP disabled, ECC enabled 2584a8e43feSDavid Howells * @MTD_FILE_MODE_OTP_FACTORY: OTP enabled in factory mode 2594a8e43feSDavid Howells * @MTD_FILE_MODE_OTP_USER: OTP enabled in user mode 2604a8e43feSDavid Howells * @MTD_FILE_MODE_RAW: OTP disabled, ECC disabled 2614a8e43feSDavid Howells * 2624a8e43feSDavid Howells * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained 2634a8e43feSDavid Howells * separately for each open file descriptor. 2644a8e43feSDavid Howells * 2654a8e43feSDavid Howells * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW - 2664a8e43feSDavid Howells * raw access to the flash, without error correction or autoplacement schemes. 2674a8e43feSDavid Howells * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode 2684a8e43feSDavid Howells * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is 2694a8e43feSDavid Howells * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)). 2704a8e43feSDavid Howells */ 2714a8e43feSDavid Howells enum mtd_file_modes { 2724a8e43feSDavid Howells MTD_FILE_MODE_NORMAL = MTD_OTP_OFF, 2734a8e43feSDavid Howells MTD_FILE_MODE_OTP_FACTORY = MTD_OTP_FACTORY, 2744a8e43feSDavid Howells MTD_FILE_MODE_OTP_USER = MTD_OTP_USER, 2754a8e43feSDavid Howells MTD_FILE_MODE_RAW, 2764a8e43feSDavid Howells }; 2774a8e43feSDavid Howells 2784a8e43feSDavid Howells #endif /* __MTD_ABI_H__ */ 279