Re: [RFC 2/3] mtd: spi-nor: core: compare JEDEC bytes to already found flash_info

From: Michael Walle
Date: Tue Jun 22 2021 - 07:57:09 EST


[+ some people from MXIC as they are ones who posted to the ML
lately. Feel free to forward this mail to the corresponding people.]

Am 2021-06-21 17:23, schrieb Rasmus Villemoes:
Macronix engineers, in their infinite wisdom, have a habit of reusing
JEDEC ids for different chips. There's already one
workaround (MX25L25635F v MX25L25635E), but the same problem exists
for MX25L3205D v MX25L3233F, the latter of which is not currently
supported by linux.

AFAICT, that case cannot really be handled with any of the ->fixup
machinery: The correct entry for the MX25L3233F would read

{ "mx25l3233f", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K |
SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ ) },

while the existing one is

{ "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, SECT_4K) },

So in spi_nor_init_params(), we won't even try reading the sfdp
info (i.e. call spi_nor_sfdp_init_params), and hence
spi_nor_post_sfdp_fixups() has no way of distinguishing the
chips.

Replacing the existing entry with the mx25l3233f one to coerce the
core into issuing the SPINOR_OP_RDSFDP is also not really an option,
because the data sheet for the mx25l3205d explicitly says not to issue
any commands not listed ("It is not recommended to adopt any other
code not in the command definition table, which will potentially enter
the hidden mode.", whatever that means).

Maybe we should ask Macronix if it is safe to send the RDSFDP command.
Can anyone from MXIC comment this?
This is also interesting because we are discussing reading the SFDP
without reading the ID first.

Of course this will not save us from two different devices sharing
the same ID and both having no RDSFDP support.

In order to support such cases, extend the logic in spi_nor_read_id()
a little so that if we already have a struct flash_info* from the name
in device tree, check the JEDEC bytes against that, and if it is a
match, accept that (device tree compatible + matching JEDEC bytes) is
stronger than merely matching JEDEC bytes.

This won't help much without a proper dt schema. No in-tree devicetree
could use is because the DT validation would complain. So if this will
go in (and the maintainers are rather hesitant to add it, I tried
it myself [1]), you'd also need to add it to jedec,spi-nor.yaml and
get an ack from Rob.

This also makes initialization slightly faster in the common case
where the flash_info was found from the name and the JEDEC bytes do
match - it avoids a second linear search over all known chips.

Signed-off-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>

-michael

[1] https://lore.kernel.org/linux-mtd/20200103223423.14025-1-michael@xxxxxxxx/