From: Marek Vasut <marek.vasut@mailbox.org>
To: Tudor Ambarus <tudor.ambarus@linaro.org>,
Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>,
u-boot@lists.denx.de, j-humphreys@ti.com
Cc: michal.simek@amd.com, jagan@amarulasolutions.com,
vigneshr@ti.com, u-kumar1@ti.com, trini@konsulko.com,
seanga2@gmail.com, caleb.connolly@linaro.org, sjg@chromium.org,
william.zhang@broadcom.com, stefan_b@posteo.net,
quentin.schulz@cherry.de, git@amd.com
Subject: Re: [PATCH] mtd: spi-nor: Fix the read issue when addr_width is 4byte
Date: Wed, 11 Dec 2024 00:45:38 +0100 [thread overview]
Message-ID: <3fab52c5-0635-4e0d-a107-9372e11bb554@mailbox.org> (raw)
In-Reply-To: <2773d157-2b75-4fe5-bf16-9e6927e0f6f4@linaro.org>
On 12/5/24 8:35 AM, Tudor Ambarus wrote:
> + Marek
>
> use get_maintainers script please
>
> On 11/18/24 9:05 AM, Venkatesh Yadav Abbarapu wrote:
>> Fix the read issue for 4byte address width by passing the entire
>> length to the read function, split the memory of 16MB size banks
>> only when the address width is 3byte. Also update the size when
>> the configuration is stacked.
>>
>> Fixes: 5d40b3d384 ("mtd: spi-nor: Add parallel and stacked memories support")
>> Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
>> ---
>> drivers/mtd/spi/spi-nor-core.c | 24 +++++++++++++++---------
>> 1 file changed, 15 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
>> index ec841fb13b..c37a9bce74 100644
>> --- a/drivers/mtd/spi/spi-nor-core.c
>> +++ b/drivers/mtd/spi/spi-nor-core.c
>> @@ -1580,6 +1580,7 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
>> loff_t offset = from;
>> u32 read_len = 0;
>> u32 rem_bank_len = 0;
>> + u32 stack_shift = 0;
>> u8 bank;
>> bool is_ofst_odd = false;
>>
>> @@ -1593,18 +1594,20 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
>> }
>>
>> while (len) {
>> - bank = (u32)from / SZ_16M;
>> - if (nor->flags & SNOR_F_HAS_PARALLEL)
>> - bank /= 2;
>> -
>> - rem_bank_len = SZ_16M * (bank + 1);
>> - if (nor->flags & SNOR_F_HAS_PARALLEL)
>> - rem_bank_len *= 2;
>> - rem_bank_len -= from;
>> -
>> + if (nor->addr_width == 3) {
>
> No, this looks bad because you enter the body of this for all the
> flashes with addr_width 3, not just for the parallel/stacked ones.
>
> Instead you should do whatever you do here just for your
> parallel/stacked cases.
>
>> + bank = (u32)from / SZ_16M;
>> + if (nor->flags & SNOR_F_HAS_PARALLEL)
>> + bank /= 2;
>> +
>> + rem_bank_len = SZ_16M * (bank + 1);
>> + if (nor->flags & SNOR_F_HAS_PARALLEL)
>> + rem_bank_len *= 2;
>> + rem_bank_len -= from;
>> + }
>> offset = from;
>>
>> if (nor->flags & SNOR_F_HAS_STACKED) {
>> + stack_shift = 1;
>> if (offset >= (mtd->size / 2)) {
>> offset = offset - (mtd->size / 2);
>> nor->spi->flags |= SPI_XFER_U_PAGE;
>> @@ -1616,6 +1619,9 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
>> if (nor->flags & SNOR_F_HAS_PARALLEL)
>> offset /= 2;
>>
>> + if (nor->addr_width == 4)
>> + rem_bank_len = (mtd->size >> stack_shift) - offset;
>
> same here.
>
> If we still want to keep this support until everything is implemented
> above SPI NOR, other option is to duplicate core methods and introduce
> dedicated methods for the parallel/stacked cases. You could keep the
> parallel/stacked methods in dedicated file as well.
>
> The advantage is that you won't interfere with current SPI NOR support
> and that you won't break any flashes anymore. Then we can easily remove
> everything once proper support is implemented above SPI NOR. The
> disadvantage is that we duplicate code ... Marek?
I can imagine the duplication can be solved by factoring out the SPI NOR
code into a library design, where each callback implementation could be
assembled from building blocks, thus avoiding code duplication. However,
this seems like a huge change for the current 2025.01 release cycle, we
are already in rc4.
For 2025.01 , either this stacked stuff has to be carefully ifdeffed
out, so it can be enabled only for platforms which need it and disabled
for all others to avoid breaking them ... or reverted outright .
prev parent reply other threads:[~2024-12-10 23:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 9:05 [PATCH] mtd: spi-nor: Fix the read issue when addr_width is 4byte Venkatesh Yadav Abbarapu
2024-12-05 7:35 ` Tudor Ambarus
2024-12-10 23:45 ` Marek Vasut [this message]
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=3fab52c5-0635-4e0d-a107-9372e11bb554@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=caleb.connolly@linaro.org \
--cc=git@amd.com \
--cc=j-humphreys@ti.com \
--cc=jagan@amarulasolutions.com \
--cc=michal.simek@amd.com \
--cc=quentin.schulz@cherry.de \
--cc=seanga2@gmail.com \
--cc=sjg@chromium.org \
--cc=stefan_b@posteo.net \
--cc=trini@konsulko.com \
--cc=tudor.ambarus@linaro.org \
--cc=u-boot@lists.denx.de \
--cc=u-kumar1@ti.com \
--cc=venkatesh.abbarapu@amd.com \
--cc=vigneshr@ti.com \
--cc=william.zhang@broadcom.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox