public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 2/2] MTD:NAND: ADD new ECC mode NAND_ECC_HW_OOB_FIRST
@ 2009-08-18 16:00 Scott Wood
  0 siblings, 0 replies; 16+ messages in thread
From: Scott Wood @ 2009-08-18 16:00 UTC (permalink / raw)
  To: u-boot

On Mon, Aug 10, 2009 at 01:27:56PM -0400, s-paulraj at dal.design.ti.com wrote:
> From: Sandeep Paulraj <s-paulraj@ti.com>
> 
> This patch adds the new mode NAND_ECC_HW_OOB_FIRST in the nand code to
> support 4-bit ECC on TI DaVinci devices with large page (up to 2K) NAND
> chips.  This ECC mode is similar to NAND_ECC_HW, with the exception of
> read_page API that first reads the OOB area, reads the data in chunks,
> feeds the ECC from OOB area to the ECC hw engine and perform any
> correction on the data as per the ECC status reported by the engine.
> 
> This patch has been accepted by Andrew Morton and can be found at
> 
> http://userweb.kernel.org/~akpm/mmotm/broken-out/mtd-nand-add-new-ecc-mode-ecc_hw_oob_first.patch
> 
> Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>
> Signed-off-by: Sneha Narnakaje <nsnehaprabha@ti.com>

Applied to u-boot-nand-flash/next.

