hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/mtd/nand/raw/nand_bch.c
....@@ -1,22 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * This file provides ECC correction for more than 1 bit per block of data,
34 * using binary BCH codes. It relies on the generic BCH library lib/bch.c.
45 *
56 * Copyright © 2011 Ivan Djelic <ivan.djelic@parrot.com>
6
- *
7
- * This file is free software; you can redistribute it and/or modify it
8
- * under the terms of the GNU General Public License as published by the
9
- * Free Software Foundation; either version 2 or (at your option) any
10
- * later version.
11
- *
12
- * This file is distributed in the hope that it will be useful, but WITHOUT
13
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
- * for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License along
18
- * with this file; if not, write to the Free Software Foundation, Inc.,
19
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
207 */
218
229 #include <linux/types.h>
....@@ -43,19 +30,18 @@
4330
4431 /**
4532 * nand_bch_calculate_ecc - [NAND Interface] Calculate ECC for data block
46
- * @mtd: MTD block structure
33
+ * @chip: NAND chip object
4734 * @buf: input buffer with raw data
4835 * @code: output buffer with ECC
4936 */
50
-int nand_bch_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf,
37
+int nand_bch_calculate_ecc(struct nand_chip *chip, const unsigned char *buf,
5138 unsigned char *code)
5239 {
53
- const struct nand_chip *chip = mtd_to_nand(mtd);
5440 struct nand_bch_control *nbc = chip->ecc.priv;
5541 unsigned int i;
5642
5743 memset(code, 0, chip->ecc.bytes);
58
- encode_bch(nbc->bch, buf, chip->ecc.size, code);
44
+ bch_encode(nbc->bch, buf, chip->ecc.size, code);
5945
6046 /* apply mask so that an erased page is a valid codeword */
6147 for (i = 0; i < chip->ecc.bytes; i++)
....@@ -67,22 +53,21 @@
6753
6854 /**
6955 * nand_bch_correct_data - [NAND Interface] Detect and correct bit error(s)
70
- * @mtd: MTD block structure
56
+ * @chip: NAND chip object
7157 * @buf: raw data read from the chip
7258 * @read_ecc: ECC from the chip
7359 * @calc_ecc: the ECC calculated from raw data
7460 *
7561 * Detect and correct bit errors for a data byte block
7662 */
77
-int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
63
+int nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
7864 unsigned char *read_ecc, unsigned char *calc_ecc)
7965 {
80
- const struct nand_chip *chip = mtd_to_nand(mtd);
8166 struct nand_bch_control *nbc = chip->ecc.priv;
8267 unsigned int *errloc = nbc->errloc;
8368 int i, count;
8469
85
- count = decode_bch(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
70
+ count = bch_decode(nbc->bch, NULL, chip->ecc.size, read_ecc, calc_ecc,
8671 NULL, errloc);
8772 if (count > 0) {
8873 for (i = 0; i < count; i++) {
....@@ -145,7 +130,7 @@
145130 if (!nbc)
146131 goto fail;
147132
148
- nbc->bch = init_bch(m, t, 0);
133
+ nbc->bch = bch_init(m, t, 0, false);
149134 if (!nbc->bch)
150135 goto fail;
151136
....@@ -180,12 +165,13 @@
180165 */
181166 nand->ecc.steps = eccsteps;
182167 nand->ecc.total = eccsteps * eccbytes;
168
+ nand->base.ecc.ctx.total = nand->ecc.total;
183169 if (mtd_ooblayout_count_eccbytes(mtd) != (eccsteps*eccbytes)) {
184170 pr_warn("invalid ecc layout\n");
185171 goto fail;
186172 }
187173
188
- nbc->eccmask = kmalloc(eccbytes, GFP_KERNEL);
174
+ nbc->eccmask = kzalloc(eccbytes, GFP_KERNEL);
189175 nbc->errloc = kmalloc_array(t, sizeof(*nbc->errloc), GFP_KERNEL);
190176 if (!nbc->eccmask || !nbc->errloc)
191177 goto fail;
....@@ -197,8 +183,7 @@
197183 goto fail;
198184
199185 memset(erased_page, 0xff, eccsize);
200
- memset(nbc->eccmask, 0, eccbytes);
201
- encode_bch(nbc->bch, erased_page, eccsize, nbc->eccmask);
186
+ bch_encode(nbc->bch, erased_page, eccsize, nbc->eccmask);
202187 kfree(erased_page);
203188
204189 for (i = 0; i < eccbytes; i++)
....@@ -221,7 +206,7 @@
221206 void nand_bch_free(struct nand_bch_control *nbc)
222207 {
223208 if (nbc) {
224
- free_bch(nbc->bch);
209
+ bch_free(nbc->bch);
225210 kfree(nbc->errloc);
226211 kfree(nbc->eccmask);
227212 kfree(nbc);