Skip to contentSkip to conversation

net/ethernet: add ZTE network driver support

PATCH Superseded Junyang Han 2 participants 8 messages Apr 15 – Apr 22

Subsystems (3)

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Junyang Han

author maintainer
#0 lore raw

PATCH 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  | 191 ++++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.h  |  51 ++++++
 9 files changed, 320 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 65902b97f5df..92ddac4bb310 100644
@@ -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
index bdc29d143160..ecc6fbb01510 100644
@@ -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
index 6bffb60ba644..7476af77d6c8 100644
@@ -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
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..94b5bd9b3c50
@@ -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
new file mode 100644
index 000000000000..f55a8de518be
@@ -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 +191 -0

191 lines not on this page · raw message

drivers/net/ethernet/zte/dinghai/en_pf.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#1 lore raw

PATCH 2/3 net/ethernet/zte/dinghai: add logging infrastructure

Introduce logging macros (DH_LOG_EMERG/ALERT/CRIT/ERR/WARN/INFO/DBG) and helper definitions for ZTE DingHai driver debugging.

---
 drivers/net/ethernet/zte/dinghai/Makefile    |  2 +-
 drivers/net/ethernet/zte/dinghai/dh_helper.h | 79 ++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/dh_log.c    | 10 +++
 drivers/net/ethernet/zte/dinghai/dh_log.h    | 64 ++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.c     | 49 ++++++++++--
 5 files changed, 196 insertions(+), 8 deletions(-)
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_helper.h
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_log.c
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_log.h
drivers/net/ethernet/zte/dinghai/Makefile +1 -1
index f55a8de518be..c2a815427c24 100644
@@ -6,5 +6,5 @@
 ccflags-y += -I$(src)
 
 obj-$(CONFIG_DINGHAI_PF) += dinghai10e.o
-dinghai10e-y := en_pf.o
+dinghai10e-y := en_pf.o dh_log.o
 
drivers/net/ethernet/zte/dinghai/dh_helper.h new file +79 -0

79 lines not on this page · raw message

drivers/net/ethernet/zte/dinghai/dh_log.c new file +10 -0
new file mode 100644
index 000000000000..5e6e42175e37
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ZTE DingHai Ethernet driver - logging runtime control
+ * Copyright (c) 2022-2024, ZTE Corporation.
+ */
+
+#include <linux/module.h>
+
+int debug_print;
+module_param(debug_print, int, 0644);
drivers/net/ethernet/zte/dinghai/dh_log.h new file +64 -0

64 lines not on this page · raw message

drivers/net/ethernet/zte/dinghai/en_pf.c +42 -7

132 lines not on this page · raw message

Signature · 1 line
2.43.0
author maintainer
#3 lore raw

PATCH 3/3 net/ethernet/zte/dinghai: add hardware register access and PCI capability scanning

In reply to Junyang Han

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 |  71 ++++
 drivers/net/ethernet/zte/dinghai/en_pf.c    | 411 ++++++++++++++++++++
 drivers/net/ethernet/zte/dinghai/en_pf.h    |  41 ++
 3 files changed, 523 insertions(+)
 create mode 100644 drivers/net/ethernet/zte/dinghai/dh_queue.h
drivers/net/ethernet/zte/dinghai/dh_queue.h new file +71 -0
new file mode 100644
index 000000000000..1e7d64ecbbf3
@@ -0,0 +1,71 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ZTE DingHai Ethernet driver - PCI capability definitions
+ * Copyright (c) 2022-2024, 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 +411 -0

417 lines not on this page · raw message

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

58 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw
In reply to Junyang Han
Quoted 2 lines · Junyang Han

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

Please take a read on

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

and

https://docs.kernel.org/process/submitting-patches.html

Please always include a patch 0/X in a patch set, explaining the big picture.

Thanks for keeping the driver small and easy to review.

Quoted 2 lines

+ * ZTE DingHai Ethernet driver
+ * Copyright (c) 2022-2024, ZTE Corporation.

And the last two years?

Quoted 1 line

+#define DRV_VERSION "1.0-1"

Driver versions are generally useless. What does this actually mean for the given very limited driver? Are you going to change the version with each patchset?

drivers/net/ethernet/zte/dinghai/en_pf.c

