All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spinand: Avoid encoding the plane select bit twice
@ 2026-12-04  7:48 ` 兰涛
  0 siblings, 0 replies; 3+ messages in thread
From: 兰涛 @ 2026-12-04  7:48 UTC (permalink / raw)
  To: miquel.raynal, linux-mtd
  Cc: richard, vigneshr, broonie, linux-spi, vikrantyadav4802,
	linux-kernel

From: "tao.lan" <tao.lan@d-robotics.cc>

spinand_create_dirmap() already encodes the plane in each descriptor's
base offset. For devices with an explicit plane-select flag, the cache
read or write path also encodes it in the column passed to spi-mem.
The dirmap fallback adds the base and the column, so plane 1 on a device
with 4 KiB pages starts at column 0x4000 instead of 0x2000.

On an FPGA platform with an MX35UF4G24AD, programming odd eraseblocks
completed without an error, but the blocks read back as erased. On the
vendor kernel, removing the extra encoding stopped the whole-block
write loss. The tested device sets SPINAND_HAS_PROG_PLANE_SELECT_BIT
but not SPINAND_HAS_READ_PLANE_SELECT_BIT, so the read-side change was
not tested on hardware.

Keep the plane encoding in the dirmap descriptor only. Pass a column
relative to that descriptor to both dirmap helpers, as required by the
spi-mem API.

Fixes: ca229bdbef29 ("mtd: spinand: Add support for setting plane select bits")
Cc: stable@vger.kernel.org
Signed-off-by: "tao.lan" <tao.lan@d-robotics.cc>
---

Notes:
    OpenAI Codex helped adapt the existing fix for upstream, draft the
    commit message, and run local build checks. No new hardware tests were run.

    The Airoha-only proposal (Message-ID:
    20261130162743.12168-1-vikrantyadav4802@gmail.com) addresses a controller
    that interprets offs as a buffer offset. This patch keeps offs relative
    at the common SPI NAND callsites without changing the spi-mem fallback.

 drivers/mtd/nand/spi/core.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index e88374529..176fd8bcf 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -531,9 +531,6 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
 	else
 		rdesc->info.op_tmpl->data.ecc = false;

-	if (spinand->flags & SPINAND_HAS_READ_PLANE_SELECT_BIT)
-		column |= req->pos.plane << fls(nanddev_page_size(nand));
-
 	while (nbytes) {
 		ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
 		if (ret < 0)
@@ -625,9 +622,6 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
 	else
 		wdesc->info.op_tmpl->data.ecc = false;

-	if (spinand->flags & SPINAND_HAS_PROG_PLANE_SELECT_BIT)
-		column |= req->pos.plane << fls(nanddev_page_size(nand));
-
 	while (nbytes) {
 		ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
 		if (ret < 0)

base-commit: 14b6830335eb6d70dec7a235094d66c22d38eb07
--
2.43.0

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

* [PATCH] mtd: spinand: Avoid encoding the plane select bit twice
@ 2026-12-04  7:48 ` 兰涛
  0 siblings, 0 replies; 3+ messages in thread
From: 兰涛 @ 2026-12-04  7:48 UTC (permalink / raw)
  To: miquel.raynal, linux-mtd
  Cc: richard, vigneshr, broonie, linux-spi, vikrantyadav4802,
	linux-kernel

From: "tao.lan" <tao.lan@d-robotics.cc>

spinand_create_dirmap() already encodes the plane in each descriptor's
base offset. For devices with an explicit plane-select flag, the cache
read or write path also encodes it in the column passed to spi-mem.
The dirmap fallback adds the base and the column, so plane 1 on a device
with 4 KiB pages starts at column 0x4000 instead of 0x2000.

On an FPGA platform with an MX35UF4G24AD, programming odd eraseblocks
completed without an error, but the blocks read back as erased. On the
vendor kernel, removing the extra encoding stopped the whole-block
write loss. The tested device sets SPINAND_HAS_PROG_PLANE_SELECT_BIT
but not SPINAND_HAS_READ_PLANE_SELECT_BIT, so the read-side change was
not tested on hardware.

Keep the plane encoding in the dirmap descriptor only. Pass a column
relative to that descriptor to both dirmap helpers, as required by the
spi-mem API.

