kernel: bump 5.4 to 5.4.58
[openwrt/openwrt.git] / target / linux / bcm63xx / patches-5.4 / 021-v5.8-mtd-rawnand-brcmnand-improve-hamming-oob-layout.patch
1 From d00358d7a1c50718232799e1ee10955bcd73795a Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
3 Date: Tue, 12 May 2020 09:57:33 +0200
4 Subject: [PATCH] mtd: rawnand: brcmnand: improve hamming oob layout
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 The current code generates 8 oob sections:
10 S1 1-5
11 ECC 6-8
12 S2 9-15
13 S3 16-21
14 ECC 22-24
15 S4 25-31
16 S5 32-37
17 ECC 38-40
18 S6 41-47
19 S7 48-53
20 ECC 54-56
21 S8 57-63
22
23 Change it by merging continuous sections:
24 S1 1-5
25 ECC 6-8
26 S2 9-21
27 ECC 22-24
28 S3 25-37
29 ECC 38-40
30 S4 41-53
31 ECC 54-56
32 S5 57-63
33
34 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
35 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
36 Link: https://lore.kernel.org/linux-mtd/20200512075733.745374-3-noltari@gmail.com
37 ---
38 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 35 +++++++++++-------------
39 1 file changed, 16 insertions(+), 19 deletions(-)
40
41 --- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
42 +++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
43 @@ -1004,33 +1004,30 @@ static int brcmnand_hamming_ooblayout_fr
44 struct brcmnand_cfg *cfg = &host->hwcfg;
45 int sas = cfg->spare_area_size << cfg->sector_size_1k;
46 int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
47 + u32 next;
48
49 - if (section >= sectors * 2)
50 + if (section > sectors)
51 return -ERANGE;
52
53 - oobregion->offset = (section / 2) * sas;
54 + next = (section * sas);
55 + if (section < sectors)
56 + next += 6;
57
58 - if (section & 1) {
59 - oobregion->offset += 9;
60 - oobregion->length = 7;
61 + if (section) {
62 + oobregion->offset = ((section - 1) * sas) + 9;
63 } else {
64 - oobregion->length = 6;
65 -
66 - /* First sector of each page may have BBI */
67 - if (!section) {
68 - /*
69 - * Small-page NAND use byte 6 for BBI while large-page
70 - * NAND use bytes 0 and 1.
71 - */
72 - if (cfg->page_size > 512) {
73 - oobregion->offset += 2;
74 - oobregion->length -= 2;
75 - } else {
76 - oobregion->length--;
77 - }
78 + if (cfg->page_size > 512) {
79 + /* Large page NAND uses first 2 bytes for BBI */
80 + oobregion->offset = 2;
81 + } else {
82 + /* Small page NAND uses last byte before ECC for BBI */
83 + oobregion->offset = 0;
84 + next--;
85 }
86 }
87
88 + oobregion->length = next - oobregion->offset;
89 +
90 return 0;
91 }
92