History

mtd: rawnand: Export nand_read_page_hwecc_oob_first()

Move the function nand_read_page_hwecc_oob_first() (previously nand_davinci_read_page_hwecc_oob_first()) to nand_base.c, and export it as a GPL symbol, so that it can be used by more modules.

Paul Cercueil committed 5 years ago

Commit d8466f71 parent 0697f843 files · +70 −68Browse files

Unified · Split

3 files
  1. drivers/mtd/nand/raw/davinci_nand.c +1 −68
  2. drivers/mtd/nand/raw/nand_base.c +67 −0
  3. include/linux/mtd/rawnand.h +2 −0
drivers/mtd/nand/raw/davinci_nand.c+1−68
@@ -371,73 +371,6 @@ correct: · 370 unmodified lines
371371 return corrected;
372372 }
373373
374−/**
375− * nand_davinci_read_page_hwecc_oob_first - Hardware ECC page read with ECC
376− * data read from OOB area
377− * @chip: nand chip info structure
378− * @buf: buffer to store read data
379− * @oob_required: caller requires OOB data read to chip->oob_poi
380− * @page: page number to read
381− *
382− * Hardware ECC for large page chips, which requires the ECC data to be
383− * extracted from the OOB before the actual data is read.
384− */
385−static int nand_davinci_read_page_hwecc_oob_first(struct nand_chip *chip,
386− uint8_t *buf,
387− int oob_required, int page)
388−{
389− struct mtd_info *mtd = nand_to_mtd(chip);
390− int i, eccsize = chip->ecc.size, ret;
391− int eccbytes = chip->ecc.bytes;
392− int eccsteps = chip->ecc.steps;
393− uint8_t *p = buf;
394− uint8_t *ecc_code = chip->ecc.code_buf;
395− unsigned int max_bitflips = 0;
396−
397− /* Read the OOB area first */
398− ret = nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize);
399− if (ret)
400− return ret;
401−
402− /* Move read cursor to start of page */
403− ret = nand_change_read_column_op(chip, 0, NULL, 0, false);
404− if (ret)
405− return ret;
406−
407− ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
408− chip->ecc.total);
409− if (ret)
410− return ret;
411−
412− for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
413− int stat;
414−
415− chip->ecc.hwctl(chip, NAND_ECC_READ);
416−
417− ret = nand_read_data_op(chip, p, eccsize, false, false);
418− if (ret)
419− return ret;
420−
421− stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL);
422− if (stat == -EBADMSG &&
423− (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
424− /* check for empty pages with bitflips */
425− stat = nand_check_erased_ecc_chunk(p, eccsize,
426− &ecc_code[i],
427− eccbytes, NULL, 0,
428− chip->ecc.strength);
429− }
430−
431− if (stat < 0) {
432− mtd->ecc_stats.failed++;
433− } else {
434− mtd->ecc_stats.corrected += stat;
435− max_bitflips = max_t(unsigned int, max_bitflips, stat);
436− }
437− }
438− return max_bitflips;
439−}
440−
441374 /*----------------------------------------------------------------------*/
442375
443376 /* An ECC layout for using 4-bit ECC with small-page flash, storing
@@ -647,7 +580,7 @@ static int davinci_nand_attach_chip(struct nand_chip *chip) · 203 unmodified lines
647580 } else if (chunks == 4 || chunks == 8) {
648581 mtd_set_ooblayout(mtd,
649582 nand_get_large_page_ooblayout());
650− chip->ecc.read_page = nand_davinci_read_page_hwecc_oob_first;
583+ chip->ecc.read_page = nand_read_page_hwecc_oob_first;
651584 } else {
652585 return -EIO;
653586 }
drivers/mtd/nand/raw/nand_base.c+67−0
@@ -3160,6 +3160,73 @@ static int nand_read_page_hwecc(struct nand_chip *chip, uint8_t *buf, · 3159 unmodified lines
31603160 return max_bitflips;
31613161 }
31623162
3163+/**
3164+ * nand_read_page_hwecc_oob_first - Hardware ECC page read with ECC
3165+ * data read from OOB area
3166+ * @chip: nand chip info structure
3167+ * @buf: buffer to store read data
3168+ * @oob_required: caller requires OOB data read to chip->oob_poi
3169+ * @page: page number to read
3170+ *
3171+ * Hardware ECC for large page chips, which requires the ECC data to be
3172+ * extracted from the OOB before the actual data is read.
3173+ */
3174+int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf,
3175+ int oob_required, int page)
3176+{
3177+ struct mtd_info *mtd = nand_to_mtd(chip);
3178+ int i, eccsize = chip->ecc.size, ret;
3179+ int eccbytes = chip->ecc.bytes;
3180+ int eccsteps = chip->ecc.steps;
3181+ uint8_t *p = buf;
3182+ uint8_t *ecc_code = chip->ecc.code_buf;
3183+ unsigned int max_bitflips = 0;
3184+
3185+ /* Read the OOB area first */
3186+ ret = nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize);
3187+ if (ret)
3188+ return ret;
3189+
3190+ /* Move read cursor to start of page */
3191+ ret = nand_change_read_column_op(chip, 0, NULL, 0, false);
3192+ if (ret)
3193+ return ret;
3194+
3195+ ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0,
3196+ chip->ecc.total);
3197+ if (ret)
3198+ return ret;
3199+
3200+ for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
3201+ int stat;
3202+
3203+ chip->ecc.hwctl(chip, NAND_ECC_READ);
3204+
3205+ ret = nand_read_data_op(chip, p, eccsize, false, false);
3206+ if (ret)
3207+ return ret;
3208+
3209+ stat = chip->ecc.correct(chip, p, &ecc_code[i], NULL);
3210+ if (stat == -EBADMSG &&
3211+ (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) {
3212+ /* check for empty pages with bitflips */
3213+ stat = nand_check_erased_ecc_chunk(p, eccsize,
3214+ &ecc_code[i],
3215+ eccbytes, NULL, 0,
3216+ chip->ecc.strength);
3217+ }
3218+
3219+ if (stat < 0) {
3220+ mtd->ecc_stats.failed++;
3221+ } else {
3222+ mtd->ecc_stats.corrected += stat;
3223+ max_bitflips = max_t(unsigned int, max_bitflips, stat);
3224+ }
3225+ }
3226+ return max_bitflips;
3227+}
3228+EXPORT_SYMBOL_GPL(nand_read_page_hwecc_oob_first);
3229+
31633230 /**
31643231 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
31653232 * @chip: nand chip info structure
include/linux/mtd/rawnand.h+2−0
@@ -1539,6 +1539,8 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len, · 1538 unmodified lines
15391539 bool force_8bit, bool check_only);
15401540 int nand_write_data_op(struct nand_chip *chip, const void *buf,
15411541 unsigned int len, bool force_8bit);
1542+int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf,
1543+ int oob_required, int page);
15421544
15431545 /* Scan and identify a NAND device */
15441546 int nand_scan_with_ids(struct nand_chip *chip, unsigned int max_chips,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t