Skip to contentSkip to conversation

Add ZTE DingHai Ethernet PF driver

PATCH New [email protected] 2 participants 4 messages Aug 2 – Aug 6

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

v10 cover Add ZTE DingHai Ethernet PF driver

From: Junyang Han <[email protected]>

This series adds initial support for the ZTE DingHai Ethernet controller, a high-performance PCIe Ethernet device supporting SR-IOV, hardware offloading, and advanced virtualization features.

Changes from v9:
- Makefile: remove unnecessary ccflags-y -I$(src).
- zxdh_pf_pci_init(): dma_set_mask_and_coherent() never fails for DMA_BIT_MASK(64).Just call it once.
- zxdh_pf_probe(): reorder local variable declarations in reverse xmas tree order.Don't print dev_err on devlink_alloc() failure.
- Remove redundant initialization of fields in kzalloc'ed structs (bar_chan_valid, vepa).
- en_pf.h: drop unused includes,forward declaration of struct devlink, unused enum zxdh_coredev_type, and unused struct fields (bar_chan_valid, vepa, irq_lock, lock mutex, coredev_type).
- Reply to Sashiko's review comments:
(1) zxdh_pf_map_capability(): validate the BAR index against ZXDH_PF_MAX_BAR_VAL right after re-reading it from config space.
(2) zxdh_pf_map_capability(): bound-check length + offset (instead of minlen + offset) against the BAR size before mapping, so the reported *len never exceeds the actually mapped region and later MMIO accesses cannot run past the pci_iomap_range() boundary.
(3) Search capabilities with IORESOURCE_MEM only (common/notify/device cfg), matching the pci_request_selected_regions(IORESOURCE_MEM) call, so a capability located in an I/O BAR is never mapped without having been requested.
(4) zxdh_pf_notify_cfg_init(): rewrite
"if (notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE)" as a
subtraction: notify_length <= PAGE_SIZE - (notify_offset % PAGE_SIZE). This removes the addition, so there is no integer wrap a malicious length could exploit to bypass the check.

Changes from v8:
- Unify the three prefix variants (dh_core* / dh_pf* / zxdh_pf*) on the vendor namespace zxdh_* .
- Address the _dev / _device suffix inconsistency: zxdh_pf_device -> zxdh_pf_dev, matching zxdh_core_dev and the upstream pci_dev / net_dev / usb_dev convention.
- Keep struct zxdh_core_dev and struct zxdh_pf_dev split, with zxdh_pf_dev hung off zxdh_core_dev::priv via the container-of pattern. The same zxdh_core_dev handle will be shared by the SF (Sub-Function) driver queued for the next merge window, and by MPF drivers further out. Each device type hangs its own private struct off priv: PF -> zxdh_pf_dev, SF -> zxdh_sf_dev (planned). Merging now would force a re-split when SF lands.
- Address v8 review comment "introduce functions yet you never use them".
- Wire up zxdh_pf_modern_cfg_init() into the probe path and zxdh_pf_modern_cfg_uninit() into the remove path.
- Drop the ZXDH_CONFIG_S_* and ZXDH_MSI_NO_VECTOR macros from dh_queue.h.

Changes from v7:
- Remove the redundant depends on NET_VENDOR_ZTE since it's already implied by the enclosing if NET_VENDOR_ZTE block in the parent Kconfig.
- Check BAR 0 is an IORESOURCE_MEM resource before ioremap().
- Rework .shutdown to quiesce hardware only.
- Add NULL guards in zxdh_set_mac() and zxdh_get_mac().
- Zero the output buffer in zxdh_pf_get_vf_mac() up front.

- Two further AI-review points were investigated and require no code change:

(1) *len is written before the bounds check inside zxdh_pf_map_capability. The two fields written through *len and *bar_off are pf_dev->notify_len and pf_dev->dev_cfg_bar_off, both populated from this function. pf_dev->notify_len is only consulted when pf_dev->notify_base != NULL, which only happens when the corresponding map_capability() call returned a non-NULL pointer; pf_dev->dev_cfg_bar_off is only consumed by zxdh_pf_get_vf_mac and zxdh_pf_set_vf_mac_reg, both of which gate their access on pf_dev->pf_sriov_cap_base. So the early *len / *bar_off writes cannot produce values that end up consumed.

