Thread View: linux.kernel.netdev
7 messages
7 total messages
Started by "Xin Tian"
Thu, 26 Nov 2026 14:57
[PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver
Author: "Xin Tian"
Date: Thu, 26 Nov 2026 14:57
Date: Thu, 26 Nov 2026 14:57
142 lines
16375 bytes
16375 bytes
This is the first series of v2 for the Yunsilicon XSC converged network
adapter (PCI vendor 0x1f67). Responding to the review of v1, this is a
much smaller, self-contained ethernet-only driver: about 5.7k added
lines, down from the combined ethernet and RDMA driver in v1.
The driver is split into the same two modules as before, which share the
xsc prefix and talk over the auxiliary bus:
1. xsc_pci (CONFIG_YUNSILICON_XSC_PCI) - the PCI core driver. Owns the
PCI function, the command queue, the event queues, MSI-X and the
CQ/QP resource pools, and publishes one auxiliary device per PF.
Patches 01-06.
2. xsc_eth (CONFIG_YUNSILICON_XSC_ETH) - the ethernet driver. Binds to
the auxiliary device, registers the netdev, brings up a single TX/RX
queue pair with NAPI and page_pool, and tracks the link state from
the port events. Patches 07-11.
Patch 01 adds the MAINTAINERS entry together with the Kbuild plumbing.
To keep the series within the requested size, this first series
deliberately omits RDMA, statistics, offloads (TSO/checksum), RSS and the
configuration interfaces (ethtool, module parameters, ndo_change_mtu).
Only the compressed-BAR PF form of the hardware is supported. These will
be submitted as follow-up series once the base driver is accepted.
The series is split so that every patch builds cleanly with GCC 8.3.1 and
W=1. The core patches add the command queue, capabilities, event queues
and resource pools incrementally, and the ethernet patches register the
netdev first, then add the channel and link handling, and finally the TX
and RX data paths.
Changes since v1:
- Split the combined ethernet+RDMA driver into a minimal ethernet-only
first series, about 5.7k added lines instead of 10k, as requested.
Addressing the netdev review of the v1 netdev patch:
- Register the link event handler before register_netdevice(), keying the
interface off xdev->eth_priv which is set before registration.
- Use ether_addr_copy() to copy the firmware MAC address.zaizuo
- Drop the unreachable NULL checks in the remove path.
- Move xsc_cqwq_get_cqe() out of the header into xsc_eth_txrx.c.
- Drop the unreachable "already opened"/"not opened" branches in
ndo_open()/ndo_stop(); the netdev core serialises these via rtnl.
- Keep xsc_set_port_admin_status() void: it runs after open/close, a
rejected call is legitimate (VF, port_link_en, multi-function
arbitration, old firmware), and the real carrier comes from the link
events and QUERY_VPORT_STATE, so we log and carry on.
Xin Tian (11):
net/xsc: add Yunsilicon XSC ethernet PCI driver skeleton
net/xsc: add doorbell and cmdq MMIO accessors
net/xsc: add the command queue
net/xsc: query HCA capabilities and reset function resources
net/xsc: add event queues and MSI-X
net/xsc: add CQ and QP helpers
net/xsc: add the ethernet netdev
net/xsc: add the single TX/RX channel
net/xsc: report link state changes
net/xsc: add the transmit path
net/xsc: add the receive path
MAINTAINERS | 7 +
drivers/net/ethernet/Kconfig | 1 +
drivers/net/ethernet/Makefile | 1 +
drivers/net/ethernet/yunsilicon/Kconfig | 27 +
drivers/net/ethernet/yunsilicon/Makefile | 9 +
.../ethernet/yunsilicon/xsc/common/xsc_cmd.h | 560 ++++++++
.../ethernet/yunsilicon/xsc/common/xsc_core.h | 311 +++++
.../ethernet/yunsilicon/xsc/common/xsc_reg.h | 23 +
.../net/ethernet/yunsilicon/xsc/net/Kconfig | 17 +
.../net/ethernet/yunsilicon/xsc/net/Makefile | 9 +
.../net/ethernet/yunsilicon/xsc/net/main.c | 1161 +++++++++++++++++
.../net/ethernet/yunsilicon/xsc/net/xsc_eth.h | 33 +
.../yunsilicon/xsc/net/xsc_eth_common.h | 117 ++
.../ethernet/yunsilicon/xsc/net/xsc_eth_rx.c | 210 +++
.../ethernet/yunsilicon/xsc/net/xsc_eth_tx.c | 87 ++
.../yunsilicon/xsc/net/xsc_eth_txrx.c | 95 ++
.../yunsilicon/xsc/net/xsc_eth_txrx.h | 36 +
.../ethernet/yunsilicon/xsc/net/xsc_eth_wq.c | 80 ++
.../ethernet/yunsilicon/xsc/net/xsc_eth_wq.h | 150 +++
.../ethernet/yunsilicon/xsc/net/xsc_queue.h | 103 ++
.../net/ethernet/yunsilicon/xsc/pci/Kconfig | 16 +
.../net/ethernet/yunsilicon/xsc/pci/Makefile | 9 +
.../net/ethernet/yunsilicon/xsc/pci/adev.c | 133 ++
.../net/ethernet/yunsilicon/xsc/pci/adev.h | 14 +
.../net/ethernet/yunsilicon/xsc/pci/alloc.c | 225 ++++
.../net/ethernet/yunsilicon/xsc/pci/alloc.h | 18 +
drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c | 708 ++++++++++
drivers/net/ethernet/yunsilicon/xsc/pci/cmd.h | 87 ++
drivers/net/ethernet/yunsilicon/xsc/pci/cq.c | 130 ++
drivers/net/ethernet/yunsilicon/xsc/pci/cq.h | 13 +
.../ethernet/yunsilicon/xsc/pci/doorbell.c | 148 +++
drivers/net/ethernet/yunsilicon/xsc/pci/eq.c | 300 +++++
drivers/net/ethernet/yunsilicon/xsc/pci/eq.h | 38 +
.../net/ethernet/yunsilicon/xsc/pci/main.c | 282 ++++
.../net/ethernet/yunsilicon/xsc/pci/pci_irq.c | 345 +++++
.../net/ethernet/yunsilicon/xsc/pci/pci_irq.h | 16 +
drivers/net/ethernet/yunsilicon/xsc/pci/qp.c | 180 +++
drivers/net/ethernet/yunsilicon/xsc/pci/qp.h | 14 +
.../net/ethernet/yunsilicon/xsc/pci/vport.c | 36 +
39 files changed, 5749 insertions(+)
create mode 100644 drivers/net/ethernet/yunsilicon/Kconfig
create mode 100644 drivers/net/ethernet/yunsilicon/Makefile
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_cmd.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/Makefile
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/main.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_rx.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/alloc.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cmd.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cmd.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cq.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/cq.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/doorbell.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/eq.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/eq.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/main.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/qp.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/qp.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/vport.c
--
2.43.0
[PATCH v2 07/11] net/xsc: add the ethernet netdev
Author: "Xin Tian"
Date: Thu, 26 Nov 2026 14:57
Date: Thu, 26 Nov 2026 14:57
1109 lines
37460 bytes
37460 bytes
Register the ethernet auxiliary driver and set up the netdev: create the
device, program the MAC address and MTU, and wire up open/close. The
queue and data path are added in follow-up patches, so the interface is
created without a channel to move packets yet.
The netdev has no ndo_start_xmit until the transmit patch lands, so it
must not be brought up in this state.
Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
drivers/net/ethernet/yunsilicon/Kconfig | 1 +
drivers/net/ethernet/yunsilicon/Makefile | 1 +
.../ethernet/yunsilicon/xsc/common/xsc_core.h | 73 +++++
.../net/ethernet/yunsilicon/xsc/net/Kconfig | 17 ++
.../net/ethernet/yunsilicon/xsc/net/Makefile | 9 +
.../net/ethernet/yunsilicon/xsc/net/main.c | 263 ++++++++++++++++++
.../net/ethernet/yunsilicon/xsc/net/xsc_eth.h | 33 +++
.../yunsilicon/xsc/net/xsc_eth_common.h | 116 ++++++++
.../ethernet/yunsilicon/xsc/net/xsc_eth_wq.h | 150 ++++++++++
.../ethernet/yunsilicon/xsc/net/xsc_queue.h | 103 +++++++
.../net/ethernet/yunsilicon/xsc/pci/Makefile | 2 +-
.../net/ethernet/yunsilicon/xsc/pci/adev.c | 133 +++++++++
.../net/ethernet/yunsilicon/xsc/pci/adev.h | 14 +
.../net/ethernet/yunsilicon/xsc/pci/main.c | 10 +
14 files changed, 924 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/Makefile
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/main.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/pci/adev.h
diff --git a/drivers/net/ethernet/yunsilicon/Kconfig b/drivers/net/ethernet/yunsilicon/Kconfig
index ffdfdf4bf..231661a4a 100644
--- a/drivers/net/ethernet/yunsilicon/Kconfig
+++ b/drivers/net/ethernet/yunsilicon/Kconfig
@@ -22,5 +22,6 @@ config NET_VENDOR_YUNSILICON
if NET_VENDOR_YUNSILICON
source "drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig"
+source "drivers/net/ethernet/yunsilicon/xsc/net/Kconfig"
endif # NET_VENDOR_YUNSILICON
diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
index b2924ccaf..54a3122fe 100644
--- a/drivers/net/ethernet/yunsilicon/Makefile
+++ b/drivers/net/ethernet/yunsilicon/Makefile
@@ -6,3 +6,4 @@
#
obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
+obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc/net/
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
index 7a74f860c..74cd5b66f 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -7,6 +7,7 @@
#define __XSC_CORE_H
#include <linux/pci.h>
+#include <linux/auxiliary_bus.h>
#include <linux/bitfield.h>
#include <linux/completion.h>
#include <linux/interrupt.h>
@@ -31,6 +32,8 @@
#define XSC_PAGE_SHIFT_4K 12
#define XSC_PAGE_SIZE_4K (_AC(1, UL) << XSC_PAGE_SHIFT_4K)
+#define XSC_INVALID_LKEY 0x100
+
struct xsc_caps {
u32 max_cqes;
u32 send_ds_num;
@@ -47,6 +50,25 @@ enum {
XSC_MAX_IRQ_NAME = 32
};
+/* adev */
+#define XSC_PCI_DRV_NAME "xsc_pci"
+#define XSC_ETH_ADEV_NAME "eth"
+
+enum {
+ XSC_QUEUE_TYPE_RAW = 2,
+ XSC_QUEUE_TYPE_RAW_TSO = 6,
+};
+
+enum xsc_adev_idx {
+ XSC_ADEV_IDX_ETH,
+ XSC_ADEV_IDX_MAX,
+};
+
+struct xsc_adev {
+ struct auxiliary_device adev;
+ struct xsc_core_device *xdev;
+};
+
/* alloc */
struct xsc_buf_list {
void *buf;
@@ -62,6 +84,54 @@ struct xsc_buf {
unsigned long size;
};
+struct xsc_frag_buf {
+ struct xsc_buf_list *frags;
+ unsigned long npages;
+ unsigned long size;
+ u8 page_shift;
+};
+
+struct xsc_frag_buf_ctrl {
+ struct xsc_buf_list *frags;
+ u32 sz_m1;
+ u16 frag_sz_m1;
+ u16 strides_offset;
+ u8 log_sz;
+ u8 log_stride;
+ u8 log_frag_strides;
+};
+
+/* wqe */
+struct xsc_send_wqe_ctrl_seg {
+ __le32 data0;
+ __le32 msg_len;
+ __le32 data2;
+ __le32 data3;
+};
+
+struct xsc_wqe_data_seg {
+ __le32 data0;
+ __le32 mkey;
+ __le64 va;
+};
+
+#define XSC_WQE_DATA_SEG_DATA0_SEG_LEN_MASK GENMASK(31, 1)
+
+/* cqe */
+struct xsc_cqe {
+ __le32 data0;
+ __le32 imm_data;
+ __le32 msg_len;
+ __le32 vni;
+ __le64 data2;
+ u8 placeholder2;
+ u8 rsv3;
+ __le16 rsv[1];
+ __le32 data1;
+};
+
+#define XSC_CQE_DATA1_OWNER BIT(31)
+
/* eq */
struct xsc_eq {
struct xsc_core_device *dev;
@@ -136,6 +206,9 @@ struct xsc_cmd;
struct xsc_core_device {
struct pci_dev *pdev;
struct device *device;
+ int adev_id;
+ struct xsc_adev **xsc_adev_list;
+ void *eth_priv;
/* async event plumbing, owned by the PCI layer */
struct work_struct event_work;
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig b/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
new file mode 100644
index 000000000..7428b2629
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+# All rights reserved.
+# Yunsilicon driver configuration
+#
+
+config YUNSILICON_XSC_ETH
+ tristate "Yunsilicon XSC ethernet driver"
+ depends on YUNSILICON_XSC_PCI
+ depends on NET
+ select PAGE_POOL
+ help
+ This driver provides ethernet support for
+ Yunsilicon XSC devices.
+
+ To compile this driver as a module, choose M here. The module
+ will be called xsc_eth.
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/Makefile b/drivers/net/ethernet/yunsilicon/xsc/net/Makefile
new file mode 100644
index 000000000..db289d974
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+# All rights reserved.
+
+ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
+
+obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc_eth.o
+
+xsc_eth-y := main.o
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
new file mode 100644
index 000000000..b9e75d7e1
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
@@ -0,0 +1,263 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/auxiliary_bus.h>
+#include <linux/irq.h>
+
+#include "common/xsc_core.h"
+#include "common/xsc_cmd.h"
+#include "xsc_eth_common.h"
+#include "xsc_eth.h"
+
+static void xsc_eth_build_nic_params(struct xsc_adapter *adapter)
+{
+ struct xsc_eth_params *params = &adapter->nic_param;
+
+ params->mtu = SW_DEFAULT_MTU;
+}
+
+static void xsc_eth_netdev_init(struct xsc_adapter *adapter)
+{
+ netif_carrier_off(adapter->netdev);
+}
+
+static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
+ enum xsc_port_status status)
+{
+ struct xsc_event_set_port_admin_status_mbox_out out;
+ struct xsc_event_set_port_admin_status_mbox_in in = {};
+ int err;
+
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_SET_PORT_ADMIN_STATUS);
+ in.status = cpu_to_be16(status);
+
+ err = xsc_cmd_exec(adapter->xdev, &in, sizeof(in), &out, sizeof(out));
+ if (err)
+ netdev_err(adapter->netdev,
+ "failed to set port admin status %s, err=%d\n",
+ status == XSC_PORT_UP ? "up" : "down", err);
+}
+
+static int xsc_eth_open(struct net_device *netdev)
+{
+ struct xsc_adapter *adapter = netdev_priv(netdev);
+
+ adapter->opened = true;
+
+ xsc_set_port_admin_status(adapter, XSC_PORT_UP);
+
+ return 0;
+}
+
+static int xsc_eth_close(struct net_device *netdev)
+{
+ struct xsc_adapter *adapter = netdev_priv(netdev);
+
+ adapter->opened = false;
+
+ netif_carrier_off(adapter->netdev);
+
+ xsc_set_port_admin_status(adapter, XSC_PORT_DOWN);
+
+ return 0;
+}
+
+static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
+ u16 mtu, u16 rx_buf_sz)
+{
+ struct xsc_set_mtu_mbox_out out;
+ struct xsc_set_mtu_mbox_in in;
+ int err;
+
+ memset(&in, 0, sizeof(struct xsc_set_mtu_mbox_in));
+ memset(&out, 0, sizeof(struct xsc_set_mtu_mbox_out));
+
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_SET_MTU);
+ in.mtu = cpu_to_be16(mtu);
+ in.rx_buf_sz_min = cpu_to_be16(rx_buf_sz);
+ in.mac_port = xdev->mac_port;
+
+ err = xsc_cmd_exec(xdev, &in, sizeof(struct xsc_set_mtu_mbox_in), &out,
+ sizeof(struct xsc_set_mtu_mbox_out));
+ if (err) {
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "failed to set hw_mtu=%u rx_buf_sz=%u, err=%d, status=%d\n",
+ mtu, rx_buf_sz, err, out.hdr.status);
+ return err;
+ }
+
+ return 0;
+}
+
+static const struct net_device_ops xsc_netdev_ops = {
+ .ndo_open = xsc_eth_open,
+ .ndo_stop = xsc_eth_close,
+};
+
+static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
+{
+ struct net_device *netdev = adapter->netdev;
+
+ netdev->netdev_ops = &xsc_netdev_ops;
+
+ netdev->min_mtu = SW_DEFAULT_MTU;
+ netdev->max_mtu = SW_DEFAULT_MTU;
+ netdev->mtu = SW_DEFAULT_MTU;
+}
+
+static int xsc_eth_nic_init(struct xsc_adapter *adapter)
+{
+ xsc_eth_build_nic_params(adapter);
+ xsc_eth_netdev_init(adapter);
+ xsc_eth_build_nic_netdev(adapter);
+
+ return 0;
+}
+
+static int xsc_eth_get_mac(struct xsc_core_device *xdev, char *mac)
+{
+ struct xsc_query_eth_mac_mbox_out *out;
+ struct xsc_query_eth_mac_mbox_in in;
+ int err;
+
+ out = kzalloc_obj(*out, GFP_KERNEL);
+ if (!out)
+ return -ENOMEM;
+
+ memset(&in, 0, sizeof(in));
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_QUERY_ETH_MAC);
+
+ err = xsc_cmd_exec(xdev, &in, sizeof(in), out, sizeof(*out));
+ if (err || out->hdr.status) {
+ netdev_warn(xsc_dev_to_netdev(xdev),
+ "get mac failed! err=%d, out.status=%u\n",
+ err, out->hdr.status);
+ err = -ENOEXEC;
+ goto exit;
+ }
+
+ ether_addr_copy(mac, out->mac);
+ netdev_dbg(xsc_dev_to_netdev(xdev),
+ "get mac %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+exit:
+ kfree(out);
+ return err;
+}
+
+static void xsc_eth_l2_addr_init(struct xsc_adapter *adapter)
+{
+ struct net_device *netdev = adapter->netdev;
+ char mac[6] = {0};
+ int ret = 0;
+
+ ret = xsc_eth_get_mac(adapter->xdev, mac);
+ if (ret) {
+ netdev_warn(netdev, "get mac failed %d, generate random mac...",
+ ret);
+ eth_random_addr(mac);
+ netdev->addr_assign_type = NET_ADDR_RANDOM;
+ } else if (!is_valid_ether_addr(mac)) {
+ netdev_warn(netdev, "invalid mac %pM from firmware, generate random mac...\n",
+ mac);
+ eth_random_addr(mac);
+ netdev->addr_assign_type = NET_ADDR_RANDOM;
+ } else {
+ netdev->addr_assign_type = NET_ADDR_PERM;
+ }
+ eth_hw_addr_set(netdev, mac);
+}
+
+static int xsc_eth_nic_enable(struct xsc_adapter *adapter)
+{
+ struct xsc_core_device *xdev = adapter->xdev;
+
+ xsc_eth_l2_addr_init(adapter);
+
+ return xsc_eth_set_hw_mtu(xdev, XSC_SW2HW_MTU(adapter->nic_param.mtu),
+ XSC_SW2HW_RX_PKT_LEN(adapter->nic_param.mtu));
+}
+
+static int xsc_eth_probe(struct auxiliary_device *adev,
+ const struct auxiliary_device_id *adev_id)
+{
+ struct xsc_adev *xsc_adev = container_of(adev, struct xsc_adev, adev);
+ struct xsc_core_device *xdev = xsc_adev->xdev;
+ struct xsc_adapter *adapter;
+ struct net_device *netdev;
+ int err;
+
+ netdev = alloc_etherdev(sizeof(struct xsc_adapter));
+ if (!netdev)
+ return -ENOMEM;
+
+ netdev->dev.parent = &xdev->pdev->dev;
+ adapter = netdev_priv(netdev);
+ adapter->netdev = netdev;
+ adapter->pdev = xdev->pdev;
+ adapter->dev = &adapter->pdev->dev;
+ adapter->xdev = xdev;
+ xdev->eth_priv = adapter;
+
+ err = xsc_eth_nic_init(adapter);
+ if (err) {
+ netdev_err(netdev, "xsc_eth_nic_init failed, err=%d\n", err);
+ goto err_free_netdev;
+ }
+
+ err = xsc_eth_nic_enable(adapter);
+ if (err) {
+ netdev_err(netdev, "xsc_eth_nic_enable failed, err=%d\n", err);
+ goto err_free_netdev;
+ }
+
+ err = register_netdev(netdev);
+ if (err) {
+ netdev_err(netdev, "register_netdev failed, err=%d\n", err);
+ goto err_free_netdev;
+ }
+
+ return 0;
+
+err_free_netdev:
+ xdev->eth_priv = NULL;
+ free_netdev(netdev);
+
+ return err;
+}
+
+static void xsc_eth_remove(struct auxiliary_device *adev)
+{
+ struct xsc_adev *xsc_adev = container_of(adev, struct xsc_adev, adev);
+ struct xsc_core_device *xdev = xsc_adev->xdev;
+ struct xsc_adapter *adapter = xdev->eth_priv;
+
+ /* Runs ndo_stop(), so the queues and the HCA are shut down first. */
+ unregister_netdev(adapter->netdev);
+
+ free_netdev(adapter->netdev);
+
+ xdev->eth_priv = NULL;
+}
+
+static const struct auxiliary_device_id xsc_eth_id_table[] = {
+ { .name = XSC_PCI_DRV_NAME "." XSC_ETH_ADEV_NAME },
+ {},
+};
+MODULE_DEVICE_TABLE(auxiliary, xsc_eth_id_table);
+
+static struct auxiliary_driver xsc_eth_driver = {
+ .name = "eth",
+ .probe = xsc_eth_probe,
+ .remove = xsc_eth_remove,
+ .id_table = xsc_eth_id_table,
+};
+module_auxiliary_driver(xsc_eth_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Yunsilicon XSC ethernet driver");
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
new file mode 100644
index 000000000..38c620f00
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef __XSC_ETH_H
+#define __XSC_ETH_H
+
+#include <linux/udp.h>
+
+#include "common/xsc_core.h"
+#include "xsc_eth_common.h"
+
+struct xsc_adapter {
+ struct net_device *netdev;
+ struct pci_dev *pdev;
+ struct device *dev;
+ struct xsc_core_device *xdev;
+
+ struct xsc_eth_params nic_param;
+
+ struct xsc_channel channel;
+
+ /* true between ndo_open and ndo_stop */
+ bool opened;
+};
+
+static inline struct net_device *xsc_dev_to_netdev(struct xsc_core_device *xdev)
+{
+ return ((struct xsc_adapter *)xdev->eth_priv)->netdev;
+}
+
+#endif /* __XSC_ETH_H */
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
new file mode 100644
index 000000000..a20ba7e62
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_common.h
@@ -0,0 +1,116 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef __XSC_ETH_COMMON_H
+#define __XSC_ETH_COMMON_H
+
+#include <linux/netdevice.h>
+#include <linux/if_vlan.h>
+#include <net/page_pool/types.h>
+#include <net/page_pool/helpers.h>
+
+#include "xsc_queue.h"
+
+#define SW_DEFAULT_MTU ETH_DATA_LEN
+
+#define XSC_HASH_IP_PORTS (BIT(0) | BIT(2) | BIT(3) | BIT(4) | BIT(1))
+#define XSC_HASH_IP6_PORTS (BIT(5) | BIT(6) | BIT(7) | BIT(8) | BIT(1))
+
+enum {
+ XSC_HASH_FUNC_TOP = 1,
+};
+
+#define XSC_ETH_HW_MTU_SEND 9800
+#define XSC_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN * 2 + ETH_FCS_LEN)
+#define XSC_SW2HW_MTU(mtu) ((mtu) + XSC_ETH_HARD_MTU)
+#define XSC_SW2HW_HLEN (ETH_HLEN + VLAN_HLEN * 2 + ETH_FCS_LEN)
+#define XSC_SW2HW_FRAG_SIZE(mtu) ((mtu) + XSC_SW2HW_HLEN)
+#define XSC_ETH_RX_MAX_HEAD_ROOM 256
+#define XSC_SW2HW_RX_PKT_LEN(mtu) \
+ ((mtu) + ETH_HLEN + XSC_ETH_RX_MAX_HEAD_ROOM)
+
+#define XSC_QPN_SQN_STUB 1025
+
+#define XSC_SKB_FRAG_SZ(len) (SKB_DATA_ALIGN(len) + \
+ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
+
+#define XSC_RQCQ_ELE_SZ 32
+#define XSC_SQCQ_ELE_SZ 32
+
+#define XSC_LOG_RQCQ_SZ 0xb
+#define XSC_LOG_SQCQ_SZ 0xa
+
+#define XSC_RQCQ_ELE_NUM BIT(XSC_LOG_RQCQ_SZ)
+#define XSC_SQCQ_ELE_NUM BIT(XSC_LOG_SQCQ_SZ)
+
+enum xsc_port_status {
+ XSC_PORT_DOWN = 0,
+ XSC_PORT_UP = 1,
+};
+
+enum xsc_queue_type {
+ XSC_QUEUE_TYPE_RQCQ,
+ XSC_QUEUE_TYPE_SQCQ,
+ XSC_QUEUE_TYPE_RQ,
+ XSC_QUEUE_TYPE_SQ,
+};
+
+struct xsc_queue_attr {
+ u32 ele_num;
+ u32 ele_size;
+ u8 ele_log_size;
+ u8 q_log_size;
+};
+
+struct xsc_eth_rx_wqe_cyc {
+ DECLARE_FLEX_ARRAY(struct xsc_wqe_data_seg, data);
+};
+
+struct xsc_cq_param {
+ struct xsc_wq_param wq;
+ struct xsc_queue_attr cq_attr;
+};
+
+struct xsc_rq_param {
+ struct xsc_wq_param wq;
+ struct xsc_queue_attr rq_attr;
+ u32 frag_size;
+};
+
+struct xsc_sq_param {
+ struct xsc_wq_param wq;
+ struct xsc_queue_attr sq_attr;
+};
+
+struct xsc_channel_param {
+ struct xsc_cq_param rqcq_param;
+ struct xsc_cq_param sqcq_param;
+ struct xsc_rq_param rq_param;
+ struct xsc_sq_param sq_param;
+};
+
+struct xsc_eth_qp {
+ struct xsc_rq rq;
+ struct xsc_sq sq;
+};
+
+struct xsc_eth_params {
+ u32 mtu;
+ u32 sq_size;
+ u32 rq_size;
+};
+
+struct xsc_channel {
+ /* data path */
+ struct xsc_eth_qp qp;
+
+ /* relationship */
+ struct xsc_adapter *adapter;
+ struct net_device *netdev;
+ int cpu;
+} ____cacheline_aligned_in_smp;
+
+#endif
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
new file mode 100644
index 000000000..35206ddf4
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
@@ -0,0 +1,150 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd. All
+ * rights reserved.
+ * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
+ */
+
+#ifndef __XSC_WQ_H
+#define __XSC_WQ_H
+
+#include "common/xsc_core.h"
+
+struct xsc_wq_param {
+ int buf_numa_node;
+ int db_numa_node;
+};
+
+struct xsc_wq_ctrl {
+ struct xsc_core_device *xdev;
+ struct xsc_frag_buf buf;
+};
+
+struct xsc_wq_cyc {
+ struct xsc_frag_buf_ctrl fbc;
+ u16 sz;
+ u16 wqe_ctr;
+ u16 cur_sz;
+};
+
+struct xsc_cqwq {
+ struct xsc_frag_buf_ctrl fbc;
+ u32 cc;
+};
+
+enum xsc_res_type {
+ XSC_RES_RQ,
+ XSC_RES_SQ,
+};
+
+u32 xsc_wq_cyc_get_size(struct xsc_wq_cyc *wq);
+
+int xsc_eth_cqwq_create(struct xsc_core_device *xdev,
+ struct xsc_wq_param *param,
+ u8 q_log_size,
+ u8 ele_log_size,
+ struct xsc_cqwq *wq,
+ struct xsc_wq_ctrl *wq_ctrl);
+
+int xsc_eth_wq_cyc_create(struct xsc_core_device *xdev,
+ struct xsc_wq_param *param,
+ u8 q_log_size,
+ u8 ele_log_size,
+ struct xsc_wq_cyc *wq,
+ struct xsc_wq_ctrl *wq_ctrl);
+void xsc_eth_wq_destroy(struct xsc_wq_ctrl *wq_ctrl);
+
+static inline void xsc_init_fbc(struct xsc_buf_list *frags,
+ u8 log_stride, u8 log_sz,
+ struct xsc_frag_buf_ctrl *fbc)
+{
+ fbc->frags = frags;
+ fbc->log_stride = log_stride;
+ fbc->log_sz = log_sz;
+ fbc->sz_m1 = (1 << fbc->log_sz) - 1;
+ fbc->log_frag_strides = PAGE_SHIFT - fbc->log_stride;
+ fbc->frag_sz_m1 = (1 << fbc->log_frag_strides) - 1;
+ fbc->strides_offset = 0;
+}
+
+static inline void *xsc_frag_buf_get_wqe(struct xsc_frag_buf_ctrl *fbc,
+ u32 ix)
+{
+ unsigned int frag;
+
+ ix += fbc->strides_offset;
+ frag = ix >> fbc->log_frag_strides;
+
+ return fbc->frags[frag].buf +
+ ((fbc->frag_sz_m1 & ix) << fbc->log_stride);
+}
+
+static inline int xsc_wq_cyc_missing(struct xsc_wq_cyc *wq)
+{
+ return wq->sz - wq->cur_sz;
+}
+
+static inline void xsc_wq_cyc_push_n(struct xsc_wq_cyc *wq, u8 n)
+{
+ wq->wqe_ctr += n;
+ wq->cur_sz += n;
+}
+
+static inline void xsc_wq_cyc_pop(struct xsc_wq_cyc *wq)
+{
+ wq->cur_sz--;
+}
+
+static inline u16 xsc_wq_cyc_ctr2ix(struct xsc_wq_cyc *wq, u16 ctr)
+{
+ return ctr & wq->fbc.sz_m1;
+}
+
+static inline u16 xsc_wq_cyc_get_head(struct xsc_wq_cyc *wq)
+{
+ return xsc_wq_cyc_ctr2ix(wq, wq->wqe_ctr);
+}
+
+static inline void *xsc_wq_cyc_get_wqe(struct xsc_wq_cyc *wq, u16 ix)
+{
+ return xsc_frag_buf_get_wqe(&wq->fbc, ix);
+}
+
+static inline u32 xsc_cqwq_ctr2ix(struct xsc_cqwq *wq, u32 ctr)
+{
+ return ctr & wq->fbc.sz_m1;
+}
+
+static inline u32 xsc_cqwq_get_ci(struct xsc_cqwq *wq)
+{
+ return xsc_cqwq_ctr2ix(wq, wq->cc);
+}
+
+static inline u32 xsc_cqwq_get_ctr_wrap_cnt(struct xsc_cqwq *wq, u32 ctr)
+{
+ return ctr >> wq->fbc.log_sz;
+}
+
+static inline u32 xsc_cqwq_get_wrap_cnt(struct xsc_cqwq *wq)
+{
+ return xsc_cqwq_get_ctr_wrap_cnt(wq, wq->cc);
+}
+
+static inline void xsc_cqwq_pop(struct xsc_cqwq *wq)
+{
+ wq->cc++;
+}
+
+static inline u32 xsc_cqwq_get_size(struct xsc_cqwq *wq)
+{
+ return wq->fbc.sz_m1 + 1;
+}
+
+static inline struct xsc_cqe *xsc_cqwq_get_wqe(struct xsc_cqwq *wq, u32 ix)
+{
+ struct xsc_cqe *cqe = xsc_frag_buf_get_wqe(&wq->fbc, ix);
+
+ return cqe;
+}
+
+#endif /* __XSC_WQ_H */
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h
new file mode 100644
index 000000000..d89e62d93
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_queue.h
@@ -0,0 +1,103 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
+ */
+
+#ifndef __XSC_QUEUE_H
+#define __XSC_QUEUE_H
+
+#include <net/page_pool/types.h>
+#include <net/page_pool/helpers.h>
+
+#include "common/xsc_core.h"
+#include "xsc_eth_wq.h"
+
+struct xsc_channel;
+
+enum {
+ XSC_SEND_WQE_DS = 16,
+};
+
+enum {
+ XSC_RECV_WQE_DS = 16,
+};
+
+enum {
+ XSC_ETH_RQ_STATE_ENABLED,
+};
+
+enum {
+ XSC_ETH_SQ_STATE_ENABLED,
+};
+
+#define XSC_RX_FRAG_SZ_ORDER 0
+
+struct xsc_cq {
+ /* data path - accessed per cqe */
+ struct xsc_cqwq wq;
+
+ struct xsc_core_cq xcq;
+ struct xsc_channel *channel;
+
+ /* control */
+ struct xsc_core_device *xdev;
+ struct xsc_wq_ctrl wq_ctrl;
+} ____cacheline_aligned_in_smp;
+
+struct xsc_dma_info {
+ struct page *page;
+ dma_addr_t addr;
+};
+
+struct xsc_rq {
+ struct xsc_core_qp cqp;
+ struct {
+ struct xsc_wq_cyc wq;
+ struct xsc_dma_info *di;
+ u8 wqe_bulk;
+ } wqe;
+
+ struct page_pool *page_pool;
+ struct xsc_wq_ctrl wq_ctrl;
+ struct xsc_cq cq;
+ u32 rqn;
+ u32 frag_size;
+
+ unsigned long state;
+} ____cacheline_aligned_in_smp;
+
+struct xsc_tx_wqe_info {
+ struct sk_buff *skb;
+ dma_addr_t dma_addr;
+};
+
+struct xsc_tx_wqe {
+ struct xsc_send_wqe_ctrl_seg ctrl;
+ struct xsc_wqe_data_seg data[];
+};
+
+struct xsc_sq {
+ struct xsc_core_qp cqp;
+ u16 cc;
+ u16 pc ____cacheline_aligned_in_smp;
+
+ struct xsc_cq cq;
+
+ /* read only */
+ struct xsc_wq_cyc wq;
+ struct xsc_tx_wqe_info *wqe_info;
+ struct netdev_queue *txq;
+ u32 sqn;
+ u16 stop_room;
+
+ unsigned long state;
+ unsigned int hw_mtu;
+
+ /* control path */
+ struct xsc_wq_ctrl wq_ctrl;
+ struct xsc_channel *channel;
+} ____cacheline_aligned_in_smp;
+
+#endif /* __XSC_QUEUE_H */
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
index 552cd5f46..9cdc31f9d 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
@@ -6,4 +6,4 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc_pci.o
-xsc_pci-y := main.o cmd.o eq.o cq.o qp.o pci_irq.o alloc.o doorbell.o
+xsc_pci-y := main.o adev.o cmd.o eq.o cq.o qp.o pci_irq.o alloc.o doorbell.o
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
new file mode 100644
index 000000000..3376ed10b
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/idr.h>
+
+#include "adev.h"
+
+static DEFINE_IDA(xsc_adev_ida);
+
+static const char * const xsc_adev_name[] = {
+ [XSC_ADEV_IDX_ETH] = XSC_ETH_ADEV_NAME,
+};
+
+static void xsc_release_adev(struct device *dev)
+{
+ struct xsc_adev *xsc_adev =
+ container_of(dev, struct xsc_adev, adev.dev);
+
+ kfree(xsc_adev);
+}
+
+static int xsc_adev_add(struct xsc_core_device *xdev, int idx)
+{
+ struct auxiliary_device *adev;
+ struct xsc_adev *xsc_adev;
+ int ret;
+
+ if (!xdev->xsc_adev_list)
+ return -ENODEV;
+
+ if (xdev->xsc_adev_list[idx])
+ return 0;
+
+ xsc_adev = kzalloc_obj(*xsc_adev, GFP_KERNEL);
+ if (!xsc_adev)
+ return -ENOMEM;
+
+ adev = &xsc_adev->adev;
+ adev->name = xsc_adev_name[idx];
+ adev->id = xdev->adev_id;
+ adev->dev.parent = &xdev->pdev->dev;
+ adev->dev.release = xsc_release_adev;
+ xsc_adev->xdev = xdev;
+
+ ret = auxiliary_device_init(adev);
+ if (ret) {
+ kfree(xsc_adev);
+ return ret;
+ }
+
+ ret = auxiliary_device_add(adev);
+ if (ret) {
+ auxiliary_device_uninit(adev);
+ return ret;
+ }
+
+ xdev->xsc_adev_list[idx] = xsc_adev;
+
+ return 0;
+}
+
+static void xsc_adev_del(struct xsc_core_device *xdev, int idx)
+{
+ struct xsc_adev *xsc_adev;
+ struct auxiliary_device *adev;
+
+ if (!xdev->xsc_adev_list)
+ return;
+
+ xsc_adev = xdev->xsc_adev_list[idx];
+ if (!xsc_adev)
+ return;
+
+ /* Clear the slot before teardown: the driver's remove callback runs
+ * synchronously inside auxiliary_device_delete() and may re-enter
+ * xsc_adev_add() for this index.
+ */
+ xdev->xsc_adev_list[idx] = NULL;
+
+ adev = &xsc_adev->adev;
+ auxiliary_device_delete(adev);
+ auxiliary_device_uninit(adev);
+}
+
+int xsc_adev_init(struct xsc_core_device *xdev)
+{
+ struct xsc_adev **xsc_adev_list;
+ int adev_id;
+ int ret;
+
+ xsc_adev_list = kcalloc(XSC_ADEV_IDX_MAX,
+ sizeof(struct xsc_adev *),
+ GFP_KERNEL);
+ if (!xsc_adev_list)
+ return -ENOMEM;
+ xdev->xsc_adev_list = xsc_adev_list;
+
+ adev_id = ida_alloc(&xsc_adev_ida, GFP_KERNEL);
+ if (adev_id < 0) {
+ ret = adev_id;
+ goto err_free_adev_list;
+ }
+ xdev->adev_id = adev_id;
+
+ ret = xsc_adev_add(xdev, XSC_ADEV_IDX_ETH);
+ if (ret)
+ goto err_dalloc_adev_id;
+
+ return 0;
+
+err_dalloc_adev_id:
+ ida_free(&xsc_adev_ida, xdev->adev_id);
+err_free_adev_list:
+ kfree(xsc_adev_list);
+ xdev->xsc_adev_list = NULL;
+
+ return ret;
+}
+
+void xsc_adev_uninit(struct xsc_core_device *xdev)
+{
+ if (!xdev->xsc_adev_list)
+ return;
+
+ xsc_adev_del(xdev, XSC_ADEV_IDX_ETH);
+ ida_free(&xsc_adev_ida, xdev->adev_id);
+ kfree(xdev->xsc_adev_list);
+ xdev->xsc_adev_list = NULL;
+}
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/adev.h b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.h
new file mode 100644
index 000000000..d5c2c940e
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef __XSC_ADEV_H
+#define __XSC_ADEV_H
+
+#include "common/xsc_core.h"
+
+int xsc_adev_init(struct xsc_core_device *xdev);
+void xsc_adev_uninit(struct xsc_core_device *xdev);
+
+#endif
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
index e158dd2e9..c800cef3d 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
@@ -7,6 +7,7 @@
#include "common/xsc_cmd.h"
#include "common/xsc_core.h"
+#include "adev.h"
#include "cq.h"
#include "eq.h"
#include "pci_irq.h"
@@ -173,8 +174,16 @@ static int xsc_pci_init(struct xsc_core_device *xdev,
goto err_cmd_cleanup;
}
+ err = xsc_adev_init(xdev);
+ if (err) {
+ pci_err(pdev, "xsc_adev_init failed: err=%d\n", err);
+ goto err_irq_eq_destroy;
+ }
+
return 0;
+err_irq_eq_destroy:
+ xsc_irq_eq_destroy(xdev);
err_cmd_cleanup:
xsc_cmd_cleanup(xdev);
err_io_unmap:
@@ -192,6 +201,7 @@ static void xsc_pci_fini(struct xsc_core_device *xdev)
{
struct pci_dev *pdev = xdev->pdev;
+ xsc_adev_uninit(xdev);
xsc_irq_eq_destroy(xdev);
xsc_cmd_cleanup(xdev);
pci_iounmap(pdev, xdev->bar);
--
2.43.0
[PATCH v2 08/11] net/xsc: add the single TX/RX channel
Author: "Xin Tian"
Date: Thu, 26 Nov 2026 14:57
Date: Thu, 26 Nov 2026 14:57
1075 lines
39486 bytes
39486 bytes
Bring up one channel on top of the netdev: build the queue parameters,
create the CQ, SQ and RQ through the core, and enable the NIC HCA so the
channel can move packets. The queue ring helpers and the fragmented
buffer allocation they rely on are added here as well.
The CQ completion callback and NAPI poll are set up by the receive patch
that follows, so the channel cannot move packets yet and the interface
must not be opened in this state.
Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
.../ethernet/yunsilicon/xsc/common/xsc_core.h | 9 +
.../net/ethernet/yunsilicon/xsc/net/Makefile | 2 +-
.../net/ethernet/yunsilicon/xsc/net/main.c | 791 +++++++++++++++++-
.../ethernet/yunsilicon/xsc/net/xsc_eth_wq.c | 80 ++
.../net/ethernet/yunsilicon/xsc/pci/alloc.c | 102 +++
5 files changed, 982 insertions(+), 2 deletions(-)
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.c
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
index 74cd5b66f..a72143ae6 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -279,6 +279,15 @@ void xsc_irq_event_register(struct xsc_core_device *xdev,
void (*handler)(void *xdev));
void xsc_irq_event_unregister(struct xsc_core_device *xdev);
+void xsc_core_fill_page_frag_array(struct xsc_frag_buf *buf,
+ __be64 *pas, unsigned int npages);
+int xsc_core_frag_buf_alloc_node(struct xsc_core_device *xdev,
+ unsigned long size,
+ struct xsc_frag_buf *buf,
+ int node);
+void xsc_core_frag_buf_free(struct xsc_core_device *xdev,
+ struct xsc_frag_buf *buf);
+
static inline void *xsc_buf_offset(struct xsc_buf *buf, unsigned long offset)
{
if (likely(buf->nbufs == 1))
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/Makefile b/drivers/net/ethernet/yunsilicon/xsc/net/Makefile
index db289d974..0e6249cec 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/net/Makefile
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/Makefile
@@ -6,4 +6,4 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc_eth.o
-xsc_eth-y := main.o
+xsc_eth-y := main.o xsc_eth_wq.o
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
index b9e75d7e1..1c7bbc27d 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
@@ -25,6 +25,774 @@ static void xsc_eth_netdev_init(struct xsc_adapter *adapter)
netif_carrier_off(adapter->netdev);
}
+static void xsc_eth_build_queue_param(struct xsc_adapter *adapter,
+ struct xsc_queue_attr *attr, u8 type)
+{
+ struct xsc_core_device *xdev = adapter->xdev;
+
+ if (adapter->nic_param.sq_size == 0)
+ adapter->nic_param.sq_size = min_t(u32,
+ BIT(xdev->caps.log_max_qp_depth),
+ XSC_SQCQ_ELE_NUM);
+ if (adapter->nic_param.rq_size == 0)
+ adapter->nic_param.rq_size = BIT(xdev->caps.log_max_qp_depth);
+
+ if (type == XSC_QUEUE_TYPE_RQCQ) {
+ attr->ele_num = min_t(int, XSC_RQCQ_ELE_NUM,
+ xdev->caps.max_cqes);
+ attr->ele_size = XSC_RQCQ_ELE_SZ;
+ attr->ele_log_size = order_base_2(XSC_RQCQ_ELE_SZ);
+ attr->q_log_size = order_base_2(attr->ele_num);
+ } else if (type == XSC_QUEUE_TYPE_SQCQ) {
+ attr->ele_num = min_t(int, XSC_SQCQ_ELE_NUM,
+ xdev->caps.max_cqes);
+ attr->ele_size = XSC_SQCQ_ELE_SZ;
+ attr->ele_log_size = order_base_2(XSC_SQCQ_ELE_SZ);
+ attr->q_log_size = order_base_2(attr->ele_num);
+ } else if (type == XSC_QUEUE_TYPE_RQ) {
+ attr->ele_num = adapter->nic_param.rq_size;
+ attr->ele_size = xdev->caps.recv_ds_num * XSC_RECV_WQE_DS;
+ attr->ele_log_size = order_base_2(attr->ele_size);
+ attr->q_log_size = order_base_2(attr->ele_num);
+ } else if (type == XSC_QUEUE_TYPE_SQ) {
+ attr->ele_num = adapter->nic_param.sq_size;
+ attr->ele_size = xdev->caps.send_ds_num * XSC_SEND_WQE_DS;
+ attr->ele_log_size = order_base_2(attr->ele_size);
+ attr->q_log_size = order_base_2(attr->ele_num);
+ }
+}
+
+static u32 xsc_rx_get_linear_frag_sz(u32 mtu)
+{
+ return XSC_SKB_FRAG_SZ(XSC_SW2HW_FRAG_SIZE(mtu));
+}
+
+static void xsc_eth_build_channel_param(struct xsc_adapter *adapter,
+ struct xsc_channel_param *chl_param)
+{
+ xsc_eth_build_queue_param(adapter, &chl_param->rqcq_param.cq_attr,
+ XSC_QUEUE_TYPE_RQCQ);
+ chl_param->rqcq_param.wq.buf_numa_node = dev_to_node(adapter->dev);
+
+ xsc_eth_build_queue_param(adapter, &chl_param->sqcq_param.cq_attr,
+ XSC_QUEUE_TYPE_SQCQ);
+ chl_param->sqcq_param.wq.buf_numa_node = dev_to_node(adapter->dev);
+
+ xsc_eth_build_queue_param(adapter, &chl_param->sq_param.sq_attr,
+ XSC_QUEUE_TYPE_SQ);
+ chl_param->sq_param.wq.buf_numa_node = dev_to_node(adapter->dev);
+
+ xsc_eth_build_queue_param(adapter, &chl_param->rq_param.rq_attr,
+ XSC_QUEUE_TYPE_RQ);
+ chl_param->rq_param.wq.buf_numa_node = dev_to_node(adapter->dev);
+ chl_param->rq_param.frag_size = XSC_SW2HW_FRAG_SIZE(adapter->nic_param.mtu);
+}
+
+static void xsc_eth_cq_error_event(struct xsc_core_cq *xcq,
+ enum xsc_event event)
+{
+ struct xsc_cq *xsc_cq = container_of(xcq, struct xsc_cq, xcq);
+ struct xsc_core_device *xdev = xsc_cq->xdev;
+
+ if (event != XSC_EVENT_TYPE_CQ_ERROR) {
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "Unexpected event type %d on CQ %06x\n",
+ event, xcq->cqn);
+ return;
+ }
+
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "Eth catch CQ ERROR: %x, cqn: %d\n", event, xcq->cqn);
+}
+
+static int xsc_eth_alloc_cq(struct xsc_channel *c, struct xsc_cq *pcq,
+ struct xsc_cq_param *pcq_param)
+{
+ u8 ele_log_size = pcq_param->cq_attr.ele_log_size;
+ struct xsc_core_device *xdev = c->adapter->xdev;
+ u8 q_log_size = pcq_param->cq_attr.q_log_size;
+ struct xsc_core_cq *core_cq = &pcq->xcq;
+ int ret;
+ u32 i;
+
+ pcq_param->wq.db_numa_node = cpu_to_node(c->cpu);
+ pcq_param->wq.buf_numa_node = cpu_to_node(c->cpu);
+
+ ret = xsc_eth_cqwq_create(xdev, &pcq_param->wq,
+ q_log_size, ele_log_size, &pcq->wq,
+ &pcq->wq_ctrl);
+ if (ret)
+ return ret;
+
+ core_cq->event = xsc_eth_cq_error_event;
+ core_cq->vector = 0;
+
+ for (i = 0; i < xsc_cqwq_get_size(&pcq->wq); i++) {
+ struct xsc_cqe *cqe = xsc_cqwq_get_wqe(&pcq->wq, i);
+
+ cqe->data1 |= cpu_to_le32(XSC_CQE_DATA1_OWNER);
+ }
+ pcq->xdev = xdev;
+ return 0;
+}
+
+static int xsc_eth_set_cq(struct xsc_channel *c,
+ struct xsc_cq *pcq,
+ struct xsc_cq_param *pcq_param)
+{
+ struct xsc_core_device *xdev = c->adapter->xdev;
+ struct xsc_create_cq_mbox_in *in;
+ unsigned int hw_npages;
+ unsigned int irqn;
+ int inlen;
+ u32 eqn;
+ int ret;
+
+ hw_npages = DIV_ROUND_UP(pcq->wq_ctrl.buf.size, XSC_PAGE_SIZE_4K);
+ /*mbox size + pas size*/
+ inlen = sizeof(struct xsc_create_cq_mbox_in) +
+ sizeof(__be64) * hw_npages;
+
+ in = kvzalloc(inlen, GFP_KERNEL);
+ if (!in)
+ return -ENOMEM;
+
+ ret = xsc_core_vector2eqn(xdev, pcq->xcq.vector, &eqn, &irqn);
+ if (ret)
+ goto err_free;
+
+ in->ctx.eqn = cpu_to_be16(eqn);
+ in->ctx.log_cq_sz = pcq_param->cq_attr.q_log_size;
+ in->ctx.pa_num = cpu_to_be16(hw_npages);
+ in->ctx.glb_func_id = cpu_to_be16(xdev->glb_func_id);
+
+ xsc_core_fill_page_frag_array(&pcq->wq_ctrl.buf,
+ &in->pas[0],
+ hw_npages);
+
+ ret = xsc_core_eth_create_cq(xdev, &pcq->xcq, in, inlen);
+ if (ret)
+ goto err_free;
+ pcq->xcq.irqn = irqn;
+ kvfree(in);
+ return 0;
+
+err_free:
+ kvfree(in);
+ return ret;
+}
+
+static void xsc_eth_free_cq(struct xsc_cq *cq)
+{
+ xsc_eth_wq_destroy(&cq->wq_ctrl);
+}
+
+static int xsc_eth_open_cq(struct xsc_channel *c,
+ struct xsc_cq *pcq,
+ struct xsc_cq_param *pcq_param)
+{
+ int ret;
+
+ ret = xsc_eth_alloc_cq(c, pcq, pcq_param);
+ if (ret)
+ return ret;
+
+ ret = xsc_eth_set_cq(c, pcq, pcq_param);
+ if (ret)
+ goto err_free_cq;
+
+ xsc_arm_cq(pcq->xdev, pcq->xcq.cqn, pcq->wq.cc, 0);
+
+ pcq->channel = c;
+
+ return 0;
+
+err_free_cq:
+ xsc_eth_free_cq(pcq);
+ return ret;
+}
+
+static void xsc_eth_close_cq(struct xsc_channel *c, struct xsc_cq *pcq)
+{
+ struct xsc_core_device *xdev = c->adapter->xdev;
+
+ /* If DESTROY_CQ failed the firmware may still own this CQ and keep
+ * writing CQEs into its buffer; leak the buffer rather than hand it
+ * back to the allocator while the device can still DMA into it.
+ */
+ if (xsc_core_eth_destroy_cq(xdev, &pcq->xcq)) {
+ netdev_err(xsc_dev_to_netdev(xdev), "failed to close cq%d\n",
+ pcq->xcq.cqn);
+ return;
+ }
+
+ xsc_eth_free_cq(pcq);
+}
+
+static void xsc_free_qp_sq_db(struct xsc_sq *sq)
+{
+ kvfree(sq->wqe_info);
+ sq->wqe_info = NULL;
+}
+
+static void xsc_free_qp_sq(struct xsc_sq *sq)
+{
+ xsc_free_qp_sq_db(sq);
+ xsc_eth_wq_destroy(&sq->wq_ctrl);
+}
+
+static int xsc_eth_alloc_qp_sq_db(struct xsc_sq *sq, int numa)
+{
+ sq->wqe_info = kvzalloc_node(array_size(xsc_wq_cyc_get_size(&sq->wq),
+ sizeof(*sq->wqe_info)),
+ GFP_KERNEL, numa);
+ if (!sq->wqe_info)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static void xsc_eth_qp_event(struct xsc_core_qp *qp, int type)
+{
+ struct xsc_core_device *xdev;
+ struct xsc_rq *rq;
+ struct xsc_sq *sq;
+
+ if (qp->eth_queue_type == XSC_RES_RQ) {
+ rq = container_of(qp, struct xsc_rq, cqp);
+ xdev = rq->cq.xdev;
+ } else if (qp->eth_queue_type == XSC_RES_SQ) {
+ sq = container_of(qp, struct xsc_sq, cqp);
+ xdev = sq->cq.xdev;
+ } else {
+ pr_err("%s:Unknown eth qp type %d\n", __func__, type);
+ return;
+ }
+
+ switch (type) {
+ case XSC_EVENT_TYPE_WQ_CATAS_ERROR:
+ case XSC_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
+ case XSC_EVENT_TYPE_WQ_ACCESS_ERROR:
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "%s:Async event %x on QP %d\n",
+ __func__, type, qp->qpn);
+ break;
+ default:
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "%s: Unexpected event type %d on QP %d\n",
+ __func__, type, qp->qpn);
+ return;
+ }
+}
+
+static int xsc_eth_open_qp_sq(struct xsc_channel *c,
+ struct xsc_sq *psq,
+ struct xsc_sq_param *psq_param)
+{
+ u8 ele_log_size = psq_param->sq_attr.ele_log_size;
+ u8 q_log_size = psq_param->sq_attr.q_log_size;
+ struct xsc_modify_raw_qp_mbox_in *modify_in;
+ struct xsc_create_qp_mbox_in *in;
+ struct xsc_core_device *xdev;
+ struct xsc_adapter *adapter;
+ unsigned int hw_npages;
+ int inlen;
+ int ret;
+
+ adapter = c->adapter;
+ xdev = adapter->xdev;
+ psq_param->wq.db_numa_node = cpu_to_node(c->cpu);
+
+ ret = xsc_eth_wq_cyc_create(xdev, &psq_param->wq,
+ q_log_size, ele_log_size, &psq->wq,
+ &psq->wq_ctrl);
+ if (ret)
+ return ret;
+
+ hw_npages = DIV_ROUND_UP(psq->wq_ctrl.buf.size, XSC_PAGE_SIZE_4K);
+ inlen = sizeof(struct xsc_create_qp_mbox_in) +
+ sizeof(__be64) * hw_npages;
+
+ in = kvzalloc(inlen, GFP_KERNEL);
+ if (!in) {
+ ret = -ENOMEM;
+ goto err_sq_wq_destroy;
+ }
+ in->req.input_qpn = cpu_to_be16(XSC_QPN_SQN_STUB);
+ in->req.qp_type = XSC_QUEUE_TYPE_RAW_TSO;
+ in->req.log_sq_sz = ilog2(xdev->caps.send_ds_num) + q_log_size;
+ in->req.pa_num = cpu_to_be16(hw_npages);
+ in->req.cqn_send = cpu_to_be16(psq->cq.xcq.cqn);
+ in->req.cqn_recv = in->req.cqn_send;
+ in->req.glb_funcid = cpu_to_be16(xdev->glb_func_id);
+
+ xsc_core_fill_page_frag_array(&psq->wq_ctrl.buf,
+ &in->req.pas[0], hw_npages);
+
+ ret = xsc_core_eth_create_qp(xdev, in, inlen, &psq->sqn);
+ if (ret)
+ goto err_sq_in_destroy;
+
+ psq->cqp.qpn = psq->sqn;
+ psq->cqp.event = xsc_eth_qp_event;
+ psq->cqp.eth_queue_type = XSC_RES_SQ;
+
+ ret = xsc_core_create_resource_common(xdev, &psq->cqp);
+ if (ret) {
+ netdev_err(adapter->netdev, "%s:error qp:%d errno:%d\n",
+ __func__, psq->sqn, ret);
+ goto err_sq_destroy;
+ }
+
+ psq->channel = c;
+
+ psq->hw_mtu = XSC_ETH_HW_MTU_SEND;
+ psq->stop_room = 1;
+
+ ret = xsc_eth_alloc_qp_sq_db(psq, psq_param->wq.db_numa_node);
+ if (ret)
+ goto err_sq_common_destroy;
+
+ inlen = sizeof(struct xsc_modify_raw_qp_mbox_in);
+ modify_in = kvzalloc(inlen, GFP_KERNEL);
+ if (!modify_in) {
+ ret = -ENOMEM;
+ goto err_sq_common_destroy;
+ }
+
+ modify_in->req.qp_out_port = xdev->pf_id;
+ modify_in->pcie_no = xdev->pcie_no;
+ modify_in->req.qpn = cpu_to_be16((u16)(psq->sqn));
+ modify_in->req.func_id = cpu_to_be16(xdev->glb_func_id);
+ modify_in->req.dma_direct = XSC_DMA_DIR_TO_MAC;
+ modify_in->req.prio = 0;
+ ret = xsc_core_eth_modify_raw_qp(xdev, modify_in);
+ if (ret)
+ goto err_sq_modify_in_destroy;
+
+ kvfree(modify_in);
+ kvfree(in);
+
+ return 0;
+
+err_sq_modify_in_destroy:
+ kvfree(modify_in);
+
+err_sq_common_destroy:
+ xsc_free_qp_sq_db(psq);
+
+ xsc_core_destroy_resource_common(xdev, &psq->cqp);
+
+err_sq_destroy:
+ xsc_core_eth_destroy_qp(xdev, psq->cqp.qpn);
+
+err_sq_in_destroy:
+ kvfree(in);
+
+err_sq_wq_destroy:
+ xsc_eth_wq_destroy(&psq->wq_ctrl);
+ return ret;
+}
+
+static void xsc_eth_close_qp_sq(struct xsc_channel *c, struct xsc_sq *psq)
+{
+ struct xsc_core_device *xdev = c->adapter->xdev;
+
+ xsc_core_destroy_resource_common(xdev, &psq->cqp);
+
+ /* If DESTROY_QP failed the QP is still live in the firmware with its
+ * WQ pages programmed; leak the WQ buffer (and in-flight skbs) rather
+ * than free pages the device can still DMA into.
+ */
+ if (xsc_core_eth_destroy_qp(xdev, psq->cqp.qpn)) {
+ netdev_err(c->adapter->netdev, "failed to close sq%d\n",
+ psq->cqp.qpn);
+ return;
+ }
+
+ xsc_free_qp_sq(psq);
+}
+
+static int xsc_eth_open_channel(struct xsc_adapter *adapter,
+ struct xsc_channel *c,
+ struct xsc_channel_param *chl_param)
+{
+ struct xsc_core_device *xdev = adapter->xdev;
+ const struct cpumask *aff;
+ unsigned int irqn;
+ u32 eqn;
+ int ret;
+
+ c->adapter = adapter;
+ c->netdev = adapter->netdev;
+ c->cpu = 0;
+
+ ret = xsc_core_vector2eqn(xdev, 0, &eqn, &irqn);
+ if (ret)
+ goto err_out;
+ aff = irq_get_affinity_mask(irqn);
+ if (aff)
+ c->cpu = cpumask_first(aff);
+
+ ret = xsc_eth_open_cq(c, &c->qp.rq.cq, &chl_param->rqcq_param);
+ if (ret)
+ goto err_out;
+
+ ret = xsc_eth_open_cq(c, &c->qp.sq.cq, &chl_param->sqcq_param);
+ if (ret)
+ goto err_close_rq_cq;
+
+ ret = xsc_eth_open_qp_sq(c, &c->qp.sq, &chl_param->sq_param);
+ if (ret)
+ goto err_close_sq_cq;
+
+ netdev_dbg(adapter->netdev, "open channel ok\n");
+ return 0;
+
+err_close_sq_cq:
+ xsc_eth_close_cq(c, &c->qp.sq.cq);
+err_close_rq_cq:
+ xsc_eth_close_cq(c, &c->qp.rq.cq);
+err_out:
+ netdev_err(adapter->netdev, "failed to open channel, err=%d\n", ret);
+ return ret;
+}
+
+static int xsc_eth_modify_qps_channel(struct xsc_adapter *adapter,
+ struct xsc_channel *c)
+{
+ int ret;
+
+ ret = xsc_core_eth_modify_qp_status(adapter->xdev, c->qp.rq.rqn,
+ XSC_CMD_OP_RTR2RTS_QP);
+ if (ret)
+ return ret;
+
+ return xsc_core_eth_modify_qp_status(adapter->xdev, c->qp.sq.sqn,
+ XSC_CMD_OP_RTR2RTS_QP);
+}
+
+static void xsc_eth_free_qp_rq(struct xsc_rq *rq)
+{
+ kvfree(rq->wqe.di);
+
+ if (rq->page_pool)
+ page_pool_destroy(rq->page_pool);
+
+ xsc_eth_wq_destroy(&rq->wq_ctrl);
+}
+
+static int xsc_eth_alloc_rq(struct xsc_channel *c,
+ struct xsc_rq *prq,
+ struct xsc_rq_param *prq_param)
+{
+ u8 ele_log_size = prq_param->rq_attr.ele_log_size;
+ struct page_pool_params pagepool_params = {0};
+ u8 q_log_size = prq_param->rq_attr.q_log_size;
+ u32 wq_sz;
+ int ret = 0;
+ int i;
+
+ prq_param->wq.db_numa_node = cpu_to_node(c->cpu);
+
+ ret = xsc_eth_wq_cyc_create(c->adapter->xdev, &prq_param->wq,
+ q_log_size, ele_log_size, &prq->wqe.wq,
+ &prq->wq_ctrl);
+ if (ret)
+ return ret;
+
+ wq_sz = xsc_wq_cyc_get_size(&prq->wqe.wq);
+ prq->wqe.di = kvzalloc_node(array_size(wq_sz, sizeof(*prq->wqe.di)),
+ GFP_KERNEL, cpu_to_node(c->cpu));
+ if (!prq->wqe.di)
+ goto err_destroy_wq;
+
+ prq->wqe.wqe_bulk = PAGE_SIZE /
+ roundup_pow_of_two(xsc_rx_get_linear_frag_sz(c->adapter->nic_param.mtu));
+
+ pagepool_params.order = XSC_RX_FRAG_SZ_ORDER;
+ pagepool_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+ pagepool_params.pool_size = wq_sz;
+ pagepool_params.nid = cpu_to_node(c->cpu);
+ pagepool_params.dev = c->adapter->dev;
+ pagepool_params.dma_dir = DMA_FROM_DEVICE;
+ pagepool_params.max_len = PAGE_SIZE;
+ prq->page_pool = page_pool_create(&pagepool_params);
+ if (IS_ERR(prq->page_pool)) {
+ ret = PTR_ERR(prq->page_pool);
+ prq->page_pool = NULL;
+ goto err_free_di;
+ }
+
+ for (i = 0; i < wq_sz; i++) {
+ struct xsc_eth_rx_wqe_cyc *wqe =
+ xsc_wq_cyc_get_wqe(&prq->wqe.wq, i);
+
+ wqe->data[0].data0 =
+ cpu_to_le32(FIELD_PREP(XSC_WQE_DATA_SEG_DATA0_SEG_LEN_MASK,
+ prq_param->frag_size));
+ wqe->data[0].mkey = cpu_to_le32(XSC_INVALID_LKEY);
+ }
+
+ prq->frag_size = prq_param->frag_size;
+
+ return 0;
+
+err_free_di:
+ kvfree(prq->wqe.di);
+err_destroy_wq:
+ xsc_eth_wq_destroy(&prq->wq_ctrl);
+ return ret;
+}
+
+static int xsc_eth_open_qp_rq(struct xsc_channel *c,
+ struct xsc_rq *prq,
+ struct xsc_rq_param *prq_param)
+{
+ struct xsc_core_device *xdev = c->adapter->xdev;
+ struct xsc_create_qp_mbox_in *in;
+ unsigned int hw_npages;
+ u8 q_log_size;
+ int inlen;
+ int ret;
+
+ ret = xsc_eth_alloc_rq(c, prq, prq_param);
+ if (ret)
+ return ret;
+
+ q_log_size = prq_param->rq_attr.q_log_size;
+ hw_npages = DIV_ROUND_UP(prq->wq_ctrl.buf.size, XSC_PAGE_SIZE_4K);
+ inlen = sizeof(struct xsc_create_qp_mbox_in) +
+ sizeof(__be64) * hw_npages;
+ in = kvzalloc(inlen, GFP_KERNEL);
+ if (!in) {
+ ret = -ENOMEM;
+ goto err_free_rq;
+ }
+
+ in->req.input_qpn = cpu_to_be16(0);
+ in->req.qp_type = XSC_QUEUE_TYPE_RAW;
+ in->req.log_rq_sz = ilog2(xdev->caps.recv_ds_num) + q_log_size;
+ in->req.pa_num = cpu_to_be16(hw_npages);
+ in->req.cqn_recv = cpu_to_be16(prq->cq.xcq.cqn);
+ in->req.cqn_send = in->req.cqn_recv;
+ in->req.glb_funcid = cpu_to_be16(xdev->glb_func_id);
+
+ xsc_core_fill_page_frag_array(&prq->wq_ctrl.buf,
+ &in->req.pas[0], hw_npages);
+
+ ret = xsc_core_eth_create_qp(xdev, in, inlen, &prq->rqn);
+ kvfree(in);
+ if (ret)
+ goto err_free_rq;
+
+ prq->cqp.qpn = prq->rqn;
+ prq->cqp.event = xsc_eth_qp_event;
+ prq->cqp.eth_queue_type = XSC_RES_RQ;
+
+ ret = xsc_core_create_resource_common(xdev, &prq->cqp);
+ if (ret) {
+ netdev_err(c->adapter->netdev,
+ "create resource common error qp:%d errno:%d\n",
+ prq->rqn, ret);
+ goto err_destroy_qp;
+ }
+
+ return 0;
+
+err_destroy_qp:
+ xsc_core_eth_destroy_qp(xdev, prq->rqn);
+err_free_rq:
+ xsc_eth_free_qp_rq(prq);
+ return ret;
+}
+
+static void xsc_eth_close_qp_rq(struct xsc_channel *c, struct xsc_rq *prq)
+{
+ struct xsc_core_device *xdev = c->adapter->xdev;
+
+ xsc_core_destroy_resource_common(xdev, &prq->cqp);
+
+ /* If DESTROY_QP failed the RQ is still live in the firmware with its
+ * WQ pages posted; leak the WQ buffer and page_pool rather than return
+ * buffer pages the device can still DMA into.
+ */
+ if (xsc_core_eth_destroy_qp(xdev, prq->cqp.qpn)) {
+ netdev_err(c->adapter->netdev, "failed to close rq%d\n",
+ prq->cqp.qpn);
+ return;
+ }
+
+ xsc_eth_free_qp_rq(prq);
+}
+
+static void xsc_eth_close_channel(struct xsc_channel *c, bool free_rq)
+{
+ if (free_rq)
+ xsc_eth_close_qp_rq(c, &c->qp.rq);
+ xsc_eth_close_cq(c, &c->qp.rq.cq);
+ memset(&c->qp.rq, 0, sizeof(struct xsc_rq));
+
+ xsc_eth_close_qp_sq(c, &c->qp.sq);
+ xsc_eth_close_cq(c, &c->qp.sq.cq);
+ memset(&c->qp.sq, 0, sizeof(struct xsc_sq));
+}
+
+static int xsc_eth_open_channels(struct xsc_adapter *adapter)
+{
+ struct xsc_channel_param *chl_param;
+ bool free_rq = false;
+ int ret = 0;
+
+ chl_param = kvzalloc_obj(*chl_param, GFP_KERNEL);
+ if (!chl_param)
+ return -ENOMEM;
+
+ xsc_eth_build_channel_param(adapter, chl_param);
+
+ ret = xsc_eth_open_channel(adapter, &adapter->channel, chl_param);
+ if (ret)
+ goto err_free_param;
+
+ ret = xsc_eth_open_qp_rq(&adapter->channel, &adapter->channel.qp.rq,
+ &chl_param->rq_param);
+ if (ret)
+ goto err_close_channel;
+ free_rq = true;
+
+ ret = xsc_eth_modify_qps_channel(adapter, &adapter->channel);
+ if (ret)
+ goto err_close_channel;
+
+ kvfree(chl_param);
+ return 0;
+
+err_close_channel:
+ xsc_eth_close_channel(&adapter->channel, free_rq);
+err_free_param:
+ kvfree(chl_param);
+ netdev_err(adapter->netdev, "failed to open channel, err=%d\n", ret);
+ return ret;
+}
+
+static void xsc_eth_close_channels(struct xsc_adapter *adapter)
+{
+ xsc_eth_close_channel(&adapter->channel, true);
+}
+
+static void xsc_eth_activate_channel(struct xsc_channel *c)
+{
+ struct xsc_sq *psq = &c->qp.sq;
+
+ psq->txq = netdev_get_tx_queue(c->netdev, 0);
+ set_bit(XSC_ETH_SQ_STATE_ENABLED, &psq->state);
+ netdev_tx_reset_queue(psq->txq);
+ netif_tx_start_queue(psq->txq);
+
+ set_bit(XSC_ETH_RQ_STATE_ENABLED, &c->qp.rq.state);
+}
+
+static void xsc_eth_deactivate_channel(struct xsc_channel *c)
+{
+ netif_tx_disable(c->netdev);
+
+ clear_bit(XSC_ETH_RQ_STATE_ENABLED, &c->qp.rq.state);
+ clear_bit(XSC_ETH_SQ_STATE_ENABLED, &c->qp.sq.state);
+
+ synchronize_net();
+}
+
+static int xsc_eth_sw_init(struct xsc_adapter *adapter)
+{
+ int ret;
+
+ ret = xsc_eth_open_channels(adapter);
+ if (ret)
+ return ret;
+
+ xsc_eth_activate_channel(&adapter->channel);
+
+ return 0;
+}
+
+static void xsc_eth_sw_deinit(struct xsc_adapter *adapter)
+{
+ xsc_eth_deactivate_channel(&adapter->channel);
+ xsc_eth_close_channels(adapter);
+}
+
+static bool xsc_get_pct_drop_config(struct xsc_core_device *xdev)
+{
+ return (xdev->pdev->device == XSC_MC_PF_DEV_ID) ||
+ (xdev->pdev->device == XSC_MF_SOC_PF_DEV_ID) ||
+ (xdev->pdev->device == XSC_MS_PF_DEV_ID) ||
+ (xdev->pdev->device == XSC_MV_SOC_PF_DEV_ID);
+}
+
+static int xsc_eth_enable_nic_hca(struct xsc_adapter *adapter)
+{
+ struct xsc_cmd_enable_nic_hca_mbox_out out = {};
+ struct xsc_cmd_enable_nic_hca_mbox_in in = {};
+ struct xsc_core_device *xdev = adapter->xdev;
+ struct net_device *netdev = adapter->netdev;
+ u16 caps_mask = 0;
+ u16 caps = 0;
+ int err;
+
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_ENABLE_NIC_HCA);
+
+ in.rss.rss_en = 1;
+ in.rss.rqn_base = cpu_to_be16(adapter->channel.qp.rq.rqn);
+ in.rss.rqn_num = cpu_to_be16(1);
+ in.rss.hfunc = XSC_HASH_FUNC_TOP;
+ in.rss.hash_tmpl = cpu_to_be32(XSC_HASH_IP_PORTS | XSC_HASH_IP6_PORTS);
+ caps_mask |= BIT(XSC_TBM_CAP_RSS);
+ caps_mask |= BIT(XSC_TBM_CAP_HASH_PPH);
+
+ if (xsc_get_pct_drop_config(xdev))
+ caps |= BIT(XSC_TBM_CAP_PCT_DROP_CONFIG);
+ caps_mask |= BIT(XSC_TBM_CAP_PCT_DROP_CONFIG);
+
+ memcpy(in.nic.mac_addr, netdev->dev_addr, ETH_ALEN);
+
+ in.nic.caps = cpu_to_be16(caps);
+ in.nic.caps_mask = cpu_to_be16(caps_mask);
+
+ err = xsc_cmd_exec(xdev, &in, sizeof(in), &out, sizeof(out));
+ if (err) {
+ netdev_err(netdev, "failed!! err=%d, status=%d\n",
+ err, out.hdr.status);
+ return -ENOEXEC;
+ }
+
+ return 0;
+}
+
+static int xsc_eth_disable_nic_hca(struct xsc_adapter *adapter)
+{
+ struct xsc_cmd_disable_nic_hca_mbox_out out = {};
+ struct xsc_cmd_disable_nic_hca_mbox_in in = {};
+ struct xsc_core_device *xdev = adapter->xdev;
+ struct net_device *netdev = adapter->netdev;
+ u16 caps = 0;
+ int err;
+
+ in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_DISABLE_NIC_HCA);
+
+ if (xsc_get_pct_drop_config(xdev))
+ caps |= BIT(XSC_TBM_CAP_PCT_DROP_CONFIG);
+
+ in.nic.caps = cpu_to_be16(caps);
+ err = xsc_cmd_exec(xdev, &in, sizeof(in), &out, sizeof(out));
+ if (err) {
+ netdev_err(netdev, "failed!! err=%d, status=%d\n",
+ err, out.hdr.status);
+ return -ENOEXEC;
+ }
+
+ return 0;
+}
+
static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
enum xsc_port_status status)
{
@@ -45,25 +813,46 @@ static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
static int xsc_eth_open(struct net_device *netdev)
{
struct xsc_adapter *adapter = netdev_priv(netdev);
+ int ret;
+
+ ret = xsc_eth_sw_init(adapter);
+ if (ret)
+ return ret;
+
+ ret = xsc_eth_enable_nic_hca(adapter);
+ if (ret)
+ goto err_sw_deinit;
adapter->opened = true;
xsc_set_port_admin_status(adapter, XSC_PORT_UP);
return 0;
+
+err_sw_deinit:
+ xsc_eth_sw_deinit(adapter);
+ return ret;
}
static int xsc_eth_close(struct net_device *netdev)
{
struct xsc_adapter *adapter = netdev_priv(netdev);
+ int ret;
adapter->opened = false;
netif_carrier_off(adapter->netdev);
+ xsc_eth_sw_deinit(adapter);
+
+ ret = xsc_eth_disable_nic_hca(adapter);
+ if (ret)
+ netdev_err(adapter->netdev, "failed to disable nic hca, err=%d\n",
+ ret);
+
xsc_set_port_admin_status(adapter, XSC_PORT_DOWN);
- return 0;
+ return ret;
}
static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.c b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.c
new file mode 100644
index 000000000..b69a4e373
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd. All
+ * rights reserved.
+ * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
+ */
+
+#include "xsc_eth_wq.h"
+#include "xsc_eth.h"
+
+u32 xsc_wq_cyc_get_size(struct xsc_wq_cyc *wq)
+{
+ return (u32)wq->fbc.sz_m1 + 1;
+}
+
+static u32 wq_get_byte_sz(u8 log_sz, u8 log_stride)
+{
+ return ((u32)1 << log_sz) << log_stride;
+}
+
+int xsc_eth_cqwq_create(struct xsc_core_device *xdev,
+ struct xsc_wq_param *param,
+ u8 q_log_size,
+ u8 ele_log_size,
+ struct xsc_cqwq *wq,
+ struct xsc_wq_ctrl *wq_ctrl)
+{
+ u8 log_wq_stride = ele_log_size;
+ u8 log_wq_sz = q_log_size;
+ int err;
+
+ err = xsc_core_frag_buf_alloc_node(xdev,
+ wq_get_byte_sz(log_wq_sz,
+ log_wq_stride),
+ &wq_ctrl->buf,
+ param->buf_numa_node);
+ if (err) {
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "xsc_core_frag_buf_alloc_node failed, %d\n", err);
+ return err;
+ }
+
+ xsc_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, &wq->fbc);
+ wq_ctrl->xdev = xdev;
+ return 0;
+}
+
+int xsc_eth_wq_cyc_create(struct xsc_core_device *xdev,
+ struct xsc_wq_param *param,
+ u8 q_log_size,
+ u8 ele_log_size,
+ struct xsc_wq_cyc *wq,
+ struct xsc_wq_ctrl *wq_ctrl)
+{
+ struct xsc_frag_buf_ctrl *fbc = &wq->fbc;
+ u8 log_wq_stride = ele_log_size;
+ u8 log_wq_sz = q_log_size;
+ int err;
+
+ err = xsc_core_frag_buf_alloc_node(xdev,
+ wq_get_byte_sz(log_wq_sz,
+ log_wq_stride),
+ &wq_ctrl->buf,
+ param->buf_numa_node);
+ if (err) {
+ netdev_err(xsc_dev_to_netdev(xdev),
+ "xsc_core_frag_buf_alloc_node failed, %d\n", err);
+ return err;
+ }
+
+ xsc_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, fbc);
+ wq->sz = xsc_wq_cyc_get_size(wq);
+ wq_ctrl->xdev = xdev;
+ return 0;
+}
+
+void xsc_eth_wq_destroy(struct xsc_wq_ctrl *wq_ctrl)
+{
+ xsc_core_frag_buf_free(wq_ctrl->xdev, &wq_ctrl->buf);
+}
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
index 46eb0b031..0b0478c64 100644
--- a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
@@ -121,3 +121,105 @@ void xsc_fill_page_array(struct xsc_buf *buf, __be64 *pas, unsigned int npages)
pas[i] = cpu_to_be64(addr);
}
}
+EXPORT_SYMBOL_GPL(xsc_fill_page_array);
+
+void xsc_core_fill_page_frag_array(struct xsc_frag_buf *buf,
+ __be64 *pas,
+ unsigned int npages)
+{
+ int i;
+ dma_addr_t addr;
+ unsigned int shift = PAGE_SHIFT - XSC_PAGE_SHIFT_4K;
+ unsigned int mask = (1 << shift) - 1;
+
+ for (i = 0; i < npages; i++) {
+ addr = buf->frags[i >> shift].map +
+ ((i & mask) << XSC_PAGE_SHIFT_4K);
+ pas[i] = cpu_to_be64(addr);
+ }
+}
+EXPORT_SYMBOL_GPL(xsc_core_fill_page_frag_array);
+
+static void *xsc_dma_zalloc_coherent_node(struct xsc_core_device *xdev,
+ size_t size, dma_addr_t *dma_handle,
+ int node)
+{
+ struct device *device = &xdev->pdev->dev;
+ int original_node;
+ void *cpu_handle;
+
+ /* WA for kernels that don't use numa_mem_id in alloc_pages_node */
+ if (node == NUMA_NO_NODE)
+ node = numa_mem_id();
+
+ original_node = dev_to_node(device);
+ set_dev_node(device, node);
+ cpu_handle = dma_alloc_coherent(device, size, dma_handle, GFP_KERNEL);
+ set_dev_node(device, original_node);
+
+ return cpu_handle;
+}
+
+int xsc_core_frag_buf_alloc_node(struct xsc_core_device *xdev,
+ unsigned long size,
+ struct xsc_frag_buf *buf,
+ int node)
+{
+ int i;
+
+ buf->size = size;
+ buf->npages = DIV_ROUND_UP(size, PAGE_SIZE);
+ buf->page_shift = PAGE_SHIFT;
+ buf->frags = kcalloc(buf->npages, sizeof(struct xsc_buf_list),
+ GFP_KERNEL);
+ if (!buf->frags)
+ goto err_out;
+
+ for (i = 0; i < buf->npages; i++) {
+ unsigned long frag_sz = min_t(unsigned long, size, PAGE_SIZE);
+ struct xsc_buf_list *frag = &buf->frags[i];
+
+ frag->buf = xsc_dma_zalloc_coherent_node(xdev, frag_sz,
+ &frag->map, node);
+ if (!frag->buf)
+ goto err_free_buf;
+ if (frag->map & ((1 << buf->page_shift) - 1)) {
+ dma_free_coherent(&xdev->pdev->dev, frag_sz,
+ buf->frags[i].buf, buf->frags[i].map);
+ pci_err(xdev->pdev, "unexpected map alignment: %pad, page_shift=%d\n",
+ &frag->map, buf->page_shift);
+ goto err_free_buf;
+ }
+ size -= frag_sz;
+ }
+
+ return 0;
+
+err_free_buf:
+ while (i--)
+ dma_free_coherent(&xdev->pdev->dev,
+ PAGE_SIZE,
+ buf->frags[i].buf,
+ buf->frags[i].map);
+ kfree(buf->frags);
+err_out:
+ return -ENOMEM;
+}
+EXPORT_SYMBOL_GPL(xsc_core_frag_buf_alloc_node);
+
+void xsc_core_frag_buf_free(struct xsc_core_device *xdev,
+ struct xsc_frag_buf *buf)
+{
+ unsigned long size = buf->size;
+ int i;
+
+ for (i = 0; i < buf->npages; i++) {
+ unsigned long frag_sz = min_t(unsigned long, size, PAGE_SIZE);
+
+ dma_free_coherent(&xdev->pdev->dev, frag_sz, buf->frags[i].buf,
+ buf->frags[i].map);
+ size -= frag_sz;
+ }
+ kfree(buf->frags);
+}
+EXPORT_SYMBOL_GPL(xsc_core_frag_buf_free);
--
2.43.0
Re: [PATCH v2 07/11] net/xsc: add the ethernet netdev
Author: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 15:57
Date: Fri, 27 Nov 2026 15:57
243 lines
15866 bytes
15866 bytes
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 4
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] At this commit, xsc_eth_probe() registers a netdev whose ops
table (xsc_netdev_ops in…
- [Low] This patch adds calls to the auxiliary bus API.
- [Low] At this commit, xsc_eth_wq.h declares xsc_eth_cqwq_create(),
xsc_eth_wq_cyc_create(), xsc_eth_wq_destroy() and…
- [Low] Several comments do not match the code.
- [Low] xsc_eth_l2_addr_init()
(drivers/net/ethernet/yunsilicon/xsc/net/main.c:156) declares `char…
--
net/xsc: add the ethernet netdev
This patch registers an ethernet auxiliary device from the xsc PCI core and
adds an auxiliary driver that creates a netdev. The netdev queries the MAC
address, sets the hardware MTU, and implements ndo_open/ndo_stop. The queue
and data path are left to follow-up patches.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig b/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
> new file mode 100644
> index 0000000000000..7428b26295b66
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/Kconfig
> @@ -0,0 +1,17 @@
[ ... ]
> +config YUNSILICON_XSC_ETH
> + tristate "Yunsilicon XSC ethernet driver"
> + depends on YUNSILICON_XSC_PCI
> + depends on NET
> + select PAGE_POOL
[Severity: Low]
Should this entry select AUXILIARY_BUS? xsc_eth uses
module_auxiliary_driver(). xsc_pci now builds adev.o, and xsc_adev_add()
in that file calls auxiliary_device_init() and auxiliary_device_add().
AUXILIARY_BUS is a bool with no prompt in drivers/base/Kconfig:
config AUXILIARY_BUS
bool
auxiliary.o is only built under obj-$(CONFIG_AUXILIARY_BUS), and
include/linux/auxiliary_bus.h has no stubs for the disabled case.
If nothing else in the config selects AUXILIARY_BUS, won't the link or
modpost fail with undefined references to __auxiliary_device_add() and
__auxiliary_driver_register()?
At the end of the series, neither YUNSILICON_XSC_PCI nor YUNSILICON_XSC_ETH
selects it.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> new file mode 100644
> index 0000000000000..b9e75d7e14e78
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -0,0 +1,263 @@
[ ... ]
> +static const struct net_device_ops xsc_netdev_ops = {
> + .ndo_open = xsc_eth_open,
> + .ndo_stop = xsc_eth_close,
> +};
[Severity: Medium]
The commit message says the netdev "must not be brought up in this state".
Does anything enforce that?
xsc_netdev_ops has no ndo_start_xmit. xsc_eth_open() always returns 0, so
the interface can be brought up once xsc_eth_probe() has called
register_netdev().
Carrier stays off at this commit, so the qdisc path drops packets. netpoll
does not check carrier, though:
__netpoll_send_skb()
if (!npinfo || !netif_running(dev) || !netif_device_present(dev)) {
...
netpoll_start_xmit()
netdev_start_xmit()
ops->ndo_start_xmit() <- NULL here
__netpoll_setup() only rejects IFF_DISABLE_NETPOLL devices. Can
configuring netconsole on this interface end in a NULL function pointer
call?
Later in the series, "net/xsc: report link state changes" adds
netif_carrier_on() while xsc_netdev_ops still has no ndo_start_xmit. At
that commit, a plain "ip link set up" with the link up seems to be enough
to hit this.
"net/xsc: add the transmit path" adds .ndo_start_xmit = xsc_eth_xmit, so
the end of the series is fine. The intermediate commits are still
bisectable, though.
Would a stub ndo_start_xmit that drops the skb work until the transmit
patch lands? Failing ndo_open with an error would be another option.
[ ... ]
> +static void xsc_eth_l2_addr_init(struct xsc_adapter *adapter)
> +{
> + struct net_device *netdev = adapter->netdev;
> + char mac[6] = {0};
> + int ret = 0;
> +
> + ret = xsc_eth_get_mac(adapter->xdev, mac);
[Severity: Low]
Is mac[] guaranteed to be u16 aligned here?
xsc_eth_get_mac() fills it with ether_addr_copy(mac, out->mac). It is then
passed to is_valid_ether_addr(), which calls is_zero_ether_addr().
include/linux/etherdevice.h documents that both need u16 alignment:
* Please note: dst & src must both be aligned to u16.
A char[6] on the stack is only 1-byte aligned. Without
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, could these become unaligned u16
accesses?
Would u8 mac[ETH_ALEN] __aligned(2), with xsc_eth_get_mac() taking a u8 *,
avoid this? The code is unchanged at the end of the series.
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
> new file mode 100644
> index 0000000000000..35206ddf42f46
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_wq.h
> @@ -0,0 +1,150 @@
[ ... ]
> +u32 xsc_wq_cyc_get_size(struct xsc_wq_cyc *wq);
> +
> +int xsc_eth_cqwq_create(struct xsc_core_device *xdev,
> + struct xsc_wq_param *param,
> + u8 q_log_size,
> + u8 ele_log_size,
> + struct xsc_cqwq *wq,
> + struct xsc_wq_ctrl *wq_ctrl);
> +
> +int xsc_eth_wq_cyc_create(struct xsc_core_device *xdev,
> + struct xsc_wq_param *param,
> + u8 q_log_size,
> + u8 ele_log_size,
> + struct xsc_wq_cyc *wq,
> + struct xsc_wq_ctrl *wq_ctrl);
> +void xsc_eth_wq_destroy(struct xsc_wq_ctrl *wq_ctrl);
[Severity: Low]
This isn't a bug, but these prototypes have no definitions at this commit.
The net Makefile only builds main.o:
xsc_eth-y := main.o
Several other items are also unused here:
xsc_queue.h
the queue parameter structs
the CQE/WQE layouts
XSC_INVALID_LKEY and XSC_QUEUE_TYPE_RAW*
adapter->channel
select PAGE_POOL
Nothing calls these functions, so this commit builds and links. Later in
the series, "net/xsc: add the single TX/RX channel" adds xsc_eth_wq.c, and
the transmit and receive patches use the rest.
Could these definitions move into the patches that first use them?
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
> new file mode 100644
> index 0000000000000..3376ed10ba6ca
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/adev.c
> @@ -0,0 +1,133 @@
[ ... ]
> +static void xsc_adev_del(struct xsc_core_device *xdev, int idx)
> +{
[ ... ]
> + /* Clear the slot before teardown: the driver's remove callback runs
> + * synchronously inside auxiliary_device_delete() and may re-enter
> + * xsc_adev_add() for this index.
> + */
> + xdev->xsc_adev_list[idx] = NULL;
[Severity: Low]
Is this comment accurate? xsc_adev_add() is static, and its only caller is
xsc_adev_init(). xsc_adev_init() is only called from xsc_pci_init().
xsc_eth_remove() never calls back into the PCI layer. It doesn't look like
the remove callback can re-enter xsc_adev_add(). The comment is unchanged
at the end of the series.
A couple of other descriptions don't seem to match the code at this commit
either. xsc_eth_remove() has:
/* Runs ndo_stop(), so the queues and the HCA are shut down first. */
xsc_eth_close() only clears adapter->opened, turns the carrier off and
sends XSC_PORT_DOWN. Queue and HCA teardown only arrive in later patches.
The commit message says:
create the device, program the MAC address and MTU
xsc_eth_l2_addr_init() only queries the MAC with XSC_CMD_OP_QUERY_ETH_MAC
and calls eth_hw_addr_set(). Nothing is written to the device.
The commit message also doesn't mention that ndo_open sets the port admin
status to up.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
Re: [PATCH v2 08/11] net/xsc: add the single TX/RX channel
Author: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 15:58
Date: Fri, 27 Nov 2026 15:58
399 lines
22530 bytes
22530 bytes
Thank you for your contribution! Sashiko AI review found 11 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 4 · Low: 6
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] xsc_eth_alloc_rq()
(drivers/net/ethernet/yunsilicon/xsc/net/main.c) reports success when…
- [Medium] The teardown order in xsc_eth_close() is not the reverse of
xsc_eth_open().
- [Medium] xsc_eth_build_queue_param() sets the RQ depth to `rq_size =
BIT(xdev->caps.log_max_qp_depth)` (line 38) with no clamp.
- [Medium] ENABLE_NIC_HCA in xsc_eth_enable_nic_hca() writes the absolute
QPN returned by CREATE_QP into in.rss.rqn_base (line 745).
- [Medium] net/xsc: WQ DMA buffers freed on xsc_core_eth_destroy_qp()
rollback failure
- [Low] Software and the CREATE_QP mailbox round the WQE stride
differently.
- [Low] When DESTROY_QP fails, xsc_eth_close_qp_rq() and
xsc_eth_close_qp_sq() return early on purpose and leak the WQ buffer,…
- [Low] The patch adds EXPORT_SYMBOL_GPL(xsc_fill_page_array) in
drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c (line 124), and the…
- [Low] In xsc_eth_qp_event(), the branch for an unknown queue type
prints `type` (the async event code) instead of qp->eth_queue_type,…
- [Low] xsc_dma_zalloc_coherent_node() (pci/alloc.c, lines 155-158) saves
the numa_node of the shared, live PCI device, overwrites it with…
- [Low] xsc_eth_open_channel() reads the live IRQ descriptor's affinity
mask without desc->lock: `aff = irq_get_affinity_mask(irqn); if (aff)…
--
net/xsc: add the single TX/RX channel
This patch brings up a single TX/RX channel on the xsc netdev. It builds
the queue parameters, creates the CQs, SQ and RQ through the core, and
enables the NIC HCA from ndo_open. It also adds the work queue ring helpers
and the fragmented DMA buffer allocation helpers in the pci core.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> index b9e75d7e14e78..1c7bbc27d8c4f 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -25,6 +25,774 @@ static void xsc_eth_netdev_init(struct xsc_adapter *adapter)
> netif_carrier_off(adapter->netdev);
> }
>
> +static void xsc_eth_build_queue_param(struct xsc_adapter *adapter,
> + struct xsc_queue_attr *attr, u8 type)
> +{
> + struct xsc_core_device *xdev = adapter->xdev;
> +
> + if (adapter->nic_param.sq_size == 0)
> + adapter->nic_param.sq_size = min_t(u32,
> + BIT(xdev->caps.log_max_qp_depth),
> + XSC_SQCQ_ELE_NUM);
> + if (adapter->nic_param.rq_size == 0)
> + adapter->nic_param.rq_size = BIT(xdev->caps.log_max_qp_depth);
[Severity: Medium]
Should rq_size be clamped here the same way sq_size is?
Further down, the RQ's CQ gets min(XSC_RQCQ_ELE_NUM, caps.max_cqes)
entries. If firmware reports log_max_qp_depth above 11, the RQ ring ends up
deeper than its 2048-entry CQ. Once the receive path fills the ring, could
more completions be outstanding than the CQ can hold?
The sq_size clamp only uses XSC_SQCQ_ELE_NUM and ignores caps.max_cqes, so
the SQ can also end up deeper than its CQ.
Separately, struct xsc_wq_cyc in xsc_eth_wq.h stores the ring size in u16
fields:
struct xsc_wq_cyc {
struct xsc_frag_buf_ctrl fbc;
u16 sz;
u16 wqe_ctr;
u16 cur_sz;
};
xsc_wq_cyc_get_size() returns u32, though. With log_max_qp_depth >= 16,
xsc_eth_wq_cyc_create() would truncate wq->sz to 0. xsc_wq_cyc_missing()
would then never be positive, so the RX ring would never be posted. Can
firmware report a value in that range?
[ ... ]
> + } else if (type == XSC_QUEUE_TYPE_RQ) {
> + attr->ele_num = adapter->nic_param.rq_size;
> + attr->ele_size = xdev->caps.recv_ds_num * XSC_RECV_WQE_DS;
> + attr->ele_log_size = order_base_2(attr->ele_size);
> + attr->q_log_size = order_base_2(attr->ele_num);
> + } else if (type == XSC_QUEUE_TYPE_SQ) {
> + attr->ele_num = adapter->nic_param.sq_size;
> + attr->ele_size = xdev->caps.send_ds_num * XSC_SEND_WQE_DS;
> + attr->ele_log_size = order_base_2(attr->ele_size);
> + attr->q_log_size = order_base_2(attr->ele_num);
> + }
> +}
[Severity: Low]
The software WQE stride here is order_base_2(ds_num * 16), which rounds
up. xsc_eth_open_qp_sq() and xsc_eth_open_qp_rq() pass the hardware a size
that rounds down:
in->req.log_sq_sz = ilog2(xdev->caps.send_ds_num) + q_log_size;
in->req.log_rq_sz = ilog2(xdev->caps.recv_ds_num) + q_log_size;
send_ds_num and recv_ds_num come from firmware, and nothing checks that
they are powers of two. If one is not, do the hardware and software then
disagree on WQE offsets and ring size?
Could one rounding be used consistently, or non-power-of-two values be
rejected?
[ ... ]
> +static void xsc_eth_qp_event(struct xsc_core_qp *qp, int type)
> +{
> + struct xsc_core_device *xdev;
> + struct xsc_rq *rq;
> + struct xsc_sq *sq;
> +
> + if (qp->eth_queue_type == XSC_RES_RQ) {
> + rq = container_of(qp, struct xsc_rq, cqp);
> + xdev = rq->cq.xdev;
> + } else if (qp->eth_queue_type == XSC_RES_SQ) {
> + sq = container_of(qp, struct xsc_sq, cqp);
> + xdev = sq->cq.xdev;
> + } else {
> + pr_err("%s:Unknown eth qp type %d\n", __func__, type);
[Severity: Low]
This isn't a bug, but should this print qp->eth_queue_type instead of type?
type is the async event code, not the queue type that failed the check.
[ ... ]
> +static int xsc_eth_open_channel(struct xsc_adapter *adapter,
> + struct xsc_channel *c,
> + struct xsc_channel_param *chl_param)
> +{
[ ... ]
> + ret = xsc_core_vector2eqn(xdev, 0, &eqn, &irqn);
> + if (ret)
> + goto err_out;
> + aff = irq_get_affinity_mask(irqn);
> + if (aff)
> + c->cpu = cpumask_first(aff);
[Severity: Low]
Can c->cpu end up >= nr_cpu_ids here?
The affinity mask is read without desc->lock. On a system with more than
BITS_PER_LONG CPUs, a concurrent write to /proc/irq/N/smp_affinity could
briefly expose an empty mask. xsc_eth_alloc_cq(), xsc_eth_open_qp_sq() and
xsc_eth_alloc_rq() then use c->cpu in cpu_to_node(c->cpu) without a range
check.
Would cpumask_first_and() with cpu_online_mask, plus a fallback when the
result is >= nr_cpu_ids, be safer?
[ ... ]
> +static int xsc_eth_alloc_rq(struct xsc_channel *c,
> + struct xsc_rq *prq,
> + struct xsc_rq_param *prq_param)
> +{
[ ... ]
> + ret = xsc_eth_wq_cyc_create(c->adapter->xdev, &prq_param->wq,
> + q_log_size, ele_log_size, &prq->wqe.wq,
> + &prq->wq_ctrl);
> + if (ret)
> + return ret;
> +
> + wq_sz = xsc_wq_cyc_get_size(&prq->wqe.wq);
> + prq->wqe.di = kvzalloc_node(array_size(wq_sz, sizeof(*prq->wqe.di)),
> + GFP_KERNEL, cpu_to_node(c->cpu));
> + if (!prq->wqe.di)
> + goto err_destroy_wq;
[Severity: High]
Is ret still 0 at this point? The last assignment was the successful
xsc_eth_wq_cyc_create(). If kvzalloc_node() fails, this path frees the WQ
buffer and returns 0.
xsc_eth_open_qp_rq() then treats the call as a success:
xsc_eth_open_qp_rq()
hw_npages = DIV_ROUND_UP(prq->wq_ctrl.buf.size, XSC_PAGE_SIZE_4K);
...
xsc_core_fill_page_frag_array(&prq->wq_ctrl.buf,
&in->req.pas[0], hw_npages);
ret = xsc_core_eth_create_qp(xdev, in, inlen, &prq->rqn);
xsc_core_frag_buf_free() kfree()s buf->frags but leaves frags, npages and
size unchanged. xsc_core_fill_page_frag_array() therefore reads the freed
frags array. CREATE_QP is then given the DMA addresses of pages that
dma_free_coherent() has already released. Could the device then DMA into
freed memory?
Later, xsc_eth_free_qp_rq() runs, from either the CREATE_QP failure path or
xsc_eth_close_qp_rq(). It calls xsc_eth_wq_destroy() again on the same
stale buf, so every coherent frag and buf->frags would be freed a second
time.
With the receive patch that follows, xsc_eth_modify_qps_channel() also ends
up posting RX WQEs while di == NULL, page_pool == NULL and wqe_bulk == 0.
Should ret be set to -ENOMEM before the goto, and should
xsc_core_frag_buf_free() clear buf->frags and buf->npages?
[ ... ]
> +static void xsc_eth_close_channel(struct xsc_channel *c, bool free_rq)
> +{
> + if (free_rq)
> + xsc_eth_close_qp_rq(c, &c->qp.rq);
> + xsc_eth_close_cq(c, &c->qp.rq.cq);
> + memset(&c->qp.rq, 0, sizeof(struct xsc_rq));
> +
> + xsc_eth_close_qp_sq(c, &c->qp.sq);
> + xsc_eth_close_cq(c, &c->qp.sq.cq);
> + memset(&c->qp.sq, 0, sizeof(struct xsc_sq));
> +}
[Severity: Low]
When DESTROY_QP fails, xsc_eth_close_qp_rq() and xsc_eth_close_qp_sq()
return early on purpose and leak the WQ buffer, because the QP is still
live in firmware. They return void, though.
Does this function then destroy the CQ that the live QP is still bound to,
and memset() away its QPN and wq_ctrl?
If so, there is no way to retry the destroy or reclaim the leaked DMA
pages. The CQN could also be reused by another queue while the old QP
still points at it.
Could the close helpers report the failure, so that the CQ teardown and
the memset() are skipped in that case?
[ ... ]
> +static int xsc_eth_enable_nic_hca(struct xsc_adapter *adapter)
> +{
[ ... ]
> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_ENABLE_NIC_HCA);
> +
> + in.rss.rss_en = 1;
> + in.rss.rqn_base = cpu_to_be16(adapter->channel.qp.rq.rqn);
[Severity: Medium]
Does firmware expect an absolute QPN in rqn_base?
struct xsc_hca_cap in common/xsc_cmd.h has raweth_rss_qp_id_base and
raweth_qp_id_base fields. The caps query in pci/main.c never parses them,
and nothing subtracts a base from rqn.
If firmware treats rqn_base as relative to raweth_rss_qp_id_base, RSS could
steer traffic to the wrong RQ on any function where that base is non-zero.
Also, cpu_to_be16() here silently narrows the 24-bit qpn returned by
xsc_core_eth_create_qp() to 16 bits.
[ ... ]
> @@ -45,25 +813,46 @@ static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
[ ... ]
> static int xsc_eth_close(struct net_device *netdev)
> {
> struct xsc_adapter *adapter = netdev_priv(netdev);
> + int ret;
>
> adapter->opened = false;
>
> netif_carrier_off(adapter->netdev);
>
> + xsc_eth_sw_deinit(adapter);
> +
> + ret = xsc_eth_disable_nic_hca(adapter);
> + if (ret)
> + netdev_err(adapter->netdev, "failed to disable nic hca, err=%d\n",
> + ret);
> +
> xsc_set_port_admin_status(adapter, XSC_PORT_DOWN);
>
> - return 0;
> + return ret;
> }
[Severity: Medium]
If xsc_core_eth_create_qp() has succeeded and a later step fails, this
rollback calls xsc_core_eth_destroy_qp() but ignores its return value,
then falls through to xsc_eth_wq_destroy() and frees the SQ WQ pages
anyway.
xsc_eth_close_qp_sq() and xsc_eth_close_qp_rq() in this same patch
check the DESTROY_QP result and deliberately leak the WQ buffer when it
fails, because the QP is still live in firmware with those pages
programmed. Shouldn't the open-time rollback follow the same rule?
As written, a failure in xsc_core_create_resource_common(),
xsc_eth_alloc_qp_sq_db() or xsc_core_eth_modify_raw_qp() followed by a
failed DESTROY_QP hands pages back to the allocator that the device can
still DMA into.
xsc_eth_open_qp_rq() has the same issue at err_destroy_qp. The result
of xsc_core_eth_destroy_qp() is dropped, and xsc_eth_free_qp_rq() then
frees the WQ buffer and destroys the page_pool anyway.
Could both paths check the destroy result and skip the buffer free (and
the page_pool destroy for the RQ) when it fails?
[Severity: Medium]
Should this teardown be the reverse of xsc_eth_open()?
Open creates the queues and then sends ENABLE_NIC_HCA with RSS pointed at
channel.qp.rq.rqn. Close does it the other way round.
xsc_eth_sw_deinit() destroys the RQ/SQ, the CQs, the buffers and the
page_pool first. Only after that is DISABLE_NIC_HCA sent, and the port is
still admin up at that point.
During that window, the HCA steering refers to a QPN that firmware has
already destroyed and may reuse. If DISABLE_NIC_HCA fails, close only logs
an error, and the HCA stays enabled with a stale RQN.
Would it be better to disable the HCA, or redirect RSS, before the queues
are destroyed?
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> index 46eb0b031511d..0b0478c64be3b 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/alloc.c
> @@ -121,3 +121,105 @@ void xsc_fill_page_array(struct xsc_buf *buf, __be64 *pas, unsigned int npages)
> pas[i] = cpu_to_be64(addr);
> }
> }
> +EXPORT_SYMBOL_GPL(xsc_fill_page_array);
[Severity: Low]
This isn't a bug, but is this export needed?
xsc_fill_page_array() is declared only in the private pci/alloc.h. Its only
caller is xsc_create_eq() in pci/eq.c, which is built into the same module.
xsc_eth uses only the new frag helpers.
The commit message doesn't mention this export either.
[ ... ]
> +static void *xsc_dma_zalloc_coherent_node(struct xsc_core_device *xdev,
> + size_t size, dma_addr_t *dma_handle,
> + int node)
> +{
> + struct device *device = &xdev->pdev->dev;
> + int original_node;
> + void *cpu_handle;
> +
> + /* WA for kernels that don't use numa_mem_id in alloc_pages_node */
> + if (node == NUMA_NO_NODE)
> + node = numa_mem_id();
> +
> + original_node = dev_to_node(device);
> + set_dev_node(device, node);
> + cpu_handle = dma_alloc_coherent(device, size, dma_handle, GFP_KERNEL);
> + set_dev_node(device, original_node);
[Severity: Low]
What serializes this save, modify and restore of the PCI device's
numa_node? mlx5_dma_zalloc_coherent_node(), which this looks derived from,
holds priv->alloc_mutex around the same sequence.
Other users of &xdev->pdev->dev can see the temporary node. One example is
the xsc_cmd dma_pool created in cmd.c, which is used from the event
workqueue without rtnl.
Two concurrent callers of the exported xsc_core_frag_buf_alloc_node() could
also interleave their save and restore steps. That would leave
dev->numa_node permanently wrong.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
Re: [PATCH v2 07/11] net/xsc: add the ethernet netdev
Author: Andrew Lunn
Date: Sat, 28 Nov 2026 17:49
Date: Sat, 28 Nov 2026 17:49
77 lines
10733 bytes
10733 bytes
> +static void xsc_eth_build_nic_params(struct xsc_adapter *adapter)
> +{
> + struct xsc_eth_params *params = &adapter->nic_param;
> +
> + params->mtu = SW_DEFAULT_MTU;
> +}
> +static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
> + u16 mtu, u16 rx_buf_sz)
> +{
> + struct xsc_set_mtu_mbox_out out;
> + struct xsc_set_mtu_mbox_in in;
> + int err;
> +
> + memset(&in, 0, sizeof(struct xsc_set_mtu_mbox_in));
> + memset(&out, 0, sizeof(struct xsc_set_mtu_mbox_out));
> +
> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_SET_MTU);
> + in.mtu = cpu_to_be16(mtu);
> + in.rx_buf_sz_min = cpu_to_be16(rx_buf_sz);
> + in.mac_port = xdev->mac_port;
> +
> + err = xsc_cmd_exec(xdev, &in, sizeof(struct xsc_set_mtu_mbox_in), &out,
> + sizeof(struct xsc_set_mtu_mbox_out));
> + if (err) {
> + netdev_err(xsc_dev_to_netdev(xdev),
> + "failed to set hw_mtu=%u rx_buf_sz=%u, err=%d, status=%d\n",
> + mtu, rx_buf_sz, err, out.hdr.status);
> + return err;
> + }
> +
> + return 0;
> +}
> +static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
> +{
> + struct net_device *netdev = adapter->netdev;
> +
> + netdev->netdev_ops = &xsc_netdev_ops;
> +
> + netdev->min_mtu = SW_DEFAULT_MTU;
> + netdev->max_mtu = SW_DEFAULT_MTU;
> + netdev->mtu = SW_DEFAULT_MTU;
If the MTU is fixed, it seems pointless having xsc_eth_set_hw_mtu().
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
> @@ -0,0 +1,33 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#ifndef __XSC_ETH_H
> +#define __XSC_ETH_H
> +
> +#include <linux/udp.h>
Why this header? How is UDP special?
> +#define SW_DEFAULT_MTU ETH_DATA_LEN
Please don't alias well known #defines. I know what ETH_DATA_LEN is,
fixing the MTU to that makes sense. But i had not idea what
SW_DEFAULT_MTU was until i got here. So you are just obfuscating the
code.
> +#define XSC_ETH_HW_MTU_SEND 9800
> +#define XSC_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN * 2 + ETH_FCS_LEN)
The code would be a lot more readable if you used these in the actual
code, rather than hide them here. I can see this and see you need
space for the ethernet header, up to two VLAN headers and the trailing
CRC. XSC_ETH_HARD_MTU tells me nothing.
Andrew
Re: [PATCH v2 07/11] net/xsc: add the ethernet netdev
Author: "Xin Tian"
Date: Tue, 01 Dec 2026 10:06
Date: Tue, 01 Dec 2026 10:06
93 lines
12111 bytes
12111 bytes
On 11/29/2026 1:49 AM, Andrew Lunn wrote:
>> +static void xsc_eth_build_nic_params(struct xsc_adapter *adapter)
>> +{
>> + struct xsc_eth_params *params = &adapter->nic_param;
>> +
>> + params->mtu = SW_DEFAULT_MTU;
>> +}
>> +static int xsc_eth_set_hw_mtu(struct xsc_core_device *xdev,
>> + u16 mtu, u16 rx_buf_sz)
>> +{
>> + struct xsc_set_mtu_mbox_out out;
>> + struct xsc_set_mtu_mbox_in in;
>> + int err;
>> +
>> + memset(&in, 0, sizeof(struct xsc_set_mtu_mbox_in));
>> + memset(&out, 0, sizeof(struct xsc_set_mtu_mbox_out));
>> +
>> + in.hdr.opcode = cpu_to_be16(XSC_CMD_OP_SET_MTU);
>> + in.mtu = cpu_to_be16(mtu);
>> + in.rx_buf_sz_min = cpu_to_be16(rx_buf_sz);
>> + in.mac_port = xdev->mac_port;
>> +
>> + err = xsc_cmd_exec(xdev, &in, sizeof(struct xsc_set_mtu_mbox_in), &out,
>> + sizeof(struct xsc_set_mtu_mbox_out));
>> + if (err) {
>> + netdev_err(xsc_dev_to_netdev(xdev),
>> + "failed to set hw_mtu=%u rx_buf_sz=%u, err=%d, status=%d\n",
>> + mtu, rx_buf_sz, err, out.hdr.status);
>> + return err;
>> + }
>> +
>> + return 0;
>> +}
>> +static void xsc_eth_build_nic_netdev(struct xsc_adapter *adapter)
>> +{
>> + struct net_device *netdev = adapter->netdev;
>> +
>> + netdev->netdev_ops = &xsc_netdev_ops;
>> +
>> + netdev->min_mtu = SW_DEFAULT_MTU;
>> + netdev->max_mtu = SW_DEFAULT_MTU;
>> + netdev->mtu = SW_DEFAULT_MTU;
> If the MTU is fixed, it seems pointless having xsc_eth_set_hw_mtu().
I'd like to keep xsc_eth_set_hw_mtu(). Fixed MTU just means the netdev
MTU isn't user-changeable; the function sends a SET_MTU firmware command
that programs the port's frame length and RX buffer size into the
hardware,
which has to happen at probe either way.
>> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth.h
>> @@ -0,0 +1,33 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
>> + * All rights reserved.
>> + */
>> +
>> +#ifndef __XSC_ETH_H
>> +#define __XSC_ETH_H
>> +
>> +#include <linux/udp.h>
> Why this header? How is UDP special?
Will remove the unused <linux/udp.h> include.
>
>> +#define SW_DEFAULT_MTU ETH_DATA_LEN
> Please don't alias well known #defines. I know what ETH_DATA_LEN is,
> fixing the MTU to that makes sense. But i had not idea what
> SW_DEFAULT_MTU was until i got here. So you are just obfuscating the
> code.
Right, I'll drop the SW_DEFAULT_MTU alias and use ETH_DATA_LEN directly.
>> +#define XSC_ETH_HW_MTU_SEND 9800
>> +#define XSC_ETH_HARD_MTU (ETH_HLEN + VLAN_HLEN * 2 + ETH_FCS_LEN)
> The code would be a lot more readable if you used these in the actual
> code, rather than hide them here. I can see this and see you need
> space for the ethernet header, up to two VLAN headers and the trailing
> CRC. XSC_ETH_HARD_MTU tells me nothing.
>
> Andrew
Agreed, XSC_ETH_HARD_MTU is not a descriptive name. I will drop
XSC_ETH_HARD_MTU and write the length calculation where it is used:
#define XSC_SW2HW_MTU(mtu) ((mtu) + ETH_HLEN + 2 * VLAN_HLEN +
ETH_FCS_LEN)
Thanks,
Xin
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads