* [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode
@ 2025-08-04 19:21 Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes Mikhail Kshevetskiy
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-04 19:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
Continuous reading mode is broken for some spi-controllers. This may lead
to errors during reading of more than one flash page at once. This patch
series improve continuous mode support and add a fallback to regular
reading method if continuous reading is not supported by spi-controller.
Mikhail Kshevetskiy (4):
drivers: mtd: spi-nand: fix direct mapping creation sizes.
drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for
continuous reading fails
drivers: mtd: spi-nand: repeat reading in regular mode if continuous
reading fails
drivers: spi: spi-airoha-snfi: return an error for continuous mode
dirmap creation cases
drivers/mtd/nand/spi/core.c | 54 ++++++++++++++++++++++++++++-------
drivers/spi/spi-airoha-snfi.c | 4 +++
2 files changed, 48 insertions(+), 10 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes.
2025-08-04 19:21 [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode Mikhail Kshevetskiy
@ 2025-08-04 19:21 ` Mikhail Kshevetskiy
2025-08-05 15:24 ` Miquel Raynal
2025-08-04 19:21 ` [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
` (2 subsequent siblings)
3 siblings, 1 reply; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-04 19:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
Continuous mode is only supported for non-raw data reads, thus raw I/O
or non-raw writing requires only single flash page mapping.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
drivers/mtd/nand/spi/core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index b0898990b2a5..b42c42ec58a4 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1103,9 +1103,6 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
};
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);
@@ -1117,6 +1114,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 +1131,9 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
return 0;
}
+ // ECC reading/writing always happen in non-continuous mode
+ 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,
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-08-04 19:21 [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes Mikhail Kshevetskiy
@ 2025-08-04 19:21 ` Mikhail Kshevetskiy
2025-08-05 15:30 ` Miquel Raynal
2025-08-04 19:21 ` [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 4/4] drivers: spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
3 siblings, 1 reply; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-04 19:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
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 togling 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
Usually, first of them have no issues with large reading support.
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 | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index b42c42ec58a4..ff6a1e2fcfdc 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1114,11 +1114,32 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
spinand->dirmaps[plane].wdesc = desc;
- if (spinand->cont_read_possible)
+ desc = NULL;
+ if (spinand->cont_read_possible) {
+ /*
+ * spi-controllers may return an error if info.length is
+ * too large
+ */
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);
+ info.op_tmpl = *spinand->op_templates.read_cache;
+ 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, try regular reading
+ */
+ spinand->cont_read_possible = false;
+
+ info.length = nanddev_page_size(nand) +
+ nanddev_per_page_oobsize(nand);
+ info.op_tmpl = *spinand->op_templates.read_cache;
+ desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
+ spinand->spimem, &info);
+ }
+
if (IS_ERR(desc))
return PTR_ERR(desc);
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails
2025-08-04 19:21 [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-08-04 19:21 ` Mikhail Kshevetskiy
2025-08-05 15:36 ` Miquel Raynal
2025-08-04 19:21 ` [PATCH 4/4] drivers: spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
3 siblings, 1 reply; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-04 19:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
Continuous reading may result in multiple flash pages reading in one
operation. Unfortunately, not all spi-nand 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 | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index ff6a1e2fcfdc..88e4c00cccc4 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -431,7 +431,7 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
* Toggling the CS during a continuous read is forbidden.
*/
if (nbytes && req->continuous)
- return -EIO;
+ return -E2BIG;
}
if (req->datalen)
@@ -893,15 +893,26 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
struct spinand_device *spinand = mtd_to_spinand(mtd);
struct mtd_ecc_stats old_stats;
unsigned int max_bitflips = 0;
- int ret;
+ int ret = -E2BIG;
mutex_lock(&spinand->lock);
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 == -E2BIG) {
+ /*
+ * Some spi controllers may not support reading up to
+ * erase block size. They will read less data than
+ * expected. If this happen disable continuous mode
+ * and repeat reading in normal mode.
+ */
+ spinand->cont_read_possible = false;
+ }
+ }
+
+ if (ret == -E2BIG)
ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
if (ops->stats) {
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 4/4] drivers: spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
2025-08-04 19:21 [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode Mikhail Kshevetskiy
` (2 preceding siblings ...)
2025-08-04 19:21 ` [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails Mikhail Kshevetskiy
@ 2025-08-04 19:21 ` Mikhail Kshevetskiy
3 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-04 19:21 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
This driver can accelerate single page operations only, thus
continuous reading mode should not be used.
Continuous reading will use sizes up to the size of one erase block.
This size is much larger than the size of single flash page. Use this
difference to identify continuous reading and return an error.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
drivers/spi/spi-airoha-snfi.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index dbe640986825..043a03cd90a1 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -618,6 +618,10 @@ static int airoha_snand_dirmap_create(struct spi_mem_dirmap_desc *desc)
if (desc->info.offset + desc->info.length > U32_MAX)
return -EINVAL;
+ /* continuous reading is not supported */
+ if (desc->info.length > SPI_NAND_CACHE_SIZE)
+ return -E2BIG;
+
if (!airoha_snand_supports_op(desc->mem, &desc->info.op_tmpl))
return -EOPNOTSUPP;
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes.
2025-08-04 19:21 ` [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes Mikhail Kshevetskiy
@ 2025-08-05 15:24 ` Miquel Raynal
0 siblings, 0 replies; 16+ messages in thread
From: Miquel Raynal @ 2025-08-05 15:24 UTC (permalink / raw)
To: Mikhail Kshevetskiy
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
Hello Mikhail,
Thanks a lot for this series!
On 04/08/2025 at 22:21:29 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:
> Continuous mode is only supported for non-raw data reads, thus raw I/O
> or non-raw writing requires only single flash page mapping.
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
> drivers/mtd/nand/spi/core.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index b0898990b2a5..b42c42ec58a4 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -1103,9 +1103,6 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
> };
> 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);
>
> @@ -1117,6 +1114,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 +1131,9 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
> return 0;
> }
>
> + // ECC reading/writing always happen in non-continuous mode
This comment does not sound helpful, at least I do not understand it?
(and the comment style should be /* */)
> + 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,
May I suggest to use two different dirmap infos? One with a large size
(for reads) and a page-sized one for other cases (including the fallback
you're introducing in PATCH 2).
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-08-04 19:21 ` [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-08-05 15:30 ` Miquel Raynal
2025-08-05 15:35 ` Mikhail Kshevetskiy
0 siblings, 1 reply; 16+ messages in thread
From: Miquel Raynal @ 2025-08-05 15:30 UTC (permalink / raw)
To: Mikhail Kshevetskiy
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
On 04/08/2025 at 22:21:30 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:
> 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 togling 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
>
> Usually, first of them have no issues with large reading support.
> Second group often supports acceleration of single page only reading.
> Thus enabling of continuous reading can break flash reading.
I would be more conservative, I believe it is very implementation
dependent; many controller drivers do not even advertise a max size.
I agree though that controllers with dirmap support may express
limitations such as the mapped size which may lead to splitting
operations into smaller chunks, possibly leading to CS changes which
would break the continuous read mode on the chip's side.
> This patch tries to create dirmap for continuous reading first and
> fallback to regular reading if spi-controller refuses to create it.
no '-' ^
>
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
> ---
> drivers/mtd/nand/spi/core.c | 29 +++++++++++++++++++++++++----
> 1 file changed, 25 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index b42c42ec58a4..ff6a1e2fcfdc 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -1114,11 +1114,32 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
>
> spinand->dirmaps[plane].wdesc = desc;
>
> - if (spinand->cont_read_possible)
> + desc = NULL;
> + if (spinand->cont_read_possible) {
> + /*
> + * spi-controllers may return an error if info.length is
> + * too large
> + */
> 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);
> + info.op_tmpl = *spinand->op_templates.read_cache;
> + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
> + spinand->spimem, &info);
> + }
> +
> + if (IS_ERR_OR_NULL(desc)) {
Here if the problem is continuous reading, I expect an error and not a
NULL pointer.
> + /*
> + * continuous reading is not supported by flash or
Not by the flash, here if we get an error, it is the spi controller
(still without '-' ;) ) that fails (please fix the comment).
> + * its spi-controller, try regular reading
> + */
> + spinand->cont_read_possible = false;
> +
> + info.length = nanddev_page_size(nand) +
> + nanddev_per_page_oobsize(nand);
> + info.op_tmpl = *spinand->op_templates.read_cache;
> + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
> + spinand->spimem, &info);
> + }
> +
> if (IS_ERR(desc))
> return PTR_ERR(desc);
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-08-05 15:30 ` Miquel Raynal
@ 2025-08-05 15:35 ` Mikhail Kshevetskiy
2025-08-06 9:03 ` Miquel Raynal
0 siblings, 1 reply; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-05 15:35 UTC (permalink / raw)
To: Miquel Raynal
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
On 05.08.2025 18:30, Miquel Raynal wrote:
> On 04/08/2025 at 22:21:30 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:
>
>> 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 togling 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
>>
>> Usually, first of them have no issues with large reading support.
>> Second group often supports acceleration of single page only reading.
>> Thus enabling of continuous reading can break flash reading.
> I would be more conservative, I believe it is very implementation
> dependent; many controller drivers do not even advertise a max size.
>
> I agree though that controllers with dirmap support may express
> limitations such as the mapped size which may lead to splitting
> operations into smaller chunks, possibly leading to CS changes which
> would break the continuous read mode on the chip's side.
>
>> This patch tries to create dirmap for continuous reading first and
>> fallback to regular reading if spi-controller refuses to create it.
> no '-' ^
>
>> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
>> ---
>> drivers/mtd/nand/spi/core.c | 29 +++++++++++++++++++++++++----
>> 1 file changed, 25 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
>> index b42c42ec58a4..ff6a1e2fcfdc 100644
>> --- a/drivers/mtd/nand/spi/core.c
>> +++ b/drivers/mtd/nand/spi/core.c
>> @@ -1114,11 +1114,32 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
>>
>> spinand->dirmaps[plane].wdesc = desc;
>>
>> - if (spinand->cont_read_possible)
>> + desc = NULL;
>> + if (spinand->cont_read_possible) {
>> + /*
>> + * spi-controllers may return an error if info.length is
>> + * too large
>> + */
>> 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);
>> + info.op_tmpl = *spinand->op_templates.read_cache;
>> + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
>> + spinand->spimem, &info);
>> + }
>> +
>> + if (IS_ERR_OR_NULL(desc)) {
> Here if the problem is continuous reading, I expect an error and not a
> NULL pointer.
NULL is possible if flash does not supports continuous reading
>
>> + /*
>> + * continuous reading is not supported by flash or
> Not by the flash, here if we get an error, it is the spi controller
> (still without '-' ;) ) that fails (please fix the comment).
we can go here in 2 cases:
1) spinand->cont_read_possible is false (flash does not supports
continuous reading)
2) spi controller returns an error (spi controller does not like
continuous reading)
>
>> + * its spi-controller, try regular reading
>> + */
>> + spinand->cont_read_possible = false;
>> +
>> + info.length = nanddev_page_size(nand) +
>> + nanddev_per_page_oobsize(nand);
>> + info.op_tmpl = *spinand->op_templates.read_cache;
>> + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
>> + spinand->spimem, &info);
>> + }
>> +
>> if (IS_ERR(desc))
>> return PTR_ERR(desc);
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails
2025-08-04 19:21 ` [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails Mikhail Kshevetskiy
@ 2025-08-05 15:36 ` Miquel Raynal
2025-08-18 12:05 ` Mikhail Kshevetskiy
0 siblings, 1 reply; 16+ messages in thread
From: Miquel Raynal @ 2025-08-05 15:36 UTC (permalink / raw)
To: Mikhail Kshevetskiy
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
On 04/08/2025 at 22:21:31 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:
> Continuous reading may result in multiple flash pages reading in one
> operation. Unfortunately, not all spi-nand 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 | 19 +++++++++++++++----
> 1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index ff6a1e2fcfdc..88e4c00cccc4 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -431,7 +431,7 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
> * Toggling the CS during a continuous read is forbidden.
> */
> if (nbytes && req->continuous)
> - return -EIO;
> + return -E2BIG;
> }
>
> if (req->datalen)
> @@ -893,15 +893,26 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
> struct spinand_device *spinand = mtd_to_spinand(mtd);
> struct mtd_ecc_stats old_stats;
> unsigned int max_bitflips = 0;
> - int ret;
> + int ret = -E2BIG;
>
> mutex_lock(&spinand->lock);
>
> 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 == -E2BIG) {
> + /*
> + * Some spi controllers may not support reading up to
> + * erase block size. They will read less data than
> + * expected. If this happen disable continuous mode
happens,
> + * and repeat reading in normal mode.
> + */
> + spinand->cont_read_possible = false;
> + }
> + }
> +
> + if (ret == -E2BIG)
While I agree with the overall logic, I find pretty unreadable to
perform the regular read upon a return value that is an error code set
in the init sequence. Can you please propose an alternate implementation?
> ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
>
> if (ops->stats) {
Thanks!
Miquèl
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-08-05 15:35 ` Mikhail Kshevetskiy
@ 2025-08-06 9:03 ` Miquel Raynal
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
0 siblings, 1 reply; 16+ messages in thread
From: Miquel Raynal @ 2025-08-06 9:03 UTC (permalink / raw)
To: Mikhail Kshevetskiy
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
Hello,
>>> @@ -1114,11 +1114,32 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
>>>
>>> spinand->dirmaps[plane].wdesc = desc;
>>>
>>> - if (spinand->cont_read_possible)
>>> + desc = NULL;
>>> + if (spinand->cont_read_possible) {
>>> + /*
>>> + * spi-controllers may return an error if info.length is
>>> + * too large
>>> + */
>>> 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);
>>> + info.op_tmpl = *spinand->op_templates.read_cache;
>>> + desc = devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev,
>>> + spinand->spimem, &info);
>>> + }
>>> +
>>> + if (IS_ERR_OR_NULL(desc)) {
>> Here if the problem is continuous reading, I expect an error and not a
>> NULL pointer.
> NULL is possible if flash does not supports continuous reading
>>
>>> + /*
>>> + * continuous reading is not supported by flash or
>> Not by the flash, here if we get an error, it is the spi controller
>> (still without '-' ;) ) that fails (please fix the comment).
>
> we can go here in 2 cases:
Yes, and that is misleading. It feels like the code is unclear this
way. Could we find a better organization?
> 1) spinand->cont_read_possible is false (flash does not supports
> continuous reading)
>
> 2) spi controller returns an error (spi controller does not like
> continuous reading)
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support
2025-08-06 9:03 ` Miquel Raynal
@ 2025-08-08 21:01 ` Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-08 21:01 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Takahiro Kuwano, Martin Kurbanov, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
Continuous reading mode is broken for some spi controllers. This may lead
to errors during reading of more than one flash page at once. This patch
series improve continuous mode support and add a fallback to regular
reading method if continuous reading is not supported by spi controller.
Changes v2:
* added helper to create reading dirmap descriptor
* fix spelling
* error code is not used for regular reading fallback anymore
* it's possible (but very unlucky) that someone will do raw reading
of the flash in continuous mode (i.e. without OOB), so fix dirmap
creation for that case.
Mikhail Kshevetskiy (4):
mtd: spinand: fix direct mapping creation sizes.
mtd: spinand: try a regular dirmap if creating a dirmap for continuous
reading fails
mtd: spinand: repeat reading in regular mode if continuous reading
fails
spi: spi-airoha-snfi: return an error for continuous mode dirmap
creation cases
drivers/mtd/nand/spi/core.c | 88 +++++++++++++++++++++++++++--------
drivers/spi/spi-airoha-snfi.c | 4 ++
2 files changed, 72 insertions(+), 20 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 1/4] mtd: spinand: fix direct mapping creation sizes.
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
@ 2025-08-08 21:01 ` Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
` (2 subsequent siblings)
3 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-08 21:01 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Takahiro Kuwano, Martin Kurbanov, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
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.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
@ 2025-08-08 21:01 ` Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
3 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-08 21:01 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Takahiro Kuwano, Martin Kurbanov, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
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
Usually, first of them have no issues with large reading support.
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..0f8636047365 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_helper(
+ 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_helper(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_helper(spinand, &info);
if (IS_ERR(desc))
return PTR_ERR(desc);
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 3/4] mtd: spinand: repeat reading in regular mode if continuous reading fails
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-08-08 21:01 ` Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
3 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-08 21:01 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Takahiro Kuwano, Martin Kurbanov, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
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 | 39 ++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 0f8636047365..5528e1f72dbc 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -378,7 +378,8 @@ static int spinand_load_page_op(struct spinand_device *spinand,
}
static int spinand_read_from_cache_op(struct spinand_device *spinand,
- const struct nand_page_io_req *req)
+ const struct nand_page_io_req *req,
+ bool *controller_is_buggy)
{
struct nand_device *nand = spinand_to_nand(spinand);
struct mtd_info *mtd = spinand_to_mtd(spinand);
@@ -430,8 +431,11 @@ 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)
+ if (nbytes && req->continuous) {
+ if (controller_is_buggy)
+ *controller_is_buggy = true;
return -EIO;
+ }
}
if (req->datalen)
@@ -646,7 +650,7 @@ int spinand_read_page(struct spinand_device *spinand,
spinand_ondie_ecc_save_status(nand, status);
- ret = spinand_read_from_cache_op(spinand, req);
+ ret = spinand_read_from_cache_op(spinand, req, NULL);
if (ret)
return ret;
@@ -770,7 +774,8 @@ static int spinand_mtd_regular_page_read(struct mtd_info *mtd, loff_t from,
static int spinand_mtd_continuous_page_read(struct mtd_info *mtd, loff_t from,
struct mtd_oob_ops *ops,
- unsigned int *max_bitflips)
+ unsigned int *max_bitflips,
+ bool *controller_is_buggy)
{
struct spinand_device *spinand = mtd_to_spinand(mtd);
struct nand_device *nand = mtd_to_nanddev(mtd);
@@ -808,7 +813,7 @@ static int spinand_mtd_continuous_page_read(struct mtd_info *mtd, loff_t from,
if (ret < 0)
goto end_cont_read;
- ret = spinand_read_from_cache_op(spinand, &iter.req);
+ ret = spinand_read_from_cache_op(spinand, &iter.req, controller_is_buggy);
if (ret)
goto end_cont_read;
@@ -892,6 +897,7 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
{
struct spinand_device *spinand = mtd_to_spinand(mtd);
struct mtd_ecc_stats old_stats;
+ bool controller_is_buggy = false;
unsigned int max_bitflips = 0;
int ret;
@@ -899,10 +905,25 @@ 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))
- ret = spinand_mtd_continuous_page_read(mtd, from, ops, &max_bitflips);
- else
- ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
+ if (spinand_use_cont_read(mtd, from, ops)) {
+ ret = spinand_mtd_continuous_page_read(mtd, from, ops,
+ &max_bitflips,
+ &controller_is_buggy);
+ if (controller_is_buggy) {
+ /*
+ * Some spi controllers may not support reading up to
+ * erase block size. They will read less data than
+ * expected. If this happen disable continuous mode
+ * and repeat reading in normal mode.
+ */
+ spinand->cont_read_possible = false;
+ 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.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
` (2 preceding siblings ...)
2025-08-08 21:01 ` [PATCH v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
@ 2025-08-08 21:01 ` Mikhail Kshevetskiy
3 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-08 21:01 UTC (permalink / raw)
To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Lorenzo Bianconi, Ray Liu, Mark Brown, Tudor Ambarus,
Takahiro Kuwano, Martin Kurbanov, Cheng Ming Lin, linux-mtd,
linux-kernel, linux-arm-kernel, linux-spi
Cc: Mikhail Kshevetskiy
This driver can accelerate single page operations only, thus
continuous reading mode should not be used.
Continuous reading will use sizes up to the size of one erase block.
This size is much larger than the size of single flash page. Use this
difference to identify continuous reading and return an error.
Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
---
drivers/spi/spi-airoha-snfi.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/spi/spi-airoha-snfi.c b/drivers/spi/spi-airoha-snfi.c
index dbe640986825..043a03cd90a1 100644
--- a/drivers/spi/spi-airoha-snfi.c
+++ b/drivers/spi/spi-airoha-snfi.c
@@ -618,6 +618,10 @@ static int airoha_snand_dirmap_create(struct spi_mem_dirmap_desc *desc)
if (desc->info.offset + desc->info.length > U32_MAX)
return -EINVAL;
+ /* continuous reading is not supported */
+ if (desc->info.length > SPI_NAND_CACHE_SIZE)
+ return -E2BIG;
+
if (!airoha_snand_supports_op(desc->mem, &desc->info.op_tmpl))
return -EOPNOTSUPP;
--
2.47.2
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails
2025-08-05 15:36 ` Miquel Raynal
@ 2025-08-18 12:05 ` Mikhail Kshevetskiy
0 siblings, 0 replies; 16+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-18 12:05 UTC (permalink / raw)
To: Miquel Raynal
Cc: Richard Weinberger, Vignesh Raghavendra, Lorenzo Bianconi,
Ray Liu, Mark Brown, Tudor Ambarus, Martin Kurbanov,
Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
linux-arm-kernel, linux-spi
Hello Miquèl, is there any comments to my v2 series? Mikhail
On 05.08.2025 18:36, Miquel Raynal wrote:
> On 04/08/2025 at 22:21:31 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:
>
>> Continuous reading may result in multiple flash pages reading in one
>> operation. Unfortunately, not all spi-nand 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 | 19 +++++++++++++++----
>> 1 file changed, 15 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
>> index ff6a1e2fcfdc..88e4c00cccc4 100644
>> --- a/drivers/mtd/nand/spi/core.c
>> +++ b/drivers/mtd/nand/spi/core.c
>> @@ -431,7 +431,7 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
>> * Toggling the CS during a continuous read is forbidden.
>> */
>> if (nbytes && req->continuous)
>> - return -EIO;
>> + return -E2BIG;
>> }
>>
>> if (req->datalen)
>> @@ -893,15 +893,26 @@ static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
>> struct spinand_device *spinand = mtd_to_spinand(mtd);
>> struct mtd_ecc_stats old_stats;
>> unsigned int max_bitflips = 0;
>> - int ret;
>> + int ret = -E2BIG;
>>
>> mutex_lock(&spinand->lock);
>>
>> 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 == -E2BIG) {
>> + /*
>> + * Some spi controllers may not support reading up to
>> + * erase block size. They will read less data than
>> + * expected. If this happen disable continuous mode
> happens,
>
>> + * and repeat reading in normal mode.
>> + */
>> + spinand->cont_read_possible = false;
>> + }
>> + }
>> +
>> + if (ret == -E2BIG)
> While I agree with the overall logic, I find pretty unreadable to
> perform the regular read upon a return value that is an error code set
> in the init sequence. Can you please propose an alternate implementation?
>
>> ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
>>
>> if (ops->stats) {
> Thanks!
> Miquèl
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2025-08-18 13:42 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04 19:21 [PATCH 0/4] drivers: mtd: spi-nand: fix continuous reading mode Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 1/4] drivers: mtd: spi-nand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-08-05 15:24 ` Miquel Raynal
2025-08-04 19:21 ` [PATCH 2/4] drivers: mtd: spi-nand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
2025-08-05 15:30 ` Miquel Raynal
2025-08-05 15:35 ` Mikhail Kshevetskiy
2025-08-06 9:03 ` Miquel Raynal
2025-08-08 21:01 ` [PATCH v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
2025-08-08 21:01 ` [PATCH v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 3/4] drivers: mtd: spi-nand: repeat reading in regular mode if continuous reading fails Mikhail Kshevetskiy
2025-08-05 15:36 ` Miquel Raynal
2025-08-18 12:05 ` Mikhail Kshevetskiy
2025-08-04 19:21 ` [PATCH 4/4] drivers: spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).