(2) The expression off * notify_offset_multiplier is u16 * u32; the overflow only triggers when notify_offset_multiplier exceeds UINT_MAX / 65535 (≈ 65537), which is well beyond any value a PCI config register would carry for this field. A malformed multiplier of that magnitude would also fail sane probing of the rest of the cap layout, so it cannot reach this arithmetic. The boundaries in practice are enforced by the 64-bit comparison at the top of zxdh_pf_map_vq_notify's notify_base branch, where off is promoted to u64 before the multiply. The three subsequent 32-bit multiplies in that function only feed pointer arithmetic against pf_dev->notify_base; a wrong offset would resolve to an address outside the mapped region and fail on access rather than corrupt kernel state.

Changes from v6:
- Clean up PCI device ID table (drop , 0, use { } sentinel)
- Move dh_core_alloc_priv/dh_core_free_priv from header to .c, they don't need to be static inline
- Use if (!x) and drop the "%i, x" dev_err() messages in common/notify cfg init.

Changes from v5:
- Drop dev_info() log spam.
- Propagate the real error code from dh_pf_pci_init() in dh_pf_probe() instead of hard-coding -ENOMEM.
- Register devlink only after dh_pf_pci_init() succeeds, and in dh_pf_remove()/dh_pf_shutdown() unregister devlink before tearing down PCI/mutex/priv.
- Drop the "dh_dev->priv = NULL" assignment from dh_core_free_priv().

Changes from v4:
- Fix sparse warning: add __iomem annotation to priv pointer
- Fix Clang format warning
- Use "dinghai:" as patch subject prefix
- Ensure proper patch threading

Note: Sent manually due to temporary git send-email unavailability in our environment. Will use git send-email or b4 for future submissions. Apologies for any inconvenience.

Changes from v3:
- Merged patches 1 and 2:
Combined initial framework with logging infrastructure
for better code organization and reduced patch count. This was done because the logging infrastructure now uses Linux's built-in dev_err(), dev_info(), dev_warn(), etc. macros instead of a custom logging system.
- Removed unnecessary variable initialization:
Fixed "don't initialise variables".
- Fixed variable declaration order:
Applied "Reverse Christmas tree" ordering with variables declared from longest to shortest line length.
- Code quality improvements:
Fixed all checkpatch.pl issues (alignment, formatting, etc.).

Changes from v2:
- Address maintainer feedback from v2 review:
* Remove meaningless initialization
* Change dh_pf_pci_table to static const for better encapsulation
* Simplify MODULE_DESCRIPTION for brevity
- Coding style improvements:
* Ensure all lines are within 80-column limit
* Use kernel types (u32/u8) consistently throughout
* Improve code readability with better formatting

Changes from v1 (addressing feedback from AndrewLunn):
- Update copyright years to 2022-2026
- Remove DRV_VERSION, MODULE_VERSION and related boilerplate
- Fix MODULE_AUTHOR to use person with email address
- Use module_pci_driver() instead of manual init/exit
- Remove empty suspend/resume callbacks
- Replace char priv[] flexible array with void *priv + kzalloc
- Switch logging from printk wrappers to dev_*() based macros
- Remove dh_helper.h and dh_log.c, simplify to dh_log.h only
- Fix variable declaration ordering (reverse Christmas tree)
- Remove unnecessary NULL check in remove and pf_dev=NULL in probe
- Fix indentation and remove unnecessary type casts
- Use kernel idiomatic "if (ret)" style

This is the initial submission and only includes the PF (Physical Function) driver. The VF (Virtual Function) driver will be submitted separately.

