public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@st.com>
To: <Artem.Bityutskiy@nokia.com>, <David.Woodhouse@intel.com>,
	<linux-mtd@lists.infradead.org>
Cc: amit.goel@st.com, shiraz.hashim@st.com,
	Viresh Kumar <viresh.kumar@st.com>,
	armando.visconti@st.com, Vipin Kumar <vipin.kumar@st.com>
Subject: [PATCH resend] Newly erased page read workaround
Date: Fri, 1 Apr 2011 15:55:34 +0530	[thread overview]
Message-ID: <1301653534-22223-1-git-send-email-viresh.kumar@st.com> (raw)

From: Vipin Kumar <vipin.kumar@st.com>

A newly erased page contains ff in data as well as spare area. While reading an
erased page, the read out ecc from spare area does not match the ecc generated
by fsmc ecc hardware accelarator. This is because ecc of data ff ff is not ff
ff. This leads to errors when jffs2 fs erases and reads back the pages to
ensure consistency.

This patch adds a software workaround to ensure that the ecc check is not
performed for erased pages. This check is a memory comparison of 512 data bytes
against 0xff. The ecc correction and error reporting algorithm is skipped if the
check passes.
It adds a few extra cycles while reading an erased page but is safer to ensure
that the page is read properly

Signed-off-by: Vipin Kumar <vipin.kumar@st.com>
Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
---
 drivers/mtd/nand/fsmc_nand.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 205b10b..7df270a 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -420,7 +420,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 	struct fsmc_nand_data *host = container_of(mtd,
 					struct fsmc_nand_data, mtd);
 	struct fsmc_eccplace *ecc_place = host->ecc_place;
-	int i, j, s, stat, eccsize = chip->ecc.size;
+	int i, j, k, s, stat, eccsize = chip->ecc.size;
 	int eccbytes = chip->ecc.bytes;
 	int eccsteps = chip->ecc.steps;
 	uint8_t *p = buf;
@@ -460,11 +460,27 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 		memcpy(&ecc_code[i], oob, 13);
 		chip->ecc.calculate(mtd, p, &ecc_calc[i]);
 
-		stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]);
-		if (stat < 0)
-			mtd->ecc_stats.failed++;
-		else
-			mtd->ecc_stats.corrected += stat;
+		/*
+		 * This is a temporary erase check. A newly erased page read
+		 * would result in an ecc error because the oob data is also
+		 * erased to FF and the calculated ecc for an FF data is not
+		 * FF..FF.
+		 * This is a workaround to skip performing correction in case
+		 * data is FF..FF
+		 */
+		for (k = 0; k < eccsize; k++) {
+			if (*(p + k) != 0xff)
+				break;
+		}
+
+		if (k < eccsize) {
+			stat = chip->ecc.correct(mtd, p, &ecc_code[i],
+					&ecc_calc[i]);
+			if (stat < 0)
+				mtd->ecc_stats.failed++;
+			else
+				mtd->ecc_stats.corrected += stat;
+		}
 	}
 
 	return 0;
-- 
1.7.3.4

             reply	other threads:[~2011-04-01 10:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01 10:25 Viresh Kumar [this message]
2011-04-01 11:30 ` [PATCH resend] Newly erased page read workaround Artem Bityutskiy
2011-04-01 11:42   ` Vipin Kumar
2011-04-01 11:44     ` Artem Bityutskiy
2011-04-04  5:45       ` Vipin Kumar
2011-04-04  6:27         ` Artem Bityutskiy
2011-04-04  9:00           ` Vipin Kumar
2011-04-04  9:02             ` Artem Bityutskiy
2011-04-04  9:28               ` Vipin Kumar

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=1301653534-22223-1-git-send-email-viresh.kumar@st.com \
    --to=viresh.kumar@st.com \
    --cc=Artem.Bityutskiy@nokia.com \
    --cc=David.Woodhouse@intel.com \
    --cc=amit.goel@st.com \
    --cc=armando.visconti@st.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=shiraz.hashim@st.com \
    --cc=vipin.kumar@st.com \
    /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