[PATCH net-next v2 3/8] net: xilinx: tsn: add endpoint MAC driver skeleton
From: Srinivas Neeli <srinivas.neeli@amd.com>
Date: 2026-09-08 19:20:32
Also in:
linux-arm-kernel, linux-devicetree, linux-rt-devel, lkml
Subsystem:
networking drivers, the rest · Maintainers:
Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds
The TSN Endpoint MAC owns the IP's host-side MCDMA data path and is the netdev physically wired to the CPU. The DSA switch needs this netdev to exist as its conduit. Add a platform driver (compatible "xlnx,tsn-ep-mac") for the endpoint. Register the netdev named "ep", set its MAC address, and provide minimal netdev and ethtool ops. ndo_open starts the queues and ndo_start_xmit drops frames. Co-developed-by: Nagadheeraj Rottela <redacted> Signed-off-by: Nagadheeraj Rottela <redacted> Signed-off-by: Srinivas Neeli <srinivas.neeli@amd.com> --- Changes in v2: - Name the netdev ep%d with NET_NAME_ENUM instead of a fixed "ep", so a second IP instance does not clash on register_netdev(). The %d enumeration is what NET_NAME_ENUM describes, and it matches the eth%d naming in net/dsa/user.c. - Drop the mapped but unused register window (ep->regs and its ioremap). It was intended for QBV support, which is not part of this series, so the endpoint driver does not use it. The mapping will be re-added when QBV support lands. - Use dev_kfree_skb_any() on the drop path, not dev_kfree_skb(). - Drop the mod_devicetable.h include, platform_device.h already pulls it in. --- drivers/net/ethernet/xilinx/tsn/Makefile | 2 +- drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h | 15 +++ drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c | 143 ++++++++++++++++++++++ drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c | 3 + 4 files changed, 162 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/xilinx/tsn/Makefile b/drivers/net/ethernet/xilinx/tsn/Makefile
index 6f99226f3dc8..5886828b386f 100644
--- a/drivers/net/ethernet/xilinx/tsn/Makefile
+++ b/drivers/net/ethernet/xilinx/tsn/Makefile@@ -1,2 +1,2 @@ obj-$(CONFIG_XILINX_TSN) += xilinx_tsn.o -xilinx_tsn-y := xilinx_tsn_main.o +xilinx_tsn-y := xilinx_tsn_main.o xilinx_tsn_ep.o
diff --git a/drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h
new file mode 100644
index 000000000000..b0757e22d1fd
--- /dev/null
+++ b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * AMD/Xilinx TSN Endpoint Ethernet MAC driver, shared definitions. + * + * Copyright (C) 2026 Advanced Micro Devices, Inc. + */ + +#ifndef _XILINX_TSN_H +#define _XILINX_TSN_H + +#include <linux/platform_device.h> + +extern struct platform_driver xlnx_tsn_ep_driver; + +#endif /* _XILINX_TSN_H */
diff --git a/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c
new file mode 100644
index 000000000000..089f17a126f5
--- /dev/null
+++ b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c@@ -0,0 +1,143 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * AMD/Xilinx TSN Endpoint MAC driver. + * + * Copyright (C) 2026 Advanced Micro Devices, Inc. + */ + +#include <linux/etherdevice.h> +#include <linux/ethtool.h> +#include <linux/if_ether.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netdevice.h> +#include <linux/of.h> +#include <linux/of_net.h> +#include <linux/platform_device.h> +#include <linux/string.h> +#include <linux/types.h> + +#include "xilinx_tsn.h" + +#define DRIVER_NAME "xilinx_tsn_ep" + +/** + * struct xlnx_tsn_ep - EP MAC private data, embedded in net_device priv area + * @ndev: the conduit netdev ("ep0" for the first IP instance) + * @dev: backing device + */ +struct xlnx_tsn_ep { + struct net_device *ndev; + struct device *dev; +}; + +static netdev_tx_t ep_start_xmit(struct sk_buff *skb, struct net_device *ndev) +{ + dev_kfree_skb_any(skb); + DEV_STATS_INC(ndev, tx_dropped); + return NETDEV_TX_OK; +} + +static int ep_open(struct net_device *ndev) +{ + netif_tx_start_all_queues(ndev); + + return 0; +} + +static int ep_stop(struct net_device *ndev) +{ + netif_tx_disable(ndev); + + return 0; +} + +static void ep_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *ed) +{ + strscpy(ed->driver, DRIVER_NAME, sizeof(ed->driver)); +} + +static const struct net_device_ops ep_netdev_ops = { + .ndo_open = ep_open, + .ndo_stop = ep_stop, + .ndo_start_xmit = ep_start_xmit, + .ndo_validate_addr = eth_validate_addr, + .ndo_set_mac_address = eth_mac_addr, +}; + +static const struct ethtool_ops ep_ethtool_ops = { + .get_drvinfo = ep_get_drvinfo, +}; + +static int xlnx_tsn_ep_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct net_device *ndev; + struct xlnx_tsn_ep *ep; + u8 mac_addr[ETH_ALEN]; + int ret; + + ndev = alloc_netdev(sizeof(*ep), "ep%d", NET_NAME_ENUM, ether_setup); + if (!ndev) + return -ENOMEM; + + SET_NETDEV_DEV(ndev, dev); + ndev->netdev_ops = &ep_netdev_ops; + ndev->ethtool_ops = &ep_ethtool_ops; + ndev->features = NETIF_F_SG; + + ep = netdev_priv(ndev); + ep->ndev = ndev; + ep->dev = dev; + + ret = of_get_mac_address(dev->of_node, mac_addr); + if (ret == -EPROBE_DEFER) { + goto err_free_ndev; + } else if (!ret && is_valid_ether_addr(mac_addr)) { + eth_hw_addr_set(ndev, mac_addr); + } else { + eth_hw_addr_random(ndev); + dev_info(dev, "no valid MAC in DT, using random address %pM\n", + ndev->dev_addr); + } + + platform_set_drvdata(pdev, ep); + + ret = register_netdev(ndev); + if (ret) { + dev_err_probe(dev, ret, "failed to register net device\n"); + goto err_free_ndev; + } + + return 0; + +err_free_ndev: + free_netdev(ndev); + return ret; +} + +static void xlnx_tsn_ep_remove(struct platform_device *pdev) +{ + struct xlnx_tsn_ep *ep = platform_get_drvdata(pdev); + + if (!ep) + return; + + unregister_netdev(ep->ndev); + free_netdev(ep->ndev); +} + +static const struct of_device_id xlnx_tsn_ep_of_match[] = { + { .compatible = "xlnx,tsn-ep-mac" }, + { } +}; +MODULE_DEVICE_TABLE(of, xlnx_tsn_ep_of_match); + +struct platform_driver xlnx_tsn_ep_driver = { + .probe = xlnx_tsn_ep_probe, + .remove = xlnx_tsn_ep_remove, + .driver = { + .name = DRIVER_NAME, + .of_match_table = xlnx_tsn_ep_of_match, + }, +};
diff --git a/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c
index afe7609c67fb..d33a00dd6d15 100644
--- a/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c
+++ b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c@@ -15,6 +15,8 @@ #include <linux/slab.h> #include <linux/types.h> +#include "xilinx_tsn.h" + #define TSN_NUM_CLOCKS 6 /**
@@ -85,6 +87,7 @@ static struct platform_driver tsn_driver = { static struct platform_driver * const tsn_drivers[] = { &tsn_driver, + &xlnx_tsn_ep_driver, }; static int __init xlnx_tsn_init(void)
--
2.43.0