Skip to contentSkip to conversation

mtd: fsl_upm: Support NAND ECC DTS properties

PATCH Superseded Aaron Sierra 4 participants 9 messages Nov 8, 2014 – Dec 17, 2014 5 messages not in the archive

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/1 mtd: fsl_upm: Support NAND ECC DTS properties

From: Jordan Friendshuh <[email protected]>

Support the generic nand-ecc-mode and nand-ecc-strength device-tree properties with the Freescale UPM NAND driver.

This patch preserves the default software ECC mode while adding the ability to use BCH ECC for larger NAND devices.

---
v2:
* Now using ECC mode and strength helpers from of_mtd.h
* ECC mode and strength checking is more robust

 .../devicetree/bindings/mtd/fsl-upm-nand.txt       |  2 +
 drivers/mtd/nand/Kconfig                           |  1 +
 drivers/mtd/nand/fsl_upm.c                         | 51 +++++++++++++++++++---
 3 files changed, 49 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt +2 -0
index fce4894..a9906f6 100644
@@ -18,6 +18,8 @@ Optional properties:
 - chip-delay : chip dependent delay for transferring data from array to
 	read registers (tR). Required if property "gpios" is not used
 	(R/B# pins not connected).
+- nand-ecc-mode : as defined by nand.txt ("soft" and "soft_bch", only).
+- nand-ecc-strength : as defined by nand.txt.
 
 Each flash chip described may optionally contain additional sub-nodes
 describing partitions of the address space. See partition.txt for more
drivers/mtd/nand/Kconfig +1 -0
index f1cf503..85c0243 100644
@@ -439,6 +439,7 @@ config MTD_NAND_FSL_UPM
 	tristate "Support for NAND on Freescale UPM"
 	depends on PPC_83xx || PPC_85xx
 	select FSL_LBC
+	select MTD_NAND_ECC_BCH
 	help
 	  Enables support for NAND Flash chips wired onto Freescale PowerPC
 	  processor localbus with User-Programmable Machine support.
drivers/mtd/nand/fsl_upm.c +46 -5

75 lines not on this page · raw message

Signature · 5 lines
1.9.1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

A message that is not in the archive (sent off-list or not yet received): 1854666513.5578.1415473916534.JavaMail.zimbra-AQeFf1F/[email protected]

#3 lore raw
Quoted 25 lines · Aaron Sierra

From: Jordan Friendshuh <jfriendshuh-AQeFf1F/[email protected]>

Support the generic nand-ecc-mode and nand-ecc-strength device-tree properties with the Freescale UPM NAND driver.

This patch preserves the default software ECC mode while adding the ability to use BCH ECC for larger NAND devices.

---
v2:
* Now using ECC mode and strength helpers from of_mtd.h
* ECC mode and strength checking is more robust

 .../devicetree/bindings/mtd/fsl-upm-nand.txt       |  2 +
 drivers/mtd/nand/Kconfig                           |  1 +
 drivers/mtd/nand/fsl_upm.c                         | 51 +++++++++++++++++++---
 3 files changed, 49 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt +0 -0
index fce4894..a9906f6 100644

Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt Optional properties: · line 23

Quoted 6 lines
Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt +2 -0
@@ -18,6 +18,8 @@ Optional properties:
 - chip-delay : chip dependent delay for transferring data from array to
 	read registers (tR). Required if property "gpios" is not used
 	(R/B# pins not connected).
+- nand-ecc-mode : as defined by nand.txt ("soft" and "soft_bch", only).
+- nand-ecc-strength : as defined by nand.txt.
 

The nand.txt recommends that each binding documents the way these properties are interpreted.

Moreover, there's no nand-ecc-step usage? Are you assuming a 512-byte size?

Signature · 6 lines
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

----- Original Message -----

Quoted 25 lines

From: "Ezequiel Garcia" <[email protected]>
Sent: Saturday, November 22, 2014 6:55:42 PM

Quoted 21 lines · Aaron Sierra

From: Jordan Friendshuh <[email protected]>

Support the generic nand-ecc-mode and nand-ecc-strength device-tree properties with the Freescale UPM NAND driver.

This patch preserves the default software ECC mode while adding the ability to use BCH ECC for larger NAND devices.

---
v2:
* Now using ECC mode and strength helpers from of_mtd.h
* ECC mode and strength checking is more robust

 .../devicetree/bindings/mtd/fsl-upm-nand.txt       |  2 +
 drivers/mtd/nand/Kconfig                           |  1 +
 drivers/mtd/nand/fsl_upm.c                         | 51
 +++++++++++++++++++---
 3 files changed, 49 insertions(+), 5 deletions(-)
Quoted 15 lines

Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt Optional properties: · line 23

Quoted 12 lines
Documentation/devicetree/bindings/mtd/fsl-upm-nand.txt +2 -0
index fce4894..a9906f6 100644
@@ -18,6 +18,8 @@ Optional properties:
 - chip-delay : chip dependent delay for transferring data from array to
 	read registers (tR). Required if property "gpios" is not used
 	(R/B# pins not connected).
+- nand-ecc-mode : as defined by nand.txt ("soft" and "soft_bch", only).
+- nand-ecc-strength : as defined by nand.txt.
 

The nand.txt recommends that each binding documents the way these properties are interpreted.

Ezequiel,
I assume you are referring to this statement, "implementations are encouraged to further specify the value(s) they support."

That is the only statement I found requesting documentation. I believe that request is satisfied, since I listed all of the modes that the driver would support with my patch applied. I used mxc-nand.txt as a reference.

Quoted 1 line

Moreover, there's no nand-ecc-step usage? Are you assuming a 512-byte size?

The ecc.bytes value is currently left to be calculated by the NAND_ECC_SOFT_BCH case in nand_base.c. That calculation assumes a 512-byte step size.

-Aaron

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#5 lore raw
In reply to a message not in the archive

On 11/08/2014 04:11 PM, Aaron Sierra wrote:
[..]

Quoted 13 lines
drivers/mtd/nand/fsl_upm.c +13 -0
+
+	/* We know mode is either NAND_ECC_SOFT or NAND_ECC_SOFT_BCH */
+	if (strength < 0 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev,
+			"ECC BCH mode requires nand-ecc-strength property");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 0) {
+		dev_err(fun->dev, "ECC strength of 0 bits is unsupported");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 1 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev, "ECC BCH mode requires > 1-bit strength");

drivers/mtd/nand/fsl_upm.c static int fun_chip_init(struct fsl_upm_nand *fun, · line 216

Quoted 10 lines
drivers/mtd/nand/fsl_upm.c +10 -0
+		ret = -EINVAL;
+		goto err;
+	} else if (strength > 1 && mode == NAND_ECC_SOFT) {
+		dev_warn(fun->dev,
+			"Forcing ECC BCH due to %d-bit strength\n", strength);
+		mode = NAND_ECC_SOFT_BCH;
+	}
+	fun->chip.ecc.mode = mode;
+	fun->chip.ecc.strength = strength;
+

Aside from my comment about the lack of ECC specification in the binding, I think the above is wrong.

You don't have hardware ECC, but software ECC (either hamming or BCH). So, you don't need to specify any nand_ecc_ctrl.strength (i.e. ecc.strength above).

It'll be set by the NAND core and override any value you set See nand_scan_tail.

So, I'd say you just need to specify the nand-ecc-mode in the devicetree binding.

The nand-ecc-strength and nand-ecc-step-size are meant for controllers with hardware ECC support.

Signature · 6 lines
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 5474E1DB.1090207-30ULvvUtt6G51wMPkGsGjgyUoB5FGQPZ@public.gmane.org

#7 lore raw
Quoted 32 lines

From: "Ezequiel Garcia" <[email protected]>
Sent: Tuesday, November 25, 2014 2:08:59 PM

On 11/08/2014 04:11 PM, Aaron Sierra wrote:
[..]

Quoted 13 lines
drivers/mtd/nand/fsl_upm.c +13 -0
+
+	/* We know mode is either NAND_ECC_SOFT or NAND_ECC_SOFT_BCH */
+	if (strength < 0 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev,
+			"ECC BCH mode requires nand-ecc-strength property");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 0) {
+		dev_err(fun->dev, "ECC strength of 0 bits is unsupported");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 1 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev, "ECC BCH mode requires > 1-bit strength");

drivers/mtd/nand/fsl_upm.c static int fun_chip_init(struct fsl_upm_nand *fun, · line 216

Quoted 10 lines
drivers/mtd/nand/fsl_upm.c +10 -0
+		ret = -EINVAL;
+		goto err;
+	} else if (strength > 1 && mode == NAND_ECC_SOFT) {
+		dev_warn(fun->dev,
+			"Forcing ECC BCH due to %d-bit strength\n", strength);
+		mode = NAND_ECC_SOFT_BCH;
+	}
+	fun->chip.ecc.mode = mode;
+	fun->chip.ecc.strength = strength;
+

Aside from my comment about the lack of ECC specification in the binding, I think the above is wrong.

Quoted 6 lines

You don't have hardware ECC, but software ECC (either hamming or BCH). So, you don't need to specify any nand_ecc_ctrl.strength (i.e. ecc.strength above).

It'll be set by the NAND core and override any value you set See nand_scan_tail.

Ezequiel,
This patch was originally the second of two patches. The first was applied to l2-mtd.git on 11/5/2014:

mtd: nand: Base BCH ECC bytes on required strength

It affects the code in nand_scan_tail that you're referring to so that it looks like this:

		/*
		 * Board driver should supply ecc.size and ecc.bytes values to
		 * select how many bits are correctable; see nand_bch_init()
		 * for details. Otherwise, default to 4 bits for large page
		 * devices.
		 */
		if (!ecc->size && (mtd->oobsize >= 64)) {
			ecc->size = 512;
			ecc->bytes = DIV_ROUND_UP(13 * ecc->strength, 8);
		}
		ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
					       &ecc->layout);
		if (!ecc->priv) {
			pr_warn("BCH ECC initialization failed!\n");
			BUG();
		}
		ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);

