|
|
@@ -1,5 +1,7 @@
|
|
|
-From: John Crispin <[email protected]>
|
|
|
-Subject: NET: add mtd-mac-address support to of_get_mac_address()
|
|
|
+From 6f8e5369ae054ec6c9265581d5a7e39738a5cd84 Mon Sep 17 00:00:00 2001
|
|
|
+From: Ansuel Smith <[email protected]>
|
|
|
+Date: Tue, 30 Mar 2021 13:16:38 +0200
|
|
|
+Subject: [PATCH 1/2] NET: add mtd-mac-address support to of_get_mac_address()
|
|
|
|
|
|
Many embedded devices have information such as mac addresses stored inside mtd
|
|
|
devices. This patch allows us to add a property inside a node describing a
|
|
|
@@ -8,11 +10,13 @@ where the mac address can be found.
|
|
|
|
|
|
Signed-off-by: John Crispin <[email protected]>
|
|
|
Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
+Signed-off-by: Ansuel Smith <[email protected]>
|
|
|
---
|
|
|
- drivers/of/of_net.c | 37 +++++++++++++++++++++++++++++++++++++
|
|
|
- include/linux/of_net.h | 1 +
|
|
|
- 2 files changed, 38 insertions(+)
|
|
|
+ drivers/of/of_net.c | 75 ++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
+ 1 file changed, 74 insertions(+), 1 deletion(-)
|
|
|
|
|
|
+diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
|
|
|
+index 6e411821583e..f072e2509cc9 100644
|
|
|
--- a/drivers/of/of_net.c
|
|
|
+++ b/drivers/of/of_net.c
|
|
|
@@ -11,6 +11,7 @@
|
|
|
@@ -23,7 +27,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
|
|
|
/**
|
|
|
* of_get_phy_mode - Get phy mode for given device_node
|
|
|
-@@ -45,7 +46,7 @@ int of_get_phy_mode(struct device_node *
|
|
|
+@@ -45,7 +46,7 @@ int of_get_phy_mode(struct device_node *np, phy_interface_t *interface)
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(of_get_phy_mode);
|
|
|
|
|
|
@@ -32,7 +36,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
{
|
|
|
struct property *pp = of_find_property(np, name, NULL);
|
|
|
|
|
|
-@@ -78,6 +79,79 @@ static const void *of_get_mac_addr_nvmem
|
|
|
+@@ -78,6 +79,70 @@ static const void *of_get_mac_addr_nvmem(struct device_node *np)
|
|
|
return mac;
|
|
|
}
|
|
|
|
|
|
@@ -47,10 +51,8 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
+ const char *part;
|
|
|
+ const __be32 *list;
|
|
|
+ phandle phandle;
|
|
|
-+ u32 mac_inc = 0;
|
|
|
+ u8 mac[ETH_ALEN];
|
|
|
+ void *addr;
|
|
|
-+ u32 inc_idx;
|
|
|
+
|
|
|
+ list = of_get_property(np, "mtd-mac-address", &size);
|
|
|
+ if (!list || (size != (2 * sizeof(*list))))
|
|
|
@@ -74,14 +76,6 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
+ ret = mtd_read(mtd, be32_to_cpup(list), 6, &retlen, mac);
|
|
|
+ put_mtd_device(mtd);
|
|
|
+
|
|
|
-+ if (of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx))
|
|
|
-+ inc_idx = 5;
|
|
|
-+ if (inc_idx > 5)
|
|
|
-+ return NULL;
|
|
|
-+
|
|
|
-+ if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc))
|
|
|
-+ mac[inc_idx] += mac_inc;
|
|
|
-+
|
|
|
+ if (!is_valid_ether_addr(mac))
|
|
|
+ return NULL;
|
|
|
+
|
|
|
@@ -108,11 +102,12 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
+#endif
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
++
|
|
|
+
|
|
|
/**
|
|
|
* Search the device tree for the best MAC address to use. 'mac-address' is
|
|
|
* checked first, because that is supposed to contain to "most recent" MAC
|
|
|
-@@ -98,12 +172,20 @@ static const void *of_get_mac_addr_nvmem
|
|
|
+@@ -98,6 +163,10 @@ static const void *of_get_mac_addr_nvmem(struct device_node *np)
|
|
|
* this case, the real MAC is in 'local-mac-address', and 'mac-address' exists
|
|
|
* but is all zeros.
|
|
|
*
|
|
|
@@ -123,13 +118,17 @@ Signed-off-by: Felix Fietkau <[email protected]>
|
|
|
* Return: Will be a valid pointer on success and ERR_PTR in case of error.
|
|
|
*/
|
|
|
const void *of_get_mac_address(struct device_node *np)
|
|
|
- {
|
|
|
- const void *addr;
|
|
|
+@@ -116,6 +185,10 @@ const void *of_get_mac_address(struct device_node *np)
|
|
|
+ if (addr)
|
|
|
+ return addr;
|
|
|
|
|
|
+ addr = of_get_mac_address_mtd(np);
|
|
|
+ if (addr)
|
|
|
+ return addr;
|
|
|
+
|
|
|
- addr = of_get_mac_addr(np, "mac-address");
|
|
|
- if (addr)
|
|
|
- return addr;
|
|
|
+ return of_get_mac_addr_nvmem(np);
|
|
|
+ }
|
|
|
+ EXPORT_SYMBOL(of_get_mac_address);
|
|
|
+--
|
|
|
+2.30.2
|
|
|
+
|