drivers: eth: Get Manual MAC address from devicetree
Move from a Kconfig to select/initialize the MAC address to using the "local-mac-address" property in devicetree. If the property is set the drivers will initialize the mac-address from the devicetree (unless the mac address is all 0's). The MAC address might get overwritten by either a driver specific means or by the setting of "zephyr,random-mac-address" in the devicetree. Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
1de61b4c42
commit
b19cf0bed3
9 changed files with 27 additions and 88 deletions
|
@ -12,10 +12,6 @@ if ETH_SAM_GMAC
|
||||||
|
|
||||||
# Read MAC address from AT24MAC402 EEPROM
|
# Read MAC address from AT24MAC402 EEPROM
|
||||||
|
|
||||||
choice ETH_SAM_GMAC_MAC_SELECT
|
|
||||||
default ETH_SAM_GMAC_MAC_I2C_EEPROM
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
||||||
default 0x5F
|
default 0x5F
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,8 @@ if ETH_SAM_GMAC
|
||||||
|
|
||||||
# Read MAC address from AT24MAC402 EEPROM
|
# Read MAC address from AT24MAC402 EEPROM
|
||||||
|
|
||||||
choice ETH_SAM_GMAC_MAC_SELECT
|
config ETH_SAM_GMAC_MAC_I2C_EEPROM
|
||||||
default ETH_SAM_GMAC_MAC_I2C_EEPROM
|
default y
|
||||||
endchoice
|
|
||||||
|
|
||||||
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
||||||
default 0x5F
|
default 0x5F
|
||||||
|
|
|
@ -34,52 +34,6 @@ config ETH_GECKO_RX_THREAD_PRIO
|
||||||
help
|
help
|
||||||
RX thread priority
|
RX thread priority
|
||||||
|
|
||||||
choice ETH_GECKO_MAC_SELECT
|
|
||||||
prompt "MAC address"
|
|
||||||
help
|
|
||||||
Choose how to configure MAC address.
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC_MANUAL
|
|
||||||
bool "Manual"
|
|
||||||
help
|
|
||||||
Assign an arbitrary MAC address.
|
|
||||||
|
|
||||||
endchoice # ETH_GECKO_MAC_SELECT
|
|
||||||
|
|
||||||
if ETH_GECKO_MAC_MANUAL
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC0
|
|
||||||
hex "MAC Address Byte 0"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC1
|
|
||||||
hex "MAC Address Byte 1"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC2
|
|
||||||
hex "MAC Address Byte 2"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC3
|
|
||||||
hex "MAC Address Byte 3"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC4
|
|
||||||
hex "MAC Address Byte 4"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
config ETH_GECKO_MAC5
|
|
||||||
hex "MAC Address Byte 5"
|
|
||||||
default 0
|
|
||||||
range 0 0xff
|
|
||||||
|
|
||||||
endif # ETH_GECKO_MAC_MANUAL
|
|
||||||
|
|
||||||
config ETH_GECKO_CARRIER_CHECK_RX_IDLE_TIMEOUT_MS
|
config ETH_GECKO_CARRIER_CHECK_RX_IDLE_TIMEOUT_MS
|
||||||
int "Carrier check timeout period (ms)"
|
int "Carrier check timeout period (ms)"
|
||||||
default 500
|
default 500
|
||||||
|
|
|
@ -65,12 +65,6 @@ config ETH_MCUX_0_UNIQUE_MAC
|
||||||
bool "Stable MAC address"
|
bool "Stable MAC address"
|
||||||
help
|
help
|
||||||
Generate MAC address from MCU's unique identification register.
|
Generate MAC address from MCU's unique identification register.
|
||||||
|
|
||||||
config ETH_MCUX_0_MANUAL_MAC
|
|
||||||
bool "Manual MAC address"
|
|
||||||
help
|
|
||||||
Get MAC address from the device tree.
|
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
endif # ETH_MCUX_0
|
endif # ETH_MCUX_0
|
||||||
|
@ -93,11 +87,6 @@ config ETH_MCUX_1_UNIQUE_MAC
|
||||||
help
|
help
|
||||||
Generate MAC address from MCU's unique identification register.
|
Generate MAC address from MCU's unique identification register.
|
||||||
|
|
||||||
config ETH_MCUX_1_MANUAL_MAC
|
|
||||||
bool "Manual MAC address"
|
|
||||||
help
|
|
||||||
Get MAC address from the device tree.
|
|
||||||
|
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
endif # ETH_MCUX_1
|
endif # ETH_MCUX_1
|
||||||
|
|
|
@ -76,23 +76,11 @@ config ETH_SAM_GMAC_MONITOR_PERIOD
|
||||||
periodically executed to detect and report any changes in the PHY
|
periodically executed to detect and report any changes in the PHY
|
||||||
link status to the operating system.
|
link status to the operating system.
|
||||||
|
|
||||||
choice ETH_SAM_GMAC_MAC_SELECT
|
|
||||||
prompt "MAC address"
|
|
||||||
help
|
|
||||||
Choose how to configure MAC address.
|
|
||||||
|
|
||||||
config ETH_SAM_GMAC_MAC_MANUAL
|
|
||||||
bool "Manual"
|
|
||||||
help
|
|
||||||
Assign the MAC address specified in the device tree.
|
|
||||||
|
|
||||||
config ETH_SAM_GMAC_MAC_I2C_EEPROM
|
config ETH_SAM_GMAC_MAC_I2C_EEPROM
|
||||||
bool "Read from an I2C EEPROM"
|
bool "Read from an I2C EEPROM"
|
||||||
help
|
help
|
||||||
Read MAC address from an I2C EEPROM.
|
Read MAC address from an I2C EEPROM.
|
||||||
|
|
||||||
endchoice
|
|
||||||
|
|
||||||
if ETH_SAM_GMAC_MAC_I2C_EEPROM
|
if ETH_SAM_GMAC_MAC_I2C_EEPROM
|
||||||
|
|
||||||
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
config ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS
|
||||||
|
|
|
@ -9,6 +9,26 @@
|
||||||
|
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
|
|
||||||
|
/* helper macro to return mac address octet from local_mac_address prop */
|
||||||
|
#define NODE_MAC_ADDR_OCTET(node, n) DT_PROP_BY_IDX(node, local_mac_address, n)
|
||||||
|
|
||||||
|
/* Determine if a mac address is all 0's */
|
||||||
|
#define NODE_MAC_ADDR_NULL(node) \
|
||||||
|
((NODE_MAC_ADDR_OCTET(node, 0) == 0) && \
|
||||||
|
(NODE_MAC_ADDR_OCTET(node, 1) == 0) && \
|
||||||
|
(NODE_MAC_ADDR_OCTET(node, 2) == 0) && \
|
||||||
|
(NODE_MAC_ADDR_OCTET(node, 3) == 0) && \
|
||||||
|
(NODE_MAC_ADDR_OCTET(node, 4) == 0) && \
|
||||||
|
(NODE_MAC_ADDR_OCTET(node, 5) == 0))
|
||||||
|
|
||||||
|
/* Given a device tree node for an ethernet controller will
|
||||||
|
* returns false if there is no local-mac-address property or
|
||||||
|
* the property is all zero's. Otherwise will return True
|
||||||
|
*/
|
||||||
|
#define NODE_HAS_VALID_MAC_ADDR(node) \
|
||||||
|
UTIL_AND(DT_NODE_HAS_PROP(node, local_mac_address),\
|
||||||
|
(!NODE_MAC_ADDR_NULL(node)))
|
||||||
|
|
||||||
static inline void gen_random_mac(u8_t *mac_addr, u8_t b0, u8_t b1, u8_t b2)
|
static inline void gen_random_mac(u8_t *mac_addr, u8_t b0, u8_t b1, u8_t b2)
|
||||||
{
|
{
|
||||||
u32_t entropy;
|
u32_t entropy;
|
||||||
|
|
|
@ -659,15 +659,8 @@ static const struct eth_gecko_dev_cfg eth0_config = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct eth_gecko_dev_data eth0_data = {
|
static struct eth_gecko_dev_data eth0_data = {
|
||||||
#ifdef CONFIG_ETH_GECKO_MAC_MANUAL
|
#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))
|
||||||
.mac_addr = {
|
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
||||||
CONFIG_ETH_GECKO_MAC0,
|
|
||||||
CONFIG_ETH_GECKO_MAC1,
|
|
||||||
CONFIG_ETH_GECKO_MAC2,
|
|
||||||
CONFIG_ETH_GECKO_MAC3,
|
|
||||||
CONFIG_ETH_GECKO_MAC4,
|
|
||||||
CONFIG_ETH_GECKO_MAC5,
|
|
||||||
},
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1210,7 +1210,7 @@ static struct eth_context eth_0_context = {
|
||||||
#if DT_INST_PROP(0, zephyr_random_mac_address)
|
#if DT_INST_PROP(0, zephyr_random_mac_address)
|
||||||
.generate_mac = generate_random_mac,
|
.generate_mac = generate_random_mac,
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_ETH_MCUX_0_MANUAL_MAC)
|
#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))
|
||||||
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
||||||
.generate_mac = NULL,
|
.generate_mac = NULL,
|
||||||
#endif
|
#endif
|
||||||
|
@ -1277,7 +1277,7 @@ static struct eth_context eth_1_context = {
|
||||||
#if DT_INST_PROP(1, zephyr_random_mac_address)
|
#if DT_INST_PROP(1, zephyr_random_mac_address)
|
||||||
.generate_mac = generate_random_mac,
|
.generate_mac = generate_random_mac,
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_ETH_MCUX_1_MANUAL_MAC)
|
#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(1))
|
||||||
.mac_addr = DT_INST_PROP(1, local_mac_address),
|
.mac_addr = DT_INST_PROP(1, local_mac_address),
|
||||||
.generate_mac = NULL,
|
.generate_mac = NULL,
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2201,7 +2201,7 @@ static const struct eth_sam_dev_cfg eth0_config = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct eth_sam_dev_data eth0_data = {
|
static struct eth_sam_dev_data eth0_data = {
|
||||||
#ifdef CONFIG_ETH_SAM_GMAC_MAC_MANUAL
|
#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))
|
||||||
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
||||||
#endif
|
#endif
|
||||||
.queue_list = {
|
.queue_list = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue