Commit 79da1707 authored by Miquel Raynal's avatar Miquel Raynal

mtd: spi-nand: Isolate the MTD read logic in a helper

There is currently only a single path for performing page reads as
requested by the MTD layer. Soon there will be two:
- a "regular" page read
- a continuous page read

Let's extract the page read logic in a dedicated helper, so the
introduction of continuous page reads will be as easy as checking whether
continuous reads shall/can be used and calling one helper or the other.

There is not behavioral change intended.
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20240826101412.20644-4-miquel.raynal@bootlin.com
parent 8adf1ac2
...@@ -630,25 +630,20 @@ static int spinand_write_page(struct spinand_device *spinand, ...@@ -630,25 +630,20 @@ static int spinand_write_page(struct spinand_device *spinand,
return nand_ecc_finish_io_req(nand, (struct nand_page_io_req *)req); return nand_ecc_finish_io_req(nand, (struct nand_page_io_req *)req);
} }
static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, static int spinand_mtd_regular_page_read(struct mtd_info *mtd, loff_t from,
struct mtd_oob_ops *ops) struct mtd_oob_ops *ops,
unsigned int *max_bitflips)
{ {
struct spinand_device *spinand = mtd_to_spinand(mtd); struct spinand_device *spinand = mtd_to_spinand(mtd);
struct nand_device *nand = mtd_to_nanddev(mtd); struct nand_device *nand = mtd_to_nanddev(mtd);
struct mtd_ecc_stats old_stats;
unsigned int max_bitflips = 0;
struct nand_io_iter iter; struct nand_io_iter iter;
bool disable_ecc = false; bool disable_ecc = false;
bool ecc_failed = false; bool ecc_failed = false;
int ret = 0; int ret;
if (ops->mode == MTD_OPS_RAW || !spinand->eccinfo.ooblayout) if (ops->mode == MTD_OPS_RAW || !mtd->ooblayout)
disable_ecc = true; disable_ecc = true;
mutex_lock(&spinand->lock);
old_stats = mtd->ecc_stats;
nanddev_io_for_each_page(nand, NAND_PAGE_READ, from, ops, &iter) { nanddev_io_for_each_page(nand, NAND_PAGE_READ, from, ops, &iter) {
if (disable_ecc) if (disable_ecc)
iter.req.mode = MTD_OPS_RAW; iter.req.mode = MTD_OPS_RAW;
...@@ -664,13 +659,33 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, ...@@ -664,13 +659,33 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
if (ret == -EBADMSG) if (ret == -EBADMSG)
ecc_failed = true; ecc_failed = true;
else else
max_bitflips = max_t(unsigned int, max_bitflips, ret); *max_bitflips = max_t(unsigned int, *max_bitflips, ret);
ret = 0; ret = 0;
ops->retlen += iter.req.datalen; ops->retlen += iter.req.datalen;
ops->oobretlen += iter.req.ooblen; ops->oobretlen += iter.req.ooblen;
} }
if (ecc_failed && !ret)
ret = -EBADMSG;
return ret;
}
static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
struct mtd_oob_ops *ops)
{
struct spinand_device *spinand = mtd_to_spinand(mtd);
struct mtd_ecc_stats old_stats;
unsigned int max_bitflips = 0;
int ret;
mutex_lock(&spinand->lock);
old_stats = mtd->ecc_stats;
ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
if (ops->stats) { if (ops->stats) {
ops->stats->uncorrectable_errors += ops->stats->uncorrectable_errors +=
mtd->ecc_stats.failed - old_stats.failed; mtd->ecc_stats.failed - old_stats.failed;
...@@ -680,9 +695,6 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from, ...@@ -680,9 +695,6 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
mutex_unlock(&spinand->lock); mutex_unlock(&spinand->lock);
if (ecc_failed && !ret)
ret = -EBADMSG;
return ret ? ret : max_bitflips; return ret ? ret : max_bitflips;
} }
......
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