* [PATCH RESEND v5 1/3] mtd: spinand: fix direct mapping creation sizes
2025-09-17 21:53 [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
@ 2025-09-17 21:53 ` Mikhail Kshevetskiy
2025-09-17 21:54 ` [PATCH RESEND v5 2/3] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Mikhail Kshevetskiy @ 2025-09-17 21:53 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Tudor Ambarus, Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin,
linux-mtd, linux-kernel
Cc: Mikhail Kshevetskiy, Andreas Gnau
Continuous mode is only supported for data reads, thus writing
requires only single flash page mapping.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
drivers/mtd/nand/spi/core.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index b0898990b2a5..09dd6e40e308 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1097,18 +1097,13 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
unsigned int plane)
{
struct nand_device *nand = spinand_to_nand(spinand);
- struct spi_mem_dirmap_info info = {
- .length = nanddev_page_size(nand) +
- nanddev_per_page_oobsize(nand),
- };
+ struct spi_mem_dirmap_info info = { 0 };
struct spi_mem_dirmap_desc *desc;
- if (spinand->cont_read_possible)
- info.length = nanddev_eraseblock_size(nand);
-
/* The plane number is passed in MSB just above the column address */
info.offset = plane << fls(nand->memorg.pagesize);
+ info.length = nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
info.op_tmpl = *spinand->op_templates.update_cache;
desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
spinand->spimem, &info);
@@ -1117,6 +1112,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
spinand->dirmaps[plane].wdesc = desc;
+ if (spinand->cont_read_possible)
+ info.length = nanddev_eraseblock_size(nand);
info.op_tmpl = *spinand->op_templates.read_cache;
desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
spinand->spimem, &info);
@@ -1132,6 +1129,7 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
return 0;
}
+ info.length = nanddev_page_size(nand) + nanddev_per_page_oobsize(nand);
info.op_tmpl = *spinand->op_templates.update_cache;
info.op_tmpl.data.ecc = true;
desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
@@ -1141,6 +1139,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
spinand->dirmaps[plane].wdesc_ecc = desc;
+ if (spinand->cont_read_possible)
+ info.length = nanddev_eraseblock_size(nand);
info.op_tmpl = *spinand->op_templates.read_cache;
info.op_tmpl.data.ecc = true;
desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
--
2.51.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RESEND v5 2/3] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-09-17 21:53 [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-09-17 21:53 ` [PATCH RESEND v5 1/3] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
@ 2025-09-17 21:54 ` Mikhail Kshevetskiy
2025-09-17 21:54 ` [PATCH RESEND v5 3/3] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Mikhail Kshevetskiy @ 2025-09-17 21:54 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Tudor Ambarus, Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin,
linux-mtd, linux-kernel
Cc: Mikhail Kshevetskiy, Andreas Gnau
Continuous reading may result in multiple flash pages reading in one
operation. Typically only one flash page has read/written (a little bit
more than 2-4 Kb), but continuous reading requires the spi controller
to read up to 512 Kb in one operation without toggling CS in beetween.
Roughly speaking spi controllers can be divided on 2 categories:
* spi controllers without dirmap acceleration support
* spi controllers with dirmap acceleration support
Firt of them will have issues with continuous reading if restriction on
the transfer length is implemented in the adjust_op_size() handler.
Second group often supports acceleration of single page only reading.
Thus enabling of continuous reading can break flash reading.
This patch tries to create dirmap for continuous reading first and
fallback to regular reading if spi controller refuses to create it.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
drivers/mtd/nand/spi/core.c | 43 ++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 09dd6e40e308..02e322490110 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1093,6 +1093,39 @@ static int spinand_mtd_block_isreserved(struct mtd_info *mtd, loff_t offs)
return ret;
}
+static struct spi_mem_dirmap_desc *spinand_create_rdesc(
+ struct spinand_device *spinand,
+ struct spi_mem_dirmap_info *info)
+{
+ struct nand_device *nand = spinand_to_nand(spinand);
+ struct spi_mem_dirmap_desc *desc = NULL;
+
+ if (spinand->cont_read_possible) {
+ /*
+ * spi controller may return an error if info->length is
+ * too large
+ */
+ info->length = nanddev_eraseblock_size(nand);
+ desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
+ spinand->spimem, info);
+ }
+
+ if (IS_ERR_OR_NULL(desc)) {
+ /*
+ * continuous reading is not supported by flash or
+ * its spi controller, use regular reading
+ */
+ spinand->cont_read_possible = false;
+
+ info->length = nanddev_page_size(nand) +
+ nanddev_per_page_oobsize(nand);
+ desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
+ spinand->spimem, info);
+ }
+
+ return desc;
+}
+
static int spinand_create_dirmap(struct spinand_device *spinand,
unsigned int plane)
{
@@ -1112,11 +1145,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
spinand->dirmaps[plane].wdesc = desc;
- if (spinand->cont_read_possible)
- info.length = nanddev_eraseblock_size(nand);
info.op_tmpl = *spinand->op_templates.read_cache;
- desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
- spinand->spimem, &info);
+ desc = spinand_create_rdesc(spinand, &info);
if (IS_ERR(desc))
return PTR_ERR(desc);
@@ -1139,12 +1169,9 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
spinand->dirmaps[plane].wdesc_ecc = desc;
- if (spinand->cont_read_possible)
- info.length = nanddev_eraseblock_size(nand);
info.op_tmpl = *spinand->op_templates.read_cache;
info.op_tmpl.data.ecc = true;
- desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
- spinand->spimem, &info);
+ desc = spinand_create_rdesc(spinand, &info);
if (IS_ERR(desc))
return PTR_ERR(desc);
--
2.51.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH RESEND v5 3/3] mtd: spinand: repeat reading in regular mode if continuous reading fails
2025-09-17 21:53 [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-09-17 21:53 ` [PATCH RESEND v5 1/3] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-09-17 21:54 ` [PATCH RESEND v5 2/3] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-09-17 21:54 ` Mikhail Kshevetskiy
2025-09-18 8:26 ` [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Miquel Raynal
2025-09-29 15:53 ` Miquel Raynal
4 siblings, 0 replies; 8+ messages in thread
From: Mikhail Kshevetskiy @ 2025-09-17 21:54 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Tudor Ambarus, Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin,
linux-mtd, linux-kernel
Cc: Mikhail Kshevetskiy, Andreas Gnau
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>
---
drivers/mtd/nand/spi/core.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 02e322490110..8bbcc80aede0 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -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 +=
--
2.51.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support
2025-09-17 21:53 [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
` (2 preceding siblings ...)
2025-09-17 21:54 ` [PATCH RESEND v5 3/3] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
@ 2025-09-18 8:26 ` Miquel Raynal
2025-09-18 12:08 ` Mikhail Kshevetskiy
2025-09-29 15:53 ` Miquel Raynal
4 siblings, 1 reply; 8+ messages in thread
From: Miquel Raynal @ 2025-09-18 8:26 UTC (permalink / raw)
To: Mikhail Kshevetskiy
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, Andreas Gnau
Hi Mikhail,
> Changes v5:
> * rename spinand_create_rdesc_helper() to spinand_create_rdesc()
> * get rid of controller_is_buggy boolean
I received patch 0 and 1 over 3 only. Plus, what is the reason for the
resend? This series was no longer in my watch list which means I was
probably expecting changes on it, which would have lead to a version
increase. Can you please clarify?
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support
2025-09-18 8:26 ` [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Miquel Raynal
@ 2025-09-18 12:08 ` Mikhail Kshevetskiy
0 siblings, 0 replies; 8+ messages in thread
From: Mikhail Kshevetskiy @ 2025-09-18 12:08 UTC (permalink / raw)
To: Miquel Raynal
Cc: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, Andreas Gnau
Hello Miquèl,
On 18.09.2025 11:26, Miquel Raynal wrote:
> Hi Mikhail,
>
>> Changes v5:
>> * rename spinand_create_rdesc_helper() to spinand_create_rdesc()
>> * get rid of controller_is_buggy boolean
> I received patch 0 and 1 over 3 only.
Quite strange, you was in the "--to" list. Also
https://lkml.org/lkml/2025/9/18/15 see all the series. Could you check
your spam folder and mailer settings?
> Plus, what is the reason for the resend?
No any activities/responds for 2 weeks. This looks like the mails were
lost in the tons of other mails :-(
> This series was no longer in my watch list which means I was
> probably expecting changes on it, which would have lead to a version
> increase. Can you please clarify?
Hm, I think, I resolve all the issues you mentioned before (in v4 and
v5). Could you look one more time?
>
> Thanks,
> Miquèl
Thanks,
Mikhail Kshevetskiy
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support
2025-09-17 21:53 [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
` (3 preceding siblings ...)
2025-09-18 8:26 ` [PATCH RESEND v5 0/3] mtd: spinand: fix continuous reading mode support Miquel Raynal
@ 2025-09-29 15:53 ` Miquel Raynal
4 siblings, 0 replies; 8+ messages in thread
From: Miquel Raynal @ 2025-09-29 15:53 UTC (permalink / raw)
To: Richard Weinberger, Vignesh Raghavendra, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, Mikhail Kshevetskiy
Cc: Andreas Gnau
On Thu, 18 Sep 2025 00:53:58 +0300, Mikhail Kshevetskiy wrote:
> Continuous reading mode is broken for some spi controllers. There are two
> possible bug scenarios:
>
> 1) "continuous mode" flash and spi controller without dirmap support,
> but with restriction on transfer length in adjust_op_size()
>
> 2) "continuous mode" flash and spi controller with dirmap support for a
> single flash page
>
> [...]
Applied to nand/next, thanks!
[1/3] mtd: spinand: fix direct mapping creation sizes
commit: e4a0cf9f1d90e6888e5373da3314f761024f6c97
[2/3] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
commit: 004f8ea0d9917398aabff7388b3bf62a84a4088b
[3/3] mtd: spinand: repeat reading in regular mode if continuous reading fails
commit: 010dc7f2dd6a0078ade3f88f627ed5fbf45ceb94
Patche(s) should be available on mtd/linux.git and will be
part of the next PR (provided that no robot complains by then).
Kind regards,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 8+ messages in thread