Quoted 6 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +5 -0
+#define DRV_SUMMARY "ZTE(R) zxdh-net driver"
+
+const char zxdh_pf_driver_version[] = DRV_VERSION;
+static const char zxdh_pf_driver_string[] = DRV_SUMMARY;
+static const char zxdh_pf_copyright[] = "Copyright (c)
 2022-2024, ZTE Corporation.";

You don't need this, you have the copyright above.

Quoted 1 line

+MODULE_AUTHOR("ZTE");

Author is a person, with an email address.

Quoted 1 line

+MODULE_DESCRIPTION(DRV_SUMMARY);

Please just put the string here, not #define.

drivers/net/ethernet/zte/dinghai/en_pf.c line 37

Quoted 6 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +6 -0
+MODULE_VERSION(DRV_VERSION);
+MODULE_LICENSE("GPL");
+static int dh_pf_pci_init(struct dh_core_dev *dev)
+{
+    int ret = 0;
+    struct zxdh_pf_device *pf_dev = NULL;

Reverse Christmas tree. This applies everywhere for a netdev driver.

drivers/net/ethernet/zte/dinghai/en_pf.c line 126

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +7 -0
+static int dh_pf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
 
+err_cfg_init:
+    mutex_destroy(&pf_dev->irq_lock);
+    mutex_destroy(&dh_dev->lock);
+    devlink_free(devlink);
+    pf_dev = NULL;

Since this is a probe function, do you really need to set pf_dev to NULL? How is it going to keep a value over EPROBE_DEFER cycles?

drivers/net/ethernet/zte/dinghai/en_pf.c line 137

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +8 -0
+static void dh_pf_remove(struct pci_dev *pdev)
+{
+    struct dh_core_dev *dh_dev = pci_get_drvdata(pdev);
+    struct devlink *devlink = priv_to_devlink(dh_dev);
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+
+    if (!dh_dev)
+        return;

How does that happen?

Quoted 6 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +6 -0
+    dh_pf_pci_close(dh_dev);
+    mutex_destroy(&pf_dev->irq_lock);
+    mutex_destroy(&dh_dev->lock);
+    devlink_free(devlink);
+    pci_set_drvdata(pdev, NULL);
+}

drivers/net/ethernet/zte/dinghai/en_pf.c line 168

Quoted 10 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +9 -0
 
+static int dh_pf_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+    return 0;
+}
+
+static int dh_pf_resume(struct pci_dev *pdev)
+{
+    return 0;
+}

If they do nothing, don't provide them. You can add them when you add suspend/resume support.

drivers/net/ethernet/zte/dinghai/en_pf.c line 191

Quoted 12 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +12 -0
+static int __init dh_pf_pci_init_module(void)
+{
+    return pci_register_driver(&dh_pf_driver);
+}
+
+static void __exit dh_pf_pci_exit_module(void)
+{
+    pci_unregister_driver(&dh_pf_driver);
+}
+
+module_init(dh_pf_pci_init_module);
+module_exit(dh_pf_pci_exit_module);

The PCI subsystem offers a wrapper to do this.

drivers/net/ethernet/zte/dinghai/en_pf.h line 33

