Skip to contentSkip to conversation

mtd: gpmi: Bitflip support in erased regions

PATCH New Elie De Brauwer 2 participants 3 messages Dec 17, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mtd: gpmi: Bitflip support in erased regions

Hello All,

This is v3 of my patch which adds support for bitflip detection/correction in erased regions when using BCH/GPMI nand.

Changes in V3:
- The fast path in V2 was not entered (my bad, I mixed some boards when
testing) due to using a faulty register offset. The fast path implemention for correctly reading fully erased blocks is now functional (and properly tested).
- Also the fast path even become a bit faster since we now break out of
the for loop as soon as we see a properly erased block (instead of briefly touching all sectors).
- The ERASE_THRESHOLD aka the number of bitflips in erased regions we
tolerate is no longer set to ecc_strength but to gf_len/2.
- Several cosmetic changes.

Main credit to the above goes to Huang Shijie, thanks a lot !

Further comments/feedback welcome, but at this point I don't see any other open points.

E.

Elie De Brauwer (1):
mtd: gpmi: Deal with bitflips in erased regions regions

 drivers/mtd/nand/gpmi-nand/bch-regs.h  |    2 ++
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c  |   16 ++++++++++++
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   44 +++++++++++++++++++++++++++++---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h |    1 +
 4 files changed, 60 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/1 mtd: gpmi: Deal with bitflips in erased regions regions

The BCH block typically used with a GPMI block on an i.MX28/i.MX6 is only able to correct bitflips on data actually streamed through the block. When erasing a block the data does not stream through the BCH block and therefore no ECC data is written to the NAND chip. This causes gpmi_ecc_read_page to return failure as soon as a single non-1-bit is found in an erased page. Typically causing problems at higher levels (ubifs corrupted empty space warnings). This problem was also observed when using SLC NAND devices.

This patch configures the BCH block to mark a block as 'erased' if no more than gf_len/2 bitflips are found. Next HW_BCH_STATUS0:ALLONES is used to check if the data read were all ones, indicating a read of a properly erased chunk was performed. If this was not the case a slow path is entered where bitflips are counted and corrected in software, allowing the upper layers to take proper actions.

---
 drivers/mtd/nand/gpmi-nand/bch-regs.h  |    2 ++
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c  |   16 ++++++++++++
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   44 +++++++++++++++++++++++++++++---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h |    1 +
 4 files changed, 60 insertions(+), 3 deletions(-)
drivers/mtd/nand/gpmi-nand/bch-regs.h +2 -0
index 588f537..a30502f 100644
@@ -30,7 +30,9 @@
 #define BM_BCH_CTRL_COMPLETE_IRQ		(1 << 0)
 
 #define HW_BCH_STATUS0				0x00000010
+#define BM_BCH_STATUS0_ALLONES_MASK		(1 << 4)
 #define HW_BCH_MODE				0x00000020
+#define BM_BCH_MODE_ERASE_THRESHOLD_MASK	0xff
 #define HW_BCH_ENCODEPTR			0x00000030
 #define HW_BCH_DATAPTR				0x00000040
 #define HW_BCH_METAPTR				0x00000050
drivers/mtd/nand/gpmi-nand/gpmi-lib.c +16 -0
index aaced29..86b9126 100644
@@ -286,6 +286,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
 			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
 
+	/*
+	 * Set the tolerance for bitflips when reading erased blocks
+	 * equal to half the gf_len.
+	 */
+	writel((gf_len/2) & BM_BCH_MODE_ERASE_THRESHOLD_MASK,
+		r->bch_regs + HW_BCH_MODE);
+
 	/* Set *all* chip selects to use layout 0. */
 	writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT);
 
@@ -1094,6 +1101,15 @@ int gpmi_is_ready(struct gpmi_nand_data *this, unsigned chip)
 	return reg & mask;
 }
 
