All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/9] Better solution for the OMAP fix
@ 2021-01-27 20:30 Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

Hello,

I recently got a bug report regarding the OMAP driver. We fixed it and
merged the fix. This fix was involving accessing BCH internal values
from within the OMAP driver which is far from ideal.

Now that the urgence is gone, here is a series to do it "the proper
way".

Cheers,
Miquèl

Main changes in v3:
* Export the number of ECC steps
* Add a 'get number of ECC bytes per step' helper.

Miquel Raynal (9):
  mtd: nand: Let ECC engines advertize the exact number of steps
  mtd: nand: ecc-bch: Populate the public nsteps field
  mtd: nand: ecc-hamming: Populate the public nsteps field
  mtd: nand: Add a helper to retrieve the number of ECC steps
  mtd: nand: Add a helper to retrieve the number of ECC bytes per step
  mtd: rawnand: Try not to use the ECC private structures
  mtd: rawnand: omap: Use ECC information from the generic structures
  mtd: nand: ecc-bch: Use the public nsteps field
  mtd: nand: ecc-hamming: Use the public nsteps field

 drivers/mtd/nand/ecc-sw-bch.c           | 10 +++++-----
 drivers/mtd/nand/ecc-sw-hamming.c       | 10 +++++-----
 drivers/mtd/nand/raw/nand_base.c        | 16 +++++++---------
 drivers/mtd/nand/raw/omap2.c            | 14 ++++++++------
 include/linux/mtd/nand-ecc-sw-bch.h     |  2 --
 include/linux/mtd/nand-ecc-sw-hamming.h |  2 --
 include/linux/mtd/nand.h                | 22 ++++++++++++++++++++++
 7 files changed, 47 insertions(+), 29 deletions(-)

-- 
2.20.1


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

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

* [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-02-06 12:59   ` Adam Ford
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field Miquel Raynal
                   ` (7 subsequent siblings)
  8 siblings, 2 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

This is an information that might be useful for specific uses, so
export it, which might avoid having to guess the number of steps when
necessary.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 include/linux/mtd/nand.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 414f8a4d2853..632becb13b46 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -231,12 +231,14 @@ struct nand_ops {
 /**
  * struct nand_ecc_context - Context for the ECC engine
  * @conf: basic ECC engine parameters
+ * @nsteps: number of ECC steps
  * @total: total number of bytes used for storing ECC codes, this is used by
  *         generic OOB layouts
  * @priv: ECC engine driver private data
  */
 struct nand_ecc_context {
 	struct nand_ecc_props conf;
+	unsigned int nsteps;
 	unsigned int total;
 	void *priv;
 };
-- 
2.20.1


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

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

* [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 3/9] mtd: nand: ecc-hamming: " Miquel Raynal
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

Advertize the actual number of steps that will actually be used by the
driver by populating the public field.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/ecc-sw-bch.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c
index 0a0ac11d5725..5018bc0db626 100644
--- a/drivers/mtd/nand/ecc-sw-bch.c
+++ b/drivers/mtd/nand/ecc-sw-bch.c
@@ -245,6 +245,7 @@ int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
 	}
 
 	nand->ecc.ctx.priv = engine_conf;
+	nand->ecc.ctx.nsteps = nsteps;
 	nand->ecc.ctx.total = nsteps * code_size;
 
 	ret = nand_ecc_sw_bch_init(nand);
-- 
2.20.1


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

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

* [PATCH v3 3/9] mtd: nand: ecc-hamming: Populate the public nsteps field
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps Miquel Raynal
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

Advertize the actual number of steps that will actually be used by the
driver by populating the public field.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/ecc-sw-hamming.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/nand/ecc-sw-hamming.c b/drivers/mtd/nand/ecc-sw-hamming.c
index 6334d1d7735d..5144775e5a59 100644
--- a/drivers/mtd/nand/ecc-sw-hamming.c
+++ b/drivers/mtd/nand/ecc-sw-hamming.c
@@ -513,6 +513,7 @@ int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
 	}
 
 	nand->ecc.ctx.priv = engine_conf;
+	nand->ecc.ctx.nsteps = mtd->writesize / conf->step_size;
 	nand->ecc.ctx.total = engine_conf->nsteps * engine_conf->code_size;
 
 	return 0;
-- 
2.20.1


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

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

