Skip to contentSkip to conversation

mtd: nand: OMAP: ELM error correction support for BCH ecc

PATCH Superseded Philip, Avinash 2 participants 14 messages Oct 31, 2012 – Dec 4, 2012

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover mtd: nand: OMAP: ELM error correction support for BCH ecc

Support to use ELM as BCH 4 & 8 bit error correction module. Also performance enhancement by adding single shot read_page and write_page functions for the nand flashes with page size less than 4 KB.

ELM module can be used to correct errors reported by BCH 4, 8 & 16 bit ECC scheme. For now only 4 & 8 bit support is added.

BCH 4 & 8 bit error detection support is already available in mainline kernel and works with software error correction.

This series is based on [1] and tested with RFC: OMAP GPMC bindings patch series

1. linux-next/20121030

Changes since v1:
- Erased page is identified by checking byte [13/7] in read ecc. To filter out bit flips in OOB area, check 0 bits in the byte greater than 4.
- GPMC ecc engine configuration moves to omap2.c NAND driver.

Philip, Avinash (3):
mtd: nand: omap2: Update nerrors using ecc.strength
mtd: devices: elm: Add support for ELM error correction
mtd: nand: omap2: Support for hardware BCH error correction

 Documentation/devicetree/bindings/mtd/elm.txt |   18 +
 drivers/mtd/devices/Makefile                  |    4 +-
 drivers/mtd/devices/elm.c                     |  420 +++++++++++++++++++
 drivers/mtd/nand/omap2.c                      |  542 +++++++++++++++++++++++--
 include/linux/platform_data/elm.h             |   54 +++
 include/linux/platform_data/mtd-nand-omap2.h  |    1 +
 6 files changed, 997 insertions(+), 42 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/elm.txt
 create mode 100644 drivers/mtd/devices/elm.c
 create mode 100644 include/linux/platform_data/elm.h
#1 lore raw

PATCH v2 1/3 mtd: nand: omap2: Update nerrors using ecc.strength

Update number of errors using nand ecc strength. Also add macro definitions BCH8_ERROR_MAX & BCH4_ERROR_MAX

---
:100644 100644 5c8978e... a02be29... M drivers/mtd/nand/omap2.c

 drivers/mtd/nand/omap2.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/mtd/nand/omap2.c +8 -4
index 5c8978e..a02be29 100644
@@ -118,6 +118,9 @@
 
 #define OMAP24XX_DMA_GPMC		4
 
+#define BCH8_MAX_ERROR		8	/* upto 8 bit correctable */
+#define BCH4_MAX_ERROR		4	/* upto 4 bit correctable */
+
 /* oob info generated runtime depending on ecc algorithm and layout selected */
 static struct nand_ecclayout omap_oobinfo;
 /* Define some generic bad / good block scan pattern which are used
@@ -1042,7 +1045,7 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
 	struct nand_chip *chip = mtd->priv;
 	u32 val;
 
-	nerrors = (info->nand.ecc.bytes == 13) ? 8 : 4;
+	nerrors = info->nand.ecc.strength;
 	dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
 	nsectors = 1;
 	/*
@@ -1219,13 +1222,14 @@ static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
 	struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
 						   mtd);
 #ifdef CONFIG_MTD_NAND_OMAP_BCH8
-	const int hw_errors = 8;
+	const int hw_errors = BCH8_MAX_ERROR;
 #else
-	const int hw_errors = 4;
+	const int hw_errors = BCH4_MAX_ERROR;
 #endif
 	info->bch = NULL;
 
-	max_errors = (ecc_opt == OMAP_ECC_BCH8_CODE_HW) ? 8 : 4;
+	max_errors = (ecc_opt == OMAP_ECC_BCH8_CODE_HW) ?
+		BCH8_MAX_ERROR : BCH4_MAX_ERROR;
 	if (max_errors != hw_errors) {
 		pr_err("cannot configure %d-bit BCH ecc, only %d-bit supported",
 		       max_errors, hw_errors);
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v2 2/3 mtd: devices: elm: Add support for ELM error correction

In reply to Philip, Avinash

The ELM hardware module can be used to speedup BCH 4/8/16 ECC scheme error correction.
For now only 4 & 8 bit support is added

Cc Grant Likely <[email protected]>
Cc Rob Herring <[email protected]>
Cc Rob Landley <[email protected]>

---
Changes since v1:
- change build attribute to CONFIG_MTD_NAND_OMAP_BCH
- Reduced indentation using by passing elm_info , offset to elm_read & elm_write
- Removed syndrome manipulation functions.

:000000 100644 0000000... b88ee83... A Documentation/devicetree/bindings/mtd/elm.txt
:100644 100644 395733a... 369a194... M drivers/mtd/devices/Makefile
:000000 100644 0000000... bb36018... A drivers/mtd/devices/elm.c
:000000 100644 0000000... d4fce31... A include/linux/platform_data/elm.h

 Documentation/devicetree/bindings/mtd/elm.txt |   18 +
 drivers/mtd/devices/Makefile                  |    4 +-
 drivers/mtd/devices/elm.c                     |  418 +++++++++++++++++++++++++
 include/linux/platform_data/elm.h             |   54 ++++
 4 files changed, 493 insertions(+), 1 deletions(-)
Documentation/devicetree/bindings/mtd/elm.txt new file +18 -0
new file mode 100644
index 0000000..b88ee83
@@ -0,0 +1,18 @@
+Error location module
+
+Required properties:
+- compatible: Must be "ti,elm"
+- reg: physical base address and size of the registers map.
+- interrupts: Interrupt number for the elm.
+- interrupt-parent: The parent interrupt controller
+
+Optional properties:
+- ti,hwmods: Name of the hwmod associated to the elm
+
+Example:
+elm: elm@0 {
+	compatible	= "ti,elm";
+	reg = <0x48080000 0x2000>;
+	interrupt-parent = <&intc>;
+	interrupts = <4>;
+};
drivers/mtd/devices/Makefile +3 -1
index 395733a..369a194 100644
@@ -17,8 +17,10 @@ obj-$(CONFIG_MTD_LART)		+= lart.o
 obj-$(CONFIG_MTD_BLOCK2MTD)	+= block2mtd.o
 obj-$(CONFIG_MTD_DATAFLASH)	+= mtd_dataflash.o
 obj-$(CONFIG_MTD_M25P80)	+= m25p80.o
+obj-$(CONFIG_MTD_NAND_OMAP_BCH)	+= elm.o
 obj-$(CONFIG_MTD_SPEAR_SMI)	+= spear_smi.o
 obj-$(CONFIG_MTD_SST25L)	+= sst25l.o
 obj-$(CONFIG_MTD_BCM47XXSFLASH)	+= bcm47xxsflash.o
 
-CFLAGS_docg3.o			+= -I$(src)
\ No newline at end of file
+
+CFLAGS_docg3.o			+= -I$(src)
drivers/mtd/devices/elm.c new file +418 -0

418 lines not on this page · raw message

include/linux/platform_data/elm.h new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#3 lore raw

PATCH v2 3/3 mtd: nand: omap2: Support for hardware BCH error correction

In reply to Philip, Avinash

ELM module can be used for hardware error correction of BCH 4 & 8 bit. Also support read & write page in one shot by adding custom read_page & write_page methods. This helps in optimizing code for NAND flashes with page size less than 4 KB.

New structure member "is_elm_used" is added to know the status of whether the ELM module is used for error correction or not.

Note:
ECC layout uses 1 extra bytes for 512 byte of data to handle erased pages. Extra byte programmed to zero for programmed pages. Also BCH8 requires 14 byte ecc to maintain compatibility with RBL ECC layout. This results a common ecc layout across RBL, U-boot & Linux with BCH8.

---
Changes since v1:
- Incorporated GPMC modification to nand driver
- Erased page detects by checking OOB byte at fixed offset.

:100644 100644 a02be29... 89bddc4... M drivers/mtd/nand/omap2.c
:100644 100644 d4fce31... b732089... M include/linux/platform_data/elm.h
:100644 100644 24d32ca... db8c68b... M include/linux/platform_data/mtd-nand-omap2.h

 drivers/mtd/nand/omap2.c                     |  532 ++++++++++++++++++++++++--
 include/linux/platform_data/elm.h            |    2 +-
 include/linux/platform_data/mtd-nand-omap2.h |    1 +
 3 files changed, 496 insertions(+), 39 deletions(-)
drivers/mtd/nand/omap2.c +494 -38
index a02be29..89bddc4 100644
@@ -25,6 +25,7 @@
 
 #ifdef CONFIG_MTD_NAND_OMAP_BCH
 #include <linux/bch.h>
+#include <linux/platform_data/elm.h>
 #endif
 
 #include <plat-omap/dma-omap.h>
@@ -121,6 +122,30 @@
 #define BCH8_MAX_ERROR		8	/* upto 8 bit correctable */
 #define BCH4_MAX_ERROR		4	/* upto 4 bit correctable */
 
