Skip to content

DSA tag protocol support #93010

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion boards/nxp/imx943_evk/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ CPU's UART1 for Cortex-A55, and UART8 for Cortex-M33.
Ethernet
--------

NETC driver supports to manage the Physical Station Interface (PSI).
NETC driver supports to manage the Physical Station Interface (PSI), and TSN switch.
The ENET0, ENETC1, ENETC2 ports could be enabled for M33 by west build option
``-DEXTRA_DTC_OVERLAY_FILE=enetc.overlay``.

The two switch ports could be verified via :zephyr:code-sample:`dsa`.

Programming and Debugging (A55)
*******************************

Expand Down
32 changes: 28 additions & 4 deletions boards/nxp/imx943_evk/imx943_evk_mimx94398_m33.dts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
pinctrl-names = "default";
status = "disabled";

phy0: phy@f {
phy0: phy@2 {
compatible = "ethernet-phy";
reg = <0xf>;
reg = <0x2>;
status = "disabled";
};

phy1: phy@10 {
phy1: phy@3 {
compatible = "ethernet-phy";
reg = <0x10>;
reg = <0x3>;
status = "disabled";
};

Expand Down Expand Up @@ -89,3 +89,27 @@
pinctrl-0 = <&lpuart8_default>;
pinctrl-names = "default";
};

&switch_port0 {
zephyr,random-mac-address;
pinctrl-0 = <&eth0_default>;
pinctrl-names = "default";
phy-handle = <&phy0>;
phy-connection-type = "mii";
status = "disabled";
};

&switch_port1 {
zephyr,random-mac-address;
pinctrl-0 = <&eth1_default>;
pinctrl-names = "default";
phy-handle = <&phy1>;
phy-connection-type = "mii";
status = "disabled";
};

/* Internal port */
&switch_port3 {
zephyr,random-mac-address;
status = "disabled";
};
1 change: 1 addition & 0 deletions drivers/ethernet/dsa/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library_sources_ifdef(CONFIG_DSA_KSZ8XXX dsa_ksz8xxx.c)
zephyr_library_sources_ifdef(CONFIG_DSA_NXP_IMX_NETC dsa_nxp_imx_netc.c)
44 changes: 13 additions & 31 deletions drivers/ethernet/dsa/Kconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Distributed Switch Architecture [DSA] configuration options
# Distributed Switch Architecture [DSA] device configuration options

# Copyright (c) 2020 DENX Software Engineering GmbH
# Lukasz Majewski <lukma@denx.de>
# Copyright 2025 NXP
# SPDX-License-Identifier: Apache-2.0

config ETH_DSA_SUPPORT_DEPRECATED
Expand All @@ -10,25 +11,13 @@ config ETH_DSA_SUPPORT_DEPRECATED
Set by an ethernet driver that supports DSA. This is obsolete,
and only used for legacy dsa device.

menuconfig NET_DSA
bool "Distributed Switch Architecture support"
menuconfig DSA_DRIVERS
bool "Distributed Switch Architecture device drivers"
default y if NET_DSA
help
Enable Distributed Switch Architecture support.

if NET_DSA

config NET_DSA_DEPRECATED
bool "Distributed Switch Architecture support for legacy device"
select DEPRECATED
depends on ETH_DSA_SUPPORT_DEPRECATED
help
This is obsolete, and only used for legacy dsa device.

config DSA_PORT_MAX_COUNT
int "DSA port max count"
default 8
help
Set DSA port max count.
if DSA_DRIVERS

config DSA_KSZ8XXX
bool
Expand Down Expand Up @@ -66,14 +55,6 @@ config DSA_KSZ_TAIL_TAGGING
help
Add support for tail tagging on DSA device.

config DSA_TAG_SIZE
int "DSA tag size in bytes"
default 1 if DSA_KSZ8794 || DSA_KSZ8863 || DSA_KSZ8463
default 0
depends on DSA_KSZ_TAIL_TAGGING
help
Set the DSA tag length in bytes.

config DSA_KSZ_PORT_ISOLATING
bool "Support for ports isolating"
depends on DSA_KSZ8794 || DSA_KSZ8863 || DSA_KSZ8463
Expand All @@ -86,10 +67,11 @@ config DSA_SPI
help
Use SPI bus to communicate with PHY

module = NET_DSA
module-dep = NET_LOG
module-str = Log level for DSA
module-help = Enables core DSA code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"
config DSA_NXP_IMX_NETC
bool "Support for NXP i.MX NETC"
default y
depends on DT_HAS_NXP_NETC_SWITCH_ENABLED
help
Add support for NXP i.MX NETC DSA device driver.

endif # NET_DSA
endif # DSA_DRIVERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ LOG_MODULE_REGISTER(dsa_netc, CONFIG_ETHERNET_LOG_LEVEL);

#include <zephyr/net/ethernet.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/ethernet/nxp_imx_netc.h>

#include "../eth.h"
#include "nxp_imx_netc.h"
#include "fsl_netc_switch.h"

#define DT_DRV_COMPAT nxp_netc_switch
Expand Down Expand Up @@ -128,6 +128,7 @@ static struct dsa_api dsa_netc_api = {
.port_idx = DT_REG_ADDR(port), \
.phy_dev = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(port, phy_handle)), \
.phy_mode = DT_PROP_OR(port, phy_connection_type, ""), \
.tag_proto = DSA_TAG_PROTO_BY_DT(port), \
.ethernet_connection = DEVICE_DT_GET_OR_NULL(DT_PHANDLE(port, ethernet)), \
.prv_config = &dsa_netc_##n##_##port##_config, \
}; \
Expand Down
2 changes: 0 additions & 2 deletions drivers/ethernet/nxp_imx_netc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ if(CONFIG_ETH_NXP_IMX_NETC)
zephyr_library_sources(eth_nxp_imx_netc.c)
zephyr_library_sources(eth_nxp_imx_netc_psi.c)
endif()

