From: Iulian Gilca <igilca1980@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: igilca@outlook.com, Iulian Gilca <igilca1980@gmail.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] of: net: Add option for random mac address
Date: Thu, 10 Oct 2024 17:54:17 -0400 [thread overview]
Message-ID: <20241010215417.332801-1-igilca1980@gmail.com> (raw)
In-Reply-To: <3287d9dd-94c2-45a8-b1e7-e4f895b75754@lunn.ch>
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@gmail.com>
---
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
next prev parent reply other threads:[~2024-10-10 21:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-10 19:05 [PATCH] of: net: Add option for random mac address Iulian Gilca
2024-10-10 19:53 ` Andrew Lunn
2024-10-10 20:29 ` [PATCH v2] User random address if dt sets so Iulian Gilca
2024-10-10 20:59 ` Andrew Lunn
2024-10-10 21:54 ` Iulian Gilca [this message]
2024-10-10 22:54 ` [PATCH] of: net: Add option for random mac address Russell King (Oracle)
2024-10-10 23:00 ` Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241010215417.332801-1-igilca1980@gmail.com \
--to=igilca1980@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=igilca@outlook.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox