]> www.infradead.org Git - users/hch/misc.git/commitdiff
mtd: spinand: repeat reading in regular mode if continuous reading fails
authorMikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Wed, 17 Sep 2025 21:54:01 +0000 (00:54 +0300)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 29 Sep 2025 15:53:08 +0000 (17:53 +0200)
Continuous reading may result in multiple flash pages reading in one
operation. Unfortunately, not all spinand controllers support such
large reading. They will read less data. Unfortunately, the operation
can't be continued.

In this case:
 * disable continuous reading on this (not good enough) spi controller
 * repeat reading in regular mode.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/nand/spi/core.c

index 58ec85c98ab84fa478bb487cef8c16fc7549a24d..f92133b8e1a60636f48ec71a5334dd4b84e3c330 100644 (file)
@@ -430,8 +430,16 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
                 * Dirmap accesses are allowed to toggle the CS.
                 * Toggling the CS during a continuous read is forbidden.
                 */
-               if (nbytes && req->continuous)
-                       return -EIO;
+               if (nbytes && req->continuous) {
+                       /*
+                        * Spi controller with broken support of continuous
+                        * reading was detected. Disable future use of
+                        * continuous reading and return -EAGAIN to retry
+                        * reading within regular mode.
+                        */
+                       spinand->cont_read_possible = false;
+                       return -EAGAIN;
+               }
        }
 
        if (req->datalen)
@@ -899,10 +907,19 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
 
        old_stats = mtd->ecc_stats;
 
-       if (spinand_use_cont_read(mtd, from, ops))
+       if (spinand_use_cont_read(mtd, from, ops)) {
                ret = spinand_mtd_continuous_page_read(mtd, from, ops, &max_bitflips);
-       else
+               if (ret == -EAGAIN && !spinand->cont_read_possible) {
+                       /*
+                        * Spi controller with broken support of continuous
+                        * reading was detected (see spinand_read_from_cache_op()),
+                        * repeat reading in regular mode.
+                        */
+                       ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
+               }
+       } else {
                ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
+       }
 
        if (ops->stats) {
                ops->stats->uncorrectable_errors +=