Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth_nxp_enet_qos_mac: implement the nxp,unique-mac address feature #83549

Merged

Conversation

theadib
Copy link
Contributor

@theadib theadib commented Jan 4, 2025

This implements to generate the MAC address of the device UUID. The UUID is hashed to reduce the size to 3 bytes.
Ideas taken from eth_nxp_enet.c
It does not implement fused MAC address.
Adding dependencies on: HWInfo and CRC

Help needed:
currently I do not know how to register the dependencies in the driver.
That will cause to fail compilation without adding HWInfo and CRC manually.

Adib.

@theadib
Copy link
Contributor Author

theadib commented Jan 4, 2025

I found the Kconfig where to setup the dependencies.
Should compile without issues now.

@theadib theadib force-pushed the nxp_enet_qos_unique_mac branch 2 times, most recently from da238fd to 4c4fe91 Compare January 4, 2025 11:49
@@ -23,6 +23,14 @@ config ETH_NXP_ENET_QOS_MAC

if ETH_NXP_ENET_QOS_MAC

config ETH_NXP_ENET_QOS_MAC_UNIQUE_MAC_ADDRESS
bool "Unique MAC address support"
Copy link
Member

Choose a reason for hiding this comment

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

could add default y and depends on $(dt_compat_any_has_prop,<compatible string>,<prop>[,<value>])

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe default y if $(dt_compat_any_has_prop,<compatible string>,<prop>[,<value>])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I can make it default "Y" but I struggle to depend on property "nxp,unique-mac" because it parses this as two arguments (the property and the value),
default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_ENET_QOS_MAC),nxp,unique-mac)
This never evaluates to true.

I searched all Kconfig for samples but there is none "grep has_prop Kconfig"

Any advice?
I would just prefer to make default y unconditionally so it can be removed on demand.

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 also tested:

DT_PROP_NXP_ENET_QOS_MAC_UNIQUE_MAC := nxp,unique-mac

config ETH_NXP_ENET_QOS_MAC_UNIQUE_MAC_ADDRESS
	bool "Unique MAC address support"
	default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_ENET_QOS_MAC),$(DT_PROP_NXP_ENET_QOS_MAC_UNIQUE_MAC))

which always evaluates to true. :-O

Copy link
Member

Choose a reason for hiding this comment

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

you are closer with the more recent comment, the issue is you need to give the value argument (for a boolean if the value is false the property is still present just invisible). If you are just checking if the property exists and not that it has a certain value, then for a boolean property it will always be true that it exists.

@theadib theadib force-pushed the nxp_enet_qos_unique_mac branch 2 times, most recently from 0743664 to 7f1070e Compare January 6, 2025 20:13
@theadib
Copy link
Contributor Author

theadib commented Jan 6, 2025

Hello @decsny the value thing is doing the trick. Thanks for pointing out.

DT_PROP_NXP_ENET_QOS_MAC_UNIQUE_MAC := nxp,unique-mac

config ETH_NXP_ENET_QOS_MAC_UNIQUE_MAC_ADDRESS
	bool "Unique MAC address support"
	default y if $(dt_compat_any_has_prop,$(DT_COMPAT_NXP_ENET_QOS_MAC),$(DT_PROP_NXP_ENET_QOS_MAC_UNIQUE_MAC),True)

MAC_ADDR_SOURCE_LOCAL,
MAC_ADDR_SOURCE_RANDOM,
MAC_ADDR_SOURCE_UNIQUE,
MAC_ADDR_SOURCE_FUSED,
Copy link
Member

Choose a reason for hiding this comment

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

when or how does the fused option get used?

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 was hoping that NXP has an predefined position in the "OTP" space.
Derek.Snell in discord answered "No" meanwhile (for the MCXN).
"Fused" will fall back to "random" address.
I am not sure if other MCU that use that driver module have such predefined space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should I remove it then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

as the enum is only used internally by this driver, it should be removed, can be added if needed later.
You may also want to consider renaming the enum to something with a prefix of the driver like the other structs in that file.

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 have done so.

if (config->random_mac) {
if (config->mac_addr_source == MAC_ADDR_SOURCE_LOCAL) {
/* Use the mac address provided in the devicetree */
#if defined(CONFIG_ETH_NXP_ENET_QOS_MAC_UNIQUE_MAC_ADDRESS)
Copy link
Member

Choose a reason for hiding this comment

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

nit, prefer to #else #define nxp_enet_unique_mac(...) as an empty macro above and remove this inline #if from this spot, if that makes sense

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 would prefer to keep a nondestructive fallback rather than generate an all zero MAC ADDRESS as in the eth_nxp_enet.c driver.
Even this is not what the user has asked for.
If you agree ...

Copy link
Member

Choose a reason for hiding this comment

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

well, if I understand correctly, this code would never be reached in the case that there is no "unique" address option in the DT. If you are really concern about it maybe the alternative definition would return an error, but that will add an instruction or two to image, but which is fine to me. I found over many cases that having inline #if tends to cause configuration and dependency problems down the line when maintaining the files, and makes it harder to read, that's why I want to avoid it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. implemented as empty macro causing lesser #if defined() in the code.

@theadib theadib force-pushed the nxp_enet_qos_unique_mac branch 5 times, most recently from 746039d to 733709e Compare January 8, 2025 08:01
This implements to generate the MAC address of the device UUID.
The UUID is hashed to reduce the size to 3 bytes.
Ideas taken from eth_nxp_enet.c
Adding dependencies on: HWInfo and CRC

Signed-off-by: Adib Taraben <theadib@gmail.com>
@theadib theadib force-pushed the nxp_enet_qos_unique_mac branch from 733709e to 9b9ea46 Compare January 8, 2025 08:11
@henrikbrixandersen henrikbrixandersen merged commit cce0826 into zephyrproject-rtos:main Jan 8, 2025
25 checks passed
@theadib theadib deleted the nxp_enet_qos_unique_mac branch January 8, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Ethernet platform: NXP Drivers NXP Semiconductors, drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants