Skip to content

Commit 67a9ad9

Browse files
ezequielgarciacomputersforpeace
authored andcommitted
mtd: nand: Warn the user if the selected ECC strength is too weak
This commit makes use of the chip->ecc_strength_ds and chip->ecc_step_ds which contain the datasheet minimum requested ECC strength to produce a noisy warning if the configured ECC strength is weaker. Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
1 parent edf02fb commit 67a9ad9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/mtd/nand/nand_base.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,39 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
37943794
}
37953795
EXPORT_SYMBOL(nand_scan_ident);
37963796

3797+
/*
3798+
* Check if the chip configuration meet the datasheet requirements.
3799+
3800+
* If our configuration corrects A bits per B bytes and the minimum
3801+
* required correction level is X bits per Y bytes, then we must ensure
3802+
* both of the following are true:
3803+
*
3804+
* (1) A / B >= X / Y
3805+
* (2) A >= X
3806+
*
3807+
* Requirement (1) ensures we can correct for the required bitflip density.
3808+
* Requirement (2) ensures we can correct even when all bitflips are clumped
3809+
* in the same sector.
3810+
*/
3811+
static bool nand_ecc_strength_good(struct mtd_info *mtd)
3812+
{
3813+
struct nand_chip *chip = mtd->priv;
3814+
struct nand_ecc_ctrl *ecc = &chip->ecc;
3815+
int corr, ds_corr;
3816+
3817+
if (ecc->size == 0 || chip->ecc_step_ds == 0)
3818+
/* Not enough information */
3819+
return true;
3820+
3821+
/*
3822+
* We get the number of corrected bits per page to compare
3823+
* the correction density.
3824+
*/
3825+
corr = (mtd->writesize * ecc->strength) / ecc->size;
3826+
ds_corr = (mtd->writesize * chip->ecc_strength_ds) / chip->ecc_step_ds;
3827+
3828+
return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds;
3829+
}
37973830

37983831
/**
37993832
* nand_scan_tail - [NAND Interface] Scan for the NAND device
@@ -4014,6 +4047,9 @@ int nand_scan_tail(struct mtd_info *mtd)
40144047
ecc->layout->oobavail += ecc->layout->oobfree[i].length;
40154048
mtd->oobavail = ecc->layout->oobavail;
40164049

4050+
/* ECC sanity check: warn noisily if it's too weak */
4051+
WARN_ON(!nand_ecc_strength_good(mtd));
4052+
40174053
/*
40184054
* Set the number of read / write steps for one page depending on ECC
40194055
* mode.

0 commit comments

Comments
 (0)