[PATCH] of: net: Add option for random mac address
From: Iulian Gilca
Date: Thu Oct 10 2024 - 17:54:43 EST
Embedded devices that don't have a fixed mac address may want
to use this property. For example dsa switch ports may use this property in
order avoid setting this from user space. Sometimes, in case of DSA switch
ports is desirable to use a random mac address rather than using the
conduit interface mac address.
example device tree config :
....
netswitch: swdev@5f {
compatible = "microchip,ksz9897";
...
ports {
port@0 {
reg = <0>;
label = "eth0";
random-address;
}
...
}
}
...
This way the switch ports that have the "random-address" property
will use a random mac address rather than the conduit mac address.
PS. Sorry for the previous malformed patch
Signed-off-by: Iulian Gilca <igilca1980@xxxxxxxxx>
---
net/core/of_net.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/core/of_net.c b/net/core/of_net.c
index 93ea425b9248..8a1fc8a4e87f 100644
--- a/net/core/of_net.c
+++ b/net/core/of_net.c
@@ -142,6 +142,11 @@ int of_get_mac_address(struct device_node *np, u8 *addr)
if (!ret)
return 0;
+ if (of_find_property(np, "random-address", NULL)) {
+ eth_random_addr(addr);
+ return 0;
+ }
+
return of_get_mac_address_nvmem(np, addr);
}
EXPORT_SYMBOL(of_get_mac_address);
--
2.43.0