mtd: spi-nor: support dumping sfdp tables
Subsystems (2)
v3 cover mtd: spi-nor: support dumping sfdp tables
Add the possibility to dump the SFDP data of a flash device.
More and more flash devices share the same flash ID and we need per device fixups. Usually, these fixups differentiate flashes by looking at differences in the SFDP data. Determining the difference is only possible if we have the SFDP data for all the flashes which share a flash ID. This will lay the foundation to dump the whole SFDP data of a flash device.
This is even more important, because some datasheets doesn't even contain the SFDP data. Fixups for these kind of flashes are nearly impossible to do.
I envision having a database of all the SFDP data for the flashes we support and make it a requirement to submit it when a new flash is added. This might or might not have legal implications. Thus I'd start with having that database private to the SPI NOR maintainers.
Changes since v2:
- use .dev_groups of the driver to attach the attributes
- add manufacturer attribue
- rename attribute name to partname
- add ABI documentation
Changes since v1:
- use sysfs_emit()
- add comment about the allocation of the sfdp dwords
- free SFDP memory in the error path
- use BIN_ATTR_RO(sfdp, 0)
- use spi_nor_read_sfdp()
Changes since RFC:
- Don't read SFDP data after probe. The flash might already be switched to 8D-8D-8D mode. Instead, cache the SFDP data
- add two sysfs files: jedec-id and name
- change the file mode of the sfdp file from 0400 to 0444. There is no hardware access anymore.
Michael Walle (2):
mtd: spi-nor: sfdp: save a copy of the SFDP data
mtd: spi-nor: add initial sysfs support
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 12 +++ drivers/mtd/spi-nor/sfdp.c | 58 ++++++++++++ drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 + 7 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.c
Signature · 1 line
2.20.1
PATCH v3 1/2 mtd: spi-nor: sfdp: save a copy of the SFDP data
Due to possible mode switching to 8D-8D-8D, it might not be possible to read the SFDP after the initial probe. To be able to dump the SFDP via sysfs afterwards, make a complete copy of it.
--- drivers/mtd/spi-nor/core.h | 10 +++++++ drivers/mtd/spi-nor/sfdp.c | 58 +++++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 ++ 3 files changed, 70 insertions(+)
drivers/mtd/spi-nor/core.h +10 -0
@@ -460,6 +460,16 @@ struct spi_nor_manufacturer {const struct spi_nor_fixups *fixups; }; +/** +* struct sfdp - SFDP data +* @num_dwords: number of entries in the dwords array +* @dwords: array of double words of the SFDP data +*/ +struct sfdp { +size_t num_dwords; +u32 *dwords; +}; +/* Manufacturer drivers. */ extern const struct spi_nor_manufacturer spi_nor_atmel;extern const struct spi_nor_manufacturer spi_nor_catalyst;
drivers/mtd/spi-nor/sfdp.c +58 -0
82 lines not on this page · raw message
include/linux/mtd/spi-nor.h +2 -0
@@ -383,6 +383,7 @@ struct spi_nor_flash_parameter;* @read_proto: the SPI protocol for read operations * @write_proto: the SPI protocol for write operations * @reg_proto: the SPI protocol for read_reg/write_reg/erase operations +* @sfdp: the SFDP data of the flash * @controller_ops: SPI NOR controller driver specific operations. * @params: [FLASH-SPECIFIC] SPI NOR flash parameters and settings. * The structure includes legacy flash parameters and
@@ -412,6 +413,7 @@ struct spi_nor {bool sst_write_second;u32 flags;enum spi_nor_cmd_ext cmd_ext_type; +struct sfdp *sfdp;const struct spi_nor_controller_ops *controller_ops;
Signature · 1 line
2.20.1
PATCH v3 2/2 mtd: spi-nor: add initial sysfs support
In reply to Michael WalleAdd support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes.
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.c
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +31 -0
@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the + flash device. + + +What: /sys/bus/spi/devices/.../manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../partname +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) This attribute is only present if the SPI NOR flash + device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serial flash + discoverable parameters) binary data of the flash.
drivers/mtd/spi-nor/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.o
drivers/mtd/spi-nor/core.c +1 -0
@@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = { .name = "spi-nor", .of_match_table = spi_nor_of_table, + .dev_groups = spi_nor_sysfs_groups, }, .id_table = spi_nor_dev_ids, },
drivers/mtd/spi-nor/core.h +2 -0
@@ -489,6 +489,8 @@ extern const struct spi_nor_manufacturer spi_nor_winbond;extern const struct spi_nor_manufacturer spi_nor_xilinx;extern const struct spi_nor_manufacturer spi_nor_xmc; +extern const struct attribute_group *spi_nor_sysfs_groups[]; +void spi_nor_spimem_setup_op (const struct spi_nor *nor,struct spi_mem_op *op,const enum spi_nor_protocol proto);
drivers/mtd/spi-nor/sysfs.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support
Hi Michael,
Quoted 74 lines · Michael Walle
Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
Signed-off-by Michael Walle <[email protected]>---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes..../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.cDocumentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +31
-0@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the + flash device. + + +What: /sys/bus/spi/devices/.../manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../partname +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) This attribute is only present if the SPI NOR flash + device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serial flash + discoverable parameters) binary data of the flash.drivers/mtd/spi-nor/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.odrivers/mtd/spi-nor/core.c +0
-0
drivers/mtd/spi-nor/core.c static struct spi_mem_driver spi_nor_driver = { · line 3352
Quoted 4 lines
drivers/mtd/spi-nor/core.c +1
-0@@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = { .name = "spi-nor", .of_match_table = spi_nor_of_table, + .dev_groups = spi_nor_sysfs_groups,
Putting these in the driver's dev_groups does create a divergence between different spi-nor controllers. For all the controllers supported in drivers/mtd/spi-nor/controllers/, would their drivers need to add the same sysfs groups to get the same support?
- Alex
Re: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support
Hi Alex,
Am 2021-04-29 18:23, schrieb Alexander Williams:
Quoted 81 lines · Michael Walle
Quoted 80 lines
Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
Signed-off-by Michael Walle <[email protected]>---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes..../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.cDocumentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +5
-0@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) The JEDEC ID of the SPI NOR flash as reported bythe
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +22
-0+ flash device. + + +What: /sys/bus/spi/devices/.../manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../partname +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) This attribute is only present if the SPI NORflash
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +3
-0+ device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serialflash
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +1
-0+ discoverable parameters) binary data of the flash.drivers/mtd/spi-nor/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.odrivers/mtd/spi-nor/core.c +0
-0@@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = {
Quoted 8 lines
drivers/mtd/spi-nor/core.c static struct spi_mem_driver spi_nor_driver = { · line 3352
Quoted 3 lines
drivers/mtd/spi-nor/core.c +1
-0.name = "spi-nor", .of_match_table = spi_nor_of_table, + .dev_groups = spi_nor_sysfs_groups,Putting these in the driver's
dev_groupsdoes create a divergence between different spi-nor controllers. For all the controllers supported indrivers/mtd/spi-nor/controllers/, would their drivers need to add the same sysfs groups to get the same support?
Well, one supports it and one does not, no? If support is added later, we should keep an eye on it. Unfortunately, I don't have any hardware to see if just adding the .dev_groups to another driver will just work.
-michael
Re: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support
Quoted 101 lines · Michael Walle
Hi Alex,
Am 2021-04-29 18:23, schrieb Alexander Williams:
Quoted 88 lines · Michael Walle
Quoted 87 lines
Add support to show the manufacturer, the partname and JEDEC identifier
as well as to dump the SFDP table. Not all flashes list their SFDP table
contents in their datasheet. So having that is useful. It might also be
helpful in bug reports from users.Signed-off-by Michael Walle <[email protected]>---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes..../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.cDocumentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +5
-0@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) The JEDEC ID of the SPI NOR flash as reported bythe
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +22
-0+ flash device. + + +What: /sys/bus/spi/devices/.../manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../partname +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) This attribute is only present if the SPI NORflash
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +3
-0+ device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serialflash
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +1
-0+ discoverable parameters) binary data of the flash.drivers/mtd/spi-nor/Makefile +1
-1@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.odrivers/mtd/spi-nor/core.c +0
-0@@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = { .name = "spi-nor", .of_match_table = spi_nor_of_table,Quoted 8 lines
drivers/mtd/spi-nor/core.c static struct spi_mem_driver spi_nor_driver = { · line 3352
Quoted 1 line
drivers/mtd/spi-nor/core.c +1
-0+ .dev_groups = spi_nor_sysfs_groups,Putting these in the driver's
dev_groupsdoes create a divergence between
different spi-nor controllers. For all the controllers supported indrivers/mtd/spi-nor/controllers/, would their drivers need to add the same sysfs
groups to get the same support?
Quoted 3 lines
Well, one supports it and one does not, no? If support is added later, we should keep an eye on it. Unfortunately, I don't have any hardware to see if just adding the .dev_groups to another driver will just work.
Right, I didn't mean to indicate opposition. Since mtd/spi-nor has certainly got its set of quirky controllers and drivers (e.g. intel-spi does not support reading the sfdp in its driver, currently), it might make sense to make these attributes dependent on the driver. This mechanism also makes the attributes available at KOBJ_BIND time, so spi_nor_scan() will have run, getting rid of a pesky race condition with user space.
This comment was just to point out the implications and make sure you and maintainers are okay with that approach.
- Alex
Re: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support
In reply to Michael WalleQuoted 26 lines · Michael Walle
Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
Signed-off-by Michael Walle <[email protected]>---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes..../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.cDocumentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +0
-0
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +1
-0@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id
Since mtd/spi-nor doesn't own this device (belongs to the spi subsystem), should we put its attributes under a named subdirectory? Perhaps something like /sys/bus/spi/devices/.../spi_nor/jedec_id ?
I'm just thinking about avoiding any potential for namespace clashes.
- Alex
Re: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support
Am 2021-04-29 23:34, schrieb Alexander Williams:
Quoted 35 lines · Michael Walle
Quoted 28 lines
Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
Signed-off-by Michael Walle <[email protected]>---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes..../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.cDocumentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +0
-0Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor line 1
Quoted 1 line
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +1
-0@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_idSince mtd/spi-nor doesn't own this device (belongs to the spi subsystem), should we put its attributes under a named subdirectory? Perhaps something like
/sys/bus/spi/devices/.../spi_nor/jedec_id?
Quoted 1 line
I'm just thinking about avoiding any potential for namespace clashes.
Good idea! Will change that in the next version.
-michael