Add ZTE DingHai Ethernet PF driver
Subsystems (3)
Junyang Han
maintainerv2 cover Add ZTE DingHai Ethernet PF driver
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 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 patch series is organized as follows:
- Patch 1: Add basic driver framework (Kconfig/Makefile, probe/remove skeleton)
- Patch 2: Add logging infrastructure using kernel standard dev_* macros
- Patch 3: Add hardware register access and PCI capability scanning
This is the initial submission and only includes the PF (Physical Function) driver. The VF (Virtual Function) driver will be submitted separately.
Junyang Han (3):
net/ethernet: add ZTE network driver support net/ethernet/zte/dinghai: add logging infrastructure net/ethernet/zte/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 | 10 + drivers/net/ethernet/zte/dinghai/dh_log.h | 60 ++ drivers/net/ethernet/zte/dinghai/dh_queue.h | 71 +++ drivers/net/ethernet/zte/dinghai/en_pf.c | 605 ++++++++++++++++++++ drivers/net/ethernet/zte/dinghai/en_pf.h | 100 ++++ 11 files changed, 914 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_log.h 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
Junyang Han
maintainerPATCH v2 1/3 net/ethernet: add ZTE network driver support
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 | 10 ++ drivers/net/ethernet/zte/dinghai/en_pf.c | 162 ++++++++++++++++++++++ drivers/net/ethernet/zte/dinghai/en_pf.h | 62 +++++++++ 9 files changed, 302 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
@@ -29210,6 +29210,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
@@ -190,5 +190,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
@@ -106,3 +106,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
@@ -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
@@ -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
@@ -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 NET_VENDOR_ZTE && 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 +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for ZTE DingHai Ethernet driver +# + +ccflags-y += -I$(src) + +obj-$(CONFIG_DINGHAI_PF) += dinghai10e.o +dinghai10e-y := en_pf.o +
drivers/net/ethernet/zte/dinghai/en_pf.c new file +162 -0
162 lines not on this page · raw message
drivers/net/ethernet/zte/dinghai/en_pf.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.27.0
Junyang Han
maintainerPATCH v2 2/3 net/ethernet/zte/dinghai: add logging infrastructure
In reply to Junyang HanIntroduce logging macros (DH_LOG_EMERG/ALERT/CRIT/ERR/WARN/INFO/DBG) and helper definitions for ZTE DingHai driver debugging.
--- drivers/net/ethernet/zte/dinghai/dh_log.h | 60 +++++++++++++++++++++++ drivers/net/ethernet/zte/dinghai/en_pf.c | 49 +++++++++++++++--- 2 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 drivers/net/ethernet/zte/dinghai/dh_log.h
drivers/net/ethernet/zte/dinghai/dh_log.h new file +60 -0
@@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* ZTE DingHai Ethernet driver - logging infrastructure +* Copyright (c) 2022-2026, ZTE Corporation. +*/ + +#ifndef __DH_LOG_H__ +#define __DH_LOG_H__ + +#include <linux/device.h> +#include <linux/kernel.h> +#include <linux/printk.h> + +#define MODULE_CMD "zxdh_cmd" +#define MODULE_NP "zxdh_np" +#define MODULE_PF "zxdh_pf" +#define MODULE_PTP "zxdh_ptp" +#define MODULE_TSN "zxdh_tsn" +#define MODULE_LAG "zxdh_lag" +#define MODULE_DHTOOLS "zxdh_tool" +#define MODULE_SEC "zxdh_sec" +#define MODULE_MPF "zxdh_mpf" +#define MODULE_FUC_HP "zxdh_func_hp" +#define MODULE_UACCE "zxdh_uacce" +#define MODULE_HEAL "zxdh_health" + +#define DH_LOG_EMERG(module, __dev, fmt, arg...) \ + dev_emerg((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_ALERT(module, __dev, fmt, arg...) \ + dev_alert((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_CRIT(module, __dev, fmt, arg...) \ + dev_crit((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_ERR(module, __dev, fmt, arg...) \ + dev_err((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_WARNING(module, __dev, fmt, arg...) \ + dev_warn((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_INFO(module, __dev, fmt, arg...) \ + dev_info((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define DH_LOG_DEBUG(module, __dev, fmt, arg...) \ + dev_dbg((__dev)->device, "[%s][%s][%d] " fmt, \ + module, __func__, __LINE__, ##arg) + +#define LOG_ERR(__dev, fmt, arg...) DH_LOG_ERR(MODULE_PF, __dev, fmt, ##arg) +#define LOG_INFO(__dev, fmt, arg...) DH_LOG_INFO(MODULE_PF, __dev, fmt, ##arg) +#define LOG_DEBUG(__dev, fmt, arg...) DH_LOG_DEBUG(MODULE_PF, __dev, fmt, ##arg) +#define LOG_WARN(__dev, fmt, arg...) DH_LOG_WARNING(MODULE_PF, __dev, fmt, ##arg) + +#endif /* __DH_LOG_H__ */
drivers/net/ethernet/zte/dinghai/en_pf.c +41 -8
137 lines not on this page · raw message
Signature · 1 line
2.27.0
Junyang Han
maintainerPATCH v2 3/3 net/ethernet/zte/dinghai: add hardware register access and PCI capability scanning
In reply to Junyang HanImplement 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 | 71 ++++ drivers/net/ethernet/zte/dinghai/en_pf.c | 410 ++++++++++++++++++++ drivers/net/ethernet/zte/dinghai/en_pf.h | 38 ++ 3 files changed, 519 insertions(+) create mode 100644 drivers/net/ethernet/zte/dinghai/dh_queue.h
drivers/net/ethernet/zte/dinghai/dh_queue.h new file +71 -0
@@ -0,0 +1,71 @@ +/* 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__ + +/* Vector value used to disable MSI for queue */ +#define ZXDH_MSI_NO_VECTOR 0xff + +/* Status byte for guest to report progress, and synchronize features */ +/* We have seen device and processed generic fields */ +#define ZXDH_CONFIG_S_ACKNOWLEDGE 1 +/* We have found a driver for the device. */ +#define ZXDH_CONFIG_S_DRIVER 2 +/* Driver has used its parts of the config, and is happy */ +#define ZXDH_CONFIG_S_DRIVER_OK 4 +/* Driver has finished configuring features */ +#define ZXDH_CONFIG_S_FEATURES_OK 8 +/* Device entered invalid state, driver must reset it */ +#define ZXDH_CONFIG_S_NEEDS_RESET 0x40 +/* We've given up on this device */ +#define ZXDH_CONFIG_S_FAILED 0x80 + +/* 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 +410 -0
422 lines not on this page · raw message
drivers/net/ethernet/zte/dinghai/en_pf.h +38 -0
@@ -15,6 +15,24 @@#define ZXDH_PF_DEVICE_ID 0x8040#define ZXDH_VF_DEVICE_ID 0x8041 +/* Common configuration */ +#define ZXDH_PCI_CAP_COMMON_CFG 1 +/* Notifications */ +#define ZXDH_PCI_CAP_NOTIFY_CFG 2 +/* ISR access */ +#define ZXDH_PCI_CAP_ISR_CFG 3 +/* Device specific configuration */ +#define ZXDH_PCI_CAP_DEVICE_CFG 4 +/* PCI configuration access */ +#define ZXDH_PCI_CAP_PCI_CFG 5 + +#define ZXDH_PF_MAX_BAR_VAL 0x5 +#define ZXDH_PF_ALIGN4 4 +#define ZXDH_PF_ALIGN2 2 +#define ZXDH_PF_MAP_MINLEN2 2 + +#define ZXDH_DEV_MAC_HIGH_OFFSET 4 +enum dh_coredev_type {DH_COREDEV_PF ,DH_COREDEV_VF ,
@@ -34,7 +52,27 @@ struct dh_core_dev { };struct zxdh_pf_device { +struct zxdh_pf_pci_common_cfg __iomem *common; +/* Device-specific data (non-legacy mode) */ +/* Base of vq notifications (non-legacy mode). */ +void __iomem *device; +void __iomem *notify_base; +void __iomem *pf_sriov_cap_base; +/* Physical base of vq notifications */ +resource_size_t notify_pa; +/* So we can sanity-check accesses. */ +size_t notify_len; +size_t device_len; +/* Capability for when we need to map notifications per-vq. */ +int32_t notify_map_cap; +uint32_t notify_offset_multiplier; +/* Multiply queue_notify_off by this value. (non-legacy mode). */ +int32_t modern_bars; +uint64_t pci_ioremap_addr[6 ]; +uint64_t sriov_bar_size; +uint32_t dev_cfg_bar_off; +bool packed_status;bool bar_chan_valid;bool vepa;struct mutex irq_lock;/* Protects IRQ operations */
Signature · 1 line
2.27.0
Quoted 3 lines · Junyang Han
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.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Please read sections 1.3 and 1.4, particularly the bit in red.
Andrew
---
pw-bot: cr
Re: [PATCH net-next v2 1/3] net/ethernet: add ZTE network driver support
In reply to Junyang HanQuoted 7 lines
(quoted diff) +4
-0+MODULE_AUTHOR("Junyang Han <[email protected]>"); +MODULE_DESCRIPTION("ZTE Corporation network adapters (DingHai series) Ethernet driver"); +err_pci_save_state: + pci_release_selected_regions(dev->pdev, pci_select_bars(dev->pdev,
IORESOURCE_MEM));
The email is still getting its white space changed. Please don't post any more versions until you have sent it to yourself and got it back again in a good state.
https://b4.docs.kernel.org/en/latest/contributor/send.html might help.
Andrew
Re: [PATCH net-next v2 3/3] net/ethernet/zte/dinghai: add hardware register access and PCI capability scanning
In reply to Junyang HanQuoted 5 lines · Junyang Han
Implement PCI configuration space access, BAR mapping, capability scanning (common/notify/device), and hardware queue register definitions for DingHai PF device.
Signed-off-by Junyang Han <[email protected]>
[...]
drivers/net/ethernet/zte/dinghai/en_pf.c void dh_pf_pci_close(struct dh_core_dev *dev) · line 134
Quoted 12 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +12
-0+ +void __iomem *zxdh_pf_map_capability (struct dh_core_dev *dh_dev,int32_t off, +size_t minlen,uint32_t align, +uint32_t start,uint32_t size, +size_t *len,resource_size_t *pa, +uint32_t *bar_off) +{ +struct pci_dev *pdev = dh_dev->pdev; +uint8_t bar =0 ; +uint32_t offset =0 ; +uint32_t length =0 ; +void __iomem *p =NULL ;
Even though the changelog says that variable declaration ordering is fixed, this patch (as some others in the series) still has the problem.
Also, please avoid using user-space fixed size types, kernel space uses short type names, like u32/u8 etc.
Try to avoid meaningless initialization as well.
These comments apply to the whole series, not only to this single patch
Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +8
-0+ +pci_read_config_byte (pdev, off + offsetof(struct zxdh_pf_pci_cap , bar), &bar); +pci_read_config_dword (pdev, off + offsetof(struct zxdh_pf_pci_cap , offset), &offset); +pci_read_config_dword (pdev, off + offsetof(struct zxdh_pf_pci_cap , length), &length); + +if (bar_off) + *bar_off = offset; +
[email protected]
maintainerHi Andrew,
Thanks for pointing me to the documentation. I understand now that net-next is currently closed and I should not have posted new feature patches during this period. I apologize for the oversight.
I noticed that RFC patches are welcome at any time. Would it be acceptable if I resubmit this series as RFC in the meantime, so that I can get early feedback and address any code issues before net-next reopens?
I will make sure to send the proper [PATCH net-next] version once the tree reopens.
Thank you for your patience and guidance.
Best regards,
Junyang Han
韩君阳 Hanjunyang
IT开发工程师 IT Development Engineer
ICF四部/无线及算力研究院/系统产品_无线及算力产品经营部 NIV Dept. IV/Wireless Product R&D Institute/Wireless Product Operation Division
南京市雨花台区宁丹路189号中兴三区A6栋2楼
No.6 HuaShen Road,Yuhuatai District,Nanjing P.R.China
M: +86-18651909520 E: [email protected] www.zte.com.cn
Original
From: AndrewLunn <[email protected]>
To: 韩君阳10295231;
Cc: [email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;冉明10033339;韩成飞10333708;张延泽10327417;
Date: 2026年04月23日 00:20
Subject: Re: [PATCH net-next v2 0/3] Add ZTE DingHai Ethernet PF driver
Quoted 3 lines · Junyang Han
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.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Please read sections 1.3 and 1.4, particularly the bit in red.
Andrew
---
pw-bot: cr
[email protected]
maintainerHi Andrew,
Thanks for pointing me to the documentation. I understand now that net-next is currently closed and I should not have posted new feature patches during this period. I apologize for the oversight.
I noticed that RFC patches are welcome at any time. Would it be acceptable if I resubmit this series as RFC in the meantime, so that I can get early feedback and address any code issues before net-next reopens?
I will make sure to send the proper [PATCH net-next] version once the tree reopens.
Thank you for your patience and guidance.
Best regards,
Junyang Han
韩君阳 Hanjunyang
IT开发工程师 IT Development Engineer
ICF四部/无线及算力研究院/系统产品_无线及算力产品经营部 NIV Dept. IV/Wireless Product R&D Institute/Wireless Product Operation Division
南京市雨花台区宁丹路189号中兴三区A6栋2楼
No.6 HuaShen Road,Yuhuatai District,Nanjing P.R.China
M: +86-18651909520 E: [email protected] www.zte.com.cn
Original
From: AndrewLunn <[email protected]>
To: 韩君阳10295231;
Cc: [email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;[email protected] <[email protected]>;冉明10033339;韩成飞10333708;张延泽10327417;
Date: 2026年04月23日 00:20
Subject: Re: [PATCH net-next v2 0/3] Add ZTE DingHai Ethernet PF driver
Quoted 3 lines · Junyang Han
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.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html
Please read sections 1.3 and 1.4, particularly the bit in red.
Andrew
---
pw-bot: cr