Skip to content

Conversation

@yangbolu1991
Copy link
Member

@yangbolu1991 yangbolu1991 commented Nov 29, 2024

NXP i.MX NETC is a TSN capable Ethernet IP. It may support
ENETC MACs, or/and multiple ports switch.

The ENETC MAC was handled by eth_nxp_imx_netc driver.
This DSA driver is to support NETC switch device.
Current driver supports DSA with limitation that only switch
function is available without management via DSA master port.
DSA master port support is TODO work.

Take i.MX RT1180 NETC hardware as an example.

Capture

The PR also reworked dsa sample for flexibility and extensibility.
Current DSA sample is initially for ip_k66f board with a switch PHY,
while it is expected as a common DSA sample for all DSA devices.
This PR only reworks the sample
with new added CONFIG_NET_SAMPLE_DSA_LLDP for ip_k66f with 3 LAN
ports.
Ideally this should be common for all DSA devices, but for now, ip_k66f
is the only platform supporting it.
As there will be more DSA functions supported, better to allow each
function enablement via option to suit hardware or device driver support
status.

Dependency:

For dsa sample built for RT1180, the exported 4 switch ports worked as switch with MAC learning.
hotplug cable will have information in the console. Here is the sample log.

00:00:00.052,000] <inf> phy_mii: PHY (3) ID 1CC816
[00:00:00.102,000] <inf> phy_mii: PHY (2) ID 1CC816
[00:00:00.141,000] <inf> dsa_netc: DSA slave port 0 Link down
[00:00:00.141,000] <inf> dsa_netc: DSA slave port 1 Link down
[00:00:00.141,000] <inf> dsa_netc: DSA slave port 2 Link down
[00:00:00.141,000] <inf> dsa_netc: DSA slave port 3 Link down
[00:00:00.141,000] <inf> nxp_imx_eth_psi: ENETC0 MAC: 00:00:00:01:02:00
[00:00:00.141,000] <inf> nxp_imx_eth_psi: ENETC0 Link down
[00:00:00.141,000] <inf> nxp_imx_eth_psi: ENETC1 MAC: 00:00:00:01:03:00
*** Booting Zephyr OS build v4.0.0-1799-gf6f1487ec520 ***
[00:00:00.143,000] <inf> net_dsa_sample: Slave interface 0 found.
[00:00:00.143,000] <inf> net_dsa_sample: Slave interface 1 found.
[00:00:00.143,000] <inf> net_dsa_sample: Slave interface 2 found.
[00:00:00.143,000] <inf> net_dsa_sample: Slave interface 3 found.
[00:00:00.143,000] <inf> net_dsa_sample: Slave interface 4 found.
[00:00:00.143,000] <inf> net_dsa_sample: DSA ports init - OK
[00:00:02.113,000] <inf> phy_rt_rtl8211f: PHY 4 is up
[00:00:02.113,000] <inf> phy_rt_rtl8211f: PHY (4) Link speed 1000 Mb, full duplex
[00:00:02.113,000] <inf> dsa_netc: DSA slave port 2 Link up
[00:00:02.624,000] <inf> phy_rt_rtl8211f: PHY 5 is up
[00:00:02.624,000] <inf> phy_rt_rtl8211f: PHY (5) Link speed 1000 Mb, full duplex
[00:00:02.624,000] <inf> dsa_netc: DSA slave port 1 Link up
uart:~$
uart:~$
uart:~$
uart:~$
uart:~$
[00:00:16.616,000] <inf> phy_rt_rtl8211f: PHY 4 is down
[00:00:16.616,000] <inf> dsa_netc: DSA slave port 2 Link down
uart:~$
uart:~$
[00:00:29.211,000] <inf> phy_mii: PHY (2) Link speed 100 Mb, full duplex
[00:00:29.211,000] <inf> dsa_netc: DSA slave port 0 Link up
uart:~$


Thanks.

@zephyrbot
Copy link

zephyrbot commented Nov 29, 2024

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-hal_nxp DNM This PR should not be merged (Do Not Merge) labels Nov 29, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

Just making sure I understand this- will all instances of this IP with an internal PHY support DSA? Or are these functions unrelated?

