Skip to content

Commit 00da2ea

Browse files
Boris Brezillonmiquelraynal
authored andcommitted
mtd: rawnand: Pass a nand_chip object to ecc->correct()
Let's make the raw NAND API consistent by patching all helpers and hooks to take a nand_chip object instead of an mtd_info one. Now is ecc->correct()'s turn. Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent af37d2c commit 00da2ea

17 files changed

Lines changed: 52 additions & 55 deletions

‎drivers/mtd/nand/raw/davinci_nand.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,9 @@ static int nand_davinci_calculate_1bit(struct nand_chip *chip,
185185
return 0;
186186
}
187187

188-
static int nand_davinci_correct_1bit(struct mtd_info *mtd, u_char *dat,
188+
static int nand_davinci_correct_1bit(struct nand_chip *chip, u_char *dat,
189189
u_char *read_ecc, u_char *calc_ecc)
190190
{
191-
struct nand_chip *chip = mtd_to_nand(mtd);
192191
uint32_t eccNand = read_ecc[0] | (read_ecc[1] << 8) |
193192
(read_ecc[2] << 16);
194193
uint32_t eccCalc = calc_ecc[0] | (calc_ecc[1] << 8) |
@@ -303,11 +302,11 @@ static int nand_davinci_calculate_4bit(struct nand_chip *chip,
303302
/* Correct up to 4 bits in data we just read, using state left in the
304303
* hardware plus the ecc_code computed when it was first written.
305304
*/
306-
static int nand_davinci_correct_4bit(struct mtd_info *mtd,
307-
u_char *data, u_char *ecc_code, u_char *null)
305+
static int nand_davinci_correct_4bit(struct nand_chip *chip, u_char *data,
306+
u_char *ecc_code, u_char *null)
308307
{
309308
int i;
310-
struct davinci_nand_info *info = to_davinci_nand(mtd);
309+
struct davinci_nand_info *info = to_davinci_nand(nand_to_mtd(chip));
311310
unsigned short ecc10[8];
312311
unsigned short *ecc16;
313312
u32 syndrome[4];

‎drivers/mtd/nand/raw/diskonchip.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,10 @@ static int doc200x_calculate_ecc(struct nand_chip *this, const u_char *dat,
893893
return 0;
894894
}
895895

896-
static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat,
896+
static int doc200x_correct_data(struct nand_chip *this, u_char *dat,
897897
u_char *read_ecc, u_char *isnull)
898898
{
899899
int i, ret = 0;
900-
struct nand_chip *this = mtd_to_nand(mtd);
901900
struct doc_priv *doc = nand_get_controller_data(this);
902901
void __iomem *docptr = doc->virtadr;
903902
uint8_t calc_ecc[6];

‎drivers/mtd/nand/raw/fsmc_nand.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
769769
memcpy(&ecc_code[i], oob, chip->ecc.bytes);
770770
chip->ecc.calculate(chip, p, &ecc_calc[i]);
771771

772-
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
772+
stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
773773
if (stat < 0) {
774774
mtd->ecc_stats.failed++;
775775
} else {
@@ -791,11 +791,10 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
791791
* calc_ecc is a 104 bit information containing maximum of 8 error
792792
* offset informations of 13 bits each in 512 bytes of read data.
793793
*/
794-
static int fsmc_bch8_correct_data(struct mtd_info *mtd, uint8_t *dat,
795-
uint8_t *read_ecc, uint8_t *calc_ecc)
794+
static int fsmc_bch8_correct_data(struct nand_chip *chip, uint8_t *dat,
795+
uint8_t *read_ecc, uint8_t *calc_ecc)
796796
{
797-
struct nand_chip *chip = mtd_to_nand(mtd);
798-
struct fsmc_nand_data *host = mtd_to_fsmc(mtd);
797+
struct fsmc_nand_data *host = mtd_to_fsmc(nand_to_mtd(chip));
799798
uint32_t err_idx[8];
800799
uint32_t num_err, i;
801800
uint32_t ecc1, ecc2, ecc3, ecc4;

‎drivers/mtd/nand/raw/jz4740_nand.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ static void jz_nand_correct_data(uint8_t *dat, int index, int mask)
215215
dat[index+1] = (data >> 8) & 0xff;
216216
}
217217

218-
static int jz_nand_correct_ecc_rs(struct mtd_info *mtd, uint8_t *dat,
219-
uint8_t *read_ecc, uint8_t *calc_ecc)
218+
static int jz_nand_correct_ecc_rs(struct nand_chip *chip, uint8_t *dat,
219+
uint8_t *read_ecc, uint8_t *calc_ecc)
220220
{
221-
struct jz_nand *nand = mtd_to_jz_nand(mtd);
221+
struct jz_nand *nand = mtd_to_jz_nand(nand_to_mtd(chip));
222222
int i, error_count, index;
223223
uint32_t reg, status, error;
224224
unsigned int timeout = 1000;

‎drivers/mtd/nand/raw/jz4780_nand.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ static int jz4780_nand_ecc_calculate(struct nand_chip *chip, const u8 *dat,
144144
return jz4780_bch_calculate(nfc->bch, &params, dat, ecc_code);
145145
}
146146

147-
static int jz4780_nand_ecc_correct(struct mtd_info *mtd, u8 *dat,
147+
static int jz4780_nand_ecc_correct(struct nand_chip *chip, u8 *dat,
148148
u8 *read_ecc, u8 *calc_ecc)
149149
{
150-
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(mtd);
150+
struct jz4780_nand_chip *nand = to_jz4780_nand_chip(nand_to_mtd(chip));
151151
struct jz4780_nand_controller *nfc = to_jz4780_nand_controller(nand->chip.controller);
152152
struct jz4780_bch_params params;
153153

‎drivers/mtd/nand/raw/lpc32xx_slc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static int lpc32xx_nand_read_page_syndrome(struct mtd_info *mtd,
639639
oobecc = chip->oob_poi + oobregion.offset;
640640

641641
for (i = 0; i < chip->ecc.steps; i++) {
642-
stat = chip->ecc.correct(mtd, buf, oobecc,
642+
stat = chip->ecc.correct(chip, buf, oobecc,
643643
&tmpecc[i * chip->ecc.bytes]);
644644
if (stat < 0)
645645
mtd->ecc_stats.failed++;

‎drivers/mtd/nand/raw/nand_base.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,7 +3123,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
31233123
for (i = 0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
31243124
int stat;
31253125

3126-
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
3126+
stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
31273127
if (stat < 0) {
31283128
mtd->ecc_stats.failed++;
31293129
} else {
@@ -3224,7 +3224,7 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
32243224
for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) {
32253225
int stat;
32263226

3227-
stat = chip->ecc.correct(mtd, p, &chip->ecc.code_buf[i],
3227+
stat = chip->ecc.correct(chip, p, &chip->ecc.code_buf[i],
32283228
&chip->ecc.calc_buf[i]);
32293229
if (stat == -EBADMSG &&
32303230
(chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
@@ -3296,7 +3296,7 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
32963296
for (i = 0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
32973297
int stat;
32983298

3299-
stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
3299+
stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]);
33003300
if (stat == -EBADMSG &&
33013301
(chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
33023302
/* check for empty pages with bitflips */
@@ -3366,7 +3366,7 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
33663366

33673367
chip->ecc.calculate(chip, p, &ecc_calc[i]);
33683368

3369-
stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
3369+
stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL);
33703370
if (stat == -EBADMSG &&
33713371
(chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
33723372
/* check for empty pages with bitflips */
@@ -3436,7 +3436,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
34363436
if (ret)
34373437
return ret;
34383438

3439-
stat = chip->ecc.correct(mtd, p, oob, NULL);
3439+
stat = chip->ecc.correct(chip, p, oob, NULL);
34403440

34413441
oob += eccbytes;
34423442

‎drivers/mtd/nand/raw/nand_bch.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,16 @@ EXPORT_SYMBOL(nand_bch_calculate_ecc);
6666

6767
/**
6868
* nand_bch_correct_data - [NAND Interface] Detect and correct bit error(s)
69-
* @mtd: MTD block structure
69+
* @chip: NAND chip object
7070
* @buf: raw data read from the chip
7171
* @read_ecc: ECC from the chip
7272
* @calc_ecc: the ECC calculated from raw data
7373
*
7474
* Detect and correct bit errors for a data byte block
7575
*/
76-
int nand_bch_correct_data(struct mtd_info *mtd, unsigned char *buf,
76+
int nand_bch_correct_data(struct nand_chip *chip, unsigned char *buf,
7777
unsigned char *read_ecc, unsigned char *calc_ecc)
7878
{
79-
const struct nand_chip *chip = mtd_to_nand(mtd);
8079
struct nand_bch_control *nbc = chip->ecc.priv;
8180
unsigned int *errloc = nbc->errloc;
8281
int i, count;

‎drivers/mtd/nand/raw/nand_ecc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,18 +490,17 @@ EXPORT_SYMBOL(__nand_correct_data);
490490

491491
/**
492492
* nand_correct_data - [NAND Interface] Detect and correct bit error(s)
493-
* @mtd: MTD block structure
493+
* @chip: NAND chip object
494494
* @buf: raw data read from the chip
495495
* @read_ecc: ECC from the chip
496496
* @calc_ecc: the ECC calculated from raw data
497497
*
498498
* Detect and correct a 1 bit error for 256/512 byte block
499499
*/
500-
int nand_correct_data(struct mtd_info *mtd, unsigned char *buf,
500+
int nand_correct_data(struct nand_chip *chip, unsigned char *buf,
501501
unsigned char *read_ecc, unsigned char *calc_ecc)
502502
{
503-
return __nand_correct_data(buf, read_ecc, calc_ecc,
504-
mtd_to_nand(mtd)->ecc.size);
503+
return __nand_correct_data(buf, read_ecc, calc_ecc, chip->ecc.size);
505504
}
506505
EXPORT_SYMBOL(nand_correct_data);
507506

‎drivers/mtd/nand/raw/omap2.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
857857

858858
/**
859859
* omap_correct_data - Compares the ECC read with HW generated ECC
860-
* @mtd: MTD device structure
860+
* @chip: NAND chip object
861861
* @dat: page data
862862
* @read_ecc: ecc read from nand flash
863863
* @calc_ecc: ecc read from HW ECC registers
@@ -869,10 +869,10 @@ static int omap_compare_ecc(u8 *ecc_data1, /* read from NAND memory */
869869
* corrected errors is returned. If uncorrectable errors exist, %-1 is
870870
* returned.
871871
*/
872-
static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
873-
u_char *read_ecc, u_char *calc_ecc)
872+
static int omap_correct_data(struct nand_chip *chip, u_char *dat,
873+
u_char *read_ecc, u_char *calc_ecc)
874874
{
875-
struct omap_nand_info *info = mtd_to_omap(mtd);
875+
struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
876876
int blockCnt = 0, i = 0, ret = 0;
877877
int stat = 0;
878878

@@ -1338,7 +1338,7 @@ static int erased_sector_bitflips(u_char *data, u_char *oob,
13381338

13391339
/**
13401340
* omap_elm_correct_data - corrects page data area in case error reported
1341-
* @mtd: MTD device structure
1341+
* @chip: NAND chip object
13421342
* @data: page data
13431343
* @read_ecc: ecc read from nand flash
13441344
* @calc_ecc: ecc read from HW ECC registers
@@ -1347,10 +1347,10 @@ static int erased_sector_bitflips(u_char *data, u_char *oob,
13471347
* In case of non-zero ecc vector, first filter out erased-pages, and
13481348
* then process data via ELM to detect bit-flips.
13491349
*/
1350-
static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data,
1351-
u_char *read_ecc, u_char *calc_ecc)
1350+
static int omap_elm_correct_data(struct nand_chip *chip, u_char *data,
1351+
u_char *read_ecc, u_char *calc_ecc)
13521352
{
1353-
struct omap_nand_info *info = mtd_to_omap(mtd);
1353+
struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
13541354
struct nand_ecc_ctrl *ecc = &info->nand.ecc;
13551355
int eccsteps = info->nand.ecc.steps;
13561356
int i , j, stat = 0;
@@ -1659,7 +1659,7 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
16591659
if (ret)
16601660
return ret;
16611661

1662-
stat = chip->ecc.correct(mtd, buf, ecc_code, ecc_calc);
1662+
stat = chip->ecc.correct(chip, buf, ecc_code, ecc_calc);
16631663

16641664
if (stat < 0) {
16651665
mtd->ecc_stats.failed++;

0 commit comments

Comments
 (0)