Junyang Han (2):
dinghai: add ZTE network driver support
dinghai: add hardware register access and PCI capability scanning

 MAINTAINERS                                 |   6 +
 drivers/net/ethernet/Kconfig                |   1 +
 drivers/net/ethernet/Makefile               |   1 +
 drivers/net/ethernet/zte/Kconfig            |  20 +
 drivers/net/ethernet/zte/Makefile           |   6 +
 drivers/net/ethernet/zte/dinghai/Kconfig    |  34 ++
 drivers/net/ethernet/zte/dinghai/Makefile   |   7 +
 drivers/net/ethernet/zte/dinghai/dh_queue.h |  56 +++
 drivers/net/ethernet/zte/dinghai/en_pf.c    | 449 ++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.h    |  75 ++++
 10 files changed, 655 insertions(+)
 create mode 100644 drivers/net/ethernet/zte/Kconfig
 create mode 100644 drivers/net/ethernet/zte/Makefile
 create mode 100644 drivers/net/ethernet/zte/dinghai/Kconfig
 create mode 100644 drivers/net/ethernet/zte/dinghai/Makefile
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_queue.h
 create mode 100644 drivers/net/ethernet/zte/dinghai/en_pf.c
 create mode 100644 drivers/net/ethernet/zte/dinghai/en_pf.h
Signature · 1 line
2.27.0
author maintainer
#1 lore raw

PATCH v10 1/2 dinghai: add ZTE network driver support

From: Junyang Han <[email protected]>

Add basic framework for ZTE DingHai ethernet PF driver, including Kconfig/Makefile build support and PCIe device probe/remove skeleton.

---
 MAINTAINERS                               |   6 +
 drivers/net/ethernet/Kconfig              |   1 +
 drivers/net/ethernet/Makefile             |   1 +
 drivers/net/ethernet/zte/Kconfig          |  20 +++
 drivers/net/ethernet/zte/Makefile         |   6 +
 drivers/net/ethernet/zte/dinghai/Kconfig  |  34 +++++
 drivers/net/ethernet/zte/dinghai/Makefile |   7 +
 drivers/net/ethernet/zte/dinghai/en_pf.c  | 174 ++++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.h  |  29 ++++
 9 files changed, 278 insertions(+)
 create mode 100644 drivers/net/ethernet/zte/Kconfig
 create mode 100644 drivers/net/ethernet/zte/Makefile
 create mode 100644 drivers/net/ethernet/zte/dinghai/Kconfig
 create mode 100644 drivers/net/ethernet/zte/dinghai/Makefile
 create mode 100644 drivers/net/ethernet/zte/dinghai/en_pf.c
 create mode 100644 drivers/net/ethernet/zte/dinghai/en_pf.h
MAINTAINERS +6 -0
index 2fb1c75afd16..73692b09bf7b 100644
@@ -29440,6 +29440,12 @@ S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
 F:	sound/hda/codecs/senarytech.c
 
+ZTE DINGHAI ETHERNET DRIVER
+M:	Junyang Han <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/zte/
+
 THE REST
 M:	Linus Torvalds <[email protected]>
 L:	[email protected]
drivers/net/ethernet/Kconfig +1 -0
index b8f70e2a1763..c2b6996b0cfe 100644
@@ -188,5 +188,6 @@ 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/zte/Kconfig"
 
 endif # ETHERNET
drivers/net/ethernet/Makefile +1 -0
index 57344fec6ce0..a34bcbd4df4e 100644
@@ -104,3 +104,4 @@ obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/
 obj-$(CONFIG_NET_VENDOR_SYNOPSYS) += synopsys/
 obj-$(CONFIG_NET_VENDOR_PENSANDO) += pensando/
 obj-$(CONFIG_OA_TC6) += oa_tc6.o
