Skip to content

Introduce new DSA switch framework #87045

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

Merged
merged 11 commits into from
Apr 23, 2025

Conversation

yangbolu1991
Copy link
Contributor

@yangbolu1991 yangbolu1991 commented Mar 13, 2025

This PR is to introduce new DSA switch framework. the RFC for new DSA architecuture is at discussion: #87091

This PR is first update according to new DSA arthiteture in RFC, the purpose and changes are as below.
Also a basic doc is added in patch
45bf638

- Aligned to Linux DSA framework which has been already mature framework
  for many years, For now in zephyr, the DSA compoenents were splited
  as: switch, port, master(not need driver file for now), slave, and tag.
  Seperated drivers were used for maintaining and developing new
  features.

- The unified dts bindings (aligned to linux) were supported. The port
  driver would parse DTS to decide the port type (master port, slave
  port, or cpu port) to set up the switch. All the ports registered as
  standard ethernet devices. (dsa port and dsa switch tree was not
  supported.)

- How to add DSA device driver based on the framework? Following dts bindings to describe
  the switch device, all the device driver needing to do is providing dsa_api implementaion and private
  data, and calling below initialization.

    DSA_INIT_INSTANCE(n, _dapi, data)

- For switch tag case, recv/xmit helpers in dsa_api could be used for
  taging/untagging. No modified ethernet drivers.
  For no-tag type case, ethernet driver of master port should support
  packet injection/extraction for slave ports leaving NULL recv/xmit.

The dsa_nxp_imx_netc.c driver will be the first example of the new DSA
framework.

The future work for DSA will be supporting bridge for ports. We may align
Linux to give users two options to use DSA device:

- Standalone mode: the switch ports work as regular ethernet ports.

- Bridge mode: switch mode with virtual bridge device which could be
  assigned IP address.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Mar 13, 2025

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.

Copy link
Collaborator

@lmajewski lmajewski left a comment

Choose a reason for hiding this comment

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

@yangbolu1991 - Thank you for your work put to port relevant pieces of Linux DSA driver to Zephyr.

Generally, for me the code looks OK. It is also great that you added the detailed documentation for DSA subsystem to Zephyr.

Currently the https://docs.zephyrproject.org/latest/boards/segger/ip_k66f/doc/index.html board (including its sample LLDP protocol program) uses the NET_DSA_LEGACY but I think that it shall finally support the new framework.

| Switch |
|+------+ +------+ +------+ +------+|
|| swp0 | | swp1 | | swp2 | | swp3 ||
++------+-+------+-+------+-+------++
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could the rx/tx diagram in #87091, but not use this diagram which is from Linux kernel document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, will replace it.
Thanks.

