[PATCH v3 2/4] mtd: rawnand: gpmi: Add strict ecc strength check
Han Xu
han.xu at nxp.com
Mon Apr 4 12:54:25 PDT 2022
Add strict ecc strength check in gpmi_check_ecc() function, which is
same as nand_ecc_is_strong_enough() did. It will check both correct bits
and correct bits per byte to ensure it meets chip required ecc strength.
Signed-off-by: Han Xu <han.xu at nxp.com>
---
Changes since v2:
- split the ecc check to a single patch
---
---
drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 24 ++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
index 4144d5937103..9a37f8cc663e 100644
--- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
@@ -238,9 +238,14 @@ static void gpmi_dump_info(struct gpmi_nand_data *this)
geo->block_mark_bit_offset);
}
-static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
+static bool gpmi_check_ecc(struct gpmi_nand_data *this)
{
+ struct nand_chip *chip = &this->nand;
+ struct mtd_info *mtd = nand_to_mtd(&this->nand);
struct bch_geometry *geo = &this->bch_geometry;
+ const struct nand_ecc_props *requirements =
+ nanddev_get_ecc_requirements(&chip->base);
+ int corr, ds_corr;
/* Do the sanity check. */
if (GPMI_IS_MXS(this)) {
@@ -248,7 +253,22 @@ static inline bool gpmi_check_ecc(struct gpmi_nand_data *this)
if (geo->gf_len == 14)
return false;
}
- return geo->ecc_strength <= this->devdata->bch_max_ecc_strength;
+
+ if (geo->ecc_strength > this->devdata->bch_max_ecc_strength)
+ return false;
+
+ /* check ecc strength, same as nand_ecc_is_strong_enough() did */
+ if (requirements->step_size) {
+ corr = mtd->writesize * geo->ecc_strength /
+ geo->ecc_chunk_size;
+ ds_corr = mtd->writesize * requirements->strength /
+ requirements->step_size;
+ if (corr < ds_corr ||
+ geo->ecc_strength < requirements->strength)
+ return false;
+ }
+
+ return true;
}
/*
--
2.17.1
More information about the linux-mtd
mailing list