Copy link
Member Author

@yangbolu1991 yangbolu1991 Dec 9, 2024

Choose a reason for hiding this comment

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

This eth_nxp_imx_netc.c driver is for normal ENETC MAC of NETC. There may be several instances designed for external usage. For example, i.MX95, there are 3 ENETC MACs externally but without switch IP in NETC.

For SoC like i.MX RT1180, there are 5 ports switch IP in NETC together with 2 ENETC MACs. So, it's designed that one ENETC MAC will connect to one switch MAC inside SoC for DSA management. The MACs connected inside SoC is called pseudo MAC in reference manual. Outside the SoC, we could see 4 switch ports and one normal eth port.
Thanks.

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this driver Kconfig select DSA support, or should the DSA_NXP_IMX_NETC Kconfig select it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I think it makes sense to rework this.

config ETH_DSA_SUPPORT
        bool
        help
          Set by an ethernet driver that supports DSA.

menuconfig NET_DSA
        bool "Distributed Switch Architecture support"
        depends on ETH_DSA_SUPPORT
        help
          Enable Distributed Switch Architecture support. For now it
          only supports Kinetics and STM32 ENET drivers.

NET_DSA should select ETH_DSA_SUPPORT. Then this is handle in common NET option, and device driver no longer needs to handle. Also it's possible eth device driver supports DSA master mode without any code wrappered with ETH_DSA_SUPPORT.

./drivers/ethernet/Kconfig.sam_gmac:    select ETH_DSA_SUPPORT
./drivers/ethernet/nxp_enet/Kconfig:    select ETH_DSA_SUPPORT
./drivers/ethernet/nxp_enet/Kconfig:    select ETH_DSA_SUPPORT
./drivers/ethernet/Kconfig.stm32_hal:   select ETH_DSA_SUPPORT

Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it makes sense to set the NET_DSA in config and then let other parts of the system either depend on it (recommended) or select it.

Copy link
Member

Choose a reason for hiding this comment

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

Should this driver Kconfig select DSA support, or should the DSA_NXP_IMX_NETC Kconfig select it?

This driver is supposed to set it, not the DSA driver, it's for indicating the master port driver was implemented to have the DSA wrapper as the send function and registering the master tx function. I think the kconfig is poorly documented and as @yangbolu1991 points out it would be ideal to not need to add DSA support for the cpu side drivers . But I think we should not be removing this config in this PR and definitely without further solution because for now it's true that only some of the drivers have implemented support for the DSA architecture

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we instead make this a Kconfig?

Copy link
Member Author

@yangbolu1991 yangbolu1991 Dec 9, 2024

Choose a reason for hiding this comment

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

Yes. That's better. I will do. Or we define max number with 10 for Kconfig? This may cover most cases in the future.
Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe these should be set by a board overlay for the RT1180? I doubt many boards are this capable as a switch, right?

Copy link
Member Author

@yangbolu1991 yangbolu1991 Dec 9, 2024

Choose a reason for hiding this comment

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

Different boards with different ethernet port number. This number here is not just for switch ports. There may be also other normal ethernet ports. For RT1180, there are 4 switch ports + 1 normal eth port.
If max number 10 is accepted here, I think future boards no longer define in board overlay. 10 should be enough for most boards.
Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

This looks like an overkill. The IPv4 and IPv6 structs take up lot of space so we should avoid allocating them just in case. You can add these settings to board overlay if you need more than default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay.

west.yml Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Commit with HAL changes should be first in this PR- also please update the commit message to be more clear- something like:

west.yml: update hal_nxp to include DSA switch driver

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it makes sense to set the NET_DSA in config and then let other parts of the system either depend on it (recommended) or select it.

Copy link
Member

Choose a reason for hiding this comment

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

I recommend putting () around this complex macro in order to avoid possible weird issues when the macro is expanded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

same here

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, thanks.

Copy link
Member

Choose a reason for hiding this comment

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

This looks like an overkill. The IPv4 and IPv6 structs take up lot of space so we should avoid allocating them just in case. You can add these settings to board overlay if you need more than default.

Added NETC switch node.

