Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/atmel/sam/sam4e_xpro/sam4e_xpro.dts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
pinctrl-0 = <&gmac_mii>;
pinctrl-names = "default";

/* Atmel OUI */
local-mac-address = [00 04 25];
zephyr,random-mac-address;

phy-handle = <&phy>;
Expand Down
10 changes: 3 additions & 7 deletions boards/atmel/sam/sam_e70_xplained/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ if ETH_SAM_GMAC

# Read MAC address from AT24MAC402 EEPROM

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
default 0x9A

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
default 1
config EEPROM
default y

config ETH_SAM_GMAC_MAC_I2C_EEPROM
config NVMEM
default y
select I2C

endif # ETH_SAM_GMAC

Expand Down
20 changes: 18 additions & 2 deletions boards/atmel/sam/sam_e70_xplained/sam_e70_xplained-common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,23 @@
pinctrl-names = "default";

eeprom: eeprom@5f {
compatible = "atmel,24mac402";
compatible = "atmel,at24", "atmel,24mac402";
reg = <0x5f>;
size = <256>;
pagesize = <16>;
address-width = <8>;
timeout = <5>;

nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;

mac_address: mac-address@9a {
reg = <0x9a 6>;
#nvmem-cell-cells = <0>;
};
};
};
};

Expand Down Expand Up @@ -128,7 +143,8 @@ zephyr_udc0: &usbhs {
pinctrl-0 = <&gmac_rmii>;
pinctrl-names = "default";

mac-eeprom = <&eeprom>;
nvmem-cells = <&mac_address>;
nvmem-cell-names = "mac-address";
phy-handle = <&phy>;
};

Expand Down
10 changes: 3 additions & 7 deletions boards/atmel/sam/sam_v71_xult/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ if ETH_SAM_GMAC

# Read MAC address from AT24MAC402 EEPROM

config ETH_SAM_GMAC_MAC_I2C_EEPROM
config EEPROM
default y
select I2C

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
default 0x9A

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
default 1
config NVMEM
default y

endif # ETH_SAM_GMAC

Expand Down
20 changes: 18 additions & 2 deletions boards/atmel/sam/sam_v71_xult/sam_v71_xult-common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,23 @@
pinctrl-names = "default";

eeprom: eeprom@5f {
compatible = "atmel,24mac402";
compatible = "atmel,at24", "atmel,24mac402";
reg = <0x5f>;
size = <256>;
pagesize = <16>;
address-width = <8>;
timeout = <5>;

nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;

mac_address: mac-address@9a {
reg = <0x9a 6>;
#nvmem-cell-cells = <0>;
};
};
};
};

Expand Down Expand Up @@ -253,7 +268,8 @@ zephyr_udc0: &usbhs {
pinctrl-0 = <&gmac_rmii>;
pinctrl-names = "default";

mac-eeprom = <&eeprom>;
nvmem-cells = <&mac_address>;
nvmem-cell-names = "mac-address";
phy-handle = <&phy>;
};

Expand Down
10 changes: 3 additions & 7 deletions boards/atmel/sam0/same54_xpro/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ if ETH_SAM_GMAC

# Read MAC address from AT24MAC402 EEPROM

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
default 0x9A

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
default 1
config EEPROM
default y

config ETH_SAM_GMAC_MAC_I2C_EEPROM
config NVMEM
default y
select I2C

endif # ETH_SAM_GMAC

Expand Down
20 changes: 18 additions & 2 deletions boards/atmel/sam0/same54_xpro/same54_xpro.dts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,23 @@
pinctrl-names = "default";

eeprom: eeprom@5e {
compatible = "atmel,24mac402";
compatible = "atmel,at24", "atmel,24mac402";
reg = <0x5e>;
size = <256>;
pagesize = <16>;
address-width = <8>;
timeout = <5>;

nvmem-layout {
compatible = "fixed-layout";
#address-cells = <1>;
#size-cells = <1>;

mac_address: mac-address@9a {
reg = <0x9a 6>;
#nvmem-cell-cells = <0>;
};
};
};
};