+#define SECTOR_BYTES		512
+/* 4 bit padding to make byte aligned, 56 = 52 + 4 */
+#define BCH4_BIT_PAD		4
+#define BCH8_ECC_MAX		((SECTOR_BYTES + BCH8_ECC_OOB_BYTES) * 8)
+#define BCH4_ECC_MAX		((SECTOR_BYTES + BCH4_ECC_OOB_BYTES) * 8)
+
+/* GPMC ecc engine settings for read */
+#define BCH_WRAPMODE_1		1	/* BCH wrap mode 1 */
+#define BCH8R_ECC_SIZE0		0x1a	/* ecc_size0 = 26 */
+#define BCH8R_ECC_SIZE1		0x2	/* ecc_size1 = 2 */
+#define BCH4R_ECC_SIZE0		0xd	/* ecc_size0 = 13 */
+#define BCH4R_ECC_SIZE1		0x3	/* ecc_size1 = 3 */
+
+/* GPMC ecc engine settings for write */
+#define BCH_WRAPMODE_6		6	/* BCH wrap mode 6 */
+#define BCH_ECC_SIZE0		0x0	/* ecc_size0 = 0, no oob protection */
+#define BCH_ECC_SIZE1		0x20	/* ecc_size1 = 32 */
+
+#ifdef CONFIG_MTD_NAND_OMAP_BCH
+static u_char bch8_vector[] = {0xf3, 0xdb, 0x14, 0x16, 0x8b, 0xd2, 0xbe, 0xcc,
+	0xac, 0x6b, 0xff, 0x99, 0x7b};
+static u_char bch4_vector[] = {0x00, 0x6b, 0x31, 0xdd, 0x41, 0xbc, 0x10};
+#endif
+
 /* oob info generated runtime depending on ecc algorithm and layout selected */
 static struct nand_ecclayout omap_oobinfo;
 /* Define some generic bad / good block scan pattern which are used
@@ -160,6 +185,8 @@ struct omap_nand_info {
 #ifdef CONFIG_MTD_NAND_OMAP_BCH
 	struct bch_control             *bch;
 	struct nand_ecclayout           ecclayout;
+	bool				is_elm_used;
+	struct device			*elm_dev;
 #endif
 };
 
@@ -1035,6 +1062,12 @@ static int omap_dev_ready(struct mtd_info *mtd)
  * omap3_enable_hwecc_bch - Program OMAP3 GPMC to perform BCH ECC correction
  * @mtd: MTD device structure
  * @mode: Read/Write mode
+ * When using BCH, sector size is hardcoded to 512 bytes.
+ * Using wrapping mode 6 both for reading and writing if ELM module not uses
+ * for error correction.
+ * On writing,
+ * eccsize0 = 0  (no additional protected byte in spare area)
+ * eccsize1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area)
  */
 static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
 {
@@ -1043,32 +1076,59 @@ static void omap3_enable_hwecc_bch(struct mtd_info *mtd, int mode)
 	struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
 						   mtd);
 	struct nand_chip *chip = mtd->priv;
-	u32 val;
+	u32 val, wr_mode;
+	unsigned int ecc_size1, ecc_size0;
+
+	/* Using wrapping mode 6 for writing */
+	wr_mode = BCH_WRAPMODE_6;
 
-	nerrors = info->nand.ecc.strength;
-	dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
-	nsectors = 1;
 	/*
-	 * Program GPMC to perform correction on one 512-byte sector at a time.
-	 * Using 4 sectors at a time (i.e. ecc.size = 2048) is also possible and
-	 * gives a slight (5%) performance gain (but requires additional code).
+	 * ECC engine enabled for valid ecc_size0 nibbles
+	 * & disabled for ecc_size1 nibbles.
 	 */