+obj-$(CONFIG_NET_VENDOR_ZTE) += zte/
drivers/net/ethernet/zte/Kconfig new file +20 -0
new file mode 100644
index 000000000000..b95c2fc7db77
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# ZTE driver configuration
+#
+
+config NET_VENDOR_ZTE
+    bool "ZTE devices"
+    default y
+    help
+      If you have a network (Ethernet) card 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 Zte cards. If you say Y, you will be asked
+      for your specific card in the following questions.
+
+if NET_VENDOR_ZTE
+
+source "drivers/net/ethernet/zte/dinghai/Kconfig"
+
+endif # NET_VENDOR_ZTE
drivers/net/ethernet/zte/Makefile new file +6 -0
new file mode 100644
index 000000000000..cd9929b61559
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for the ZTE device drivers
+#
+
+obj-$(CONFIG_DINGHAI) += dinghai/
drivers/net/ethernet/zte/dinghai/Kconfig new file +34 -0
new file mode 100644
index 000000000000..121be3bf7707
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# ZTE DingHai Ethernet driver configuration
+#
+
+config DINGHAI
+    bool "ZTE DingHai Ethernet driver"
+    depends on PCI
+    select NET_DEVLINK
+    help
+      This driver supports ZTE DingHai Ethernet devices.
+
+      DingHai is a high-performance Ethernet controller that supports
+      multiple features including hardware offloading, SR-IOV, and
+      advanced virtualization capabilities.
+
+      If you say Y here, you can select specific driver variants below.
+
+      If unsure, say N.
+
+if DINGHAI
+
+config DINGHAI_PF
+    tristate "ZTE DingHai PF (Physical Function) driver"
+    help
+      This driver supports ZTE DingHai PCI Express Ethernet
+      adapters (PF).
+
+      To compile this driver as a module, choose M here. The module
+      will be named dinghai10e.
+
+      If unsure, say N.
+
+endif # DINGHAI
drivers/net/ethernet/zte/dinghai/Makefile new file +7 -0
new file mode 100644
index 000000000000..e2f4da33df59
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for ZTE DingHai Ethernet driver
+#
+
+obj-$(CONFIG_DINGHAI_PF) += dinghai10e.o
+dinghai10e-y := en_pf.o
drivers/net/ethernet/zte/dinghai/en_pf.c new file +174 -0

174 lines not on this page · raw message

drivers/net/ethernet/zte/dinghai/en_pf.h new file +29 -0
new file mode 100644
index 000000000000..f6b9dc94a57d
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ZTE DingHai Ethernet driver - PF header
+ * Copyright (c) 2022-2026, ZTE Corporation.
+ */
+
+#ifndef __ZXDH_EN_PF_H__
+#define __ZXDH_EN_PF_H__
+
+#define ZXDH_PF_VENDOR_ID	0x1cf2
+#define ZXDH_PF_DEVICE_ID	0x8040
+#define ZXDH_VF_DEVICE_ID	0x8041
+
+struct zxdh_core_dev {
+	struct device *device;
+	struct pci_dev *pdev;
+	struct devlink *devlink;
+	void *priv;
+};
+
+struct zxdh_pf_dev {
+	void __iomem *pci_ioremap_addr[6];
+};
+
+void *zxdh_core_alloc_priv(struct zxdh_core_dev *zxdh_dev, size_t size);
+void zxdh_core_free_priv(struct zxdh_core_dev *zxdh_dev);
+void zxdh_pf_pci_close(struct zxdh_core_dev *zxdh_dev);
+
+#endif /* __ZXDH_EN_PF_H__ */
Signature · 1 line
2.27.0
author maintainer
#2 lore raw

PATCH v10 2/2 dinghai: add hardware register access and PCI capability scanning

In reply to [email protected]

From: Junyang Han <[email protected]>

Implement PCI configuration space access, BAR mapping, capability scanning (common/notify/device), and hardware queue register definitions for DingHai PF device.