Expand Down Expand Up @@ -158,7 +173,8 @@ zephyr_udc0: &usb0 {
pinctrl-0 = <&gmac_rmii>;
pinctrl-names = "default";

mac-eeprom = <&eeprom>;
nvmem-cells = <&mac_address>;
nvmem-cell-names = "mac-address";
phy-handle = <&phy>;
};

Expand Down
24 changes: 0 additions & 24 deletions drivers/ethernet/Kconfig.sam_gmac
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,6 @@ config ETH_SAM_GMAC_BUF_RX_COUNT
fit at least two Ethernet frames: one being received by the GMAC module
and the other being processed by the higher layer networking stack.

config ETH_SAM_GMAC_MAC_I2C_EEPROM
bool "Read from an I2C EEPROM"
help
Read MAC address from an I2C EEPROM.

if ETH_SAM_GMAC_MAC_I2C_EEPROM

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS
hex "I2C EEPROM internal address"
range 0 0xffffffff
help
Internal address of the EEPROM chip where the MAC address is stored.
Chips with 1 to 4 byte internal address size are supported. Address
size has to be configured in a separate Kconfig option.

config ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE
int "I2C EEPROM internal address size"
default 1
range 1 4
help
Size (in bytes) of the internal EEPROM address.

endif # ETH_SAM_GMAC_MAC_I2C_EEPROM

config PTP_CLOCK_SAM_GMAC
bool "SAM GMAC PTP clock driver support"
default y
Expand Down
34 changes: 34 additions & 0 deletions drivers/ethernet/eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define ZEPHYR_DRIVERS_ETHERNET_ETH_H_

#include <zephyr/types.h>
#include <zephyr/net/ethernet.h>
#include <zephyr/random/random.h>

/* helper macro to return mac address octet from local_mac_address prop */
Expand Down Expand Up @@ -42,4 +43,37 @@ static inline void gen_random_mac(uint8_t *mac_addr, uint8_t b0, uint8_t b1, uin
sys_rand_get(&mac_addr[3], 3U);
}

static inline int net_eth_mac_load(const struct net_eth_mac_config *cfg, uint8_t *mac_addr)
{
if (cfg == NULL || cfg->type == NET_ETH_MAC_DEFAULT) {
return -ENODATA;
}

/* Copy the static part */
memcpy(mac_addr, cfg->addr, cfg->addr_len);

if (cfg->type == NET_ETH_MAC_STATIC && cfg->addr_len == NET_ETH_ADDR_LEN) {
/* Complete static address */
return 0;
}

if (cfg->type == NET_ETH_MAC_RANDOM) {
sys_rand_get(&mac_addr[cfg->addr_len], NET_ETH_ADDR_LEN - cfg->addr_len);

/* Set MAC address locally administered, unicast (LAA) */
mac_addr[0] |= 0x02;

return 0;
}

#if defined(CONFIG_NVMEM)
if (cfg->type == NET_ETH_MAC_NVMEM) {
return nvmem_cell_read(&cfg->cell, &mac_addr[cfg->addr_len], 0,
NET_ETH_ADDR_LEN - cfg->addr_len);
}
#endif

return -ENODATA;
}

#endif /* ZEPHYR_DRIVERS_ETHERNET_ETH_H_ */
43 changes: 9 additions & 34 deletions drivers/ethernet/eth_sam_gmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/nvmem.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/sys/barrier.h>
#include <zephyr/sys/util.h>
Expand Down Expand Up @@ -1729,38 +1730,6 @@ static int eth_initialize(const struct device *dev)
return retval;
}

#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
{
uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS;
int ret;
const struct i2c_dt_spec i2c = I2C_DT_SPEC_GET(DT_INST_PHANDLE(0, mac_eeprom));

if (!device_is_ready(i2c.bus)) {
LOG_ERR("Bus device is not ready");
return;
}

ret = i2c_write_read_dt(&i2c,
&iaddr, CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE,
mac_addr, 6);

if (ret != 0) {
LOG_ERR("I2C: failed to read MAC addr");
return;
}
}
#endif

static void generate_mac(uint8_t mac_addr[6])
{
#if DT_INST_NODE_HAS_PROP(0, mac_eeprom)
get_mac_addr_from_i2c_eeprom(mac_addr);
#elif DT_INST_PROP(0, zephyr_random_mac_address)
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);
#endif
}

