Skip to content

Commit 3e01d52

Browse files
committed
mtd: rawnand: marvell: Ensure program page operations are successful
The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* successful. The NAND core offers helpers to finish a page write (sending the "PAGE PROG" command, waiting for the NAND chip to be ready again, and checking the operation status). But in some cases, advanced controller drivers might want to optimize this and craft their own page write helper to leverage additional hardware capabilities, thus not always using the core facilities. Some drivers, like this one, do not use the core helper to finish a page write because the final cycles are automatically managed by the hardware. In this case, the additional care must be taken to manually perform the final status check. Let's read the NAND chip status at the end of the page write helper and return -EIO upon error. Cc: [email protected] Fixes: 02f26ec ("mtd: nand: add reworked Marvell NAND controller driver") Reported-by: Aviram Dali <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Tested-by: Ravi Chandra Minnikanti <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 0bb80ec commit 3e01d52

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/mtd/nand/raw/marvell_nand.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,7 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip,
11651165
.ndcb[2] = NDCB2_ADDR5_PAGE(page),
11661166
};
11671167
unsigned int oob_bytes = lt->spare_bytes + (raw ? lt->ecc_bytes : 0);
1168+
u8 status;
11681169
int ret;
11691170

11701171
/* NFCv2 needs more information about the operation being executed */
@@ -1198,7 +1199,18 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip,
11981199

11991200
ret = marvell_nfc_wait_op(chip,
12001201
PSEC_TO_MSEC(sdr->tPROG_max));
1201-
return ret;
1202+
if (ret)
1203+
return ret;
1204+
1205+
/* Check write status on the chip side */
1206+
ret = nand_status_op(chip, &status);
1207+
if (ret)
1208+
return ret;
1209+
1210+
if (status & NAND_STATUS_FAIL)
1211+
return -EIO;
1212+
1213+
return 0;
12021214
}
12031215

12041216
static int marvell_nfc_hw_ecc_hmg_write_page_raw(struct nand_chip *chip,
@@ -1627,6 +1639,7 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip,
16271639
int data_len = lt->data_bytes;
16281640
int spare_len = lt->spare_bytes;
16291641
int chunk, ret;
1642+
u8 status;
16301643

16311644
marvell_nfc_select_target(chip, chip->cur_cs);
16321645

@@ -1663,6 +1676,14 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip,
16631676
if (ret)
16641677
return ret;
16651678

1679+
/* Check write status on the chip side */
1680+
ret = nand_status_op(chip, &status);
1681+
if (ret)
1682+
return ret;
1683+
1684+
if (status & NAND_STATUS_FAIL)
1685+
return -EIO;
1686+
16661687
return 0;
16671688
}
16681689

0 commit comments

Comments
 (0)