zephyr_library_sources_ifdef(CONFIG_DSA_NXP_IMX_NETC dsa_nxp_imx_netc.c)
11 changes: 0 additions & 11 deletions drivers/ethernet/nxp_imx_netc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,3 @@ config ETH_NXP_IMX_RX_RING_BUF_SIZE
store one complete Ethernet frame, and be a multiple of 8.

endif # ETH_NXP_IMX_NETC

if NET_DSA

config DSA_NXP_IMX_NETC
bool "Support for NXP i.MX NETC"
default y
depends on DT_HAS_NXP_NETC_SWITCH_ENABLED
help
Add support for NXP i.MX NETC DSA device driver.

endif
8 changes: 3 additions & 5 deletions drivers/ethernet/nxp_imx_netc/eth_nxp_imx_netc.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ int netc_eth_init_common(const struct device *dev)

int netc_eth_tx(const struct device *dev, struct net_pkt *pkt)
{
const struct netc_eth_config *cfg = dev->config;
struct netc_eth_data *data = dev->data;
netc_buffer_struct_t buff = {.buffer = data->tx_buff, .length = sizeof(data->tx_buff)};
netc_frame_struct_t frame = {.buffArray = &buff, .length = 1};
Expand All @@ -303,6 +302,7 @@ int netc_eth_tx(const struct device *dev, struct net_pkt *pkt)
size_t pkt_len = net_pkt_get_len(pkt);
#if defined(NETC_HAS_NO_SWITCH_TAG_SUPPORT)
struct ethernet_context *eth_ctx = net_if_l2_data(data->iface);
const struct netc_eth_config *cfg = dev->config;
#endif
status_t result;
int ret;
Expand All @@ -314,18 +314,16 @@ int netc_eth_tx(const struct device *dev, struct net_pkt *pkt)

iface_dst = data->iface;

if (cfg->pseudo_mac) {
#if defined(NETC_HAS_NO_SWITCH_TAG_SUPPORT)
if (cfg->pseudo_mac) {
/* DSA conduit port not used */
if (eth_ctx->dsa_port != DSA_CONDUIT_PORT) {
return -ENOSYS;
}
/* DSA driver redirects the iface */
iface_dst = pkt->iface;
#else
return -ENOSYS;
#endif
}
#endif

k_mutex_lock(&data->tx_mutex, K_FOREVER);

Expand Down
2 changes: 1 addition & 1 deletion drivers/ethernet/nxp_imx_netc/eth_nxp_imx_netc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_DRIVERS_ETHERNET_ETH_NXP_IMX_NETC_PRIV_H_
#define ZEPHYR_DRIVERS_ETHERNET_ETH_NXP_IMX_NETC_PRIV_H_

#include "nxp_imx_netc.h"
#include <zephyr/drivers/ethernet/nxp_imx_netc.h>
#include "fsl_netc_endpoint.h"
#include "fsl_msgintr.h"

Expand Down
42 changes: 42 additions & 0 deletions dts/arm/nxp/nxp_imx943_m33.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@
status = "disabled";
};

/* Internal port */
enetc_psi3: ethernet@4cd40000 {
compatible = "nxp,imx-netc-psi";
reg = <0x4cd40000 0x10000>;
mac-index = <3>;
si-index = <3>;
phy-connection-type = "internal";
status = "disabled";
};

netc_ptp_clock0: ptp_clock@4cd80000 {
compatible = "nxp,netc-ptp-clock";
reg = <0x4cd80000 0x10000>;
Expand All @@ -323,6 +333,38 @@
clocks = <&scmi_clk IMX943_CLK_ENET>;
status = "disabled";
};

netc_switch: switch {
compatible = "nxp,netc-switch";
status = "disabled";
#address-cells = <1>;
#size-cells = <0>;

switch_port0: switch_port@0 {
reg = <0>;
status = "disabled";
};

switch_port1: switch_port@1 {
reg = <1>;
status = "disabled";
};

/* Parallel interface is muxed with enetc_psi0. */
switch_port2: switch_port@2 {
reg = <2>;
status = "disabled";
};

/* Internal port */
switch_port3: switch_port@3 {
reg = <3>;
ethernet = <&enetc_psi3>;
phy-connection-type = "internal";
tag-protocol = "netc";
status = "disabled";
};
};
};
};
};
Expand Down
9 changes: 8 additions & 1 deletion dts/bindings/dsa/dsa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
description: DSA Device

child-binding:
description: Properties of slave port
description: Properties of port

include:
- name: pinctrl-device.yaml
Expand All @@ -25,3 +25,10 @@ child-binding:
description:
A phandle to a valid Ethernet device node. This host
device is what the switch port is connected to.
tag-protocol:
type: string
description:
Tag protocol the switch using. Or the switch supports no tag way
if it's not specified on CPU port.
enum:
- "netc"
8 changes: 8 additions & 0 deletions include/zephyr/net/dsa_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ extern "C" {
}; \
DT_INST_FOREACH_CHILD_STATUS_OKAY_VARGS(n, fn, n);

#define DSA_TAG_PROTO_NONE 0
#define DSA_TAG_PROTO_NETC 1

#define DSA_TAG_PROTO_BY_DT(node_id) \
(DT_ENUM_HAS_VALUE(node_id, tag_protocol, netc) ? DSA_TAG_PROTO_NETC : DSA_TAG_PROTO_NONE)

/** DSA switch context data */
struct dsa_switch_context {
/** Pointers to all DSA user network interfaces */
Expand Down Expand Up @@ -137,6 +143,8 @@ struct dsa_port_config {
const struct device *phy_dev;
/** PHY mode */
const char *phy_mode;
/** Tag protocol */
const int tag_proto;
/** Ethernet device connected to the port */
const struct device *ethernet_connection;
/** Instance specific config */
Expand Down
1 change: 1 addition & 0 deletions samples/net/dsa/boards/imx943_evk_mimx94398_m33_ddr.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_NET_SAMPLE_DSA_LLDP=n
39 changes: 39 additions & 0 deletions samples/net/dsa/boards/imx943_evk_mimx94398_m33_ddr.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

&emdio {
status = "okay";

phy0: phy@2 {
status = "okay";
};

phy1: phy@3 {
status = "okay";
};
};

/* Internal port */
&enetc_psi3 {
status = "okay";
};

&netc_switch {
status = "okay";

switch_port0: switch_port@0 {
status = "okay";
};

switch_port1: switch_port@1 {
status = "okay";
};

/* Internal port */
switch_port3: switch_port@3 {
status = "okay";
};
};
1 change: 1 addition & 0 deletions samples/net/dsa/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tests:
- ip_k66f
- mimxrt1180_evk/mimxrt1189/cm33
- mimxrt1180_evk/mimxrt1189/cm7
- imx943_evk/mimx94398/m33/ddr
depends_on: eth
1 change: 1 addition & 0 deletions subsys/net/l2/ethernet/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ module-help = Enables core ARP code to output debug messages.
source "subsys/net/Kconfig.template.log_config.net"
endif # NET_ARP

source "subsys/net/l2/ethernet/dsa/Kconfig"
source "subsys/net/l2/ethernet/gptp/Kconfig"
source "subsys/net/l2/ethernet/lldp/Kconfig"

Expand Down
1 change: 1 addition & 0 deletions subsys/net/l2/ethernet/dsa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ zephyr_library_sources(dsa_core.c)
zephyr_library_sources(dsa_port.c)
zephyr_library_sources(dsa_user.c)
zephyr_library_sources(dsa_tag.c)
zephyr_library_sources_ifdef(CONFIG_DSA_TAG_PROTOCOL_NETC dsa_tag_netc.c)
endif()
Loading
Loading