linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/6] mtd: spi-nor: generic flash driver
@ 2022-05-13 13:35 Michael Walle
  2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
                   ` (6 more replies)
  0 siblings, 7 replies; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

Add a generic flash driver, which is used when we don't find a matching
flash in our database. All the basic features of a flash can be discovered
by SFDP and most (if not all) newer flashes support it.

Michael Walle (6):
  mtd: spi-nor: hide jedec_id sysfs attribute if not present
  mtd: spi-nor: sysfs: hide manufacturer if it is not set
  mtd: spi-nor: remember full JEDEC flash ID
  mtd: spi-nor: move function declaration out of sfdp.h
  mtd: spi-nor: add generic flash driver
  mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver

 .../ABI/testing/sysfs-bus-spi-devices-spi-nor |  6 +++++
 drivers/mtd/spi-nor/core.c                    | 18 +++++++++++++
 drivers/mtd/spi-nor/core.h                    |  3 +++
 drivers/mtd/spi-nor/debugfs.c                 |  2 +-
 drivers/mtd/spi-nor/sfdp.c                    | 27 +++++++++++++++++++
 drivers/mtd/spi-nor/sfdp.h                    |  2 --
 drivers/mtd/spi-nor/sysfs.c                   | 20 +++++++++++++-
 include/linux/mtd/spi-nor.h                   |  3 +++
 8 files changed, 77 insertions(+), 4 deletions(-)

-- 
2.30.2


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

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

* [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-07-26 10:00   ` Takahiro Kuwano
  2022-05-13 13:35 ` [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

Some non-jedec compliant flashes (like the Everspin flashes) don't have
an ID at all. Hide the attribute in this case.

Fixes: 36ac02286265 ("mtd: spi-nor: add initial sysfs support")
Signed-off-by: Michael Walle <michael@walle.cc>
---
 .../ABI/testing/sysfs-bus-spi-devices-spi-nor      |  3 +++
 drivers/mtd/spi-nor/sysfs.c                        | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
index d76cd3946434..e9ef69aef20b 100644
--- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
+++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
@@ -5,6 +5,9 @@ Contact:	linux-mtd@lists.infradead.org
 Description:	(RO) The JEDEC ID of the SPI NOR flash as reported by the
 		flash device.
 
+		The attribute is not present if the flash doesn't support
+		the "Read JEDEC ID" command (9Fh). This is the case for
+		non-JEDEC compliant flashes.
 
 What:		/sys/bus/spi/devices/.../spi-nor/manufacturer
 Date:		April 2021
diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 9aec9d8a98ad..4c3b351aef24 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -67,6 +67,19 @@ static struct bin_attribute *spi_nor_sysfs_bin_entries[] = {
 	NULL
 };
 
+static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
+					struct attribute *attr, int n)
+{
+	struct spi_device *spi = to_spi_device(kobj_to_dev(kobj));
+	struct spi_mem *spimem = spi_get_drvdata(spi);
+	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
+
+	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
+		return 0;
+
+	return 0444;
+}
+
 static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
 					    struct bin_attribute *attr, int n)
 {
@@ -82,6 +95,7 @@ static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
 
 static const struct attribute_group spi_nor_sysfs_group = {
 	.name		= "spi-nor",
+	.is_visible	= spi_nor_sysfs_is_visible,
 	.is_bin_visible	= spi_nor_sysfs_is_bin_visible,
 	.attrs		= spi_nor_sysfs_entries,
 	.bin_attrs	= spi_nor_sysfs_bin_entries,
-- 
2.30.2


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

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

* [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
  2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-07-26 10:04   ` Takahiro Kuwano
  2022-05-13 13:35 ` [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

The manufacturer may be optional when pure SFDP flashes are supported.
Hide the sysfs property if no manufacturer is set.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor | 3 +++
 drivers/mtd/spi-nor/sysfs.c                             | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
index e9ef69aef20b..c800621eff95 100644
--- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
+++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
@@ -15,6 +15,9 @@ KernelVersion:	5.14
 Contact:	linux-mtd@lists.infradead.org
 Description:	(RO) Manufacturer of the SPI NOR flash.
 
+		The attribute is not present if the flash device isn't
+		known to the kernel and is only probed by its SFDP
+		tables.
 
 What:		/sys/bus/spi/devices/.../spi-nor/partname
 Date:		April 2021
diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 4c3b351aef24..20563c1926f4 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -74,6 +74,8 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
 	struct spi_mem *spimem = spi_get_drvdata(spi);
 	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
 
+	if (attr == &dev_attr_manufacturer.attr && !nor->manufacturer)
+		return 0;
 	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
 		return 0;
 
-- 
2.30.2


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

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

* [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
  2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
  2022-05-13 13:35 ` [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-07-29  1:00   ` Takahiro Kuwano
  2022-05-13 13:35 ` [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

At the moment, we print the JEDEC ID that is stored in our database. The
generic flash support won't have such an entry in our database. To find
out the JEDEC ID later we will have to cache it. There is also another
advantage: If the flash is found in the database, the ID could be
truncated because the ID of the entry is used which can be shorter. Some
flashes still holds valuable information in the bytes after the JEDEC ID
and come in handy during debugging of when coping with INFO6() entries.
These are not accessible for now.

Save a copy of the ID bytes after reading and display it via debugfs.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c    | 5 +++++
 drivers/mtd/spi-nor/debugfs.c | 2 +-
 include/linux/mtd/spi-nor.h   | 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index ce5d69317d46..65cd8e668579 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1664,6 +1664,11 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
 		return ERR_PTR(ret);
 	}
 
+	/* Cache the complete flash ID. */
+	nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL);
+	if (!nor->id)
+		return ERR_PTR(-ENOMEM);
+
 	info = spi_nor_match_id(nor, id);
 	if (!info) {
 		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c
index eaf84f7a0676..23d51e7ba0a7 100644
--- a/drivers/mtd/spi-nor/debugfs.c
+++ b/drivers/mtd/spi-nor/debugfs.c
@@ -81,7 +81,7 @@ static int spi_nor_params_show(struct seq_file *s, void *data)
 	int i;
 
 	seq_printf(s, "name\t\t%s\n", info->name);
-	seq_printf(s, "id\t\t%*ph\n", info->id_len, info->id);
+	seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id);
 	string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf));
 	seq_printf(s, "size\t\t%s\n", buf);
 	seq_printf(s, "write size\t%u\n", params->writesize);
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index 1ede4c89805a..4dd6cd7389ca 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -349,6 +349,8 @@ struct spi_nor_flash_parameter;
  * @bouncebuf:		bounce buffer used when the buffer passed by the MTD
  *                      layer is not DMA-able
  * @bouncebuf_size:	size of the bounce buffer