+/* Returns 1 if the last transaction consisted only out of ones. */
+int gpmi_allones(struct gpmi_nand_data *this)
+{
+	struct resources *r = &this->resources;
+	uint32_t reg = readl(r->bch_regs + HW_BCH_STATUS0);
+
+	return reg & BM_BCH_STATUS0_ALLONES_MASK;
+}
+
 static inline void set_dma_type(struct gpmi_nand_data *this,
 					enum dma_ops_type type)
 {
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +41 -3

68 lines not on this page · raw message

drivers/mtd/nand/gpmi-nand/gpmi-nand.h +1 -0
index a7685e3..4ddd6af 100644
@@ -268,6 +268,7 @@ extern void gpmi_clear_bch(struct gpmi_nand_data *);
 extern void gpmi_dump_info(struct gpmi_nand_data *);
 extern int bch_set_geometry(struct gpmi_nand_data *);
 extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
+extern int gpmi_allones(struct gpmi_nand_data *);
 extern int gpmi_send_command(struct gpmi_nand_data *);
 extern void gpmi_begin(struct gpmi_nand_data *);
 extern void gpmi_end(struct gpmi_nand_data *);
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH v3] mtd: gpmi: Deal with bitflips in erased regions regions

Quoted 44 lines · Elie De Brauwer

The BCH block typically used with a GPMI block on an i.MX28/i.MX6 is only able to correct bitflips on data actually streamed through the block. When erasing a block the data does not stream through the BCH block and therefore no ECC data is written to the NAND chip. This causes gpmi_ecc_read_page to return failure as soon as a single non-1-bit is found in an erased page. Typically causing problems at higher levels (ubifs corrupted empty space warnings). This problem was also observed when using SLC NAND devices.

This patch configures the BCH block to mark a block as 'erased' if no more than gf_len/2 bitflips are found. Next HW_BCH_STATUS0:ALLONES is used to check if the data read were all ones, indicating a read of a properly erased chunk was performed. If this was not the case a slow path is entered where bitflips are counted and corrected in software, allowing the upper layers to take proper actions.

---
 drivers/mtd/nand/gpmi-nand/bch-regs.h  |    2 ++
 drivers/mtd/nand/gpmi-nand/gpmi-lib.c  |   16 ++++++++++++
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |   44 +++++++++++++++++++++++++++++---
 drivers/mtd/nand/gpmi-nand/gpmi-nand.h |    1 +
 4 files changed, 60 insertions(+), 3 deletions(-)
drivers/mtd/nand/gpmi-nand/bch-regs.h +2 -0
index 588f537..a30502f 100644
@@ -30,7 +30,9 @@
 #define BM_BCH_CTRL_COMPLETE_IRQ		(1 << 0)
 
 #define HW_BCH_STATUS0				0x00000010
+#define BM_BCH_STATUS0_ALLONES_MASK		(1 << 4)
 #define HW_BCH_MODE				0x00000020
+#define BM_BCH_MODE_ERASE_THRESHOLD_MASK	0xff
 #define HW_BCH_ENCODEPTR			0x00000030
 #define HW_BCH_DATAPTR				0x00000040
 #define HW_BCH_METAPTR				0x00000050
drivers/mtd/nand/gpmi-nand/gpmi-lib.c +0 -0
index aaced29..86b9126 100644

drivers/mtd/nand/gpmi-nand/gpmi-lib.c int bch_set_geometry(struct gpmi_nand_data *this) · line 293

Quoted 8 lines
drivers/mtd/nand/gpmi-nand/gpmi-lib.c +5 -0
@@ -286,6 +286,13 @@ int bch_set_geometry(struct gpmi_nand_data *this)
 			| BF_BCH_FLASH0LAYOUT1_DATAN_SIZE(block_size, this),
 			r->bch_regs + HW_BCH_FLASH0LAYOUT1);
 
+	/*
+	 * Set the tolerance for bitflips when reading erased blocks
+	 * equal to half the gf_len.
+	 */
+	writel((gf_len/2) & BM_BCH_MODE_ERASE_THRESHOLD_MASK,

Please code it like this:
writel((gf_len / 2) & BM_BCH_MODE_ERASE_THRESHOLD_MASK,

Since the name gpmi_allones is complained by Brain, you have to send a v4 version.

thanks
Huang Shijie