Commit 3e01d525 authored by Miquel Raynal's avatar Miquel Raynal

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: stable@vger.kernel.org
Fixes: 02f26ecf ("mtd: nand: add reworked Marvell NAND controller driver")
Reported-by: default avatarAviram Dali <aviramd@marvell.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Tested-by: default avatarRavi Chandra Minnikanti <rminnikanti@marvell.com>
Link: https://lore.kernel.org/linux-mtd/20230717194221.229778-1-miquel.raynal@bootlin.com
parent 0bb80ecc
...@@ -1165,6 +1165,7 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip, ...@@ -1165,6 +1165,7 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip,
.ndcb[2] = NDCB2_ADDR5_PAGE(page), .ndcb[2] = NDCB2_ADDR5_PAGE(page),
}; };
unsigned int oob_bytes = lt->spare_bytes + (raw ? lt->ecc_bytes : 0); unsigned int oob_bytes = lt->spare_bytes + (raw ? lt->ecc_bytes : 0);
u8 status;
int ret; int ret;
/* NFCv2 needs more information about the operation being executed */ /* 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, ...@@ -1198,7 +1199,18 @@ static int marvell_nfc_hw_ecc_hmg_do_write_page(struct nand_chip *chip,
ret = marvell_nfc_wait_op(chip, ret = marvell_nfc_wait_op(chip,
PSEC_TO_MSEC(sdr->tPROG_max)); PSEC_TO_MSEC(sdr->tPROG_max));
if (ret)
return ret;
/* Check write status on the chip side */
ret = nand_status_op(chip, &status);
if (ret)
return ret; return ret;
if (status & NAND_STATUS_FAIL)
return -EIO;
return 0;
} }
static int marvell_nfc_hw_ecc_hmg_write_page_raw(struct nand_chip *chip, 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, ...@@ -1627,6 +1639,7 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip,
int data_len = lt->data_bytes; int data_len = lt->data_bytes;
int spare_len = lt->spare_bytes; int spare_len = lt->spare_bytes;
int chunk, ret; int chunk, ret;
u8 status;
marvell_nfc_select_target(chip, chip->cur_cs); marvell_nfc_select_target(chip, chip->cur_cs);
...@@ -1663,6 +1676,14 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip, ...@@ -1663,6 +1676,14 @@ static int marvell_nfc_hw_ecc_bch_write_page(struct nand_chip *chip,
if (ret) if (ret)
return ret; return ret;
/* Check write status on the chip side */
ret = nand_status_op(chip, &status);
if (ret)
return ret;
if (status & NAND_STATUS_FAIL)
return -EIO;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment