Skip to content

Commit c2b1c41

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 91b1b84 commit c2b1c41

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

drivers/ethernet/eth_lan9250.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,14 @@ static int lan9250_init(const struct device *dev)
697697
return ret;
698698
}
699699
lan9250_configure(dev);
700+
701+
/* use a random MAC address if requested in the device tree */
702+
if (config->random_mac) {
703+
sys_rand_get(context->mac_address, sizeof(context->mac_address));
704+
/* locally administered, unicast address */
705+
context->mac_address[0] &= ~(BIT(0) | BIT(2) | BIT(3));
706+
context->mac_address[0] |= BIT(1);
707+
}
700708
lan9250_set_macaddr(dev);
701709

702710
k_thread_create(&context->thread, context->thread_stack,
@@ -719,6 +727,7 @@ static int lan9250_init(const struct device *dev)
719727
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8)), \
720728
.interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
721729
.timeout = CONFIG_ETH_LAN9250_BUF_ALLOC_TIMEOUT, \
730+
.random_mac = DT_INST_PROP(inst, zephyr_random_mac_address), \
722731
}; \
723732
\
724733
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)