Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by "Xin Tian"
Thu, 26 Nov 2026 14:57
[PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver
Author: "Xin Tian"
Date: Thu, 26 Nov 2026 14:57
Date: Thu, 26 Nov 2026 14:57
402 lines
20465 bytes
20465 bytes
skeleton
Add the Yunsilicon vendor Kbuild glue and the PCI layer of the XSC
ethernet driver. For now the PCI core only enables the device, maps
BAR0 and records DMA capabilities; the doorbell, command queue and
netdev layer are added by subsequent patches.
Signed-off-by: Xin Tian <tianx@yunsilicon.com>
---
MAINTAINERS | 7 +
drivers/net/ethernet/Kconfig | 1 +
drivers/net/ethernet/Makefile | 1 +
drivers/net/ethernet/yunsilicon/Kconfig | 26 +++
drivers/net/ethernet/yunsilicon/Makefile | 8 +
.../ethernet/yunsilicon/xsc/common/xsc_core.h | 35 ++++
.../ethernet/yunsilicon/xsc/common/xsc_reg.h | 23 +++
.../net/ethernet/yunsilicon/xsc/pci/Kconfig | 16 ++
.../net/ethernet/yunsilicon/xsc/pci/Makefile | 9 +
.../net/ethernet/yunsilicon/xsc/pci/main.c | 170 ++++++++++++++++++
10 files changed, 296 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_core.h
create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.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/main.c
diff --git a/MAINTAINERS b/MAINTAINERS
index c24144478..bc9e7d267 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30069,6 +30069,13 @@ S: Maintained
F: Documentation/input/devices/yealink.rst
F: drivers/input/misc/yealink.*
+YUNSILICON XSC DRIVERS
+M: Honggang Wei <weihg@yunsilicon.com>
+M: Xin Tian <tianx@yunsilicon.com>
+L: netdev@vger.kernel.org
+S: Maintained
+F: drivers/net/ethernet/yunsilicon/xsc
+
ZD1211RW WIRELESS DRIVER
L: linux-wireless@vger.kernel.org
S: Orphan
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
index 8581ccba1..88cdf87b0 100644
--- a/drivers/net/ethernet/Kconfig
+++ b/drivers/net/ethernet/Kconfig
@@ -189,6 +189,7 @@ source "drivers/net/ethernet/wangxun/Kconfig"
source "drivers/net/ethernet/wiznet/Kconfig"
source "drivers/net/ethernet/xilinx/Kconfig"
source "drivers/net/ethernet/xircom/Kconfig"
+source "drivers/net/ethernet/yunsilicon/Kconfig"
source "drivers/net/ethernet/zte/Kconfig"
endif # ETHERNET
diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile
index 2b1153d35..5b571d761 100644
--- a/drivers/net/ethernet/Makefile
+++ b/drivers/net/ethernet/Makefile
@@ -101,6 +101,7 @@ obj-$(CONFIG_NET_VENDOR_VIA) += via/
obj-$(CONFIG_NET_VENDOR_WANGXUN) += wangxun/
obj-$(CONFIG_NET_VENDOR_WIZNET) += wiznet/
obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/
+obj-$(CONFIG_NET_VENDOR_YUNSILICON) += yunsilicon/
obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/
obj-$(CONFIG_NET_VENDOR_SYNOPSYS) += synopsys/
obj-$(CONFIG_NET_VENDOR_PENSANDO) += pensando/
diff --git a/drivers/net/ethernet/yunsilicon/Kconfig b/drivers/net/ethernet/yunsilicon/Kconfig
new file mode 100644
index 000000000..ffdfdf4bf
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/Kconfig
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+# All rights reserved.
+#
+# Yunsilicon driver configuration
+#
+
+config NET_VENDOR_YUNSILICON
+ bool "Yunsilicon devices"
+ default y
+ depends on PCI
+ depends on 64BIT || COMPILE_TEST
+ help
+ If you have a network (Ethernet) device belonging to this class,
+ say Y.
+
+ Note that the answer to this question doesn't directly affect the
+ kernel: saying N will just cause the configurator to skip all
+ the questions about Yunsilicon cards. If you say Y, you will be asked
+ for your specific card in the following questions.
+
+if NET_VENDOR_YUNSILICON
+
+source "drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig"
+
+endif # NET_VENDOR_YUNSILICON
diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
new file mode 100644
index 000000000..b2924ccaf
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+# All rights reserved.
+#
+# Makefile for the Yunsilicon device drivers.
+#
+
+obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
new file mode 100644
index 000000000..2d0eda8a2
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef __XSC_CORE_H
+#define __XSC_CORE_H
+
+#include <linux/pci.h>
+#include <linux/bitfield.h>
+
+#define XSC_PCI_VENDOR_ID 0x1f67
+
+#define XSC_MC_PF_DEV_ID 0x1011
+
+#define XSC_MF_HOST_PF_DEV_ID 0x1051
+#define XSC_MF_SOC_PF_DEV_ID 0x1053
+
+#define XSC_MS_PF_DEV_ID 0x1111
+
+#define XSC_MV_HOST_PF_DEV_ID 0x1151
+#define XSC_MV_SOC_PF_DEV_ID 0x1153
+
+#define XSC_PAGE_SHIFT_4K 12
+#define XSC_PAGE_SIZE_4K (_AC(1, UL) << XSC_PAGE_SHIFT_4K)
+
+struct xsc_core_device {
+ struct pci_dev *pdev;
+ struct device *device;
+
+ void __iomem *bar;
+ int bar_num;
+};
+
+#endif
diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h
new file mode 100644
index 000000000..26773383f
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#ifndef __XSC_REG_H
+#define __XSC_REG_H
+#define CMDQM_HOST_REQ_BUF_BASE_H_ADDR_MEM_ADDR 0x0
+#define CMDQM_HOST_REQ_BUF_BASE_L_ADDR_MEM_ADDR 0x4
+#define CMDQM_HOST_REQ_PID_MEM_ADDR 0x8
+#define CMDQM_HOST_RSP_BUF_BASE_H_ADDR_MEM_ADDR 0x10
+#define CMDQM_HOST_RSP_BUF_BASE_L_ADDR_MEM_ADDR 0x14
+#define CMDQM_HOST_RSP_PID_MEM_ADDR 0x18
+#define CMDQM_HOST_RSP_CID_MEM_ADDR 0x1c
+#define CMDQM_HOST_VF_ERR_STS_MEM_ADDR 0x20
+
+#define DB_CQ_FUNC_MEM_ADDR 0x8c4
+#define DB_EQ_FUNC_MEM_ADDR 0x8c8
+#define DB_CQ_CID_DIRECT_MEM_ADDR 0x8cc
+#define TX_DB_FUNC_MEM_ADDR 0x8d0
+#define RX_DB_FUNC_MEM_ADDR 0x8d4
+
+#endif
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig b/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig
new file mode 100644
index 000000000..a27a37b3a
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+# All rights reserved.
+# Yunsilicon PCI configuration
+#
+
+config YUNSILICON_XSC_PCI
+ tristate "Yunsilicon XSC PCI driver"
+ depends on PCI
+ depends on NET
+ help
+ This driver provides the PCI core for Yunsilicon XSC
+ ethernet devices.
+
+ To compile this driver as a module, choose M here. The module
+ will be called xsc_pci.
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
new file mode 100644
index 000000000..c163aa950
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/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_PCI) += xsc_pci.o
+
+xsc_pci-y := main.o
diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
new file mode 100644
index 000000000..c926507a7
--- /dev/null
+++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
@@ -0,0 +1,170 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
+ * All rights reserved.
+ */
+
+#include <linux/slab.h>
+
+#include "common/xsc_core.h"
+
+static const struct pci_device_id xsc_pci_id_table[] = {
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MC_PF_DEV_ID) },
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MF_HOST_PF_DEV_ID) },
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MF_SOC_PF_DEV_ID) },
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MS_PF_DEV_ID) },
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MV_HOST_PF_DEV_ID) },
+ { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MV_SOC_PF_DEV_ID) },
+ { 0 }
+};
+
+static int xsc_set_dma_caps(struct pci_dev *pdev)
+{
+ int err;
+
+ err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+ if (!err)
+ dma_set_max_seg_size(&pdev->dev, SZ_2G);
+
+ return err;
+}
+
+static int xsc_pci_init(struct xsc_core_device *xdev,
+ const struct pci_device_id *id)
+{
+ struct pci_dev *pdev = xdev->pdev;
+ void __iomem *bar_base;
+ int bar_num = 0;
+ int err;
+
+ err = pci_enable_device(pdev);
+ if (err) {
+ pci_err(pdev, "failed to enable PCI device: err=%d\n", err);
+ goto err_out;
+ }
+
+ err = pci_request_region(pdev, bar_num, KBUILD_MODNAME);
+ if (err) {
+ pci_err(pdev, "failed to request %s pci_region=%d: err=%d\n",
+ KBUILD_MODNAME, bar_num, err);
+ goto err_disable;
+ }
+
+ pci_set_master(pdev);
+
+ err = xsc_set_dma_caps(pdev);
+ if (err) {
+ pci_err(pdev, "failed to set DMA capabilities mask: err=%d\n",
+ err);
+ goto err_clr_master;
+ }
+
+ bar_base = pci_ioremap_bar(pdev, bar_num);
+ if (!bar_base) {
+ pci_err(pdev, "failed to ioremap %s bar%d\n", KBUILD_MODNAME,
+ bar_num);
+ err = -ENOMEM;
+ goto err_clr_master;
+ }
+
+ err = pci_save_state(pdev);
+ if (err) {
+ pci_err(pdev, "pci_save_state failed: err=%d\n", err);
+ goto err_io_unmap;
+ }
+
+ xdev->bar_num = bar_num;
+ xdev->bar = bar_base;
+
+ return 0;
+
+err_io_unmap:
+ pci_iounmap(pdev, bar_base);
+err_clr_master:
+ pci_clear_master(pdev);
+ pci_release_region(pdev, bar_num);
+err_disable:
+ pci_disable_device(pdev);
+err_out:
+ return err;
+}
+
+static void xsc_pci_fini(struct xsc_core_device *xdev)
+{
+ struct pci_dev *pdev = xdev->pdev;
+
+ pci_iounmap(pdev, xdev->bar);
+ pci_clear_master(pdev);
+ pci_release_region(pdev, xdev->bar_num);
+ pci_disable_device(pdev);
+}
+
+static int xsc_pci_probe(struct pci_dev *pci_dev,
+ const struct pci_device_id *id)
+{
+ struct xsc_core_device *xdev;
+ int err;
+
+ xdev = kzalloc_obj(*xdev, GFP_KERNEL);
+ if (!xdev)
+ return -ENOMEM;
+
+ xdev->pdev = pci_dev;
+ xdev->device = &pci_dev->dev;
+
+ pci_set_drvdata(pci_dev, xdev);
+ err = xsc_pci_init(xdev, id);
+ if (err) {
+ pci_err(pci_dev, "xsc_pci_init failed %d\n", err);
+ goto err_unset_pci_drvdata;
+ }
+
+ return 0;
+
+err_unset_pci_drvdata:
+ pci_set_drvdata(pci_dev, NULL);
+ kfree(xdev);
+
+ return err;
+}
+
+static void xsc_pci_remove(struct pci_dev *pci_dev)
+{
+ struct xsc_core_device *xdev = pci_get_drvdata(pci_dev);
+
+ xsc_pci_fini(xdev);
+ pci_set_drvdata(pci_dev, NULL);
+ kfree(xdev);
+}
+
+static struct pci_driver xsc_pci_driver = {
+ .name = "xsc-pci",
+ .id_table = xsc_pci_id_table,
+ .probe = xsc_pci_probe,
+ .remove = xsc_pci_remove,
+};
+
+static int __init xsc_init(void)
+{
+ int err;
+
+ err = pci_register_driver(&xsc_pci_driver);
+ if (err) {
+ pr_err("failed to register pci driver\n");
+ return err;
+ }
+
+ return 0;
+}
+
+static void __exit xsc_fini(void)
+{
+ pci_unregister_driver(&xsc_pci_driver);
+}
+
+module_init(xsc_init);
+module_exit(xsc_fini);
+
+MODULE_DEVICE_TABLE(pci, xsc_pci_id_table);
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Yunsilicon XSC PCI driver");
--
2.43.0
Re: [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver
Author: netdev-bot+sashiko
Date: Fri, 27 Nov 2026 15:57
Date: Fri, 27 Nov 2026 15:57
197 lines
14131 bytes
14131 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
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] In xsc_pci_init(), BAR0 is mapped with pci_ioremap_bar(),
which is a plain ioremap() of pdev->resource[0], but it is unmapped…
- [Low] The subject line is cut short.
- [Low] The new MAINTAINERS entry 'YUNSILICON XSC DRIVERS' has only 'F:
drivers/net/ethernet/yunsilicon/xsc'.
- [Low] xsc_pci_driver.name is "xsc-pci".
--
net/xsc: add Yunsilicon XSC ethernet PCI driver
This commit adds the Yunsilicon vendor Kconfig/Makefile glue and a
skeleton PCI driver for XSC ethernet devices. The PCI core enables the
device, requests and maps BAR0, and sets the DMA masks. The doorbell,
command queue and netdev layers come in later patches.
> net/xsc: add Yunsilicon XSC ethernet PCI driver
>
> skeleton
[Severity: Low]
This isn't a bug, but the subject line seems to have been split. The word
"skeleton" is now the first line of the body.
As a result the shortlog reads "net/xsc: add Yunsilicon XSC ethernet PCI
driver". The commit only adds a PCI skeleton with no netdev. Could
"skeleton" go back into the subject line?
> diff --git a/MAINTAINERS b/MAINTAINERS
> index bde216003f428..1cd2a0a6477c7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -30909,6 +30909,13 @@ S: Maintained
> F: Documentation/input/devices/yealink.rst
> F: drivers/input/misc/yealink.*
>
> +YUNSILICON XSC DRIVERS
> +M: Honggang Wei <weihg@yunsilicon.com>
> +M: Xin Tian <tianx@yunsilicon.com>
> +L: netdev@vger.kernel.org
> +S: Maintained
> +F: drivers/net/ethernet/yunsilicon/xsc
[Severity: Low]
This isn't a bug, but should this F: entry be
drivers/net/ethernet/yunsilicon/ with a trailing slash?
As written it does not cover the vendor-level files this patch adds,
drivers/net/ethernet/yunsilicon/Kconfig and
drivers/net/ethernet/yunsilicon/Makefile. Changes to those files would not
be sent to the listed maintainers.
The new line in drivers/net/ethernet/Makefile is also out of order:
obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/
obj-$(CONFIG_NET_VENDOR_YUNSILICON) += yunsilicon/
obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/
In drivers/net/ethernet/Kconfig the matching source line comes after
xircom. Both issues are still present at the end of the series.
> +
> ZD1211RW WIRELESS DRIVER
> L: linux-wireless@vger.kernel.org
> S: Orphan
[ ... ]
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> new file mode 100644
> index 0000000000000..c926507a74b04
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
[ ... ]
> + bar_base = pci_ioremap_bar(pdev, bar_num);
> + if (!bar_base) {
> + pci_err(pdev, "failed to ioremap %s bar%d\n", KBUILD_MODNAME,
> + bar_num);
> + err = -ENOMEM;
> + goto err_clr_master;
> + }
> +
> + err = pci_save_state(pdev);
> + if (err) {
> + pci_err(pdev, "pci_save_state failed: err=%d\n", err);
> + goto err_io_unmap;
> + }
> +
> + xdev->bar_num = bar_num;
> + xdev->bar = bar_base;
> +
> + return 0;
> +
> +err_io_unmap:
> + pci_iounmap(pdev, bar_base);
[Severity: Medium]
Is pci_iounmap() the right call to undo pci_ioremap_bar()? It pairs with
pci_iomap(), while pci_ioremap_bar() is a plain ioremap(). xsc_pci_fini()
uses the same pairing on remove.
On s390 zPCI without MIO, the two calls are not symmetric.
zpci_map_resources() stores a cookie from pci_iomap_range_fh() in
resource[0].start, and that call takes the only reference.
pci_ioremap_bar() returns that cookie without taking a reference:
arch/s390/pci/pci.c:ioremap_prot() {
...
if (!static_branch_unlikely(&have_mio))
return (void __iomem *)phys_addr;
...
}
pci_iounmap() then calls pci_iounmap_fh(), which drops the reference that
zpci_map_resources() holds:
arch/s390/pci/pci.c:pci_iounmap_fh() {
...
WARN_ON(!zpci_iomap_start[idx].count);
if (!--zpci_iomap_start[idx].count) {
zpci_iomap_start[idx].fh = 0;
zpci_iomap_start[idx].bar = 0;
}
...
}
After one unbind, or one probe failure that reaches err_io_unmap, would
the next probe get a cookie whose fh is 0? Then every BAR0 readl()/writel()
would go to the wrong function handle.
When the device is finally removed, zpci_unmap_resources() calls
pci_iounmap_fh() again. That would trigger WARN_ON(!count) and underflow
the counter.
Later patches in the series add more ways to reach err_io_unmap, such as
xsc_cmd_init() failing.
Could this pair pci_ioremap_bar() with iounmap() instead? Another option is
to use pci_iomap()/pci_iounmap() or pcim_iomap_region().
> +err_clr_master:
> + pci_clear_master(pdev);
> + pci_release_region(pdev, bar_num);
> +err_disable:
> + pci_disable_device(pdev);
> +err_out:
> + return err;
> +}
> +
> +static void xsc_pci_fini(struct xsc_core_device *xdev)
> +{
> + struct pci_dev *pdev = xdev->pdev;
> +
> + pci_iounmap(pdev, xdev->bar);
> + pci_clear_master(pdev);
> + pci_release_region(pdev, xdev->bar_num);
> + pci_disable_device(pdev);
> +}
[ ... ]
> +static struct pci_driver xsc_pci_driver = {
> + .name = "xsc-pci",
[Severity: Low]
This isn't a bug, but the driver name here is "xsc-pci". The module is
called xsc_pci per the Kconfig help and the Makefile, and
pci_request_region() in xsc_pci_init() claims BAR0 under KBUILD_MODNAME
("xsc_pci").
So /sys/bus/pci/drivers/xsc-pci and the owner shown in /proc/iomem would
have different names. Later in the series xsc_core.h defines
XSC_PCI_DRV_NAME as "xsc_pci", but .name still uses the hyphenated string.
Would .name = KBUILD_MODNAME be more consistent?
> + .id_table = xsc_pci_id_table,
> + .probe = xsc_pci_probe,
> + .remove = xsc_pci_remove,
> +};
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
Re: [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver
Author: Andrew Lunn
Date: Sat, 28 Nov 2026 17:32
Date: Sat, 28 Nov 2026 17:32
22 lines
8728 bytes
8728 bytes
> +static int __init xsc_init(void)
> +{
> + int err;
> +
> + err = pci_register_driver(&xsc_pci_driver);
> + if (err) {
> + pr_err("failed to register pci driver\n");
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static void __exit xsc_fini(void)
> +{
> + pci_unregister_driver(&xsc_pci_driver);
> +}
module_pci_driver()
Andrew
Re: [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver
Author: Jason Xing
Date: Sun, 29 Nov 2026 02:53
Date: Sun, 29 Nov 2026 02:53
445 lines
26821 bytes
26821 bytes
On Thu, Nov 26, 2026 at 10:57 PM Xin Tian <tianx@yunsilicon.com> wrote:
>
> skeleton
nit: make it a complete sentence instead of a simple word
>
> Add the Yunsilicon vendor Kbuild glue and the PCI layer of the XSC
> ethernet driver. For now the PCI core only enables the device, maps
> BAR0 and records DMA capabilities; the doorbell, command queue and
> netdev layer are added by subsequent patches.
>
> Signed-off-by: Xin Tian <tianx@yunsilicon.com>
> ---
> MAINTAINERS | 7 +
> drivers/net/ethernet/Kconfig | 1 +
> drivers/net/ethernet/Makefile | 1 +
> drivers/net/ethernet/yunsilicon/Kconfig | 26 +++
> drivers/net/ethernet/yunsilicon/Makefile | 8 +
> .../ethernet/yunsilicon/xsc/common/xsc_core.h | 35 ++++
> .../ethernet/yunsilicon/xsc/common/xsc_reg.h | 23 +++
> .../net/ethernet/yunsilicon/xsc/pci/Kconfig | 16 ++
> .../net/ethernet/yunsilicon/xsc/pci/Makefile | 9 +
> .../net/ethernet/yunsilicon/xsc/pci/main.c | 170 ++++++++++++++++++
> 10 files changed, 296 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_core.h
> create mode 100644 drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.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/main.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index c24144478..bc9e7d267 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -30069,6 +30069,13 @@ S: Maintained
> F: Documentation/input/devices/yealink.rst
> F: drivers/input/misc/yealink.*
>
> +YUNSILICON XSC DRIVERS
> +M: Honggang Wei <weihg@yunsilicon.com>
> +M: Xin Tian <tianx@yunsilicon.com>
> +L: netdev@vger.kernel.org
> +S: Maintained
> +F: drivers/net/ethernet/yunsilicon/xsc
> +
> ZD1211RW WIRELESS DRIVER
> L: linux-wireless@vger.kernel.org
> S: Orphan
> diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
> index 8581ccba1..88cdf87b0 100644
> --- a/drivers/net/ethernet/Kconfig
> +++ b/drivers/net/ethernet/Kconfig
> @@ -189,6 +189,7 @@ source "drivers/net/ethernet/wangxun/Kconfig"
> source "drivers/net/ethernet/wiznet/Kconfig"
> source "drivers/net/ethernet/xilinx/Kconfig"
> source "drivers/net/ethernet/xircom/Kconfig"
> +source "drivers/net/ethernet/yunsilicon/Kconfig"
> source "drivers/net/ethernet/zte/Kconfig"
>
> endif # ETHERNET
> diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile
> index 2b1153d35..5b571d761 100644
> --- a/drivers/net/ethernet/Makefile
> +++ b/drivers/net/ethernet/Makefile
> @@ -101,6 +101,7 @@ obj-$(CONFIG_NET_VENDOR_VIA) += via/
> obj-$(CONFIG_NET_VENDOR_WANGXUN) += wangxun/
> obj-$(CONFIG_NET_VENDOR_WIZNET) += wiznet/
> obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/
> +obj-$(CONFIG_NET_VENDOR_YUNSILICON) += yunsilicon/
> obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/
> obj-$(CONFIG_NET_VENDOR_SYNOPSYS) += synopsys/
> obj-$(CONFIG_NET_VENDOR_PENSANDO) += pensando/
> diff --git a/drivers/net/ethernet/yunsilicon/Kconfig b/drivers/net/ethernet/yunsilicon/Kconfig
> new file mode 100644
> index 000000000..ffdfdf4bf
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/Kconfig
> @@ -0,0 +1,26 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> +# All rights reserved.
> +#
> +# Yunsilicon driver configuration
> +#
> +
> +config NET_VENDOR_YUNSILICON
> + bool "Yunsilicon devices"
> + default y
> + depends on PCI
> + depends on 64BIT || COMPILE_TEST
> + help
> + If you have a network (Ethernet) device belonging to this class,
> + say Y.
> +
> + Note that the answer to this question doesn't directly affect the
> + kernel: saying N will just cause the configurator to skip all
> + the questions about Yunsilicon cards. If you say Y, you will be asked
> + for your specific card in the following questions.
> +
> +if NET_VENDOR_YUNSILICON
> +
> +source "drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig"
> +
> +endif # NET_VENDOR_YUNSILICON
> diff --git a/drivers/net/ethernet/yunsilicon/Makefile b/drivers/net/ethernet/yunsilicon/Makefile
> new file mode 100644
> index 000000000..b2924ccaf
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/Makefile
> @@ -0,0 +1,8 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> +# All rights reserved.
> +#
> +# Makefile for the Yunsilicon device drivers.
> +#
> +
> +obj-$(CONFIG_YUNSILICON_XSC_PCI) += xsc/pci/
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
> new file mode 100644
> index 000000000..2d0eda8a2
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#ifndef __XSC_CORE_H
> +#define __XSC_CORE_H
> +
> +#include <linux/pci.h>
> +#include <linux/bitfield.h>
> +
> +#define XSC_PCI_VENDOR_ID 0x1f67
> +
> +#define XSC_MC_PF_DEV_ID 0x1011
> +
> +#define XSC_MF_HOST_PF_DEV_ID 0x1051
> +#define XSC_MF_SOC_PF_DEV_ID 0x1053
> +
> +#define XSC_MS_PF_DEV_ID 0x1111
> +
> +#define XSC_MV_HOST_PF_DEV_ID 0x1151
> +#define XSC_MV_SOC_PF_DEV_ID 0x1153
> +
> +#define XSC_PAGE_SHIFT_4K 12
> +#define XSC_PAGE_SIZE_4K (_AC(1, UL) << XSC_PAGE_SHIFT_4K)
> +
> +struct xsc_core_device {
> + struct pci_dev *pdev;
> + struct device *device;
> +
> + void __iomem *bar;
> + int bar_num;
> +};
> +
> +#endif
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h
> new file mode 100644
> index 000000000..26773383f
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/common/xsc_reg.h
> @@ -0,0 +1,23 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#ifndef __XSC_REG_H
> +#define __XSC_REG_H
> +#define CMDQM_HOST_REQ_BUF_BASE_H_ADDR_MEM_ADDR 0x0
> +#define CMDQM_HOST_REQ_BUF_BASE_L_ADDR_MEM_ADDR 0x4
> +#define CMDQM_HOST_REQ_PID_MEM_ADDR 0x8
> +#define CMDQM_HOST_RSP_BUF_BASE_H_ADDR_MEM_ADDR 0x10
> +#define CMDQM_HOST_RSP_BUF_BASE_L_ADDR_MEM_ADDR 0x14
> +#define CMDQM_HOST_RSP_PID_MEM_ADDR 0x18
> +#define CMDQM_HOST_RSP_CID_MEM_ADDR 0x1c
> +#define CMDQM_HOST_VF_ERR_STS_MEM_ADDR 0x20
> +
> +#define DB_CQ_FUNC_MEM_ADDR 0x8c4
> +#define DB_EQ_FUNC_MEM_ADDR 0x8c8
> +#define DB_CQ_CID_DIRECT_MEM_ADDR 0x8cc
> +#define TX_DB_FUNC_MEM_ADDR 0x8d0
> +#define RX_DB_FUNC_MEM_ADDR 0x8d4
> +
> +#endif
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig b/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig
> new file mode 100644
> index 000000000..a27a37b3a
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/Kconfig
> @@ -0,0 +1,16 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> +# All rights reserved.
> +# Yunsilicon PCI configuration
> +#
> +
> +config YUNSILICON_XSC_PCI
> + tristate "Yunsilicon XSC PCI driver"
> + depends on PCI
> + depends on NET
> + help
> + This driver provides the PCI core for Yunsilicon XSC
> + ethernet devices.
> +
> + To compile this driver as a module, choose M here. The module
> + will be called xsc_pci.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile b/drivers/net/ethernet/yunsilicon/xsc/pci/Makefile
> new file mode 100644
> index 000000000..c163aa950
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/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_PCI) += xsc_pci.o
> +
> +xsc_pci-y := main.o
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/main.c b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> new file mode 100644
> index 000000000..c926507a7
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/main.c
> @@ -0,0 +1,170 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd.
> + * All rights reserved.
> + */
> +
> +#include <linux/slab.h>
> +
> +#include "common/xsc_core.h"
> +
> +static const struct pci_device_id xsc_pci_id_table[] = {
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MC_PF_DEV_ID) },
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MF_HOST_PF_DEV_ID) },
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MF_SOC_PF_DEV_ID) },
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MS_PF_DEV_ID) },
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MV_HOST_PF_DEV_ID) },
> + { PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_MV_SOC_PF_DEV_ID) },
> + { 0 }
> +};
> +
> +static int xsc_set_dma_caps(struct pci_dev *pdev)
> +{
> + int err;
> +
> + err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> + if (!err)
> + dma_set_max_seg_size(&pdev->dev, SZ_2G);
> +
> + return err;
> +}
> +
> +static int xsc_pci_init(struct xsc_core_device *xdev,
> + const struct pci_device_id *id)
Dead @id parameter.
To check for unneeded parameters like this, you can use
-Wunused-parameter under W=2 to flag them.
> +{
> + struct pci_dev *pdev = xdev->pdev;
> + void __iomem *bar_base;
> + int bar_num = 0;
> + int err;
> +
> + err = pci_enable_device(pdev);
> + if (err) {
> + pci_err(pdev, "failed to enable PCI device: err=%d\n", err);
> + goto err_out;
> + }
> +
> + err = pci_request_region(pdev, bar_num, KBUILD_MODNAME);
> + if (err) {
> + pci_err(pdev, "failed to request %s pci_region=%d: err=%d\n",
> + KBUILD_MODNAME, bar_num, err);
> + goto err_disable;
> + }
> +
> + pci_set_master(pdev);
> +
> + err = xsc_set_dma_caps(pdev);
> + if (err) {
> + pci_err(pdev, "failed to set DMA capabilities mask: err=%d\n",
> + err);
> + goto err_clr_master;
> + }
> +
> + bar_base = pci_ioremap_bar(pdev, bar_num);
> + if (!bar_base) {
> + pci_err(pdev, "failed to ioremap %s bar%d\n", KBUILD_MODNAME,
> + bar_num);
> + err = -ENOMEM;
> + goto err_clr_master;
> + }
> +
> + err = pci_save_state(pdev);
> + if (err) {
> + pci_err(pdev, "pci_save_state failed: err=%d\n", err);
> + goto err_io_unmap;
> + }
> +
> + xdev->bar_num = bar_num;
> + xdev->bar = bar_base;
> +
> + return 0;
> +
> +err_io_unmap:
> + pci_iounmap(pdev, bar_base);
> +err_clr_master:
> + pci_clear_master(pdev);
IIUC, pci_clear_master is redundant since pci_disable_device gets
called soon. A similar patch can be seen in the commit 2f48b1d854e8
("pds_core: remove redundant pci_clear_master()").
> + pci_release_region(pdev, bar_num);
> +err_disable:
> + pci_disable_device(pdev);
> +err_out:
> + return err;
> +}
> +
> +static void xsc_pci_fini(struct xsc_core_device *xdev)
> +{
> + struct pci_dev *pdev = xdev->pdev;
> +
> + pci_iounmap(pdev, xdev->bar);
> + pci_clear_master(pdev);
Same here
> + pci_release_region(pdev, xdev->bar_num);
> + pci_disable_device(pdev);
> +}
> +
> +static int xsc_pci_probe(struct pci_dev *pci_dev,
> + const struct pci_device_id *id)
> +{
> + struct xsc_core_device *xdev;
> + int err;
> +
> + xdev = kzalloc_obj(*xdev, GFP_KERNEL);
> + if (!xdev)
> + return -ENOMEM;
> +
> + xdev->pdev = pci_dev;
> + xdev->device = &pci_dev->dev;
> +
> + pci_set_drvdata(pci_dev, xdev);
> + err = xsc_pci_init(xdev, id);
> + if (err) {
> + pci_err(pci_dev, "xsc_pci_init failed %d\n", err);
Error logs in xsc_pci_init are enough for users/admins to pinpoint
the issue. How about removing it?
Thanks,
Jason
> + goto err_unset_pci_drvdata;
> + }
> +
> + return 0;
> +
> +err_unset_pci_drvdata:
> + pci_set_drvdata(pci_dev, NULL);
> + kfree(xdev);
> +
> + return err;
> +}
> +
> +static void xsc_pci_remove(struct pci_dev *pci_dev)
> +{
> + struct xsc_core_device *xdev = pci_get_drvdata(pci_dev);
> +
> + xsc_pci_fini(xdev);
> + pci_set_drvdata(pci_dev, NULL);
> + kfree(xdev);
> +}
> +
> +static struct pci_driver xsc_pci_driver = {
> + .name = "xsc-pci",
> + .id_table = xsc_pci_id_table,
> + .probe = xsc_pci_probe,
> + .remove = xsc_pci_remove,
> +};
> +
> +static int __init xsc_init(void)
> +{
> + int err;
> +
> + err = pci_register_driver(&xsc_pci_driver);
> + if (err) {
> + pr_err("failed to register pci driver\n");
> + return err;
> + }
> +
> + return 0;
> +}
> +
> +static void __exit xsc_fini(void)
> +{
> + pci_unregister_driver(&xsc_pci_driver);
> +}
> +
> +module_init(xsc_init);
> +module_exit(xsc_fini);
> +
> +MODULE_DEVICE_TABLE(pci, xsc_pci_id_table);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Yunsilicon XSC PCI driver");
> --
> 2.43.0
Re: [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver
Author: "Xin Tian"
Date: Tue, 01 Dec 2026 09:48
Date: Tue, 01 Dec 2026 09:48
29 lines
9425 bytes
9425 bytes
On 11/29/2026 1:32 AM, Andrew Lunn wrote:
>> +static int __init xsc_init(void)
>> +{
>> + int err;
>> +
>> + err = pci_register_driver(&xsc_pci_driver);
>> + if (err) {
>> + pr_err("failed to register pci driver\n");
>> + return err;
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static void __exit xsc_fini(void)
>> +{
>> + pci_unregister_driver(&xsc_pci_driver);
>> +}
> module_pci_driver()
>
> Andrew
Will replace the hand-written init/exit with module_pci_driver().
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