All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pratyush Yadav <pratyush@kernel.org>
To: Hendrik Donner <hd@os-cillation.de>
Cc: Michael Walle <mwalle@kernel.org>,
	 Sanjaikumar V S <sanjaikumarvs@gmail.com>,
	 linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	 miquel.raynal@bootlin.com, pratyush@kernel.org,  richard@nod.at,
	 sanjaikumar.vs@dicortech.com, stable@vger.kernel.org,
	 tudor.ambarus@linaro.org,  vigneshr@ti.com
Subject: Re: [PATCH v2 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence
Date: Fri, 13 Mar 2026 11:46:37 +0000	[thread overview]
Message-ID: <2vxzpl58dk9u.fsf@kernel.org> (raw)
In-Reply-To: <8a1db3a5-09b3-4ef1-87e8-66553a81ec27@os-cillation.de> (Hendrik Donner's message of "Fri, 6 Mar 2026 23:36:03 +0100")

On Fri, Mar 06 2026, Hendrik Donner wrote:

> Hello,
>
> On 2/23/26 10:29, Michael Walle wrote:
>> Hi,
>> On Mon Feb 23, 2026 at 10:17 AM CET, Sanjaikumar V S wrote:
>>>> Raises concern about writes ending at odd offsets potentially
>>>> having the same issue
>>>
>>> The odd end address case (trailing byte) is already handled in the
>>> existing code at lines 243-255:
>>>
>>> /* Write out trailing byte if it exists. */
>>> if (actual != len) {
>>>      ret = spi_nor_write_enable(nor);
>>>      ...
>>>      ret = sst_nor_write_data(nor, to, 1, buf + actual);
>>> }
>> Ah, I must be blind. I stopped reading at the write_disable.
>> 
>>> So write_enable is already called before writing the trailing
>>> byte. My patch only addresses the odd start case where BP clears
>>> WEL before the AAI sequence begins.
>>>
>>>> Suggests simplifying the conditional logic by removing the length
>>>> check
>>>
>>> The condition `if (actual < len - 1)` avoids an unnecessary
>>> write_enable when len == 1 (single byte write at odd address, no
>>> AAI follows). But if you prefer unconditional write_enable for
>>> simplicity, I can change it in v3.
>> I know, but I actually don't like repeating the condition in the for
>> loop. So I'd prefer to have a local "needs_write_enable" boolean
>> which will be set to true. But then, I wouldn't care too much if
>> there is a write enable followed by a write disable for a rare case.
>> 
>>>> Notes the patch lacks runtime testing
>>>
>>> I don't have the hardware setup to test odd-address writes at the
>>> moment. The fix is based on code analysis. I have tested patch 2/2
>>> (dirmap fallback) on hardware.
>> I'm hesitant - because like I said, if there is really a bug - it
>> would have never worked correctly, since day 1. But yeah, I've also
>> read the datasheet and it clearly states that the byte write will
>> clear the write enable latch.
>> 
>
> i can confirm both patches fix real issues, i have similiar fixes
> on a kernel tree i always wanted to clean up and upstream. Diffs
> based on 6.6.127:
>
> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
> index 197d2c1101ed5..eaa50561ede2c 100644
> --- a/drivers/mtd/spi-nor/sst.c
> +++ b/drivers/mtd/spi-nor/sst.c
> @@ -155,6 +155,13 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>                 if (ret)
>                         goto out;
>
> +               ret = spi_nor_write_enable(nor);
> +               if (ret)
> +                       goto out;
> +               ret = spi_nor_wait_till_ready(nor);
> +               if (ret)
> +                       goto out;
> +
>                 to++;
>                 actual++;
>         }
>
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 1b0c6770c14e4..646bfb2e91a65 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -276,7 +276,7 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
>         if (spi_nor_spimem_bounce(nor, &op))
>                 memcpy(nor->bouncebuf, buf, op.data.nbytes);
>
> -       if (nor->dirmap.wdesc) {
> +       if (nor->dirmap.wdesc && nor->program_opcode != SPINOR_OP_AAI_WP) {

Why is this better? This removes the use of dirmap for all flashes other
than SST.

>                 nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val,
>                                               op.data.nbytes, op.data.buf.out);
>         } else {
>
>
> I think patch 2 of this series is the better approach though.

There is a v4 here:
https://lore.kernel.org/linux-mtd/20260311103057.29-1-sanjaikumarvs@gmail.com/T/#u

Can you please review and test it so we can apply it?

>
> Regards,
> Hendrik
>
>>> Please let me know if you'd like me to send a v3 with the
>>> simplified unconditional write_enable.
>> Please see above.
>> -michael
>> ______________________________________________________
>> Linux MTD discussion mailing list
>> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>

-- 
Regards,
Pratyush Yadav

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

WARNING: multiple messages have this Message-ID (diff)
From: Pratyush Yadav <pratyush@kernel.org>
To: Hendrik Donner <hd@os-cillation.de>
Cc: Michael Walle <mwalle@kernel.org>,
	 Sanjaikumar V S <sanjaikumarvs@gmail.com>,
	 linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
	 miquel.raynal@bootlin.com, pratyush@kernel.org,  richard@nod.at,
	 sanjaikumar.vs@dicortech.com, stable@vger.kernel.org,
	 tudor.ambarus@linaro.org,  vigneshr@ti.com
Subject: Re: [PATCH v2 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence
Date: Fri, 13 Mar 2026 11:46:37 +0000	[thread overview]
Message-ID: <2vxzpl58dk9u.fsf@kernel.org> (raw)
In-Reply-To: <8a1db3a5-09b3-4ef1-87e8-66553a81ec27@os-cillation.de> (Hendrik Donner's message of "Fri, 6 Mar 2026 23:36:03 +0100")

On Fri, Mar 06 2026, Hendrik Donner wrote:

> Hello,
>
> On 2/23/26 10:29, Michael Walle wrote:
>> Hi,
>> On Mon Feb 23, 2026 at 10:17 AM CET, Sanjaikumar V S wrote:
>>>> Raises concern about writes ending at odd offsets potentially
>>>> having the same issue
>>>
>>> The odd end address case (trailing byte) is already handled in the
>>> existing code at lines 243-255:
>>>
>>> /* Write out trailing byte if it exists. */
>>> if (actual != len) {
>>>      ret = spi_nor_write_enable(nor);
>>>      ...
>>>      ret = sst_nor_write_data(nor, to, 1, buf + actual);
>>> }
>> Ah, I must be blind. I stopped reading at the write_disable.
>> 
>>> So write_enable is already called before writing the trailing
>>> byte. My patch only addresses the odd start case where BP clears
>>> WEL before the AAI sequence begins.
>>>
>>>> Suggests simplifying the conditional logic by removing the length
>>>> check
>>>
>>> The condition `if (actual < len - 1)` avoids an unnecessary
>>> write_enable when len == 1 (single byte write at odd address, no
>>> AAI follows). But if you prefer unconditional write_enable for
>>> simplicity, I can change it in v3.
>> I know, but I actually don't like repeating the condition in the for
>> loop. So I'd prefer to have a local "needs_write_enable" boolean
>> which will be set to true. But then, I wouldn't care too much if
>> there is a write enable followed by a write disable for a rare case.
>> 
>>>> Notes the patch lacks runtime testing
>>>
>>> I don't have the hardware setup to test odd-address writes at the
>>> moment. The fix is based on code analysis. I have tested patch 2/2
>>> (dirmap fallback) on hardware.
>> I'm hesitant - because like I said, if there is really a bug - it
>> would have never worked correctly, since day 1. But yeah, I've also
>> read the datasheet and it clearly states that the byte write will
>> clear the write enable latch.
>> 
>
> i can confirm both patches fix real issues, i have similiar fixes
> on a kernel tree i always wanted to clean up and upstream. Diffs
> based on 6.6.127:
>
> diff --git a/drivers/mtd/spi-nor/sst.c b/drivers/mtd/spi-nor/sst.c
> index 197d2c1101ed5..eaa50561ede2c 100644
> --- a/drivers/mtd/spi-nor/sst.c
> +++ b/drivers/mtd/spi-nor/sst.c
> @@ -155,6 +155,13 @@ static int sst_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
>                 if (ret)
>                         goto out;
>
> +               ret = spi_nor_write_enable(nor);
> +               if (ret)
> +                       goto out;
> +               ret = spi_nor_wait_till_ready(nor);
> +               if (ret)
> +                       goto out;
> +
>                 to++;
>                 actual++;
>         }
>
>
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 1b0c6770c14e4..646bfb2e91a65 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -276,7 +276,7 @@ static ssize_t spi_nor_spimem_write_data(struct spi_nor *nor, loff_t to,
>         if (spi_nor_spimem_bounce(nor, &op))
>                 memcpy(nor->bouncebuf, buf, op.data.nbytes);
>
> -       if (nor->dirmap.wdesc) {
> +       if (nor->dirmap.wdesc && nor->program_opcode != SPINOR_OP_AAI_WP) {

Why is this better? This removes the use of dirmap for all flashes other
than SST.

>                 nbytes = spi_mem_dirmap_write(nor->dirmap.wdesc, op.addr.val,
>                                               op.data.nbytes, op.data.buf.out);
>         } else {
>
>
> I think patch 2 of this series is the better approach though.

There is a v4 here:
https://lore.kernel.org/linux-mtd/20260311103057.29-1-sanjaikumarvs@gmail.com/T/#u

Can you please review and test it so we can apply it?

>
> Regards,
> Hendrik
>
>>> Please let me know if you'd like me to send a v3 with the
>>> simplified unconditional write_enable.
>> Please see above.
>> -michael
>> ______________________________________________________
>> Linux MTD discussion mailing list
>> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>

-- 
Regards,
Pratyush Yadav

  reply	other threads:[~2026-03-13 11:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20  9:42 [PATCH v2 0/2] mtd: spi-nor: Fix SST AAI write mode Sanjaikumar V S
2026-02-20  9:42 ` Sanjaikumar V S
2026-02-20  9:42 ` [PATCH v2 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
2026-02-20  9:42   ` Sanjaikumar V S
2026-02-23  8:18   ` Michael Walle
2026-02-23  8:18     ` Michael Walle
2026-02-23  9:17     ` Sanjaikumar V S
2026-02-23  9:17       ` Sanjaikumar V S
2026-02-23  9:29       ` Michael Walle
2026-02-23  9:29         ` Michael Walle
2026-03-06 22:36         ` Hendrik Donner
2026-03-06 22:36           ` Hendrik Donner
2026-03-13 11:46           ` Pratyush Yadav [this message]
2026-03-13 11:46             ` Pratyush Yadav
2026-03-13 12:50             ` Hendrik Donner
2026-03-13 12:50               ` Hendrik Donner
2026-03-13 13:39               ` Pratyush Yadav
2026-03-13 13:39                 ` Pratyush Yadav
2026-02-20  9:42 ` [PATCH v2 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
2026-02-20  9:42   ` Sanjaikumar V S
2026-02-23 10:17 ` [PATCH v3 0/2] mtd: spi-nor: Fix SST AAI write mode Sanjaikumar V S
2026-02-23 10:17   ` Sanjaikumar V S
2026-02-23 10:17   ` [PATCH v3 1/2] mtd: spi-nor: sst: Fix write enable before AAI sequence Sanjaikumar V S
2026-02-23 10:17     ` Sanjaikumar V S
2026-02-23 10:17   ` [PATCH v3 2/2] mtd: spi-nor: core: Fix AAI mode when dirmap is not available Sanjaikumar V S
2026-02-23 10:17     ` Sanjaikumar V S

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2vxzpl58dk9u.fsf@kernel.org \
    --to=pratyush@kernel.org \
    --cc=hd@os-cillation.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=richard@nod.at \
    --cc=sanjaikumar.vs@dicortech.com \
    --cc=sanjaikumarvs@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tudor.ambarus@linaro.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.