Skip to content

Commit 3a4a893

Browse files
committed
mtd: rawnand: arasan: 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: Michal Simek <[email protected]> Cc: [email protected] Fixes: 88ffef1 ("mtd: rawnand: arasan: Support the hardware BCH ECC engine") Signed-off-by: Miquel Raynal <[email protected]> Acked-by: Michal Simek <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 9836a98 commit 3a4a893

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/mtd/nand/raw/arasan-nand-controller.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ static int anfc_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf,
515515
struct mtd_info *mtd = nand_to_mtd(chip);
516516
unsigned int len = mtd->writesize + (oob_required ? mtd->oobsize : 0);
517517
dma_addr_t dma_addr;
518+
u8 status;
518519
int ret;
519520
struct anfc_op nfc_op = {
520521
.pkt_reg =
@@ -561,10 +562,21 @@ static int anfc_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf,
561562
}
562563

563564
/* Spare data is not protected */
564-
if (oob_required)
565+
if (oob_required) {
565566
ret = nand_write_oob_std(chip, page);
567+
if (ret)
568+
return ret;
569+
}
566570

567-
return ret;
571+
/* Check write status on the chip side */
572+
ret = nand_status_op(chip, &status);
573+
if (ret)
574+
return ret;
575+
576+
if (status & NAND_STATUS_FAIL)
577+
return -EIO;
578+
579+
return 0;
568580
}
569581

570582
static int anfc_sel_write_page_hw_ecc(struct nand_chip *chip, const u8 *buf,

0 commit comments

Comments
 (0)