+	ecc_size0 = BCH_ECC_SIZE0;
+	ecc_size1 = BCH_ECC_SIZE1;
 
-	writel(ECC1, info->reg.gpmc_ecc_control);
+	 /* Perform ecc calculation on 512-byte sector */
+	nsectors = 1;
+
+	/* update number of error correction */
+	nerrors = info->nand.ecc.strength;
 
 	/*
-	 * When using BCH, sector size is hardcoded to 512 bytes.
-	 * Here we are using wrapping mode 6 both for reading and writing, with:
-	 *  size0 = 0  (no additional protected byte in spare area)
-	 *  size1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area)
+	 * Perform multi sector reading/writing for
+	 * NAND flashes with page size < 4096
 	 */
-	val = (32 << ECCSIZE1_SHIFT) | (0 << ECCSIZE0_SHIFT);
+	if (info->is_elm_used && (mtd->writesize <= 4096)) {
+		if (mode == NAND_ECC_READ) {
+			/* Using wrapping mode 1 for reading */
+			wr_mode = BCH_WRAPMODE_1;
+
+			/*
+			 * ECC engine enabled for ecc_size0 nibbles
+			 * & disabled for ecc_size1 nibbles.
+			 */
+			ecc_size0 = (nerrors == 8) ?
+				BCH8R_ECC_SIZE0 : BCH4R_ECC_SIZE0;
+			ecc_size1 = (nerrors == 8) ?
+				BCH8R_ECC_SIZE1 : BCH4R_ECC_SIZE1;
+		}
+
+		/* Perform ecc calculation for one page (< 4096) */
+		nsectors = info->nand.ecc.steps;
+	}
+
+	dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
+
+	writel(ECC1, info->reg.gpmc_ecc_control);
+
+	val = (ecc_size1 << ECCSIZE1_SHIFT) | (ecc_size0 << ECCSIZE0_SHIFT);
 	writel(val, info->reg.gpmc_ecc_size_config);
 
 	/* BCH configuration */
 	val = ((1                        << 16) | /* enable BCH */
 	       (((nerrors == 8) ? 1 : 0) << 12) | /* 8 or 4 bits */
-	       (0x06                     <<  8) | /* wrap mode = 6 */
+	       (wr_mode                  <<  8) | /* wrap mode */
 	       (dev_width                <<  7) | /* bus width */
 	       (((nsectors-1) & 0x7)     <<  4) | /* number of sectors */
 	       (info->gpmc_cs            <<  1) | /* ECC CS */
@@ -1166,6 +1226,280 @@ static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat,
 }
 
 /**
+ * omap3_calculate_ecc_bch - Generate bytes of ECC bytes
+ * @mtd:	MTD device structure
+ * @dat:	The pointer to data on which ecc is computed
+ * @ecc_code:	The ecc_code buffer
+ *
+ * support reading og BCH4/8 ecc vectors for the page
+ */
+static int omap3_calculate_ecc_bch(struct mtd_info *mtd, const u_char *dat,
+				    u_char *ecc_code)
+{
+	struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
+						   mtd);
+	unsigned long nsectors, bch_val1, bch_val2, bch_val3, bch_val4;
+	int i, eccbchtsel;
+
+	nsectors = ((readl(info->reg.gpmc_ecc_config) >> 4) & 0x7) + 1;
+	/*
+	 * find BCH scheme used
+	 * 0 -> BCH4
+	 * 1 -> BCH8
+	 */
+	eccbchtsel = ((readl(info->reg.gpmc_ecc_config) >> 12) & 0x3);
+
+	for (i = 0; i < nsectors; i++) {
+
+		/* Read hw-computed remainder */
+		bch_val1 = readl(info->reg.gpmc_bch_result0[i]);
+		bch_val2 = readl(info->reg.gpmc_bch_result1[i]);
+		if (eccbchtsel) {
+			bch_val3 = readl(info->reg.gpmc_bch_result2[i]);
+			bch_val4 = readl(info->reg.gpmc_bch_result3[i]);
+		}
+
+		if (eccbchtsel) {
+			/* BCH8 ecc scheme */
+			*ecc_code++ = (bch_val4 & 0xFF);
+			*ecc_code++ = ((bch_val3 >> 24) & 0xFF);
+			*ecc_code++ = ((bch_val3 >> 16) & 0xFF);
+			*ecc_code++ = ((bch_val3 >> 8) & 0xFF);
+			*ecc_code++ = (bch_val3 & 0xFF);
+			*ecc_code++ = ((bch_val2 >> 24) & 0xFF);
+			*ecc_code++ = ((bch_val2 >> 16) & 0xFF);
+			*ecc_code++ = ((bch_val2 >> 8) & 0xFF);
+			*ecc_code++ = (bch_val2 & 0xFF);
+			*ecc_code++ = ((bch_val1 >> 24) & 0xFF);
+			*ecc_code++ = ((bch_val1 >> 16) & 0xFF);
+			*ecc_code++ = ((bch_val1 >> 8) & 0xFF);
+			*ecc_code++ = (bch_val1 & 0xFF);
+			/*
+			 * Setting 14th byte to zero to handle
+			 * erased page & maintain compatibility
+			 * with RBL
+			 */
+			*ecc_code++ = 0x0;
+		} else {
+			/* BCH4 ecc scheme */
+			*ecc_code++ = ((bch_val2 >> 12) & 0xFF);
+			*ecc_code++ = ((bch_val2 >> 4) & 0xFF);
+			*ecc_code++ = ((bch_val2 & 0xF) << 4) |
+				((bch_val1 >> 28) & 0xF);
+			*ecc_code++ = ((bch_val1 >> 20) & 0xFF);
+			*ecc_code++ = ((bch_val1 >> 12) & 0xFF);
+			*ecc_code++ = ((bch_val1 >> 4) & 0xFF);
+			*ecc_code++ = ((bch_val1 & 0xF) << 4);
+			/*
+			 * Setting 8th byte to zero to handle
+			 * erased page
+			 */
+			*ecc_code++ = 0x0;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * erased_sector_bitflips - count bit flips
+ * @data:	data sector buffer
+ * @oob:	oob buffer
+ * @info:	omap_nand_info
+ *
+ * Check the bit flips in erased page falls below correctable level.
+ * If falls below, report the page as erased with correctable bit
+ * flip, else report as uncorrectable page.
+ */
+static int erased_sector_bitflips(u_char *data, u_char *oob,
+		struct omap_nand_info *info)
+{
+	int flip_bits = 0, i;
+
+	for (i = 0; i < info->nand.ecc.size; i++) {
+		flip_bits += hweight8(~data[i]);
+		if (flip_bits > info->nand.ecc.strength)
+			return 0;
+	}
+
+	for (i = 0; i < info->nand.ecc.bytes - 1; i++) {
+		flip_bits += hweight8(~oob[i]);
+		if (flip_bits > info->nand.ecc.strength)
+			return 0;
+	}
+
+	/*
+	 * Bit flips falls in correctable level.
+	 * Fill data araea with 0xFF
+	 */
+	memset(data, 0xFF, info->nand.ecc.size);
+
+	return flip_bits;
+}
+
+/**
+ * omap_elm_correct_data - corrects page data area in case error reported
+ * @mtd:	MTD device structure
+ * @data:	page data
+ * @read_ecc:	ecc read from nand flash
+ * @calc_ecc:	ecc read from HW ECC registers
+ *
+ * Calculated ecc vector reported as zero in case of non-error pages.
+ * In case of error/erased pages non-zero error vector is reported.
+ * In case of non-zero ecc vector, check read_ecc at fixed offset
+ * (x = 13/7 in case of BCH8/4 == 0) to find page programmed or not.
+ * To handle bit flips in this data, count the number of 0's in
+ * read_ecc[x] and check if it greater than 4. If it is less, it is
+ * programmed page, else erased page.
+ *
+ * 1. If page is erased, check with standard ecc vector (ecc vector
+ * for erased page to find any bit flip). If check fails, bit flip
+ * is present in erased page. Count the bit flips in erased page and
+ * if it falls under correctable level, report page with 0xFF and
+ * update the correctable bit information.
+ * 2. If error is reported on programmed page, update elm error
+ * vector and correct the page with ELM error correction routine.
+ *
+ */
+static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data,
+				u_char *read_ecc, u_char *calc_ecc)
+{
+	struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
+			mtd);
+	int eccsteps = info->nand.ecc.steps;
+	int i , j, stat = 0;
+	int eccsize, eccflag, ecc_vector_size;
+	struct elm_errorvec err_vec[ERROR_VECTOR_MAX];
+	u_char *ecc_vec = calc_ecc;
+	u_char *erased_ecc_vec;
+	enum bch_ecc type;
+	bool is_error_reported = false;
+
+	/* Initialize elm error vector to zero */
+	memset(err_vec, 0, sizeof(err_vec));
+
+	if (info->nand.ecc.strength == BCH8_MAX_ERROR) {
+		type = BCH8_ECC;
+		ecc_vector_size = BCH8_SIZE;
+		eccsize = BCH8_ECC_OOB_BYTES;
+		erased_ecc_vec = bch8_vector;
+	} else {
+		type = BCH4_ECC;
+		ecc_vector_size = BCH4_SIZE;
+		eccsize = BCH4_ECC_OOB_BYTES;
+		erased_ecc_vec = bch4_vector;
+	}
+
+	for (i = 0; i < eccsteps ; i++) {
+		eccflag = 0;	/* initialize eccflag */
+
+		/*
+		 * Check any error reported,
+		 * In case of error, non zero ecc reported.
+		 */
+
+		for (j = 0; (j < eccsize); j++) {
+			if (calc_ecc[j] != 0) {
+				eccflag = 1; /* non zero ecc, error present */
+				break;
+			}
+		}
+
+		if (eccflag == 1) {
+
+			/*
+			 * Check data area is programmed by counting
+			 * number of 0's at fixed offset in spare area.
+			 * Checking count of 0's against 4(threshold set
+			 * to 4 to allow half bit flips at byte offset,
+			 * worst case)
+			 * In case programmed page expects at least 4
+			 * zeros in byte.
+			 * If zeros are less than 4 for programmed page /
+			 * zeros are more than 4 erased page, either
+			 * case page reported as uncorrectable.
+			 */
+			if (hweight8(~read_ecc[eccsize]) >= 4) {
+				/*
+				 * Update elm error vector as
+				 * data area is programmed
+				 */
+				err_vec[i].error_reported = true;
+				is_error_reported = true;
+			} else {
+				/* Error reported in erased page */
+				int bitflip_count;
+				u_char *buf = &data[info->nand.ecc.size * i];
+
+				if (memcmp(calc_ecc, erased_ecc_vec, eccsize)) {
+					bitflip_count = erased_sector_bitflips(
+							buf, read_ecc, info);
+
+					if (bitflip_count)
+						stat += bitflip_count;
+					else
+						return -EINVAL;
+				}
+			}
+		}
+
+		/* Update the ecc vector */
+		calc_ecc = calc_ecc + ecc_vector_size;
+		read_ecc = read_ecc + ecc_vector_size;
+	}
+
+	/* Check if any error reported */
+	if (!is_error_reported)
+		return stat;
+
+	/* Decode BCH error using ELM module */
+	elm_decode_bch_error_page(info->elm_dev, ecc_vec, err_vec);
+
+	for (i = 0; i < eccsteps; i++) {
+		if (err_vec[i].error_reported) {
+			for (j = 0; j < err_vec[i].error_count; j++) {
+				u32 bit_pos, byte_pos, error_max, pos;
+
+				if (type == BCH8_ECC)
+					error_max = BCH8_ECC_MAX;
+				else
+					error_max = BCH4_ECC_MAX;
+
+				if (info->nand.ecc.strength == BCH8_MAX_ERROR)
+					pos = err_vec[i].error_loc[j];
+				else
+					/* Add 4 to take care 4 bit padding */
+					pos = err_vec[i].error_loc[j] +
+						BCH4_BIT_PAD;
+
+				/* Calculate bit position of error */
+				bit_pos = pos % 8;
+
+				/* Calculate byte position of error */
+				byte_pos = (error_max - pos - 1) / 8;
+
+				if (pos < error_max)
+					data[byte_pos] ^= 1 << bit_pos;
+				/* else, not interested to correct ecc */
+			}
+		}
+
+		/* Update number of correctable errors */
+		stat += err_vec[i].error_count;
+
+		/* Update page data with sector size */
+		data += info->nand.ecc.size;
+	}
+
+	for (i = 0; i < eccsteps; i++)
+		/* Return error if uncorrectable error present */
+		if (err_vec[i].error_uncorrectable)
+			return -EINVAL;
+
+	return stat;
+}
+
+/**
  * omap3_correct_data_bch - Decode received data and correct errors
  * @mtd: MTD device structure
  * @data: page data
@@ -1198,6 +1532,89 @@ static int omap3_correct_data_bch(struct mtd_info *mtd, u_char *data,
 }
 
 /**
+ * omap_write_page_bch - BCH ecc based write page function for entire page
+ * @mtd:		mtd info structure
+ * @chip:		nand chip info structure
+ * @buf:		data buffer
+ * @oob_required:	must write chip->oob_poi to OOB
+ *
+ * Custom write page method evolved to support multi sector writing in one shot
+ */
+static int omap_write_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
+				  const uint8_t *buf, int oob_required)
+{
+	int i;
+	uint8_t *ecc_calc = chip->buffers->ecccalc;
+	uint32_t *eccpos = chip->ecc.layout->eccpos;
+
+	/* Enable GPMC ecc engine */
+	chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
+
+	/* Write data */
+	chip->write_buf(mtd, buf, mtd->writesize);
+
+	/* Update ecc vector from GPMC result registers */
+	chip->ecc.calculate(mtd, buf, &ecc_calc[0]);
+
+	for (i = 0; i < chip->ecc.total; i++)
+		chip->oob_poi[eccpos[i]] = ecc_calc[i];
+
+	/* Write ecc vector to OOB area */
+	chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
+	return 0;
+}
+
+/**
+ * omap_read_page_bch - BCH ecc based page read function for entire page
+ * @mtd:		mtd info structure
+ * @chip:		nand chip info structure
+ * @buf:		buffer to store read data
+ * @oob_required:	caller requires OOB data read to chip->oob_poi
+ * @page:		page number to read
+ *
+ * For BCH ecc scheme, GPMC used for syndrome calculation and ELM module
+ * used for error correction.
+ * Custom method evolved to support ELM error correction & multi sector
+ * reading. On reading page data area is read along with OOB data with
+ * ecc engine enabled. ecc vector updated after read of OOB data.
+ * For non error pages ecc vector reported as zero.
+ */
+static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
+				uint8_t *buf, int oob_required, int page)
+{
+	uint8_t *ecc_calc = chip->buffers->ecccalc;
+	uint8_t *ecc_code = chip->buffers->ecccode;
+	uint32_t *eccpos = chip->ecc.layout->eccpos;
+	uint8_t *oob = &chip->oob_poi[eccpos[0]];
+	uint32_t oob_pos = mtd->writesize + chip->ecc.layout->eccpos[0];
+	int stat;
+
+	/* Enable GPMC ecc engine */
+	chip->ecc.hwctl(mtd, NAND_ECC_READ);
+
+	/* Read data */
+	chip->read_buf(mtd, buf, mtd->writesize);
+
+	/* Read oob bytes */
+	chip->cmdfunc(mtd, NAND_CMD_RNDOUT, oob_pos, -1);
+	chip->read_buf(mtd, oob, chip->ecc.total);
+
+	/* Calculate ecc bytes */
+	chip->ecc.calculate(mtd, buf, ecc_calc);
+
+	memcpy(ecc_code, &chip->oob_poi[eccpos[0]], chip->ecc.total);
+
+	stat = chip->ecc.correct(mtd, buf, ecc_code, ecc_calc);
+
+	if (stat < 0)
+		mtd->ecc_stats.failed++;
+	else
+		mtd->ecc_stats.corrected += stat;
+
+	return 0;
+}
+
+/**
  * omap3_free_bch - Release BCH ecc resources
  * @mtd: MTD device structure
  */
