Skip to content

Commit 18073e3

Browse files
committed
mtd: spi-nand: macronix: Extract the bitflip retrieval logic
With GET_STATUS commands, SPI-NAND devices can tell the status of the last read operation, in particular if there was: - no bitflips - corrected bitflips - uncorrectable bitflips The next step then to read an ECC status register and retrieve the amount of bitflips, when relevant, if possible. The logic used here works well for now, but will no longer apply to continuous reads. In order to prepare the introduction of continuous reads, let's factorize out the code that is specific to single-page reads. Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent ed148d3 commit 18073e3

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

drivers/mtd/nand/spi/macronix.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,29 @@ static int macronix_get_eccsr(struct spinand_device *spinand, u8 *eccsr)
6464
return 0;
6565
}
6666

67-
static int macronix_ecc_get_status(struct spinand_device *spinand,
68-
u8 status)
67+
static int macronix_get_bf(struct spinand_device *spinand, u8 status)
6968
{
7069
struct nand_device *nand = spinand_to_nand(spinand);
7170
u8 eccsr;
7271

72+
/*
73+
* Let's try to retrieve the real maximum number of bitflips
74+
* in order to avoid forcing the wear-leveling layer to move
75+
* data around if it's not necessary.
76+
*/
77+
if (macronix_get_eccsr(spinand, spinand->scratchbuf))
78+
return nanddev_get_ecc_conf(nand)->strength;
79+
80+
eccsr = *spinand->scratchbuf;
81+
if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength || !eccsr))
82+
return nanddev_get_ecc_conf(nand)->strength;
83+
84+
return eccsr;
85+
}
86+
87+
static int macronix_ecc_get_status(struct spinand_device *spinand,
88+
u8 status)
89+
{
7390
switch (status & STATUS_ECC_MASK) {
7491
case STATUS_ECC_NO_BITFLIPS:
7592
return 0;
@@ -78,21 +95,7 @@ static int macronix_ecc_get_status(struct spinand_device *spinand,
7895
return -EBADMSG;
7996

8097
case STATUS_ECC_HAS_BITFLIPS:
81-
/*
82-
* Let's try to retrieve the real maximum number of bitflips
83-
* in order to avoid forcing the wear-leveling layer to move
84-
* data around if it's not necessary.
85-
*/
86-
if (macronix_get_eccsr(spinand, spinand->scratchbuf))
87-
return nanddev_get_ecc_conf(nand)->strength;
88-
89-
eccsr = *spinand->scratchbuf;
90-
if (WARN_ON(eccsr > nanddev_get_ecc_conf(nand)->strength ||
91-
!eccsr))
92-
return nanddev_get_ecc_conf(nand)->strength;
93-
94-
return eccsr;
95-
98+
return macronix_get_bf(spinand, status);
9699
default:
97100
break;
98101
}

0 commit comments

Comments
 (0)