In this case ecc->strength is unnecessarily recalculated at the end and ecc->strength isn't checked for zero in the initial calculation. Perhaps this block in nand_scan_tail should be patched again to preserve the original behaviour if ecc->strength or ecc->size are zero.

The only other in-kernel user of SOFT_BCH is sunxi_nand.c and it calculates ecc->bytes from ecc->size and ecc->strength itself, so it has defined all three values by this point.

Quoted 5 lines

So, I'd say you just need to specify the nand-ecc-mode in the devicetree binding.

The nand-ecc-strength and nand-ecc-step-size are meant for controllers with hardware ECC support.

Software BCH allows controllers without hardware support for multiple bit correction to be used with NAND devices that require multiple bit correction, so like a hardware controller it needs to know how many bits to correct.

Quoted 4 lines

--
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 412246484.206926.1416953948359.JavaMail.zimbra-AQeFf1F/[email protected]

#9 lore raw
Quoted 66 lines · Aaron Sierra
Quoted 32 lines

From: "Ezequiel Garcia" <[email protected]>
Sent: Tuesday, November 25, 2014 2:08:59 PM

On 11/08/2014 04:11 PM, Aaron Sierra wrote:
[..]

Quoted 13 lines
drivers/mtd/nand/fsl_upm.c +13 -0
+
+	/* We know mode is either NAND_ECC_SOFT or NAND_ECC_SOFT_BCH */
+	if (strength < 0 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev,
+			"ECC BCH mode requires nand-ecc-strength property");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 0) {
+		dev_err(fun->dev, "ECC strength of 0 bits is unsupported");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 1 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev, "ECC BCH mode requires > 1-bit strength");

