nand: gpmc: Handle bitflips in erased pages when using BCH ECC engine
authorDavid Rivshin <DRivshin@allworx.com>
Thu, 18 Nov 2021 18:25:24 +0000 (13:25 -0500)
committerTom Rini <trini@konsulko.com>
Sun, 16 Jan 2022 13:31:03 +0000 (08:31 -0500)
commitf44bcb9f0d73c13738b8f3e437bda75fda642ad7
treee552e7973388813473581560b3ba37245e3b289d
parenta6e562fe36b2bae780589a81a11fceb6e1b4a9f7
nand: gpmc: Handle bitflips in erased pages when using BCH ECC engine

In the case of an erased (sub)page both the data and ECC are all 0xFF
bytes. This fails the normal ECC verification, as the computed ECC of
all-0xFF is not also 0xFF. The GPMC NAND driver attempted to detect
erased pages by checking that the ECC bytes are all-0xFF, but this had
two problems:
1) bitflips in the data were not corrected, so the data looked not-erased
2) bitflips in the ECC bytes were reported as uncorrectable ECC errors

The equivalent Linux driver [1] correctly handles this by counting the
number of 0-bits in the combination of data and ECC bytes. If the number
of 0-bits is less than the amount of bits correctable by the selected
ECC algorithm, then it is treated as an erased page with correctable
bitflips.

Implement similar, though simplified, logic in omap_correct_data_bch().

[1] see omap_elm_correct_data() in omap2.c

Signed-off-by: David Rivshin <drivshin@allworx.com>
drivers/mtd/nand/raw/omap_gpmc.c