/*
* Copyright (c) 2018 Intel Corporation
* Copyright 2025 NXP
Copy link
Collaborator

Choose a reason for hiding this comment

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

According to our discussion, let's add a "dsa_" prefix in order to follow the same naming rules in Zephyr driver, for example, use "dsa_core.c dsa_port.c dsa_salve.c ..."

Another suggestion, in order to make the old architectrue code and new architecuture code works simulteneously in new architecuture developing period, let's don't modify the old file directly, we could create new architeccture code in each new clean file, so that we could define which files can be compiled in cmake according to CONFIG_NET_DSA_DEPRECATED.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. That will make code much clear. Will do that.
Thank you very much.

@yangbolu1991
Copy link
Contributor Author

Rebased to trigger CI.

JiafeiPan
JiafeiPan previously approved these changes Apr 21, 2025
jukkar
jukkar previously approved these changes Apr 22, 2025
maass-hamburg
maass-hamburg previously approved these changes Apr 22, 2025
@kartben kartben requested a review from Copilot April 22, 2025 11:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new DSA switch framework for Zephyr aligned with the Linux DSA model. Key changes include updating header files and typedefs to use the new DSA naming (e.g. “user” and “conduit” instead of “slave” and “master”), adding a new dsa_core.h for DSA core APIs, and updating DTS bindings and Ethernet drivers (including nxp_imx_netc, eth_stm32_hal, and eth_nxp_enet) to support the new framework.

Reviewed Changes

Copilot reviewed 32 out of 41 changed files in this pull request and generated no comments.

Show a summary per file
File Description
include/zephyr/net/ethernet.h Adjusted conditional inclusion and renamed DSA port enums to reflect new architecture.
include/zephyr/net/dsa_core.h Introduces core DSA framework interfaces and data structures.
dts/bindings/dsa/*.yaml Unifies DTS bindings for DSA by including a common dsa.yaml file.
drivers/ethernet/nxp_imx_netc/* Updated NETC driver code to use new DSA handling, including revised Tx descriptor reclamation and DSA port handling.
drivers/ethernet/dsa/dsa_ksz8xxx.c Updated capability bit masks to align with new DSA port naming.
drivers/ethernet/eth_stm32_hal.c, eth_nxp_enet.c Updated usage of DSA conditional compilation to use CONFIG_NET_DSA_DEPRECATED for backward compatibility.
Files not reviewed (9)
  • boards/nxp/mimxrt1180_evk/mimxrt1180_evk.dtsi: Language not supported
  • doc/connectivity/networking/dsa.rst: Language not supported
  • doc/connectivity/networking/index.rst: Language not supported
  • doc/releases/migration-guide-4.2.rst: Language not supported
  • drivers/ethernet/Kconfig.nxp_enet: Language not supported
  • drivers/ethernet/Kconfig.sam_gmac: Language not supported
  • drivers/ethernet/Kconfig.stm32_hal: Language not supported
  • drivers/ethernet/dsa/Kconfig: Language not supported
  • drivers/ethernet/nxp_imx_netc/Kconfig: Language not supported

Copy link
Collaborator

@kartben kartben left a comment

Choose a reason for hiding this comment

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

some comments related to docs.
Also, did was this presented/discussed in the Architecture WG?

/**
* @brief Distributed Switch Architecture (DSA)
* @defgroup dsa_core Distributed Switch Architecture (DSA)
* @since 2.5
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks wrong?

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 once hesitated to use 2.5 or not previously, as the legacy dsa.h existed.
Let me use 4.2 I think it makes sense since it's new file added.
Thanks.

Comment on lines 71 to 72
- ``DSA_SWITCH_INST_INIT(n, _dapi, data, fn)``
- ``DSA_PORT_INST_INIT(port, n, cfg)``
Copy link
Collaborator

Choose a reason for hiding this comment

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

if these macros are API please don't put them in a hidden Doxygen block. Also, please cross reference them using :c:macro: role

Copy link
Contributor Author

@yangbolu1991 yangbolu1991 Apr 23, 2025

Choose a reason for hiding this comment

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

Okay, will do that.
I put it in hidden doxygen block was because I thought it's used only by drivers. And the doc was describing device driver support.
Let me move them and related structures out. I think maybe it's better for device driver developer to understand and for cross reference.
Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

please review the entire file for Doxygen comments. It looks like you have put a lot more as "internal" stuff as you may have orginally intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right... I had intended to hidden most.
But let me expose APIs/structure related to device driver support. That may be useful for device driver developer to read doc.
Thanks.

- ``DSA_SWITCH_INST_INIT(n, _dapi, data, fn)``
- ``DSA_PORT_INST_INIT(port, n, cfg)``

.. code-block:: console
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.. code-block:: console
.. code-block:: c

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix, thanks!

This is copied from Linux DSA documentation. It applies to zephyr too. Although conduit port and
cpu port exposed as ethernet device in zephyr, they are not able to be used.

.. code-block:: console
Copy link
Collaborator

Choose a reason for hiding this comment

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

??

maybe you meant .. note::

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix, thanks!

@dleach02
Copy link
Member

some comments related to docs. Also, did was this presented/discussed in the Architecture WG?

It was discussed in the Networking WG meeting on 4/14. The meeting was recorded.

yangbolu1991 and others added 8 commits April 23, 2025 15:44
The new DSA framework purpose and changes are as below.

- Aligned to Linux DSA framework which has been already mature framework
  for many years, For now in zephyr, the DSA components were splited
  as: switch, port, master(not need driver file for now), slave, and tag.
  Seperated drivers were used for maintaining and developing new
  features.

- The unified dts bindings (aligned to linux) were supported. The port
  driver would parse DTS to decide the port type (master port, slave
  port, or cpu port) to set up the switch. All the ports registered as
  standard ethernet devices. (dsa port and dsa switch tree was not
  supported.)

- How to add DSA device driver based on the framework? All the device
  driver needing to do is providing dsa_spi implementation and private
  data, and calling below initialization.

    DSA_INIT_INSTANCE(n, _dapi, data)

- For switch tag case, recv/xmit helpers in dsa_api could be used for
  taging/untagging. No modified ethernet drivers.
  For no-tag type case, ethernet driver of master port should support
  packet injection/extraction for slave ports leaving NULL recv/xmit.

The dsa_nxp_imx_netc.c driver will be the first example of the new DSA
framework.

The future work for DSA will be supporting bridge for ports. We may align
Linux to give users two options to use DSA device:

- Standalone mode: the switch ports work as regular ethernet ports.

- Bridge mode: switch mode with virtual bridge device which could be
  assigned IP address.

Signed-off-by: Yangbo Lu <[email protected]>
Added DSA document.

Signed-off-by: Yangbo Lu <[email protected]>
Added support for no-tag type DSA conduit.

Signed-off-by: Yangbo Lu <[email protected]>
Adapted to use new DSA framework. And related platforms converted
in samples too.

Signed-off-by: Yangbo Lu <[email protected]>
Converted to use random mac addresses for switch.

Signed-off-by: Yangbo Lu <[email protected]>
Renamed master/slave to conduit/user.

Signed-off-by: Yangbo Lu <[email protected]>
Converted to new dsa core driver. And adapted mimxrt1180_evk to it.

Signed-off-by: Yangbo Lu <[email protected]>
Enable DHCPv4 when network interface goes up. This makes it easier
to test IP connectivity with DSA.

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

Updated to v8. Changes includes,

  • Fixed documentation (dsa.rst and dsa_core.h) per @kartben suggestion.

Thanks a lot.

@maass-hamburg maass-hamburg requested a review from kartben April 23, 2025 15:55
@kartben kartben merged commit c09ec58 into zephyrproject-rtos:main Apr 23, 2025
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.