linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support
@ 2025-08-14  6:54 Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14  6:54 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.

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 as well.

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.50.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RESEND v2 1/4] mtd: spinand: fix direct mapping creation sizes.
  2025-08-14  6:54 [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
@ 2025-08-14  6:54 ` Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND 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; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14  6:54 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 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.50.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RESEND v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
  2025-08-14  6:54 [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
@ 2025-08-14  6:54 ` Mikhail Kshevetskiy
  2025-08-24 16:26   ` Miquel Raynal
  2025-08-14  6:54 ` [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
  3 siblings, 1 reply; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14  6:54 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 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.50.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if continuous reading fails
  2025-08-14  6:54 [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
  2025-08-14  6:54 ` [PATCH RESEND v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-08-14  6:54 ` Mikhail Kshevetskiy
  2025-08-24 16:24   ` Miquel Raynal
  2025-08-14  6:54 ` [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
  3 siblings, 1 reply; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14  6:54 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 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.50.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14  6:54 [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
                   ` (2 preceding siblings ...)
  2025-08-14  6:54 ` [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
@ 2025-08-14  6:54 ` Mikhail Kshevetskiy
  2025-08-14 15:29   ` Mark Brown
  2025-08-20  8:49   ` Frieder Schrempf
  3 siblings, 2 replies; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14  6:54 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.50.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14  6:54 ` [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
@ 2025-08-14 15:29   ` Mark Brown
  2025-08-14 15:33     ` Mikhail Kshevetskiy
  2025-08-20  8:49   ` Frieder Schrempf
  1 sibling, 1 reply; 14+ messages in thread
From: Mark Brown @ 2025-08-14 15:29 UTC (permalink / raw)
  To: Mikhail Kshevetskiy
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Lorenzo Bianconi, Ray Liu, Tudor Ambarus, Martin Kurbanov,
	Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
	linux-arm-kernel, linux-spi

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
> 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.

This seems like it just applies anyway regardless of the rest of the
series?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14 15:29   ` Mark Brown
@ 2025-08-14 15:33     ` Mikhail Kshevetskiy
  2025-08-20  8:49       ` Frieder Schrempf
  2025-08-24 15:50       ` Miquel Raynal
  0 siblings, 2 replies; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-14 15:33 UTC (permalink / raw)
  To: Mark Brown
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Lorenzo Bianconi, Ray Liu, Tudor Ambarus, Martin Kurbanov,
	Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
	linux-arm-kernel, linux-spi


On 14.08.2025 18:29, Mark Brown wrote:
> On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
>> 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.
> This seems like it just applies anyway regardless of the rest of the
> series?

Could you provide a link? I do not see this in upstream linux repo.

Mikhail Kshevetskiy


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14  6:54 ` [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
  2025-08-14 15:29   ` Mark Brown
@ 2025-08-20  8:49   ` Frieder Schrempf
  1 sibling, 0 replies; 14+ messages in thread
From: Frieder Schrempf @ 2025-08-20  8:49 UTC (permalink / raw)
  To: Mikhail Kshevetskiy, 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

Am 14.08.25 um 08:54 schrieb 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>

Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14 15:33     ` Mikhail Kshevetskiy
@ 2025-08-20  8:49       ` Frieder Schrempf
  2025-08-20  9:49         ` Mikhail Kshevetskiy
  2025-08-21  6:49         ` Lorenzo Bianconi
  2025-08-24 15:50       ` Miquel Raynal
  1 sibling, 2 replies; 14+ messages in thread
From: Frieder Schrempf @ 2025-08-20  8:49 UTC (permalink / raw)
  To: Mikhail Kshevetskiy, Mark Brown
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Lorenzo Bianconi, Ray Liu, Tudor Ambarus, Martin Kurbanov,
	Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
	linux-arm-kernel, linux-spi

Am 14.08.25 um 17:33 schrieb Mikhail Kshevetskiy:
> 
> On 14.08.2025 18:29, Mark Brown wrote:
>> On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
>>> 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.
>> This seems like it just applies anyway regardless of the rest of the
>> series?
> 
> Could you provide a link? I do not see this in upstream linux repo.

Mark asked if this could be applied without the other patches of this
series through his SPI tree and I think that is indeed correct. The
other patches are still being reviewed and applied via the MTD tree.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-20  8:49       ` Frieder Schrempf
@ 2025-08-20  9:49         ` Mikhail Kshevetskiy
  2025-08-21  6:49         ` Lorenzo Bianconi
  1 sibling, 0 replies; 14+ messages in thread
From: Mikhail Kshevetskiy @ 2025-08-20  9:49 UTC (permalink / raw)
  To: Frieder Schrempf, Mark Brown
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Lorenzo Bianconi, Ray Liu, Tudor Ambarus, Martin Kurbanov,
	Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
	linux-arm-kernel, linux-spi

On 20.08.2025 11:49, Frieder Schrempf wrote:
> Am 14.08.25 um 17:33 schrieb Mikhail Kshevetskiy:
>> On 14.08.2025 18:29, Mark Brown wrote:
>>> On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
>>>> 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.
>>> This seems like it just applies anyway regardless of the rest of the
>>> series?
>> Could you provide a link? I do not see this in upstream linux repo.
> Mark asked if this could be applied without the other patches of this
> series through his SPI tree and I think that is indeed correct. The
> other patches are still being reviewed and applied via the MTD tree.
Thanks for clarification. I could add it to other aihoha spi driver fixes.

Mikhail

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-20  8:49       ` Frieder Schrempf
  2025-08-20  9:49         ` Mikhail Kshevetskiy
@ 2025-08-21  6:49         ` Lorenzo Bianconi
  1 sibling, 0 replies; 14+ messages in thread
From: Lorenzo Bianconi @ 2025-08-21  6:49 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: Mikhail Kshevetskiy, Mark Brown, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, Ray Liu, Tudor Ambarus,
	Martin Kurbanov, Takahiro Kuwano, Cheng Ming Lin, linux-mtd,
	linux-kernel, linux-arm-kernel, linux-spi

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

> Am 14.08.25 um 17:33 schrieb Mikhail Kshevetskiy:
> > 
> > On 14.08.2025 18:29, Mark Brown wrote:
> >> On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
> >>> 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.
> >> This seems like it just applies anyway regardless of the rest of the
> >> series?
> > 
> > Could you provide a link? I do not see this in upstream linux repo.
> 
> Mark asked if this could be applied without the other patches of this
> series through his SPI tree and I think that is indeed correct. The
> other patches are still being reviewed and applied via the MTD tree.

Can you please add the following Fixes tag?

Fixes: a403997c12019 ("spi: airoha: add SPI-NAND Flash controller driver")

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases
  2025-08-14 15:33     ` Mikhail Kshevetskiy
  2025-08-20  8:49       ` Frieder Schrempf
@ 2025-08-24 15:50       ` Miquel Raynal
  1 sibling, 0 replies; 14+ messages in thread
From: Miquel Raynal @ 2025-08-24 15:50 UTC (permalink / raw)
  To: Mikhail Kshevetskiy
  Cc: Mark Brown, Richard Weinberger, Vignesh Raghavendra,
	Lorenzo Bianconi, Ray Liu, Tudor Ambarus, Martin Kurbanov,
	Takahiro Kuwano, Cheng Ming Lin, linux-mtd, linux-kernel,
	linux-arm-kernel, linux-spi

On 14/08/2025 at 18:33:25 +03, Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu> wrote:

> On 14.08.2025 18:29, Mark Brown wrote:
>> On Thu, Aug 14, 2025 at 09:54:23AM +0300, Mikhail Kshevetskiy wrote:
>>> 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.
>> This seems like it just applies anyway regardless of the rest of the
>> series?
>
> Could you provide a link? I do not see this in upstream linux repo.

No link, Mark can apply this without the rest of the series it seems. If
that's the case, it's best to send two series because these patches
apply to different trees.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if continuous reading fails
  2025-08-14  6:54 ` [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
@ 2025-08-24 16:24   ` Miquel Raynal
  0 siblings, 0 replies; 14+ messages in thread
From: Miquel Raynal @ 2025-08-24 16: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,

> +		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;

I am fine with the idea, but could we avoid this little dance and drop
the extra controller_is_buggy boolean, and just let
spinand_mtd_continuous_page_read() do the fixup and return -EAGAIN?

> +			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 +=

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RESEND v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
  2025-08-14  6:54 ` [PATCH RESEND v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
@ 2025-08-24 16:26   ` Miquel Raynal
  0 siblings, 0 replies; 14+ messages in thread
From: Miquel Raynal @ 2025-08-24 16:26 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 14/08/2025 at 09:54:21 +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 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(

Can we drop _helper from the name? Just spinand_create_rdesc() sounds
as useful.

> +					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;
> +

Looks good otherwise.

Thanks,
Miquèl

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-08-24 16:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-14  6:54 [PATCH RESEND v2 0/4] mtd: spinand: fix continuous reading mode support Mikhail Kshevetskiy
2025-08-14  6:54 ` [PATCH RESEND v2 1/4] mtd: spinand: fix direct mapping creation sizes Mikhail Kshevetskiy
2025-08-14  6:54 ` [PATCH RESEND v2 2/4] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Mikhail Kshevetskiy
2025-08-24 16:26   ` Miquel Raynal
2025-08-14  6:54 ` [PATCH RESEND v2 3/4] mtd: spinand: repeat reading in regular mode if " Mikhail Kshevetskiy
2025-08-24 16:24   ` Miquel Raynal
2025-08-14  6:54 ` [PATCH RESEND v2 4/4] spi: spi-airoha-snfi: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-08-14 15:29   ` Mark Brown
2025-08-14 15:33     ` Mikhail Kshevetskiy
2025-08-20  8:49       ` Frieder Schrempf
2025-08-20  9:49         ` Mikhail Kshevetskiy
2025-08-21  6:49         ` Lorenzo Bianconi
2025-08-24 15:50       ` Miquel Raynal
2025-08-20  8:49   ` Frieder Schrempf

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).