@@ -1120,11 +1120,16 @@ static int sunxi_nfc_hw_ecc_read_error(struct nand_chip *nand,
int ret;
/* Check the physical representation for bitflips in erased pages. */
- if (nand->options & NAND_NEED_SCRAMBLING)
- sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->size);
+ if (nand->options & NAND_NEED_SCRAMBLING) {
+ ret = sunxi_nfc_read_column(nand, read->page, data_off, data, ecc->size);
+ if (ret)
+ return ret;
+ }
- sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oob_off,
- oob, oob_len);
+ ret = sunxi_nfc_read_column(nand, read->page, nand_to_mtd(nand)->writesize + oob_off,
+ oob, oob_len);
+ if (ret)
+ return ret;
ret = nand_check_erased_ecc_chunk(data, ecc->size, oob, oob_len, NULL, 0,
ecc->strength);
@@ -1308,6 +1313,7 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf,
{
struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
+ struct mtd_info *mtd = nand_to_mtd(nand);
struct nand_ecc_ctrl *ecc = &nand->ecc;
struct sunxi_nfc_ecc_read read = {
.buf = buf,
@@ -1315,6 +1321,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf,
.oob_required = oob_required,
.dma = true,
};
+ unsigned int corrected = mtd->ecc_stats.corrected;
+ unsigned int failed = mtd->ecc_stats.failed;
struct scatterlist sg;
int ret, i;
u32 status, pattern_found, wait;
@@ -1366,9 +1374,19 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf,
ret = sunxi_nfc_oob_read_batch(nand, &read, status, pattern_found,
0, nchunks);
if (ret)
- return ret;
+ goto err_stats;
- return sunxi_nfc_oob_finish_read(nand, &read, NULL);
+ ret = sunxi_nfc_oob_finish_read(nand, &read, NULL);
+ if (ret < 0)
+ goto err_stats;
+
+ return ret;
+
+err_stats:
+ /* The caller retries the whole read in PIO mode. */
+ mtd->ecc_stats.corrected = corrected;
+ mtd->ecc_stats.failed = failed;
+ return ret;
}
static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand,
@@ -1453,7 +1471,9 @@ static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *buf,
};
int ret, step, cur_off = 0;
- nand_read_page_op(nand, page, 0, NULL, 0);
+ ret = nand_read_page_op(nand, page, 0, NULL, 0);
+ if (ret)
+ return ret;
sunxi_nfc_hw_ecc_enable(nand);
@@ -1461,10 +1481,11 @@ static int sunxi_nfc_hw_ecc_read_chunks_pio(struct nand_chip *nand, u8 *buf,
for (step = first_step; step < end_step; step++) {
ret = sunxi_nfc_hw_ecc_read_chunk(nand, &read, step, &cur_off);
if (ret < 0)
- return ret;
+ goto out;
}
ret = sunxi_nfc_oob_finish_read(nand, &read, &cur_off);
+out:
sunxi_nfc_hw_ecc_disable(nand);
return ret;
@@ -1482,7 +1503,9 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
{
int ret;
- nand_read_page_op(nand, page, 0, NULL, 0);
+ ret = nand_read_page_op(nand, page, 0, NULL, 0);
+ if (ret)
+ return ret;
ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page,
nand->ecc.steps);
@@ -1510,7 +1533,9 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
int ret;
- nand_read_page_op(nand, page, 0, NULL, 0);
+ ret = nand_read_page_op(nand, page, 0, NULL, 0);
+ if (ret)
+ return ret;
ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks);
if (ret >= 0)