144 lines · c
1/* SPDX-License-Identifier: GPL-2.0-or-later */2/*3 * NAND family Bad Block Management (BBM) header file4 * - Bad Block Table (BBT) implementation5 *6 * Copyright © 2005 Samsung Electronics7 * Kyungmin Park <kyungmin.park@samsung.com>8 *9 * Copyright © 2000-200510 * Thomas Gleixner <tglx@linuxtronix.de>11 */12#ifndef __LINUX_MTD_BBM_H13#define __LINUX_MTD_BBM_H14 15/* The maximum number of NAND chips in an array */16#define NAND_MAX_CHIPS 817 18/**19 * struct nand_bbt_descr - bad block table descriptor20 * @options: options for this descriptor21 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE22 * when bbt is searched, then we store the found bbts pages here.23 * Its an array and supports up to 8 chips now24 * @offs: offset of the pattern in the oob area of the page25 * @veroffs: offset of the bbt version counter in the oob are of the page26 * @version: version read from the bbt page during scan27 * @len: length of the pattern, if 0 no pattern check is performed28 * @maxblocks: maximum number of blocks to search for a bbt. This number of29 * blocks is reserved at the end of the device where the tables are30 * written.31 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than32 * bad) block in the stored bbt33 * @pattern: pattern to identify bad block table or factory marked good /34 * bad blocks, can be NULL, if len = 035 *36 * Descriptor for the bad block table marker and the descriptor for the37 * pattern which identifies good and bad blocks. The assumption is made38 * that the pattern and the version count are always located in the oob area39 * of the first block.40 */41struct nand_bbt_descr {42 int options;43 int pages[NAND_MAX_CHIPS];44 int offs;45 int veroffs;46 uint8_t version[NAND_MAX_CHIPS];47 int len;48 int maxblocks;49 int reserved_block_code;50 uint8_t *pattern;51};52 53/* Options for the bad block table descriptors */54 55/* The number of bits used per block in the bbt on the device */56#define NAND_BBT_NRBITS_MSK 0x0000000F57#define NAND_BBT_1BIT 0x0000000158#define NAND_BBT_2BIT 0x0000000259#define NAND_BBT_4BIT 0x0000000460#define NAND_BBT_8BIT 0x0000000861/* The bad block table is in the last good block of the device */62#define NAND_BBT_LASTBLOCK 0x0000001063/* The bbt is at the given page, else we must scan for the bbt */64#define NAND_BBT_ABSPAGE 0x0000002065/* bbt is stored per chip on multichip devices */66#define NAND_BBT_PERCHIP 0x0000008067/* bbt has a version counter at offset veroffs */68#define NAND_BBT_VERSION 0x0000010069/* Create a bbt if none exists */70#define NAND_BBT_CREATE 0x0000020071/*72 * Create an empty BBT with no vendor information. Vendor's information may be73 * unavailable, for example, if the NAND controller has a different data and OOB74 * layout or if this information is already purged. Must be used in conjunction75 * with NAND_BBT_CREATE.76 */77#define NAND_BBT_CREATE_EMPTY 0x0000040078/* Write bbt if neccecary */79#define NAND_BBT_WRITE 0x0000200080/* Read and write back block contents when writing bbt */81#define NAND_BBT_SAVECONTENT 0x0000400082 83/*84 * Use a flash based bad block table. By default, OOB identifier is saved in85 * OOB area. This option is passed to the default bad block table function.86 */87#define NAND_BBT_USE_FLASH 0x0002000088/*89 * Do not store flash based bad block table marker in the OOB area; store it90 * in-band.91 */92#define NAND_BBT_NO_OOB 0x0004000093/*94 * Do not write new bad block markers to OOB; useful, e.g., when ECC covers95 * entire spare area. Must be used with NAND_BBT_USE_FLASH.96 */97#define NAND_BBT_NO_OOB_BBM 0x0008000098 99/*100 * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr101 * was allocated dynamicaly and must be freed in nand_cleanup(). Has no meaning102 * in nand_chip.bbt_options.103 */104#define NAND_BBT_DYNAMICSTRUCT 0x80000000105 106/* The maximum number of blocks to scan for a bbt */107#define NAND_BBT_SCAN_MAXBLOCKS 4108 109/*110 * Bad block scanning errors111 */112#define ONENAND_BBT_READ_ERROR 1113#define ONENAND_BBT_READ_ECC_ERROR 2114#define ONENAND_BBT_READ_FATAL_ERROR 4115 116/**117 * struct bbm_info - [GENERIC] Bad Block Table data structure118 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry119 * @options: options for this descriptor120 * @bbt: [INTERN] bad block table pointer121 * @isbad_bbt: function to determine if a block is bad122 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for123 * initial bad block scan124 * @priv: [OPTIONAL] pointer to private bbm date125 */126struct bbm_info {127 int bbt_erase_shift;128 int options;129 130 uint8_t *bbt;131 132 int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);133 134 /* TODO Add more NAND specific fileds */135 struct nand_bbt_descr *badblock_pattern;136 137 void *priv;138};139 140/* OneNAND BBT interface */141extern int onenand_default_bbt(struct mtd_info *mtd);142 143#endif /* __LINUX_MTD_BBM_H */144