mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: Ensure ECC configuration is propagated to upper layers
@ 2024-07-02  8:44 Sascha Hauer
  2024-07-03  8:53 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2024-07-02  8:44 UTC (permalink / raw)
  To: Barebox List

This is an adoption of Linux Commit:

|commit 3a1b777eb9fb75d09c45ae5dd1d007eddcbebf1f
|Author: Miquel Raynal <miquel.raynal@bootlin.com>
|Date:   Tue May 7 10:58:42 2024 +0200
|
|    mtd: rawnand: Ensure ECC configuration is propagated to upper layers
|
|    Until recently the "upper layer" was MTD. But following incremental
|    reworks to bring spi-nand support and more recently generic ECC support,
|    there is now an intermediate "generic NAND" layer that also needs to get
|    access to some values. When using "converted" ECC engines, like the
|    software ones, these values are already propagated correctly. But
|    otherwise when using good old raw NAND controller drivers, we need to
|    manually set these values ourselves at the end of the "scan" operation,
|    once these values have been negotiated.
|
|    Without this propagation, later (generic) checks like the one warning
|    users that the ECC strength is not high enough might simply no longer
|    work.
|
|    Fixes: 8c126720fe10 ("mtd: rawnand: Use the ECC framework nand_ecc_is_strong_enough() helper")
|    Cc: stable@vger.kernel.org
|    Reported-by: Sascha Hauer <s.hauer@pengutronix.de>
|    Closes: https://lore.kernel.org/all/Zhe2JtvvN1M4Ompw@pengutronix.de/
|    Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
|    Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
|    Link: https://lore.kernel.org/linux-mtd/20240507085842.108844-1-miquel.raynal@bootlin.com

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/raw/nand_base.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index e586c4cc89..b6bef46499 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -6087,6 +6087,7 @@ static const struct nand_ops rawnand_ops = {
 int nand_scan_tail(struct nand_chip *chip)
 {
 	struct mtd_info *mtd = nand_to_mtd(chip);
+	struct nand_device *base = &chip->base;
 	struct nand_ecc_ctrl *ecc = &chip->ecc;
 	int ret, i;
 
@@ -6231,9 +6232,13 @@ int nand_scan_tail(struct nand_chip *chip)
 	if (!ecc->write_oob_raw)
 		ecc->write_oob_raw = ecc->write_oob;
 
-	/* propagate ecc info to mtd_info */
+	/* Propagate ECC info to the generic NAND and MTD layers */
 	mtd->ecc_strength = ecc->strength;
+	if (!base->ecc.ctx.conf.strength)
+		base->ecc.ctx.conf.strength = ecc->strength;
 	mtd->ecc_step_size = ecc->size;
+	if (!base->ecc.ctx.conf.step_size)
+		base->ecc.ctx.conf.step_size = ecc->size;
 
 	/*
 	 * Set the number of read / write steps for one page depending on ECC
@@ -6241,6 +6246,8 @@ int nand_scan_tail(struct nand_chip *chip)
 	 */
 	if (!ecc->steps)
 		ecc->steps = mtd->writesize / ecc->size;
+	if (!base->ecc.ctx.nsteps)
+		base->ecc.ctx.nsteps = ecc->steps;
 	if (ecc->steps * ecc->size != mtd->writesize) {
 		WARN(1, "Invalid ECC parameters\n");
 		ret = -EINVAL;
-- 
2.39.2




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

* Re: [PATCH] mtd: rawnand: Ensure ECC configuration is propagated to upper layers
  2024-07-02  8:44 [PATCH] mtd: rawnand: Ensure ECC configuration is propagated to upper layers Sascha Hauer
@ 2024-07-03  8:53 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-07-03  8:53 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer


On Tue, 02 Jul 2024 10:44:55 +0200, Sascha Hauer wrote:
> This is an adoption of Linux Commit:
> 
> |commit 3a1b777eb9fb75d09c45ae5dd1d007eddcbebf1f
> |Author: Miquel Raynal <miquel.raynal@bootlin.com>
> |Date:   Tue May 7 10:58:42 2024 +0200
> |
> |    mtd: rawnand: Ensure ECC configuration is propagated to upper layers
> |
> |    Until recently the "upper layer" was MTD. But following incremental
> |    reworks to bring spi-nand support and more recently generic ECC support,
> |    there is now an intermediate "generic NAND" layer that also needs to get
> |    access to some values. When using "converted" ECC engines, like the
> |    software ones, these values are already propagated correctly. But
> |    otherwise when using good old raw NAND controller drivers, we need to
> |    manually set these values ourselves at the end of the "scan" operation,
> |    once these values have been negotiated.
> |
> |    Without this propagation, later (generic) checks like the one warning
> |    users that the ECC strength is not high enough might simply no longer
> |    work.
> |
> |    Fixes: 8c126720fe10 ("mtd: rawnand: Use the ECC framework nand_ecc_is_strong_enough() helper")
> |    Cc: stable@vger.kernel.org
> |    Reported-by: Sascha Hauer <s.hauer@pengutronix.de>
> |    Closes: https://lore.kernel.org/all/Zhe2JtvvN1M4Ompw@pengutronix.de/
> |    Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> |    Tested-by: Sascha Hauer <s.hauer@pengutronix.de>
> |    Link: https://lore.kernel.org/linux-mtd/20240507085842.108844-1-miquel.raynal@bootlin.com
> 
> [...]

Applied, thanks!

[1/1] mtd: rawnand: Ensure ECC configuration is propagated to upper layers
      https://git.pengutronix.de/cgit/barebox/commit/?id=0f5c97472bfb (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2024-07-03  8:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-02  8:44 [PATCH] mtd: rawnand: Ensure ECC configuration is propagated to upper layers Sascha Hauer
2024-07-03  8:53 ` Sascha Hauer

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