-Scott

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 2/2] MTD:NAND: ADD new ECC mode NAND_ECC_HW_OOB_FIRST
@ 2009-08-11 22:34 Scott Wood
  2009-08-12 11:48 ` Paulraj, Sandeep
  0 siblings, 1 reply; 16+ messages in thread
From: Scott Wood @ 2009-08-11 22:34 UTC (permalink / raw)
  To: u-boot

On Mon, Aug 10, 2009 at 01:27:56PM -0400, s-paulraj at dal.design.ti.com wrote:
>  /**
> + * nand_read_page_hwecc_oob_first - [REPLACABLE] hw ecc, read oob first
> + * @mtd:	mtd info structure
> + * @chip:	nand chip info structure
> + * @buf:	buffer to store read data
> + *
> + * Hardware ECC for large page chips, require OOB to be read first.

That statement may be true on some controllers, but not all.

> + * For this ECC mode, the write_page method is re-used from ECC_HW.
> + * These methods read/write ECC from the OOB area, unlike the
> + * ECC_HW_SYNDROME support with multiple ECC steps, follows the
> + * "infix ECC" scheme and reads/writes ECC from the data area, by
> + * overwriting the NAND manufacturer bad block markings.
> + */
> +static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
> +	struct nand_chip *chip, uint8_t *buf, int page)
> +{
> +	int i, eccsize = chip->ecc.size;
> +	int eccbytes = chip->ecc.bytes;
> +	int eccsteps = chip->ecc.steps;
> +	uint8_t *p = buf;
> +	uint8_t *ecc_code = chip->buffers->ecccode;
> +	uint32_t *eccpos = chip->ecc.layout->eccpos;
> +	uint8_t *ecc_calc = chip->buffers->ecccalc;
> +
> +	/* Read the OOB area first */
> +	chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);

Note that a READ0 command will have already been issued at this point. 

I guess it looks to the NAND chip as a zero-byte read, but still things
are getting quite ugly.  The "generic" interface is one big layering
violation that assumes a certain type of very simple controller, and
we're accumulating hacks to deal with less straightforward controllers.
:-(

-Scott

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 2/2] MTD:NAND: ADD new ECC mode NAND_ECC_HW_OOB_FIRST
@ 2009-08-11 22:17 Scott Wood
  0 siblings, 0 replies; 16+ messages in thread
From: Scott Wood @ 2009-08-11 22:17 UTC (permalink / raw)
  To: u-boot

On Mon, Aug 10, 2009 at 01:27:56PM -0400, s-paulraj at dal.design.ti.com wrote:
> From: Sandeep Paulraj <s-paulraj@ti.com>
> 
> This patch adds the new mode NAND_ECC_HW_OOB_FIRST in the nand code to
> support 4-bit ECC on TI DaVinci devices with large page (up to 2K) NAND
> chips.  This ECC mode is similar to NAND_ECC_HW, with the exception of
> read_page API that first reads the OOB area, reads the data in chunks,
> feeds the ECC from OOB area to the ECC hw engine and perform any
> correction on the data as per the ECC status reported by the engine.

Is this going to be used by any other NAND controllers?  If it's not a
particularly common thing, perhaps the DaVinci NAND controller driver
should just override the read_page method.

Even if it's shared, the alternative read_page should probably be
provided in library form for the controller driver to use if desired.  We
should move most of the so-called generic NAND stuff in that direction;
currently it bloats u-boot even on hardware that doesn't need it.

> This patch has been accepted by Andrew Morton and can be found at
> 
> http://userweb.kernel.org/~akpm/mmotm/broken-out/mtd-nand-add-new-ecc-mode-ecc_hw_oob_first.patch

That's a testing tree -- it's not actually "accepted" if it's not in the
mtd tree (or Linus's).

> +	case NAND_ECC_HW_OOB_FIRST:
> +		/* Similar to NAND_ECC_HW, but a separate read_page handle */
> +		if (!chip->ecc.calculate || !chip->ecc.correct ||
> +		     !chip->ecc.hwctl) {
> +			printk(KERN_WARNING "No ECC functions supplied, "
> +			       "Hardware ECC not possible\n");
> +			BUG();
> +		}
> +		if (!chip->ecc.read_page)
> +			chip->ecc.read_page = nand_read_page_hwecc_oob_first;

Would anyone ever use this with read_page non-NULL?  It seems like its
whole point is to overide that.

-Scott

^ permalink raw reply	[flat|nested] 16+ messages in thread
* [U-Boot] [PATCH 2/2] MTD:NAND: ADD new ECC mode NAND_ECC_HW_OOB_FIRST
@ 2009-08-10 17:27 s-paulraj at dal.design.ti.com
  0 siblings, 0 replies; 16+ messages in thread
From: s-paulraj at dal.design.ti.com @ 2009-08-10 17:27 UTC (permalink / raw)
  To: u-boot

From: Sandeep Paulraj <s-paulraj@ti.com>

This patch adds the new mode NAND_ECC_HW_OOB_FIRST in the nand code to
support 4-bit ECC on TI DaVinci devices with large page (up to 2K) NAND
chips.  This ECC mode is similar to NAND_ECC_HW, with the exception of
read_page API that first reads the OOB area, reads the data in chunks,
feeds the ECC from OOB area to the ECC hw engine and perform any
correction on the data as per the ECC status reported by the engine.

This patch has been accepted by Andrew Morton and can be found at

http://userweb.kernel.org/~akpm/mmotm/broken-out/mtd-nand-add-new-ecc-mode-ecc_hw_oob_first.patch

Signed-off-by: Sandeep Paulraj <s-paulraj@ti.com>
Signed-off-by: Sneha Narnakaje <nsnehaprabha@ti.com>
---
 drivers/mtd/nand/nand_base.c |   59 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/mtd/nand.h     |    1 +
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ca02628..426bb95 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1068,6 +1068,54 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 }
 
 /**
+ * nand_read_page_hwecc_oob_first - [REPLACABLE] hw ecc, read oob first
+ * @mtd:	mtd info structure
+ * @chip:	nand chip info structure
+ * @buf:	buffer to store read data
+ *
+ * Hardware ECC for large page chips, require OOB to be read first.
+ * For this ECC mode, the write_page method is re-used from ECC_HW.
+ * These methods read/write ECC from the OOB area, unlike the
+ * ECC_HW_SYNDROME support with multiple ECC steps, follows the
+ * "infix ECC" scheme and reads/writes ECC from the data area, by
+ * overwriting the NAND manufacturer bad block markings.
+ */
+static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
+	struct nand_chip *chip, uint8_t *buf, int page)
+{
+	int i, eccsize = chip->ecc.size;
+	int eccbytes = chip->ecc.bytes;
+	int eccsteps = chip->ecc.steps;
+	uint8_t *p = buf;
+	uint8_t *ecc_code = chip->buffers->ecccode;
+	uint32_t *eccpos = chip->ecc.layout->eccpos;
+	uint8_t *ecc_calc = chip->buffers->ecccalc;
+
+	/* Read the OOB area first */
+	chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
+	chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
+	chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
+
+	for (i = 0; i < chip->ecc.total; i++)
+		ecc_code[i] = chip->oob_poi[eccpos[i]];
+
+	for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
+		int stat;
+
+		chip->ecc.hwctl(mtd, NAND_ECC_READ);
+		chip->read_buf(mtd, p, eccsize);
+		chip->ecc.calculate(mtd, p, &ecc_calc[i]);
+
+		stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
+		if (stat < 0)
+			mtd->ecc_stats.failed++;
+		else
+			mtd->ecc_stats.corrected += stat;
+	}
+	return 0;
+}
+
+/**
  * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read
  * @mtd:	mtd info structure
  * @chip:	nand chip info structure
@@ -2730,6 +2778,17 @@ int nand_scan_tail(struct mtd_info *mtd)
 		chip->ecc.write_page_raw = nand_write_page_raw;
 
 	switch (chip->ecc.mode) {
+	case NAND_ECC_HW_OOB_FIRST:
+		/* Similar to NAND_ECC_HW, but a separate read_page handle */
+		if (!chip->ecc.calculate || !chip->ecc.correct ||
+		     !chip->ecc.hwctl) {
+			printk(KERN_WARNING "No ECC functions supplied, "
+			       "Hardware ECC not possible\n");
+			BUG();
+		}
+		if (!chip->ecc.read_page)
+			chip->ecc.read_page = nand_read_page_hwecc_oob_first;
+
 	case NAND_ECC_HW:
 		/* Use standard hwecc read page function ? */
 		if (!chip->ecc.read_page)
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index d6aa392..cb7c19a 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -128,6 +128,7 @@ typedef enum {
 	NAND_ECC_SOFT,
 	NAND_ECC_HW,
 	NAND_ECC_HW_SYNDROME,
+	NAND_ECC_HW_OOB_FIRST,
 } nand_ecc_modes_t;
 
 /*
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-09-01 20:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <7081825318460577925@unknownmsgid>
2009-09-01 15:22 ` [U-Boot] [PATCH 2/2] MTD:NAND: ADD new ECC mode NAND_ECC_HW_OOB_FIRST John Rigby
2009-09-01 15:36   ` Scott Wood
2009-09-01 16:03     ` Paulraj, Sandeep
2009-09-01 16:31       ` John Rigby
     [not found]       ` <0554BEF07D437848AF01B9C9B5F0BC5D9217B3B7@dlee01.ent.ti.com>
2009-09-01 16:55         ` John Rigby
2009-09-01 19:19       ` Scott Wood
2009-09-01 19:59         ` Matt Waddel
2009-09-01 20:06           ` Scott Wood
2009-08-18 16:00 Scott Wood
  -- strict thread matches above, loose matches on Subject: below --
2009-08-11 22:34 Scott Wood
2009-08-12 11:48 ` Paulraj, Sandeep
2009-08-12 16:11   ` Scott Wood
     [not found]     ` <0554BEF07D437848AF01B9C9B5F0BC5D7C628A5C@dlee01.ent.ti.com>
2009-08-12 17:11       ` Scott Wood
2009-08-14 14:03         ` Paulraj, Sandeep
2009-08-11 22:17 Scott Wood
2009-08-10 17:27 s-paulraj at dal.design.ti.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox