| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * This file provides ECC correction for more than 1 bit per block of data, |
|---|
| 3 | 4 | * using binary BCH codes. It relies on the generic BCH library lib/bch.c. |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * 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. |
|---|
| 20 | 7 | */ |
|---|
| 21 | 8 | |
|---|
| 22 | 9 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 43 | 30 | |
|---|
| 44 | 31 | /** |
|---|
| 45 | 32 | * nand_bch_calculate_ecc - [NAND Interface] Calculate ECC for data block |
|---|
| 46 | | - * @mtd: MTD block structure |
|---|
| 33 | + * @chip: NAND chip object |
|---|
| 47 | 34 | * @buf: input buffer with raw data |
|---|
| 48 | 35 | * @code: output buffer with ECC |
|---|
| 49 | 36 | */ |
|---|
| 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, |
|---|
| 51 | 38 | unsigned char *code) |
|---|
| 52 | 39 | { |
|---|
| 53 | | - const struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 54 | 40 | struct nand_bch_control *nbc = chip->ecc.priv; |
|---|
| 55 | 41 | unsigned int i; |
|---|
| 56 | 42 | |
|---|
| 57 | 43 | 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); |
|---|
| 59 | 45 | |
|---|
| 60 | 46 | /* apply mask so that an erased page is a valid codeword */ |
|---|
| 61 | 47 | for (i = 0; i < chip->ecc.bytes; i++) |
|---|
| .. | .. |
|---|
| 67 | 53 | |
|---|
| 68 | 54 | /** |
|---|
| 69 | 55 | * nand_bch_correct_data - [NAND Interface] Detect and correct bit error(s) |
|---|
| 70 | | - * @mtd: MTD block structure |
|---|
| 56 | + * @chip: NAND chip object |
|---|
| 71 | 57 | * @buf: raw data read from the chip |
|---|
| 72 | 58 | * @read_ecc: ECC from the chip |
|---|
| 73 | 59 | * @calc_ecc: the ECC calculated from raw data |
|---|
| 74 | 60 | * |
|---|
| 75 | 61 | * Detect and correct bit errors for a data byte block |
|---|
| 76 | 62 | */ |
|---|
| 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, |
|---|
| 78 | 64 | unsigned char *read_ecc, unsigned char *calc_ecc) |
|---|
| 79 | 65 | { |
|---|
| 80 | | - const struct nand_chip *chip = mtd_to_nand(mtd); |
|---|
| 81 | 66 | struct nand_bch_control *nbc = chip->ecc.priv; |
|---|
| 82 | 67 | unsigned int *errloc = nbc->errloc; |
|---|
| 83 | 68 | int i, count; |
|---|
| 84 | 69 | |
|---|
| 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, |
|---|
| 86 | 71 | NULL, errloc); |
|---|
| 87 | 72 | if (count > 0) { |
|---|
| 88 | 73 | for (i = 0; i < count; i++) { |
|---|
| .. | .. |
|---|
| 145 | 130 | if (!nbc) |
|---|
| 146 | 131 | goto fail; |
|---|
| 147 | 132 | |
|---|
| 148 | | - nbc->bch = init_bch(m, t, 0); |
|---|
| 133 | + nbc->bch = bch_init(m, t, 0, false); |
|---|
| 149 | 134 | if (!nbc->bch) |
|---|
| 150 | 135 | goto fail; |
|---|
| 151 | 136 | |
|---|
| .. | .. |
|---|
| 180 | 165 | */ |
|---|
| 181 | 166 | nand->ecc.steps = eccsteps; |
|---|
| 182 | 167 | nand->ecc.total = eccsteps * eccbytes; |
|---|
| 168 | + nand->base.ecc.ctx.total = nand->ecc.total; |
|---|
| 183 | 169 | if (mtd_ooblayout_count_eccbytes(mtd) != (eccsteps*eccbytes)) { |
|---|
| 184 | 170 | pr_warn("invalid ecc layout\n"); |
|---|
| 185 | 171 | goto fail; |
|---|
| 186 | 172 | } |
|---|
| 187 | 173 | |
|---|
| 188 | | - nbc->eccmask = kmalloc(eccbytes, GFP_KERNEL); |
|---|
| 174 | + nbc->eccmask = kzalloc(eccbytes, GFP_KERNEL); |
|---|
| 189 | 175 | nbc->errloc = kmalloc_array(t, sizeof(*nbc->errloc), GFP_KERNEL); |
|---|
| 190 | 176 | if (!nbc->eccmask || !nbc->errloc) |
|---|
| 191 | 177 | goto fail; |
|---|
| .. | .. |
|---|
| 197 | 183 | goto fail; |
|---|
| 198 | 184 | |
|---|
| 199 | 185 | 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); |
|---|
| 202 | 187 | kfree(erased_page); |
|---|
| 203 | 188 | |
|---|
| 204 | 189 | for (i = 0; i < eccbytes; i++) |
|---|
| .. | .. |
|---|
| 221 | 206 | void nand_bch_free(struct nand_bch_control *nbc) |
|---|
| 222 | 207 | { |
|---|
| 223 | 208 | if (nbc) { |
|---|
| 224 | | - free_bch(nbc->bch); |
|---|
| 209 | + bch_free(nbc->bch); |
|---|
| 225 | 210 | kfree(nbc->errloc); |
|---|
| 226 | 211 | kfree(nbc->eccmask); |
|---|
| 227 | 212 | kfree(nbc); |
|---|