@@ -1106,6 +1106,7 @@ static int sunxi_nfc_read_column(struct nand_chip *nand, int page,
struct sunxi_nfc_ecc_read {
u8 *buf;
int page;
+ int first_req_step;
unsigned int max_bitflips;
bool oob_required;
bool dma;
@@ -1234,6 +1235,9 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand,
int bitflips;
user_data_sz = sunxi_nfc_user_data_sz(sunxi_nand, step);
+ if (step < read->first_req_step)
+ continue;
+
if (status & NFC_ECC_ERR(slot)) {
/* Preserve PIO data before the raw erased-page check. */
if (!read->dma && !randomized)
@@ -1294,7 +1298,7 @@ static int sunxi_nfc_oob_read_batch(struct nand_chip *nand,
for (slot = 0; slot < nsteps; slot++) {
int step = first_step + slot;
- if (!(status & NFC_ECC_ERR(slot)))
+ if (step < read->first_req_step || !(status & NFC_ECC_ERR(slot)))
continue;
ret = sunxi_nfc_hw_ecc_read_error(nand, read, step);
@@ -1451,12 +1455,14 @@ static int sunxi_nfc_hw_ecc_read_batch_dma(struct nand_chip *nand,
}
static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf,
- int oob_required, int page, int nchunks)
+ int oob_required, int page,
+ int first_req_step, int end_step)
{
struct mtd_info *mtd = nand_to_mtd(nand);
struct sunxi_nfc_ecc_read read = {
.buf = buf,
.page = page,
+ .first_req_step = first_req_step,
.oob_required = oob_required,
.dma = true,
};
@@ -1464,8 +1470,9 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, u8 *buf,
unsigned int failed = mtd->ecc_stats.failed;
int first_step, batch_steps, ret;
- for (first_step = 0; first_step < nchunks; first_step += batch_steps) {
- batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, nchunks);
+ /* PAGE_OP transfers a prefix; only the requested steps contribute ECC results. */
+ for (first_step = 0; first_step < end_step; first_step += batch_steps) {
+ batch_steps = sunxi_nfc_dma_batch_steps(nand, first_step, end_step);
ret = sunxi_nfc_hw_ecc_read_batch_dma(nand, &read, first_step, batch_steps);
if (ret)
goto err_stats;
@@ -1618,7 +1625,7 @@ static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
if (ret)
return ret;
- ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page,
+ ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page, 0,
nand->ecc.steps);
if (ret >= 0)
return ret;
@@ -1641,14 +1648,15 @@ static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
u32 data_offs, u32 readlen,
u8 *buf, int page)
{
- int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
+ int first_step = data_offs / nand->ecc.size;
+ int end_step = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
int ret;
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);
+ ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, first_step, end_step);
if (ret >= 0)
return ret;