diff mbox series

[v2,1/2] mtd: nand: Add a helper to retrieve the number of ECC steps

Message ID 20210120101750.1163-2-miquel.raynal@bootlin.com
State New
Headers show
Series Fix OMAP2 ECC/OOB layout logic | expand

Commit Message

Miquel Raynal Jan. 20, 2021, 10:17 a.m. UTC
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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Boris Brezillon Jan. 20, 2021, 10:30 a.m. UTC | #1
On Wed, 20 Jan 2021 11:17:49 +0100
Miquel Raynal <miquel.raynal@bootlin.com> 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>
> ---
>  include/linux/mtd/nand.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
> index 414f8a4d2853..27e87c02971c 100644
> --- a/include/linux/mtd/nand.h
> +++ b/include/linux/mtd/nand.h
> @@ -585,6 +585,18 @@ nanddev_get_ecc_conf(struct nand_device *nand)
>  	return &nand->ecc.ctx.conf;
>  }
>  
> +/**
> + * nanddev_get_ecc_nsteps() - Extract the actual number of ECC steps
> + * @nand: NAND device
> + */
> +static inline unsigned int
> +nanddev_get_ecc_nsteps(struct nand_device *nand)
> +{
> +	const struct nand_ecc_props *conf = nanddev_get_ecc_conf(nand);
> +
> +	return nanddev_page_size(nand) / conf->step_size;

Some ECC engines might cover OOB bytes too, so you can't really guess
the number of steps with a simple page_size / step_size division. I
think it's safer to store the number of steps and step_size directly in
the conf and let the engine fill those.

> +}
> +
>  /**
>   * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
>   *                                  device
diff mbox series

Patch

diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 414f8a4d2853..27e87c02971c 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -585,6 +585,18 @@  nanddev_get_ecc_conf(struct nand_device *nand)
 	return &nand->ecc.ctx.conf;
 }
 
+/**
+ * nanddev_get_ecc_nsteps() - Extract the actual number of ECC steps
+ * @nand: NAND device
+ */
+static inline unsigned int
+nanddev_get_ecc_nsteps(struct nand_device *nand)
+{
+	const struct nand_ecc_props *conf = nanddev_get_ecc_conf(nand);
+
+	return nanddev_page_size(nand) / conf->step_size;
+}
+
 /**
  * nanddev_get_ecc_requirements() - Extract the ECC requirements from a NAND
  *                                  device