Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bbm.h
Go to the documentation of this file.
1 /*
2  * linux/include/linux/mtd/bbm.h
3  *
4  * NAND family Bad Block Management (BBM) header file
5  * - Bad Block Table (BBT) implementation
6  *
7  * Copyright © 2005 Samsung Electronics
8  * Kyungmin Park <[email protected]>
9  *
10  * Copyright © 2000-2005
11  * Thomas Gleixner <[email protected]>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26  *
27  */
28 #ifndef __LINUX_MTD_BBM_H
29 #define __LINUX_MTD_BBM_H
30 
31 /* The maximum number of NAND chips in an array */
32 #define NAND_MAX_CHIPS 8
33 
58  int options;
60  int offs;
61  int veroffs;
63  int len;
64  int maxblocks;
67 };
68 
69 /* Options for the bad block table descriptors */
70 
71 /* The number of bits used per block in the bbt on the device */
72 #define NAND_BBT_NRBITS_MSK 0x0000000F
73 #define NAND_BBT_1BIT 0x00000001
74 #define NAND_BBT_2BIT 0x00000002
75 #define NAND_BBT_4BIT 0x00000004
76 #define NAND_BBT_8BIT 0x00000008
77 /* The bad block table is in the last good block of the device */
78 #define NAND_BBT_LASTBLOCK 0x00000010
79 /* The bbt is at the given page, else we must scan for the bbt */
80 #define NAND_BBT_ABSPAGE 0x00000020
81 /* bbt is stored per chip on multichip devices */
82 #define NAND_BBT_PERCHIP 0x00000080
83 /* bbt has a version counter at offset veroffs */
84 #define NAND_BBT_VERSION 0x00000100
85 /* Create a bbt if none exists */
86 #define NAND_BBT_CREATE 0x00000200
87 /*
88  * Create an empty BBT with no vendor information. Vendor's information may be
89  * unavailable, for example, if the NAND controller has a different data and OOB
90  * layout or if this information is already purged. Must be used in conjunction
91  * with NAND_BBT_CREATE.
92  */
93 #define NAND_BBT_CREATE_EMPTY 0x00000400
94 /* Search good / bad pattern through all pages of a block */
95 #define NAND_BBT_SCANALLPAGES 0x00000800
96 /* Scan block empty during good / bad block scan */
97 #define NAND_BBT_SCANEMPTY 0x00001000
98 /* Write bbt if neccecary */
99 #define NAND_BBT_WRITE 0x00002000
100 /* Read and write back block contents when writing bbt */
101 #define NAND_BBT_SAVECONTENT 0x00004000
102 /* Search good / bad pattern on the first and the second page */
103 #define NAND_BBT_SCAN2NDPAGE 0x00008000
104 /* Search good / bad pattern on the last page of the eraseblock */
105 #define NAND_BBT_SCANLASTPAGE 0x00010000
106 /*
107  * Use a flash based bad block table. By default, OOB identifier is saved in
108  * OOB area. This option is passed to the default bad block table function.
109  */
110 #define NAND_BBT_USE_FLASH 0x00020000
111 /*
112  * Do not store flash based bad block table marker in the OOB area; store it
113  * in-band.
114  */
115 #define NAND_BBT_NO_OOB 0x00040000
116 /*
117  * Do not write new bad block markers to OOB; useful, e.g., when ECC covers
118  * entire spare area. Must be used with NAND_BBT_USE_FLASH.
119  */
120 #define NAND_BBT_NO_OOB_BBM 0x00080000
121 
122 /*
123  * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
124  * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
125  * in nand_chip.bbt_options.
126  */
127 #define NAND_BBT_DYNAMICSTRUCT 0x80000000
128 
129 /* The maximum number of blocks to scan for a bbt */
130 #define NAND_BBT_SCAN_MAXBLOCKS 4
131 
132 /*
133  * Constants for oob configuration
134  */
135 #define NAND_SMALL_BADBLOCK_POS 5
136 #define NAND_LARGE_BADBLOCK_POS 0
137 #define ONENAND_BADBLOCK_POS 0
138 
139 /*
140  * Bad block scanning errors
141  */
142 #define ONENAND_BBT_READ_ERROR 1
143 #define ONENAND_BBT_READ_ECC_ERROR 2
144 #define ONENAND_BBT_READ_FATAL_ERROR 4
145 
157 struct bbm_info {
160  int options;
161 
163 
164  int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
165 
166  /* TODO Add more NAND specific fileds */
168 
169  void *priv;
170 };
171 
172 /* OneNAND BBT interface */
173 extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
174 extern int onenand_default_bbt(struct mtd_info *mtd);
175 
176 #endif /* __LINUX_MTD_BBM_H */