From: Kamal Dasu <kdasu.kdev@gmail.com>
To: linux-mtd@lists.infradead.org, computersforpeace@gmail.com
Cc: f.fainelli@gmail.com, bcm-kernel-feedback-list@broadcom.com,
Kamal Dasu <kdasu.kdev@gmail.com>
Subject: [PATCH 1/2] mtd: brcmnand: Add check for erased page bitflips
Date: Fri, 29 Apr 2016 16:21:24 -0400 [thread overview]
Message-ID: <1461961285-24159-1-git-send-email-kdasu.kdev@gmail.com> (raw)
Check for erased page bitflips in a page. And if well within
threshold return data as all 0xff.
Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
drivers/mtd/nand/brcmnand/brcmnand.c | 83 +++++++++++++++++++++++++++++++++---
1 file changed, 78 insertions(+), 5 deletions(-)
diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c b/drivers/mtd/nand/brcmnand/brcmnand.c
index e052839..29a9abd 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1490,6 +1490,64 @@ 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, fill buf with 0xff 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, oob_nbits, data_nbits;
+ void *oob = chip->oob_poi;
+ unsigned int max_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;
+ oob_nbits = sas << 3;
+ data_nbits = chip->ecc.size << 3;
+
+ /* 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) {
+ unsigned int bitflips = 0;
+
+ bitflips += oob_nbits - bitmap_weight(oob, oob_nbits);
+ bitflips += data_nbits - bitmap_weight(buf, data_nbits);
+
+ buf += chip->ecc.size;
+ addr += chip->ecc.size;
+
+ /* Too many bitflips */
+ if (bitflips > chip->ecc.strength)
+ return -EBADMSG;
+
+ max_bitflips = max(max_bitflips, bitflips);
+ }
+
+ return max_bitflips;
+}
+
static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip,
u64 addr, unsigned int trans, u32 *buf, u8 *oob)
{
@@ -1520,11 +1578,26 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip,
}
if (mtd_is_eccerr(err)) {
- dev_dbg(ctrl->dev, "uncorrectable error at 0x%llx\n",
- (unsigned long long)err_addr);
- mtd->ecc_stats.failed++;
- /* NAND layer expects zero on ECC errors */
- return 0;
+ int ret;
+
+ ret = brcmstb_nand_verify_erased_page(mtd, chip, buf, addr);
+ if (ret < 0) {
+ dev_dbg(ctrl->dev, "uncorrectable error at 0x%llx\n",
+ (unsigned long long)err_addr);
+ mtd->ecc_stats.failed++;
+ /* NAND layer expects zero on ECC errors */
+ return 0;
+ } else {
+ if (buf)
+ memset(buf, 0xff, FC_BYTES * trans);
+ if (oob)
+ memset(oob, 0xff, mtd->oobsize);
+
+ dev_info(&host->pdev->dev,
+ "corrected %d bitflips in blank page at 0x%llx\n",
+ ret, (unsigned long long)addr);
+ return ret;
+ }
}
if (mtd_is_bitflip(err)) {
--
1.9.1
next reply other threads:[~2016-04-29 20:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-29 20:21 Kamal Dasu [this message]
2016-04-29 20:21 ` [PATCH 2/2] mtd: brcmnand: Detect sticky ucorr ecc error on dma reads Kamal Dasu
2016-05-30 8:50 ` Boris Brezillon
2016-06-01 16:50 ` Kamal Dasu
2016-06-01 17:20 ` Boris Brezillon
2016-06-01 20:37 ` Boris Brezillon
2016-06-02 18:55 ` Kamal Dasu
2016-05-30 8:42 ` [PATCH 1/2] mtd: brcmnand: Add check for erased page bitflips Boris Brezillon
2016-06-01 16:46 ` Kamal Dasu
2016-06-01 17:14 ` Brian Norris
2016-06-01 17:22 ` Boris Brezillon
2016-06-01 17:27 ` Kamal Dasu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1461961285-24159-1-git-send-email-kdasu.kdev@gmail.com \
--to=kdasu.kdev@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=computersforpeace@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).