Signed-off-by: Yangbo Lu <[email protected]>
Added pinctrl for NETC switch ports.

Signed-off-by: Yangbo Lu <[email protected]>
Moved netc node from m33 dts to common dtsi. ENETC PSI0 kept
disabled for M7 for now.

Signed-off-by: Yangbo Lu <[email protected]>
Enabled switch ports in dts.

Signed-off-by: Yangbo Lu <[email protected]>
Added board init for switch ports.

Signed-off-by: Yangbo Lu <[email protected]>
Documented the NETC DSA support.

Signed-off-by: Yangbo Lu <[email protected]>
The multiple ports DSA device may have some ports disabled in
dts. This should be handled in the sample.

Signed-off-by: Yangbo Lu <[email protected]>
@yangbolu1991
Copy link
Member Author

Updated to v8. Changes include,

  • Converted to use "nxp,netc-switch" compatible.
  • Converted to use "ethernet" for switch port to describe connection instead of "dsa-master-port".
  • included ethernet-controller.yaml in nxp,netc-switch.yaml for reusing.

Thanks a lot.

@DerekSnell DerekSnell dismissed their stale review February 5, 2025 17:38

netc-switch binding name addressed

decsny
decsny previously approved these changes Feb 10, 2025
@decsny decsny added this to the v4.1.0 milestone Feb 10, 2025
@decsny
Copy link
Member

decsny commented Feb 10, 2025

@jukkar @rlubos please help visit this PR before 4.1 feature freeze

* check_ll_ether_addr table
*/
if (check_ll_ether_addr(lladst.addr, &eth_filter_l2_addr_base[0][0])) {
return 1;
Copy link
Member

Choose a reason for hiding this comment

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

Please do not return "plain" values here and in the final return, but either NET_OK, NET_CONTINUE or NET_DROP

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

struct sockaddr_ll dst;
struct ethernet_context *ctx = net_if_l2_data(iface);
struct net_eth_hdr *eth_hdr = (struct net_eth_hdr *) buffer;
struct net_eth_hdr *eth_hdr = (struct net_eth_hdr *)buffer;
Copy link
Member

Choose a reason for hiding this comment

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

Could you place the cosmetic changes in this file to a separate commit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Thanks.

Comment on lines 13 to 14
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.0.2"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.168.0.1"
Copy link
Member

Choose a reason for hiding this comment

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

Please use the documentation IPv4 address space here so 192.0.2.2 and 192.0.2.1

Copy link
Member Author

Choose a reason for hiding this comment

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

okay

Fixed style problem for dsa_lldp.c with clang-format.

Signed-off-by: Yangbo Lu <[email protected]>
Current DSA sample is initially for ip_k66f board with a switch PHY,
while it is expected as a common DSA sample for all DSA devices.

This patch does not change any function. It only reworks the sample
with new added CONFIG_NET_SAMPLE_DSA_LLDP for ip_k66f with 3 LAN
ports.
Ideally this should be common for all DSA devices, but for now, ip_k66f
is the only platform supporting it.
As there will be more DSA functions supported, better to allow each
function enablement via option to suit hardware or device driver support
status.

Also improved dsa_ll_addr_switch_cb return value with enum value instead
of plain value.

Signed-off-by: Yangbo Lu <[email protected]>
Moved platform specific options to board.
Also changed IP/Gateway to align documentation.

Signed-off-by: Yangbo Lu <[email protected]>
Added mimxrt1180_evk board support.

Signed-off-by: Yangbo Lu <[email protected]>
@yangbolu1991
Copy link
Member Author

yangbolu1991 commented Feb 11, 2025

Updated to v9 for dsa sample code improvement per @jukkar suggestion . Changes include,

  • Split dsa_lldp.c code style fix-up into seperate patch.
  • Improved dsa_ll_addr_switch_cb enum return value.
  • Aligned dsa sample board config IP/Gateway to document.

Thank you very much.

@yangbolu1991 yangbolu1991 requested a review from jukkar February 11, 2025 09:35
@kartben kartben merged commit 7a22dc9 into zephyrproject-rtos:main Feb 11, 2025
26 checks passed
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.

10 participants