drivers/mtd/nand/fsl_upm.c static int fun_chip_init(struct fsl_upm_nand *fun, · line 216

Quoted 10 lines
drivers/mtd/nand/fsl_upm.c +10 -0
+		ret = -EINVAL;
+		goto err;
+	} else if (strength > 1 && mode == NAND_ECC_SOFT) {
+		dev_warn(fun->dev,
+			"Forcing ECC BCH due to %d-bit strength\n", strength);
+		mode = NAND_ECC_SOFT_BCH;
+	}
+	fun->chip.ecc.mode = mode;
+	fun->chip.ecc.strength = strength;
+

Aside from my comment about the lack of ECC specification in the binding, I think the above is wrong.

Quoted 6 lines

You don't have hardware ECC, but software ECC (either hamming or BCH). So, you don't need to specify any nand_ecc_ctrl.strength (i.e. ecc.strength above).

It'll be set by the NAND core and override any value you set See nand_scan_tail.

Ezequiel,
This patch was originally the second of two patches. The first was applied to l2-mtd.git on 11/5/2014:

mtd: nand: Base BCH ECC bytes on required strength

It affects the code in nand_scan_tail that you're referring to so that it looks like this:

		/*
		 * Board driver should supply ecc.size and ecc.bytes values to
		 * select how many bits are correctable; see nand_bch_init()
		 * for details. Otherwise, default to 4 bits for large page
		 * devices.
		 */
		if (!ecc->size && (mtd->oobsize >= 64)) {
			ecc->size = 512;
			ecc->bytes = DIV_ROUND_UP(13 * ecc->strength, 8);
		}
		ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
					       &ecc->layout);
		if (!ecc->priv) {
			pr_warn("BCH ECC initialization failed!\n");
			BUG();
		}
		ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);
Quoted 5 lines

In this case ecc->strength is unnecessarily recalculated at the end and ecc->strength isn't checked for zero in the initial calculation. Perhaps this block in nand_scan_tail should be patched again to preserve the original behaviour if ecc->strength or ecc->size are zero.

Exactly, I was talking about that snippet. I missed the fact that ecc.strength is used to get bytes, and then re-calculated. Some comments are definitely needed there.

Quoted 7 lines

