Skip to content

Commit

Permalink
drivers: ethernet: enc28j60: Add DT property to set random mac
Browse files Browse the repository at this point in the history
Use the DT property zephyr,random-mac-address to set a boot time
random mac address.

Signed-off-by: Dean Sellers <[email protected]>
  • Loading branch information
dean-at-evos authored and nashif committed Jul 28, 2024
1 parent aa3470b commit dfe7cb5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions drivers/ethernet/eth_enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <ethernet/eth_stats.h>

#include "eth_enc28j60_priv.h"
#include "eth.h"

#define D10D24S 11

Expand Down Expand Up @@ -801,10 +802,19 @@ static int eth_enc28j60_init(const struct device *dev)
/* Errata B7/1 */
k_busy_wait(D10D24S);

/* Assign octets not previously taken from devicetree */
context->mac_address[0] = MICROCHIP_OUI_B0;
context->mac_address[1] = MICROCHIP_OUI_B1;
context->mac_address[2] = MICROCHIP_OUI_B2;
/* Apply a random MAC address if requested in DT */
if (config->random_mac) {
gen_random_mac(context->mac_address, MICROCHIP_OUI_B0, MICROCHIP_OUI_B1,
MICROCHIP_OUI_B2);
LOG_INF("Random MAC Addr %02x:%02x:%02x:%02x:%02x:%02x", context->mac_address[0],
context->mac_address[1], context->mac_address[2], context->mac_address[3],
context->mac_address[4], context->mac_address[5]);
} else {
/* Assign octets not previously taken from devicetree */
context->mac_address[0] = MICROCHIP_OUI_B0;
context->mac_address[1] = MICROCHIP_OUI_B1;
context->mac_address[2] = MICROCHIP_OUI_B2;
}

if (eth_enc28j60_init_buffers(dev)) {
return -ETIMEDOUT;
Expand Down Expand Up @@ -850,6 +860,7 @@ static int eth_enc28j60_init(const struct device *dev)
.full_duplex = DT_INST_PROP(0, full_duplex), \
.timeout = CONFIG_ETH_ENC28J60_TIMEOUT, \
.hw_rx_filter = DT_INST_PROP_OR(inst, hw_rx_filter, ENC28J60_RECEIVE_FILTERS), \
.random_mac = DT_INST_PROP(inst, zephyr_random_mac_address), \
}; \
\
ETH_NET_DEVICE_DT_INST_DEFINE(inst, eth_enc28j60_init, NULL, &eth_enc28j60_runtime_##inst, \
Expand Down
1 change: 1 addition & 0 deletions drivers/ethernet/eth_enc28j60_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ struct eth_enc28j60_config {
uint8_t full_duplex;
int32_t timeout;
uint8_t hw_rx_filter;
bool random_mac;
};

struct eth_enc28j60_runtime {
Expand Down

0 comments on commit dfe7cb5

Please sign in to comment.