+ * @id:			The flash's ID bytes. Always contains
+ *			SPI_NOR_MAX_ID_LEN bytes.
  * @info:		SPI NOR part JEDEC MFR ID and other info
  * @manufacturer:	SPI NOR manufacturer
  * @addr_width:		number of address bytes
@@ -379,6 +381,7 @@ struct spi_nor {
 	struct spi_mem		*spimem;
 	u8			*bouncebuf;
 	size_t			bouncebuf_size;
+	u8			*id;
 	const struct flash_info	*info;
 	const struct spi_nor_manufacturer *manufacturer;
 	u8			addr_width;
-- 
2.30.2


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

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

* [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
                   ` (2 preceding siblings ...)
  2022-05-13 13:35 ` [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-07-26 23:41   ` Takahiro Kuwano
  2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

sfdp.h should only contain constants related to the JEDEC SFDP
specification(s).

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.h | 2 ++
 drivers/mtd/spi-nor/sfdp.h | 2 --
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 61886868cd02..3a19b8092ab8 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -694,6 +694,8 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
 				     const u8 *buf, size_t len);
 
+int spi_nor_parse_sfdp(struct spi_nor *nor);
+
 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
 {
 	return container_of(mtd, struct spi_nor, mtd);
diff --git a/drivers/mtd/spi-nor/sfdp.h b/drivers/mtd/spi-nor/sfdp.h
index bbf80d2990ab..c1969f0a2f46 100644
--- a/drivers/mtd/spi-nor/sfdp.h
+++ b/drivers/mtd/spi-nor/sfdp.h
@@ -107,6 +107,4 @@ struct sfdp_parameter_header {
 	u8		id_msb;
 };
 
-int spi_nor_parse_sfdp(struct spi_nor *nor);
-
 #endif /* __LINUX_MTD_SFDP_H */
-- 
2.30.2


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

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

* [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
                   ` (3 preceding siblings ...)
  2022-05-13 13:35 ` [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-05-13 14:47   ` kernel test robot
                     ` (2 more replies)
  2022-05-13 13:35 ` [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
  2022-07-26  8:06 ` [PATCH 0/6] mtd: spi-nor: " Tudor.Ambarus
  6 siblings, 3 replies; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

Our SFDP is parsing is everything we need to support all basic
operations of a flash device. If the flash isn't found in our in-kernel
flash database, gracefully fall back to a driver described solely by its
SFDP tables.

It is still recommended to add the flash to the in-kernel database.
First, we get a proper partname and secondly, for all features not
described by the SFDP like OTP we need the entry anyway.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/core.c | 13 +++++++++++++
 drivers/mtd/spi-nor/core.h |  1 +
 drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 65cd8e668579..ee193a61310a 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1632,6 +1632,11 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
 	&spi_nor_xmc,
 };
 
+static const struct flash_info spi_nor_generic_flash = {
+	.name = "spi-nor-generic",
+	.parse_sfdp = true,
+};
+
 static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
 						 const u8 *id)
 {
@@ -1670,6 +1675,14 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
 		return ERR_PTR(-ENOMEM);
 
 	info = spi_nor_match_id(nor, id);
+
+	/* Fallback to a generic flash described only by its SFDP data. */
+	if (!info) {
+		ret = spi_nor_check_sfdp_signature(nor);
+		if (!ret)
+			info = &spi_nor_generic_flash;
+	}
+
 	if (!info) {
 		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
 			SPI_NOR_MAX_ID_LEN, id);
diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
index 3a19b8092ab8..aa9f218245a5 100644
--- a/drivers/mtd/spi-nor/core.h
+++ b/drivers/mtd/spi-nor/core.h
@@ -694,6 +694,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
 int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
 				     const u8 *buf, size_t len);
 
+int spi_nor_check_sfdp_signature(struct spi_nor *nor);
 int spi_nor_parse_sfdp(struct spi_nor *nor);
 
 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index a5211543d30d..9bdb3d5dc7e8 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -1247,6 +1247,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
 		nor->info->fixups->post_sfdp(nor);
 }
 
+/**
+ * spi_nor_check_sfdp_header() - check for a valid SFDP header
+ * @nor:		pointer to a 'struct spi_nor'
+ *
+ * Used to detect if the flash supports the RDSFDP command as well as the
+ * presence of a valid SFDP table.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+int spi_nor_check_sfdp_signature(struct spi_nor *nor)
+{
+	u32 signature;
+	int err;
+
+	/* Get the SFDP header. */
+	err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
+					   &signature);
+	if (err < 0)
+		return err;
+
+	/* Check the SFDP signature. */
+	if (le32_to_cpu(signature) != SFDP_SIGNATURE)
+		return -EINVAL;
+
+	return 0;
+}
+
 /**
  * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
  * @nor:		pointer to a 'struct spi_nor'
-- 
2.30.2


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

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

* [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
                   ` (4 preceding siblings ...)
  2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
@ 2022-05-13 13:35 ` Michael Walle
  2022-07-29  1:25   ` Takahiro Kuwano
  2022-07-26  8:06 ` [PATCH 0/6] mtd: spi-nor: " Tudor.Ambarus
  6 siblings, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-05-13 13:35 UTC (permalink / raw)
  To: Tudor Ambarus, Pratyush Yadav, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

We don't have a database entry for the generic SPI-NOR flash driver and
thus we don't have a JEDEC ID to print. Print the (cached) JEDEC ID
instead.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/mtd/spi-nor/sysfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
index 20563c1926f4..c09bb832b3b9 100644
--- a/drivers/mtd/spi-nor/sysfs.c
+++ b/drivers/mtd/spi-nor/sysfs.c
@@ -35,8 +35,10 @@ static ssize_t jedec_id_show(struct device *dev,
 	struct spi_device *spi = to_spi_device(dev);
 	struct spi_mem *spimem = spi_get_drvdata(spi);
 	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
+	const u8 *id = nor->info->id_len ? nor->info->id : nor->id;
+	u8 id_len = nor->info->id_len ?: SPI_NOR_MAX_ID_LEN;
 
-	return sysfs_emit(buf, "%*phN\n", nor->info->id_len, nor->info->id);
+	return sysfs_emit(buf, "%*phN\n", id_len, id);
 }
 static DEVICE_ATTR_RO(jedec_id);
 
@@ -76,7 +78,7 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
 
 	if (attr == &dev_attr_manufacturer.attr && !nor->manufacturer)
 		return 0;
-	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
+	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len && !nor->id)
 		return 0;
 
 	return 0444;
-- 
2.30.2


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

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

* Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
@ 2022-05-13 14:47   ` kernel test robot
  2022-07-21  9:32     ` Biju Das
  2022-07-21  9:48     ` Michael Walle
  2022-07-28  3:28   ` Tudor.Ambarus
  2022-07-29  1:40   ` Takahiro Kuwano
  2 siblings, 2 replies; 22+ messages in thread
From: kernel test robot @ 2022-05-13 14:47 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: kbuild-all, linux-kernel, linux-mtd

Hi Michael,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mtd/spi-nor/next]
[also build test WARNING on next-20220513]
[cannot apply to linux/master linus/master v5.18-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Michael-Walle/mtd-spi-nor-generic-flash-driver/20220513-214238
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git spi-nor/next
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20220513/202205132220.uRTFaqNA-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/d38c0ac1528d85bea65fc5a9e7f61a10dbc051fb
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Michael-Walle/mtd-spi-nor-generic-flash-driver/20220513-214238
        git checkout d38c0ac1528d85bea65fc5a9e7f61a10dbc051fb
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/mtd/spi-nor/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/mtd/spi-nor/sfdp.c:1260: warning: expecting prototype for spi_nor_check_sfdp_header(). Prototype was for spi_nor_check_sfdp_signature() instead


vim +1260 drivers/mtd/spi-nor/sfdp.c

  1249	
  1250	/**
  1251	 * spi_nor_check_sfdp_header() - check for a valid SFDP header
  1252	 * @nor:		pointer to a 'struct spi_nor'
  1253	 *
  1254	 * Used to detect if the flash supports the RDSFDP command as well as the
  1255	 * presence of a valid SFDP table.
  1256	 *
  1257	 * Return: 0 on success, -errno otherwise.
  1258	 */
  1259	int spi_nor_check_sfdp_signature(struct spi_nor *nor)
> 1260	{
  1261		u32 signature;
  1262		int err;
  1263	
  1264		/* Get the SFDP header. */
  1265		err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
  1266						   &signature);
  1267		if (err < 0)
  1268			return err;
  1269	
  1270		/* Check the SFDP signature. */
  1271		if (le32_to_cpu(signature) != SFDP_SIGNATURE)
  1272			return -EINVAL;
  1273	
  1274		return 0;
  1275	}
  1276	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

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

* Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 14:47   ` kernel test robot
@ 2022-07-21  9:32     ` Biju Das
  2022-07-21  9:48     ` Michael Walle
  1 sibling, 0 replies; 22+ messages in thread
From: Biju Das @ 2022-07-21  9:32 UTC (permalink / raw)
  To: michael
  Cc: linux-kernel, linux-mtd, miquel.raynal, p.yadav, richard,
	tudor.ambarus, vigneshr

> Our SFDP is parsing is everything we need to support all basic operations of
> a flash device. If the flash isn't found in our in-kernel flash database,
> gracefully fall back to a driver described solely by its SFDP tables.
> 
> It is still recommended to add the flash to the in-kernel database.
> First, we get a proper partname and secondly, for all features not described
> by the SFDP like OTP we need the entry anyway.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/mtd/spi-nor/core.c | 13 +++++++++++++  drivers/mtd/spi-nor/core.h |
> 1 +  drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
>  3 files changed, 41 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index
> 65cd8e668579..ee193a61310a 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1632,6 +1632,11 @@ static const struct spi_nor_manufacturer
> *manufacturers[] = {
>  	&spi_nor_xmc,
>  };
> 
> +static const struct flash_info spi_nor_generic_flash = {
> +	.name = "spi-nor-generic",
> +	.parse_sfdp = true,
> +};
> +
>  static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
>  						 const u8 *id)
>  {
> @@ -1670,6 +1675,14 @@ static const struct flash_info *spi_nor_detect(struct
> spi_nor *nor)
>  		return ERR_PTR(-ENOMEM);
> 
>  	info = spi_nor_match_id(nor, id);
> +
> +	/* Fallback to a generic flash described only by its SFDP data. */
> +	if (!info) {
> +		ret = spi_nor_check_sfdp_signature(nor);
> +		if (!ret)
> +			info = &spi_nor_generic_flash;
> +	}

May be this can be combined as

 	if (!info && (!spi_nor_check_sfdp_signature(nor)))
		info = &spi_nor_generic_flash;

Cheers,
Biju

>  	if (!info) {
>  		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
>  			SPI_NOR_MAX_ID_LEN, id);
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index
> 153cb4b174ee..b084cb6db401 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -703,6 +703,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor,
> u8 opcode,  int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8
> opcode,
>  				     const u8 *buf, size_t len);
> 
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor);
>  int spi_nor_parse_sfdp(struct spi_nor *nor);
> 
>  static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) diff --
> git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index
> a5211543d30d..9bdb3d5dc7e8 100644
> --- a/drivers/mtd/spi-nor/sfdp.c
> +++ b/drivers/mtd/spi-nor/sfdp.c
> @@ -1247,6 +1247,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor
> *nor)
>  		nor->info->fixups->post_sfdp(nor);
>  }
> 
> +/**
> + * spi_nor_check_sfdp_header() - check for a valid SFDP header
> + * @nor:		pointer to a 'struct spi_nor'
> + *
> + * Used to detect if the flash supports the RDSFDP command as well as
> +the
> + * presence of a valid SFDP table.
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor) {
> +	u32 signature;
> +	int err;
> +
> +	/* Get the SFDP header. */
> +	err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
> +					   &signature);
> +	if (err < 0)
> +		return err;
> +
> +	/* Check the SFDP signature. */
> +	if (le32_to_cpu(signature) != SFDP_SIGNATURE)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +
>  /**
>   * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters.
>   * @nor:		pointer to a 'struct spi_nor'
> --
> 2.25.1



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

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

* Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 14:47   ` kernel test robot
  2022-07-21  9:32     ` Biju Das
@ 2022-07-21  9:48     ` Michael Walle
  2022-07-21  9:52       ` Biju Das
  1 sibling, 1 reply; 22+ messages in thread
From: Michael Walle @ 2022-07-21  9:48 UTC (permalink / raw)
  To: Biju Das
  Cc: linux-kernel, linux-mtd, miquel.raynal, p.yadav, richard,
	tudor.ambarus, vigneshr

Hi,

>> +
>> +	/* Fallback to a generic flash described only by its SFDP data. */
>> +	if (!info) {
>> +		ret = spi_nor_check_sfdp_signature(nor);
>> +		if (!ret)
>> +			info = &spi_nor_generic_flash;
>> +	}
> 
> May be this can be combined as
> 
>  	if (!info && (!spi_nor_check_sfdp_signature(nor)))
> 		info = &spi_nor_generic_flash;

While this is the behavior, I don't like (1) calling functions
in the condition and (2) rely on the && and || semantics, i.e.
to just call the second part if the first is true/false.

-michael

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

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

* RE: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-07-21  9:48     ` Michael Walle
@ 2022-07-21  9:52       ` Biju Das
  2022-10-28 18:00         ` Biju Das
  0 siblings, 1 reply; 22+ messages in thread
From: Biju Das @ 2022-07-21  9:52 UTC (permalink / raw)
  To: Michael Walle
  Cc: linux-kernel, linux-mtd, miquel.raynal, p.yadav, richard,
	tudor.ambarus, vigneshr

Hi Michael Walle,

> Subject: Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
> 
> Hi,
> 
> >> +
> >> +	/* Fallback to a generic flash described only by its SFDP data. */
> >> +	if (!info) {
> >> +		ret = spi_nor_check_sfdp_signature(nor);
> >> +		if (!ret)
> >> +			info = &spi_nor_generic_flash;
> >> +	}
> >
> > May be this can be combined as
> >
> >  	if (!info && (!spi_nor_check_sfdp_signature(nor)))
> > 		info = &spi_nor_generic_flash;
> 
> While this is the behavior, I don't like (1) calling functions in the
> condition and (2) rely on the && and || semantics, i.e.
> to just call the second part if the first is true/false.

OK fine. I recently got a review comment from mainline for optimizing the number
of lines. That is the reason for suggestion.

Cheers,
biju

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

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

* Re: [PATCH 0/6] mtd: spi-nor: generic flash driver
  2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
                   ` (5 preceding siblings ...)
  2022-05-13 13:35 ` [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
@ 2022-07-26  8:06 ` Tudor.Ambarus
  2022-07-29  1:52   ` Takahiro Kuwano
  6 siblings, 1 reply; 22+ messages in thread
From: Tudor.Ambarus @ 2022-07-26  8:06 UTC (permalink / raw)
  To: michael, p.yadav, miquel.raynal, richard, vigneshr,
	Takahiro.Kuwano, tkuw584924
  Cc: linux-kernel, linux-mtd

Hi, Takahiro,

Would you please review this patch set?

Thanks,
ta

On 5/13/22 16:35, Michael Walle wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Add a generic flash driver, which is used when we don't find a matching
> flash in our database. All the basic features of a flash can be discovered
> by SFDP and most (if not all) newer flashes support it.
> 
> Michael Walle (6):
>   mtd: spi-nor: hide jedec_id sysfs attribute if not present
>   mtd: spi-nor: sysfs: hide manufacturer if it is not set
>   mtd: spi-nor: remember full JEDEC flash ID
>   mtd: spi-nor: move function declaration out of sfdp.h
>   mtd: spi-nor: add generic flash driver
>   mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver
> 
>  .../ABI/testing/sysfs-bus-spi-devices-spi-nor |  6 +++++
>  drivers/mtd/spi-nor/core.c                    | 18 +++++++++++++
>  drivers/mtd/spi-nor/core.h                    |  3 +++
>  drivers/mtd/spi-nor/debugfs.c                 |  2 +-
>  drivers/mtd/spi-nor/sfdp.c                    | 27 +++++++++++++++++++
>  drivers/mtd/spi-nor/sfdp.h                    |  2 --
>  drivers/mtd/spi-nor/sysfs.c                   | 20 +++++++++++++-
>  include/linux/mtd/spi-nor.h                   |  3 +++
>  8 files changed, 77 insertions(+), 4 deletions(-)
> 
> --
> 2.30.2
> 


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

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

* Re: [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present
  2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
@ 2022-07-26 10:00   ` Takahiro Kuwano
  0 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-26 10:00 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> Some non-jedec compliant flashes (like the Everspin flashes) don't have
> an ID at all. Hide the attribute in this case.
> 
> Fixes: 36ac02286265 ("mtd: spi-nor: add initial sysfs support")
> Signed-off-by: Michael Walle <michael@walle.cc>

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Best Regards,
Takahiro

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

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

* Re: [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set
  2022-05-13 13:35 ` [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
@ 2022-07-26 10:04   ` Takahiro Kuwano
  0 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-26 10:04 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> The manufacturer may be optional when pure SFDP flashes are supported.
> Hide the sysfs property if no manufacturer is set.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Best Regards,
Takahiro


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

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

* Re: [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h
  2022-05-13 13:35 ` [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
@ 2022-07-26 23:41   ` Takahiro Kuwano
  0 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-26 23:41 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> sfdp.h should only contain constants related to the JEDEC SFDP
> specification(s).
> 
> Signed-off-by: Michael Walle <michael@walle.cc>

I think sfdp.h can contain declaration for a function implemented in sfdp.c,
but not a strong preference.

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Thanks,
Takahiro

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

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

* Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
  2022-05-13 14:47   ` kernel test robot
@ 2022-07-28  3:28   ` Tudor.Ambarus
  2022-07-29  1:40   ` Takahiro Kuwano
  2 siblings, 0 replies; 22+ messages in thread
From: Tudor.Ambarus @ 2022-07-28  3:28 UTC (permalink / raw)
  To: michael, p.yadav, miquel.raynal, richard, vigneshr
  Cc: linux-kernel, linux-mtd

On 5/13/22 16:35, Michael Walle wrote:
> It is still recommended to add the flash to the in-kernel database.
> First, we get a proper partname and secondly, for all features not

I wouldn't advertise to add an entry in the flash_info array just for
the sake of a proper name. The name shouldn't matter. If all the flash
caps can be discovered when parsing SFDP let's not add an entry at all.

> described by the SFDP like OTP we need the entry anyway.

Yeah, caps like OTP are not SFDP discoverable, we should add a flash_entry
when things can not be discovered solely by parsing SFDP.

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

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

* Re: [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID
  2022-05-13 13:35 ` [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
@ 2022-07-29  1:00   ` Takahiro Kuwano
  0 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-29  1:00 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> At the moment, we print the JEDEC ID that is stored in our database. The
> generic flash support won't have such an entry in our database. To find
> out the JEDEC ID later we will have to cache it. There is also another
> advantage: If the flash is found in the database, the ID could be
> truncated because the ID of the entry is used which can be shorter. Some
> flashes still holds valuable information in the bytes after the JEDEC ID
> and come in handy during debugging of when coping with INFO6() entries.
> These are not accessible for now.
> 
> Save a copy of the ID bytes after reading and display it via debugfs.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/mtd/spi-nor/core.c    | 5 +++++
>  drivers/mtd/spi-nor/debugfs.c | 2 +-
>  include/linux/mtd/spi-nor.h   | 3 +++
>  3 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index ce5d69317d46..65cd8e668579 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1664,6 +1664,11 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
>  		return ERR_PTR(ret);
>  	}
>  
> +	/* Cache the complete flash ID. */
> +	nor->id = devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL);
> +	if (!nor->id)
> +		return ERR_PTR(-ENOMEM);
> +
>  	info = spi_nor_match_id(nor, id);
>  	if (!info) {
>  		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
> diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c
> index eaf84f7a0676..23d51e7ba0a7 100644
> --- a/drivers/mtd/spi-nor/debugfs.c
> +++ b/drivers/mtd/spi-nor/debugfs.c
> @@ -81,7 +81,7 @@ static int spi_nor_params_show(struct seq_file *s, void *data)
>  	int i;
>  
>  	seq_printf(s, "name\t\t%s\n", info->name);
> -	seq_printf(s, "id\t\t%*ph\n", info->id_len, info->id);
> +	seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id);
>  	string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf));
>  	seq_printf(s, "size\t\t%s\n", buf);
>  	seq_printf(s, "write size\t%u\n", params->writesize);
> diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
> index 1ede4c89805a..4dd6cd7389ca 100644
> --- a/include/linux/mtd/spi-nor.h
> +++ b/include/linux/mtd/spi-nor.h
> @@ -349,6 +349,8 @@ struct spi_nor_flash_parameter;
>   * @bouncebuf:		bounce buffer used when the buffer passed by the MTD
>   *                      layer is not DMA-able
>   * @bouncebuf_size:	size of the bounce buffer
> + * @id:			The flash's ID bytes. Always contains
> + *			SPI_NOR_MAX_ID_LEN bytes.
>   * @info:		SPI NOR part JEDEC MFR ID and other info
>   * @manufacturer:	SPI NOR manufacturer
>   * @addr_width:		number of address bytes
> @@ -379,6 +381,7 @@ struct spi_nor {
>  	struct spi_mem		*spimem;
>  	u8			*bouncebuf;
>  	size_t			bouncebuf_size;
> +	u8			*id;
>  	const struct flash_info	*info;
>  	const struct spi_nor_manufacturer *manufacturer;
>  	u8			addr_width;

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Thanks,
Takahiro


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

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

* Re: [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver
  2022-05-13 13:35 ` [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
@ 2022-07-29  1:25   ` Takahiro Kuwano
  0 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-29  1:25 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> We don't have a database entry for the generic SPI-NOR flash driver and
> thus we don't have a JEDEC ID to print. Print the (cached) JEDEC ID
> instead.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/mtd/spi-nor/sysfs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
> index 20563c1926f4..c09bb832b3b9 100644
> --- a/drivers/mtd/spi-nor/sysfs.c
> +++ b/drivers/mtd/spi-nor/sysfs.c
> @@ -35,8 +35,10 @@ static ssize_t jedec_id_show(struct device *dev,
>  	struct spi_device *spi = to_spi_device(dev);
>  	struct spi_mem *spimem = spi_get_drvdata(spi);
>  	struct spi_nor *nor = spi_mem_get_drvdata(spimem);
> +	const u8 *id = nor->info->id_len ? nor->info->id : nor->id;
> +	u8 id_len = nor->info->id_len ?: SPI_NOR_MAX_ID_LEN;
>  
> -	return sysfs_emit(buf, "%*phN\n", nor->info->id_len, nor->info->id);
> +	return sysfs_emit(buf, "%*phN\n", id_len, id);
>  }
>  static DEVICE_ATTR_RO(jedec_id);
>  
> @@ -76,7 +78,7 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
>  
>  	if (attr == &dev_attr_manufacturer.attr && !nor->manufacturer)
>  		return 0;
> -	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
> +	if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len && !nor->id)
>  		return 0;
>  
>  	return 0444;

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

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

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

* Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
  2022-05-13 14:47   ` kernel test robot
  2022-07-28  3:28   ` Tudor.Ambarus
@ 2022-07-29  1:40   ` Takahiro Kuwano
  2 siblings, 0 replies; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-29  1:40 UTC (permalink / raw)
  To: Michael Walle, Tudor Ambarus, Pratyush Yadav, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: linux-kernel, linux-mtd

On 5/13/2022 10:35 PM, Michael Walle wrote:
> Our SFDP is parsing is everything we need to support all basic
redundant "is"?

> operations of a flash device. If the flash isn't found in our in-kernel
> flash database, gracefully fall back to a driver described solely by its
> SFDP tables.
> 
> It is still recommended to add the flash to the in-kernel database.
> First, we get a proper partname and secondly, for all features not
> described by the SFDP like OTP we need the entry anyway.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  drivers/mtd/spi-nor/core.c | 13 +++++++++++++
>  drivers/mtd/spi-nor/core.h |  1 +
>  drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++
>  3 files changed, 41 insertions(+)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 65cd8e668579..ee193a61310a 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1632,6 +1632,11 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
>  	&spi_nor_xmc,
>  };
>  
> +static const struct flash_info spi_nor_generic_flash = {
> +	.name = "spi-nor-generic",
> +	.parse_sfdp = true,
> +};
> +
>  static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
>  						 const u8 *id)
>  {
> @@ -1670,6 +1675,14 @@ static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
>  		return ERR_PTR(-ENOMEM);
>  
>  	info = spi_nor_match_id(nor, id);
> +
> +	/* Fallback to a generic flash described only by its SFDP data. */
> +	if (!info) {
> +		ret = spi_nor_check_sfdp_signature(nor);
> +		if (!ret)
> +			info = &spi_nor_generic_flash;
> +	}
> +
>  	if (!info) {
>  		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
>  			SPI_NOR_MAX_ID_LEN, id);
> diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h
> index 3a19b8092ab8..aa9f218245a5 100644
> --- a/drivers/mtd/spi-nor/core.h
> +++ b/drivers/mtd/spi-nor/core.h
> @@ -694,6 +694,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor, u8 opcode,
>  int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode,
>  				     const u8 *buf, size_t len);
>  
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor);
>  int spi_nor_parse_sfdp(struct spi_nor *nor);
>  
>  static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd)
> diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
> index a5211543d30d..9bdb3d5dc7e8 100644
> --- a/drivers/mtd/spi-nor/sfdp.c
> +++ b/drivers/mtd/spi-nor/sfdp.c
> @@ -1247,6 +1247,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor *nor)
>  		nor->info->fixups->post_sfdp(nor);
>  }
>  
> +/**
> + * spi_nor_check_sfdp_header() - check for a valid SFDP header
> + * @nor:		pointer to a 'struct spi_nor'
> + *
> + * Used to detect if the flash supports the RDSFDP command as well as the
> + * presence of a valid SFDP table.
> + *
> + * Return: 0 on success, -errno otherwise.
> + */
> +int spi_nor_check_sfdp_signature(struct spi_nor *nor)
> +{
> +	u32 signature;
> +	int err;
> +
> +	/* Get the SFDP header. */
> +	err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature),
> +					   &signature);
> +	if (err < 0)
> +		return err;
> +
> +	/* Check the SFDP signature. */
> +	if (le32_to_cpu(signature) != SFDP_SIGNATURE)
> +		return -EINVAL;
> +
> +	return 0;
> +}
> +

Nice to use this function from spi_nor_parse_sfdp() as well, but I found it's
not straightforward...

Reviewed-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>

Thanks,
Takahiro

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

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

* Re: [PATCH 0/6] mtd: spi-nor: generic flash driver
  2022-07-26  8:06 ` [PATCH 0/6] mtd: spi-nor: " Tudor.Ambarus
@ 2022-07-29  1:52   ` Takahiro Kuwano
  2022-07-29  5:34     ` Tudor.Ambarus
  0 siblings, 1 reply; 22+ messages in thread
From: Takahiro Kuwano @ 2022-07-29  1:52 UTC (permalink / raw)
  To: Tudor.Ambarus, michael, p.yadav, miquel.raynal, richard,
	vigneshr, Takahiro.Kuwano
  Cc: linux-kernel, linux-mtd

Hi Tudor and Michael,

On 7/26/2022 5:06 PM, Tudor.Ambarus@microchip.com wrote:
> Hi, Takahiro,
> 
> Would you please review this patch set?
> 
I tested a Flash device that is not yet in the database.
https://www.infineon.com/dgdl/Infineon-S25FS256T_256Mb_SEMPER_Nano_Flash_Quad_SPI_1.8V-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c80027ecd0180740c5a46707a&da=t

And it works fine.


zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/partname
spi-nor-generic
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/jedec_id
342b190f0890
zynq> cat /sys/bus/spi/devices/spi0.0/spi-nor/manufacturer
spansion
zynq> xxd -p /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
53464450080101ff00000114000100ff84000102500100ffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
ffffffffffffffffffffffffffffffffe7ffe2ffffffff0f48eb086bffff
ffffeeffffffffff00ffffff00ff11d810d800ff00ff321cfeff71e9ffe1
ec031c607a757a75f766805c00d65dfff938c0a100000000000000000000
0000ffffffff710600fedcdcffff
zynq> md5sum /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
13ecce2f195c4c71648e90d4a7e4a0df  /sys/bus/spi/devices/spi0.0/spi-nor/sfdp
zynq> test_qspi.sh
6+0 records in
6+0 records out
6291456 bytes (6.0MB) copied, 0.231887 seconds, 25.9MB/s
Copied 6291456 bytes from qspi_test to address 0x00000000 in flash
Erased 6291456 bytes from address 0x00000000 in flash
Copied 6291456 bytes from address 0x00000000 in flash to qspi_read
0000000 ffff ffff ffff ffff ffff ffff ffff ffff
*
0600000
Copied 6291456 bytes from qspi_test to address 0x00000000 in flash
Copied 6291456 bytes from address 0x00000000 in flash to qspi_read
20b1c32188a5e337ef7575ffb5e4fa424f6bf5a9  qspi_test
20b1c32188a5e337ef7575ffb5e4fa424f6bf5a9  qspi_read


Thanks,
Takahiro

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

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

* Re: [PATCH 0/6] mtd: spi-nor: generic flash driver
  2022-07-29  1:52   ` Takahiro Kuwano
@ 2022-07-29  5:34     ` Tudor.Ambarus
  0 siblings, 0 replies; 22+ messages in thread
From: Tudor.Ambarus @ 2022-07-29  5:34 UTC (permalink / raw)
  To: tkuw584924, michael, p.yadav, miquel.raynal, richard, vigneshr,
	Takahiro.Kuwano
  Cc: linux-kernel, linux-mtd

On 7/29/22 04:52, Takahiro Kuwano wrote:
> Hi Tudor and Michael,

Hi!

> 
> On 7/26/2022 5:06 PM, Tudor.Ambarus@microchip.com wrote:
>> Hi, Takahiro,
>>
>> Would you please review this patch set?
>>
> I tested a Flash device that is not yet in the database.
> https://www.infineon.com/dgdl/Infineon-S25FS256T_256Mb_SEMPER_Nano_Flash_Quad_SPI_1.8V-DataSheet-v01_00-EN.pdf?fileId=8ac78c8c80027ecd0180740c5a46707a&da=t
> 
> And it works fine.

Cool, thanks for the involvement!

Michael, I'll consider to include this once the merge window is open.
I'll stop queuing patches for now as we're late in the release cycle.

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

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

* RE: [PATCH 5/6] mtd: spi-nor: add generic flash driver
  2022-07-21  9:52       ` Biju Das
@ 2022-10-28 18:00         ` Biju Das
  0 siblings, 0 replies; 22+ messages in thread
From: Biju Das @ 2022-10-28 18:00 UTC (permalink / raw)
  To: Michael Walle, tudor.ambarus
  Cc: linux-kernel, linux-mtd, miquel.raynal, p.yadav, richard, vigneshr

Hi All,

Any update on [1]?. As per [2], we need to use generic flash driver as our flash chip
supports sfdp. Anything to be improved on [1]?? Please let us know.

[1] https://lore.kernel.org/lkml/20220810220654.1297699-1-michael@walle.cc/T/#m3ce890b65360f9fbe17b813d692f848b5c6d78e7
[2] https://patchwork.kernel.org/project/linux-renesas-soc/patch/20220715105716.2415068-3-biju.das.jz@bp.renesas.com/

Cheers,
Biju

> Subject: RE: [PATCH 5/6] mtd: spi-nor: add generic flash driver
> 
> Hi Michael Walle,
> 
> > Subject: Re: [PATCH 5/6] mtd: spi-nor: add generic flash driver
> >
> > Hi,
> >
> > >> +
> > >> +	/* Fallback to a generic flash described only by its SFDP
> data. */
> > >> +	if (!info) {
> > >> +		ret = spi_nor_check_sfdp_signature(nor);
> > >> +		if (!ret)
> > >> +			info = &spi_nor_generic_flash;
> > >> +	}
> > >
> > > May be this can be combined as
> > >
> > >  	if (!info && (!spi_nor_check_sfdp_signature(nor)))
> > > 		info = &spi_nor_generic_flash;
> >
> > While this is the behavior, I don't like (1) calling functions in
> the
> > condition and (2) rely on the && and || semantics, i.e.
> > to just call the second part if the first is true/false.
> 
> OK fine. I recently got a review comment from mainline for optimizing
> the number of lines. That is the reason for suggestion.
> 
> Cheers,
> biju

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

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

end of thread, other threads:[~2022-10-28 18:00 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 13:35 [PATCH 0/6] mtd: spi-nor: generic flash driver Michael Walle
2022-05-13 13:35 ` [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Michael Walle
2022-07-26 10:00   ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Michael Walle
2022-07-26 10:04   ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Michael Walle
2022-07-29  1:00   ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Michael Walle
2022-07-26 23:41   ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 5/6] mtd: spi-nor: add generic flash driver Michael Walle
2022-05-13 14:47   ` kernel test robot
2022-07-21  9:32     ` Biju Das
2022-07-21  9:48     ` Michael Walle
2022-07-21  9:52       ` Biju Das
2022-10-28 18:00         ` Biju Das
2022-07-28  3:28   ` Tudor.Ambarus
2022-07-29  1:40   ` Takahiro Kuwano
2022-05-13 13:35 ` [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for " Michael Walle
2022-07-29  1:25   ` Takahiro Kuwano
2022-07-26  8:06 ` [PATCH 0/6] mtd: spi-nor: " Tudor.Ambarus
2022-07-29  1:52   ` Takahiro Kuwano
2022-07-29  5:34     ` Tudor.Ambarus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).