linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F
@ 2018-06-21 10:33 Chris Packham
  2018-06-21 10:33 ` [PATCH v4 1/6] mtd: rawnand: marvell: Handle on-die ECC Chris Packham
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham

Hi,

I'm looking at adding support for the Micron MT29F1G08ABAFAWP-ITE:F chip
to one of our boards which uses the Marvell NFCv2 controller.

This particular chip is a bit odd in that the datasheet states support
for ONFI 1.0 but the revision number field is 00 00. It also is marked
ABAFA but reports internally as ABAGA. Finally it has internal 8-bit ECC
which cannot be disabled.

The existing test in micron_supports_on_die_ecc() determines that on-die
ECC is supported but not mandatory but I know for this chip it is
mandatory despite what set_features returns.

In order for this to work I need to set nand-ecc-mode = "on-die" in my
dts. Ideally I'd like it to be automatic based on what the hardware can
support but that may be asking too much at the moment.

Here's a dump of the parameter page from the chip I have

00000000: 4f 4e 46 49 00 00 18 00 3f 00 00 00 00 00 00 00 ONFI....?.......
00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000020: 4d 49 43 52 4f 4e 20 20 20 20 20 20 4d 54 32 39  MICRON MT29
00000030: 46 31 47 30 38 41 42 41 47 41 57 50 20 20 20 20  F1G08ABAGAWP    
00000040: 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ,...............
00000050: 00 08 00 00 80 00 00 02 00 00 20 00 40 00 00 00  ..........  .@...
00000060: 00 04 00 00 01 22 01 14 00 01 05 08 00 00 04 00 ....."..........
00000070: 08 01 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000080: 08 3f 00 3f 00 58 02 10 27 46 00 64 00 00 00 00 .?.?.X..'F.d....
00000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000a0: 00 00 00 00 01 00 00 00 00 02 04 80 01 81 04 03 ................
000000b0: 02 01 1e 90 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 85 a6 ................

Series changes in v3:
- No longer RFC
- dropped "mtd: rawnand: micron: add ONFI_FEATURE_ON_DIE_ECC to supported
  features" which Boris has already picked up
- dropped "mtd: rawnand: marvell: Support page size of 2048 with 8-bit ECC"
  since I can't test it.

Series changes in v4:
- based on top of http://patchwork.ozlabs.org/patch/932006/

Chris Packham (6):
  mtd: rawnand: marvell: Handle on-die ECC
  mtd: rawnand: add manufacturer fixup for ONFI parameter page
  mtd: rawnand: add defines for ONFI version bits
  mtd: rawnand: micron: add fixup for ONFI revision
  mtd: rawnand: micron: support 8/512 on-die ECC
  mtd: rawnand: micron: detect forced on-die ECC

 drivers/mtd/nand/raw/marvell_nand.c |  1 +
 drivers/mtd/nand/raw/nand_base.c    | 14 +++--
 drivers/mtd/nand/raw/nand_micron.c  | 98 ++++++++++++++++++++++-------
 include/linux/mtd/rawnand.h         | 14 +++++
 4 files changed, 98 insertions(+), 29 deletions(-)

-- 
2.17.1

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

* [PATCH v4 1/6] mtd: rawnand: marvell: Handle on-die ECC
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 10:33 ` [PATCH v4 2/6] mtd: rawnand: add manufacturer fixup for ONFI parameter page Chris Packham
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

