[mvebu]: enable swconfig and the mvsw6171 driver
[openwrt/svn-archive/archive.git] / target / linux / mvebu / patches-3.14 / 008-nand_warn_weak_ecc_strength.patch
1 From 67a9ad9b8a6f6ea76ef8fc484ae49970d72d5534 Mon Sep 17 00:00:00 2001
2 From: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
3 Date: Wed, 14 May 2014 14:58:06 -0300
4 Subject: mtd: nand: Warn the user if the selected ECC strength is too weak
5
6 This commit makes use of the chip->ecc_strength_ds and chip->ecc_step_ds which
7 contain the datasheet minimum requested ECC strength to produce a noisy warning
8 if the configured ECC strength is weaker.
9
10 Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
11 Signed-off-by: Brian Norris <computersforpeace@gmail.com>
12
13 --- a/drivers/mtd/nand/nand_base.c
14 +++ b/drivers/mtd/nand/nand_base.c
15 @@ -3682,6 +3682,39 @@ int nand_scan_ident(struct mtd_info *mtd
16 }
17 EXPORT_SYMBOL(nand_scan_ident);
18
19 +/*
20 + * Check if the chip configuration meet the datasheet requirements.
21 +
22 + * If our configuration corrects A bits per B bytes and the minimum
23 + * required correction level is X bits per Y bytes, then we must ensure
24 + * both of the following are true:
25 + *
26 + * (1) A / B >= X / Y
27 + * (2) A >= X
28 + *
29 + * Requirement (1) ensures we can correct for the required bitflip density.
30 + * Requirement (2) ensures we can correct even when all bitflips are clumped
31 + * in the same sector.
32 + */
33 +static bool nand_ecc_strength_good(struct mtd_info *mtd)
34 +{
35 + struct nand_chip *chip = mtd->priv;
36 + struct nand_ecc_ctrl *ecc = &chip->ecc;
37 + int corr, ds_corr;
38 +
39 + if (ecc->size == 0 || chip->ecc_step_ds == 0)
40 + /* Not enough information */
41 + return true;
42 +
43 + /*
44 + * We get the number of corrected bits per page to compare
45 + * the correction density.
46 + */
47 + corr = (mtd->writesize * ecc->strength) / ecc->size;
48 + ds_corr = (mtd->writesize * chip->ecc_strength_ds) / chip->ecc_step_ds;
49 +
50 + return corr >= ds_corr && ecc->strength >= chip->ecc_strength_ds;
51 +}
52
53 /**
54 * nand_scan_tail - [NAND Interface] Scan for the NAND device
55 @@ -3891,6 +3924,9 @@ int nand_scan_tail(struct mtd_info *mtd)
56 ecc->layout->oobavail += ecc->layout->oobfree[i].length;
57 mtd->oobavail = ecc->layout->oobavail;
58
59 + /* ECC sanity check: warn noisily if it's too weak */
60 + WARN_ON(!nand_ecc_strength_good(mtd));
61 +
62 /*
63 * Set the number of read / write steps for one page depending on ECC
64 * mode.