The only other in-kernel user of SOFT_BCH is sunxi_nand.c and it calculates ecc->bytes from ecc->size and ecc->strength itself, so it has defined all three values by this point.

Quoted 3 lines

So, I'd say you just need to specify the nand-ecc-mode in the devicetree binding.

Quoted 8 lines
Quoted 2 lines

The nand-ecc-strength and nand-ecc-step-size are meant for controllers with hardware ECC support.

Software BCH allows controllers without hardware support for multiple bit correction to be used with NAND devices that require multiple bit correction, so like a hardware controller it needs to know how many bits to correct.

Right, right.

I'd say you should require an ECC step size in your binding, instead of assuming the 512-byte that gets set if the ecc.size is 0.

BTW, how does this patch deal with old devicetree files?

Signature · 6 lines
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 547505E7.7000502-30ULvvUtt6G51wMPkGsGjgyUoB5FGQPZ@public.gmane.org

#11 lore raw

----- Original Message -----

Quoted 34 lines

From: "Ezequiel Garcia" <[email protected]>
Sent: Tuesday, November 25, 2014 4:42:47 PM

Quoted 29 lines · Aaron Sierra
Quoted 29 lines

From: "Ezequiel Garcia" <[email protected]>
Sent: Tuesday, November 25, 2014 2:08:59 PM

On 11/08/2014 04:11 PM, Aaron Sierra wrote:
[..]

Quoted 23 lines
(quoted diff) +23 -0
+
+	/* We know mode is either NAND_ECC_SOFT or NAND_ECC_SOFT_BCH */
+	if (strength < 0 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev,
+			"ECC BCH mode requires nand-ecc-strength property");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 0) {
+		dev_err(fun->dev, "ECC strength of 0 bits is unsupported");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength == 1 && mode == NAND_ECC_SOFT_BCH) {
+		dev_err(fun->dev, "ECC BCH mode requires > 1-bit strength");
+		ret = -EINVAL;
+		goto err;
+	} else if (strength > 1 && mode == NAND_ECC_SOFT) {
+		dev_warn(fun->dev,
+			"Forcing ECC BCH due to %d-bit strength\n", strength);
+		mode = NAND_ECC_SOFT_BCH;
+	}
+	fun->chip.ecc.mode = mode;
+	fun->chip.ecc.strength = strength;
+

[ snip ]

Quoted 2 lines

I'd say you should require an ECC step size in your binding, instead of assuming the 512-byte that gets set if the ecc.size is 0.

Yes, I agree that the fsl_upm driver should require that nand-ecc-step-size and nand-ecc-strength both be defined with "soft_bch".

Quoted 1 line

BTW, how does this patch deal with old devicetree files?

The fsl_upm driver previously only supported 1-bit "soft" ECC, so _this_ patch expects that existing device trees don't define nand-ecc-strength or nand-ecc-mode. In that case "soft" ECC will be detected and used.

However, if for some reason an existing device tree defines nand-ecc-strength, then the snippet that you provided above shows that the ECC mode would be overridden (forcing "soft_bch" for ECC strength values greater than 1).

-Aaron
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw
In reply to a message not in the archive

Hi Aaron,

Quoted 8 lines · Aaron Sierra

From: Jordan Friendshuh <jfriendshuh-AQeFf1F/[email protected]>

Support the generic nand-ecc-mode and nand-ecc-strength device-tree properties with the Freescale UPM NAND driver.

This patch preserves the default software ECC mode while adding the ability to use BCH ECC for larger NAND devices.

Quoted 6 lines

---
v2:
* Now using ECC mode and strength helpers from of_mtd.h
* ECC mode and strength checking is more robust

Should I be expecting an update? Ezequiel made a few comments, and I'm not sure if you were planning any action based on them.

Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

----- Original Message -----

Quoted 21 lines

From: "Brian Norris" <[email protected]>
Sent: Tuesday, December 16, 2014 6:35:06 PM

Hi Aaron,

Quoted 8 lines · Aaron Sierra

From: Jordan Friendshuh <[email protected]>

Support the generic nand-ecc-mode and nand-ecc-strength device-tree properties with the Freescale UPM NAND driver.

This patch preserves the default software ECC mode while adding the ability to use BCH ECC for larger NAND devices.

Quoted 6 lines

---
v2:
* Now using ECC mode and strength helpers from of_mtd.h
* ECC mode and strength checking is more robust

Quoted 2 lines

Should I be expecting an update? Ezequiel made a few comments, and I'm not sure if you were planning any action based on them.

Brian,

Yes, I intend to provide an updated patch based on Ezequiel's comments. Sorry for not being clear about this earlier. I thought I would have done the work by now.

-Aaron

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/