Quoted 7 lines
drivers/net/ethernet/zte/dinghai/en_pf.h new file +7 -0
+struct dh_core_dev {
+    struct device *device;
+    enum dh_coredev_type coredev_type;
+    struct pci_dev *pdev;
+    struct devlink *devlink;
+    struct mutex lock; /* Protects device configuration */
+    char priv[] __aligned(32);

That is unusual. priv is usually a void * and allocated. If you want an actual array, you might want to have a second member indicate the size of the array, look at all the work done recently on flexible arrays.

Andrew

---
pw-bot: cr

#2 lore raw

Re: [PATCH net-next 2/3] net/ethernet/zte/dinghai: add logging infrastructure

In reply to Junyang Han

drivers/net/ethernet/zte/dinghai/dh_helper.h line 26

Quoted 10 lines
drivers/net/ethernet/zte/dinghai/dh_helper.h new file +10 -0
+#define dh_dbg(__dev, format, ...)                    \
+    dev_dbg((__dev)->device, "%s:%d:(pid %d): " format,        \
+         __func__, __LINE__, current->pid,            \
+         ##__VA_ARGS__)
+
+#define dh_dbg_once(__dev, format, ...)                \
+    dev_dbg_once((__dev)->device,                \
+             "%s:%d:(pid %d): " format,            \
+             __func__, __LINE__, current->pid,        \
+             ##__VA_ARGS__)

There is a dislike for adding wrappers around the existing kernel log functions. What value does this add?

drivers/net/ethernet/zte/dinghai/dh_log.c line 10

Quoted 2 lines
drivers/net/ethernet/zte/dinghai/dh_log.c new file +2 -0
+int debug_print;
+module_param(debug_print, int, 0644);

Module parameters are not liked.

drivers/net/ethernet/zte/dinghai/en_pf.c MODULE_DESCRIPTION(DRV_SUMMARY); · line 30

Quoted 6 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +5 -0
+module_param_named(debug_mask, dh_debug_mask, uint, 0644);
+MODULE_PARM_DESC(debug_mask, "debug mask: 1 = dump cmd data, 2 =
 dump cmd exec time, 3 = both. Default=0");
+static bool probe_vf = 1;
+module_param(probe_vf, bool, 0644);
+MODULE_PARM_DESC(probe_vf, "probe_vf: 0 = N, 1 = Y");

I suggest you remove all these.

Debug code is reasonable to have during development. But once the driver actually works, it should not be needed.

drivers/net/ethernet/zte/dinghai/en_pf.c static int dh_pf_pci_init(struct dh_core_dev *dev) · line 51

Quoted 8 lines

const struct pci_device_id dh_pf_pci_table[] = {

drivers/net/ethernet/zte/dinghai/en_pf.c +2 -1
@@ -39,26 +47,34 @@ static int dh_pf_pci_init(struct dh_core_dev *dev)
     pci_set_drvdata(dev->pdev, dev);
 
     ret = pci_enable_device(dev->pdev);
-    if (ret)
+    if (ret) {
+        LOG_ERR("pci_enable_device failed: %d\n", ret);

dev_err(dev, ..)

drivers/net/ethernet/zte/dinghai/en_pf.c static int dh_pf_pci_init(struct dh_core_dev *dev) · line 59

Quoted 9 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +3 -1
         return -ENOMEM;
+    }
 
     ret = dma_set_mask_and_coherent(dev->device, DMA_BIT_MASK(64));
     if (ret) {
         ret = dma_set_mask_and_coherent(dev->device, DMA_BIT_MASK(32));
-        if (ret)
+        if (ret) {
+            LOG_ERR("dma_set_mask_and_coherent failed: %d\n", ret);

dev_err(dev, ...

And maybe it should actually be dev_err_probe() if this is a probe function, and you need to handle -EPROBE_DEFER.

Debug logging should be limited to actual debug stuff. Please use the standard logging primitives for anything which is not debug, so dev_err(), dev_warn(), dev_info(). netdev_err(), netdev_warn() etc.

Andrew

#4 lore raw

Re: [PATCH net-next 3/3] net/ethernet/zte/dinghai: add hardware register access and PCI capability scanning

In reply to Junyang Han
Quoted 10 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +10 -0
+int32_t zxdh_pf_pci_find_capability(struct pci_dev *pdev, uint8_t cfg_type,
+                    uint32_t ioresource_types, int32_t *bars)
+{
+    int32_t pos = 0;
+    uint8_t type = 0;
+    uint8_t bar = 0;
+
+    for (pos = pci_find_capability(pdev, PCI_CAP_ID_VNDR); pos > 0;
+         pos = pci_find_next_capability(pdev, pos, PCI_CAP_ID_VNDR)) {
+        pci_read_config_byte(pdev, pos + offsetof
Quoted 3 lines

(struct zxdh_pf_pci_cap, cfg_type), &type);
+ pci_read_config_byte(pdev, pos + offsetof
(struct zxdh_pf_pci_cap, bar), &bar);

Something odd going on with indentation? Has the mailer corrupted it?

Quoted 14 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +14 -0
+
+        /* ignore structures with reserved BAR values */
+        if (bar > ZXDH_PF_MAX_BAR_VAL)
+            continue;
+
+        if (type == cfg_type) {
+            if (pci_resource_len(pdev, bar) &&
+                pci_resource_flags(pdev, bar) & ioresource_types) {
+                *bars |= (1 << bar);
+                return pos;
+            }
+        }
+    }
+

drivers/net/ethernet/zte/dinghai/en_pf.c void dh_pf_pci_close(struct dh_core_dev *dev) · line 192

Quoted 10 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +10 -0
+    return 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)
+    p = pci_iomap_range(pdev, bar, offset, length);
+    if (unlikely(!p)) {

Is this hot path? Please only use unlikely() when dealing with frames in the hot path.

Quoted 25 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +12 -0
+int32_t zxdh_pf_common_cfg_init(struct dh_core_dev *dh_dev)
+{
+    int32_t common = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+    struct pci_dev *pdev = dh_dev->pdev;
+
+    /* check for a common config: if not, use legacy mode (bar 0). */
+    common = zxdh_pf_pci_find_capability(pdev, ZXDH_PCI_CAP_COMMON_CFG,
+                         IORESOURCE_IO | IORESOURCE_MEM,
+                         &pf_dev->modern_bars);
+    if (common == 0) {
+        LOG_ERR("missing capabilities %i, leaving for legacy driver\

n", common);

drivers/net/ethernet/zte/dinghai/en_pf.c +12 -0
+        return -ENODEV;
+    }
+
+    pf_dev->common = zxdh_pf_map_capability(dh_dev, common,
+                        sizeof(struct zxdh_pf_pci_common_cfg),
+                        ZXDH_PF_ALIGN4, 0,
+                        sizeof(struct zxdh_pf_pci_common_cfg),
+                        NULL, NULL, NULL);
+    if (unlikely(!pf_dev->common)) {
+        LOG_ERR("pf_dev->common is null\n");
+        return -EINVAL;
+    }

drivers/net/ethernet/zte/dinghai/en_pf.c void dh_pf_pci_close(struct dh_core_dev *dev) · line 256

Quoted 10 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +9 -0
+
+    return 0;
+}
 
+int32_t zxdh_pf_notify_cfg_init(struct dh_core_dev *dh_dev)
+{
+    /* We don't know how many VQs we'll map, ahead of the time.
+     * If notify length is small, map it all now. Otherwise, map each VQ individually later.
+     */
+    if ((uint64_t)notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) {

Please try to avoid casts. They suggest the types are wrong. You will probably have better code if you don't need the cast.

drivers/net/ethernet/zte/dinghai/en_pf.c void dh_pf_pci_close(struct dh_core_dev *dev) · line 318

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +8 -0
+int32_t zxdh_pf_modern_cfg_init(struct dh_core_dev *dh_dev)
+{
+    int32_t ret = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+    struct pci_dev *pdev = dh_dev->pdev;
+
+    ret = zxdh_pf_common_cfg_init(dh_dev);
+    if (ret != 0) {

if (ret)

would be more normal.

drivers/net/ethernet/zte/dinghai/en_pf.c void dh_pf_pci_close(struct dh_core_dev *dev) · line 429

Quoted 11 lines

+void zxdh_pf_get_vf_mac
(struct dh_core_dev *dh_dev, uint8_t *mac, int32_t vf_id)

drivers/net/ethernet/zte/dinghai/en_pf.c +9 -0
+{
+    uint32_t DEV_MAC_L = 0;
+    uint16_t DEV_MAC_H = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+
+    if (pf_dev->pf_sriov_cap_base) {
+        DEV_MAC_L = ioread32((void __iomem *)(pf_dev->pf_sriov_cap_base +
+                     (pf_dev->sriov_bar_size) * vf_id +
+                     pf_dev->dev_cfg_bar_off));

Is the cast needed? pf_dev->pf_sriov_cap_base should already be void * __iomem.

Andrew

author maintainer
#7 lore raw
In reply to Junyang Han

Hi Andrew,

Thank you for your detailed review. Please see my responses below.

Quoted 2 lines

Please always include a patch 0/X in a patch set, explaining the big picture.

Cover letter (patch 0/X) has been added in v2 explaining the big picture.

Quoted 4 lines

+ * ZTE DingHai Ethernet driver
+ * Copyright (c) 2022-2024, ZTE Corporation.

And the last two years?

Copyright year updated to 2022-2026.

Quoted 5 lines

+#define DRV_VERSION "1.0-1"

Driver versions are generally useless. What does this actually mean for the given very limited driver? Are you going to change the version with each patchset?

Removed. Driver version is not needed for upstream submission.

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +5 -0
+#define DRV_SUMMARY "ZTE(R) zxdh-net driver"
+
+const char zxdh_pf_driver_version[] = DRV_VERSION;
+static const char zxdh_pf_driver_string[] = DRV_SUMMARY;
+static const char zxdh_pf_copyright[] = "Copyright (c)
 2022-2024, ZTE Corporation.";

You don't need this, you have the copyright above.

Removed all these. The copyright in the file header is sufficient.

Quoted 3 lines

+MODULE_AUTHOR("ZTE");

Author is a person, with an email address.

Fixed. Now using:
MODULE_AUTHOR("Junyang Han <[email protected]>");

Quoted 3 lines

+MODULE_DESCRIPTION(DRV_SUMMARY);

Please just put the string here, not #define.

Fixed. Now using:
MODULE_DESCRIPTION("ZTE Corporation network adapters (DingHai series) Ethernet driver");

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +6 -0
+MODULE_VERSION(DRV_VERSION);
+MODULE_LICENSE("GPL");
+static int dh_pf_pci_init(struct dh_core_dev *dev)
+{
+    int ret = 0;
+    struct zxdh_pf_device *pf_dev = NULL;

Reverse Christmas tree. This applies everywhere for a netdev driver.

Fixed. Function variable declarations now follow reverse Christmas tree.

Quoted 11 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +7 -0
+static int dh_pf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
 
+err_cfg_init:
+    mutex_destroy(&pf_dev->irq_lock);
+    mutex_destroy(&dh_dev->lock);
+    devlink_free(devlink);
+    pf_dev = NULL;

Since this is a probe function, do you really need to set pf_dev to NULL? How is it going to keep a value over EPROBE_DEFER cycles?

Removed. pf_dev doesn't need to be set to NULL.

Quoted 10 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +8 -0
+static void dh_pf_remove(struct pci_dev *pdev)
+{
+    struct dh_core_dev *dh_dev = pci_get_drvdata(pdev);
+    struct devlink *devlink = priv_to_devlink(dh_dev);
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+
+    if (!dh_dev)
+        return;

How does that happen?

Removed the NULL check.

Quoted 17 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +15 -0
+    dh_pf_pci_close(dh_dev);
+    mutex_destroy(&pf_dev->irq_lock);
+    mutex_destroy(&dh_dev->lock);
+    devlink_free(devlink);
+    pci_set_drvdata(pdev, NULL);
+}
 
+static int dh_pf_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+    return 0;
+}
+
+static int dh_pf_resume(struct pci_dev *pdev)
+{
+    return 0;
+}
Quoted 2 lines

If they do nothing, don't provide them. You can add them when you add suspend/resume support.

Removed. Suspend/resume will be added when needed.

Quoted 13 lines
drivers/net/ethernet/zte/dinghai/en_pf.c new file +12 -0
+static int __init dh_pf_pci_init_module(void)
+{
+    return pci_register_driver(&dh_pf_driver);
+}
+
+static void __exit dh_pf_pci_exit_module(void)
+{
+    pci_unregister_driver(&dh_pf_driver);
+}
+
+module_init(dh_pf_pci_init_module);
+module_exit(dh_pf_pci_exit_module);
Quoted 1 line

The PCI subsystem offers a wrapper to do this.

Fixed. Now using module_pci_driver(dh_pf_driver).

Quoted 8 lines
drivers/net/ethernet/zte/dinghai/en_pf.h new file +7 -0
+struct dh_core_dev {
+    struct device *device;
+    enum dh_coredev_type coredev_type;
+    struct pci_dev *pdev;
+    struct devlink *devlink;
+    struct mutex lock; /* Protects device configuration */
+    char priv[] __aligned(32);
Quoted 4 lines

That is unusual. priv is usually a void * and allocated. If you want an actual array, you might want to have a second member indicate the size of the array, look at all the work done recently on flexible arrays.

Fixed. Changed to void *priv, allocated dynamically with kzalloc().

Best regards,
Junyang Han

author maintainer
#5 lore raw

Re: [PATCH net-next 3/3] net/ethernet/zte/dinghai: add hardware register access and PCI capability scanning

In reply to Junyang Han

Hi Andrew,

Thank you for reviewing patch 3/3. Please see my responses below.

Quoted 14 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +10 -0
+int32_t zxdh_pf_pci_find_capability(struct pci_dev *pdev, uint8_t cfg_type,
+                    uint32_t ioresource_types, int32_t *bars)
+{
+    int32_t pos = 0;
+    uint8_t type = 0;
+    uint8_t bar = 0;
+
+    for (pos = pci_find_capability(pdev, PCI_CAP_ID_VNDR); pos > 0;
+         pos = pci_find_next_capability(pdev, pos, PCI_CAP_ID_VNDR)) {
+        pci_read_config_byte(pdev, pos + offsetof

(struct zxdh_pf_pci_cap, cfg_type), &type);
+ pci_read_config_byte(pdev, pos + offsetof
(struct zxdh_pf_pci_cap, bar), &bar);

Quoted 1 line

Something odd going on with indentation? Has the mailer corrupted it?

The indentation in the original patch was correct (4-space). The mailer appears to have corrupted the formatting in the display. Code is properly indented in the actual patch.

Quoted 25 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +24 -0
+
+        /* ignore structures with reserved BAR values */
+        if (bar > ZXDH_PF_MAX_BAR_VAL)
+            continue;
+
+        if (type == cfg_type) {
+            if (pci_resource_len(pdev, bar) &&
+                pci_resource_flags(pdev, bar) & ioresource_types) {
+                *bars |= (1 << bar);
+                return pos;
+            }
+        }
+    }
+
+    return 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)
+    p = pci_iomap_range(pdev, bar, offset, length);
+    if (unlikely(!p)) {
Quoted 2 lines

Is this hot path? Please only use unlikely() when dealing with frames in the hot path.

Removed unlikely(). It's not in a hot path.

Quoted 36 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +12 -0
+int32_t zxdh_pf_common_cfg_init(struct dh_core_dev *dh_dev)
+{
+    int32_t common = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+    struct pci_dev *pdev = dh_dev->pdev;
+
+    /* check for a common config: if not, use legacy mode (bar 0). */
+    common = zxdh_pf_pci_find_capability(pdev, ZXDH_PCI_CAP_COMMON_CFG,
+                         IORESOURCE_IO | IORESOURCE_MEM,
+                         &pf_dev->modern_bars);
+    if (common == 0) {
+        LOG_ERR("missing capabilities %i, leaving for legacy driver\

n", common);

drivers/net/ethernet/zte/dinghai/en_pf.c +21 -0
+        return -ENODEV;
+    }
+
+    pf_dev->common = zxdh_pf_map_capability(dh_dev, common,
+                        sizeof(struct zxdh_pf_pci_common_cfg),
+                        ZXDH_PF_ALIGN4, 0,
+                        sizeof(struct zxdh_pf_pci_common_cfg),
+                        NULL, NULL, NULL);
+    if (unlikely(!pf_dev->common)) {
+        LOG_ERR("pf_dev->common is null\n");
+        return -EINVAL;
+    }
+
+    return 0;
+}
 
+int32_t zxdh_pf_notify_cfg_init(struct dh_core_dev *dh_dev)
+{
+    /* We don't know how many VQs we'll map, ahead of the time.
+     * If notify length is small, map it all now. Otherwise, map each VQ individually later.
+     */
+    if ((uint64_t)notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE) {
Quoted 2 lines

Please try to avoid casts. They suggest the types are wrong. You will probably have better code if you don't need the cast.

Fixed. Changed notify_length and notify_offset to size_t type. The cast is no longer needed:
if (notify_length + (notify_offset % PAGE_SIZE) <= PAGE_SIZE)

Quoted 9 lines
drivers/net/ethernet/zte/dinghai/en_pf.c +8 -0
+int32_t zxdh_pf_modern_cfg_init(struct dh_core_dev *dh_dev)
+{
+    int32_t ret = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+    struct pci_dev *pdev = dh_dev->pdev;
+
+    ret = zxdh_pf_common_cfg_init(dh_dev);
+    if (ret != 0) {
Quoted 3 lines

if (ret)

would be more normal.

Fixed. Changed to "if (ret)".

Quoted 12 lines

+void zxdh_pf_get_vf_mac
(struct dh_core_dev *dh_dev, uint8_t *mac, int32_t vf_id)

drivers/net/ethernet/zte/dinghai/en_pf.c +9 -0
+{
+    uint32_t DEV_MAC_L = 0;
+    uint16_t DEV_MAC_H = 0;
+    struct zxdh_pf_device *pf_dev = dh_core_priv(dh_dev);
+
+    if (pf_dev->pf_sriov_cap_base) {
+        DEV_MAC_L = ioread32((void __iomem *)(pf_dev->pf_sriov_cap_base +
+                     (pf_dev->sriov_bar_size) * vf_id +
+                     pf_dev->dev_cfg_bar_off));
Quoted 2 lines

Is the cast needed? pf_dev->pf_sriov_cap_base should already be void * __iomem.

Fixed. Removed the cast. pf_sriov_cap_base is already void __iomem *.

Best regards,
Junyang Han