Lines Matching +full:nand +full:- +full:ecc +full:- +full:strength
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * This file provides ECC correction for more than 1 bit per block of data,
20 * struct nand_bch_control - private NAND BCH control structure
23 * @eccmask: XOR ecc mask, allows erased pages to be decoded as valid
32 * nand_bch_calculate_ecc - [NAND Interface] Calculate ECC for data block
33 * @chip: NAND chip object
35 * @code: output buffer with ECC
40 struct nand_bch_control *nbc = chip->ecc.priv; in nand_bch_calculate_ecc()
43 memset(code, 0, chip->ecc.bytes); in nand_bch_calculate_ecc()
44 bch_encode(nbc->bch, buf, chip->ecc.size, code); in nand_bch_calculate_ecc()
47 for (i = 0; i < chip->ecc.bytes; i++) in nand_bch_calculate_ecc()
48 code[i] ^= nbc->eccmask[i]; in nand_bch_calculate_ecc()
55 * nand_bch_correct_data - [NAND Interface] Detect and correct bit error(s)
56 * @chip: NAND chip object
58 * @read_ecc: ECC from the chip
59 * @calc_ecc: the ECC calculated from raw data
66 struct nand_bch_control *nbc = chip->ecc.priv; in nand_bch_correct_data()
67 unsigned int *errloc = nbc->errloc; in nand_bch_correct_data()
70 count = bch_decode(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc, in nand_bch_correct_data()
74 if (errloc[i] < (chip->ecc.size*8)) in nand_bch_correct_data()
77 /* else error in ecc, no action needed */ in nand_bch_correct_data()
83 pr_err("ecc unrecoverable error\n"); in nand_bch_correct_data()
84 count = -EBADMSG; in nand_bch_correct_data()
91 * nand_bch_init - [NAND Interface] Initialize NAND BCH error correction
95 * a pointer to a new NAND BCH control structure, or NULL upon failure
97 * Initialize NAND BCH error correction. Parameters @eccsize and @eccbytes
100 * required to store m*t bits, where m is such that 2^m-1 > @eccsize*8.
103 * @eccsize = 512 (thus, m=13 is the smallest integer such that 2^m-1 > 512*8)
108 struct nand_chip *nand = mtd_to_nand(mtd); in nand_bch_init() local
112 unsigned int eccsize = nand->ecc.size; in nand_bch_init()
113 unsigned int eccbytes = nand->ecc.bytes; in nand_bch_init()
114 unsigned int eccstrength = nand->ecc.strength; in nand_bch_init()
118 nand->ecc.bytes = eccbytes; in nand_bch_init()
122 pr_warn("ecc parameters not supplied\n"); in nand_bch_init()
133 nbc->bch = bch_init(m, t, 0, false); in nand_bch_init()
134 if (!nbc->bch) in nand_bch_init()
138 if (nbc->bch->ecc_bytes != eccbytes) { in nand_bch_init()
140 eccbytes, nbc->bch->ecc_bytes); in nand_bch_init()
144 eccsteps = mtd->writesize/eccsize; in nand_bch_init()
147 if (!mtd->ooblayout) { in nand_bch_init()
159 * ecc->steps and ecc->total might be used by mtd->ooblayout->ecc(), in nand_bch_init()
166 nand->ecc.steps = eccsteps; in nand_bch_init()
167 nand->ecc.total = eccsteps * eccbytes; in nand_bch_init()
168 nand->base.ecc.ctx.total = nand->ecc.total; in nand_bch_init()
170 pr_warn("invalid ecc layout\n"); in nand_bch_init()
174 nbc->eccmask = kzalloc(eccbytes, GFP_KERNEL); in nand_bch_init()
175 nbc->errloc = kmalloc_array(t, sizeof(*nbc->errloc), GFP_KERNEL); in nand_bch_init()
176 if (!nbc->eccmask || !nbc->errloc) in nand_bch_init()
179 * compute and store the inverted ecc of an erased ecc block in nand_bch_init()
186 bch_encode(nbc->bch, erased_page, eccsize, nbc->eccmask); in nand_bch_init()
190 nbc->eccmask[i] ^= 0xff; in nand_bch_init()
193 nand->ecc.strength = (eccbytes * 8) / fls(8 * eccsize); in nand_bch_init()
203 * nand_bch_free - [NAND Interface] Release NAND BCH ECC resources
204 * @nbc: NAND BCH control structure
209 bch_free(nbc->bch); in nand_bch_free()
210 kfree(nbc->errloc); in nand_bch_free()
211 kfree(nbc->eccmask); in nand_bch_free()
219 MODULE_DESCRIPTION("NAND software BCH ECC support");