>From the controllers point of view this is the same as no or
software only ECC.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
Changes in v2:
- New
Changes in v3:
- Add review from Boris
Changes in v4:
- None

 drivers/mtd/nand/raw/marvell_nand.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index ebb1d141b900..ba6889bbe802 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -2157,6 +2157,7 @@ static int marvell_nand_ecc_init(struct mtd_info *mtd,
 		break;
 	case NAND_ECC_NONE:
 	case NAND_ECC_SOFT:
+	case NAND_ECC_ON_DIE:
 		if (!nfc->caps->is_nfcv2 && mtd->writesize != SZ_512 &&
 		    mtd->writesize != SZ_2K) {
 			dev_err(nfc->dev, "NFCv1 cannot write %d bytes pages\n",
-- 
2.17.1

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

* [PATCH v4 2/6] mtd: rawnand: add manufacturer fixup for ONFI parameter page
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
  2018-06-21 10:33 ` [PATCH v4 1/6] mtd: rawnand: marvell: Handle on-die ECC Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 10:33 ` [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits Chris Packham
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

This is called after the ONFI parameter page checksum is verified
and allows us to override the contents of the parameter page.

Suggested-by: Boris Brezillon <boris.brezillon@bootlin.com>
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
Changes in v2:
- New
Changes in v3:
- Add doc comment and review from Boris
Changes in v4:
- None

 drivers/mtd/nand/raw/nand_base.c | 4 ++++
 include/linux/mtd/rawnand.h      | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 0cd3e216b95c..65250308c82d 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5172,6 +5172,10 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
 		}
 	}
 
+	if (chip->manufacturer.desc && chip->manufacturer.desc->ops &&
+	    chip->manufacturer.desc->ops->fixup_onfi_param_page)
+		chip->manufacturer.desc->ops->fixup_onfi_param_page(chip, p);
+
 	/* Check version */
 	val = le16_to_cpu(p->revision);
 	if (val & (1 << 5))
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index 3e8ec3b8a39c..ef7e3b4e91ea 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -778,11 +778,14 @@ nand_get_sdr_timings(const struct nand_data_interface *conf)
  *	  implementation) if any.
  * @cleanup: the ->init() function may have allocated resources, ->cleanup()
  *	     is here to let vendor specific code release those resources.
+ * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI
+ *	parameter page. This is called after the checksum is verified.
  */
 struct nand_manufacturer_ops {
 	void (*detect)(struct nand_chip *chip);
 	int (*init)(struct nand_chip *chip);
 	void (*cleanup)(struct nand_chip *chip);
+	void (*fixup_onfi_param_page)(struct nand_chip *chip, struct nand_onfi_params *p);
 };
 
 /**
-- 
2.17.1

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

* [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
  2018-06-21 10:33 ` [PATCH v4 1/6] mtd: rawnand: marvell: Handle on-die ECC Chris Packham
  2018-06-21 10:33 ` [PATCH v4 2/6] mtd: rawnand: add manufacturer fixup for ONFI parameter page Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 11:05   ` Boris Brezillon
  2018-06-21 10:33 ` [PATCH v4 4/6] mtd: rawnand: micron: add fixup for ONFI revision Chris Packham
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

Add defines for the ONFI version bits and use them in
nand_flash_detect_onfi().

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v4:
- New

 drivers/mtd/nand/raw/nand_base.c | 10 +++++-----
 include/linux/mtd/rawnand.h      | 11 +++++++++++
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 65250308c82d..36048e0cf1f5 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5178,15 +5178,15 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
 
 	/* Check version */
 	val = le16_to_cpu(p->revision);
-	if (val & (1 << 5))
+	if (val & ONFI_VERSION_2_3)
 		chip->parameters.onfi.version = 23;
-	else if (val & (1 << 4))
+	else if (val & ONFI_VERSION_2_2)
 		chip->parameters.onfi.version = 22;
-	else if (val & (1 << 3))
+	else if (val & ONFI_VERSION_2_1)
 		chip->parameters.onfi.version = 21;
-	else if (val & (1 << 2))
+	else if (val & ONFI_VERSION_2_0)
 		chip->parameters.onfi.version = 20;
-	else if (val & (1 << 1))
+	else if (val & ONFI_VERSION_1_0)
 		chip->parameters.onfi.version = 10;
 
 	if (!chip->parameters.onfi.version) {
diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
index ef7e3b4e91ea..015bc3f2fc13 100644
--- a/include/linux/mtd/rawnand.h
+++ b/include/linux/mtd/rawnand.h
@@ -230,6 +230,17 @@ enum nand_ecc_algo {
 /* Keep gcc happy */
 struct nand_chip;
 
+/* ONFI version bits */
+#define ONFI_VERSION_1_0		BIT(1)
+#define ONFI_VERSION_2_0		BIT(2)
+#define ONFI_VERSION_2_1		BIT(3)
+#define ONFI_VERSION_2_2		BIT(4)
+#define ONFI_VERSION_2_3		BIT(5)
+#define ONFI_VERSION_3_0		BIT(6)
+#define ONFI_VERSION_3_1		BIT(7)
+#define ONFI_VERSION_3_2		BIT(8)
+#define ONFI_VERSION_4_0		BIT(9)
+
 /* ONFI features */
 #define ONFI_FEATURE_16_BIT_BUS		(1 << 0)
 #define ONFI_FEATURE_EXT_PARAM_PAGE	(1 << 7)
-- 
2.17.1

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

* [PATCH v4 4/6] mtd: rawnand: micron: add fixup for ONFI revision
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
                   ` (2 preceding siblings ...)
  2018-06-21 10:33 ` [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 10:33 ` [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC Chris Packham
  2018-06-21 10:33 ` [PATCH v4 6/6] mtd: rawnand: micron: detect forced " Chris Packham
  5 siblings, 0 replies; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

Some Micron NAND chips (MT29F1G08ABAFAWP-ITE:F) report 00 00 for the
revision number field of the ONFI parameter page. Rather than rejecting
these outright assume ONFI version 1.0 if the revision number is 00 00.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>
---
This is now qualified on vendor == MICRON. I haven't qualified this
based on specific chips the ABAFA (id=d1) and ABBFA (id=a1) variants are
documented to have this behaviour.

Changes in v2:
- use fixup_onfi_param_page
Changes in v3:
- add code comment next to workaround
Changes in v4:
- use define for ONFI_VERSION

 drivers/mtd/nand/raw/nand_micron.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
index 203faba0a9c1..d30bd4df9b12 100644
--- a/drivers/mtd/nand/raw/nand_micron.c
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -290,6 +290,19 @@ static int micron_nand_init(struct nand_chip *chip)
 	return 0;
 }
 
+static void micron_fixup_onfi_param_page(struct nand_chip *chip,
+					 struct nand_onfi_params *p)
+{
+	/*
+	 * MT29F1G08ABAFAWP-ITE:F and possibly others report 00 00 for the
+	 * revision number field of the ONFI parameter page. Assume ONFI
+	 * version 1.0 if the revision number is 00 00.
+	 */
+	if (le16_to_cpu(p->revision) == 0)
+		p->revision = cpu_to_le16(ONFI_VERSION_1_0);
+}
+
 const struct nand_manufacturer_ops micron_nand_manuf_ops = {
 	.init = micron_nand_init,
+	.fixup_onfi_param_page = micron_fixup_onfi_param_page,
 };
-- 
2.17.1

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

* [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
                   ` (3 preceding siblings ...)
  2018-06-21 10:33 ` [PATCH v4 4/6] mtd: rawnand: micron: add fixup for ONFI revision Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 11:16   ` Boris Brezillon
  2018-06-21 10:33 ` [PATCH v4 6/6] mtd: rawnand: micron: detect forced " Chris Packham
  5 siblings, 1 reply; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

Micron MT29F1G08ABAFAWP-ITE:F supports an on-die ECC with 8 bits
per 512 bytes. Add support for this combination.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- New
Changes in v3:
- Handle reporting of corrected errors that don't require a rewrite, expand
  comment for the ECC status bits.
Changes in v4:
- Use a switch statement for handling ECC status
- Update ecc_stats.corrected

 drivers/mtd/nand/raw/nand_micron.c | 68 ++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
index d30bd4df9b12..f1ecd4986b50 100644
--- a/drivers/mtd/nand/raw/nand_micron.c
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -18,10 +18,28 @@
 #include <linux/mtd/rawnand.h>
 
 /*
- * Special Micron status bit that indicates when the block has been
- * corrected by on-die ECC and should be rewritten
+ * Special Micron status bit 3 indicates that the block has been
+ * corrected by on-die ECC and should be rewritten.
+ *
+ * On chips with 8-bit ECC and additional bit can be used to distinguish
+ * cases where a errors were corrected without needing a rewrite
+ *
+ * Bit 4 Bit 3 Bit 0 Description
+ * ----- ----- ----- -----------
+ * 0     0     0     No Errors
+ * 0     0     1     Multiple uncorrected errors
+ * 0     1     0     4 - 6 errors corrected, recommend rewrite
+ * 0     1     1     Reserved
+ * 1     0     0     1 - 3 errors corrected
+ * 1     0     1     Reserved
+ * 1     1     0     7 - 8 errors corrected, recommend rewrite
  */
-#define NAND_STATUS_WRITE_RECOMMENDED	BIT(3)
+#define NAND_STATUS_MASK		(BIT(4) | BIT(3) | BIT(0))
+#define NAND_STATUS_NO_ERRORS		0
+#define NAND_STATUS_UNCORRECTABLE	BIT(0)
+#define NAND_STATUS_4_6_CORRECTED	BIT(3)
+#define NAND_STATUS_1_3_CORRECTED	BIT(4)
+#define NAND_STATUS_7_8_CORRECTED	(BIT(4) | BIT(3))
 
 struct nand_onfi_vendor_micron {
 	u8 two_plane_read;
@@ -137,18 +155,31 @@ micron_nand_read_page_on_die_ecc(struct mtd_info *mtd, struct nand_chip *chip,
 	if (ret)
 		goto out;
 
-	if (status & NAND_STATUS_FAIL) {
+	/*
+	 * The internal ECC doesn't tell us the number of bitflips
+	 * that have been corrected, but tells us if it recommends to
+	 * rewrite the block. If it's the case, then we pretend we had
+	 * a number of bitflips equal to the ECC strength, which will
+	 * hint the NAND core to rewrite the block.
+	 */
+	switch (status & NAND_STATUS_MASK) {
+	case NAND_STATUS_UNCORRECTABLE:
 		mtd->ecc_stats.failed++;
-	} else if (status & NAND_STATUS_WRITE_RECOMMENDED) {
-		/*
-		 * The internal ECC doesn't tell us the number of bitflips
-		 * that have been corrected, but tells us if it recommends to
-		 * rewrite the block. If it's the case, then we pretend we had
-		 * a number of bitflips equal to the ECC strength, which will
-		 * hint the NAND core to rewrite the block.
-		 */
-		mtd->ecc_stats.corrected += chip->ecc.strength;
+		break;
+	case NAND_STATUS_1_3_CORRECTED:
+		mtd->ecc_stats.corrected++;
+		max_bitflips = 1;
+		break;
+	case NAND_STATUS_4_6_CORRECTED:
+		mtd->ecc_stats.corrected += 4;
+		/* rewrite recommended */
+		max_bitflips = chip->ecc.strength;
+		break;
+	case NAND_STATUS_7_8_CORRECTED:
+		mtd->ecc_stats.corrected += 7;
+		/* rewrite recommended */
 		max_bitflips = chip->ecc.strength;
+		break;
 	}
 
 	ret = nand_read_data_op(chip, buf, mtd->writesize, false);
@@ -239,13 +270,6 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip)
 	if (feature[0] & ONFI_FEATURE_ON_DIE_ECC_EN)
 		return MICRON_ON_DIE_MANDATORY;
 
-	/*
-	 * Some Micron NANDs have an on-die ECC of 4/512, some other
-	 * 8/512. We only support the former.
-	 */
-	if (chip->ecc_strength_ds != 4)
-		return MICRON_ON_DIE_UNSUPPORTED;
-
 	return MICRON_ON_DIE_SUPPORTED;
 }
 
@@ -275,9 +299,9 @@ static int micron_nand_init(struct nand_chip *chip)
 			return -EINVAL;
 		}
 
-		chip->ecc.bytes = 8;
+		chip->ecc.bytes = chip->ecc_strength_ds * 2;
 		chip->ecc.size = 512;
-		chip->ecc.strength = 4;
+		chip->ecc.strength = chip->ecc_strength_ds;
 		chip->ecc.algo = NAND_ECC_BCH;
 		chip->ecc.read_page = micron_nand_read_page_on_die_ecc;
 		chip->ecc.write_page = micron_nand_write_page_on_die_ecc;
-- 
2.17.1

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

* [PATCH v4 6/6] mtd: rawnand: micron: detect forced on-die ECC
  2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
                   ` (4 preceding siblings ...)
  2018-06-21 10:33 ` [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC Chris Packham
@ 2018-06-21 10:33 ` Chris Packham
  2018-06-21 11:20   ` Boris Brezillon
  5 siblings, 1 reply; 10+ messages in thread
From: Chris Packham @ 2018-06-21 10:33 UTC (permalink / raw)
  To: miquel.raynal, boris.brezillon, dwmw2, computersforpeace,
	linux-mtd
  Cc: linux-kernel, Chris Packham, Richard Weinberger, Marek Vasut

Some Micron NAND chips have on-die ECC forceably enabled. The detect
these based on chip ID as there seems to be no other way of
distinguishing these chips from those that have optional support for
on-die ECC.

When a chip with mandatory on-die ECC is detected change the current ECC
mode to on-die.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
I'm not convinced that just changing chip->ecc.mode is sensible. An
alternative I considered was only proceeding if the ecc.mode is set to
ON_DIE.

Changes in v4:
- New

 drivers/mtd/nand/raw/nand_micron.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
index f1ecd4986b50..9ba9007a9a06 100644
--- a/drivers/mtd/nand/raw/nand_micron.c
+++ b/drivers/mtd/nand/raw/nand_micron.c
@@ -227,6 +227,14 @@ enum {
 	MICRON_ON_DIE_MANDATORY,
 };
 
+/*
+ * These parts are known to have on-die ECC forceably enabled
+ */
+static u8 micron_on_die_ecc[] = {
+	0xd1, /* MT29F1G08ABAFA */
+	0xa1, /* MT29F1G08ABBFA */
+};
+
 /*
  * Try to detect if the NAND support on-die ECC. To do this, we enable
  * the feature, and read back if it has been enabled as expected. We
@@ -241,6 +249,11 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip)
 {
 	u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = { 0, };
 	int ret;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(micron_on_die_ecc); i++)
+		if (chip->id.data[1] == micron_on_die_ecc[i])
+			return MICRON_ON_DIE_MANDATORY;
 
 	if (!chip->parameters.onfi.version)
 		return MICRON_ON_DIE_UNSUPPORTED;
@@ -289,8 +302,8 @@ static int micron_nand_init(struct nand_chip *chip)
 	ondie = micron_supports_on_die_ecc(chip);
 
 	if (ondie == MICRON_ON_DIE_MANDATORY) {
-		pr_err("On-die ECC forcefully enabled, not supported\n");
-		return -EINVAL;
+		pr_info("On-die ECC forcefully enabled\n");
+		chip->ecc.mode = NAND_ECC_ON_DIE;
 	}
 
 	if (chip->ecc.mode == NAND_ECC_ON_DIE) {
-- 
2.17.1

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

* Re: [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits
  2018-06-21 10:33 ` [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits Chris Packham
@ 2018-06-21 11:05   ` Boris Brezillon
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-06-21 11:05 UTC (permalink / raw)
  To: Chris Packham
  Cc: miquel.raynal, dwmw2, computersforpeace, linux-mtd, linux-kernel,
	Richard Weinberger, Marek Vasut

On Thu, 21 Jun 2018 22:33:25 +1200
Chris Packham <chris.packham@alliedtelesis.co.nz> wrote:

> Add defines for the ONFI version bits and use them in
> nand_flash_detect_onfi().
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Reviewed-by: Boris Brezillon <boris.brezillon@bootlin.com>

> ---
> Changes in v4:
> - New
> 
>  drivers/mtd/nand/raw/nand_base.c | 10 +++++-----
>  include/linux/mtd/rawnand.h      | 11 +++++++++++
>  2 files changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 65250308c82d..36048e0cf1f5 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -5178,15 +5178,15 @@ static int nand_flash_detect_onfi(struct nand_chip *chip)
>  
>  	/* Check version */
>  	val = le16_to_cpu(p->revision);
> -	if (val & (1 << 5))
> +	if (val & ONFI_VERSION_2_3)
>  		chip->parameters.onfi.version = 23;
> -	else if (val & (1 << 4))
> +	else if (val & ONFI_VERSION_2_2)
>  		chip->parameters.onfi.version = 22;
> -	else if (val & (1 << 3))
> +	else if (val & ONFI_VERSION_2_1)
>  		chip->parameters.onfi.version = 21;
> -	else if (val & (1 << 2))
> +	else if (val & ONFI_VERSION_2_0)
>  		chip->parameters.onfi.version = 20;
> -	else if (val & (1 << 1))
> +	else if (val & ONFI_VERSION_1_0)
>  		chip->parameters.onfi.version = 10;
>  
>  	if (!chip->parameters.onfi.version) {
> diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h
> index ef7e3b4e91ea..015bc3f2fc13 100644
> --- a/include/linux/mtd/rawnand.h
> +++ b/include/linux/mtd/rawnand.h
> @@ -230,6 +230,17 @@ enum nand_ecc_algo {
>  /* Keep gcc happy */
>  struct nand_chip;
>  
> +/* ONFI version bits */
> +#define ONFI_VERSION_1_0		BIT(1)
> +#define ONFI_VERSION_2_0		BIT(2)
> +#define ONFI_VERSION_2_1		BIT(3)
> +#define ONFI_VERSION_2_2		BIT(4)
> +#define ONFI_VERSION_2_3		BIT(5)
> +#define ONFI_VERSION_3_0		BIT(6)
> +#define ONFI_VERSION_3_1		BIT(7)
> +#define ONFI_VERSION_3_2		BIT(8)
> +#define ONFI_VERSION_4_0		BIT(9)
> +
>  /* ONFI features */
>  #define ONFI_FEATURE_16_BIT_BUS		(1 << 0)
>  #define ONFI_FEATURE_EXT_PARAM_PAGE	(1 << 7)

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

* Re: [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC
  2018-06-21 10:33 ` [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC Chris Packham
@ 2018-06-21 11:16   ` Boris Brezillon
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-06-21 11:16 UTC (permalink / raw)
  To: Chris Packham
  Cc: miquel.raynal, dwmw2, computersforpeace, linux-mtd, linux-kernel,
	Richard Weinberger, Marek Vasut

On Thu, 21 Jun 2018 22:33:27 +1200
Chris Packham <chris.packham@alliedtelesis.co.nz> wrote:

> Micron MT29F1G08ABAFAWP-ITE:F supports an on-die ECC with 8 bits
> per 512 bytes. Add support for this combination.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> Changes in v2:
> - New
> Changes in v3:
> - Handle reporting of corrected errors that don't require a rewrite, expand
>   comment for the ECC status bits.
> Changes in v4:
> - Use a switch statement for handling ECC status
> - Update ecc_stats.corrected
> 
>  drivers/mtd/nand/raw/nand_micron.c | 68 ++++++++++++++++++++----------
>  1 file changed, 46 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
> index d30bd4df9b12..f1ecd4986b50 100644
> --- a/drivers/mtd/nand/raw/nand_micron.c
> +++ b/drivers/mtd/nand/raw/nand_micron.c
> @@ -18,10 +18,28 @@
>  #include <linux/mtd/rawnand.h>
>  
>  /*
> - * Special Micron status bit that indicates when the block has been
> - * corrected by on-die ECC and should be rewritten
> + * Special Micron status bit 3 indicates that the block has been
> + * corrected by on-die ECC and should be rewritten.
> + *
> + * On chips with 8-bit ECC and additional bit can be used to distinguish
> + * cases where a errors were corrected without needing a rewrite
> + *
> + * Bit 4 Bit 3 Bit 0 Description
> + * ----- ----- ----- -----------
> + * 0     0     0     No Errors
> + * 0     0     1     Multiple uncorrected errors
> + * 0     1     0     4 - 6 errors corrected, recommend rewrite
> + * 0     1     1     Reserved
> + * 1     0     0     1 - 3 errors corrected
> + * 1     0     1     Reserved
> + * 1     1     0     7 - 8 errors corrected, recommend rewrite
>   */
> -#define NAND_STATUS_WRITE_RECOMMENDED	BIT(3)
> +#define NAND_STATUS_MASK		(BIT(4) | BIT(3) | BIT(0))
> +#define NAND_STATUS_NO_ERRORS		0
> +#define NAND_STATUS_UNCORRECTABLE	BIT(0)
> +#define NAND_STATUS_4_6_CORRECTED	BIT(3)
> +#define NAND_STATUS_1_3_CORRECTED	BIT(4)
> +#define NAND_STATUS_7_8_CORRECTED	(BIT(4) | BIT(3))

NAND_ECC_STATUS_ prefix would be better than NAND_STATUS_

>  
>  struct nand_onfi_vendor_micron {
>  	u8 two_plane_read;
> @@ -137,18 +155,31 @@ micron_nand_read_page_on_die_ecc(struct mtd_info *mtd, struct nand_chip *chip,
>  	if (ret)
>  		goto out;
>  
> -	if (status & NAND_STATUS_FAIL) {
> +	/*
> +	 * The internal ECC doesn't tell us the number of bitflips
> +	 * that have been corrected, but tells us if it recommends to
> +	 * rewrite the block. If it's the case, then we pretend we had
> +	 * a number of bitflips equal to the ECC strength, which will
> +	 * hint the NAND core to rewrite the block.
> +	 */
> +	switch (status & NAND_STATUS_MASK) {
> +	case NAND_STATUS_UNCORRECTABLE:

I'd recommend handling 8bit and 4bit on-die ECC separately (create on
subfunction per kind of ECC), and not using the same _MASK, just in
case unused bits value have a different meaning or are simply not set
to 0 by default.

>  		mtd->ecc_stats.failed++;
> -	} else if (status & NAND_STATUS_WRITE_RECOMMENDED) {
> -		/*
> -		 * The internal ECC doesn't tell us the number of bitflips
> -		 * that have been corrected, but tells us if it recommends to
> -		 * rewrite the block. If it's the case, then we pretend we had
> -		 * a number of bitflips equal to the ECC strength, which will
> -		 * hint the NAND core to rewrite the block.
> -		 */
> -		mtd->ecc_stats.corrected += chip->ecc.strength;
> +		break;
> +	case NAND_STATUS_1_3_CORRECTED:
> +		mtd->ecc_stats.corrected++;
> +		max_bitflips = 1;

Should you always take the max of the range, so here:

		mtd->ecc_stats.corrected += 3;
		max_bitflips = 3;

> +		break;
> +	case NAND_STATUS_4_6_CORRECTED:
> +		mtd->ecc_stats.corrected += 4;

					 += 6;

> +		/* rewrite recommended */
> +		max_bitflips = chip->ecc.strength;

Here it should be 6, not chip->ecc.strength.

> +		break;
> +	case NAND_STATUS_7_8_CORRECTED:
> +		mtd->ecc_stats.corrected += 7;

					 += 8;

> +		/* rewrite recommended */
>  		max_bitflips = chip->ecc.strength;
> +		break;
>  	}
>  
>  	ret = nand_read_data_op(chip, buf, mtd->writesize, false);
> @@ -239,13 +270,6 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip)
>  	if (feature[0] & ONFI_FEATURE_ON_DIE_ECC_EN)
>  		return MICRON_ON_DIE_MANDATORY;
>  
> -	/*
> -	 * Some Micron NANDs have an on-die ECC of 4/512, some other
> -	 * 8/512. We only support the former.
> -	 */
> -	if (chip->ecc_strength_ds != 4)
> -		return MICRON_ON_DIE_UNSUPPORTED;

I'd prefer to keep an explicit check here rather than accepting
everything. See how 8 and 4 bit ECC differ, it's likely to be the case
if Micron ever has a 16bit ECC.

> -
>  	return MICRON_ON_DIE_SUPPORTED;
>  }
>  
> @@ -275,9 +299,9 @@ static int micron_nand_init(struct nand_chip *chip)
>  			return -EINVAL;
>  		}
>  
> -		chip->ecc.bytes = 8;
> +		chip->ecc.bytes = chip->ecc_strength_ds * 2;
>  		chip->ecc.size = 512;
> -		chip->ecc.strength = 4;
> +		chip->ecc.strength = chip->ecc_strength_ds;
>  		chip->ecc.algo = NAND_ECC_BCH;
>  		chip->ecc.read_page = micron_nand_read_page_on_die_ecc;
>  		chip->ecc.write_page = micron_nand_write_page_on_die_ecc;

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

* Re: [PATCH v4 6/6] mtd: rawnand: micron: detect forced on-die ECC
  2018-06-21 10:33 ` [PATCH v4 6/6] mtd: rawnand: micron: detect forced " Chris Packham
@ 2018-06-21 11:20   ` Boris Brezillon
  0 siblings, 0 replies; 10+ messages in thread
From: Boris Brezillon @ 2018-06-21 11:20 UTC (permalink / raw)
  To: Chris Packham
  Cc: miquel.raynal, dwmw2, computersforpeace, linux-mtd, linux-kernel,
	Richard Weinberger, Marek Vasut

On Thu, 21 Jun 2018 22:33:28 +1200
Chris Packham <chris.packham@alliedtelesis.co.nz> wrote:

> Some Micron NAND chips have on-die ECC forceably enabled. The detect
> these based on chip ID as there seems to be no other way of
> distinguishing these chips from those that have optional support for
> on-die ECC.
> 
> When a chip with mandatory on-die ECC is detected change the current ECC
> mode to on-die.
> 
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> I'm not convinced that just changing chip->ecc.mode is sensible. An
> alternative I considered was only proceeding if the ecc.mode is set to
> ON_DIE.
> 
> Changes in v4:
> - New
> 
>  drivers/mtd/nand/raw/nand_micron.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c
> index f1ecd4986b50..9ba9007a9a06 100644
> --- a/drivers/mtd/nand/raw/nand_micron.c
> +++ b/drivers/mtd/nand/raw/nand_micron.c
> @@ -227,6 +227,14 @@ enum {
>  	MICRON_ON_DIE_MANDATORY,
>  };
>  
> +/*
> + * These parts are known to have on-die ECC forceably enabled
> + */
> +static u8 micron_on_die_ecc[] = {
> +	0xd1, /* MT29F1G08ABAFA */
> +	0xa1, /* MT29F1G08ABBFA */
> +};
> +
>  /*
>   * Try to detect if the NAND support on-die ECC. To do this, we enable
>   * the feature, and read back if it has been enabled as expected. We
> @@ -241,6 +249,11 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip)
>  {
>  	u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = { 0, };
>  	int ret;
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(micron_on_die_ecc); i++)
> +		if (chip->id.data[1] == micron_on_die_ecc[i])
> +			return MICRON_ON_DIE_MANDATORY;
>  
>  	if (!chip->parameters.onfi.version)
>  		return MICRON_ON_DIE_UNSUPPORTED;
> @@ -289,8 +302,8 @@ static int micron_nand_init(struct nand_chip *chip)
>  	ondie = micron_supports_on_die_ecc(chip);
>  
>  	if (ondie == MICRON_ON_DIE_MANDATORY) {
> -		pr_err("On-die ECC forcefully enabled, not supported\n");
> -		return -EINVAL;
> +		pr_info("On-die ECC forcefully enabled\n");
> +		chip->ecc.mode = NAND_ECC_ON_DIE;

No, you can't do that, because most NAND drivers simply don't support
NAND_ECC_ON_DIE, and will override chip->ecc.mode without even checking
its value. You should just fail if chip->ecc.mode != NAND_ECC_ON_DIE.

		if (chip->ecc.mode != NAND_ECC_ON_DIE) {
			pr_err("On-die ECC can't be disabled\n");
			return -EINVAL;
		}
>  	}
>  
>  	if (chip->ecc.mode == NAND_ECC_ON_DIE) {

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

end of thread, other threads:[~2018-06-21 11:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-21 10:33 [PATCH v4 0/6] mtd: rawnand: support MT29F1G08ABAFAWP-ITE:F Chris Packham
2018-06-21 10:33 ` [PATCH v4 1/6] mtd: rawnand: marvell: Handle on-die ECC Chris Packham
2018-06-21 10:33 ` [PATCH v4 2/6] mtd: rawnand: add manufacturer fixup for ONFI parameter page Chris Packham
2018-06-21 10:33 ` [PATCH v4 3/6] mtd: rawnand: add defines for ONFI version bits Chris Packham
2018-06-21 11:05   ` Boris Brezillon
2018-06-21 10:33 ` [PATCH v4 4/6] mtd: rawnand: micron: add fixup for ONFI revision Chris Packham
2018-06-21 10:33 ` [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC Chris Packham
2018-06-21 11:16   ` Boris Brezillon
2018-06-21 10:33 ` [PATCH v4 6/6] mtd: rawnand: micron: detect forced " Chris Packham
2018-06-21 11:20   ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).