All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brian Norris" <computersforpeace@gmail.com>
To: "Artem Bityutskiy" <dedekind1@gmail.com>
Cc: Kevin Cernekee <cernekee@gmail.com>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org,
	David Woodhouse <dwmw2@infradead.org>,
	Matthieu Castet <matthieu.castet@parrot.com>
Subject: [PATCH v2 11/14] mtd: nand: wait to set BBT version
Date: Tue, 20 Sep 2011 18:35:57 -0700	[thread overview]
Message-ID: <1316568957-21625-1-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1315426421-16243-12-git-send-email-computersforpeace@gmail.com>

Because there are so many cases of checking, writing, and re-writing of
the bad block table(s), we might as well wait until the we've settled on
a valid, clean copy of the table. This also prevents us from falsely
incrementing the table version. For example, we may have the following:

  Primary table, with version 0x02
  Mirror table, with version 0x01
  Primary table has uncorrectable ECC errors

If we don't have this fix applied, then we will:

  Choose to read the primary table (higher version)
  Set mirror table version to 0x02
  Read back primary table
  Invalidate table because of ECC errors
  Retry readback operation with mirror table, now version 0x02
  Mirrored table reads cleanly
  Writeback BBT to primary table location (with "version 0x02")

However, the mirrored table shouldn't have a new version number.
Instead, we actually want:

  Choose to read the primary table (higher version)
  Read back primary table
  Invalidate table because of ECC errors
  Retry readback with mirror table (version 0x01)
  Mirrored table reads cleanly
  Set both tables to version 0x01
  Writeback BBT to primary table location (version 0x01)

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
v2: change to `mtd_is_*' prefix

 drivers/mtd/nand/nand_bbt.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index 11185aa..e7976c7 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -909,11 +909,9 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
 				writeops = 0x03;
 			} else if (td->pages[i] == -1) {
 				rd = md;
-				td->version[i] = md->version[i];
 				writeops = 0x01;
 			} else if (md->pages[i] == -1) {
 				rd = td;
-				md->version[i] = td->version[i];
 				writeops = 0x02;
 			} else if (td->version[i] == md->version[i]) {
 				rd = td;
@@ -921,11 +919,9 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
 					rd2 = md;
 			} else if (((int8_t)(td->version[i] - md->version[i])) > 0) {
 				rd = td;
-				md->version[i] = td->version[i];
 				writeops = 0x02;
 			} else {
 				rd = md;
-				td->version[i] = md->version[i];
 				writeops = 0x01;
 			}
 		} else {
@@ -957,6 +953,7 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
 			if (mtd_is_eccerr(res)) {
 				/* Mark table as invalid */
 				rd->pages[i] = -1;
+				rd->version[i] = 0;
 				i--;
 				continue;
 			}
@@ -967,6 +964,7 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
 			if (mtd_is_eccerr(res2)) {
 				/* Mark table as invalid */
 				rd2->pages[i] = -1;
+				rd2->version[i] = 0;
 				i--;
 				continue;
 			}
@@ -976,6 +974,12 @@ static int check_create(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_desc
 		if (mtd_is_bitflip(res) || mtd_is_bitflip(res2))
 			writeops = 0x03;
 
+		/* Update version numbers before writing */
+		if (md) {
+			td->version[i] = max(td->version[i], md->version[i]);
+			md->version[i] = td->version[i];
+		}
+
 		/* Write the bad block table to the device? */
 		if ((writeops & 0x01) && (td->options & NAND_BBT_WRITE)) {
 			res = write_bbt(mtd, buf, td, md, chipsel);
-- 
1.7.5.4

  reply	other threads:[~2011-09-21  1:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-07 20:13 [PATCH 00/14] mtd: nand: improve flash-based BBT robustness Brian Norris
2011-09-07 20:13 ` [PATCH 01/14] mtd: nand: refactor scanning code Brian Norris
2011-09-11 13:58   ` Artem Bityutskiy
2011-09-07 20:13 ` [PATCH 02/14] mtd: nand: do not ignore all ECC errors Brian Norris
2011-09-11 13:58   ` Artem Bityutskiy
2011-09-07 20:13 ` [PATCH 03/14] mtd: define `is_ecc_error()' macros Brian Norris
2011-09-11 13:57   ` Artem Bityutskiy
2011-09-19  4:14     ` Artem Bityutskiy
2011-09-19 18:43       ` Brian Norris
2011-09-20  7:19         ` Artem Bityutskiy
2011-09-21  1:30           ` [PATCH v2 03/14] mtd: define `mtd_is_*()' functions Brian Norris
2011-09-21  1:40           ` [PATCH 03/14] mtd: define `is_ecc_error()' macros Brian Norris
2011-09-21  6:24             ` Artem Bityutskiy
2011-09-07 20:13 ` [PATCH 04/14] mtd: utilize " Brian Norris
2011-09-21  1:34   ` [PATCH v2 04/14] mtd: utilize `mtd_is_*()' functions Brian Norris
2011-09-07 20:13 ` [PATCH 05/14] mtd: nand: remove unnecessary variable Brian Norris
2011-09-11 13:58   ` Artem Bityutskiy
2011-09-07 20:13 ` [PATCH 06/14] mtd: nand: fix style Brian Norris
2011-09-11 14:00   ` Artem Bityutskiy
2011-09-07 20:13 ` [PATCH 07/14] mtd: nand: begin restructuring check_create Brian Norris
2011-09-07 20:13 ` [PATCH 08/14] mtd: nand: remove gotos in `check_create()' Brian Norris
2011-09-07 20:13 ` [PATCH 09/14] mtd: nand: report ECC errors properly when reading BBT Brian Norris
2011-09-21  1:35   ` [PATCH v2 " Brian Norris
2011-09-07 20:13 ` [PATCH 10/14] mtd: nand: scrub BBT on ECC errors Brian Norris
2011-09-21  1:35   ` [PATCH v2 " Brian Norris
2011-09-07 20:13 ` [PATCH 11/14] mtd: nand: wait to set BBT version Brian Norris
2011-09-21  1:35   ` Brian Norris [this message]
2011-09-07 20:13 ` [PATCH 12/14] mtd: nand: do not scan bad blocks with NAND_BBT_NO_OOB set Brian Norris
2011-09-21  1:36   ` [PATCH v2 " Brian Norris
2011-09-07 20:13 ` [PATCH 13/14] mtd: nand: invalidate cache on unaligned reads Brian Norris
2011-09-07 20:13 ` [PATCH 14/14] mtd: nand: switch `check_pattern()' to standard `memcmp()' Brian Norris

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=1316568957-21625-1-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=cernekee@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=matthieu.castet@parrot.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.