static void phy_link_state_changed(const struct device *pdev,
struct phy_link_state *state,
void *user_data)
Expand Down Expand Up @@ -1836,7 +1805,11 @@ static void eth0_iface_init(struct net_if *iface)
return;
}

generate_mac(dev_data->mac_addr);
result = net_eth_mac_load(cfg->mcfg, dev_data->mac_addr);
if (result < 0) {
LOG_ERR("Failed to load MAC (%d)", result);
return;
}

LOG_INF("MAC: %02x:%02x:%02x:%02x:%02x:%02x",
dev_data->mac_addr[0], dev_data->mac_addr[1],
Expand Down Expand Up @@ -2153,6 +2126,7 @@ static void eth0_irq_config(void)
}

PINCTRL_DT_INST_DEFINE(0);
NET_ETH_MAC_DT_INST_DEFINE(0);

static const struct eth_sam_dev_cfg eth0_config = {
.regs = (Gmac *)DT_REG_ADDR(DT_INST_PARENT(0)),
Expand All @@ -2161,7 +2135,8 @@ static const struct eth_sam_dev_cfg eth0_config = {
.clock_cfg = SAM_DT_CLOCK_PMC_CFG(0, DT_INST_PARENT(0)),
#endif
.config_func = eth0_irq_config,
.phy_dev = DEVICE_DT_GET(DT_INST_PHANDLE(0, phy_handle))
.phy_dev = DEVICE_DT_GET(DT_INST_PHANDLE(0, phy_handle)),
.mcfg = NET_ETH_MAC_DT_INST_DEV_CONFIG_GET(0),
};

static struct eth_sam_dev_data eth0_data = {
Expand Down
1 change: 1 addition & 0 deletions drivers/ethernet/eth_sam_gmac_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ struct eth_sam_dev_cfg {
const struct pinctrl_dev_config *pcfg;
void (*config_func)(void);
const struct device *phy_dev;
const struct net_eth_mac_config *mcfg;
};

/* Device run time data */
Expand Down
2 changes: 2 additions & 0 deletions drivers/wifi/nrf_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ zephyr_include_directories(
inc
# for net_sprint_ll_addr
${ZEPHYR_BASE}/subsys/net/ip
# for net_eth_mac_load
${ZEPHYR_BASE}/drivers/ethernet
)

zephyr_include_directories_ifdef(CONFIG_NRF70_OFFLOADED_RAW_TX
Expand Down
31 changes: 0 additions & 31 deletions drivers/wifi/nrf_wifi/Kconfig.nrfwifi
Original file line number Diff line number Diff line change
Expand Up @@ -532,37 +532,6 @@ config NRF70_RPU_EXTEND_TWT_SP
mechanism is not used.
endif # NRF_WIFI_LOW_POWER

config WIFI_FIXED_MAC_ADDRESS
string "Wi-Fi Fixed MAC address in format XX:XX:XX:XX:XX:XX"
help
This option overrides the MAC address read from OTP. It is strictly for testing purposes only.

choice
prompt "Wi-Fi MAC address type"
default WIFI_FIXED_MAC_ADDRESS_ENABLED if WIFI_FIXED_MAC_ADDRESS != ""
default WIFI_OTP_MAC_ADDRESS
help
Select the type of MAC address to be used by the Wi-Fi driver

config WIFI_OTP_MAC_ADDRESS
bool "Use MAC address from OTP"
help
This option uses the MAC address stored in the OTP memory of the nRF70.

config WIFI_FIXED_MAC_ADDRESS_ENABLED
bool "fixed MAC address"
help
Enable fixed MAC address

config WIFI_RANDOM_MAC_ADDRESS
bool "Random MAC address generation at runtime"
depends on ENTROPY_GENERATOR
help
This option enables random MAC address generation at runtime.
The random MAC address is generated using the entropy device random generator.

endchoice

config NRF70_RSSI_STALE_TIMEOUT_MS
int "RSSI stale timeout in milliseconds"
default 1000
Expand Down
Loading
Loading