* [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (2 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 3/9] mtd: nand: ecc-hamming: " Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step Miquel Raynal
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

This operation is very common and deserves a helper. It of course only
works after the ECC engine initialization.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 include/linux/mtd/nand.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 632becb13b46..8a0116396689 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -587,6 +587,16 @@ nanddev_get_ecc_conf(struct nand_device *nand)
 	return &nand->ecc.ctx.conf;
 }
 
+/**
+ * nanddev_get_ecc_nsteps() - Extract the number of ECC steps
+ * @nand: NAND device
+ */
+static inline unsigned int
+nanddev_get_ecc_nsteps(struct nand_device *nand)
+{
+	return nand->ecc.ctx.nsteps;
+}
+
 /**
  * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
  *                                  device
-- 
2.20.1


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

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

* [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (3 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures Miquel Raynal
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

This operation is very common and deserves a helper. It of course only
works after the ECC engine initialization.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 include/linux/mtd/nand.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 8a0116396689..32fc7edf65b3 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -597,6 +597,16 @@ nanddev_get_ecc_nsteps(struct nand_device *nand)
 	return nand->ecc.ctx.nsteps;
 }
 
+/**
+ * nanddev_get_ecc_bytes_per_step() - Extract the number of ECC bytes per step
+ * @nand: NAND device
+ */
+static inline unsigned int
+nanddev_get_ecc_bytes_per_step(struct nand_device *nand)
+{
+	return nand->ecc.ctx.total / nand->ecc.ctx.nsteps;
+}
+
 /**
  * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
  *                                  device
-- 
2.20.1


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

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

* [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (4 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures Miquel Raynal
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

Most of the time, there is no need to use the software ECC Hamming and
BCH algorithms private context to know their configuration. All the
data has been stored by their ->init_ctx() hook in the generic NAND
ECC engine structure, so use this one when possible.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/raw/nand_base.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index c33fa1b1847f..4e1bd1e5d474 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -5162,8 +5162,8 @@ int rawnand_sw_hamming_init(struct nand_chip *chip)
 	chip->ecc.size = base->ecc.ctx.conf.step_size;
 	chip->ecc.strength = base->ecc.ctx.conf.strength;
 	chip->ecc.total = base->ecc.ctx.total;
-	chip->ecc.steps = engine_conf->nsteps;
-	chip->ecc.bytes = engine_conf->code_size;
+	chip->ecc.steps = nanddev_get_ecc_nsteps(base);
+	chip->ecc.bytes = base->ecc.ctx.total / nanddev_get_ecc_nsteps(base);
 
 	return 0;
 }
@@ -5201,7 +5201,7 @@ EXPORT_SYMBOL(rawnand_sw_hamming_cleanup);
 int rawnand_sw_bch_init(struct nand_chip *chip)
 {
 	struct nand_device *base = &chip->base;
-	struct nand_ecc_sw_bch_conf *engine_conf;
+	const struct nand_ecc_props *ecc_conf = nanddev_get_ecc_conf(base);
 	int ret;
 
 	base->ecc.user_conf.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
@@ -5213,13 +5213,11 @@ int rawnand_sw_bch_init(struct nand_chip *chip)
 	if (ret)
 		return ret;
 
-	engine_conf = base->ecc.ctx.priv;
-
-	chip->ecc.size = base->ecc.ctx.conf.step_size;
-	chip->ecc.strength = base->ecc.ctx.conf.strength;
+	chip->ecc.size = ecc_conf->step_size;
+	chip->ecc.strength = ecc_conf->strength;
 	chip->ecc.total = base->ecc.ctx.total;
-	chip->ecc.steps = engine_conf->nsteps;
-	chip->ecc.bytes = engine_conf->code_size;
+	chip->ecc.steps = nanddev_get_ecc_nsteps(base);
+	chip->ecc.bytes = base->ecc.ctx.total / nanddev_get_ecc_nsteps(base);
 
 	return 0;
 }
-- 
2.20.1


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

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

* [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (5 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 9/9] mtd: nand: ecc-hamming: " Miquel Raynal
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

As part of a previous fix, we imported the BCH internal structure in
order to get information about the BCH engine configuration.

It is best not to access private structure so instead, a small rework
has been done to export more information from the ECC engines. Now,
let's use these.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/raw/omap2.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/omap2.c b/drivers/mtd/nand/raw/omap2.c
index 2c3e65cb68f3..c75e7a0b101f 100644
--- a/drivers/mtd/nand/raw/omap2.c
+++ b/drivers/mtd/nand/raw/omap2.c
@@ -1868,18 +1868,19 @@ static int omap_sw_ooblayout_ecc(struct mtd_info *mtd, int section,
 				 struct mtd_oob_region *oobregion)
 {
 	struct nand_device *nand = mtd_to_nanddev(mtd);
-	const struct nand_ecc_sw_bch_conf *engine_conf = nand->ecc.ctx.priv;
+	unsigned int nsteps = nanddev_get_ecc_nsteps(nand);
+	unsigned int ecc_bytes = nanddev_get_ecc_bytes_per_step(nand);
 	int off = BADBLOCK_MARKER_LENGTH;
 
-	if (section >= engine_conf->nsteps)
+	if (section >= nsteps)
 		return -ERANGE;
 
 	/*
 	 * When SW correction is employed, one OMAP specific marker byte is
 	 * reserved after each ECC step.
 	 */
-	oobregion->offset = off + (section * (engine_conf->code_size + 1));
-	oobregion->length = engine_conf->code_size;
+	oobregion->offset = off + (section * (ecc_bytes + 1));
+	oobregion->length = ecc_bytes;
 
 	return 0;
 }
@@ -1888,7 +1889,8 @@ static int omap_sw_ooblayout_free(struct mtd_info *mtd, int section,
 				  struct mtd_oob_region *oobregion)
 {
 	struct nand_device *nand = mtd_to_nanddev(mtd);
-	const struct nand_ecc_sw_bch_conf *engine_conf = nand->ecc.ctx.priv;
+	unsigned int nsteps = nanddev_get_ecc_nsteps(nand);
+	unsigned int ecc_bytes = nanddev_get_ecc_bytes_per_step(nand);
 	int off = BADBLOCK_MARKER_LENGTH;
 
 	if (section)
@@ -1898,7 +1900,7 @@ static int omap_sw_ooblayout_free(struct mtd_info *mtd, int section,
 	 * When SW correction is employed, one OMAP specific marker byte is
 	 * reserved after each ECC step.
 	 */
-	off += ((engine_conf->code_size + 1) * engine_conf->nsteps);
+	off += ((ecc_bytes + 1) * nsteps);
 	if (off >= mtd->oobsize)
 		return -ERANGE;
 
-- 
2.20.1


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

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

* [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (6 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  2021-01-27 20:30 ` [PATCH v3 9/9] mtd: nand: ecc-hamming: " Miquel Raynal
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

The software BCH ECC engine stores the nsteps variable in its own
private structure while it is also exported as a public ECC field.

Let's get rid of the redundant private one and let's use the
nand_ecc_context structure when possible.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/ecc-sw-bch.c       | 9 ++++-----
 include/linux/mtd/nand-ecc-sw-bch.h | 2 --
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c
index 5018bc0db626..405552d014a8 100644
--- a/drivers/mtd/nand/ecc-sw-bch.c
+++ b/drivers/mtd/nand/ecc-sw-bch.c
@@ -236,7 +236,6 @@ int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
 		goto free_engine_conf;
 
 	engine_conf->code_size = code_size;
-	engine_conf->nsteps = nsteps;
 	engine_conf->calc_buf = kzalloc(mtd->oobsize, GFP_KERNEL);
 	engine_conf->code_buf = kzalloc(mtd->oobsize, GFP_KERNEL);
 	if (!engine_conf->calc_buf || !engine_conf->code_buf) {
@@ -254,7 +253,7 @@ int nand_ecc_sw_bch_init_ctx(struct nand_device *nand)
 
 	/* Verify the layout validity */
 	if (mtd_ooblayout_count_eccbytes(mtd) !=
-	    engine_conf->nsteps * engine_conf->code_size) {
+	    nand->ecc.ctx.nsteps * engine_conf->code_size) {
 		pr_err("Invalid ECC layout\n");
 		ret = -EINVAL;
 		goto cleanup_bch_ctx;
@@ -296,7 +295,7 @@ static int nand_ecc_sw_bch_prepare_io_req(struct nand_device *nand,
 	struct mtd_info *mtd = nanddev_to_mtd(nand);
 	int eccsize = nand->ecc.ctx.conf.step_size;
 	int eccbytes = engine_conf->code_size;
-	int eccsteps = engine_conf->nsteps;
+	int eccsteps = nand->ecc.ctx.nsteps;
 	int total = nand->ecc.ctx.total;
 	u8 *ecccalc = engine_conf->calc_buf;
 	const u8 *data;
@@ -334,7 +333,7 @@ static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand,
 	int eccsize = nand->ecc.ctx.conf.step_size;
 	int total = nand->ecc.ctx.total;
 	int eccbytes = engine_conf->code_size;
-	int eccsteps = engine_conf->nsteps;
+	int eccsteps = nand->ecc.ctx.nsteps;
 	u8 *ecccalc = engine_conf->calc_buf;
 	u8 *ecccode = engine_conf->code_buf;
 	unsigned int max_bitflips = 0;
@@ -366,7 +365,7 @@ static int nand_ecc_sw_bch_finish_io_req(struct nand_device *nand,
 		nand_ecc_sw_bch_calculate(nand, data, &ecccalc[i]);
 
 	/* Finish a page read: compare and correct */
-	for (eccsteps = engine_conf->nsteps, i = 0, data = req->databuf.in;
+	for (eccsteps = nand->ecc.ctx.nsteps, i = 0, data = req->databuf.in;
 	     eccsteps;
 	     eccsteps--, i += eccbytes, data += eccsize) {
 		int stat =  nand_ecc_sw_bch_correct(nand, data,
diff --git a/include/linux/mtd/nand-ecc-sw-bch.h b/include/linux/mtd/nand-ecc-sw-bch.h
index 22c92073b3dd..9da9969505a8 100644
--- a/include/linux/mtd/nand-ecc-sw-bch.h
+++ b/include/linux/mtd/nand-ecc-sw-bch.h
@@ -16,7 +16,6 @@
  * @req_ctx: Save request context and tweak the original request to fit the
  *           engine needs
  * @code_size: Number of bytes needed to store a code (one code per step)
- * @nsteps: Number of steps
  * @calc_buf: Buffer to use when calculating ECC bytes
  * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
  * @bch: BCH control structure
@@ -26,7 +25,6 @@
 struct nand_ecc_sw_bch_conf {
 	struct nand_ecc_req_tweak_ctx req_ctx;
 	unsigned int code_size;
-	unsigned int nsteps;
 	u8 *calc_buf;
 	u8 *code_buf;
 	struct bch_control *bch;
-- 
2.20.1


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

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

* [PATCH v3 9/9] mtd: nand: ecc-hamming: Use the public nsteps field
  2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
                   ` (7 preceding siblings ...)
  2021-01-27 20:30 ` [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field Miquel Raynal
@ 2021-01-27 20:30 ` Miquel Raynal
  2021-03-02 16:33   ` Miquel Raynal
  8 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2021-01-27 20:30 UTC (permalink / raw)
  To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis, Miquel Raynal

The software Hamming ECC engine stores the nsteps variable in its own
private structure while it is also exported as a public ECC field.

Let's get rid of the redundant private one and let's use the
nand_ecc_context structure when possible.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/mtd/nand/ecc-sw-hamming.c       | 9 ++++-----
 include/linux/mtd/nand-ecc-sw-hamming.h | 2 --
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/ecc-sw-hamming.c b/drivers/mtd/nand/ecc-sw-hamming.c
index 5144775e5a59..a7655b668f32 100644
--- a/drivers/mtd/nand/ecc-sw-hamming.c
+++ b/drivers/mtd/nand/ecc-sw-hamming.c
@@ -504,7 +504,6 @@ int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
 		goto free_engine_conf;
 
 	engine_conf->code_size = 3;
-	engine_conf->nsteps = mtd->writesize / conf->step_size;
 	engine_conf->calc_buf = kzalloc(mtd->oobsize, GFP_KERNEL);
 	engine_conf->code_buf = kzalloc(mtd->oobsize, GFP_KERNEL);
 	if (!engine_conf->calc_buf || !engine_conf->code_buf) {
@@ -514,7 +513,7 @@ int nand_ecc_sw_hamming_init_ctx(struct nand_device *nand)
 
 	nand->ecc.ctx.priv = engine_conf;
 	nand->ecc.ctx.nsteps = mtd->writesize / conf->step_size;
-	nand->ecc.ctx.total = engine_conf->nsteps * engine_conf->code_size;
+	nand->ecc.ctx.total = nand->ecc.ctx.nsteps * engine_conf->code_size;
 
 	return 0;
 
@@ -549,7 +548,7 @@ static int nand_ecc_sw_hamming_prepare_io_req(struct nand_device *nand,
 	struct mtd_info *mtd = nanddev_to_mtd(nand);
 	int eccsize = nand->ecc.ctx.conf.step_size;
 	int eccbytes = engine_conf->code_size;
-	int eccsteps = engine_conf->nsteps;
+	int eccsteps = nand->ecc.ctx.nsteps;
 	int total = nand->ecc.ctx.total;
 	u8 *ecccalc = engine_conf->calc_buf;
 	const u8 *data;
@@ -587,7 +586,7 @@ static int nand_ecc_sw_hamming_finish_io_req(struct nand_device *nand,
 	int eccsize = nand->ecc.ctx.conf.step_size;
 	int total = nand->ecc.ctx.total;
 	int eccbytes = engine_conf->code_size;
-	int eccsteps = engine_conf->nsteps;
+	int eccsteps = nand->ecc.ctx.nsteps;
 	u8 *ecccalc = engine_conf->calc_buf;
 	u8 *ecccode = engine_conf->code_buf;
 	unsigned int max_bitflips = 0;
@@ -619,7 +618,7 @@ static int nand_ecc_sw_hamming_finish_io_req(struct nand_device *nand,
 		nand_ecc_sw_hamming_calculate(nand, data, &ecccalc[i]);
 
 	/* Finish a page read: compare and correct */
-	for (eccsteps = engine_conf->nsteps, i = 0, data = req->databuf.in;
+	for (eccsteps = nand->ecc.ctx.nsteps, i = 0, data = req->databuf.in;
 	     eccsteps;
 	     eccsteps--, i += eccbytes, data += eccsize) {
 		int stat =  nand_ecc_sw_hamming_correct(nand, data,
diff --git a/include/linux/mtd/nand-ecc-sw-hamming.h b/include/linux/mtd/nand-ecc-sw-hamming.h
index 9f9073d86ff3..c6c71894c575 100644
--- a/include/linux/mtd/nand-ecc-sw-hamming.h
+++ b/include/linux/mtd/nand-ecc-sw-hamming.h
@@ -17,7 +17,6 @@
  * @req_ctx: Save request context and tweak the original request to fit the
  *           engine needs
  * @code_size: Number of bytes needed to store a code (one code per step)
- * @nsteps: Number of steps
  * @calc_buf: Buffer to use when calculating ECC bytes
  * @code_buf: Buffer to use when reading (raw) ECC bytes from the chip
  * @sm_order: Smart Media special ordering
@@ -25,7 +24,6 @@
 struct nand_ecc_sw_hamming_conf {
 	struct nand_ecc_req_tweak_ctx req_ctx;
 	unsigned int code_size;
-	unsigned int nsteps;
 	u8 *calc_buf;
 	u8 *code_buf;
 	unsigned int sm_order;
-- 
2.20.1


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

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

* Re: [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps
  2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
@ 2021-02-06 12:59   ` Adam Ford
  2021-03-02 16:33   ` Miquel Raynal
  1 sibling, 0 replies; 20+ messages in thread
From: Adam Ford @ 2021-02-06 12:59 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Vignesh Raghavendra, Tudor Ambarus, Richard Weinberger, ladis,
	Boris Brezillon, linux-mtd

On Wed, Jan 27, 2021 at 2:30 PM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> This is an information that might be useful for specific uses, so
> export it, which might avoid having to guess the number of steps when
> necessary.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

For the series,
Tested-by: Adam Ford <aford173@gmail.com> #logicpd Torpedo

> ---
>  include/linux/mtd/nand.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index 414f8a4d2853..632becb13b46 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -231,12 +231,14 @@ struct nand_ops {
>  /**
>   * struct nand_ecc_context - Context for the ECC engine
>   * @conf: basic ECC engine parameters
> + * @nsteps: number of ECC steps
>   * @total: total number of bytes used for storing ECC codes, this is used by
>   *         generic OOB layouts
>   * @priv: ECC engine driver private data
>   */
>  struct nand_ecc_context {
>         struct nand_ecc_props conf;
> +       unsigned int nsteps;
>         unsigned int total;
>         void *priv;
>  };
> --
> 2.20.1
>

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

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

* Re: [PATCH v3 9/9] mtd: nand: ecc-hamming: Use the public nsteps field
  2021-01-27 20:30 ` [PATCH v3 9/9] mtd: nand: ecc-hamming: " Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:20 UTC, Miquel Raynal wrote:
> The software Hamming ECC engine stores the nsteps variable in its own
> private structure while it is also exported as a public ECC field.
> 
> Let's get rid of the redundant private one and let's use the
> nand_ecc_context structure when possible.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field
  2021-01-27 20:30 ` [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:19 UTC, Miquel Raynal wrote:
> The software BCH ECC engine stores the nsteps variable in its own
> private structure while it is also exported as a public ECC field.
> 
> Let's get rid of the redundant private one and let's use the
> nand_ecc_context structure when possible.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures
  2021-01-27 20:30 ` [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:18 UTC, Miquel Raynal wrote:
> As part of a previous fix, we imported the BCH internal structure in
> order to get information about the BCH engine configuration.
> 
> It is best not to access private structure so instead, a small rework
> has been done to export more information from the ECC engines. Now,
> let's use these.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures
  2021-01-27 20:30 ` [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:17 UTC, Miquel Raynal wrote:
> Most of the time, there is no need to use the software ECC Hamming and
> BCH algorithms private context to know their configuration. All the
> data has been stored by their ->init_ctx() hook in the generic NAND
> ECC engine structure, so use this one when possible.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step
  2021-01-27 20:30 ` [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:16 UTC, Miquel Raynal wrote:
> This operation is very common and deserves a helper. It of course only
> works after the ECC engine initialization.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps
  2021-01-27 20:30 ` [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:15 UTC, Miquel Raynal wrote:
> This operation is very common and deserves a helper. It of course only
> works after the ECC engine initialization.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 3/9] mtd: nand: ecc-hamming: Populate the public nsteps field
  2021-01-27 20:30 ` [PATCH v3 3/9] mtd: nand: ecc-hamming: " Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:14 UTC, Miquel Raynal wrote:
> Advertize the actual number of steps that will actually be used by the
> driver by populating the public field.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field
  2021-01-27 20:30 ` [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field Miquel Raynal
@ 2021-03-02 16:33   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:13 UTC, Miquel Raynal wrote:
> Advertize the actual number of steps that will actually be used by the
> driver by populating the public field.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

* Re: [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps
  2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
  2021-02-06 12:59   ` Adam Ford
@ 2021-03-02 16:33   ` Miquel Raynal
  1 sibling, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2021-03-02 16:33 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Tudor Ambarus, linux-mtd
  Cc: Boris Brezillon, Adam Ford, ladis

On Wed, 2021-01-27 at 20:30:12 UTC, Miquel Raynal wrote:
> This is an information that might be useful for specific uses, so
> export it, which might avoid having to guess the number of steps when
> necessary.
> 
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Tested-by: Adam Ford <aford173@gmail.com> #logicpd Torpedo

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next.

Miquel

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

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

end of thread, other threads:[~2021-03-03 21:56 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 20:30 [PATCH v3 0/9] Better solution for the OMAP fix Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 1/9] mtd: nand: Let ECC engines advertize the exact number of steps Miquel Raynal
2021-02-06 12:59   ` Adam Ford
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 2/9] mtd: nand: ecc-bch: Populate the public nsteps field Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 3/9] mtd: nand: ecc-hamming: " Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 4/9] mtd: nand: Add a helper to retrieve the number of ECC steps Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 5/9] mtd: nand: Add a helper to retrieve the number of ECC bytes per step Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 6/9] mtd: rawnand: Try not to use the ECC private structures Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 7/9] mtd: rawnand: omap: Use ECC information from the generic structures Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 8/9] mtd: nand: ecc-bch: Use the public nsteps field Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal
2021-01-27 20:30 ` [PATCH v3 9/9] mtd: nand: ecc-hamming: " Miquel Raynal
2021-03-02 16:33   ` Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.