[PATCH 03/20] net: xilinx: tsn: add endpoint MAC driver skeleton
Nagadheeraj Rottela <[email protected]>
| Newsgroups | org.kernel.vger.linux-devicetree,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.kernel.vger.netdev |
|---|---|
| Message-ID | <[email protected]> |
From: Srinivas Neeli <[email protected]> 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. This skeleton handles device bring-up only, with no data path yet. So ndo_open just starts the queues and ndo_start_xmit drops frames. Signed-off-by: Srinivas Neeli <[email protected]> Co-developed-by: Nagadheeraj Rottela <[email protected]> Signed-off-by: Nagadheeraj Rottela <[email protected]> --- drivers/net/ethernet/xilinx/tsn/Makefile | 2 +- drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h | 15 ++ .../net/ethernet/xilinx/tsn/xilinx_tsn_ep.c | 152 ++++++++++++++++++ .../net/ethernet/xilinx/tsn/xilinx_tsn_main.c | 3 + 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/xilinx/tsn/xilinx_tsn.h create mode 100644 drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c 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..9b556edf5423 --- /dev/null +++ b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_ep.c @@ -0,0 +1,152 @@ +// 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/mod_devicetable.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 ("ep") + * @dev: backing device + * @regs: EP MAC register window + */ +struct xlnx_tsn_ep { + struct net_device *ndev; + struct device *dev; + void __iomem *regs; +}; + +static netdev_tx_t ep_start_xmit(struct sk_buff *skb, struct net_device *ndev) +{ + dev_kfree_skb(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", NET_NAME_UNKNOWN, 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; + + ep->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(ep->regs)) { + ret = PTR_ERR(ep->regs); + goto err_free_ndev; + } + + 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 1ef1b0c2ee6e..3df8c026741f 100644 --- a/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c +++ b/drivers/net/ethernet/xilinx/tsn/xilinx_tsn_main.c @@ -16,6 +16,8 @@ #include <linux/slab.h> #include <linux/types.h> +#include "xilinx_tsn.h" + #define TSN_NUM_CLOCKS 6 /** @@ -86,6 +88,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.34.1