Skip to contentSkip to conversation

nvmem: layouts: fixed-layout: Apply mac-base consumer offsets

PATCH In review Navid Ghahremani 1 participant 2 messages Oct 10 – Nov 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: layouts: fixed-layout: Apply mac-base consumer offsets

The fixed-cell binding describes mac-base cells whose consumer argument is an offset from a stored base address. The fixed-layout driver currently registers these as ordinary cells, so all consumers receive the unchanged base address. On the ZTE ZXHN H3600 this gives LAN and WAN the same MAC.

Allow the DT cell parser to call a layout-specific fixup and use it to attach a read postprocessor for mac-base cells. Support the binding's six-byte binary and 17-byte colon-separated ASCII formats. Keep the raw read length while returning a six-byte address, and reject unsupported sizes and bit-field MAC cells. Legacy cells retain their existing path.

This follows the mac-base support introduced in OpenWrt by Rafal Milecki, but keeps the postprocessor in the fixed-layout driver introduced in mainline since then. The ASCII parser receives a terminated local copy.

---
 drivers/nvmem/core.c                 | 14 +++++++--
 drivers/nvmem/internals.h            |  3 +-
 drivers/nvmem/layouts/Kconfig        |  1 +
 drivers/nvmem/layouts/fixed-layout.c | 45 +++++++++++++++++++++++++++-
 include/linux/nvmem-provider.h       |  3 +-
 5 files changed, 61 insertions(+), 5 deletions(-)
drivers/nvmem/core.c +12 -2
index 0556d14017..5de82ccdb1 100644
@@ -789,7 +789,8 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
 	return 0;
 }
 
-int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
+int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np,
+			    int (*fixup)(struct nvmem_cell_info *info))
 {
 	struct device *dev = &nvmem->dev;
 	const __be32 *addr;
@@ -827,6 +828,15 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
 		if (nvmem->fixup_dt_cell_info)
 			nvmem->fixup_dt_cell_info(nvmem, &info);
 
+		if (fixup) {
+			ret = fixup(&info);
+			if (ret) {
+				kfree(info.name);
+				of_node_put(info.np);
+				return ret;
+			}
+		}
+
 		ret = nvmem_add_one_cell(nvmem, &info);
 		kfree(info.name);
 		if (ret) {
@@ -841,7 +851,7 @@ EXPORT_SYMBOL_GPL(nvmem_add_cells_from_dt);
 
 static int nvmem_add_cells_from_legacy_of(struct nvmem_device *nvmem)
 {
-	return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node);
+	return nvmem_add_cells_from_dt(nvmem, nvmem->dev.of_node, NULL);
 }
 
 int nvmem_layout_register(struct nvmem_layout *layout)
drivers/nvmem/internals.h +2 -1
index 4e610deeaa..060d41363e 100644
@@ -39,7 +39,8 @@ struct nvmem_device {
 	bool			sysfs_cells_populated;
 };
 
-int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np);
+int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np,
+			    int (*fixup)(struct nvmem_cell_info *info));
 
 #if IS_ENABLED(CONFIG_OF)
 int nvmem_layout_bus_register(void);
drivers/nvmem/layouts/Kconfig +1 -0
index 5e586dfebe..66fc5d9e1f 100644
@@ -3,6 +3,7 @@
 config NVMEM_LAYOUTS
 	bool
 	depends on OF
+	select GENERIC_NET_UTILS
 
 if NVMEM_LAYOUTS
 
drivers/nvmem/layouts/fixed-layout.c +44 -1

62 lines not on this page · raw message

include/linux/nvmem-provider.h +2 -1
index 6063fe5b77..1e31101201 100644
@@ -215,7 +215,8 @@ static inline int nvmem_layout_register(struct nvmem_layout *layout)
 static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {}
 
 static inline int nvmem_add_cells_from_dt(struct nvmem_device *nvmem,
-					  struct device_node *np)
+					  struct device_node *np,
+					  int (*fixup)(struct nvmem_cell_info *info))
 {
 	return -EOPNOTSUPP;
 }
Signature · 1 line
2.55.0
#1 lore raw

Hi,

Please drop this patch. I wrote it for the ZTE ZXHN H3600 board, which will now take its LAN and WAN addresses from two plain cells instead, so nothing in mainline needs it right now.

Best regards,
Navid