@@ -1236,30 +1653,55 @@ static int omap3_init_bch(struct mtd_info *mtd, int ecc_opt)
 		goto fail;
 	}
 
-	/* software bch library is only used to detect and locate errors */
-	info->bch = init_bch(13, max_errors, 0x201b /* hw polynomial */);
-	if (!info->bch)
-		goto fail;
-
-	info->nand.ecc.size    = 512;
-	info->nand.ecc.hwctl   = omap3_enable_hwecc_bch;
-	info->nand.ecc.correct = omap3_correct_data_bch;
-	info->nand.ecc.mode    = NAND_ECC_HW;
+	info->nand.ecc.size = 512;
+	info->nand.ecc.hwctl = omap3_enable_hwecc_bch;
+	info->nand.ecc.mode = NAND_ECC_HW;
+	info->nand.ecc.strength = max_errors;
+	if (info->is_elm_used && (mtd->writesize <= 4096)) {
+		enum bch_ecc bch_type;
 
-	/*
-	 * The number of corrected errors in an ecc block that will trigger
-	 * block scrubbing defaults to the ecc strength (4 or 8).
-	 * Set mtd->bitflip_threshold here to define a custom threshold.
-	 */
+		if (max_errors == BCH8_MAX_ERROR) {
+			bch_type = BCH8_ECC;
+			info->nand.ecc.bytes = BCH8_SIZE;
+		} else {
+			bch_type = BCH4_ECC;
+			info->nand.ecc.bytes = BCH4_SIZE;
+		}
 
-	if (max_errors == 8) {
-		info->nand.ecc.strength  = 8;
-		info->nand.ecc.bytes     = 13;
-		info->nand.ecc.calculate = omap3_calculate_ecc_bch8;
+		info->nand.ecc.correct = omap_elm_correct_data;
+		info->nand.ecc.calculate = omap3_calculate_ecc_bch;
+		info->nand.ecc.read_page = omap_read_page_bch;
+		info->nand.ecc.write_page = omap_write_page_bch;
+		info->elm_dev = elm_request(bch_type);
+		if (!info->elm_dev) {
+			pr_err("Request to elm module failed\n");
+			goto fail;
+		}
 	} else {
-		info->nand.ecc.strength  = 4;
-		info->nand.ecc.bytes     = 7;
-		info->nand.ecc.calculate = omap3_calculate_ecc_bch4;
+		/*
+		 * software bch library is only used to detect and
+		 * locate errors
+		 */
+		info->bch = init_bch(13, max_errors,
+				0x201b /* hw polynomial */);
+		if (!info->bch)
+			goto fail;
+
+		info->nand.ecc.correct = omap3_correct_data_bch;
+
+		/*
+		 * The number of corrected errors in an ecc block that will
+		 * trigger block scrubbing defaults to the ecc strength (4 or 8)
+		 * Set mtd->bitflip_threshold here to define a custom threshold.
+		 */
+
+		if (max_errors == 8) {
+			info->nand.ecc.bytes = 13;
+			info->nand.ecc.calculate = omap3_calculate_ecc_bch8;
+		} else {
+			info->nand.ecc.bytes = 7;
+			info->nand.ecc.calculate = omap3_calculate_ecc_bch4;
+		}
 	}
 
 	pr_info("enabling NAND BCH ecc with %d-bit correction\n", max_errors);
@@ -1275,7 +1717,7 @@ fail:
  */
 static int omap3_init_bch_tail(struct mtd_info *mtd)
 {
-	int i, steps;
+	int i, steps, offset;
 	struct omap_nand_info *info = container_of(mtd, struct omap_nand_info,
 						   mtd);
 	struct nand_ecclayout *layout = &info->ecclayout;
@@ -1297,11 +1739,22 @@ static int omap3_init_bch_tail(struct mtd_info *mtd)
 		goto fail;
 	}
 
+	/* ECC layout compatible with RBL for BCH8 */
+	if (info->is_elm_used && (info->nand.ecc.bytes == BCH8_SIZE))
+		offset = 2;
+	else
+		offset = mtd->oobsize - layout->eccbytes;
+
 	/* put ecc bytes at oob tail */
 	for (i = 0; i < layout->eccbytes; i++)
-		layout->eccpos[i] = mtd->oobsize-layout->eccbytes+i;
+		layout->eccpos[i] = offset + i;
+
+
+	if (info->is_elm_used && (info->nand.ecc.bytes == BCH8_SIZE))
+		layout->oobfree[0].offset = 2 + layout->eccbytes * steps;
+	else
+		layout->oobfree[0].offset = 2;
 
-	layout->oobfree[0].offset = 2;
 	layout->oobfree[0].length = mtd->oobsize-2-layout->eccbytes;
 	info->nand.ecc.layout = layout;
 
@@ -1365,6 +1818,9 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
 	info->nand.options	= pdata->devsize;
 	info->nand.options	|= NAND_SKIP_BBTSCAN;
 
+#ifdef CONFIG_MTD_NAND_OMAP_BCH
+	info->is_elm_used	= pdata->is_elm_used;
+#endif
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (res == NULL) {
 		err = -EINVAL;
include/linux/platform_data/elm.h +2 -1
index d4fce31..b732089 100644
@@ -30,7 +30,8 @@ enum bch_ecc {
 #define BCH4_ECC_OOB_BYTES		7
 /* RBL requires 14 byte even though BCH8 uses only 13 byte */
 #define BCH8_SIZE			(BCH8_ECC_OOB_BYTES + 1)
-#define BCH4_SIZE			(BCH4_ECC_OOB_BYTES)
+/* Uses 1 extra byte to handle erased pages */
+#define BCH4_SIZE			(BCH4_ECC_OOB_BYTES + 1)
 
 /**
  * struct elm_errorvec - error vector for elm
include/linux/platform_data/mtd-nand-omap2.h +1 -0
index 24d32ca..db8c68b 100644
@@ -60,6 +60,7 @@ struct omap_nand_platform_data {
 	int			devsize;
 	enum omap_ecc           ecc_opt;
 	struct gpmc_nand_regs	reg;
+	bool			is_elm_used;
 };
 
 #endif
Signature · 1 line
1.7.0.4
#4 lore raw

Re: [PATCH v2 3/3] mtd: nand: omap2: Support for hardware BCH error correction

Quoted 6 lines · Avinash
drivers/mtd/nand/omap2.c +6 -0
+static int erased_sector_bitflips(u_char *data, u_char *oob,
+               struct omap_nand_info *info)
+{
+       int flip_bits = 0, i;
+
+       for (i = 0; i < info->nand.ecc.size; i++) {

drivers/mtd/nand/omap2.c static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat, · line 1329

Quoted 10 lines
drivers/mtd/nand/omap2.c +10 -0
+               flip_bits += hweight8(~data[i]);
+               if (flip_bits > info->nand.ecc.strength)
+                       return 0;
+       }
+
+       for (i = 0; i < info->nand.ecc.bytes - 1; i++) {
+               flip_bits += hweight8(~oob[i]);
+               if (flip_bits > info->nand.ecc.strength)
+                       return 0;
+       }

Why do you need the second for loop?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#5 lore raw

RE: [PATCH v2 3/3] mtd: nand: omap2: Support for hardware BCH error correction

Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Avinash
drivers/mtd/nand/omap2.c +10 -0
+static int erased_sector_bitflips(u_char *data, u_char *oob,
+               struct omap_nand_info *info)
+{
+       int flip_bits = 0, i;
+
+       for (i = 0; i < info->nand.ecc.size; i++) {
+               flip_bits += hweight8(~data[i]);
+               if (flip_bits > info->nand.ecc.strength)
+                       return 0;
+       }
Quoted 8 lines

drivers/mtd/nand/omap2.c static int omap3_calculate_ecc_bch8(struct mtd_info *mtd, const u_char *dat, · line 1329

Quoted 6 lines
drivers/mtd/nand/omap2.c +6 -0
+
+       for (i = 0; i < info->nand.ecc.bytes - 1; i++) {
+               flip_bits += hweight8(~oob[i]);
+               if (flip_bits > info->nand.ecc.strength)
+                       return 0;
+       }

Why do you need the second for loop?

BCH ecc is self protected & can correct bit flips in ecc bytes. So here checking bit flips in read_ecc. I will rename variable "oob" to "read_ecc"

Thanks
Avinash

Quoted 5 lines
Signature · 3 lines
-- 
Best Regards,
Artem Bityutskiy
#6 lore raw
In reply to Philip, Avinash
Quoted 7 lines · Avinash

Support to use ELM as BCH 4 & 8 bit error correction module. Also performance enhancement by adding single shot read_page and write_page functions for the nand flashes with page size less than 4 KB.

ELM module can be used to correct errors reported by BCH 4, 8 & 16 bit ECC scheme. For now only 4 & 8 bit support is added.

Quoted 7 lines

BCH 4 & 8 bit error detection support is already available in mainline kernel and works with software error correction.

This series is based on [1] and tested with RFC: OMAP GPMC bindings patch series

1. linux-next/20121030

Would you please re-send a version which cleanly applies to the l2-mtd.git tree? This series has many conflicts. Thanks!

git://git.infradead.org/users/dedekind/l2-mtd.git

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#7 lore raw
Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Avinash

Support to use ELM as BCH 4 & 8 bit error correction module. Also performance enhancement by adding single shot read_page and write_page functions for the nand flashes with page size less than 4 KB.

ELM module can be used to correct errors reported by BCH 4, 8 & 16 bit ECC scheme. For now only 4 & 8 bit support is added.

BCH 4 & 8 bit error detection support is already available in mainline kernel and works with software error correction.

Quoted 7 lines
Quoted 4 lines

This series is based on [1] and tested with RFC: OMAP GPMC bindings patch series

1. linux-next/20121030

Would you please re-send a version which cleanly applies to the l2-mtd.git tree? This series has many conflicts. Thanks!

Artem,

Omap nand driver is being changed considerably with Afzal's omap-gpmc cleanup series for common arm zImage [2] and those changes move many
of the nand related code from platform folders to omap nand driver.

Omap-gpmc changes are present in Tony's " omap-for-v3.8/cleanup-headers-gpmc" branch [3]and is present in linux-next also, but is not present in l2-mtd. Tony has signed tag including omap-gpmc cleanup series, "omap-for-v3.8/cleanup-headers-prepare-multiplatform-v3-signed" [4]

If this series is made over l2-mtd, and it would cause lot of conflict with omap-gpmc cleanup series.

I am not sure how this dependency has to be handled for this series, let me know whether you still want it to be made over l2-mtd?

2. http://markmail.org/message/ev67wm7irgc2qc5d#query:+page:1+mid:wgjdv6fsfghnua5z+state:results
3. http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap.git;a=shortlog;h=refs/heads/omap-for-v3.8/cleanup-headers-gpmc
4. http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap.git;a=tag;h=refs/tags/omap-for-v3.8/cleanup-headers-prepare-multiplatform-v3-signed

Thanks
Avinash

Quoted 7 lines

git://git.infradead.org/users/dedekind/l2-mtd.git

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#8 lore raw
In reply to Artem Bityutskiy
Quoted 32 lines · Avinash
Quoted 11 lines · Artem Bityutskiy
Quoted 10 lines · Avinash

Support to use ELM as BCH 4 & 8 bit error correction module. Also performance enhancement by adding single shot read_page and write_page functions for the nand flashes with page size less than 4 KB.

ELM module can be used to correct errors reported by BCH 4, 8 & 16 bit ECC scheme. For now only 4 & 8 bit support is added.

BCH 4 & 8 bit error detection support is already available in mainline kernel and works with software error correction.

Quoted 7 lines
Quoted 4 lines

This series is based on [1] and tested with RFC: OMAP GPMC bindings patch series

1. linux-next/20121030

Would you please re-send a version which cleanly applies to the l2-mtd.git tree? This series has many conflicts. Thanks!

Artem,

Omap nand driver is being changed considerably with Afzal's omap-gpmc cleanup series for common arm zImage [2] and those changes move many
of the nand related code from platform folders to omap nand driver.

Omap-gpmc changes are present in Tony's " omap-for-v3.8/cleanup-headers-gpmc" branch [3]and is present in linux-next also, but is not present in l2-mtd. Tony has signed tag including omap-gpmc cleanup series, "omap-for-v3.8/cleanup-headers-prepare-multiplatform-v3-signed" [4]

Quoted 5 lines

If this series is made over l2-mtd, and it would cause lot of conflict with omap-gpmc cleanup series.

I am not sure how this dependency has to be handled for this series, let me know whether you still want it to be made over l2-mtd?

Artem,

Is it possible for you to give ack for these patches so that these patches can go in Tony's tree where Omap-gpmc changes are present?

Thanks
Avinash

Quoted 18 lines

2. http://markmail.org/message/ev67wm7irgc2qc5d#query:+page:1+mid:wgjdv6fsfghnua5z+state:results
3. http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap.git;a=shortlog;h=refs/heads/omap-for-v3.8/cleanup-headers-gpmc
4. http://git.kernel.org/?p=linux/kernel/git/tmlind/linux-omap.git;a=tag;h=refs/tags/omap-for-v3.8/cleanup-headers-prepare-multiplatform-v3-signed

Thanks
Avinash

Quoted 7 lines

git://git.infradead.org/users/dedekind/l2-mtd.git

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#9 lore raw
Quoted 7 lines · Avinash
Quoted 2 lines

I am not sure how this dependency has to be handled for this series, let me know whether you still want it to be made over l2-mtd?

Artem,

Is it possible for you to give ack for these patches so that these patches can go in Tony's tree where Omap-gpmc changes are present?

I would prefer if people like Ivan could take a look at this first.

Also, I am not sure this is a good idea. Or at least we should agree on some common strategy for bit-flips in the erased areas:

"+ * 1. If page is erased, check with standard ecc vector (ecc vector
+ * for erased page to find any bit flip). If check fails, bit flip
+ * is present in erased page. Count the bit flips in erased page and
+ * if it falls under correctable level, report page with 0xFF and
+ * update the correctable bit information."

Basically, you are working-around JFFS2 limitations.

Do you suggest we do this in all the drivers?

If we want to do this, may be we better do this in higher level, common to all drivers?

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#10 lore raw
Quoted 10 lines · Artem Bityutskiy
Quoted 7 lines · Avinash
Quoted 2 lines

I am not sure how this dependency has to be handled for this series, let me know whether you still want it to be made over l2-mtd?

Artem,

Is it possible for you to give ack for these patches so that these patches can go in Tony's tree where Omap-gpmc changes are present?

I would prefer if people like Ivan could take a look at this first.

Ok.

Quoted 10 lines

Also, I am not sure this is a good idea. Or at least we should agree on some common strategy for bit-flips in the erased areas:

"+ * 1. If page is erased, check with standard ecc vector (ecc vector
+ * for erased page to find any bit flip). If check fails, bit flip
+ * is present in erased page. Count the bit flips in erased page and
+ * if it falls under correctable level, report page with 0xFF and
+ * update the correctable bit information."

Idea here is to make faster scanning of erased page without bit flips. For omap nand driver ecc reported by hardware is non-zero and non 0xff. So comparing with the standard vector for erased page and skipping error correction for erased page without bit flips.

Strategy for bit flips in erased page bit flips, can be
1. Don't make as erased page and mark it as bad.
2. Report the erased page with correctable bit flip if it falls under correctable level. Report the page with erased page with correctable errors.
Is the concern is here with erased page with correctable error? I think as error is under correctable level, we still can use the page. May be we can think of limiting the check to half of correctable level?

I would go for option 2, see discussion [1].

Option 2 adopted in this patch series.

Quoted 3 lines

Basically, you are working-around JFFS2 limitations.

Do you suggest we do this in all the drivers?

I am not sure how the situation handled in other drivers. This depends on the platforms. This method can be adopted for platforms where ecc reported non-zero & non 0xff with erased page.

Quoted 4 lines

If we want to do this, may be we better do this in higher level, common to all drivers?

I doubt how we handle in higher level with existing MTD setup. Issues I am seeing on implementing at higher layer is
1. Calculation of standard ecc vector for erased page.
2. Skipping ecc error correction, as currently error correction in .read_page()
Can be handled by adding common .read_page() method on certain flag, populated for platform specific.

1. http://lists.infradead.org/pipermail/linux-mtd/2011-April/034604.html

Thanks
Avinash

Quoted 4 lines
Signature · 2 lines
Best Regards,
Artem Bityutskiy
#11 lore raw
Quoted 6 lines · Avinash

Idea here is to make faster scanning of erased page without bit flips. For omap nand driver ecc reported by hardware is non-zero and non 0xff.
So comparing with the standard vector for erased page and skipping error
correction for erased page without bit flips.

So you mean that when you read a page, and you see there are bit-flips, you start correcting them. But if you notice that the page is actually an erased page, you optimize this case by not running the correction machinery, but just filling the buffer with 0xFFs. Right?

Quoted 1 line
Signature · 2 lines
Best Regards,
Artem Bityutskiy
#12 lore raw
Quoted 8 lines · Artem Bityutskiy
Quoted 6 lines · Avinash

Idea here is to make faster scanning of erased page without bit flips. For omap nand driver ecc reported by hardware is non-zero and non 0xff.
So comparing with the standard vector for erased page and skipping error
correction for erased page without bit flips.

Quoted 4 lines

So you mean that when you read a page, and you see there are bit-flips, you start correcting them. But if you notice that the page is actually an erased page, you optimize this case by not running the correction machinery, but just filling the buffer with 0xFFs. Right?

Yes it is an optimization for erased page bit flip handling.
On erased page, ecc bytes not valid. So no direct correction machinery available for bit flips in erased page. Hence I was checking if any bit flips reported in erased page. If bit flip present in erased page and falls under correctable level, report the page with 0xff with correctable errors.

Thanks
Avinash

Quoted 5 lines
Quoted 1 line
Signature · 2 lines
Best Regards,
Artem Bityutskiy
#13 lore raw
In reply to Artem Bityutskiy
Quoted 5 lines · Avinash
Quoted 4 lines · Artem Bityutskiy
Quoted 3 lines · Avinash
Quoted 2 lines

I am not sure how this dependency has to be handled for this series, let me know whether you still want it to be made over l2-mtd?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Artem,

Is it possible for you to give ack for these patches so that these patches can go in Tony's tree where Omap-gpmc changes are present?

I would prefer if people like Ivan could take a look at this first.

Ok.

Ivan/Artem,

Any comments in this patch series?
I hope ELM support can get in 3.8.

Quoted 30 lines
Quoted 11 lines

Also, I am not sure this is a good idea. Or at least we should agree on some common strategy for bit-flips in the erased areas:

"+ * 1. If page is erased, check with standard ecc vector (ecc vector
+ * for erased page to find any bit flip). If check fails, bit flip
+ * is present in erased page. Count the bit flips in erased page and
+ * if it falls under correctable level, report page with 0xFF and
+ * update the correctable bit information."

Idea here is to make faster scanning of erased page without bit flips. For omap nand driver ecc reported by hardware is non-zero and non 0xff. So comparing with the standard vector for erased page and skipping error correction for erased page without bit flips.

Strategy for bit flips in erased page bit flips, can be
1. Don't make as erased page and mark it as bad.
2. Report the erased page with correctable bit flip if it falls under correctable level. Report the page with erased page with correctable errors.
Is the concern is here with erased page with correctable error? I think as error is under correctable level, we still can use the page. May be we can think of limiting the check to half of correctable level?

I would go for option 2, see discussion [1].

Option 2 adopted in this patch series.

Quoted 7 lines
Quoted 3 lines

Basically, you are working-around JFFS2 limitations.

Do you suggest we do this in all the drivers?

I am not sure how the situation handled in other drivers. This depends on the platforms. This method can be adopted for platforms where ecc reported non-zero & non 0xff with erased page.

Any comments?

Thanks
Avinash

Quoted 25 lines
Quoted 5 lines

If we want to do this, may be we better do this in higher level, common to all drivers?

I doubt how we handle in higher level with existing MTD setup. Issues I am seeing on implementing at higher layer is
1. Calculation of standard ecc vector for erased page.
2. Skipping ecc error correction, as currently error correction in .read_page()
Can be handled by adding common .read_page() method on certain flag, populated for platform specific.

1. http://lists.infradead.org/pipermail/linux-mtd/2011-April/034604.html

Thanks
Avinash

Quoted 4 lines
Signature · 2 lines
Best Regards,
Artem Bityutskiy