Skip to content

Commit 90ccf0a

Browse files
committed
mtd: nand: ecc-hamming: Rename the exported functions
Prefix by ecc_sw_hamming_ the functions which should be internal only but are exported for "raw" operations. Prefix by nand_ecc_sw_hamming_ the other functions which will be used in the context of the declaration of an Hamming proper ECC engine object. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20200929230124.31491-16-miquel.raynal@bootlin.com
1 parent b551fa3 commit 90ccf0a

13 files changed

Lines changed: 108 additions & 92 deletions

File tree

‎drivers/mtd/nand/ecc-sw-hamming.c‎

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static const char bitsperbyte[256] = {
7575
* addressbits is a lookup table to filter out the bits from the xor-ed
7676
* ECC data that identify the faulty location.
7777
* this is only used for repairing parity
78-
* see the comments in nand_correct_data for more details
78+
* see the comments in nand_ecc_sw_hamming_correct for more details
7979
*/
8080
static const char addressbits[256] = {
8181
0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
@@ -112,11 +112,11 @@ static const char addressbits[256] = {
112112
0x0e, 0x0e, 0x0f, 0x0f, 0x0e, 0x0e, 0x0f, 0x0f
113113
};
114114

115-
void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
116-
unsigned char *code, bool sm_order)
115+
int ecc_sw_hamming_calculate(const unsigned char *buf, unsigned int step_size,
116+
unsigned char *code, bool sm_order)
117117
{
118118
const u32 *bp = (uint32_t *)buf;
119-
const u32 eccsize_mult = eccsize >> 8;
119+
const u32 eccsize_mult = step_size >> 8;
120120
/* current value in buffer */
121121
u32 cur;
122122
/* rp0..rp17 are the various accumulated parities (per byte) */
@@ -347,31 +347,32 @@ void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize,
347347
(invparity[par & 0x55] << 2) |
348348
(invparity[rp17] << 1) |
349349
(invparity[rp16] << 0);
350+
351+
return 0;
350352
}
351-
EXPORT_SYMBOL(__nand_calculate_ecc);
353+
EXPORT_SYMBOL(ecc_sw_hamming_calculate);
352354

353355
/**
354-
* nand_calculate_ecc - Calculate 3-byte ECC for 256/512-byte block
355-
* @chip: NAND chip object
356+
* nand_ecc_sw_hamming_calculate - Calculate 3-byte ECC for 256/512-byte block
357+
* @nand: NAND device
356358
* @buf: Input buffer with raw data
357359
* @code: Output buffer with ECC
358360
*/
359-
int nand_calculate_ecc(struct nand_chip *chip, const unsigned char *buf,
360-
unsigned char *code)
361+
int nand_ecc_sw_hamming_calculate(struct nand_device *nand,
362+
const unsigned char *buf, unsigned char *code)
361363
{
364+
struct nand_chip *chip = mtd_to_nand(nanddev_to_mtd(nand));
362365
bool sm_order = chip->ecc.options & NAND_ECC_SOFT_HAMMING_SM_ORDER;
363366

364-
__nand_calculate_ecc(buf, chip->ecc.size, code, sm_order);
365-
366-
return 0;
367+
return ecc_sw_hamming_calculate(buf, chip->ecc.size, code, sm_order);
367368
}
368-
EXPORT_SYMBOL(nand_calculate_ecc);
369+
EXPORT_SYMBOL(nand_ecc_sw_hamming_calculate);
369370

370-
int __nand_correct_data(unsigned char *buf,
371-
unsigned char *read_ecc, unsigned char *calc_ecc,
372-
unsigned int eccsize, bool sm_order)
371+
int ecc_sw_hamming_correct(unsigned char *buf, unsigned char *read_ecc,
372+
unsigned char *calc_ecc, unsigned int step_size,
373+
bool sm_order)
373374
{
374-
const u32 eccsize_mult = eccsize >> 8;
375+
const u32 eccsize_mult = step_size >> 8;
375376
unsigned char b0, b1, b2, bit_addr;
376377
unsigned int byte_addr;
377378

@@ -437,26 +438,28 @@ int __nand_correct_data(unsigned char *buf,
437438
pr_err("%s: uncorrectable ECC error\n", __func__);
438439
return -EBADMSG;
439440
}
440-
EXPORT_SYMBOL(__nand_correct_data);
441+
EXPORT_SYMBOL(ecc_sw_hamming_correct);
441442

442443
/**
443-
* nand_correct_data - Detect and correct bit error(s)
444-
* @chip: NAND chip object
444+
* nand_ecc_sw_hamming_correct - Detect and correct bit error(s)
445+
* @nand: NAND device
445446
* @buf: Raw data read from the chip
446447
* @read_ecc: ECC bytes read from the chip
447448
* @calc_ecc: ECC calculated from the raw data
448449
*
449450
* Detect and correct up to 1 bit error per 256/512-byte block.
450451
*/
451-
int nand_correct_data(struct nand_chip *chip, unsigned char *buf,
452-
unsigned char *read_ecc, unsigned char *calc_ecc)
452+
int nand_ecc_sw_hamming_correct(struct nand_device *nand, unsigned char *buf,
453+
unsigned char *read_ecc,
454+
unsigned char *calc_ecc)
453455
{
456+
struct nand_chip *chip = mtd_to_nand(nanddev_to_mtd(nand));
454457
bool sm_order = chip->ecc.options & NAND_ECC_SOFT_HAMMING_SM_ORDER;
455458

456-
return __nand_correct_data(buf, read_ecc, calc_ecc, chip->ecc.size,
457-
sm_order);
459+
return ecc_sw_hamming_correct(buf, read_ecc, calc_ecc, chip->ecc.size,
460+
sm_order);
458461
}
459-
EXPORT_SYMBOL(nand_correct_data);
462+
EXPORT_SYMBOL(nand_ecc_sw_hamming_correct);
460463

461464
MODULE_LICENSE("GPL");
462465
MODULE_AUTHOR("Frans Meulenbroeks <fransmeulenbroeks@gmail.com>");

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/delay.h>
2020
#include <linux/mtd/mtd.h>
2121
#include <linux/mtd/rawnand.h>
22-
#include <linux/mtd/nand-ecc-sw-hamming.h>
2322
#include <linux/mtd/partitions.h>
2423
#include <linux/iopoll.h>
2524

@@ -252,7 +251,7 @@ static int cs553x_attach_chip(struct nand_chip *chip)
252251
chip->ecc.bytes = 3;
253252
chip->ecc.hwctl = cs_enable_hwecc;
254253
chip->ecc.calculate = cs_calculate_ecc;
255-
chip->ecc.correct = nand_correct_data;
254+
chip->ecc.correct = rawnand_sw_hamming_correct;
256255
chip->ecc.strength = 1;
257256

258257
return 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static int fsmc_nand_attach_chip(struct nand_chip *nand)
918918
case NAND_ECC_ENGINE_TYPE_ON_HOST:
919919
dev_info(host->dev, "Using 1-bit HW ECC scheme\n");
920920
nand->ecc.calculate = fsmc_read_hwecc_ecc1;
921-
nand->ecc.correct = nand_correct_data;
921+
nand->ecc.correct = rawnand_sw_hamming_correct;
922922
nand->ecc.hwctl = fsmc_enable_hwecc;
923923
nand->ecc.bytes = 3;
924924
nand->ecc.strength = 1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
803803
chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
804804
chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
805805
chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
806-
chip->ecc.correct = nand_correct_data;
806+
chip->ecc.correct = rawnand_sw_hamming_correct;
807807
chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
808808

809809
/*

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5139,6 +5139,27 @@ static void nand_scan_ident_cleanup(struct nand_chip *chip)
51395139
kfree(chip->parameters.onfi);
51405140
}
51415141

5142+
int rawnand_sw_hamming_calculate(struct nand_chip *chip,
5143+
const unsigned char *buf,
5144+
unsigned char *code)
5145+
{
5146+
struct nand_device *base = &chip->base;
5147+
5148+
return nand_ecc_sw_hamming_calculate(base, buf, code);
5149+
}
5150+
EXPORT_SYMBOL(rawnand_sw_hamming_calculate);
5151+
5152+
int rawnand_sw_hamming_correct(struct nand_chip *chip,
5153+
unsigned char *buf,
5154+
unsigned char *read_ecc,
5155+
unsigned char *calc_ecc)
5156+
{
5157+
struct nand_device *base = &chip->base;
5158+
5159+
return nand_ecc_sw_hamming_correct(base, buf, read_ecc, calc_ecc);
5160+
}
5161+
EXPORT_SYMBOL(rawnand_sw_hamming_correct);
5162+
51425163
int rawnand_sw_bch_init(struct nand_chip *chip)
51435164
{
51445165
struct nand_device *base = &chip->base;
@@ -5263,8 +5284,8 @@ static int nand_set_ecc_soft_ops(struct nand_chip *chip)
52635284

52645285
switch (ecc->algo) {
52655286
case NAND_ECC_ALGO_HAMMING:
5266-
ecc->calculate = nand_calculate_ecc;
5267-
ecc->correct = nand_correct_data;
5287+
ecc->calculate = rawnand_sw_hamming_calculate;
5288+
ecc->correct = rawnand_sw_hamming_correct;
52685289
ecc->read_page = nand_read_page_swecc;
52695290
ecc->read_subpage = nand_read_subpage;
52705291
ecc->write_page = nand_write_page_swecc;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
#include <linux/module.h>
2020
#include <linux/mtd/rawnand.h>
21-
#include <linux/mtd/nand-ecc-sw-hamming.h>
2221
#include <linux/mtd/partitions.h>
2322
#include <linux/mtd/ndfc.h>
2423
#include <linux/slab.h>
@@ -146,7 +145,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
146145
chip->controller = &ndfc->ndfc_control;
147146
chip->legacy.read_buf = ndfc_read_buf;
148147
chip->legacy.write_buf = ndfc_write_buf;
149-
chip->ecc.correct = nand_correct_data;
148+
chip->ecc.correct = rawnand_sw_hamming_correct;
150149
chip->ecc.hwctl = ndfc_enable_hwecc;
151150
chip->ecc.calculate = ndfc_calculate_ecc;
152151
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int sharpsl_attach_chip(struct nand_chip *chip)
107107
chip->ecc.strength = 1;
108108
chip->ecc.hwctl = sharpsl_nand_enable_hwecc;
109109
chip->ecc.calculate = sharpsl_nand_calculate_ecc;
110-
chip->ecc.correct = nand_correct_data;
110+
chip->ecc.correct = rawnand_sw_hamming_correct;
111111

112112
return 0;
113113
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ static int tmio_nand_correct_data(struct nand_chip *chip, unsigned char *buf,
293293
int r0, r1;
294294

295295
/* assume ecc.size = 512 and ecc.bytes = 6 */
296-
r0 = __nand_correct_data(buf, read_ecc, calc_ecc, 256, false);
296+
r0 = rawnand_sw_hamming_correct(chip, buf, read_ecc, calc_ecc);
297297
if (r0 < 0)
298298
return r0;
299-
r1 = __nand_correct_data(buf + 256, read_ecc + 3, calc_ecc + 3, 256,
300-
false);
299+
r1 = rawnand_sw_hamming_correct(chip, buf + 256, read_ecc + 3,
300+
calc_ecc + 3);
301301
if (r1 < 0)
302302
return r1;
303303
return r0 + r1;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ static int txx9ndfmc_correct_data(struct nand_chip *chip, unsigned char *buf,
194194
int stat;
195195

196196
for (eccsize = chip->ecc.size; eccsize > 0; eccsize -= 256) {
197-
stat = __nand_correct_data(buf, read_ecc, calc_ecc, 256,
198-
false);
197+
stat = rawnand_sw_hamming_correct(chip, buf, read_ecc,
198+
calc_ecc);
199199
if (stat < 0)
200200
return stat;
201201
corrected += stat;

‎drivers/mtd/sm_ftl.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,20 +216,19 @@ static void sm_break_offset(struct sm_ftl *ftl, loff_t loffset,
216216

217217
static int sm_correct_sector(uint8_t *buffer, struct sm_oob *oob)
218218
{
219+
bool sm_order = IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC);
219220
uint8_t ecc[3];
220221

221-
__nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc,
222-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
223-
if (__nand_correct_data(buffer, ecc, oob->ecc1, SM_SMALL_PAGE,
224-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0)
222+
ecc_sw_hamming_calculate(buffer, SM_SMALL_PAGE, ecc, sm_order);
223+
if (ecc_sw_hamming_correct(buffer, ecc, oob->ecc1, SM_SMALL_PAGE,
224+
sm_order) < 0)
225225
return -EIO;
226226

227227
buffer += SM_SMALL_PAGE;
228228

229-
__nand_calculate_ecc(buffer, SM_SMALL_PAGE, ecc,
230-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
231-
if (__nand_correct_data(buffer, ecc, oob->ecc2, SM_SMALL_PAGE,
232-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC)) < 0)
229+
ecc_sw_hamming_calculate(buffer, SM_SMALL_PAGE, ecc, sm_order);
230+
if (ecc_sw_hamming_correct(buffer, ecc, oob->ecc2, SM_SMALL_PAGE,
231+
sm_order) < 0)
233232
return -EIO;
234233
return 0;
235234
}
@@ -369,6 +368,7 @@ static int sm_write_block(struct sm_ftl *ftl, uint8_t *buf,
369368
int zone, int block, int lba,
370369
unsigned long invalid_bitmap)
371370
{
371+
bool sm_order = IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC);
372372
struct sm_oob oob;
373373
int boffset;
374374
int retry = 0;
@@ -395,13 +395,13 @@ static int sm_write_block(struct sm_ftl *ftl, uint8_t *buf,
395395
}
396396

397397
if (ftl->smallpagenand) {
398-
__nand_calculate_ecc(buf + boffset, SM_SMALL_PAGE,
399-
oob.ecc1,
400-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
398+
ecc_sw_hamming_calculate(buf + boffset,
399+
SM_SMALL_PAGE, oob.ecc1,
400+
sm_order);
401401

402-
__nand_calculate_ecc(buf + boffset + SM_SMALL_PAGE,
403-
SM_SMALL_PAGE, oob.ecc2,
404-
IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_HAMMING_SMC));
402+
ecc_sw_hamming_calculate(buf + boffset + SM_SMALL_PAGE,
403+
SM_SMALL_PAGE, oob.ecc2,
404+
sm_order);
405405
}
406406
if (!sm_write_sector(ftl, zone, block, boffset,
407407
buf + boffset, &oob))

0 commit comments

Comments
 (0)