Skip to contentSkip to conversation

nand_base: SOFT_BCH: Request strength over bytes

PATCH Superseded Aaron Sierra 3 participants 6 messages Jan 13, 2015 – Feb 2, 2015 1 message not in the archive

Subsystems (3)
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 1/2 nand_base: SOFT_BCH: Request strength over bytes

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

---
 drivers/mtd/nand/nand_base.c  | 21 +++++++++++++++------
 drivers/mtd/nand/sunxi_nand.c |  2 --
 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +15 -6
index 41585df..993612c 100644
@@ -4028,22 +4028,31 @@ int nand_scan_tail(struct mtd_info *mtd)
 		ecc->read_oob = nand_read_oob_std;
 		ecc->write_oob = nand_write_oob_std;
 		/*
-		 * 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.
+		 * Board driver should supply ecc.size and ecc.strength values
+		 * to select how many bits are correctable. 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->strength = 4;
 		}
+
+		/*
+		 * We previously recommended drivers pass ecc.size and
+		 * ecc.bytes. Continue to support drivers that do.
+		 * See nand_bch_init() for details.
+		 */
+		if (ecc->bytes && !ecc->strength)
+			ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);
+
+		ecc->bytes = DIV_ROUND_UP(
+				ecc->strength * fls(8 * ecc->size), 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);
 		break;
 
 	case NAND_ECC_NONE:
drivers/mtd/nand/sunxi_nand.c +0 -2
index ccaa8e2..6f93b29 100644
@@ -1110,8 +1110,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
 
 	switch (ecc->mode) {
 	case NAND_ECC_SOFT_BCH:
-		ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * ecc->size),
-					  8);
 		break;
 	case NAND_ECC_HW:
 		ret = sunxi_nand_hw_ecc_ctrl_init(mtd, ecc, np);
Signature · 1 line
1.9.1
Reviewed-by on v1 1/2
#2 lore raw

Hi Aaron,

Quoted 11 lines · On Mon, 12 Jan 2015 18:35:55 -0600 (CST) Aaron Sierra <[email protected]>…

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

Apart from the nit below, you can add my:

Quoted 26 lines
---
 drivers/mtd/nand/nand_base.c  | 21 +++++++++++++++------
 drivers/mtd/nand/sunxi_nand.c |  2 --
 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +3 -5
index 41585df..993612c 100644
@@ -4028,22 +4028,31 @@ int nand_scan_tail(struct mtd_info *mtd)
 		ecc->read_oob = nand_read_oob_std;
 		ecc->write_oob = nand_write_oob_std;
 		/*
-		 * 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.
+		 * Board driver should supply ecc.size and ecc.strength values
+		 * to select how many bits are correctable. 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);

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 4046

Quoted 10 lines
drivers/mtd/nand/nand_base.c +9 -0
+			ecc->strength = 4;
 		}
+
+		/*
+		 * We previously recommended drivers pass ecc.size and
+		 * ecc.bytes. Continue to support drivers that do.
+		 * See nand_bch_init() for details.
+		 */
+		if (ecc->bytes && !ecc->strength)
+			ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);

How about fixing all NAND_ECC_SOFT_BCH users (AFAICT the only remaining one is nandsim, since you fixed sunxi_nand) instead of keeping this backward compat code.

Best Regards,

Boris

Signature · 3 lines
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#3 lore raw

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

Quoted 56 lines

From: "Boris Brezillon" <[email protected]>
Sent: Wednesday, January 14, 2015 3:34:49 AM

Hi Aaron,

Quoted 11 lines · On Mon, 12 Jan 2015 18:35:55 -0600 (CST) Aaron Sierra <[email protected]>…

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

Apart from the nit below, you can add my:

Quoted 32 lines
---
 drivers/mtd/nand/nand_base.c  | 21 +++++++++++++++------
 drivers/mtd/nand/sunxi_nand.c |  2 --
 2 files changed, 15 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +8 -5
index 41585df..993612c 100644
@@ -4028,22 +4028,31 @@ int nand_scan_tail(struct mtd_info *mtd)
 		ecc->read_oob = nand_read_oob_std;
 		ecc->write_oob = nand_write_oob_std;
 		/*
-		 * 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.
+		 * Board driver should supply ecc.size and ecc.strength values
+		 * to select how many bits are correctable. 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->strength = 4;
 		}
+
+		/*
+		 * We previously recommended drivers pass ecc.size and
+		 * ecc.bytes. Continue to support drivers that do.
Quoted 8 lines

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 4046

Quoted 4 lines
drivers/mtd/nand/nand_base.c +4 -0
+		 * See nand_bch_init() for details.
+		 */
+		if (ecc->bytes && !ecc->strength)
+			ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);

