Skip to content

Conversation

@pdgendt
Copy link
Contributor

@pdgendt pdgendt commented Sep 26, 2025

A proof-of-concept using PR #96379 as an alternative for #74835.

Note that this loads the MAC address during driver initialization. A more complete (but complex) solution would be to move it to the network interface initialization.

@pdgendt pdgendt mentioned this pull request Sep 29, 2025
@pdgendt pdgendt force-pushed the nvmem-mac-address branch 2 times, most recently from 9afd50b to 8241eb8 Compare September 30, 2025 13:01
@pdgendt pdgendt changed the title [PoC] drivers: ethernet: sam_gmac: Use NVMEM cell to get MAC address [PoC] drivers: ethernet/wifi: Use NVMEM cell to get MAC address Sep 30, 2025
@pdgendt pdgendt force-pushed the nvmem-mac-address branch from 8241eb8 to 8ac0a2f Compare October 6, 2025 19:12
Comment on lines +52 to +62
/* 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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to have no difference between the static mac address and the default. as most drivers set the mac address from the dt as the initial value of the mac address in the data struct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain a bit what you mean here? I don't fully understand.

This static MAC address is when you have the following:

eth-driver {
	local-mac-address = [02 02 03 04 05 06];
};

This should only ever be used during testing. An alternative is have the OUI in the static part:

eth-driver {
	local-mac-address = [00 04 25];
	zephyr,random-mac-address;
};
/* or */
eth-driver {
	local-mac-address = [00 04 25];
	nvmem-cells = <&mac_address>;
	nvmem-cell-names = "mac-address";
};

Maybe the naming should be changed in that case to something like mac-address-prefix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most instance based drivers use something like:

static struct eth_litex_dev_data eth_data##n = { \
.mac_addr = DT_INST_PROP_OR(n, local_mac_address, {0}), \
}; \

saving that also in the config struct seems not nessesary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'd refactor those to use the struct net_eth_mac_config instead.


#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/nvmem.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be added to eth.h instead

Comment on lines 14 to 15
config NVMEM
default y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVMEM, should be selected by the ethernet driver, if it has nvmem-cell is set, similar to the gpios being activated by the ethernet phys, that have a reset or irq gpio. (or at least implied)

@GseoC
Copy link

GseoC commented Oct 23, 2025

Hello @pdgendt ,

I've used this P-R to successfully implement a use-case on STM32 platforms (P-R: #98149). I had to add a fuse sub-system. Feel free to review it.

@GseoC
Copy link

GseoC commented Oct 23, 2025

I think there are some other users that may be interested in the fuse framework. It's probably applicable to your #98140 P-R as well.

* @param node_id Node identifier.
*/
#define Z_NET_ETH_MAC_DEV_CONFIG_NAME(node_id) \
_CONCAT(__net_eth_mac_dev_config, DEVICE_DT_NAME_GET(node_id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a _ between the prefix and the device name?

select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
select ETH_DSA_SUPPORT_DEPRECATED
select PINCTRL
imply NVMEM if ($(dt_compat_any_has_prop,$(DT_COMPAT_ATMEL_SAM_GMAC),nvmem-cells) || \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select or imply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer imply as it isn't a hard requirement, and could be turned off, for example for testing purposes.

@pdgendt pdgendt force-pushed the nvmem-mac-address branch 2 times, most recently from 1793285 to 44acb16 Compare November 3, 2025 09:59
@pdgendt pdgendt changed the title [PoC] drivers: ethernet/wifi: Use NVMEM cell to get MAC address drivers: ethernet: Use NVMEM cell to get MAC address Nov 3, 2025
@pdgendt pdgendt marked this pull request as ready for review November 3, 2025 10:02
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Could you fill the commit message body of commit
"include: zephyr: net: ethernet.h: Add MAC address configuration"?

I don't understand the CI build test failures.

Add MAC address configuration struct and macros.

Signed-off-by: Pieter De Gendt <[email protected]>
Given an ethernet MAC configuration struct, load a MAC address into a
provided array.

Signed-off-by: Pieter De Gendt <[email protected]>
Turn ethernet controller devicetree nodes into NVMEM consumers. Allow
passing mac-address cells.

Signed-off-by: Pieter De Gendt <[email protected]>
Rework the Atmel SAM GMAC driver to read a MAC address from the provided
NVMEM cell instead of using I2C commands directly.

Signed-off-by: Pieter De Gendt <[email protected]>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants