Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtd: rawnand: sunxi: do not count BBM bytes twice

BBM is already part of USER_DATA section, so we should not remove it twice

This was working ok because we are on the safe size, advertising that
there was 2 bytes less available than in reality.

But we can't change old platforms, since it may lead to a different ECC
strength, so, introduce a legacy flag for old platforms, and switch the
new platforms to the correct count.

Signed-off-by: Richard Genoud <richard.genoud@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

authored by

Richard Genoud and committed by
Miquel Raynal
8fa72836 848c1399

+20 -3
+20 -3
drivers/mtd/nand/raw/sunxi_nand.c
··· 275 275 * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chuncks 276 276 * @has_ecc_clk: If the controller needs an ECC clock. 277 277 * @has_mbus_clk: If the controller needs a mbus clock. 278 + * @legacy_max_strength:If the maximize strength function was off by 2 bytes 279 + * NB: this should not be used in new controllers 278 280 * @reg_io_data: I/O data register 279 281 * @reg_ecc_err_cnt: ECC error counter register 280 282 * @reg_user_data: User data register ··· 306 304 bool has_ecc_block_512; 307 305 bool has_ecc_clk; 308 306 bool has_mbus_clk; 307 + bool legacy_max_strength; 309 308 unsigned int reg_io_data; 310 309 unsigned int reg_ecc_err_cnt; 311 310 unsigned int reg_user_data; ··· 1808 1805 ecc->size = 1024; 1809 1806 nsectors = mtd->writesize / ecc->size; 1810 1807 1811 - /* Reserve 2 bytes for the BBM */ 1812 - bytes = (mtd->oobsize - 2) / nsectors; 1808 + /* 1809 + * The 2 BBM bytes should not be removed from the grand total, 1810 + * because they are part of the USER_DATA_SZ. 1811 + * But we can't modify that for older platform since it may 1812 + * result in a stronger ECC at the end, and break the 1813 + * compatibility. 1814 + */ 1815 + if (nfc->caps->legacy_max_strength) 1816 + bytes = (mtd->oobsize - 2) / nsectors; 1817 + else 1818 + bytes = mtd->oobsize / nsectors; 1813 1819 1814 - /* 4 non-ECC bytes are added before each ECC bytes section */ 1820 + /* 1821 + * USER_DATA_SZ non-ECC bytes are added before each ECC bytes 1822 + * section, they contain the 2 BBM bytes 1823 + */ 1815 1824 bytes -= USER_DATA_SZ; 1816 1825 1817 1826 /* and bytes has to be even. */ ··· 2388 2373 2389 2374 static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = { 2390 2375 .has_ecc_block_512 = true, 2376 + .legacy_max_strength = true, 2391 2377 .reg_io_data = NFC_REG_A10_IO_DATA, 2392 2378 .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, 2393 2379 .reg_user_data = NFC_REG_A10_USER_DATA, ··· 2410 2394 static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = { 2411 2395 .has_mdma = true, 2412 2396 .has_ecc_block_512 = true, 2397 + .legacy_max_strength = true, 2413 2398 .reg_io_data = NFC_REG_A23_IO_DATA, 2414 2399 .reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT, 2415 2400 .reg_user_data = NFC_REG_A10_USER_DATA,