linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts
@ 2022-08-25 21:44 Michael Walle
  2022-08-25 21:44 ` [PATCH v1 01/14] net: add helper eth_addr_add() Michael Walle
                   ` (14 more replies)
  0 siblings, 15 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

This is now the third attempt to fetch the MAC addresses from the VPD
for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/20211228142549.1275412-1-michael@walle.cc/


NVMEM cells are typically added by board code or by the devicetree. But
as the cells get more complex, there is (valid) push back from the
devicetree maintainers to not put that handling in the devicetree.

Therefore, introduce NVMEM layouts. They operate on the NVMEM device and
can add cells during runtime. That way it is possible to add complex
cells than it is possible right now with the offset/length/bits
description in the device tree. For example, you can have post processing
for individual cells (think of endian swapping, or ethernet offset
handling). You can also have cells which have no static offset, like the
ones in an u-boot environment. The last patches will convert the current
u-boot environment driver to a NVMEM layout and lifting the restriction
that it only works with mtd devices. But as it will change the required
compatible strings, it is marked as RFC for now. It also needs to have
its device tree schema update which is left out here.

For now, the layouts are selected by a specifc compatible string in a
device tree. E.g. the VPD on the kontron sl28 do (within a SPI flash node):
  compatible = "kontron,sl28-vpd", "user-otp";
or if you'd use the u-boot environment (within an MTD patition):
  compatible = "u-boot,env", "nvmem";

The "user-otp" (or "nvmem") will lead to a NVMEM device, the
"kontron,sl28-vpd" (or "u-boot,env") will then apply the specific layout
on top of the NVMEM device.

NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM
core can't be compiled as a module. The layouts needs to be available at
probe time. (That is also the reason why they get registered with
subsys_initcall().) So if the NVMEM core would be a module, the layouts
could be modules, too.

Michael Walle (14):
  net: add helper eth_addr_add()
  of: base: add of_parse_phandle_with_optional_args()
  nvmem: core: add an index parameter to the cell
  nvmem: core: drop the removal of the cells in nvmem_add_cells()
  nvmem: core: add nvmem_add_one_cell()
  nvmem: core: introduce NVMEM layouts
  nvmem: core: add per-cell post processing
  dt-bindings: mtd: relax the nvmem compatible string
  dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  nvmem: layouts: add sl28vpd layout
  nvmem: core: export nvmem device size
  nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout
  nvmem: layouts: u-boot-env: add device node
  arm64: dts: ls1028a: sl28: get MAC addresses from VPD

 .../devicetree/bindings/mtd/mtd.yaml          |   7 +-
 .../nvmem/layouts/kontron,sl28-vpd.yaml       |  52 +++++
 .../fsl-ls1028a-kontron-kbox-a-230-ls.dts     |   8 +
 .../fsl-ls1028a-kontron-sl28-var1.dts         |   2 +
 .../fsl-ls1028a-kontron-sl28-var2.dts         |   4 +
 .../fsl-ls1028a-kontron-sl28-var4.dts         |   2 +
 .../freescale/fsl-ls1028a-kontron-sl28.dts    |  13 ++
 drivers/nvmem/Kconfig                         |   2 +
 drivers/nvmem/Makefile                        |   1 +
 drivers/nvmem/core.c                          | 183 +++++++++++----
 drivers/nvmem/imx-ocotp.c                     |   4 +-
 drivers/nvmem/layouts/Kconfig                 |  22 ++
 drivers/nvmem/layouts/Makefile                |   7 +
 drivers/nvmem/layouts/sl28vpd.c               | 144 ++++++++++++
 drivers/nvmem/layouts/u-boot-env.c            | 147 ++++++++++++
 drivers/nvmem/u-boot-env.c                    | 218 ------------------
 include/linux/etherdevice.h                   |  14 ++
 include/linux/nvmem-consumer.h                |  11 +
 include/linux/nvmem-provider.h                |  47 +++-
 include/linux/of.h                            |  25 ++
 20 files changed, 649 insertions(+), 264 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
 create mode 100644 drivers/nvmem/layouts/Kconfig
 create mode 100644 drivers/nvmem/layouts/Makefile
 create mode 100644 drivers/nvmem/layouts/sl28vpd.c
 create mode 100644 drivers/nvmem/layouts/u-boot-env.c
 delete mode 100644 drivers/nvmem/u-boot-env.c

-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 01/14] net: add helper eth_addr_add()
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-09-01 16:26   ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 02/14] of: base: add of_parse_phandle_with_optional_args() Michael Walle
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Add a helper to add an offset to a ethernet address. This comes in handy
if you have a base ethernet address for multiple interfaces.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 include/linux/etherdevice.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
index 92b10e67d5f8..d1be5ca4d5cb 100644
--- a/include/linux/etherdevice.h
+++ b/include/linux/etherdevice.h
@@ -485,6 +485,20 @@ static inline void eth_addr_inc(u8 *addr)
 	u64_to_ether_addr(u, addr);
 }
 
+/**
+ * eth_addr_add() - Add (or subtract) and offset to/from the given MAC address.
+ *
+ * @offset: Offset to add.
+ * @addr: Pointer to a six-byte array containing Ethernet address to increment.
+ */
+static inline void eth_addr_add(u8 *addr, long offset)
+{
+	u64 u = ether_addr_to_u64(addr);
+
+	u += offset;
+	u64_to_ether_addr(u, addr);
+}
+
 /**
  * is_etherdev_addr - Tell if given Ethernet address belongs to the device.
  * @dev: Pointer to a device structure
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 02/14] of: base: add of_parse_phandle_with_optional_args()
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
  2022-08-25 21:44 ` [PATCH v1 01/14] net: add helper eth_addr_add() Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 03/14] nvmem: core: add an index parameter to the cell Michael Walle
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle, Rob Herring

Add a new variant of the of_parse_phandle_with_args() which treats the
cells name as optional. If it's missing, it is assumed that the phandle
has no arguments.

Up until now, a nvmem node didn't have any arguments, so all the device
trees haven't any '#*-cells' property. But there is a need for an
additional argument for the phandle, for which we need a '#*-cells'
property. Therefore, we need to support nvmem nodes with and without
this property.

Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Rob Herring <robh@kernel.org>
---
 include/linux/of.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/linux/of.h b/include/linux/of.h
index 766d002bddb9..a0fe1a017452 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -1008,6 +1008,31 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
 					    index, out_args);
 }
 
+/**
+ * of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list
+ * @np:		pointer to a device tree node containing a list
+ * @list_name:	property name that contains a list
+ * @cells_name:	property name that specifies phandles' arguments count
+ * @index:	index of a phandle to parse out
+ * @out_args:	optional pointer to output arguments structure (will be filled)
+ *
+ * Same as of_parse_phandle_with_args() except that if the cells_name property
+ * is not found, cell_count of 0 is assumed.
+ *
+ * This is used to useful, if you have a phandle which didn't have arguments
+ * before and thus doesn't have a '#*-cells' property but is now migrated to
+ * having arguments while retaining backwards compatibility.
+ */
+static inline int of_parse_phandle_with_optional_args(const struct device_node *np,
+						      const char *list_name,
+						      const char *cells_name,
+						      int index,
+						      struct of_phandle_args *out_args)
+{
+	return __of_parse_phandle_with_args(np, list_name, cells_name,
+					    0, index, out_args);
+}
+
 /**
  * of_property_count_u8_elems - Count the number of u8 elements in a property
  *
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 03/14] nvmem: core: add an index parameter to the cell
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
  2022-08-25 21:44 ` [PATCH v1 01/14] net: add helper eth_addr_add() Michael Walle
  2022-08-25 21:44 ` [PATCH v1 02/14] of: base: add of_parse_phandle_with_optional_args() Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 04/14] nvmem: core: drop the removal of the cells in nvmem_add_cells() Michael Walle
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Sometimes a cell can represend multiple values. For example, a base
ethernet address stored in the NVMEM can be expanded into multiple
discreet ones by adding an offset.

For this use case, introduce an index parameter which is then used to
distiguish between values. This parameter will then be passed to the
post process hook which can then use it to create different values
during reading.

At the moment, there is only support for the device tree path. You can
add the index to the phandle, e.g.

  &net {
          nvmem-cells = <&base_mac_address 2>;
          nvmem-cell-names = "mac-address";
  };

  &nvmem_provider {
          base_mac_address: base-mac-address@0 {
                  #nvmem-cell-cells = <1>;
                  reg = <0 6>;
          };
  };

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c           | 37 ++++++++++++++++++++++++----------
 drivers/nvmem/imx-ocotp.c      |  4 ++--
 include/linux/nvmem-provider.h |  4 ++--
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 321d7d63e068..ab055e4fc409 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -60,6 +60,7 @@ struct nvmem_cell_entry {
 struct nvmem_cell {
 	struct nvmem_cell_entry *entry;
 	const char		*id;
+	int			index;
 };
 
 static DEFINE_MUTEX(nvmem_mutex);
@@ -1127,7 +1128,8 @@ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id)
 }
 EXPORT_SYMBOL_GPL(devm_nvmem_device_get);
 
-static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, const char *id)
+static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry,
+					    const char *id, int index)
 {
 	struct nvmem_cell *cell;
 	const char *name = NULL;
@@ -1146,6 +1148,7 @@ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, cons
 
 	cell->id = name;
 	cell->entry = entry;
+	cell->index = index;
 
 	return cell;
 }
@@ -1184,7 +1187,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
 				__nvmem_device_put(nvmem);
 				cell = ERR_PTR(-ENOENT);
 			} else {
-				cell = nvmem_create_cell(cell_entry, con_id);
+				cell = nvmem_create_cell(cell_entry, con_id, 0);
 				if (IS_ERR(cell))
 					__nvmem_device_put(nvmem);
 			}
@@ -1232,15 +1235,27 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 	struct nvmem_device *nvmem;
 	struct nvmem_cell_entry *cell_entry;
 	struct nvmem_cell *cell;
+	struct of_phandle_args cell_spec;
 	int index = 0;
+	int cell_index = 0;
+	int ret;
 
 	/* if cell name exists, find index to the name */
 	if (id)
 		index = of_property_match_string(np, "nvmem-cell-names", id);
 
-	cell_np = of_parse_phandle(np, "nvmem-cells", index);
-	if (!cell_np)
-		return ERR_PTR(-ENOENT);
+	ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
+						  "#nvmem-cell-cells",
+						  index, &cell_spec);
+	if (ret)
+		return ERR_PTR(ret);
+
+	if (cell_spec.args_count > 1)
+		return ERR_PTR(-EINVAL);
+
+	cell_np = cell_spec.np;
+	if (cell_spec.args_count)
+		cell_index = cell_spec.args[0];
 
 	nvmem_np = of_get_next_parent(cell_np);
 	if (!nvmem_np)
@@ -1257,7 +1272,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
 		return ERR_PTR(-ENOENT);
 	}
 
-	cell = nvmem_create_cell(cell_entry, id);
+	cell = nvmem_create_cell(cell_entry, id, cell_index);
 	if (IS_ERR(cell))
 		__nvmem_device_put(nvmem);
 
@@ -1410,8 +1425,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
 }
 
 static int __nvmem_cell_read(struct nvmem_device *nvmem,
-		      struct nvmem_cell_entry *cell,
-		      void *buf, size_t *len, const char *id)
+			     struct nvmem_cell_entry *cell,
+			     void *buf, size_t *len, const char *id, int index)
 {
 	int rc;
 
@@ -1425,7 +1440,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
 	if (nvmem->cell_post_process) {
-		rc = nvmem->cell_post_process(nvmem->priv, id,
+		rc = nvmem->cell_post_process(nvmem->priv, id, index,
 					      cell->offset, buf, cell->bytes);
 		if (rc)
 			return rc;
@@ -1460,7 +1475,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
-	rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id);
+	rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index);
 	if (rc) {
 		kfree(buf);
 		return ERR_PTR(rc);
@@ -1773,7 +1788,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 	if (rc)
 		return rc;
 
-	rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL);
+	rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0);
 	if (rc)
 		return rc;
 
diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c
index 14284e866f26..e9b52ecb3f72 100644
--- a/drivers/nvmem/imx-ocotp.c
+++ b/drivers/nvmem/imx-ocotp.c
@@ -222,8 +222,8 @@ static int imx_ocotp_read(void *context, unsigned int offset,
 	return ret;
 }
 
-static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset,
-			     void *data, size_t bytes)
+static int imx_ocotp_cell_pp(void *context, const char *id, int index,
+			     unsigned int offset, void *data, size_t bytes)
 {
 	struct ocotp_priv *priv = context;
 
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 50caa117cb62..8f964b394292 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -20,8 +20,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,
 typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
 				 void *val, size_t bytes);
 /* used for vendor specific post processing of cell data */
-typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, unsigned int offset,
-					  void *buf, size_t bytes);
+typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
+					 unsigned int offset, void *buf, size_t bytes);
 
 enum nvmem_type {
 	NVMEM_TYPE_UNKNOWN = 0,
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 04/14] nvmem: core: drop the removal of the cells in nvmem_add_cells()
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (2 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 03/14] nvmem: core: add an index parameter to the cell Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 05/14] nvmem: core: add nvmem_add_one_cell() Michael Walle
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

If nvmem_add_cells() fails, the whole nvmem_register() will fail
and the cells will then be removed anyway. This is a prepartion
to introduce a nvmem_add_one_cell() which can then be used by
nvmem_add_cells().

This is then the same to what nvmem_add_cells_from_table() and
nvmem_add_cells_from_of() do.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index ab055e4fc409..be38e62fd190 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		    int ncells)
 {
 	struct nvmem_cell_entry **cells;
-	int i, rval;
+	int i, rval = 0;
 
 	cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
 	if (!cells)
@@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
 		if (!cells[i]) {
 			rval = -ENOMEM;
-			goto err;
+			goto out;
 		}
 
 		rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
 		if (rval) {
 			kfree(cells[i]);
-			goto err;
+			goto out;
 		}
 
 		nvmem_cell_entry_add(cells[i]);
 	}
 
+out:
 	/* remove tmp array */
 	kfree(cells);
 
-	return 0;
-err:
-	while (i--)
-		nvmem_cell_entry_drop(cells[i]);
-
-	kfree(cells);
-
 	return rval;
 }
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 05/14] nvmem: core: add nvmem_add_one_cell()
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (3 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 04/14] nvmem: core: drop the removal of the cells in nvmem_add_cells() Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Add a new function to add exactly one cell. This will be used by the
nvmem layout drivers to add custom cells. In contrast to the
nvmem_add_cells(), this has the advantage that we don't have to assemble
a list of cells on runtime.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c           | 58 ++++++++++++++++++++--------------
 include/linux/nvmem-provider.h |  5 +++
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index be38e62fd190..3dfd149374a8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -501,6 +501,35 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
 	return 0;
 }
 
+/**
+ * nvmem_add_one_cell() - Add one cell information to an nvmem device
+ *
+ * @nvmem: nvmem device to add cells to.
+ * @info: nvmem cell info to add to the device
+ *
+ * Return: 0 or negative error code on failure.
+ */
+int nvmem_add_one_cell(struct nvmem_device *nvmem,
+		       const struct nvmem_cell_info *info)
+{
+	struct nvmem_cell_entry *cell;
+	int rval;
+
+	cell = kzalloc(sizeof(*cell), GFP_KERNEL);
+	if (!cell)
+		return -ENOMEM;
+
+	rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, info, cell);
+	if (rval) {
+		kfree(cell);
+		return rval;
+	}
+
+	nvmem_cell_entry_add(cell);
+
+	return 0;
+}
+
 /**
  * nvmem_add_cells() - Add cell information to an nvmem device
  *
@@ -514,34 +543,15 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,
 		    const struct nvmem_cell_info *info,
 		    int ncells)
 {
-	struct nvmem_cell_entry **cells;
-	int i, rval = 0;
-
-	cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
-	if (!cells)
-		return -ENOMEM;
+	int i, rval;
 
 	for (i = 0; i < ncells; i++) {
-		cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
-		if (!cells[i]) {
-			rval = -ENOMEM;
-			goto out;
-		}
-
-		rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
-		if (rval) {
-			kfree(cells[i]);
-			goto out;
-		}
-
-		nvmem_cell_entry_add(cells[i]);
+		rval = nvmem_add_one_cell(nvmem, &info[i]);
+		if (rval)
+			return rval;
 	}
 
-out:
-	/* remove tmp array */
-	kfree(cells);
-
-	return rval;
+	return 0;
 }
 
 /**
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index 8f964b394292..e710404959e7 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -138,6 +138,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,
 void nvmem_add_cell_table(struct nvmem_cell_table *table);
 void nvmem_del_cell_table(struct nvmem_cell_table *table);
 
+int nvmem_add_one_cell(struct nvmem_device *nvmem,
+		       const struct nvmem_cell_info *info);
+
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -155,6 +158,8 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c)
 
 static inline void nvmem_add_cell_table(struct nvmem_cell_table *table) {}
 static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
+static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
+				     const struct nvmem_cell_info *info) {}
 
 #endif /* CONFIG_NVMEM */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (4 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 05/14] nvmem: core: add nvmem_add_one_cell() Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-26  8:16   ` Michael Walle
                     ` (2 more replies)
  2022-08-25 21:44 ` [PATCH v1 07/14] nvmem: core: add per-cell post processing Michael Walle
                   ` (8 subsequent siblings)
  14 siblings, 3 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

NVMEM layouts are used to generate NVMEM cells during runtime. Think of
an EEPROM with a well-defined conent. For now, the content can be
described by a device tree or a board file. But this only works if the
offsets and lengths are static and don't change. One could also argue
that putting the layout of the EEPROM in the device tree is the wrong
place. Instead, the device tree should just have a specific compatible
string.

Right now there are two use cases:
 (1) The NVMEM cell needs special processing. E.g. if it only specifies
     a base MAC address offset and you need to add an offset, or it
     needs to parse a MAC from ASCII format or some proprietary format.
     (Post processing of cells is added in a later commit).
 (2) u-boot environment parsing. The cells don't have a particular
     offset but it needs parsing the content to determine the offsets
     and length.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/Kconfig          |  2 ++
 drivers/nvmem/Makefile         |  1 +
 drivers/nvmem/core.c           | 57 ++++++++++++++++++++++++++++++++++
 drivers/nvmem/layouts/Kconfig  |  5 +++
 drivers/nvmem/layouts/Makefile |  4 +++
 include/linux/nvmem-provider.h | 38 +++++++++++++++++++++++
 6 files changed, 107 insertions(+)
 create mode 100644 drivers/nvmem/layouts/Kconfig
 create mode 100644 drivers/nvmem/layouts/Makefile

diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
index bab8a29c9861..1416837b107b 100644
--- a/drivers/nvmem/Kconfig
+++ b/drivers/nvmem/Kconfig
@@ -357,4 +357,6 @@ config NVMEM_U_BOOT_ENV
 
 	  If compiled as module it will be called nvmem_u-boot-env.
 
+source "drivers/nvmem/layouts/Kconfig"
+
 endif
diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
index 399f9972d45b..cd5a5baa2f3a 100644
--- a/drivers/nvmem/Makefile
+++ b/drivers/nvmem/Makefile
@@ -5,6 +5,7 @@
 
 obj-$(CONFIG_NVMEM)		+= nvmem_core.o
 nvmem_core-y			:= core.o
+obj-y				+= layouts/
 
 # Devices
 obj-$(CONFIG_NVMEM_BCM_OCOTP)	+= nvmem-bcm-ocotp.o
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 3dfd149374a8..5357fc378700 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -74,6 +74,9 @@ static LIST_HEAD(nvmem_lookup_list);
 
 static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
 
+static DEFINE_SPINLOCK(nvmem_layout_lock);
+static LIST_HEAD(nvmem_layouts);
+
 static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
 			    void *val, size_t bytes)
 {
@@ -744,6 +747,56 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 	return 0;
 }
 
+int nvmem_register_layout(struct nvmem_layout *layout)
+{
+	spin_lock(&nvmem_layout_lock);
+	list_add(&layout->node, &nvmem_layouts);
+	spin_unlock(&nvmem_layout_lock);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(nvmem_register_layout);
+
+static struct nvmem_layout *nvmem_get_compatible_layout(struct device_node *np)
+{
+	struct nvmem_layout *p, *ret = NULL;
+
+	spin_lock(&nvmem_layout_lock);
+
+	list_for_each_entry(p, &nvmem_layouts, node) {
+		if (of_match_node(p->of_match_table, np)) {
+			ret = p;
+			break;
+		}
+	}
+
+	spin_unlock(&nvmem_layout_lock);
+
+	return ret;
+}
+
+static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem)
+{
+	struct nvmem_layout *layout;
+
+	layout = nvmem_get_compatible_layout(nvmem->dev.of_node);
+	if (layout)
+		layout->add_cells(&nvmem->dev, nvmem, layout);
+
+	return 0;
+}
+
+const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+					struct nvmem_layout *layout)
+{
+	const struct of_device_id *match;
+
+	match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
+
+	return match ? match->data : NULL;
+}
+EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data);
+
 /**
  * nvmem_register() - Register a nvmem device for given nvmem_config.
  * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
@@ -872,6 +925,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (rval)
 		goto err_remove_cells;
 
+	rval = nvmem_add_cells_from_layout(nvmem);
+	if (rval)
+		goto err_remove_cells;
+
 	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
 
 	return nvmem;
diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
new file mode 100644
index 000000000000..9ad3911d1605
--- /dev/null
+++ b/drivers/nvmem/layouts/Kconfig
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+menu "Layout Types"
+
+endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
new file mode 100644
index 000000000000..6fdb3c60a4fa
--- /dev/null
+++ b/drivers/nvmem/layouts/Makefile
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for nvmem layouts.
+#
diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
index e710404959e7..323685841e9f 100644
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -127,6 +127,28 @@ struct nvmem_cell_table {
 	struct list_head	node;
 };
 
+/**
+ * struct nvmem_layout - NVMEM layout definitions
+ *
+ * @name:		Layout name.
+ * @of_match_table:	Open firmware match table.
+ * @add_cells:		Will be called if a nvmem device is found which
+ *			has this layout. The function will add layout
+ *			specific cells with nvmem_add_one_cell().
+ * @node:		List node.
+ *
+ * A nvmem device can hold a well defined structure which can just be
+ * evaluated during runtime. For example a TLV list, or a list of "name=val"
+ * pairs. A nvmem layout can parse the nvmem device and add appropriate
+ * cells.
+ */
+struct nvmem_layout {
+	const char *name;
+	const struct of_device_id *of_match_table;
+	int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout *layout);
+	struct list_head node;
+};
+
 #if IS_ENABLED(CONFIG_NVMEM)
 
 struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
@@ -141,6 +163,10 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table);
 int nvmem_add_one_cell(struct nvmem_device *nvmem,
 		       const struct nvmem_cell_info *info);
 
+int nvmem_register_layout(struct nvmem_layout *layout);
+const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+					struct nvmem_layout *layout);
+
 #else
 
 static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
@@ -161,5 +187,17 @@ static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
 static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
 				     const struct nvmem_cell_info *info) {}
 
