mtd: brcmnand: Add check for erased page bitflips
Subsystems (2)
PATCH v2 1/2 mtd: brcmnand: Add check for erased page bitflips
Check for erased page bitflips in a page. And if well within threshold return data as all 0xff. Apply sw check for controller version < 7.2. Controller vesion >= 7.2 has hw support.
---
V2 changes
Added use of nand_check_erased_ecc_chunk
Restrict change to older controller < 7.2
--- drivers/mtd/nand/brcmnand/brcmnand.c | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
drivers/mtd/nand/brcmnand/brcmnand.c +61 -0
@@ -1545,6 +1545,55 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,return ret; } +/* +* Check a page to see if it is erased (w/ bitflips) after an uncorrectable ECC +* error +* +* Because the HW ECC signals an ECC error if an erase paged has even a single +* bitflip, we must check each ECC error to see if it is actually an erased +* page with bitflips, not a truly corrupted page. +* +* On a real error, return a negative error code (-EBADMSG for ECC error), and +* buf will contain raw data. +* Otherwise, buf gets filled with 0xffs and return the maximum number of +* bitflips-per-ECC-sector to the caller. +* +*/ +static int brcmstb_nand_verify_erased_page (struct mtd_info *mtd, +struct nand_chip *chip,void *buf,u64 addr) +{ +int i, sas; +void *oob = chip->oob_poi; +int bitflips =0 ; +int page = addr >> chip->page_shift; +int ret; + +if (!buf) { + buf = chip->buffers->databuf; +/* Invalidate page cache */ + chip->pagebuf =-1 ; + } + + sas = mtd->oobsize / chip->ecc.steps; + +/* read without ecc for verification */ + chip->cmdfunc (mtd,NAND_CMD_READ0 ,0x00 , page); + ret = chip->ecc.read_page_raw (mtd, chip, buf, true, page); +if (ret) +return ret; + +for (i =0 ; i < chip->ecc.steps; i++, oob += sas) { + bitflips =nand_check_erased_ecc_chunk (buf, chip->ecc.size, + oob, sas,NULL ,0 , + chip->ecc.strength); +/* Too many bitflips */ +if (bitflips <0 ) +break ; + } + +return bitflips; +} +static int brcmnand_read (struct mtd_info *mtd,struct nand_chip *chip,u64 addr,unsigned int trans,u32 *buf,u8 *oob) {
@@ -1575,6 +1624,18 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, }if (mtd_is_eccerr (err)) { +/* +* Controller version 7.2 has hw encoder to detect erased page +* bitflips, apply sw verification for older controllers only +*/ +if (ctrl->nand_version <0x0702 ) { + err =brcmstb_nand_verify_erased_page (mtd, chip, buf, + addr); +/* erased page bitflips corrected */ +if (err >0 ) +return err; + } +dev_dbg (ctrl->dev,"uncorrectable error at 0x%llx\n" , (unsigned long long )err_addr); mtd->ecc_stats.failed++;
Signature · 1 line
1.9.1
PATCH v2 2/2 mtd: brcmnand: Detect sticky ucorr ecc error on dma reads
This change provides a fix for controller bug where nand controller could have a possible sticky error after a PIO followed by a DMA read. The fix retries a read if we see a uncorr_ecc after read to detect such sticky errors. The fix applies to only controller version 7.0 and 7.1.
---
V2 Changes
Restrict controller bug workaround to version 7.0 and 7.1
--- drivers/mtd/nand/brcmnand/brcmnand.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/mtd/nand/brcmnand/brcmnand.c +18 -0
@@ -1601,9 +1601,11 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip,struct brcmnand_controller *ctrl = host->ctrl;u64 err_addr =0 ;int err; +static bool retry = true;dev_dbg (ctrl->dev,"read %llx -> %p\n" , (unsigned long long )addr, buf); +try_dmaread:brcmnand_write_reg (ctrl,BRCMNAND_UNCORR_COUNT ,0 );if (has_flash_dma (ctrl) && !oob &&flash_dma_buf_ok (buf)) {
@@ -1625,6 +1627,22 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip,if (mtd_is_eccerr (err)) {/* +* On controller version and 7.0, 7.1 , DMA read after a +* prior PIO read that reported uncorrectable error, +* the DMA engine captures this error following DMA read +* cleared only on subsequent DMA read, so just retry once +* to clear a possible false error reported for current DMA +* read +*/ +if ((ctrl->nand_version ==0x0700 ) || + (ctrl->nand_version ==0x0701 )) { +if (retry) { + retry = false; + goto try_dmaread; + } + } + +/* * Controller version 7.2 has hw encoder to detect erased page * bitflips, apply sw verification for older controllers only */
Signature · 1 line
1.9.1
Quoted 38 lines · On Wed, 8 Jun 2016 17:01:20 -0400 Kamal Dasu <[email protected]> wrote:
Check for erased page bitflips in a page. And if well within threshold return data as all
0xff. Apply sw check for controller version < 7.2. Controller vesion >= 7.2 has hw support.Signed-off-by Kamal Dasu <[email protected]>---
V2 changes
Added use ofnand_check_erased_ecc_chunk
Restrict change to older controller < 7.2--- drivers/mtd/nand/brcmnand/brcmnand.c | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/mtd/nand/brcmnand/brcmnand.c +17
-0@@ -1545,6 +1545,55 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,return ret; } +/* +* Check a page to see if it is erased (w/ bitflips) after an uncorrectable ECC +* error +* +* Because the HW ECC signals an ECC error if an erase paged has even a single +* bitflip, we must check each ECC error to see if it is actually an erased +* page with bitflips, not a truly corrupted page. +* +* On a real error, return a negative error code (-EBADMSG for ECC error), and +* buf will contain raw data. +* Otherwise, buf gets filled with 0xffs and return the maximum number of +* bitflips-per-ECC-sector to the caller. +* +*/ +static int brcmstb_nand_verify_erased_page (struct mtd_info *mtd, +struct nand_chip *chip,void *buf,u64 addr) +{
drivers/mtd/nand/brcmnand/brcmnand.c static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, · line 1574
Quoted 10 lines
drivers/mtd/nand/brcmnand/brcmnand.c +10
-0+int i, sas; +void *oob = chip->oob_poi; +int bitflips =0 ; +int page = addr >> chip->page_shift; +int ret; + +if (!buf) { + buf = chip->buffers->databuf; +/* Invalidate page cache */ + chip->pagebuf =-1 ;
Yes, I know it's ugly.
I'm seriously considering droping the page caching feature, not only because it complicates usage of the databuf buffer, but also because in some cases you might want to really read the same page several times without the cache in the way (for example when you want to check the read-disturb effect by reading over and over a single NAND page).
Actually, I still don't see the usefulness of it, since upper layers (mainly FS layers) are already relying the VFS cache...
Brian, is there any good reason to keep it?
drivers/mtd/nand/brcmnand/brcmnand.c static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, · line 1581
Quoted 7 lines
drivers/mtd/nand/brcmnand/brcmnand.c +7
-0+ } + + sas = mtd->oobsize / chip->ecc.steps; + +/* read without ecc for verification */ + chip->cmdfunc (mtd,NAND_CMD_READ0 ,0x00 , page); + ret = chip->ecc.read_page_raw (mtd, chip, buf, true, page);
Ok, so you have to read the whole page again :(. Are you sure the controller does not leave the data untouched when it sees uncorrectable errors? This way you would only have to read the OOB bytes for the faulty sectors and not the whole page.
The rest looks good to me.
Quoted 37 lines
drivers/mtd/nand/brcmnand/brcmnand.c +27
-0+if (ret) +return ret; + +for (i =0 ; i < chip->ecc.steps; i++, oob += sas) { + bitflips =nand_check_erased_ecc_chunk (buf, chip->ecc.size, + oob, sas,NULL ,0 , + chip->ecc.strength); +/* Too many bitflips */ +if (bitflips <0 ) +break ; + } + +return bitflips; +} +static int brcmnand_read (struct mtd_info *mtd,struct nand_chip *chip,u64 addr,unsigned int trans,u32 *buf,u8 *oob) {@@ -1575,6 +1624,18 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, }if (mtd_is_eccerr (err)) { +/* +* Controller version 7.2 has hw encoder to detect erased page +* bitflips, apply sw verification for older controllers only +*/ +if (ctrl->nand_version <0x0702 ) { + err =brcmstb_nand_verify_erased_page (mtd, chip, buf, + addr); +/* erased page bitflips corrected */ +if (err >0 ) +return err; + } +dev_dbg (ctrl->dev,"uncorrectable error at 0x%llx\n" , (unsigned long long )err_addr); mtd->ecc_stats.failed++;
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Quoted 55 lines · On Wed, 8 Jun 2016 17:01:20 -0400 Kamal Dasu <[email protected]> wrote:
Check for erased page bitflips in a page. And if well within threshold return data as all
0xff. Apply sw check for controller version < 7.2. Controller vesion >= 7.2 has hw support.Signed-off-by Kamal Dasu <[email protected]>---
V2 changes
Added use ofnand_check_erased_ecc_chunk
Restrict change to older controller < 7.2--- drivers/mtd/nand/brcmnand/brcmnand.c | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)drivers/mtd/nand/brcmnand/brcmnand.c +34
-0@@ -1545,6 +1545,55 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,return ret; } +/* +* Check a page to see if it is erased (w/ bitflips) after an uncorrectable ECC +* error +* +* Because the HW ECC signals an ECC error if an erase paged has even a single +* bitflip, we must check each ECC error to see if it is actually an erased +* page with bitflips, not a truly corrupted page. +* +* On a real error, return a negative error code (-EBADMSG for ECC error), and +* buf will contain raw data. +* Otherwise, buf gets filled with 0xffs and return the maximum number of +* bitflips-per-ECC-sector to the caller. +* +*/ +static int brcmstb_nand_verify_erased_page (struct mtd_info *mtd, +struct nand_chip *chip,void *buf,u64 addr) +{ +int i, sas; +void *oob = chip->oob_poi; +int bitflips =0 ; +int page = addr >> chip->page_shift; +int ret; + +if (!buf) { + buf = chip->buffers->databuf; +/* Invalidate page cache */ + chip->pagebuf =-1 ; + } + + sas = mtd->oobsize / chip->ecc.steps; + +/* read without ecc for verification */ + chip->cmdfunc (mtd,NAND_CMD_READ0 ,0x00 , page); + ret = chip->ecc.read_page_raw (mtd, chip, buf, true, page);
drivers/mtd/nand/brcmnand/brcmnand.c static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, · line 1591
Quoted 10 lines
drivers/mtd/nand/brcmnand/brcmnand.c +10
-0+if (ret) +return ret; + +for (i =0 ; i < chip->ecc.steps; i++, oob += sas) { + bitflips =nand_check_erased_ecc_chunk (buf, chip->ecc.size, + oob, sas,NULL ,0 , + chip->ecc.strength); +/* Too many bitflips */ +if (bitflips <0 ) +break ;
Hm, should be
ret = nand_check_erased_ecc_chunk(buf, chip->ecc.size, oob, sas, NULL, 0, chip->ecc.strength); if (ret < 0) return ret; bitflips = max(bitflips, ret);
Quoted 27 lines
drivers/mtd/nand/brcmnand/brcmnand.c +17
-0+ } + +return bitflips; +} +static int brcmnand_read (struct mtd_info *mtd,struct nand_chip *chip,u64 addr,unsigned int trans,u32 *buf,u8 *oob) {@@ -1575,6 +1624,18 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, }if (mtd_is_eccerr (err)) { +/* +* Controller version 7.2 has hw encoder to detect erased page +* bitflips, apply sw verification for older controllers only +*/ +if (ctrl->nand_version <0x0702 ) { + err =brcmstb_nand_verify_erased_page (mtd, chip, buf, + addr); +/* erased page bitflips corrected */ +if (err >0 ) +return err; + } +dev_dbg (ctrl->dev,"uncorrectable error at 0x%llx\n" , (unsigned long long )err_addr); mtd->ecc_stats.failed++;
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Boris,
Quoted 9 lines
drivers/mtd/nand/brcmnand/brcmnand.c static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, · line 1591
Quoted 8 lines
drivers/mtd/nand/brcmnand/brcmnand.c +8
-0+ +for (i =0 ; i < chip->ecc.steps; i++, oob += sas) { + bitflips =nand_check_erased_ecc_chunk (buf, chip->ecc.size, + oob, sas,NULL ,0 , + chip->ecc.strength); +/* Too many bitflips */ +if (bitflips <0 ) +break ;
Quoted 9 lines
Hm, should be
ret = nand_check_erased_ecc_chunk(buf, chip->ecc.size, oob, sas, NULL, 0, chip->ecc.strength); if (ret < 0) return ret; bitflips = max(bitflips, ret);
Sounds reasonable to return max bitflips from a sector within a page instead of the last count. I will make the change accordingly and send a V3 patch.
Thanks
Kamal