Skip to content

Commit b40fb04

Browse files
committed
drivers: ethernet: lan9250: add support for a random mac address
Extend the lan9250 driver to support using a local administered unicast random mac address during init. This follows the device tree settings for zephyr_random_mac_address from other ethernet drivers for the added support. Signed-off-by: Charles Hardin <ckhardin@gmail.com>
1 parent 13daf24 commit b40fb04

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

drivers/ethernet/eth_lan9250.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <zephyr/net/net_pkt.h>
1616
#include <zephyr/net/net_if.h>
1717
#include <zephyr/net/ethernet.h>
18+
#include <zephyr/random/random.h>
1819
#include <ethernet/eth_stats.h>
1920

2021
#include "eth_lan9250_priv.h"
@@ -697,6 +698,14 @@ static int lan9250_init(const struct device *dev)
697698
return ret;
698699
}
699700
lan9250_configure(dev);
701+
702+
/* use a random MAC address if requested in the device tree */
703+
if (config->random_mac) {
704+
sys_rand_get(context->mac_address, sizeof(context->mac_address));
705+
/* locally administered, unicast address */
706+
context->mac_address[0] &= ~(BIT(0) | BIT(2) | BIT(3));
707+
context->mac_address[0] |= BIT(1);
708+
}
700709
lan9250_set_macaddr(dev);
701710

702711
k_thread_create(&context->thread, context->thread_stack,
@@ -719,6 +728,7 @@ static int lan9250_init(const struct device *dev)
719728
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8)), \
720729
.interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
721730
.timeout = CONFIG_ETH_LAN9250_BUF_ALLOC_TIMEOUT, \
731+
.random_mac = DT_INST_PROP(inst, zephyr_random_mac_address), \
722732
}; \
723733
\
724734
ETH_NET_DEVICE_DT_INST_DEFINE(inst, lan9250_init, NULL, &lan9250_##inst##_runtime, \

drivers/ethernet/eth_lan9250_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ struct lan9250_config {
312312
struct gpio_dt_spec reset;
313313
uint8_t full_duplex;
314314
int32_t timeout;
315+
bool random_mac;
315316
};
316317

317318
struct lan9250_runtime {

0 commit comments

Comments
 (0)