+static inline int nvmem_register_layout(struct nvmem_layout *layout)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline const void *
+nvmem_layout_get_match_data(struct nvmem_device *nvmem,
+			    struct nvmem_layout *layout)
+{
+	return NULL;
+}
+
 #endif /* CONFIG_NVMEM */
 #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 07/14] nvmem: core: add per-cell post processing
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (5 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-30 13:37   ` Srinivas Kandagatla
  2022-08-25 21:44 ` [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string Michael Walle
                   ` (7 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Instead of relying on the name the consumer is using for the cell, like
it is done for the nvmem .cell_post_process configuration parameter,
provide a per-cell post processing hook. This can then be populated by
the NVMEM provider (or the NVMEM layout) when adding the cell.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c           | 16 ++++++++++++++++
 include/linux/nvmem-consumer.h |  5 +++++
 2 files changed, 21 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 5357fc378700..cbfbe6264e6c 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -52,6 +52,7 @@ struct nvmem_cell_entry {
 	int			bytes;
 	int			bit_offset;
 	int			nbits;
+	nvmem_cell_post_process_t post_process;
 	struct device_node	*np;
 	struct nvmem_device	*nvmem;
 	struct list_head	node;
@@ -468,6 +469,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
 	cell->offset = info->offset;
 	cell->bytes = info->bytes;
 	cell->name = info->name;
+	cell->post_process = info->post_process;
 
 	cell->bit_offset = info->bit_offset;
 	cell->nbits = info->nbits;
@@ -1500,6 +1502,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
 	if (cell->bit_offset || cell->nbits)
 		nvmem_shift_read_buffer_in_place(cell, buf);
 
+	if (cell->post_process) {
+		rc = cell->post_process(nvmem->priv, id, index,
+					cell->offset, buf, cell->bytes);
+		if (rc)
+			return rc;
+	}
+
 	if (nvmem->cell_post_process) {
 		rc = nvmem->cell_post_process(nvmem->priv, id, index,
 					      cell->offset, buf, cell->bytes);
@@ -1608,6 +1617,13 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
 	    (cell->bit_offset == 0 && len != cell->bytes))
 		return -EINVAL;
 
+	/*
+	 * Any cells which have a post_process hook are read-only because we
+	 * cannot reverse the operation and it might affect other cells, too.
+	 */
+	if (cell->post_process)
+		return -EINVAL;
+
 	if (cell->bit_offset || cell->nbits) {
 		buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
 		if (IS_ERR(buf))
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 980f9c9ac0bc..761b8ef78adc 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -19,6 +19,10 @@ struct device_node;
 struct nvmem_cell;
 struct nvmem_device;
 
+/* duplicated from nvmem-provider.h */
+typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
+					 unsigned int offset, void *buf, size_t bytes);
+
 struct nvmem_cell_info {
 	const char		*name;
 	unsigned int		offset;
@@ -26,6 +30,7 @@ struct nvmem_cell_info {
 	unsigned int		bit_offset;
 	unsigned int		nbits;
 	struct device_node	*np;
+	nvmem_cell_post_process_t post_process;
 };
 
 /**
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (6 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 07/14] nvmem: core: add per-cell post processing Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-31  7:37   ` Krzysztof Kozlowski
  2022-08-31 21:48   ` Rob Herring
  2022-08-25 21:44 ` [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout Michael Walle
                   ` (6 subsequent siblings)
  14 siblings, 2 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

The "user-otp" and "factory-otp" compatible string just depicts a
generic NVMEM device. But an actual device tree node might as well
contain a more specific compatible string. Make it possible to add
more specific binding elsewere and just match part of the compatibles
here.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/mtd/mtd.yaml b/Documentation/devicetree/bindings/mtd/mtd.yaml
index 376b679cfc70..0291e439b6a6 100644
--- a/Documentation/devicetree/bindings/mtd/mtd.yaml
+++ b/Documentation/devicetree/bindings/mtd/mtd.yaml
@@ -33,9 +33,10 @@ patternProperties:
 
     properties:
       compatible:
-        enum:
-          - user-otp
-          - factory-otp
+        contains:
+          enum:
+            - user-otp
+            - factory-otp
 
     required:
       - compatible
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (7 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-26 16:05   ` Rob Herring
  2022-08-31  7:45   ` Krzysztof Kozlowski
  2022-08-25 21:44 ` [PATCH v1 10/14] nvmem: layouts: add sl28vpd layout Michael Walle
                   ` (5 subsequent siblings)
  14 siblings, 2 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Add a schema for the NVMEM layout on Kontron's sl28 boards.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 .../nvmem/layouts/kontron,sl28-vpd.yaml       | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml

diff --git a/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
new file mode 100644
index 000000000000..e4bc2d9182db
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
@@ -0,0 +1,52 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/layouts/kontron,sl28-vpd.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NVMEM layout of the Kontron SMARC-sAL28 vital product data
+
+maintainers:
+  - Michael Walle <michael@walle.cc>
+
+description:
+  The vital product data (VPD) of the sl28 boards contains a serial
+  number and a base MAC address. The actual MAC addresses for the
+  on-board ethernet devices are derived from this base MAC address by
+  adding an offset.
+
+properties:
+  compatible:
+    items:
+      - const: kontron,sl28-vpd
+      - const: user-otp
+
+  serial-number:
+    type: object
+
+  base-mac-address:
+    type: object
+
+    properties:
+      "#nvmem-cell-cells":
+        const: 1
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+      otp-1 {
+          compatible = "kontron,sl28-vpd", "user-otp";
+
+          serial_number: serial-number {
+          };
+
+          base_mac_address: base-mac-address {
+              #nvmem-cell-cells = <1>;
+          };
+      };
+
+...
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 10/14] nvmem: layouts: add sl28vpd layout
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (8 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [PATCH v1 11/14] nvmem: core: export nvmem device size Michael Walle
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

This layout applies to the VPD of the Kontron sl28 boards. The VPD only
contains a base MAC address. Therefore, we have to add an individual
offset to it. This is done by taking the second argument of the nvmem
phandle into account. Also this let us checking the VPD version and the
checksum.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/layouts/Kconfig   |   9 ++
 drivers/nvmem/layouts/Makefile  |   2 +
 drivers/nvmem/layouts/sl28vpd.c | 144 ++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 drivers/nvmem/layouts/sl28vpd.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 9ad3911d1605..75082f6b471d 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -2,4 +2,13 @@
 
 menu "Layout Types"
 
+config NVMEM_LAYOUT_SL28_VPD
+	bool "Kontron sl28 VPD layout support"
+	select CRC8
+	help
+	  Say Y here if you want to support the VPD layout of the Kontron
+	  SMARC-sAL28 boards.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index 6fdb3c60a4fa..fc617b9e87d0 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -2,3 +2,5 @@
 #
 # Makefile for nvmem layouts.
 #
+
+obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c
new file mode 100644
index 000000000000..e6ec673aa58a
--- /dev/null
+++ b/drivers/nvmem/layouts/sl28vpd.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/crc8.h>
+#include <linux/etherdevice.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <uapi/linux/if_ether.h>
+
+#define SL28VPD_MAGIC 'V'
+
+struct sl28vpd_header {
+	u8 magic;
+	u8 version;
+} __packed;
+
+struct sl28vpd_v1 {
+	struct sl28vpd_header header;
+	char serial_number[15];
+	u8 base_mac_address[ETH_ALEN];
+	u8 crc8;
+} __packed;
+
+static int sl28vpd_mac_address_pp(void *priv, const char *id, int index,
+				  unsigned int offset, void *buf,
+				  size_t bytes)
+{
+	if (bytes != ETH_ALEN)
+		return -EINVAL;
+
+	if (index < 0)
+		return -EINVAL;
+
+	if (!is_valid_ether_addr(buf))
+		return -EINVAL;
+
+	eth_addr_add(buf, index);
+
+	return 0;
+}
+
+static const struct nvmem_cell_info sl28vpd_v1_entries[] = {
+	{
+		.name = "serial-number",
+		.offset = offsetof(struct sl28vpd_v1, serial_number),
+		.bytes = sizeof_field(struct sl28vpd_v1, serial_number),
+	},
+	{
+		.name = "base-mac-address",
+		.offset = offsetof(struct sl28vpd_v1, base_mac_address),
+		.bytes = sizeof_field(struct sl28vpd_v1, base_mac_address),
+		.post_process = sl28vpd_mac_address_pp,
+	},
+};
+
+static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem)
+{
+	struct sl28vpd_v1 data_v1;
+	u8 table[CRC8_TABLE_SIZE];
+	int ret;
+	u8 crc;
+
+	crc8_populate_msb(table, 0x07);
+
+	ret = nvmem_device_read(nvmem, 0, sizeof(data_v1), &data_v1);
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(data_v1))
+		return -EIO;
+
+	crc = crc8(table, (void *)&data_v1, sizeof(data_v1) - 1, 0);
+
+	if (crc != data_v1.crc8) {
+		dev_err(dev,
+			"Checksum is invalid (got %02x, expected %02x).\n",
+			crc, data_v1.crc8);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem,
+			     struct nvmem_layout *layout)
+{
+	const struct nvmem_cell_info *pinfo;
+	struct nvmem_cell_info info = {0};
+	struct sl28vpd_header hdr;
+	int ret, i;
+
+	/* check header */
+	ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr);
+	if (ret < 0)
+		return ret;
+	else if (ret != sizeof(hdr))
+		return -EIO;
+
+	if (hdr.magic != SL28VPD_MAGIC) {
+		dev_err(dev, "Invalid magic value (%02x)\n", hdr.magic);
+		return -EINVAL;
+	}
+
+	if (hdr.version != 1) {
+		dev_err(dev, "Version %d is unsupported.\n", hdr.version);
+		return -EINVAL;
+	}
+
+	ret = sl28vpd_v1_check_crc(dev, nvmem);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < ARRAY_SIZE(sl28vpd_v1_entries); i++) {
+		pinfo = &sl28vpd_v1_entries[i];
+
+		info.name = pinfo->name;
+		info.offset = pinfo->offset;
+		info.bytes = pinfo->bytes;
+		info.post_process = pinfo->post_process;
+		info.np = of_get_child_by_name(dev->of_node, pinfo->name);
+
+		ret = nvmem_add_one_cell(nvmem, &info);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static const struct of_device_id sl28vpd_of_match_table[] = {
+	{ .compatible = "kontron,sl28-vpd" },
+	{},
+};
+
+struct nvmem_layout sl28vpd_layout = {
+	.name = "sl28-vpd",
+	.of_match_table = sl28vpd_of_match_table,
+	.add_cells = sl28vpd_add_cells,
+};
+
+static int __init sl28vpd_init(void)
+{
+	return nvmem_register_layout(&sl28vpd_layout);
+}
+subsys_initcall(sl28vpd_init);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 11/14] nvmem: core: export nvmem device size
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (9 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 10/14] nvmem: layouts: add sl28vpd layout Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-25 21:44 ` [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout Michael Walle
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Export the size of the nvmem device. NVMEM layout drivers might need it
and might not have access to the device which is registering the NVMEM
device.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/core.c           | 13 +++++++++++++
 include/linux/nvmem-consumer.h |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index cbfbe6264e6c..f46ae358fe88 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -2031,6 +2031,19 @@ const char *nvmem_dev_name(struct nvmem_device *nvmem)
 }
 EXPORT_SYMBOL_GPL(nvmem_dev_name);
 
+/**
+ * nvmem_device_size() - Get the size of a given nvmem device.
+ *
+ * @nvmem: nvmem device.
+ *
+ * Return: size of the nvmem device.
+ */
+size_t nvmem_device_size(struct nvmem_device *nvmem)
+{
+	return nvmem->size;
+}
+EXPORT_SYMBOL_GPL(nvmem_device_size);
+
 static int __init nvmem_init(void)
 {
 	return bus_register(&nvmem_bus_type);
diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
index 761b8ef78adc..6b2a80a5fdd5 100644
--- a/include/linux/nvmem-consumer.h
+++ b/include/linux/nvmem-consumer.h
@@ -90,6 +90,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,
 			   struct nvmem_cell_info *info, void *buf);
 int nvmem_device_cell_write(struct nvmem_device *nvmem,
 			    struct nvmem_cell_info *info, void *buf);
+size_t nvmem_device_size(struct nvmem_device *nvmem);
 
 const char *nvmem_dev_name(struct nvmem_device *nvmem);
 
@@ -219,6 +220,11 @@ static inline int nvmem_device_write(struct nvmem_device *nvmem,
 	return -EOPNOTSUPP;
 }
 
+static inline size_t nvmem_device_size(struct nvmem_device *nvmem)
+{
+	return 0;
+}
+
 static inline const char *nvmem_dev_name(struct nvmem_device *nvmem)
 {
 	return NULL;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (10 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 11/14] nvmem: core: export nvmem device size Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-28 14:04   ` Rafał Miłecki
  2022-08-25 21:44 ` [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node Michael Walle
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Instead of hardcoding the underlying access method mtd_read() and
duplicating all the error handling, rewrite the driver as a nvmem
layout which just uses nvmem_device_read() and thus works with any
NVMEM device.

But because this is now not a device anymore, the compatible string
will have to be changed so the device will still be probed:
  compatible = "u-boot,env";
to
  compatible = "u-boot,env", "nvmem-cells";

"nvmem-cells" will tell the mtd layer to register a nvmem_device().
"u-boot,env" will tell the NVMEM that it should apply the u-boot
environment layout to the NVMEM device.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/layouts/Kconfig      |   8 ++
 drivers/nvmem/layouts/Makefile     |   1 +
 drivers/nvmem/layouts/u-boot-env.c | 143 +++++++++++++++++++
 drivers/nvmem/u-boot-env.c         | 218 -----------------------------
 4 files changed, 152 insertions(+), 218 deletions(-)
 create mode 100644 drivers/nvmem/layouts/u-boot-env.c
 delete mode 100644 drivers/nvmem/u-boot-env.c

diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
index 75082f6b471d..3db0c139a8b7 100644
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -11,4 +11,12 @@ config NVMEM_LAYOUT_SL28_VPD
 
 	  If unsure, say N.
 
+config NVMEM_LAYOUT_U_BOOT_ENV
+	bool "U-Boot environment support"
+	select CRC32
+	help
+	  Say Y here if you want to support u-boot's environment.
+
+	  If unsure, say N.
+
 endmenu
diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
index fc617b9e87d0..dae93fff2b85 100644
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
+obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o
diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
new file mode 100644
index 000000000000..40b7e9a778c4
--- /dev/null
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Rafał Miłecki <rafal@milecki.pl>
+ */
+
+#include <linux/crc32.h>
+#include <linux/dev_printk.h>
+#include <linux/mod_devicetable.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/slab.h>
+
+enum u_boot_env_format {
+	U_BOOT_FORMAT_SINGLE,
+	U_BOOT_FORMAT_REDUNDANT,
+};
+
+struct u_boot_env_image_single {
+	__le32 crc32;
+	u8 data[];
+} __packed;
+
+struct u_boot_env_image_redundant {
+	__le32 crc32;
+	u8 mark;
+	u8 data[];
+} __packed;
+
+static int u_boot_env_add_cells(struct nvmem_device *nvmem, uint8_t *buf,
+				size_t data_offset, size_t data_len)
+{
+	struct nvmem_cell_info info = {0};
+	char *data = buf + data_offset;
+	char *var, *value, *eq;
+	int err;
+
+	for (var = data;
+	     var < data + data_len && *var;
+	     var = value + strlen(value) + 1) {
+		eq = strchr(var, '=');
+		if (!eq)
+			break;
+		*eq = '\0';
+		value = eq + 1;
+
+		info.name = var;
+		info.offset = data_offset + value - data;
+		info.bytes = strlen(value);
+
+		err = nvmem_add_one_cell(nvmem, &info);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+static int u_boot_add_cells(struct device *dev, struct nvmem_device *nvmem,
+			    struct nvmem_layout *layout)
+{
+	size_t size = nvmem_device_size(nvmem);
+	enum u_boot_env_format format;
+	size_t crc32_data_offset;
+	size_t crc32_data_len;
+	size_t crc32_offset;
+	size_t data_offset;
+	size_t data_len;
+	u32 crc32;
+	u32 calc;
+	u8 *buf;
+	int err;
+
+	format = (uintptr_t)nvmem_layout_get_match_data(nvmem, layout);
+
+	buf = kzalloc(size, GFP_KERNEL);
+	if (!buf) {
+		err = -ENOMEM;
+		goto err_out;
+	}
+
+	err = nvmem_device_read(nvmem, 0, size, buf);
+	if (err < 0) {
+		dev_err(dev, "Failed to read from nvmem device (%pe)\n",
+			ERR_PTR(err));
+		goto err_kfree;
+	} else if (err != size) {
+		dev_err(dev, "Short read from nvmem device.\n");
+		err = -EIO;
+		goto err_kfree;
+	}
+
+	switch (format) {
+	case U_BOOT_FORMAT_SINGLE:
+		crc32_offset = offsetof(struct u_boot_env_image_single, crc32);
+		crc32_data_offset = offsetof(struct u_boot_env_image_single, data);
+		data_offset = offsetof(struct u_boot_env_image_single, data);
+		break;
+	case U_BOOT_FORMAT_REDUNDANT:
+		crc32_offset = offsetof(struct u_boot_env_image_redundant, crc32);
+		crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
+		data_offset = offsetof(struct u_boot_env_image_redundant, data);
+		break;
+	}
+	crc32 = le32_to_cpu(*(u32 *)(buf + crc32_offset));
+	crc32_data_len = size - crc32_data_offset;
+	data_len = size - data_offset;
+
+	calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
+	if (calc != crc32) {
+		dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32);
+		err = -EINVAL;
+		goto err_kfree;
+	}
+
+	buf[size - 1] = '\0';
+	err = u_boot_env_add_cells(nvmem, buf, data_offset, data_len);
+	if (err)
+		dev_err(dev, "Failed to add cells: %d\n", err);
+
+err_kfree:
+	kfree(buf);
+err_out:
+	return err;
+}
+
+static const struct of_device_id u_boot_env_of_match_table[] = {
+	{ .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
+	{ .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
+	{ .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
+	{},
+};
+
+static struct nvmem_layout u_boot_env_layout = {
+	.name = "u_boot_env",
+	.of_match_table = u_boot_env_of_match_table,
+	.add_cells = u_boot_add_cells,
+};
+
+static int __init u_boot_env_init(void)
+{
+	return nvmem_register_layout(&u_boot_env_layout);
+}
+subsys_initcall(u_boot_env_init);
diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
deleted file mode 100644
index 9b9abfb8f187..000000000000
--- a/drivers/nvmem/u-boot-env.c
+++ /dev/null
@@ -1,218 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2022 Rafał Miłecki <rafal@milecki.pl>
- */
-
-#include <linux/crc32.h>
-#include <linux/mod_devicetable.h>
-#include <linux/module.h>
-#include <linux/mtd/mtd.h>
-#include <linux/nvmem-consumer.h>
-#include <linux/nvmem-provider.h>
-#include <linux/of_device.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-
-enum u_boot_env_format {
-	U_BOOT_FORMAT_SINGLE,
-	U_BOOT_FORMAT_REDUNDANT,
-};
-
-struct u_boot_env {
-	struct device *dev;
-	enum u_boot_env_format format;
-
-	struct mtd_info *mtd;
-
-	/* Cells */
-	struct nvmem_cell_info *cells;
-	int ncells;
-};
-
-struct u_boot_env_image_single {
-	__le32 crc32;
-	uint8_t data[];
-} __packed;
-
-struct u_boot_env_image_redundant {
-	__le32 crc32;
-	u8 mark;
-	uint8_t data[];
-} __packed;
-
-static int u_boot_env_read(void *context, unsigned int offset, void *val,
-			   size_t bytes)
-{
-	struct u_boot_env *priv = context;
-	struct device *dev = priv->dev;
-	size_t bytes_read;
-	int err;
-
-	err = mtd_read(priv->mtd, offset, bytes, &bytes_read, val);
-	if (err && !mtd_is_bitflip(err)) {
-		dev_err(dev, "Failed to read from mtd: %d\n", err);
-		return err;
-	}
-
-	if (bytes_read != bytes) {
-		dev_err(dev, "Failed to read %zu bytes\n", bytes);
-		return -EIO;
-	}
-
-	return 0;
-}
-
-static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf,
-				size_t data_offset, size_t data_len)
-{
-	struct device *dev = priv->dev;
-	char *data = buf + data_offset;
-	char *var, *value, *eq;
-	int idx;
-
-	priv->ncells = 0;
-	for (var = data; var < data + data_len && *var; var += strlen(var) + 1)
-		priv->ncells++;
-
-	priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL);
-	if (!priv->cells)
-		return -ENOMEM;
-
-	for (var = data, idx = 0;
-	     var < data + data_len && *var;
-	     var = value + strlen(value) + 1, idx++) {
-		eq = strchr(var, '=');
-		if (!eq)
-			break;
-		*eq = '\0';
-		value = eq + 1;
-
-		priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL);
-		if (!priv->cells[idx].name)
-			return -ENOMEM;
-		priv->cells[idx].offset = data_offset + value - data;
-		priv->cells[idx].bytes = strlen(value);
-	}
-
-	if (WARN_ON(idx != priv->ncells))
-		priv->ncells = idx;
-
-	return 0;
-}
-
-static int u_boot_env_parse(struct u_boot_env *priv)
-{
-	struct device *dev = priv->dev;
-	size_t crc32_data_offset;
-	size_t crc32_data_len;
-	size_t crc32_offset;
-	size_t data_offset;
-	size_t data_len;
-	uint32_t crc32;
-	uint32_t calc;
-	size_t bytes;
-	uint8_t *buf;
-	int err;
-
-	buf = kcalloc(1, priv->mtd->size, GFP_KERNEL);
-	if (!buf) {
-		err = -ENOMEM;
-		goto err_out;
-	}
-
-	err = mtd_read(priv->mtd, 0, priv->mtd->size, &bytes, buf);
-	if ((err && !mtd_is_bitflip(err)) || bytes != priv->mtd->size) {
-		dev_err(dev, "Failed to read from mtd: %d\n", err);
-		goto err_kfree;
-	}
-
-	switch (priv->format) {
-	case U_BOOT_FORMAT_SINGLE:
-		crc32_offset = offsetof(struct u_boot_env_image_single, crc32);
-		crc32_data_offset = offsetof(struct u_boot_env_image_single, data);
-		data_offset = offsetof(struct u_boot_env_image_single, data);
-		break;
-	case U_BOOT_FORMAT_REDUNDANT:
-		crc32_offset = offsetof(struct u_boot_env_image_redundant, crc32);
-		crc32_data_offset = offsetof(struct u_boot_env_image_redundant, mark);
-		data_offset = offsetof(struct u_boot_env_image_redundant, data);
-		break;
-	}
-	crc32 = le32_to_cpu(*(uint32_t *)(buf + crc32_offset));
-	crc32_data_len = priv->mtd->size - crc32_data_offset;
-	data_len = priv->mtd->size - data_offset;
-
-	calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L;
-	if (calc != crc32) {
-		dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32);
-		err = -EINVAL;
-		goto err_kfree;
-	}
-
-	buf[priv->mtd->size - 1] = '\0';
-	err = u_boot_env_add_cells(priv, buf, data_offset, data_len);
-	if (err)
-		dev_err(dev, "Failed to add cells: %d\n", err);
-
-err_kfree:
-	kfree(buf);
-err_out:
-	return err;
-}
-
-static int u_boot_env_probe(struct platform_device *pdev)
-{
-	struct nvmem_config config = {
-		.name = "u-boot-env",
-		.reg_read = u_boot_env_read,
-	};
-	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
-	struct u_boot_env *priv;
-	int err;
-
-	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
-	if (!priv)
-		return -ENOMEM;
-	priv->dev = dev;
-
-	priv->format = (uintptr_t)of_device_get_match_data(dev);
-
-	priv->mtd = of_get_mtd_device_by_node(np);
-	if (IS_ERR(priv->mtd)) {
-		dev_err_probe(dev, PTR_ERR(priv->mtd), "Failed to get %pOF MTD\n", np);
-		return PTR_ERR(priv->mtd);
-	}
-
-	err = u_boot_env_parse(priv);
-	if (err)
-		return err;
-
-	config.dev = dev;
-	config.cells = priv->cells;
-	config.ncells = priv->ncells;
-	config.priv = priv;
-	config.size = priv->mtd->size;
-
-	return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config));
-}
-
-static const struct of_device_id u_boot_env_of_match_table[] = {
-	{ .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, },
-	{ .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
-	{ .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, },
-	{},
-};
-
-static struct platform_driver u_boot_env_driver = {
-	.probe = u_boot_env_probe,
-	.driver = {
-		.name = "u_boot_env",
-		.of_match_table = u_boot_env_of_match_table,
-	},
-};
-module_platform_driver(u_boot_env_driver);
-
-MODULE_AUTHOR("Rafał Miłecki");
-MODULE_LICENSE("GPL");
-MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (11 preceding siblings ...)
  2022-08-25 21:44 ` [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-28 13:55   ` Rafał Miłecki
  2022-08-25 21:44 ` [PATCH v1 14/14] arm64: dts: ls1028a: sl28: get MAC addresses from VPD Michael Walle
  2022-08-28 15:05 ` [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Rafał Miłecki
  14 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Register the device node so we can actually make use of the cells from
within the device tree.

This obviously only works if the environment variable name can be mapped
to the device node, which isn't always the case. Think of "_" vs "-".
But for simple things like ethaddr, this will work.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 drivers/nvmem/layouts/u-boot-env.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c
index 40b7e9a778c4..0901cc1f5acd 100644
--- a/drivers/nvmem/layouts/u-boot-env.c
+++ b/drivers/nvmem/layouts/u-boot-env.c
@@ -5,9 +5,11 @@
 
 #include <linux/crc32.h>
 #include <linux/dev_printk.h>
+#include <linux/device.h>
 #include <linux/mod_devicetable.h>
 #include <linux/nvmem-consumer.h>
 #include <linux/nvmem-provider.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 
 enum u_boot_env_format {
@@ -26,7 +28,8 @@ struct u_boot_env_image_redundant {
 	u8 data[];
 } __packed;
 
-static int u_boot_env_add_cells(struct nvmem_device *nvmem, uint8_t *buf,
+static int u_boot_env_add_cells(struct device *dev,
+				struct nvmem_device *nvmem, uint8_t *buf,
 				size_t data_offset, size_t data_len)
 {
 	struct nvmem_cell_info info = {0};
@@ -46,6 +49,7 @@ static int u_boot_env_add_cells(struct nvmem_device *nvmem, uint8_t *buf,
 		info.name = var;
 		info.offset = data_offset + value - data;
 		info.bytes = strlen(value);
+		info.np = of_get_child_by_name(dev->of_node, var);
 
 		err = nvmem_add_one_cell(nvmem, &info);
 		if (err)
@@ -113,7 +117,7 @@ static int u_boot_add_cells(struct device *dev, struct nvmem_device *nvmem,
 	}
 
 	buf[size - 1] = '\0';
-	err = u_boot_env_add_cells(nvmem, buf, data_offset, data_len);
+	err = u_boot_env_add_cells(dev, nvmem, buf, data_offset, data_len);
 	if (err)
 		dev_err(dev, "Failed to add cells: %d\n", err);
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v1 14/14] arm64: dts: ls1028a: sl28: get MAC addresses from VPD
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (12 preceding siblings ...)
  2022-08-25 21:44 ` [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node Michael Walle
@ 2022-08-25 21:44 ` Michael Walle
  2022-08-28 15:05 ` [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Rafał Miłecki
  14 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-25 21:44 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum, Michael Walle

Now that it is finally possible to get the MAC addresses from the OTP
memory, use it to set the addresses of the network devices.

There are 8 reserved MAC addresses in total per board. Distribute them
as follows:

+----------+------+------+------+------+------+
|          | var1 | var2 | var3 | var4 | kbox |
+----------+------+------+------+------+------+
| enetc #0 |   +0 |      |      |   +0 |   +0 |
| enetc #1 |      |      |   +0 |   +1 |   +1 |
| enetc #2 | rand | rand | rand | rand | rand |
| enetc #3 |      |      |      |      |      |
| felix p0 |      |   +0 |      |      |   +4 |
| felix p1 |      |   +1 |      |      |   +5 |
| felix p2 |      |      |      |      |   +6 |
| felix p3 |      |      |      |      |   +7 |
| felix p4 |      |      |      |      |      |
| felix p5 |      |      |      |      |      |
+----------+------+------+------+------+------+

An empty cell means, the port is not available and thus doesn't need an
ethernet address.

Signed-off-by: Michael Walle <michael@walle.cc>
---
 .../freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts |  8 ++++++++
 .../dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts |  2 ++
 .../dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts |  4 ++++
 .../dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts |  2 ++
 .../boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts | 13 +++++++++++++
 5 files changed, 29 insertions(+)

diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts
index 6b575efd84a7..b5c874c145d3 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-kbox-a-230-ls.dts
@@ -76,6 +76,8 @@ &mscc_felix_port0 {
 	managed = "in-band-status";
 	phy-handle = <&qsgmii_phy0>;
 	phy-mode = "qsgmii";
+	nvmem-cells = <&base_mac_address 4>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
@@ -84,6 +86,8 @@ &mscc_felix_port1 {
 	managed = "in-band-status";
 	phy-handle = <&qsgmii_phy1>;
 	phy-mode = "qsgmii";
+	nvmem-cells = <&base_mac_address 5>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
@@ -92,6 +96,8 @@ &mscc_felix_port2 {
 	managed = "in-band-status";
 	phy-handle = <&qsgmii_phy2>;
 	phy-mode = "qsgmii";
+	nvmem-cells = <&base_mac_address 6>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
@@ -100,6 +106,8 @@ &mscc_felix_port3 {
 	managed = "in-band-status";
 	phy-handle = <&qsgmii_phy3>;
 	phy-mode = "qsgmii";
+	nvmem-cells = <&base_mac_address 7>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts
index 7cd29ab970d9..1f34c7553459 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var1.dts
@@ -55,5 +55,7 @@ &enetc_port0 {
 &enetc_port1 {
 	phy-handle = <&phy0>;
 	phy-mode = "rgmii-id";
+	nvmem-cells = <&base_mac_address 0>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts
index 330e34f933a3..0ed0d2545922 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var2.dts
@@ -48,6 +48,8 @@ &mscc_felix_port0 {
 	managed = "in-band-status";
 	phy-handle = <&phy0>;
 	phy-mode = "sgmii";
+	nvmem-cells = <&base_mac_address 0>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
@@ -56,6 +58,8 @@ &mscc_felix_port1 {
 	managed = "in-band-status";
 	phy-handle = <&phy1>;
 	phy-mode = "sgmii";
+	nvmem-cells = <&base_mac_address 1>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts
index 9b5e92fb753e..a4421db3784e 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28-var4.dts
@@ -43,5 +43,7 @@ vddh: vddh-regulator {
 &enetc_port1 {
 	phy-handle = <&phy1>;
 	phy-mode = "rgmii-id";
+	nvmem-cells = <&base_mac_address 1>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
diff --git a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts
index 4ab17b984b03..72429b37a8b4 100644
--- a/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts
+++ b/arch/arm64/boot/dts/freescale/fsl-ls1028a-kontron-sl28.dts
@@ -92,6 +92,8 @@ &enetc_port0 {
 	phy-handle = <&phy0>;
 	phy-mode = "sgmii";
 	managed = "in-band-status";
+	nvmem-cells = <&base_mac_address 0>;
+	nvmem-cell-names = "mac-address";
 	status = "okay";
 };
 
@@ -154,6 +156,17 @@ partition@3e0000 {
 				label = "bootloader environment";
 			};
 		};
+
+		otp-1 {
+			compatible = "kontron,sl28-vpd", "user-otp";
+
+			serial_number: serial-number {
+			};
+
+			base_mac_address: base-mac-address {
+				#nvmem-cell-cells = <1>;
+			};
+		};
 	};
 };
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
@ 2022-08-26  8:16   ` Michael Walle
  2022-08-28 14:06   ` Rafał Miłecki
  2022-08-30 13:36   ` Srinivas Kandagatla
  2 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-26  8:16 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

Am 2022-08-25 23:44, schrieb Michael Walle:

> +struct nvmem_layout {
> +	const char *name;
> +	const struct of_device_id *of_match_table;
> +	int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout 
> *layout);

This must be:
int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct 
nvmem_layout *layout);

> +	struct list_head node;
> +};
> +

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-25 21:44 ` [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout Michael Walle
@ 2022-08-26 16:05   ` Rob Herring
  2022-08-31  7:45   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 49+ messages in thread
From: Rob Herring @ 2022-08-26 16:05 UTC (permalink / raw)
  To: Michael Walle
  Cc: Vignesh Raghavendra, Jakub Kicinski, Krzysztof Kozlowski,
	Eric Dumazet, devicetree, netdev, Paolo Abeni, Rob Herring,
	Frank Rowand, Ahmad Fatoum, linux-arm-kernel,
	Rafał Miłecki, Shawn Guo, Li Yang, David S . Miller,
	Richard Weinberger, linux-kernel, Srinivas Kandagatla, linux-mtd,
	Miquel Raynal

On Thu, 25 Aug 2022 23:44:18 +0200, Michael Walle wrote:
> Add a schema for the NVMEM layout on Kontron's sl28 boards.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  .../nvmem/layouts/kontron,sl28-vpd.yaml       | 52 +++++++++++++++++++
>  1 file changed, 52 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mtd/mtd.example.dtb: otp-2: compatible:0: 'kontron,sl28-vpd' was expected
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mtd/mtd.example.dtb: otp-2: compatible: ['user-otp'] is too short
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mtd/mtd.example.dtb: otp-2: '#address-cells', '#size-cells', 'mac-address@0' do not match any of the regexes: 'pinctrl-[0-9]+'
	From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node
  2022-08-25 21:44 ` [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node Michael Walle
@ 2022-08-28 13:55   ` Rafał Miłecki
  2022-08-28 14:36     ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Rafał Miłecki @ 2022-08-28 13:55 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 25.08.2022 23:44, Michael Walle wrote:
> Register the device node so we can actually make use of the cells from
> within the device tree.
> 
> This obviously only works if the environment variable name can be mapped
> to the device node, which isn't always the case. Think of "_" vs "-".
> But for simple things like ethaddr, this will work.

We probably shouldn't support undocumented syntax (bindings).

I've identical local patch that waits for
[PATCH] dt-bindings: nvmem: u-boot,env: add basic NVMEM cells
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220703084843.21922-1-zajec5@gmail.com/
to be accepted.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout
  2022-08-25 21:44 ` [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout Michael Walle
@ 2022-08-28 14:04   ` Rafał Miłecki
  2022-08-28 14:42     ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Rafał Miłecki @ 2022-08-28 14:04 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 25.08.2022 23:44, Michael Walle wrote:
> Instead of hardcoding the underlying access method mtd_read() and
> duplicating all the error handling, rewrite the driver as a nvmem
> layout which just uses nvmem_device_read() and thus works with any
> NVMEM device.
> 
> But because this is now not a device anymore, the compatible string
> will have to be changed so the device will still be probed:
>    compatible = "u-boot,env";
> to
>    compatible = "u-boot,env", "nvmem-cells";
> 
> "nvmem-cells" will tell the mtd layer to register a nvmem_device().
> "u-boot,env" will tell the NVMEM that it should apply the u-boot
> environment layout to the NVMEM device.

That's fishy but maybe we can ignore backward compatibility at
point.

Still you need to update DT binding.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
  2022-08-26  8:16   ` Michael Walle
@ 2022-08-28 14:06   ` Rafał Miłecki
  2022-08-28 14:33     ` Michael Walle
  2022-08-30 13:36   ` Srinivas Kandagatla
  2 siblings, 1 reply; 49+ messages in thread
From: Rafał Miłecki @ 2022-08-28 14:06 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 25.08.2022 23:44, Michael Walle wrote:
> For now, the content can be
> described by a device tree or a board file. But this only works if the
> offsets and lengths are static and don't change.

Not really true (see Broadcom's NVRAM and U-Boot's env data).

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-28 14:06   ` Rafał Miłecki
@ 2022-08-28 14:33     ` Michael Walle
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-28 14:33 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-28 16:06, schrieb Rafał Miłecki:
> On 25.08.2022 23:44, Michael Walle wrote:
>> For now, the content can be
>> described by a device tree or a board file. But this only works if the
>> offsets and lengths are static and don't change.
> 
> Not really true (see Broadcom's NVRAM and U-Boot's env data).

All except those two drivers don't add cells on their own. And for
these it is not possible to add non static cells, except in board
code maybe. This series make it possible to add this runtime parsing
to any NVMEM device.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node
  2022-08-28 13:55   ` Rafał Miłecki
@ 2022-08-28 14:36     ` Michael Walle
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-28 14:36 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-28 15:55, schrieb Rafał Miłecki:
> On 25.08.2022 23:44, Michael Walle wrote:
>> Register the device node so we can actually make use of the cells from
>> within the device tree.
>> 
>> This obviously only works if the environment variable name can be 
>> mapped
>> to the device node, which isn't always the case. Think of "_" vs "-".
>> But for simple things like ethaddr, this will work.
> 
> We probably shouldn't support undocumented syntax (bindings).

If we only support a predefined list of variables, we can make them
device tree compatible anyway. E.g. we could have a mapping
"serial-number" <-> "serial#"

-michael

> I've identical local patch that waits for
> [PATCH] dt-bindings: nvmem: u-boot,env: add basic NVMEM cells
> https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20220703084843.21922-1-zajec5@gmail.com/
> to be accepted.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout
  2022-08-28 14:04   ` Rafał Miłecki
@ 2022-08-28 14:42     ` Michael Walle
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-28 14:42 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-28 16:04, schrieb Rafał Miłecki:
> On 25.08.2022 23:44, Michael Walle wrote:
>> Instead of hardcoding the underlying access method mtd_read() and
>> duplicating all the error handling, rewrite the driver as a nvmem
>> layout which just uses nvmem_device_read() and thus works with any
>> NVMEM device.
>> 
>> But because this is now not a device anymore, the compatible string
>> will have to be changed so the device will still be probed:
>>    compatible = "u-boot,env";
>> to
>>    compatible = "u-boot,env", "nvmem-cells";
>> 
>> "nvmem-cells" will tell the mtd layer to register a nvmem_device().
>> "u-boot,env" will tell the NVMEM that it should apply the u-boot
>> environment layout to the NVMEM device.
> 
> That's fishy but maybe we can ignore backward compatibility at
> point.

As mentioned in the cover letter, this is why this is an RFC. I
didn't see any users in the device tree, nor can I see how this
would have been used anyway, because you cannot find a cell by
its device tree node, because none is registered. So maybe we
can still change the compatible string.

-michael

> Still you need to update DT binding.


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts
  2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
                   ` (13 preceding siblings ...)
  2022-08-25 21:44 ` [PATCH v1 14/14] arm64: dts: ls1028a: sl28: get MAC addresses from VPD Michael Walle
@ 2022-08-28 15:05 ` Rafał Miłecki
  2022-08-29  8:22   ` Michael Walle
  2022-08-31  7:48   ` Krzysztof Kozlowski
  14 siblings, 2 replies; 49+ messages in thread
From: Rafał Miłecki @ 2022-08-28 15:05 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 25.08.2022 23:44, Michael Walle wrote:
> This is now the third attempt to fetch the MAC addresses from the VPD
> for the Kontron sl28 boards. Previous discussions can be found here:
> https://lore.kernel.org/lkml/20211228142549.1275412-1-michael@walle.cc/
> 
> 
> NVMEM cells are typically added by board code or by the devicetree. But
> as the cells get more complex, there is (valid) push back from the
> devicetree maintainers to not put that handling in the devicetree.

I dropped the ball waiting for Rob's reponse in the
[PATCH 0/2] dt-bindings: nvmem: support describing cells
https://lore.kernel.org/linux-arm-kernel/0b7b8f7ea6569f79524aea1a3d783665@walle.cc/T/

Before we go any further can we have a clear answer from Rob (or
Krzysztof now too?):


Is there any point in having bindings like:

compatible = "mac-address";

for NVMEM cells nodes? So systems (Linux, U-Boot) can handle them in a
more generic way?


Or do we prefer more conditional drivers code (or layouts code as in
this Michael's proposal) that will handle cells properly based on their
names?


I'm not arguing for any solution. I just want to make sure we choose the
right way to proceed.


> Therefore, introduce NVMEM layouts. They operate on the NVMEM device and
> can add cells during runtime. That way it is possible to add complex
> cells than it is possible right now with the offset/length/bits
> description in the device tree. For example, you can have post processing
> for individual cells (think of endian swapping, or ethernet offset
> handling). You can also have cells which have no static offset, like the
> ones in an u-boot environment. The last patches will convert the current
> u-boot environment driver to a NVMEM layout and lifting the restriction
> that it only works with mtd devices. But as it will change the required
> compatible strings, it is marked as RFC for now. It also needs to have
> its device tree schema update which is left out here.

So do I get it right that we want to have:

1. NVMEM drivers for providing I/O access to NVMEM devices
2. NVMEM layouts for parsing & NVMEM cells and translating their content
?

I guess it sounds good and seems to be a clean solution.


One thing I believe you need to handle is replacing "cell_post_process"
callback with your layout thing.

I find it confusing to have
1. cell_post_process() CB at NVMEM device level
2. post_process() CB at NVMEM cell level


> For now, the layouts are selected by a specifc compatible string in a
> device tree. E.g. the VPD on the kontron sl28 do (within a SPI flash node):
>    compatible = "kontron,sl28-vpd", "user-otp";
> or if you'd use the u-boot environment (within an MTD patition):
>    compatible = "u-boot,env", "nvmem";
> 
> The "user-otp" (or "nvmem") will lead to a NVMEM device, the
> "kontron,sl28-vpd" (or "u-boot,env") will then apply the specific layout
> on top of the NVMEM device.
> 
> NVMEM layouts as modules?
> While possible in principle, it doesn't make any sense because the NVMEM
> core can't be compiled as a module. The layouts needs to be available at
> probe time. (That is also the reason why they get registered with
> subsys_initcall().) So if the NVMEM core would be a module, the layouts
> could be modules, too.
> 
> Michael Walle (14):
>    net: add helper eth_addr_add()
>    of: base: add of_parse_phandle_with_optional_args()
>    nvmem: core: add an index parameter to the cell
>    nvmem: core: drop the removal of the cells in nvmem_add_cells()
>    nvmem: core: add nvmem_add_one_cell()
>    nvmem: core: introduce NVMEM layouts
>    nvmem: core: add per-cell post processing
>    dt-bindings: mtd: relax the nvmem compatible string
>    dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
>    nvmem: layouts: add sl28vpd layout
>    nvmem: core: export nvmem device size
>    nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout
>    nvmem: layouts: u-boot-env: add device node
>    arm64: dts: ls1028a: sl28: get MAC addresses from VPD
> 
>   .../devicetree/bindings/mtd/mtd.yaml          |   7 +-
>   .../nvmem/layouts/kontron,sl28-vpd.yaml       |  52 +++++
>   .../fsl-ls1028a-kontron-kbox-a-230-ls.dts     |   8 +
>   .../fsl-ls1028a-kontron-sl28-var1.dts         |   2 +
>   .../fsl-ls1028a-kontron-sl28-var2.dts         |   4 +
>   .../fsl-ls1028a-kontron-sl28-var4.dts         |   2 +
>   .../freescale/fsl-ls1028a-kontron-sl28.dts    |  13 ++
>   drivers/nvmem/Kconfig                         |   2 +
>   drivers/nvmem/Makefile                        |   1 +
>   drivers/nvmem/core.c                          | 183 +++++++++++----
>   drivers/nvmem/imx-ocotp.c                     |   4 +-
>   drivers/nvmem/layouts/Kconfig                 |  22 ++
>   drivers/nvmem/layouts/Makefile                |   7 +
>   drivers/nvmem/layouts/sl28vpd.c               | 144 ++++++++++++
>   drivers/nvmem/layouts/u-boot-env.c            | 147 ++++++++++++
>   drivers/nvmem/u-boot-env.c                    | 218 ------------------
>   include/linux/etherdevice.h                   |  14 ++
>   include/linux/nvmem-consumer.h                |  11 +
>   include/linux/nvmem-provider.h                |  47 +++-
>   include/linux/of.h                            |  25 ++
>   20 files changed, 649 insertions(+), 264 deletions(-)
>   create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>   create mode 100644 drivers/nvmem/layouts/Kconfig
>   create mode 100644 drivers/nvmem/layouts/Makefile
>   create mode 100644 drivers/nvmem/layouts/sl28vpd.c
>   create mode 100644 drivers/nvmem/layouts/u-boot-env.c
>   delete mode 100644 drivers/nvmem/u-boot-env.c

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts
  2022-08-28 15:05 ` [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Rafał Miłecki
@ 2022-08-29  8:22   ` Michael Walle
  2022-08-30 13:37     ` Srinivas Kandagatla
  2022-08-31  7:48   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-29  8:22 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

Hi,

Am 2022-08-28 17:05, schrieb Rafał Miłecki:
> On 25.08.2022 23:44, Michael Walle wrote:
>> This is now the third attempt to fetch the MAC addresses from the VPD
>> for the Kontron sl28 boards. Previous discussions can be found here:
>> https://lore.kernel.org/lkml/20211228142549.1275412-1-michael@walle.cc/
>> 
>> 
>> NVMEM cells are typically added by board code or by the devicetree. 
>> But
>> as the cells get more complex, there is (valid) push back from the
>> devicetree maintainers to not put that handling in the devicetree.
> 
> I dropped the ball waiting for Rob's reponse in the
> [PATCH 0/2] dt-bindings: nvmem: support describing cells
> https://lore.kernel.org/linux-arm-kernel/0b7b8f7ea6569f79524aea1a3d783665@walle.cc/T/
> 
> Before we go any further can we have a clear answer from Rob (or
> Krzysztof now too?):
> 
> 
> Is there any point in having bindings like:
> 
> compatible = "mac-address";
> 
> for NVMEM cells nodes? So systems (Linux, U-Boot) can handle them in a
> more generic way?
> 
> 
> Or do we prefer more conditional drivers code (or layouts code as in
> this Michael's proposal) that will handle cells properly based on their
> names?

What do you mean by "based on their names?".

> I'm not arguing for any solution. I just want to make sure we choose 
> the
> right way to proceed.

With the 'compatible = "mac-address"', how would you detect what kind
of transformation you need to apply? You could guess ascii, yes. But
swapping bytes? You cannot guess that. So you'd need additional 
information
coming from the device tree. But Rob was quite clear that this shouldn't
be in the device tree:

| I still don't think trying to encode transformations of data into the 
DT
| is right approach.

https://lore.kernel.org/linux-devicetree/YaZ5JNCFeKcdIfu8@robh.at.kernel.org/

He also mention that the compatible should be on the nvmem device level
and should use specific compatible strings:
https://lore.kernel.org/linux-devicetree/CAL_JsqL55mZJ6jUyQACer2pKMNDV08-FgwBREsJVgitnuF18Cg@mail.gmail.com/

And IMHO that makes sense, because it matches the hardware and not any
NVMEM cells which is the *content* of a memory device.

And as you see in the sl28vpd layout, it allows you to do much more, 
like
checking for integrity, and make it future proof by supporting different
versions of this sl28vpd layout.

What if you use it with the u-boot,env? You wouldn't need it because
u-boot,env will already know how to interpret it as an ascii string
(and it also know the offset). In this sense, u-boot,env is already a
compatible string describing the content of a NVMEM device (and the
compatible string is at the device level).

>> Therefore, introduce NVMEM layouts. They operate on the NVMEM device 
>> and
>> can add cells during runtime. That way it is possible to add complex
>> cells than it is possible right now with the offset/length/bits
>> description in the device tree. For example, you can have post 
>> processing
>> for individual cells (think of endian swapping, or ethernet offset
>> handling). You can also have cells which have no static offset, like 
>> the
>> ones in an u-boot environment. The last patches will convert the 
>> current
>> u-boot environment driver to a NVMEM layout and lifting the 
>> restriction
>> that it only works with mtd devices. But as it will change the 
>> required
>> compatible strings, it is marked as RFC for now. It also needs to have
>> its device tree schema update which is left out here.
> 
> So do I get it right that we want to have:
> 
> 1. NVMEM drivers for providing I/O access to NVMEM devices
> 2. NVMEM layouts for parsing & NVMEM cells and translating their 
> content
> ?

Correct.

> I guess it sounds good and seems to be a clean solution.

Good to hear :)

> One thing I believe you need to handle is replacing "cell_post_process"
> callback with your layout thing.
> 
> I find it confusing to have
> 1. cell_post_process() CB at NVMEM device level
> 2. post_process() CB at NVMEM cell level

What is wrong with having a callback at both levels?

Granted, in this particular case (it is just used at one place), I still
think that it is the wrong approach to add this transformation in the
driver (in this particular case). The driver is supposed to give you
access to the SoC's fuse box, but it will magically change the content
of a cell if the nvmem consumer named this cell "mac-address" (which
you also found confusing the last time and I do too!).

The driver itself doesn't add any cells on its own, so I cannot register
a .post_process hook there. Therefore, you'd need that post_process hook
on every cell, which is equivalent to have a post_process hook at
device level.

Unless you have a better idea. I'll leave that up to NXP to fix that (or
leave it like that).

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
  2022-08-26  8:16   ` Michael Walle
  2022-08-28 14:06   ` Rafał Miłecki
@ 2022-08-30 13:36   ` Srinivas Kandagatla
  2022-08-30 14:24     ` Michael Walle
  2 siblings, 1 reply; 49+ messages in thread
From: Srinivas Kandagatla @ 2022-08-30 13:36 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum



On 25/08/2022 22:44, Michael Walle wrote:
> NVMEM layouts are used to generate NVMEM cells during runtime. Think of
> an EEPROM with a well-defined conent. For now, the content can be
> described by a device tree or a board file. But this only works if the
> offsets and lengths are static and don't change. One could also argue
> that putting the layout of the EEPROM in the device tree is the wrong
> place. Instead, the device tree should just have a specific compatible
> string.
> 
> Right now there are two use cases:
>   (1) The NVMEM cell needs special processing. E.g. if it only specifies
>       a base MAC address offset and you need to add an offset, or it
>       needs to parse a MAC from ASCII format or some proprietary format.
>       (Post processing of cells is added in a later commit).
>   (2) u-boot environment parsing. The cells don't have a particular
>       offset but it needs parsing the content to determine the offsets
>       and length.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>   drivers/nvmem/Kconfig          |  2 ++
>   drivers/nvmem/Makefile         |  1 +
>   drivers/nvmem/core.c           | 57 ++++++++++++++++++++++++++++++++++
>   drivers/nvmem/layouts/Kconfig  |  5 +++
>   drivers/nvmem/layouts/Makefile |  4 +++
>   include/linux/nvmem-provider.h | 38 +++++++++++++++++++++++
>   6 files changed, 107 insertions(+)
>   create mode 100644 drivers/nvmem/layouts/Kconfig
>   create mode 100644 drivers/nvmem/layouts/Makefile

update to ./Documentation/driver-api/nvmem.rst would help others.

> 
> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
> index bab8a29c9861..1416837b107b 100644
> --- a/drivers/nvmem/Kconfig
> +++ b/drivers/nvmem/Kconfig
> @@ -357,4 +357,6 @@ config NVMEM_U_BOOT_ENV
>   
>   	  If compiled as module it will be called nvmem_u-boot-env.
>   
> +source "drivers/nvmem/layouts/Kconfig"
> +
>   endif
> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
> index 399f9972d45b..cd5a5baa2f3a 100644
> --- a/drivers/nvmem/Makefile
> +++ b/drivers/nvmem/Makefile
> @@ -5,6 +5,7 @@
>   
>   obj-$(CONFIG_NVMEM)		+= nvmem_core.o
>   nvmem_core-y			:= core.o
> +obj-y				+= layouts/
>   
>   # Devices
>   obj-$(CONFIG_NVMEM_BCM_OCOTP)	+= nvmem-bcm-ocotp.o
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 3dfd149374a8..5357fc378700 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -74,6 +74,9 @@ static LIST_HEAD(nvmem_lookup_list);
>   
>   static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
>   
> +static DEFINE_SPINLOCK(nvmem_layout_lock);
> +static LIST_HEAD(nvmem_layouts);
> +
>   static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
>   			    void *val, size_t bytes)
>   {
> @@ -744,6 +747,56 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
>   	return 0;
>   }
>   
> +int nvmem_register_layout(struct nvmem_layout *layout)
> +{
> +	spin_lock(&nvmem_layout_lock);
> +	list_add(&layout->node, &nvmem_layouts);
> +	spin_unlock(&nvmem_layout_lock);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_register_layout);

we should provide nvmem_unregister_layout too, so that providers can add 
them if they can in there respective drivers.

> +
> +static struct nvmem_layout *nvmem_get_compatible_layout(struct device_node *np)
> +{
> +	struct nvmem_layout *p, *ret = NULL;
> +
> +	spin_lock(&nvmem_layout_lock);
> +
> +	list_for_each_entry(p, &nvmem_layouts, node) {
> +		if (of_match_node(p->of_match_table, np)) {
> +			ret = p;
> +			break;
> +		}
> +	}
> +
> +	spin_unlock(&nvmem_layout_lock);
> +
> +	return ret;
> +}
> +
> +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem)
> +{
> +	struct nvmem_layout *layout;
> +
> +	layout = nvmem_get_compatible_layout(nvmem->dev.of_node);
> +	if (layout)
> +		layout->add_cells(&nvmem->dev, nvmem, layout);

access to add_cells can crash hear as we did not check it before adding 
in to list.
Or
we could relax add_cells callback for usecases like imx-octop.


> +
> +	return 0;
> +}
> +
> +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
> +					struct nvmem_layout *layout)
> +{
> +	const struct of_device_id *match;
> +
> +	match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
> +
> +	return match ? match->data : NULL;
> +}
> +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data);
> +
>   /**
>    * nvmem_register() - Register a nvmem device for given nvmem_config.
>    * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem
> @@ -872,6 +925,10 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>   	if (rval)
>   		goto err_remove_cells;
>   
> +	rval = nvmem_add_cells_from_layout(nvmem);
> +	if (rval)
> +		goto err_remove_cells;
> +
>   	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
>   
>   	return nvmem;
> diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig
> new file mode 100644
> index 000000000000..9ad3911d1605
> --- /dev/null
> +++ b/drivers/nvmem/layouts/Kconfig
> @@ -0,0 +1,5 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +menu "Layout Types"
> +
> +endmenu
> diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile
> new file mode 100644
> index 000000000000..6fdb3c60a4fa
> --- /dev/null
> +++ b/drivers/nvmem/layouts/Makefile
> @@ -0,0 +1,4 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# Makefile for nvmem layouts.
> +#
> diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h
> index e710404959e7..323685841e9f 100644
> --- a/include/linux/nvmem-provider.h
> +++ b/include/linux/nvmem-provider.h
> @@ -127,6 +127,28 @@ struct nvmem_cell_table {
>   	struct list_head	node;
>   };
>   
> +/**
> + * struct nvmem_layout - NVMEM layout definitions
> + *
> + * @name:		Layout name.
> + * @of_match_table:	Open firmware match table.
> + * @add_cells:		Will be called if a nvmem device is found which
> + *			has this layout. The function will add layout
> + *			specific cells with nvmem_add_one_cell().
> + * @node:		List node.
> + *
> + * A nvmem device can hold a well defined structure which can just be
> + * evaluated during runtime. For example a TLV list, or a list of "name=val"
> + * pairs. A nvmem layout can parse the nvmem device and add appropriate
> + * cells.
> + */
> +struct nvmem_layout {
> +	const char *name;
> +	const struct of_device_id *of_match_table;

looking at this, I think its doable to convert the existing 
cell_post_process callback to layouts by adding a layout specific 
callback here.


--srini
> +	int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout *layout);
> +	struct list_head node;
> +};
> +
>   #if IS_ENABLED(CONFIG_NVMEM)
>   
>   struct nvmem_device *nvmem_register(const struct nvmem_config *cfg);
> @@ -141,6 +163,10 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table);
>   int nvmem_add_one_cell(struct nvmem_device *nvmem,
>   		       const struct nvmem_cell_info *info);
>   
> +int nvmem_register_layout(struct nvmem_layout *layout);
> +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
> +					struct nvmem_layout *layout);
> +
>   #else
>   
>   static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c)
> @@ -161,5 +187,17 @@ static inline void nvmem_del_cell_table(struct nvmem_cell_table *table) {}
>   static inline int nvmem_add_one_cell(struct nvmem_device *nvmem,
>   				     const struct nvmem_cell_info *info) {}
>   
> +static inline int nvmem_register_layout(struct nvmem_layout *layout)
> +{
> +	return -EOPNOTSUPP;
> +}
> +
> +static inline const void *
> +nvmem_layout_get_match_data(struct nvmem_device *nvmem,
> +			    struct nvmem_layout *layout)
> +{
> +	return NULL;
> +}
> +
>   #endif /* CONFIG_NVMEM */
>   #endif  /* ifndef _LINUX_NVMEM_PROVIDER_H */

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 07/14] nvmem: core: add per-cell post processing
  2022-08-25 21:44 ` [PATCH v1 07/14] nvmem: core: add per-cell post processing Michael Walle
@ 2022-08-30 13:37   ` Srinivas Kandagatla
  2022-08-30 14:20     ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Srinivas Kandagatla @ 2022-08-30 13:37 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum



On 25/08/2022 22:44, Michael Walle wrote:
> Instead of relying on the name the consumer is using for the cell, like
> it is done for the nvmem .cell_post_process configuration parameter,
> provide a per-cell post processing hook. This can then be populated by
> the NVMEM provider (or the NVMEM layout) when adding the cell.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>   drivers/nvmem/core.c           | 16 ++++++++++++++++
>   include/linux/nvmem-consumer.h |  5 +++++
>   2 files changed, 21 insertions(+)
> 
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 5357fc378700..cbfbe6264e6c 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -52,6 +52,7 @@ struct nvmem_cell_entry {
>   	int			bytes;
>   	int			bit_offset;
>   	int			nbits;
> +	nvmem_cell_post_process_t post_process;


two post_processing callbacks for cells is confusing tbh, we could 
totally move to use of cell->post_process.

one idea is to point cell->post_process to nvmem->cell_post_process 
during cell creation time which should clean this up a bit.

Other option is to move to using layouts for every thing.

prefixing post_process with read should also make it explicit that this 
callback is very specific to reads only.


>   	struct device_node	*np;
>   	struct nvmem_device	*nvmem;
>   	struct list_head	node;
> @@ -468,6 +469,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
>   	cell->offset = info->offset;
>   	cell->bytes = info->bytes;
>   	cell->name = info->name;
> +	cell->post_process = info->post_process;
>   
>   	cell->bit_offset = info->bit_offset;
>   	cell->nbits = info->nbits;
> @@ -1500,6 +1502,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
>   	if (cell->bit_offset || cell->nbits)
>   		nvmem_shift_read_buffer_in_place(cell, buf);
>   
> +	if (cell->post_process) {
> +		rc = cell->post_process(nvmem->priv, id, index,
> +					cell->offset, buf, cell->bytes);
> +		if (rc)
> +			return rc;
> +	}
> +
>   	if (nvmem->cell_post_process) {
>   		rc = nvmem->cell_post_process(nvmem->priv, id, index,
>   					      cell->offset, buf, cell->bytes);
> @@ -1608,6 +1617,13 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si
>   	    (cell->bit_offset == 0 && len != cell->bytes))
>   		return -EINVAL;
>   
> +	/*
> +	 * Any cells which have a post_process hook are read-only because we
> +	 * cannot reverse the operation and it might affect other cells, too.
> +	 */
> +	if (cell->post_process)
> +		return -EINVAL;

Post process was always implicitly for reads only, this check should 
also tie the loose ends of cell_post_processing callback.


--srini
> +
>   	if (cell->bit_offset || cell->nbits) {
>   		buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
>   		if (IS_ERR(buf))
> diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h
> index 980f9c9ac0bc..761b8ef78adc 100644
> --- a/include/linux/nvmem-consumer.h
> +++ b/include/linux/nvmem-consumer.h
> @@ -19,6 +19,10 @@ struct device_node;
>   struct nvmem_cell;
>   struct nvmem_device;
>   
> +/* duplicated from nvmem-provider.h */
> +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index,
> +					 unsigned int offset, void *buf, size_t bytes);
> +
>   struct nvmem_cell_info {
>   	const char		*name;
>   	unsigned int		offset;
> @@ -26,6 +30,7 @@ struct nvmem_cell_info {
>   	unsigned int		bit_offset;
>   	unsigned int		nbits;
>   	struct device_node	*np;
> +	nvmem_cell_post_process_t post_process;
>   };
>   
>   /**

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts
  2022-08-29  8:22   ` Michael Walle
@ 2022-08-30 13:37     ` Srinivas Kandagatla
  0 siblings, 0 replies; 49+ messages in thread
From: Srinivas Kandagatla @ 2022-08-30 13:37 UTC (permalink / raw)
  To: Michael Walle, Rafał Miłecki
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

Thanks Michael for the work.

On 29/08/2022 09:22, Michael Walle wrote:
> 
>> One thing I believe you need to handle is replacing "cell_post_process"
>> callback with your layout thing.
>>
>> I find it confusing to have
>> 1. cell_post_process() CB at NVMEM device level
>> 2. post_process() CB at NVMEM cell level
> 
> What is wrong with having a callback at both levels?

we should converge this tbh, its more than one code paths to deal with 
similar usecases.

I have put down some thoughts in "[PATCH v1 06/14] nvmem: core: 
introduce NVMEM layouts" and "[PATCH v1 07/14] nvmem: core: add per-cell 
post processing" review.


--srini
> 
> Granted, in this particular case (it is just used at one place), I still
> think that it is the wrong approach to add this transformation in the
> driver (in this particular case). The driver is supposed to give you
> access to the SoC's fuse box, but it will magically change the content
> of a cell if the nvmem consumer named this cell "mac-address" (which
> you also found confusing the last time and I do too!).
> 
> The driver itself doesn't add any cells on its own, so I cannot register
> a .post_process hook there. Therefore, you'd need that post_process hook
> on every cell, which is equivalent to have a post_process hook at
> device level.
> 
> Unless you have a better idea. I'll leave that up to NXP to fix that (or
> leave it like that).
> 
> -michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 07/14] nvmem: core: add per-cell post processing
  2022-08-30 13:37   ` Srinivas Kandagatla
@ 2022-08-30 14:20     ` Michael Walle
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-30 14:20 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Hi,

Am 2022-08-30 15:37, schrieb Srinivas Kandagatla:
> On 25/08/2022 22:44, Michael Walle wrote:
>> Instead of relying on the name the consumer is using for the cell, 
>> like
>> it is done for the nvmem .cell_post_process configuration parameter,
>> provide a per-cell post processing hook. This can then be populated by
>> the NVMEM provider (or the NVMEM layout) when adding the cell.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>   drivers/nvmem/core.c           | 16 ++++++++++++++++
>>   include/linux/nvmem-consumer.h |  5 +++++
>>   2 files changed, 21 insertions(+)
>> 
>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>> index 5357fc378700..cbfbe6264e6c 100644
>> --- a/drivers/nvmem/core.c
>> +++ b/drivers/nvmem/core.c
>> @@ -52,6 +52,7 @@ struct nvmem_cell_entry {
>>   	int			bytes;
>>   	int			bit_offset;
>>   	int			nbits;
>> +	nvmem_cell_post_process_t post_process;
> 
> 
> two post_processing callbacks for cells is confusing tbh, we could
> totally move to use of cell->post_process.
> 
> one idea is to point cell->post_process to nvmem->cell_post_process
> during cell creation time which should clean this up a bit.

You'll then trigger the read-only check below for all the cells
if nvmem->cell_post_process is set.

> Other option is to move to using layouts for every thing.

As mentioned in a previous reply, I can't see how it could be
achieved. The problem here is that:
  (1) the layout isn't creating the cells, the OF parser is
  (2) even if we would create the cells, we wouldn't know
      which cell needs the post_process. So we are back to
      the situation above, were we have to add it to all
      the cells, making them read-only. [We depend on the
      name of the nvmem-consumer to apply the hook.

> prefixing post_process with read should also make it explicit that
> this callback is very specific to reads only.

good idea.

-michael

>>   	struct device_node	*np;
>>   	struct nvmem_device	*nvmem;
>>   	struct list_head	node;
>> @@ -468,6 +469,7 @@ static int 
>> nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
>>   	cell->offset = info->offset;
>>   	cell->bytes = info->bytes;
>>   	cell->name = info->name;
>> +	cell->post_process = info->post_process;
>>     	cell->bit_offset = info->bit_offset;
>>   	cell->nbits = info->nbits;
>> @@ -1500,6 +1502,13 @@ static int __nvmem_cell_read(struct 
>> nvmem_device *nvmem,
>>   	if (cell->bit_offset || cell->nbits)
>>   		nvmem_shift_read_buffer_in_place(cell, buf);
>>   +	if (cell->post_process) {
>> +		rc = cell->post_process(nvmem->priv, id, index,
>> +					cell->offset, buf, cell->bytes);
>> +		if (rc)
>> +			return rc;
>> +	}
>> +
>>   	if (nvmem->cell_post_process) {
>>   		rc = nvmem->cell_post_process(nvmem->priv, id, index,
>>   					      cell->offset, buf, cell->bytes);
>> @@ -1608,6 +1617,13 @@ static int __nvmem_cell_entry_write(struct 
>> nvmem_cell_entry *cell, void *buf, si
>>   	    (cell->bit_offset == 0 && len != cell->bytes))
>>   		return -EINVAL;
>>   +	/*
>> +	 * Any cells which have a post_process hook are read-only because we
>> +	 * cannot reverse the operation and it might affect other cells, 
>> too.
>> +	 */
>> +	if (cell->post_process)
>> +		return -EINVAL;
> 
> Post process was always implicitly for reads only, this check should
> also tie the loose ends of cell_post_processing callback.
> 
> 
> --srini
>> +
>>   	if (cell->bit_offset || cell->nbits) {
>>   		buf = nvmem_cell_prepare_write_buffer(cell, buf, len);
>>   		if (IS_ERR(buf))
>> diff --git a/include/linux/nvmem-consumer.h 
>> b/include/linux/nvmem-consumer.h
>> index 980f9c9ac0bc..761b8ef78adc 100644
>> --- a/include/linux/nvmem-consumer.h
>> +++ b/include/linux/nvmem-consumer.h
>> @@ -19,6 +19,10 @@ struct device_node;
>>   struct nvmem_cell;
>>   struct nvmem_device;
>>   +/* duplicated from nvmem-provider.h */
>> +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, 
>> int index,
>> +					 unsigned int offset, void *buf, size_t bytes);
>> +
>>   struct nvmem_cell_info {
>>   	const char		*name;
>>   	unsigned int		offset;
>> @@ -26,6 +30,7 @@ struct nvmem_cell_info {
>>   	unsigned int		bit_offset;
>>   	unsigned int		nbits;
>>   	struct device_node	*np;
>> +	nvmem_cell_post_process_t post_process;
>>   };
>>     /**

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-30 13:36   ` Srinivas Kandagatla
@ 2022-08-30 14:24     ` Michael Walle
  2022-08-30 14:43       ` Srinivas Kandagatla
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-30 14:24 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-30 15:36, schrieb Srinivas Kandagatla:
> On 25/08/2022 22:44, Michael Walle wrote:
>> NVMEM layouts are used to generate NVMEM cells during runtime. Think 
>> of
>> an EEPROM with a well-defined conent. For now, the content can be
>> described by a device tree or a board file. But this only works if the
>> offsets and lengths are static and don't change. One could also argue
>> that putting the layout of the EEPROM in the device tree is the wrong
>> place. Instead, the device tree should just have a specific compatible
>> string.
>> 
>> Right now there are two use cases:
>>   (1) The NVMEM cell needs special processing. E.g. if it only 
>> specifies
>>       a base MAC address offset and you need to add an offset, or it
>>       needs to parse a MAC from ASCII format or some proprietary 
>> format.
>>       (Post processing of cells is added in a later commit).
>>   (2) u-boot environment parsing. The cells don't have a particular
>>       offset but it needs parsing the content to determine the offsets
>>       and length.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>   drivers/nvmem/Kconfig          |  2 ++
>>   drivers/nvmem/Makefile         |  1 +
>>   drivers/nvmem/core.c           | 57 
>> ++++++++++++++++++++++++++++++++++
>>   drivers/nvmem/layouts/Kconfig  |  5 +++
>>   drivers/nvmem/layouts/Makefile |  4 +++
>>   include/linux/nvmem-provider.h | 38 +++++++++++++++++++++++
>>   6 files changed, 107 insertions(+)
>>   create mode 100644 drivers/nvmem/layouts/Kconfig
>>   create mode 100644 drivers/nvmem/layouts/Makefile
> 
> update to ./Documentation/driver-api/nvmem.rst would help others.

Sure. Didn't know about that one.

>> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
>> index bab8a29c9861..1416837b107b 100644
>> --- a/drivers/nvmem/Kconfig
>> +++ b/drivers/nvmem/Kconfig
>> @@ -357,4 +357,6 @@ config NVMEM_U_BOOT_ENV
>>     	  If compiled as module it will be called nvmem_u-boot-env.
>>   +source "drivers/nvmem/layouts/Kconfig"
>> +
>>   endif
>> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
>> index 399f9972d45b..cd5a5baa2f3a 100644
>> --- a/drivers/nvmem/Makefile
>> +++ b/drivers/nvmem/Makefile
>> @@ -5,6 +5,7 @@
>>     obj-$(CONFIG_NVMEM)		+= nvmem_core.o
>>   nvmem_core-y			:= core.o
>> +obj-y				+= layouts/
>>     # Devices
>>   obj-$(CONFIG_NVMEM_BCM_OCOTP)	+= nvmem-bcm-ocotp.o
>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>> index 3dfd149374a8..5357fc378700 100644
>> --- a/drivers/nvmem/core.c
>> +++ b/drivers/nvmem/core.c
>> @@ -74,6 +74,9 @@ static LIST_HEAD(nvmem_lookup_list);
>>     static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
>>   +static DEFINE_SPINLOCK(nvmem_layout_lock);
>> +static LIST_HEAD(nvmem_layouts);
>> +
>>   static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int 
>> offset,
>>   			    void *val, size_t bytes)
>>   {
>> @@ -744,6 +747,56 @@ static int nvmem_add_cells_from_of(struct 
>> nvmem_device *nvmem)
>>   	return 0;
>>   }
>>   +int nvmem_register_layout(struct nvmem_layout *layout)
>> +{
>> +	spin_lock(&nvmem_layout_lock);
>> +	list_add(&layout->node, &nvmem_layouts);
>> +	spin_unlock(&nvmem_layout_lock);
>> +
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(nvmem_register_layout);
> 
> we should provide nvmem_unregister_layout too, so that providers can
> add them if they can in there respective drivers.

Actually, that was the idea; that you can have layouts outside of 
layouts/.
I also had a nvmem_unregister_layout() but removed it because it was 
dead
code. Will re-add it again.

>> +
>> +static struct nvmem_layout *nvmem_get_compatible_layout(struct 
>> device_node *np)
>> +{
>> +	struct nvmem_layout *p, *ret = NULL;
>> +
>> +	spin_lock(&nvmem_layout_lock);
>> +
>> +	list_for_each_entry(p, &nvmem_layouts, node) {
>> +		if (of_match_node(p->of_match_table, np)) {
>> +			ret = p;
>> +			break;
>> +		}
>> +	}
>> +
>> +	spin_unlock(&nvmem_layout_lock);
>> +
>> +	return ret;
>> +}
>> +
>> +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem)
>> +{
>> +	struct nvmem_layout *layout;
>> +
>> +	layout = nvmem_get_compatible_layout(nvmem->dev.of_node);
>> +	if (layout)
>> +		layout->add_cells(&nvmem->dev, nvmem, layout);
> 
> access to add_cells can crash hear as we did not check it before
> adding in to list.
> Or
> we could relax add_cells callback for usecases like imx-octop.

good catch, will use layout && layout->add_cells.

>> +
>> +	return 0;
>> +}
>> +
>> +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
>> +					struct nvmem_layout *layout)
>> +{
>> +	const struct of_device_id *match;
>> +
>> +	match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
>> +
>> +	return match ? match->data : NULL;
>> +}
>> +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data);
>> +
>>   /**
>>    * nvmem_register() - Register a nvmem device for given 
>> nvmem_config.
>>    * Also creates a binary entry in 
>> /sys/bus/nvmem/devices/dev-name/nvmem
>> @@ -872,6 +925,10 @@ struct nvmem_device *nvmem_register(const struct 
>> nvmem_config *config)
>>   	if (rval)
>>   		goto err_remove_cells;
>>   +	rval = nvmem_add_cells_from_layout(nvmem);
>> +	if (rval)
>> +		goto err_remove_cells;
>> +
>>   	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
>>     	return nvmem;
>> diff --git a/drivers/nvmem/layouts/Kconfig 
>> b/drivers/nvmem/layouts/Kconfig
>> new file mode 100644
>> index 000000000000..9ad3911d1605
>> --- /dev/null
>> +++ b/drivers/nvmem/layouts/Kconfig
>> @@ -0,0 +1,5 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +
>> +menu "Layout Types"
>> +
>> +endmenu
>> diff --git a/drivers/nvmem/layouts/Makefile 
>> b/drivers/nvmem/layouts/Makefile
>> new file mode 100644
>> index 000000000000..6fdb3c60a4fa
>> --- /dev/null
>> +++ b/drivers/nvmem/layouts/Makefile
>> @@ -0,0 +1,4 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +#
>> +# Makefile for nvmem layouts.
>> +#
>> diff --git a/include/linux/nvmem-provider.h 
>> b/include/linux/nvmem-provider.h
>> index e710404959e7..323685841e9f 100644
>> --- a/include/linux/nvmem-provider.h
>> +++ b/include/linux/nvmem-provider.h
>> @@ -127,6 +127,28 @@ struct nvmem_cell_table {
>>   	struct list_head	node;
>>   };
>>   +/**
>> + * struct nvmem_layout - NVMEM layout definitions
>> + *
>> + * @name:		Layout name.
>> + * @of_match_table:	Open firmware match table.
>> + * @add_cells:		Will be called if a nvmem device is found which
>> + *			has this layout. The function will add layout
>> + *			specific cells with nvmem_add_one_cell().
>> + * @node:		List node.
>> + *
>> + * A nvmem device can hold a well defined structure which can just be
>> + * evaluated during runtime. For example a TLV list, or a list of 
>> "name=val"
>> + * pairs. A nvmem layout can parse the nvmem device and add 
>> appropriate
>> + * cells.
>> + */
>> +struct nvmem_layout {
>> +	const char *name;
>> +	const struct of_device_id *of_match_table;
> 
> looking at this, I think its doable to convert the existing
> cell_post_process callback to layouts by adding a layout specific
> callback here.

can you elaborate on that?

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-30 14:24     ` Michael Walle
@ 2022-08-30 14:43       ` Srinivas Kandagatla
  2022-08-30 15:02         ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Srinivas Kandagatla @ 2022-08-30 14:43 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum



On 30/08/2022 15:24, Michael Walle wrote:
> Am 2022-08-30 15:36, schrieb Srinivas Kandagatla:
>> On 25/08/2022 22:44, Michael Walle wrote:
>>> NVMEM layouts are used to generate NVMEM cells during runtime. Think of
>>> an EEPROM with a well-defined conent. For now, the content can be
>>> described by a device tree or a board file. But this only works if the
>>> offsets and lengths are static and don't change. One could also argue
>>> that putting the layout of the EEPROM in the device tree is the wrong
>>> place. Instead, the device tree should just have a specific compatible
>>> string.
>>>
>>> Right now there are two use cases:
>>>   (1) The NVMEM cell needs special processing. E.g. if it only specifies
>>>       a base MAC address offset and you need to add an offset, or it
>>>       needs to parse a MAC from ASCII format or some proprietary format.
>>>       (Post processing of cells is added in a later commit).
>>>   (2) u-boot environment parsing. The cells don't have a particular
>>>       offset but it needs parsing the content to determine the offsets
>>>       and length.
>>>
>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>> ---
>>>   drivers/nvmem/Kconfig          |  2 ++
>>>   drivers/nvmem/Makefile         |  1 +
>>>   drivers/nvmem/core.c           | 57 ++++++++++++++++++++++++++++++++++
>>>   drivers/nvmem/layouts/Kconfig  |  5 +++
>>>   drivers/nvmem/layouts/Makefile |  4 +++
>>>   include/linux/nvmem-provider.h | 38 +++++++++++++++++++++++
>>>   6 files changed, 107 insertions(+)
>>>   create mode 100644 drivers/nvmem/layouts/Kconfig
>>>   create mode 100644 drivers/nvmem/layouts/Makefile
>>
>> update to ./Documentation/driver-api/nvmem.rst would help others.
> 
> Sure. Didn't know about that one.
> 
>>> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig
>>> index bab8a29c9861..1416837b107b 100644
>>> --- a/drivers/nvmem/Kconfig
>>> +++ b/drivers/nvmem/Kconfig
>>> @@ -357,4 +357,6 @@ config NVMEM_U_BOOT_ENV
>>>           If compiled as module it will be called nvmem_u-boot-env.
>>>   +source "drivers/nvmem/layouts/Kconfig"
>>> +
>>>   endif
>>> diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile
>>> index 399f9972d45b..cd5a5baa2f3a 100644
>>> --- a/drivers/nvmem/Makefile
>>> +++ b/drivers/nvmem/Makefile
>>> @@ -5,6 +5,7 @@
>>>     obj-$(CONFIG_NVMEM)        += nvmem_core.o
>>>   nvmem_core-y            := core.o
>>> +obj-y                += layouts/
>>>     # Devices
>>>   obj-$(CONFIG_NVMEM_BCM_OCOTP)    += nvmem-bcm-ocotp.o
>>> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
>>> index 3dfd149374a8..5357fc378700 100644
>>> --- a/drivers/nvmem/core.c
>>> +++ b/drivers/nvmem/core.c
>>> @@ -74,6 +74,9 @@ static LIST_HEAD(nvmem_lookup_list);
>>>     static BLOCKING_NOTIFIER_HEAD(nvmem_notifier);
>>>   +static DEFINE_SPINLOCK(nvmem_layout_lock);
>>> +static LIST_HEAD(nvmem_layouts);
>>> +
>>>   static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned 
>>> int offset,
>>>                   void *val, size_t bytes)
>>>   {
>>> @@ -744,6 +747,56 @@ static int nvmem_add_cells_from_of(struct 
>>> nvmem_device *nvmem)
>>>       return 0;
>>>   }
>>>   +int nvmem_register_layout(struct nvmem_layout *layout)
>>> +{
>>> +    spin_lock(&nvmem_layout_lock);
>>> +    list_add(&layout->node, &nvmem_layouts);
>>> +    spin_unlock(&nvmem_layout_lock);
>>> +
>>> +    return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(nvmem_register_layout);
>>
>> we should provide nvmem_unregister_layout too, so that providers can
>> add them if they can in there respective drivers.
> 
> Actually, that was the idea; that you can have layouts outside of layouts/.
> I also had a nvmem_unregister_layout() but removed it because it was dead
> code. Will re-add it again.
> 
>>> +
>>> +static struct nvmem_layout *nvmem_get_compatible_layout(struct 
>>> device_node *np)
>>> +{
>>> +    struct nvmem_layout *p, *ret = NULL;
>>> +
>>> +    spin_lock(&nvmem_layout_lock);
>>> +
>>> +    list_for_each_entry(p, &nvmem_layouts, node) {
>>> +        if (of_match_node(p->of_match_table, np)) {
>>> +            ret = p;
>>> +            break;
>>> +        }
>>> +    }
>>> +
>>> +    spin_unlock(&nvmem_layout_lock);
>>> +
>>> +    return ret;
>>> +}
>>> +
>>> +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem)
>>> +{
>>> +    struct nvmem_layout *layout;
>>> +
>>> +    layout = nvmem_get_compatible_layout(nvmem->dev.of_node);
>>> +    if (layout)
>>> +        layout->add_cells(&nvmem->dev, nvmem, layout);
>>
>> access to add_cells can crash hear as we did not check it before
>> adding in to list.
>> Or
>> we could relax add_cells callback for usecases like imx-octop.
> 
> good catch, will use layout && layout->add_cells.
> 
>>> +
>>> +    return 0;
>>> +}
>>> +
>>> +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem,
>>> +                    struct nvmem_layout *layout)
>>> +{
>>> +    const struct of_device_id *match;
>>> +
>>> +    match = of_match_node(layout->of_match_table, nvmem->dev.of_node);
>>> +
>>> +    return match ? match->data : NULL;
>>> +}
>>> +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data);
>>> +
>>>   /**
>>>    * nvmem_register() - Register a nvmem device for given nvmem_config.
>>>    * Also creates a binary entry in 
>>> /sys/bus/nvmem/devices/dev-name/nvmem
>>> @@ -872,6 +925,10 @@ struct nvmem_device *nvmem_register(const struct 
>>> nvmem_config *config)
>>>       if (rval)
>>>           goto err_remove_cells;
>>>   +    rval = nvmem_add_cells_from_layout(nvmem);
>>> +    if (rval)
>>> +        goto err_remove_cells;
>>> +
>>>       blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
>>>         return nvmem;
>>> diff --git a/drivers/nvmem/layouts/Kconfig 
>>> b/drivers/nvmem/layouts/Kconfig
>>> new file mode 100644
>>> index 000000000000..9ad3911d1605
>>> --- /dev/null
>>> +++ b/drivers/nvmem/layouts/Kconfig
>>> @@ -0,0 +1,5 @@
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +
>>> +menu "Layout Types"
>>> +
>>> +endmenu
>>> diff --git a/drivers/nvmem/layouts/Makefile 
>>> b/drivers/nvmem/layouts/Makefile
>>> new file mode 100644
>>> index 000000000000..6fdb3c60a4fa
>>> --- /dev/null
>>> +++ b/drivers/nvmem/layouts/Makefile
>>> @@ -0,0 +1,4 @@
>>> +# SPDX-License-Identifier: GPL-2.0
>>> +#
>>> +# Makefile for nvmem layouts.
>>> +#
>>> diff --git a/include/linux/nvmem-provider.h 
>>> b/include/linux/nvmem-provider.h
>>> index e710404959e7..323685841e9f 100644
>>> --- a/include/linux/nvmem-provider.h
>>> +++ b/include/linux/nvmem-provider.h
>>> @@ -127,6 +127,28 @@ struct nvmem_cell_table {
>>>       struct list_head    node;
>>>   };
>>>   +/**
>>> + * struct nvmem_layout - NVMEM layout definitions
>>> + *
>>> + * @name:        Layout name.
>>> + * @of_match_table:    Open firmware match table.
>>> + * @add_cells:        Will be called if a nvmem device is found which
>>> + *            has this layout. The function will add layout
>>> + *            specific cells with nvmem_add_one_cell().
>>> + * @node:        List node.
>>> + *
>>> + * A nvmem device can hold a well defined structure which can just be
>>> + * evaluated during runtime. For example a TLV list, or a list of 
>>> "name=val"
>>> + * pairs. A nvmem layout can parse the nvmem device and add appropriate
>>> + * cells.
>>> + */
>>> +struct nvmem_layout {
>>> +    const char *name;
>>> +    const struct of_device_id *of_match_table;
>>
>> looking at this, I think its doable to convert the existing
>> cell_post_process callback to layouts by adding a layout specific
>> callback here.
> 
> can you elaborate on that?

If we relax add_cells + add nvmem_unregister_layout() and update struct 
nvmem_layout to include post_process callback like

struct nvmem_layout {
	const char *name;
	const struct of_device_id *of_match_table;
	int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout *layout);
	struct list_head node;
	/* default callback for every cell */
	nvmem_cell_post_process_t post_process;
};

then we can move imx-ocotp to this layout style without add_cell 
callback, and finally get rid of cell_process_callback from both 
nvmem_config and nvmem_device.

If layout specific post_process callback is available and cell does not 
have a callback set then we can can be either updated cell post_process 
callback with this one or invoke layout specific callback directly.

does that make sense?


--srini


> 
> -michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-30 14:43       ` Srinivas Kandagatla
@ 2022-08-30 15:02         ` Michael Walle
  2022-08-30 15:23           ` Srinivas Kandagatla
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-30 15:02 UTC (permalink / raw)
  To: Srinivas Kandagatla
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-30 16:43, schrieb Srinivas Kandagatla:

>>>> diff --git a/drivers/nvmem/layouts/Makefile 
>>>> b/drivers/nvmem/layouts/Makefile
>>>> new file mode 100644
>>>> index 000000000000..6fdb3c60a4fa
>>>> --- /dev/null
>>>> +++ b/drivers/nvmem/layouts/Makefile
>>>> @@ -0,0 +1,4 @@
>>>> +# SPDX-License-Identifier: GPL-2.0
>>>> +#
>>>> +# Makefile for nvmem layouts.
>>>> +#
>>>> diff --git a/include/linux/nvmem-provider.h 
>>>> b/include/linux/nvmem-provider.h
>>>> index e710404959e7..323685841e9f 100644
>>>> --- a/include/linux/nvmem-provider.h
>>>> +++ b/include/linux/nvmem-provider.h
>>>> @@ -127,6 +127,28 @@ struct nvmem_cell_table {
>>>>       struct list_head    node;
>>>>   };
>>>>   +/**
>>>> + * struct nvmem_layout - NVMEM layout definitions
>>>> + *
>>>> + * @name:        Layout name.
>>>> + * @of_match_table:    Open firmware match table.
>>>> + * @add_cells:        Will be called if a nvmem device is found 
>>>> which
>>>> + *            has this layout. The function will add layout
>>>> + *            specific cells with nvmem_add_one_cell().
>>>> + * @node:        List node.
>>>> + *
>>>> + * A nvmem device can hold a well defined structure which can just 
>>>> be
>>>> + * evaluated during runtime. For example a TLV list, or a list of 
>>>> "name=val"
>>>> + * pairs. A nvmem layout can parse the nvmem device and add 
>>>> appropriate
>>>> + * cells.
>>>> + */
>>>> +struct nvmem_layout {
>>>> +    const char *name;
>>>> +    const struct of_device_id *of_match_table;
>>> 
>>> looking at this, I think its doable to convert the existing
>>> cell_post_process callback to layouts by adding a layout specific
>>> callback here.
>> 
>> can you elaborate on that?
> 
> If we relax add_cells + add nvmem_unregister_layout() and update
> struct nvmem_layout to include post_process callback like
> 
> struct nvmem_layout {
> 	const char *name;
> 	const struct of_device_id *of_match_table;
> 	int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout 
> *layout);
> 	struct list_head node;
> 	/* default callback for every cell */
> 	nvmem_cell_post_process_t post_process;
> };
> 
> then we can move imx-ocotp to this layout style without add_cell
> callback, and finally get rid of cell_process_callback from both
> nvmem_config and nvmem_device.
> 
> If layout specific post_process callback is available and cell does
> not have a callback set then we can can be either updated cell
> post_process callback with this one or invoke layout specific callback
> directly.
> 
> does that make sense?

Yes I get what you mean. BUT I'm not so sure; it mixes different
things together. Layouts will add cells, analogue to
nvmem_add_cells_from_of() or nvmem_add_cells_from_table(). With
the hook above, the layout mechanism is abused to add post
processing to cells added by other means.

What is then the difference to the driver having that "global"
post process hook?

The correct place to add the per-cell hook in this case would be
nvmem_add_cells_from_of().

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts
  2022-08-30 15:02         ` Michael Walle
@ 2022-08-30 15:23           ` Srinivas Kandagatla
  0 siblings, 0 replies; 49+ messages in thread
From: Srinivas Kandagatla @ 2022-08-30 15:23 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum



On 30/08/2022 16:02, Michael Walle wrote:
> Am 2022-08-30 16:43, schrieb Srinivas Kandagatla:
> 
>>>>> diff --git a/drivers/nvmem/layouts/Makefile 
>>>>> b/drivers/nvmem/layouts/Makefile
>>>>> new file mode 100644
>>>>> index 000000000000..6fdb3c60a4fa
>>>>> --- /dev/null
>>>>> +++ b/drivers/nvmem/layouts/Makefile
>>>>> @@ -0,0 +1,4 @@
>>>>> +# SPDX-License-Identifier: GPL-2.0
>>>>> +#
>>>>> +# Makefile for nvmem layouts.
>>>>> +#
>>>>> diff --git a/include/linux/nvmem-provider.h 
>>>>> b/include/linux/nvmem-provider.h
>>>>> index e710404959e7..323685841e9f 100644
>>>>> --- a/include/linux/nvmem-provider.h
>>>>> +++ b/include/linux/nvmem-provider.h
>>>>> @@ -127,6 +127,28 @@ struct nvmem_cell_table {
>>>>>       struct list_head    node;
>>>>>   };
>>>>>   +/**
>>>>> + * struct nvmem_layout - NVMEM layout definitions
>>>>> + *
>>>>> + * @name:        Layout name.
>>>>> + * @of_match_table:    Open firmware match table.
>>>>> + * @add_cells:        Will be called if a nvmem device is found which
>>>>> + *            has this layout. The function will add layout
>>>>> + *            specific cells with nvmem_add_one_cell().
>>>>> + * @node:        List node.
>>>>> + *
>>>>> + * A nvmem device can hold a well defined structure which can just be
>>>>> + * evaluated during runtime. For example a TLV list, or a list of 
>>>>> "name=val"
>>>>> + * pairs. A nvmem layout can parse the nvmem device and add 
>>>>> appropriate
>>>>> + * cells.
>>>>> + */
>>>>> +struct nvmem_layout {
>>>>> +    const char *name;
>>>>> +    const struct of_device_id *of_match_table;
>>>>
>>>> looking at this, I think its doable to convert the existing
>>>> cell_post_process callback to layouts by adding a layout specific
>>>> callback here.
>>>
>>> can you elaborate on that?
>>
>> If we relax add_cells + add nvmem_unregister_layout() and update
>> struct nvmem_layout to include post_process callback like
>>
>> struct nvmem_layout {
>>     const char *name;
>>     const struct of_device_id *of_match_table;
>>     int (*add_cells)(struct nvmem_device *nvmem, struct nvmem_layout 
>> *layout);
>>     struct list_head node;
>>     /* default callback for every cell */
>>     nvmem_cell_post_process_t post_process;
>> };
>>
>> then we can move imx-ocotp to this layout style without add_cell
>> callback, and finally get rid of cell_process_callback from both
>> nvmem_config and nvmem_device.
>>
>> If layout specific post_process callback is available and cell does
>> not have a callback set then we can can be either updated cell
>> post_process callback with this one or invoke layout specific callback
>> directly.
>>
>> does that make sense?
> 
> Yes I get what you mean. BUT I'm not so sure; it mixes different
> things together. Layouts will add cells, analogue to
> nvmem_add_cells_from_of() or nvmem_add_cells_from_table(). With
> the hook above, the layout mechanism is abused to add post
> processing to cells added by other means.

We are still defining what layout exactly mean w.r.t to nvmem :-)

> 

There are two aspects to this as nvmem core is concerned

1> parse and add cells based on some provider specific algo/stucture.
2> post process cell data before user can see it.

In some cases we need 1 and 2 while in other cases we just need 1 or 2.

Having an unified interface would help with maintenance and removing 
duplication.

> What is then the difference to the driver having that "global"
> post process hook?

w.r.t post processing there should be no difference.

cell can have no post-processing or a default post processing or a 
specific one depending on its configuration.

> 
> The correct place to add the per-cell hook in this case would be
> nvmem_add_cells_from_of().

yes, that is the place where it should go. we have to work on the 
details but if provider is associated with a layout then this should be 
doable.


--srini
> 
> -michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-25 21:44 ` [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string Michael Walle
@ 2022-08-31  7:37   ` Krzysztof Kozlowski
  2022-08-31  7:48     ` Michael Walle
  2022-08-31 21:48   ` Rob Herring
  1 sibling, 1 reply; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31  7:37 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, Rafał Miłecki,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 26/08/2022 00:44, Michael Walle wrote:
> The "user-otp" and "factory-otp" compatible string just depicts a
> generic NVMEM device. But an actual device tree node might as well
> contain a more specific compatible string. Make it possible to add
> more specific binding elsewere and just match part of the compatibles

typo: elsewhere

> here.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/mtd/mtd.yaml b/Documentation/devicetree/bindings/mtd/mtd.yaml
> index 376b679cfc70..0291e439b6a6 100644
> --- a/Documentation/devicetree/bindings/mtd/mtd.yaml
> +++ b/Documentation/devicetree/bindings/mtd/mtd.yaml
> @@ -33,9 +33,10 @@ patternProperties:
>  
>      properties:
>        compatible:
> -        enum:
> -          - user-otp
> -          - factory-otp
> +        contains:
> +          enum:
> +            - user-otp
> +            - factory-otp

This does not work in the "elsewhere" place. You need to use similar
approach as we do for syscon or primecell.

>  
>      required:
>        - compatible


Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-25 21:44 ` [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout Michael Walle
  2022-08-26 16:05   ` Rob Herring
@ 2022-08-31  7:45   ` Krzysztof Kozlowski
  2022-08-31  8:17     ` Michael Walle
  1 sibling, 1 reply; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31  7:45 UTC (permalink / raw)
  To: Michael Walle, Miquel Raynal, Richard Weinberger,
	Vignesh Raghavendra, Rob Herring, Krzysztof Kozlowski,
	Srinivas Kandagatla, Shawn Guo, Li Yang, Rafał Miłecki,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 26/08/2022 00:44, Michael Walle wrote:
> Add a schema for the NVMEM layout on Kontron's sl28 boards.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  .../nvmem/layouts/kontron,sl28-vpd.yaml       | 52 +++++++++++++++++++
>  1 file changed, 52 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
> 
> diff --git a/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
> new file mode 100644
> index 000000000000..e4bc2d9182db
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
> @@ -0,0 +1,52 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/nvmem/layouts/kontron,sl28-vpd.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: NVMEM layout of the Kontron SMARC-sAL28 vital product data
> +
> +maintainers:
> +  - Michael Walle <michael@walle.cc>
> +
> +description:
> +  The vital product data (VPD) of the sl28 boards contains a serial
> +  number and a base MAC address. The actual MAC addresses for the
> +  on-board ethernet devices are derived from this base MAC address by
> +  adding an offset.
> +
> +properties:
> +  compatible:
> +    items:
> +      - const: kontron,sl28-vpd
> +      - const: user-otp
> +
> +  serial-number:
> +    type: object

You should define the contents of this object. I would expect this to be
uint32 or string. I think you also need description, as this is not
really standard field.

> +
> +  base-mac-address:

Fields should be rather described here, not in top-level description.

> +    type: object

On this level:
    additionalProperties: false

> +
> +    properties:
> +      "#nvmem-cell-cells":
> +        const: 1
> +

I also wonder why you do not have unit addresses. What if you want to
have two base MAC addresses?

> +required:
> +  - compatible

Other fields are I guess required? At least serial-number should be always?

> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +      otp-1 {

Messed up indentation (use 4 spaces). Generic node name "otp".

> +          compatible = "kontron,sl28-vpd", "user-otp";
> +
> +          serial_number: serial-number {

What's the point of the empty node?

> +          };
> +
> +          base_mac_address: base-mac-address {
> +              #nvmem-cell-cells = <1>;
> +          };
> +      };
> +
> +...


Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-31  7:37   ` Krzysztof Kozlowski
@ 2022-08-31  7:48     ` Michael Walle
  2022-08-31  7:55       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-31  7:48 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-31 09:37, schrieb Krzysztof Kozlowski:
> On 26/08/2022 00:44, Michael Walle wrote:
>> The "user-otp" and "factory-otp" compatible string just depicts a
>> generic NVMEM device. But an actual device tree node might as well
>> contain a more specific compatible string. Make it possible to add
>> more specific binding elsewere and just match part of the compatibles
> 
> typo: elsewhere
> 
>> here.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>> 
>> diff --git a/Documentation/devicetree/bindings/mtd/mtd.yaml 
>> b/Documentation/devicetree/bindings/mtd/mtd.yaml
>> index 376b679cfc70..0291e439b6a6 100644
>> --- a/Documentation/devicetree/bindings/mtd/mtd.yaml
>> +++ b/Documentation/devicetree/bindings/mtd/mtd.yaml
>> @@ -33,9 +33,10 @@ patternProperties:
>> 
>>      properties:
>>        compatible:
>> -        enum:
>> -          - user-otp
>> -          - factory-otp
>> +        contains:
>> +          enum:
>> +            - user-otp
>> +            - factory-otp
> 
> This does not work in the "elsewhere" place. You need to use similar
> approach as we do for syscon or primecell.

I'm a bit confused. Looking at
   Documentation/devicetree/bindings/arm/primecell.yaml
it is done in the same way as this binding.

Whereas, the syscon use a "select:" on top of it. I'm
pretty sure, I've tested it without the select and the
validator picked up the constraints.

Could you elaborate on what is wrong here? Select missing?

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts
  2022-08-28 15:05 ` [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Rafał Miłecki
  2022-08-29  8:22   ` Michael Walle
@ 2022-08-31  7:48   ` Krzysztof Kozlowski
  1 sibling, 0 replies; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31  7:48 UTC (permalink / raw)
  To: Rafał Miłecki, Michael Walle, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra, Rob Herring,
	Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo, Li Yang,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

On 28/08/2022 18:05, Rafał Miłecki wrote:
> On 25.08.2022 23:44, Michael Walle wrote:
>> This is now the third attempt to fetch the MAC addresses from the VPD
>> for the Kontron sl28 boards. Previous discussions can be found here:
>> https://lore.kernel.org/lkml/20211228142549.1275412-1-michael@walle.cc/
>>
>>
>> NVMEM cells are typically added by board code or by the devicetree. But
>> as the cells get more complex, there is (valid) push back from the
>> devicetree maintainers to not put that handling in the devicetree.
> 
> I dropped the ball waiting for Rob's reponse in the
> [PATCH 0/2] dt-bindings: nvmem: support describing cells
> https://lore.kernel.org/linux-arm-kernel/0b7b8f7ea6569f79524aea1a3d783665@walle.cc/T/
> 
> Before we go any further can we have a clear answer from Rob (or
> Krzysztof now too?):
> 
> 
> Is there any point in having bindings like:
> 
> compatible = "mac-address";
> 
> for NVMEM cells nodes? So systems (Linux, U-Boot) can handle them in a
> more generic way?

I think Rob is already in the subject, but I wonder how would that work
for U-Boot? You might have multiple cards, so how does this matching
would work? IOW, what problem would it solve comparing to existing
solution (alias to ethernet device with mac-address field)?

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-31  7:48     ` Michael Walle
@ 2022-08-31  7:55       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31  7:55 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On 31/08/2022 10:48, Michael Walle wrote:
> Am 2022-08-31 09:37, schrieb Krzysztof Kozlowski:
>> On 26/08/2022 00:44, Michael Walle wrote:
>>> The "user-otp" and "factory-otp" compatible string just depicts a
>>> generic NVMEM device. But an actual device tree node might as well
>>> contain a more specific compatible string. Make it possible to add
>>> more specific binding elsewere and just match part of the compatibles
>>
>> typo: elsewhere
>>
>>> here.
>>>
>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>> ---
>>>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
>>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/mtd/mtd.yaml 
>>> b/Documentation/devicetree/bindings/mtd/mtd.yaml
>>> index 376b679cfc70..0291e439b6a6 100644
>>> --- a/Documentation/devicetree/bindings/mtd/mtd.yaml
>>> +++ b/Documentation/devicetree/bindings/mtd/mtd.yaml
>>> @@ -33,9 +33,10 @@ patternProperties:
>>>
>>>      properties:
>>>        compatible:
>>> -        enum:
>>> -          - user-otp
>>> -          - factory-otp
>>> +        contains:
>>> +          enum:
>>> +            - user-otp
>>> +            - factory-otp
>>
>> This does not work in the "elsewhere" place. You need to use similar
>> approach as we do for syscon or primecell.
> 
> I'm a bit confused. Looking at
>    Documentation/devicetree/bindings/arm/primecell.yaml
> it is done in the same way as this binding.

Yes. primecell is like your mtd here. And how are other places with
primcell (like other places with user-otp) done?

> 
> Whereas, the syscon use a "select:" on top of it. I'm
> pretty sure, I've tested it without the select and the
> validator picked up the constraints.
> 
> Could you elaborate on what is wrong here? Select missing?

You got warning from Rob, so run tests. I think you will see the errors,
just like bot reported them.

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-31  7:45   ` Krzysztof Kozlowski
@ 2022-08-31  8:17     ` Michael Walle
  2022-08-31  9:24       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-31  8:17 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-31 09:45, schrieb Krzysztof Kozlowski:
> On 26/08/2022 00:44, Michael Walle wrote:
>> Add a schema for the NVMEM layout on Kontron's sl28 boards.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  .../nvmem/layouts/kontron,sl28-vpd.yaml       | 52 
>> +++++++++++++++++++
>>  1 file changed, 52 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>> 
>> diff --git 
>> a/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml 
>> b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>> new file mode 100644
>> index 000000000000..e4bc2d9182db
>> --- /dev/null
>> +++ 
>> b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>> @@ -0,0 +1,52 @@
>> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
>> +%YAML 1.2
>> +---
>> +$id: 
>> http://devicetree.org/schemas/nvmem/layouts/kontron,sl28-vpd.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: NVMEM layout of the Kontron SMARC-sAL28 vital product data
>> +
>> +maintainers:
>> +  - Michael Walle <michael@walle.cc>
>> +
>> +description:
>> +  The vital product data (VPD) of the sl28 boards contains a serial
>> +  number and a base MAC address. The actual MAC addresses for the
>> +  on-board ethernet devices are derived from this base MAC address by
>> +  adding an offset.
>> +
>> +properties:
>> +  compatible:
>> +    items:
>> +      - const: kontron,sl28-vpd
>> +      - const: user-otp
>> +
>> +  serial-number:
>> +    type: object
> 
> You should define the contents of this object. I would expect this to 
> be
> uint32 or string. I think you also need description, as this is not
> really standard field.

First thing, this binding isn't like the usual ones, so it might be
totally wrong.

What I'd like to achieve here is the following:

We have the nvmem-consumer dt binding where you can reference a
nvmem cell in a consumer node. Example:
   nvmem-cells = <&base_mac_address 5>;
   nvmem-cell-names = "mac-address";

On the other end of the link we have the nvmem-provider. The dt
bindings works well if that one has individual cell nodes, like
it is described in the nvmem.yaml binding. I.e. you can give the
cell a label and make a reference to it in the consumer just like
in the example above.

Now comes the catch: what if there is no actual description of the
cell in the device tree, but is is generated during runtime. How
can I get a label to it. Therefore, in this case, there is just
an empty node and the driver will associate it with the cell
created during runtime (see patch 10). It is not expected, that
is has any properties.

>> +
>> +  base-mac-address:
> 
> Fields should be rather described here, not in top-level description.
> 
>> +    type: object
> 
> On this level:
>     additionalProperties: false
> 
>> +
>> +    properties:
>> +      "#nvmem-cell-cells":
>> +        const: 1
>> +
> 
> I also wonder why you do not have unit addresses. What if you want to
> have two base MAC addresses?

That would describe an offset within the nvmem device. But the offset
might not be constant, depending on the content. My understanding
so far was that in that case, you use the "-N" suffix.

base-mac-address-1
base-mac-address-2

(or maybe completely different names).

>> +required:
>> +  - compatible
> 
> Other fields are I guess required? At least serial-number should be 
> always?

Yes I could add them to the required list, but they are only
"required" if you need to reference them within the device tree, in 
which
case there have to be there anyway. IOW, the driver doesn't care if
there is a node. If there is none, it doesn't set the "struct 
device_node*"
in the nvmem cell.

>> +
>> +additionalProperties: false
>> +
>> +examples:
>> +  - |
>> +      otp-1 {
> 
> Messed up indentation (use 4 spaces). Generic node name "otp".
> 
>> +          compatible = "kontron,sl28-vpd", "user-otp";
>> +
>> +          serial_number: serial-number {
> 
> What's the point of the empty node?

See above.

-michael

>> +          };
>> +
>> +          base_mac_address: base-mac-address {
>> +              #nvmem-cell-cells = <1>;
>> +          };
>> +      };
>> +
>> +...

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-31  8:17     ` Michael Walle
@ 2022-08-31  9:24       ` Krzysztof Kozlowski
  2022-08-31  9:51         ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31  9:24 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On 31/08/2022 11:17, Michael Walle wrote:
> Am 2022-08-31 09:45, schrieb Krzysztof Kozlowski:
>> On 26/08/2022 00:44, Michael Walle wrote:
>>> Add a schema for the NVMEM layout on Kontron's sl28 boards.
>>>
>>> Signed-off-by: Michael Walle <michael@walle.cc>
>>> ---
>>>  .../nvmem/layouts/kontron,sl28-vpd.yaml       | 52 
>>> +++++++++++++++++++
>>>  1 file changed, 52 insertions(+)
>>>  create mode 100644 
>>> Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>>>
>>> diff --git 
>>> a/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml 
>>> b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>>> new file mode 100644
>>> index 000000000000..e4bc2d9182db
>>> --- /dev/null
>>> +++ 
>>> b/Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml
>>> @@ -0,0 +1,52 @@
>>> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
>>> +%YAML 1.2
>>> +---
>>> +$id: 
>>> http://devicetree.org/schemas/nvmem/layouts/kontron,sl28-vpd.yaml#
>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>> +
>>> +title: NVMEM layout of the Kontron SMARC-sAL28 vital product data
>>> +
>>> +maintainers:
>>> +  - Michael Walle <michael@walle.cc>
>>> +
>>> +description:
>>> +  The vital product data (VPD) of the sl28 boards contains a serial
>>> +  number and a base MAC address. The actual MAC addresses for the
>>> +  on-board ethernet devices are derived from this base MAC address by
>>> +  adding an offset.
>>> +
>>> +properties:
>>> +  compatible:
>>> +    items:
>>> +      - const: kontron,sl28-vpd
>>> +      - const: user-otp
>>> +
>>> +  serial-number:
>>> +    type: object
>>
>> You should define the contents of this object. I would expect this to 
>> be
>> uint32 or string. I think you also need description, as this is not
>> really standard field.
> 
> First thing, this binding isn't like the usual ones, so it might be
> totally wrong.
> 
> What I'd like to achieve here is the following:
> 
> We have the nvmem-consumer dt binding where you can reference a
> nvmem cell in a consumer node. Example:
>    nvmem-cells = <&base_mac_address 5>;
>    nvmem-cell-names = "mac-address";
> 
> On the other end of the link we have the nvmem-provider. The dt
> bindings works well if that one has individual cell nodes, like
> it is described in the nvmem.yaml binding. I.e. you can give the
> cell a label and make a reference to it in the consumer just like
> in the example above.

You can also achieve it with phandle argument to the nvmwm controller,
right? Just like most of providers are doing (clocks, resets). Having
fake (empty) nodes just for that seems like overkill.

> 
> Now comes the catch: what if there is no actual description of the
> cell in the device tree, but is is generated during runtime. How
> can I get a label to it.

Same as clocks, resets, power-domains and everyone else.


> Therefore, in this case, there is just
> an empty node and the driver will associate it with the cell
> created during runtime (see patch 10). It is not expected, that
> is has any properties.

It cannot be even referenced as it does not have #cells property...

> 
>>> +
>>> +  base-mac-address:
>>
>> Fields should be rather described here, not in top-level description.
>>
>>> +    type: object
>>
>> On this level:
>>     additionalProperties: false
>>
>>> +
>>> +    properties:
>>> +      "#nvmem-cell-cells":
>>> +        const: 1
>>> +
>>
>> I also wonder why you do not have unit addresses. What if you want to
>> have two base MAC addresses?
> 
> That would describe an offset within the nvmem device. But the offset
> might not be constant, depending on the content. My understanding
> so far was that in that case, you use the "-N" suffix.
> 
> base-mac-address-1
> base-mac-address-2
> 
> (or maybe completely different names).

You do not allow "base-mac-address-1". Your binding explicitly accepts
only "base-mac-address".

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-31  9:24       ` Krzysztof Kozlowski
@ 2022-08-31  9:51         ` Michael Walle
  2022-08-31 13:07           ` Krzysztof Kozlowski
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-31  9:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-31 11:24, schrieb Krzysztof Kozlowski:
> On 31/08/2022 11:17, Michael Walle wrote:

>> First thing, this binding isn't like the usual ones, so it might be
>> totally wrong.
>> 
>> What I'd like to achieve here is the following:
>> 
>> We have the nvmem-consumer dt binding where you can reference a
>> nvmem cell in a consumer node. Example:
>>    nvmem-cells = <&base_mac_address 5>;
>>    nvmem-cell-names = "mac-address";
>> 
>> On the other end of the link we have the nvmem-provider. The dt
>> bindings works well if that one has individual cell nodes, like
>> it is described in the nvmem.yaml binding. I.e. you can give the
>> cell a label and make a reference to it in the consumer just like
>> in the example above.
> 
> You can also achieve it with phandle argument to the nvmwm controller,
> right? Just like most of providers are doing (clocks, resets). Having
> fake (empty) nodes just for that seems like overkill.

You mean like
  nvmem-cells = <&nvmem_device SERIAL_NUMBER>;

I'm not sure about the implications for now, because one is
referencing the device and not individal cells. Putting that
aside for now, there seems to be a problem with the index for
the base mac address: You will have different number of arguments
for the phandle. That doesn't work, right?

nvmem-cells = <&nvmem_device SERIAL_NUMBER>;
nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS 1>;

>> Now comes the catch: what if there is no actual description of the
>> cell in the device tree, but is is generated during runtime. How
>> can I get a label to it.
> 
> Same as clocks, resets, power-domains and everyone else.

See
https://git.kernel.org/torvalds/c/084973e944bec21804f8afb0515b25434438699a

And I guess this discussion is relevant here:
https://lore.kernel.org/linux-devicetree/20220124160300.25131-1-zajec5@gmail.com/

>> Therefore, in this case, there is just
>> an empty node and the driver will associate it with the cell
>> created during runtime (see patch 10). It is not expected, that
>> is has any properties.
> 
> It cannot be even referenced as it does not have #cells property...

You mean "#nvmem-cell-cells"? See patch #2. None of the nvmem
cells had such a property for now.

>>>> +
>>>> +  base-mac-address:
>>> 
>>> Fields should be rather described here, not in top-level description.
>>> 
>>>> +    type: object
>>> 
>>> On this level:
>>>     additionalProperties: false
>>> 
>>>> +
>>>> +    properties:
>>>> +      "#nvmem-cell-cells":
>>>> +        const: 1
>>>> +
>>> 
>>> I also wonder why you do not have unit addresses. What if you want to
>>> have two base MAC addresses?
>> 
>> That would describe an offset within the nvmem device. But the offset
>> might not be constant, depending on the content. My understanding
>> so far was that in that case, you use the "-N" suffix.
>> 
>> base-mac-address-1
>> base-mac-address-2
>> 
>> (or maybe completely different names).
> 
> You do not allow "base-mac-address-1". Your binding explicitly accepts
> only "base-mac-address".

Because the binding matches the driver, which matches the driver
which matches the VPD data and there is only one base mac address.
Thus, no need for different ones.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-31  9:51         ` Michael Walle
@ 2022-08-31 13:07           ` Krzysztof Kozlowski
  2022-08-31 15:29             ` Michael Walle
  0 siblings, 1 reply; 49+ messages in thread
From: Krzysztof Kozlowski @ 2022-08-31 13:07 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On 31/08/2022 12:51, Michael Walle wrote:
> Am 2022-08-31 11:24, schrieb Krzysztof Kozlowski:
>> On 31/08/2022 11:17, Michael Walle wrote:
> 
>>> First thing, this binding isn't like the usual ones, so it might be
>>> totally wrong.
>>>
>>> What I'd like to achieve here is the following:
>>>
>>> We have the nvmem-consumer dt binding where you can reference a
>>> nvmem cell in a consumer node. Example:
>>>    nvmem-cells = <&base_mac_address 5>;
>>>    nvmem-cell-names = "mac-address";
>>>
>>> On the other end of the link we have the nvmem-provider. The dt
>>> bindings works well if that one has individual cell nodes, like
>>> it is described in the nvmem.yaml binding. I.e. you can give the
>>> cell a label and make a reference to it in the consumer just like
>>> in the example above.
>>
>> You can also achieve it with phandle argument to the nvmwm controller,
>> right? Just like most of providers are doing (clocks, resets). Having
>> fake (empty) nodes just for that seems like overkill.
> 
> You mean like
>   nvmem-cells = <&nvmem_device SERIAL_NUMBER>;

Yes.

> 
> I'm not sure about the implications for now, because one is
> referencing the device and not individal cells. Putting that
> aside for now, there seems to be a problem with the index for
> the base mac address: You will have different number of arguments
> for the phandle. That doesn't work, right?
> 
> nvmem-cells = <&nvmem_device SERIAL_NUMBER>;
> nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS 1>;

It could work, but looks poor, however it could be still nicely extended
with new defines and renames later:

Once:
nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS>;

Later renamed to (with some ABI impact, but in theory names are not part
of ABI, but numbers are):
nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS_1>;
nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS_2>;

(or even skip renaming and just add suffix _2)

You cannot rename device nodes, without deprecating them.

> 
>>> Now comes the catch: what if there is no actual description of the
>>> cell in the device tree, but is is generated during runtime. How
>>> can I get a label to it.
>>
>> Same as clocks, resets, power-domains and everyone else.
> 
> See
> https://git.kernel.org/torvalds/c/084973e944bec21804f8afb0515b25434438699a
> 
> And I guess this discussion is relevant here:
> https://lore.kernel.org/linux-devicetree/20220124160300.25131-1-zajec5@gmail.com/

Eh, ok, I jumped in the middle of something and seems Rob was fine with
these empty nodes. Looks weird and overkill too me (imagine defining 500
clocks in clock-controller like that), but I am here still learning. :)

I guess it makes sense for the cases when OTP/nvmem cells are not
controller specific, not fixed for given OTP controller but rather board
specific and having defined them in header would not make sense.

But then if they are strictly/statically defined as children of a
device, means they are fixed for given OTP and effort is the same as
having them in header...

> 
>>> Therefore, in this case, there is just
>>> an empty node and the driver will associate it with the cell
>>> created during runtime (see patch 10). It is not expected, that
>>> is has any properties.
>>
>> It cannot be even referenced as it does not have #cells property...
> 
> You mean "#nvmem-cell-cells"? See patch #2. None of the nvmem
> cells had such a property for now.

Oh, so so how do you reference them? Users of this seems to be missing,
so I am guessing that directly via phandle to label and nvmem maps them
 with nvmem_find_cell_of_node()?

> 
>>>>> +
>>>>> +  base-mac-address:
>>>>
>>>> Fields should be rather described here, not in top-level description.
>>>>
>>>>> +    type: object
>>>>
>>>> On this level:
>>>>     additionalProperties: false
>>>>
>>>>> +
>>>>> +    properties:
>>>>> +      "#nvmem-cell-cells":
>>>>> +        const: 1
>>>>> +
>>>>
>>>> I also wonder why you do not have unit addresses. What if you want to
>>>> have two base MAC addresses?
>>>
>>> That would describe an offset within the nvmem device. But the offset
>>> might not be constant, depending on the content. My understanding
>>> so far was that in that case, you use the "-N" suffix.
>>>
>>> base-mac-address-1
>>> base-mac-address-2
>>>
>>> (or maybe completely different names).
>>
>> You do not allow "base-mac-address-1". Your binding explicitly accepts
>> only "base-mac-address".
> 
> Because the binding matches the driver, which matches the driver
> which matches the VPD data and there is only one base mac address.
> Thus, no need for different ones.

True, but it is also not extensible, so you have to be sure you covered
100% of this device. And then if you have a new, slightly different
device, you need entirely new schema, because this one is not reusable
at all.

It's ok, it just has some drawbacks/limitations.

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout
  2022-08-31 13:07           ` Krzysztof Kozlowski
@ 2022-08-31 15:29             ` Michael Walle
  0 siblings, 0 replies; 49+ messages in thread
From: Michael Walle @ 2022-08-31 15:29 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-31 15:07, schrieb Krzysztof Kozlowski:
> On 31/08/2022 12:51, Michael Walle wrote:
>> Am 2022-08-31 11:24, schrieb Krzysztof Kozlowski:
>>> On 31/08/2022 11:17, Michael Walle wrote:
>> 
>>>> First thing, this binding isn't like the usual ones, so it might be
>>>> totally wrong.
>>>> 
>>>> What I'd like to achieve here is the following:
>>>> 
>>>> We have the nvmem-consumer dt binding where you can reference a
>>>> nvmem cell in a consumer node. Example:
>>>>    nvmem-cells = <&base_mac_address 5>;
>>>>    nvmem-cell-names = "mac-address";
>>>> 
>>>> On the other end of the link we have the nvmem-provider. The dt
>>>> bindings works well if that one has individual cell nodes, like
>>>> it is described in the nvmem.yaml binding. I.e. you can give the
>>>> cell a label and make a reference to it in the consumer just like
>>>> in the example above.
>>> 
>>> You can also achieve it with phandle argument to the nvmwm 
>>> controller,
>>> right? Just like most of providers are doing (clocks, resets). Having
>>> fake (empty) nodes just for that seems like overkill.
>> 
>> You mean like
>>   nvmem-cells = <&nvmem_device SERIAL_NUMBER>;
> 
> Yes.
> 
>> 
>> I'm not sure about the implications for now, because one is
>> referencing the device and not individal cells. Putting that
>> aside for now, there seems to be a problem with the index for
>> the base mac address: You will have different number of arguments
>> for the phandle. That doesn't work, right?
>> 
>> nvmem-cells = <&nvmem_device SERIAL_NUMBER>;
>> nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS 1>;
> 
> It could work, but looks poor, however it could be still nicely 
> extended
> with new defines and renames later:
> 
> Once:
> nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS>;
> 
> Later renamed to (with some ABI impact, but in theory names are not 
> part
> of ABI, but numbers are):
> nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS_1>;
> nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS_2>;

Ah I think I didn't express correctly what I want to achieve:

nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS 1>;

means "take base mac address and add one to it". the first
argument is treated as the offset. i.e.
   nvmem-cells = <&nvmem_device BASE_MAC_ADDRESS 5>;
would be "base_mac + 5". It is not another base mac address.

whereas, the serial number doesn't take an argument.

I think it could be achieved with some preprocessor magic
like:
#define SL28VPD_SERIAL_NUMBER   (0 << 8)
#define SL28VPD_MAC_ADDRESS(x)  (1 << 8) + (x & 0xff)
#define SL28VPD_ANOTHER_THING   (2 << 8)

I'm not sure if that is any better.

Also the whole binding around nvmem is that it references the cells,
not the device. So if you insist on using the phandle to the
nvmem device, I'll really have to check if that is something which
could be done. I.e. have a look at
   
https://elixir.bootlin.com/linux/latest/source/drivers/nvmem/core.c#L1242

It assumes the reference phandle points to a cell and fetches
the parent to get the nvmem device. We could try to get a device
by the current handle and if that succeeds use that one. But I
*think* it doesn't work with the EPROBE_DEFERRED. I.e. the device
might not be there, because it wasn't probed yet.

> (or even skip renaming and just add suffix _2)
> 
> You cannot rename device nodes, without deprecating them.
> 
>> 
>>>> Now comes the catch: what if there is no actual description of the
>>>> cell in the device tree, but is is generated during runtime. How
>>>> can I get a label to it.
>>> 
>>> Same as clocks, resets, power-domains and everyone else.
>> 
>> See
>> https://git.kernel.org/torvalds/c/084973e944bec21804f8afb0515b25434438699a
>> 
>> And I guess this discussion is relevant here:
>> https://lore.kernel.org/linux-devicetree/20220124160300.25131-1-zajec5@gmail.com/
> 
> Eh, ok, I jumped in the middle of something and seems Rob was fine with
> these empty nodes. Looks weird and overkill too me (imagine defining 
> 500
> clocks in clock-controller like that), but I am here still learning. :)
> 
> I guess it makes sense for the cases when OTP/nvmem cells are not
> controller specific, not fixed for given OTP controller but rather 
> board
> specific and having defined them in header would not make sense.
> 
> But then if they are strictly/statically defined as children of a
> device, means they are fixed for given OTP and effort is the same as
> having them in header...
> 
>>>> Therefore, in this case, there is just
>>>> an empty node and the driver will associate it with the cell
>>>> created during runtime (see patch 10). It is not expected, that
>>>> is has any properties.
>>> 
>>> It cannot be even referenced as it does not have #cells property...
>> 
>> You mean "#nvmem-cell-cells"? See patch #2. None of the nvmem
>> cells had such a property for now.
> 
> Oh, so so how do you reference them? Users of this seems to be missing,
> so I am guessing that directly via phandle to label and nvmem maps them
>  with nvmem_find_cell_of_node()?

Mh? there are plenty of users which references a nvmem cell. E.g.
https://elixir.bootlin.com/linux/v5.19.5/source/arch/arm64/boot/dts/freescale/imx8mm.dtsi#L76
https://elixir.bootlin.com/linux/v5.19.5/source/arch/arm64/boot/dts/freescale/imx8mm.dtsi#L1080

The entry point for the "fetch mac address" is here:
https://elixir.bootlin.com/linux/v5.19.5/source/net/ethernet/eth.c#L550

And the relevant functions is:
https://elixir.bootlin.com/linux/v5.19.5/source/drivers/nvmem/core.c#L1226
which uses of_parse_phandle(), which don't need the "#-cells" property, 
but
is limited to no arguments. Thus the new function in patch #2.

>>>>>> +
>>>>>> +  base-mac-address:
>>>>> 
>>>>> Fields should be rather described here, not in top-level 
>>>>> description.
>>>>> 
>>>>>> +    type: object
>>>>> 
>>>>> On this level:
>>>>>     additionalProperties: false
>>>>> 
>>>>>> +
>>>>>> +    properties:
>>>>>> +      "#nvmem-cell-cells":
>>>>>> +        const: 1
>>>>>> +
>>>>> 
>>>>> I also wonder why you do not have unit addresses. What if you want 
>>>>> to
>>>>> have two base MAC addresses?
>>>> 
>>>> That would describe an offset within the nvmem device. But the 
>>>> offset
>>>> might not be constant, depending on the content. My understanding
>>>> so far was that in that case, you use the "-N" suffix.
>>>> 
>>>> base-mac-address-1
>>>> base-mac-address-2
>>>> 
>>>> (or maybe completely different names).
>>> 
>>> You do not allow "base-mac-address-1". Your binding explicitly 
>>> accepts
>>> only "base-mac-address".
>> 
>> Because the binding matches the driver, which matches the driver
>> which matches the VPD data and there is only one base mac address.
>> Thus, no need for different ones.
> 
> True, but it is also not extensible, so you have to be sure you covered
> 100% of this device. And then if you have a new, slightly different
> device, you need entirely new schema, because this one is not reusable
> at all.
> 
> It's ok, it just has some drawbacks/limitations.

But isn't that the whole thing around the specific compatible?
And you can still add subnodes if there is a new version of
the vpd. The driver will figure that out and add the cells.

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-25 21:44 ` [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string Michael Walle
  2022-08-31  7:37   ` Krzysztof Kozlowski
@ 2022-08-31 21:48   ` Rob Herring
  2022-08-31 22:30     ` Michael Walle
  1 sibling, 1 reply; 49+ messages in thread
From: Rob Herring @ 2022-08-31 21:48 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On Thu, Aug 25, 2022 at 11:44:17PM +0200, Michael Walle wrote:
> The "user-otp" and "factory-otp" compatible string just depicts a
> generic NVMEM device. But an actual device tree node might as well
> contain a more specific compatible string. Make it possible to add
> more specific binding elsewere and just match part of the compatibles
> here.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>
> ---
>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)

In hindsight it looks like we are mixing 2 different purposes of 'which 
instance is this' and 'what is this'. 'compatible' is supposed to be the 
latter.

Maybe there's a better way to handle user/factory? There's a similar 
need with partitions for A/B or factory/update.

Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-31 21:48   ` Rob Herring
@ 2022-08-31 22:30     ` Michael Walle
  2022-09-02 14:46       ` Rob Herring
  0 siblings, 1 reply; 49+ messages in thread
From: Michael Walle @ 2022-08-31 22:30 UTC (permalink / raw)
  To: Rob Herring
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

Am 2022-08-31 23:48, schrieb Rob Herring:
> On Thu, Aug 25, 2022 at 11:44:17PM +0200, Michael Walle wrote:
>> The "user-otp" and "factory-otp" compatible string just depicts a
>> generic NVMEM device. But an actual device tree node might as well
>> contain a more specific compatible string. Make it possible to add
>> more specific binding elsewere and just match part of the compatibles
>> here.
>> 
>> Signed-off-by: Michael Walle <michael@walle.cc>
>> ---
>>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> In hindsight it looks like we are mixing 2 different purposes of 'which
> instance is this' and 'what is this'. 'compatible' is supposed to be 
> the
> latter.
> 
> Maybe there's a better way to handle user/factory? There's a similar
> need with partitions for A/B or factory/update.

I'm not sure I understand what you mean. It has nothing to with
user and factory provisionings.

SPI flashes have a user programmable and a factory programmable
area, some have just one of them. Whereas with A/B you (as in the
user or the board manufacturer) defines an area within a memory device
to be either slot A or slot B. But here the flash dictates what's
factory and what's user storage. It's in the datasheet.

HTH
-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 01/14] net: add helper eth_addr_add()
  2022-08-25 21:44 ` [PATCH v1 01/14] net: add helper eth_addr_add() Michael Walle
@ 2022-09-01 16:26   ` Michael Walle
  2022-09-01 16:31     ` Andrew Lunn
  2022-09-01 19:54     ` Jakub Kicinski
  0 siblings, 2 replies; 49+ messages in thread
From: Michael Walle @ 2022-09-01 16:26 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand
  Cc: linux-mtd, devicetree, linux-kernel, linux-arm-kernel, netdev,
	Ahmad Fatoum

Hi netdev maintainers,

Am 2022-08-25 23:44, schrieb Michael Walle:
> Add a helper to add an offset to a ethernet address. This comes in 
> handy
> if you have a base ethernet address for multiple interfaces.
> 
> Signed-off-by: Michael Walle <michael@walle.cc>

Would it be possible to get an Ack for this patch, so I don't have
to repost this large (and still growing) series to netdev every time?

I guess it would be ok to have this go through another tree?

-michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 01/14] net: add helper eth_addr_add()
  2022-09-01 16:26   ` Michael Walle
@ 2022-09-01 16:31     ` Andrew Lunn
  2022-09-01 19:54     ` Jakub Kicinski
  1 sibling, 0 replies; 49+ messages in thread
From: Andrew Lunn @ 2022-09-01 16:31 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, linux-mtd, devicetree,
	linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On Thu, Sep 01, 2022 at 06:26:39PM +0200, Michael Walle wrote:
> Hi netdev maintainers,
> 
> Am 2022-08-25 23:44, schrieb Michael Walle:
> > Add a helper to add an offset to a ethernet address. This comes in handy
> > if you have a base ethernet address for multiple interfaces.
> > 
> > Signed-off-by: Michael Walle <michael@walle.cc>
> 
> Would it be possible to get an Ack for this patch, so I don't have
> to repost this large (and still growing) series to netdev every time?

Looks O.K. to me

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 01/14] net: add helper eth_addr_add()
  2022-09-01 16:26   ` Michael Walle
  2022-09-01 16:31     ` Andrew Lunn
@ 2022-09-01 19:54     ` Jakub Kicinski
  1 sibling, 0 replies; 49+ messages in thread
From: Jakub Kicinski @ 2022-09-01 19:54 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Rob Herring, Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo,
	Li Yang, Rafał Miłecki, David S . Miller, Eric Dumazet,
	Paolo Abeni, Frank Rowand, linux-mtd, devicetree, linux-kernel,
	linux-arm-kernel, netdev, Ahmad Fatoum

On Thu, 01 Sep 2022 18:26:39 +0200 Michael Walle wrote:
> Am 2022-08-25 23:44, schrieb Michael Walle:
> > Add a helper to add an offset to a ethernet address. This comes in 
> > handy
> > if you have a base ethernet address for multiple interfaces.
> > 
> > Signed-off-by: Michael Walle <michael@walle.cc>  
> 
> Would it be possible to get an Ack for this patch, so I don't have
> to repost this large (and still growing) series to netdev every time?
> 
> I guess it would be ok to have this go through another tree?

Andrew's ack is strong enough, but in case there's any doubt:

Acked-by: Jakub Kicinski <kuba@kernel.org>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string
  2022-08-31 22:30     ` Michael Walle
@ 2022-09-02 14:46       ` Rob Herring
  0 siblings, 0 replies; 49+ messages in thread
From: Rob Herring @ 2022-09-02 14:46 UTC (permalink / raw)
  To: Michael Walle
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Krzysztof Kozlowski, Srinivas Kandagatla, Shawn Guo, Li Yang,
	Rafał Miłecki, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Frank Rowand, MTD Maling List,
	devicetree, linux-kernel, linux-arm-kernel, netdev, Ahmad Fatoum

On Wed, Aug 31, 2022 at 5:30 PM Michael Walle <michael@walle.cc> wrote:
>
> Am 2022-08-31 23:48, schrieb Rob Herring:
> > On Thu, Aug 25, 2022 at 11:44:17PM +0200, Michael Walle wrote:
> >> The "user-otp" and "factory-otp" compatible string just depicts a
> >> generic NVMEM device. But an actual device tree node might as well
> >> contain a more specific compatible string. Make it possible to add
> >> more specific binding elsewere and just match part of the compatibles
> >> here.
> >>
> >> Signed-off-by: Michael Walle <michael@walle.cc>
> >> ---
> >>  Documentation/devicetree/bindings/mtd/mtd.yaml | 7 ++++---
> >>  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > In hindsight it looks like we are mixing 2 different purposes of 'which
> > instance is this' and 'what is this'. 'compatible' is supposed to be
> > the
> > latter.
> >
> > Maybe there's a better way to handle user/factory? There's a similar
> > need with partitions for A/B or factory/update.
>
> I'm not sure I understand what you mean. It has nothing to with
> user and factory provisionings.
>
> SPI flashes have a user programmable and a factory programmable
> area, some have just one of them. Whereas with A/B you (as in the
> user or the board manufacturer) defines an area within a memory device
> to be either slot A or slot B. But here the flash dictates what's
> factory and what's user storage. It's in the datasheet.

Ah, right. Nevermind...

Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-09-02 14:47 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-25 21:44 [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Michael Walle
2022-08-25 21:44 ` [PATCH v1 01/14] net: add helper eth_addr_add() Michael Walle
2022-09-01 16:26   ` Michael Walle
2022-09-01 16:31     ` Andrew Lunn
2022-09-01 19:54     ` Jakub Kicinski
2022-08-25 21:44 ` [PATCH v1 02/14] of: base: add of_parse_phandle_with_optional_args() Michael Walle
2022-08-25 21:44 ` [PATCH v1 03/14] nvmem: core: add an index parameter to the cell Michael Walle
2022-08-25 21:44 ` [PATCH v1 04/14] nvmem: core: drop the removal of the cells in nvmem_add_cells() Michael Walle
2022-08-25 21:44 ` [PATCH v1 05/14] nvmem: core: add nvmem_add_one_cell() Michael Walle
2022-08-25 21:44 ` [PATCH v1 06/14] nvmem: core: introduce NVMEM layouts Michael Walle
2022-08-26  8:16   ` Michael Walle
2022-08-28 14:06   ` Rafał Miłecki
2022-08-28 14:33     ` Michael Walle
2022-08-30 13:36   ` Srinivas Kandagatla
2022-08-30 14:24     ` Michael Walle
2022-08-30 14:43       ` Srinivas Kandagatla
2022-08-30 15:02         ` Michael Walle
2022-08-30 15:23           ` Srinivas Kandagatla
2022-08-25 21:44 ` [PATCH v1 07/14] nvmem: core: add per-cell post processing Michael Walle
2022-08-30 13:37   ` Srinivas Kandagatla
2022-08-30 14:20     ` Michael Walle
2022-08-25 21:44 ` [PATCH v1 08/14] dt-bindings: mtd: relax the nvmem compatible string Michael Walle
2022-08-31  7:37   ` Krzysztof Kozlowski
2022-08-31  7:48     ` Michael Walle
2022-08-31  7:55       ` Krzysztof Kozlowski
2022-08-31 21:48   ` Rob Herring
2022-08-31 22:30     ` Michael Walle
2022-09-02 14:46       ` Rob Herring
2022-08-25 21:44 ` [PATCH v1 09/14] dt-bindings: nvmem: add YAML schema for the sl28 vpd layout Michael Walle
2022-08-26 16:05   ` Rob Herring
2022-08-31  7:45   ` Krzysztof Kozlowski
2022-08-31  8:17     ` Michael Walle
2022-08-31  9:24       ` Krzysztof Kozlowski
2022-08-31  9:51         ` Michael Walle
2022-08-31 13:07           ` Krzysztof Kozlowski
2022-08-31 15:29             ` Michael Walle
2022-08-25 21:44 ` [PATCH v1 10/14] nvmem: layouts: add sl28vpd layout Michael Walle
2022-08-25 21:44 ` [PATCH v1 11/14] nvmem: core: export nvmem device size Michael Walle
2022-08-25 21:44 ` [RFC PATCH v1 12/14] nvmem: layouts: rewrite the u-boot-env driver as a NVMEM layout Michael Walle
2022-08-28 14:04   ` Rafał Miłecki
2022-08-28 14:42     ` Michael Walle
2022-08-25 21:44 ` [RFC PATCH v1 13/14] nvmem: layouts: u-boot-env: add device node Michael Walle
2022-08-28 13:55   ` Rafał Miłecki
2022-08-28 14:36     ` Michael Walle
2022-08-25 21:44 ` [PATCH v1 14/14] arm64: dts: ls1028a: sl28: get MAC addresses from VPD Michael Walle
2022-08-28 15:05 ` [PATCH v1 00/14] nvmem: core: introduce NVMEM layouts Rafał Miłecki
2022-08-29  8:22   ` Michael Walle
2022-08-30 13:37     ` Srinivas Kandagatla
2022-08-31  7:48   ` Krzysztof Kozlowski

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).