Skip to content

Commit 5806816

Browse files
committed
drivers: net: sam_gmac: update random MAC addr for multi inst support
Add variable 'random_mac_addr' for 'zephyr,random-mac-address' from device tree. Update generate_mac() to get random MAC address for each GAMC interface with the 'zephyr,random-mac-address' property. Signed-off-by: Tony Han <[email protected]>
1 parent e225164 commit 5806816

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

drivers/ethernet/eth_sam_gmac.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,12 +1716,15 @@ static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
17161716
}
17171717
#endif
17181718

1719-
static void generate_mac(uint8_t mac_addr[6])
1719+
static void generate_mac(uint8_t mac_addr[6], const struct eth_sam_dev_cfg *const cfg)
17201720
{
17211721
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
1722+
ARG_UNUSED(cfg);
17221723
get_mac_addr_from_i2c_eeprom(mac_addr);
1723-
#elif DT_INST_PROP(0, zephyr_random_mac_address)
1724-
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);
1724+
#else
1725+
if (cfg->random_mac_addr) {
1726+
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);
1727+
}
17251728
#endif
17261729
}
17271730

@@ -1811,7 +1814,7 @@ static void eth_iface_init(struct net_if *iface)
18111814
return;
18121815
}
18131816

1814-
generate_mac(dev_data->mac_addr);
1817+
generate_mac(dev_data->mac_addr, cfg);
18151818

18161819
LOG_INF("%s MAC: %02x:%02x:%02x:%02x:%02x:%02x", dev->name,
18171820
dev_data->mac_addr[0], dev_data->mac_addr[1],
@@ -2131,6 +2134,7 @@ static const struct ethernet_api eth_api = {
21312134
#else
21322135
#define CFG_CLK_DEFN(n)
21332136
#endif
2137+
21342138
#define SAM_GMAC_CFG_DEFN(n) \
21352139
BUILD_ASSERT(DT_INST_PROP(n, max_frame_size) == 1518 || \
21362140
DT_INST_PROP(n, max_frame_size) == 1536 || \
@@ -2148,6 +2152,7 @@ static const struct ethernet_api eth_api = {
21482152
.max_frame_size = DT_INST_PROP(n, max_frame_size), \
21492153
.num_queues = DT_INST_PROP(n, num_queues), \
21502154
.phy_conn_type = DT_INST_ENUM_IDX(n, phy_connection_type), \
2155+
.random_mac_addr = DT_INST_PROP(n, zephyr_random_mac_address), \
21512156
};
21522157

21532158
#define DEFN_RX_FLAG_LIST_0(n) \

drivers/ethernet/eth_sam_gmac_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ struct eth_sam_dev_cfg {
265265
const uint32_t max_frame_size;
266266
const uint8_t num_queues;
267267
const uint8_t phy_conn_type;
268+
const bool random_mac_addr;
268269
};
269270

270271
/* Device run time data */

0 commit comments

Comments
 (0)