---
 drivers/net/ethernet/zte/dinghai/dh_queue.h |  56 ++++
 drivers/net/ethernet/zte/dinghai/en_pf.c    | 275 ++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.h    |  46 ++++
 3 files changed, 377 insertions(+)
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_queue.h
drivers/net/ethernet/zte/dinghai/dh_queue.h new file +56 -0
new file mode 100644
index 000000000000..5b63895c1ea1
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ZTE DingHai Ethernet driver - PCI capability definitions
+ * Copyright (c) 2022-2026, ZTE Corporation.
+ */
+
+#ifndef __DH_QUEUE_H__
+#define __DH_QUEUE_H__
+
+#include <linux/types.h>
+
+/* This is the PCI capability header: */
+struct zxdh_pf_pci_cap {
+	__u8 cap_vndr;		/* Generic PCI field: PCI_CAP_ID_VNDR */
+	__u8 cap_next;		/* Generic PCI field: next ptr. */
+	__u8 cap_len;		/* Generic PCI field: capability length */
+	__u8 cfg_type;		/* Identifies the structure. */
+	__u8 bar;		/* Where to find it. */
+	__u8 id;		/* Multiple capabilities of the same type */
+	__u8 padding[2];		/* Pad to full dword. */
+	__le32 offset;		/* Offset within bar. */
+	__le32 length;		/* Length of the structure, in bytes. */
+};
+
+/* Fields in ZXDH_PF_PCI_CAP_COMMON_CFG: */
+struct zxdh_pf_pci_common_cfg {
+	/* About the whole device. */
+	__le32 device_feature_select; /* read-write */
+	__le32 device_feature;	/* read-only */
+	__le32 guest_feature_select; /* read-write */
+	__le32 guest_feature;		/* read-write */
+	__le16 msix_config;		/* read-write */
+	__le16 num_queues;		/* read-only */
+	__u8 device_status;		/* read-write */
+	__u8 config_generation;	/* read-only */
+
+	/* About a specific virtqueue. */
+	__le16 queue_select;		/* read-write */
+	__le16 queue_size;		/* read-write, power of 2. */
+	__le16 queue_msix_vector;	/* read-write */
+	__le16 queue_enable;		/* read-write */
+	__le16 queue_notify_off;	/* read-only */
+	__le32 queue_desc_lo;		/* read-write */
+	__le32 queue_desc_hi;		/* read-write */
+	__le32 queue_avail_lo;		/* read-write */
+	__le32 queue_avail_hi;		/* read-write */
+	__le32 queue_used_lo;		/* read-write */
+	__le32 queue_used_hi;		/* read-write */
+};
+
+struct zxdh_pf_pci_notify_cap {
+	struct zxdh_pf_pci_cap cap;
+	__le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */
+};
+
+#endif /* __DH_QUEUE_H__ */
drivers/net/ethernet/zte/dinghai/en_pf.c +275 -0

303 lines not on this page · raw message

drivers/net/ethernet/zte/dinghai/en_pf.h +46 -0

67 lines not on this page · raw message

Signature · 1 line
2.27.0
#3 lore raw
In reply to [email protected]
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 34 lines · On Sun, 2 Aug 2026 16:00:48 +0800 (CST) you wrote:

From: Junyang Han <[email protected]>

This series adds initial support for the ZTE DingHai Ethernet controller, a high-performance PCIe Ethernet device supporting SR-IOV, hardware offloading, and advanced virtualization features.

Changes from v9:
- Makefile: remove unnecessary ccflags-y -I$(src).
- zxdh_pf_pci_init(): dma_set_mask_and_coherent() never fails for DMA_BIT_MASK(64).Just call it once.
- zxdh_pf_probe(): reorder local variable declarations in reverse xmas tree order.Don't print dev_err on devlink_alloc() failure.
- Remove redundant initialization of fields in kzalloc'ed structs (bar_chan_valid, vepa).
- en_pf.h: drop unused includes,forward declaration of struct devlink, unused enum zxdh_coredev_type, and unused struct fields (bar_chan_valid, vepa, irq_lock, lock mutex, coredev_type).
- Reply to Sashiko's review comments:
(1) zxdh_pf_map_capability(): validate the BAR index against ZXDH_PF_MAX_BAR_VAL right after re-reading it from config space.
(2) zxdh_pf_map_capability(): bound-check length + offset (instead of minlen + offset) against the BAR size before mapping, so the reported *len never exceeds the actually mapped region and later MMIO accesses cannot run past the pci_iomap_range() boundary.
(3) Search capabilities with IORESOURCE_MEM only (common/notify/device cfg), matching the pci_request_selected_regions(IORESOURCE_MEM) call, so a capability located in an I/O BAR is never mapped without having been requested.
(4) zxdh_pf_notify_cfg_init(): rewrite
"if (notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE)" as a
subtraction: notify_length <= PAGE_SIZE - (notify_offset % PAGE_SIZE). This removes the addition, so there is no integer wrap a malicious length could exploit to bypass the check.

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v10,1/2] dinghai: add ZTE network driver support

    https://git.kernel.org/netdev/net-next/c/b8180f7977aa

- [net-next,v10,2/2] dinghai: add hardware register access and PCI capability scanning (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html