How about fixing all NAND_ECC_SOFT_BCH users (AFAICT the only remaining one is nandsim, since you fixed sunxi_nand) instead of keeping this backward compat code.

Boris,
Yes, nandsim was the only other that I found. I will submit an update that does not include this backward compatibility code, thanks.

-Aaron

Quoted 4 lines

Best Regards,

Boris

#4 lore raw

PATCH v2 1/2 nand_base: SOFT_BCH: Request strength over bytes

In reply to Boris Brezillon

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

---
v2:
* nandsim: Set ECC strength to chip->ecc.strength
* nand_base: Don't provide ECC bytes-to-strength backward compat

 drivers/mtd/nand/nand_base.c  | 14 ++++++++------
 drivers/mtd/nand/nandsim.c    |  1 +
 drivers/mtd/nand/sunxi_nand.c |  2 --
 3 files changed, 9 insertions(+), 8 deletions(-)
drivers/mtd/nand/nand_base.c +8 -6
index 41585df..2f9c0bf 100644
@@ -4028,22 +4028,24 @@ int nand_scan_tail(struct mtd_info *mtd)
 		ecc->read_oob = nand_read_oob_std;
 		ecc->write_oob = nand_write_oob_std;
 		/*
-		 * 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.
+		 * Board driver should supply ecc.size and ecc.strength values
+		 * to select how many bits are correctable. 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->strength = 4;
 		}
+
+		/* See nand_bch_init() for details. */
+		ecc->bytes = DIV_ROUND_UP(
+				ecc->strength * fls(8 * ecc->size), 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);
 		break;
 
 	case NAND_ECC_NONE:
drivers/mtd/nand/nandsim.c +1 -0
index ab5bbf5..0ed1464 100644
@@ -2343,6 +2343,7 @@ static int __init ns_init_module(void)
 		}
 		chip->ecc.mode = NAND_ECC_SOFT_BCH;
 		chip->ecc.size = 512;
+		chip->ecc.strength = bch;
 		chip->ecc.bytes = eccbytes;
 		NS_INFO("using %u-bit/%u bytes BCH ECC\n", bch, chip->ecc.size);
 	}
drivers/mtd/nand/sunxi_nand.c +0 -2
index ccaa8e2..6f93b29 100644
@@ -1110,8 +1110,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
 
 	switch (ecc->mode) {
 	case NAND_ECC_SOFT_BCH:
-		ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * ecc->size),
-					  8);
 		break;
 	case NAND_ECC_HW:
 		ret = sunxi_nand_hw_ecc_ctrl_init(mtd, ecc, np);
Signature · 1 line
1.9.1
#5 lore raw

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

Quoted 22 lines

From: "Aaron Sierra" <[email protected]>
Sent: Wednesday, January 14, 2015 5:41:31 PM

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

---
v2:
* nandsim: Set ECC strength to chip->ecc.strength
* nand_base: Don't provide ECC bytes-to-strength backward compat

Quoted 5 lines
 drivers/mtd/nand/nand_base.c  | 14 ++++++++------
 drivers/mtd/nand/nandsim.c    |  1 +
 drivers/mtd/nand/sunxi_nand.c |  2 --
 3 files changed, 9 insertions(+), 8 deletions(-)

Is this patch still being considered despite the changes requested for the 2nd patch in this series?

-Aaron

#6 lore raw
Quoted 23 lines · Aaron Sierra

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

Quoted 22 lines

From: "Aaron Sierra" <[email protected]>
Sent: Wednesday, January 14, 2015 5:41:31 PM

Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation.

Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once.

This reverts/generalizes this commit:
mtd: nand: Base BCH ECC bytes on required strength

---
v2:
* nandsim: Set ECC strength to chip->ecc.strength
* nand_base: Don't provide ECC bytes-to-strength backward compat

Quoted 8 lines
Quoted 5 lines
 drivers/mtd/nand/nand_base.c  | 14 ++++++++------
 drivers/mtd/nand/nandsim.c    |  1 +
 drivers/mtd/nand/sunxi_nand.c |  2 --
 3 files changed, 9 insertions(+), 8 deletions(-)

Is this patch still being considered despite the changes requested for the 2nd patch in this series?

Sorry, I thought I had queued it up. Pushed this patch to l2-mtd.git now. Thanks.

Brian