Fixes: ca229bdbef29 ("mtd: spinand: Add support for setting plane select bits")
Cc: stable@vger.kernel.org
Signed-off-by: "tao.lan" <tao.lan@d-robotics.cc>
---

Notes:
    OpenAI Codex helped adapt the existing fix for upstream, draft the
    commit message, and run local build checks. No new hardware tests were run.

    The Airoha-only proposal (Message-ID:
    20261130162743.12168-1-vikrantyadav4802@gmail.com) addresses a controller
    that interprets offs as a buffer offset. This patch keeps offs relative
    at the common SPI NAND callsites without changing the spi-mem fallback.

 drivers/mtd/nand/spi/core.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index e88374529..176fd8bcf 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -531,9 +531,6 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
 	else
 		rdesc->info.op_tmpl->data.ecc = false;

-	if (spinand->flags & SPINAND_HAS_READ_PLANE_SELECT_BIT)
-		column |= req->pos.plane << fls(nanddev_page_size(nand));
-
 	while (nbytes) {
 		ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
 		if (ret < 0)
@@ -625,9 +622,6 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
 	else
 		wdesc->info.op_tmpl->data.ecc = false;

-	if (spinand->flags & SPINAND_HAS_PROG_PLANE_SELECT_BIT)
-		column |= req->pos.plane << fls(nanddev_page_size(nand));
-
 	while (nbytes) {
 		ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
 		if (ret < 0)

base-commit: 14b6830335eb6d70dec7a235094d66c22d38eb07
--
2.43.0

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH] mtd: spinand: Avoid encoding the plane select bit twice
  2026-12-04  7:48 ` 兰涛
  (?)
@ 2026-12-04  8:02 ` sashiko-bot
  -1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-04  8:02 UTC (permalink / raw)
  To: 兰涛, miquel.raynal, linux-mtd
  Cc: richard, vigneshr, broonie, vikrantyadav4802

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mtd: spinand: unused plane-select flags left in spinand.h and
  macronix.c
--

commit dee6d9d83747207bf94a0171dd2e3e69a66c20de
Author: tao.lan <tao.lan@d-robotics.cc>

mtd: spinand: Avoid encoding the plane select bit twice

This commit removes the plane-select bit encoding from
spinand_read_from_cache_op() and spinand_write_to_cache_op(), leaving
plane addressing solely to the dirmap descriptor base offset set by
spinand_create_dirmap().

> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index e883745299a4e..176fd8bcf689e 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -531,9 +531,6 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
>  	else
>  		rdesc->info.op_tmpl->data.ecc = false;
>  
> -	if (spinand->flags & SPINAND_HAS_READ_PLANE_SELECT_BIT)
> -		column |= req->pos.plane << fls(nanddev_page_size(nand));
> -
>  	while (nbytes) {
>  		ret = spi_mem_dirmap_read(rdesc, column, nbytes, buf);
>  		if (ret < 0)
> @@ -625,9 +622,6 @@ static int spinand_write_to_cache_op(struct spinand_device *spinand,
>  	else
>  		wdesc->info.op_tmpl->data.ecc = false;
>  
> -	if (spinand->flags & SPINAND_HAS_PROG_PLANE_SELECT_BIT)
> -		column |= req->pos.plane << fls(nanddev_page_size(nand));
> -
>  	while (nbytes) {
>  		ret = spi_mem_dirmap_write(wdesc, column, nbytes, buf);
>  		if (ret < 0)

[Severity: Low]
Should SPINAND_HAS_READ_PLANE_SELECT_BIT and SPINAND_HAS_PROG_PLANE_SELECT_BIT
also be removed from include/linux/mtd/spinand.h and
drivers/mtd/nand/spi/macronix.c?

Deleting these two checks removes the only readers of both flags in the tree,
since spinand_create_dirmap() already encodes the plane unconditionally.
Leaving the unused definitions and macronix_spinand_table entries behind makes
it look like those flags still control column plane addressing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204074839.3822300-1-tao.lan@d-robotics.cc?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2026-12-04  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  7:48 [PATCH] mtd: spinand: Avoid encoding the plane select bit twice 兰涛
2026-12-04  7:48 ` 兰涛
2026-12-04  8:02 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.