Skip to contentSkip to conversation

eea: Add basic driver framework for Alibaba Elastic Ethernet Adaptor

PATCH Applied Xuan Zhuo 3 participants 25 messages May 14 – May 19

Subsystems (3)
lore
Share & tools
lore

Xuan Zhuo

author maintainer
#0 lore raw

v43 cover eea: Add basic driver framework for Alibaba Elastic Ethernet Adaptor

Add a driver framework for EEA that will be available in the future.

This driver is currently quite minimal, implementing only fundamental core functionalities. Key features include: I/O queue management via adminq, basic PCI-layer operations, and essential RX/TX data communication capabilities. It also supports the creation, initialization, and management of network devices (netdev). Furthermore, the ring structures for both I/O queues and adminq have been abstracted into a simple, unified, and reusable library implementation, facilitating future extension and maintenance.

v43:
1. fix the comments from sashiko

v42:
1. fix the comments from Jakub
2. fix the comments from sashiko

v41:
1. make https://sashiko.dev/ happy

v40:
1. fix comments from https://sashiko.dev/

v39:
1. fix comments from https://sashiko.dev/#/patchset/20260407122001.22265-1-xuanzhuo%40linux.alibaba.com

v38:
1. fix comments from https://sashiko.dev/#/patchset/20260404135144.33166-1-xuanzhuo%40linux.alibaba.com

v36:
1. fix comments from https://sashiko.dev/#/patchset/20260323074441.91691-1-xuanzhuo%40linux.alibaba.com

v35:
1. fix comments from https://netdev-ai.bots.linux.dev/ai-review.html?id=24371ffc-a1ea-46e1-a6b3-b8cbcbb52efb

v34:
1. fix the comments from https://sashiko.dev/#/patchset/20260317015257.79494-1-xuanzhuo%40linux.alibaba.com

v33:
1. fix the comments. old version refers enet_bind_new_q_and_cfg, but that is changed to eea_bind_q_and_cfg.

v32:
1. remove unused parameters from eea_net_ha_reset_remove and eea_create_pp
2. call skb_mark_for_recycle for new skb for frag_list skbs

v31:
1. remove unused parameter "enet" from eex_rx_post()

v30:
1. fix some small problems

v29:
Address AI-generated review suggestions from the previous version.

v28:
Address AI-generated review suggestions from the previous version.

v27:
Address AI-generated review suggestions from the previous version.

v26:
Adopting suggestions from the previous AI review, another significant change is the introduction of an IRQ block to implement IRQ proxying. With this design, when an IRQ occurs, we no longer invoke the RX data structure directly -- instead, the IRQ block serves as an intermediary proxy. This approach offers several advantages: IRQ resources no longer need to be reallocated during reset operations, and IRQs are decoupled from RX structures. Consequently, when certain errors occur, we can fall back and safely reuse the original memory resources.

v25:
I have adopted most of the suggestions from the AI's feedback. However, I believe some of the feedback is incorrect. I have already replied in the previous thread. http://lore.kernel.org/all/[email protected]

v24:
1. Add null checks for enet->rx and enet->tx in eea_get_ethtool_stat to prevent errors when reading rx = enet->rx[i] in case enet->rx is null. tx is similar. With rtnl protection in place, this check is sufficient.
2. Use 'received' as the return value in eea_poll.

v23:
I have moved netif_set_real_num_queues() out of eea_start_rxtx(), so eea_start_rxtx() is now a void function. I believe enet_bind_new_q_and_cfg() is a more suitable place to include netif_set_real_num_queues(). In eea_active_ring_and_irq(), I first execute request_irq() before interacting with the hardware to create queues. Therefore, during the NIC setup process, all driver-internal operations (memory allocation, IRQ initialization, sysfs configuration, etc.) will be completed before the final notification to the hardware.

v22:
1. Use the budget from the NAPI poll function as the parameter for napi_consume_skb.
2. Stop the TX queue when the remaining ring slots cannot hold an SKB.

v21:
Fix two issues from the previous version:
1, a DMA unmap operation was missing.
2, RCU APIs were not used in eea_stats. Although the standard practice when
using RCU would require adding the __rcu annotation to both the rx and tx fields, in many cases these fields are read without needing RCU protection. Therefore, I do not want to add the __rcu annotation. Instead, I use a spin lock to protect modifications to rx and tx.

v20:
Fix the partially initialized structure passed to db. @Jakub
http://lore.kernel.org/all/[email protected]

v19:
fix the comments from @Simon Horman

v18:
v17 with [PATCH] prefix.

v17:
1. In eea_adminq_dev_status, uniformly use enet->cfg.rx_ring_num.
2. Add a struct eea_net_cfg *cfg parameter to eea_free_rx and eea_free_tx. When called in the normal path, pass enet->cfg as the argument; when called during initialization, pass the temporary cfg instead.
3. Move the .ndo_get_stats64 callback into eea_net.c.
4. In the .ndo_get_stats64 callback, add a comment explaining how the TX and RX statistics are protected by RCU.

/* This function is protected by RCU. Here uses enet->tx and enet->rx
* to check whether the TX and RX structures are safe to access. In
* eea_free_rxtx_q_mem, before freeing the TX and RX resources, enet->rx
* and enet->tx are set to NULL, and synchronize_net is called. */

v16:
1. follow the advices from @ALOK TIWARI
http://lore.kernel.org/all/[email protected]

v15:
1. remove 'default m' from eea kconfig
2. free the resources when open failed.

v14:
1. some tiny fixes

v13:
1. fix some tiny fixes @Simon

v12:
I encountered some issues with sending the v11 patches, as they were quite messy. Therefore, I'm resending them as v12.

v11:
1. remove auto clean __free(kfree)
2. some tiny fixes

v10:
1. name the jump labels after the target @Jakub
2. rm __GFP_ZERO from dma_alloc_coherent @Jakub
v9:
1. some fixes for ethtool from http://lore.kernel.org/all/[email protected]

v8: 1. rename eea_net_tmp to eea_net_init_ctx
2. rm code that allocs memory to destroy queues
3. some other minor changes

v7: 1. remove the irrelative code from ethtool commit
2. build every commits with W12

v6: Split the big one commit to five commits
v5: Thanks for the comments from Kalesh Anakkur Purayil, ALOK TIWARI
v4: Thanks for the comments from Troy Mitchell, Przemek Kitszel, Andrew Lunn, Kalesh Anakkur Purayil
v3: Thanks for the comments from Paolo Abenchi
v2: Thanks for the comments from Simon Horman and Andrew Lunn
v1: Thanks for the comments from Simon Horman and Andrew Lunn

Xuan Zhuo (8):
eea: introduce PCI framework
eea: introduce ring and descriptor structures
eea: probe the netdevice and create adminq
eea: create/destroy rx,tx queues for netdevice open and stop
eea: implement packet receive logic
eea: implement packet transmit logic
eea: introduce ethtool support
eea: introduce callback for ndo_get_stats64 and register netdev

 MAINTAINERS                                   |   8 +
 drivers/net/ethernet/Kconfig                  |   1 +
 drivers/net/ethernet/Makefile                 |   1 +
 drivers/net/ethernet/alibaba/Kconfig          |  28 +
 drivers/net/ethernet/alibaba/Makefile         |   5 +
 drivers/net/ethernet/alibaba/eea/Makefile     |   9 +
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 542 +++++++++++
 drivers/net/ethernet/alibaba/eea/eea_adminq.h |  83 ++
 drivers/net/ethernet/alibaba/eea/eea_desc.h   | 138 +++
 .../net/ethernet/alibaba/eea/eea_ethtool.c    | 273 ++++++
 .../net/ethernet/alibaba/eea/eea_ethtool.h    |  48 +
 drivers/net/ethernet/alibaba/eea/eea_net.c    | 887 ++++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_net.h    | 198 ++++
 drivers/net/ethernet/alibaba/eea/eea_pci.c    | 744 +++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_pci.h    |  73 ++
 drivers/net/ethernet/alibaba/eea/eea_ring.c   | 249 +++++
 drivers/net/ethernet/alibaba/eea/eea_ring.h   |  99 ++
 drivers/net/ethernet/alibaba/eea/eea_rx.c     | 814 ++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_tx.c     | 500 ++++++++++
 19 files changed, 4700 insertions(+)
 create mode 100644 drivers/net/ethernet/alibaba/Kconfig
 create mode 100644 drivers/net/ethernet/alibaba/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_desc.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_rx.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_tx.c

--
2.32.0.3.g01195cf9f

author maintainer
#1 lore raw

PATCH v43 1/8 eea: introduce PCI framework

Add basic driver framework for the Alibaba Elastic Ethernet Adapter(EEA).

This commit implements the EEA PCI probe functionality.

---
 MAINTAINERS                                |   8 +
 drivers/net/ethernet/Kconfig               |   1 +
 drivers/net/ethernet/Makefile              |   1 +
 drivers/net/ethernet/alibaba/Kconfig       |  28 ++
 drivers/net/ethernet/alibaba/Makefile      |   5 +
 drivers/net/ethernet/alibaba/eea/Makefile  |   3 +
 drivers/net/ethernet/alibaba/eea/eea_pci.c | 487 +++++++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_pci.h |  50 +++
 8 files changed, 583 insertions(+)
 create mode 100644 drivers/net/ethernet/alibaba/Kconfig
 create mode 100644 drivers/net/ethernet/alibaba/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.h
MAINTAINERS +8 -0
index 5bbbbde6b907..829015eaa3ce 100644
@@ -802,6 +802,14 @@ S:	Maintained
 F:	Documentation/i2c/busses/i2c-ali1563.rst
 F:	drivers/i2c/busses/i2c-ali1563.c
 
+ALIBABA ELASTIC ETHERNET ADAPTER DRIVER
+M:	Xuan Zhuo <[email protected]>
+M:	Wen Gu <[email protected]>
+R:	Philo Lu <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/net/ethernet/alibaba/eea
+
 ALIBABA ELASTIC RDMA DRIVER
 M:	Cheng Xu <[email protected]>
 M:	Kai Shen <[email protected]>
drivers/net/ethernet/Kconfig +1 -0
index b8f70e2a1763..78c79ad7bba5 100644
@@ -22,6 +22,7 @@ source "drivers/net/ethernet/aeroflex/Kconfig"
 source "drivers/net/ethernet/agere/Kconfig"
 source "drivers/net/ethernet/airoha/Kconfig"
 source "drivers/net/ethernet/alacritech/Kconfig"
+source "drivers/net/ethernet/alibaba/Kconfig"
 source "drivers/net/ethernet/allwinner/Kconfig"
 source "drivers/net/ethernet/altera/Kconfig"
 source "drivers/net/ethernet/amazon/Kconfig"
drivers/net/ethernet/Makefile +1 -0
index 57344fec6ce0..bba55d9af387 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_NET_VENDOR_ADI) += adi/
 obj-$(CONFIG_NET_VENDOR_AGERE) += agere/
 obj-$(CONFIG_NET_VENDOR_AIROHA) += airoha/
 obj-$(CONFIG_NET_VENDOR_ALACRITECH) += alacritech/
+obj-$(CONFIG_NET_VENDOR_ALIBABA) += alibaba/
 obj-$(CONFIG_NET_VENDOR_ALLWINNER) += allwinner/
 obj-$(CONFIG_ALTERA_TSE) += altera/
 obj-$(CONFIG_NET_VENDOR_AMAZON) += amazon/
drivers/net/ethernet/alibaba/Kconfig new file +28 -0
new file mode 100644
index 000000000000..b8fd3c92fa4c
@@ -0,0 +1,28 @@
+#
+# Alibaba network device configuration
+#
+
+config NET_VENDOR_ALIBABA
+	bool "Alibaba Devices"
+	default y
+	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 Alibaba devices. If you say Y, you will be asked
+	  for your specific device in the following questions.
+
+if NET_VENDOR_ALIBABA
+
+config ALIBABA_EEA
+	tristate "Alibaba Elastic Ethernet Adapter support"
+	depends on PCI_MSI
+	depends on 64BIT
+	select PAGE_POOL
+	help
+	  This driver supports Alibaba Elastic Ethernet Adapter.
+
+	  To compile this driver as a module, choose M here.
+
+endif #NET_VENDOR_ALIBABA
drivers/net/ethernet/alibaba/Makefile new file +5 -0
new file mode 100644
index 000000000000..63a527e79ba7
@@ -0,0 +1,5 @@
+#
+# Makefile for the Alibaba network device drivers.
+#
+
+obj-$(CONFIG_ALIBABA_EEA) += eea/
drivers/net/ethernet/alibaba/eea/Makefile new file +3 -0
new file mode 100644
index 000000000000..a07f3019ec1f
@@ -0,0 +1,3 @@
+
+obj-$(CONFIG_ALIBABA_EEA) += eea.o
+eea-y := eea_pci.o
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +487 -0

487 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_pci.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#2 lore raw

Re: [PATCH net-next v43 1/8] eea: introduce PCI framework

From https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260514095138.80680-1-xuanzhuo%40linux.alibaba.com

commit 46941a5c3a95ebc5ea79193eb1c2ceab7183da1d
Author: Xuan Zhuo <[email protected]>
eea: introduce PCI framework
This patch adds a basic PCI driver framework for the Alibaba Elastic Ethernet Adapter (EEA), implementing PCI probe, remove, shutdown, the device-status handshake helpers, and an MMIO config layout. A few questions inline below.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +0 -0
new file mode 100644
index 000000000000..65a0ceb73b35
@@ -0,0 +1,487 @@

[ ... ]

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +11 -0
+int eea_device_reset(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev = edev->ep_dev;
+	int err;
+	u8 val;
+
+	eea_pci_io_set_status(edev, 0);
+
+	/* We are no longer waiting for device ack during the shutdown flow. */
+	if (ep_dev->shutdown)
+		return 0;

drivers/net/ethernet/alibaba/eea/eea_pci.c line 129

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	/* A longer timeout is set here to handle edge cases, though it should
+	 * return promptly in most scenarios.
+	 *
+	 * In our case, all replies are handled by the DPU software, so there is
+	 * no race condition between the hardware processes and the register.
+	 */
+	err = read_poll_timeout(cfg_read8, val, (!val || val == 0xFF), 20,
+				EEA_RESET_TIMEOUT_US,
+				false, ep_dev->reg, device_status);

On the shutdown path, ep_dev->shutdown is set to true and eea_device_reset() then returns immediately after writing device_status = 0, skipping the read_poll_timeout() that would otherwise wait for the device to acknowledge the reset:
eea_pci_shutdown():

    ep_dev->shutdown = true;
    /* do net device stop and clear. */
    eea_device_reset(edev);
    pci_clear_master(pci_dev);

After that, eea_pci_shutdown() calls pci_clear_master(), which only clears the bus-master enable bit and does not drain in-flight or posted DMA writes. Without a flush read of an MMIO register from this function or a synchronous device-side ack, is there a guarantee that the device has stopped issuing DMA before pci_clear_master() runs?
On kexec or warm-reboot, can in-flight DMA after eea_pci_shutdown() returns land in pages that the next kernel has reused?

Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +28 -0
+
+	/* Surprise PCIe Removal */
+	if (val == 0xFF)
+		return -EINVAL;
+
+	return err;
+}
+
+int eea_pci_set_aq_up(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev = edev->ep_dev;
+	u8 status = eea_pci_io_get_status(edev);
+	int err;
+	u8 val;
+
+	eea_pci_io_set_status(edev, status | EEA_S_OK);
+
+	/* A longer timeout is set here to handle edge cases, though it should
+	 * return promptly in most scenarios.
+	 *
+	 * In our case, all replies are handled by the DPU software, so there is
+	 * no race condition between the hardware processes and the register.
+	 */
+	err = read_poll_timeout(cfg_read8, val,
+				val & (EEA_S_OK | EEA_S_FAILED),
+				20, EEA_RESET_TIMEOUT_US,
+				false, ep_dev->reg, device_status);
+

drivers/net/ethernet/alibaba/eea/eea_pci.c line 167

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+	/* Surprise PCIe Removal */
+	if (val == 0xFF)
+		return -EINVAL;
+
+	/* device fail */
+	if (val & EEA_S_FAILED)
+		return -EINVAL;
+
+	return err;
+}

Can this handshake actually observe device acknowledgment?
The driver writes status | EEA_S_OK to device_status, then read_poll_timeout() waits for the readback to satisfy (val & (EEA_S_OK | EEA_S_FAILED)). read_poll_timeout() with sleep_before_read = false performs the op() once before sleeping, so the very first cfg_read8() of device_status will return the value that was just written, which already has EEA_S_OK set. The condition is met on iteration zero, the 60-second EEA_RESET_TIMEOUT_US never elapses, and EEA_S_FAILED never gets a chance to be observed.
For the device to ever indicate failure, would it need to first clear EEA_S_OK and then either re-assert EEA_S_OK on success or set EEA_S_FAILED on failure? Or use a separate ack/done bit that is distinct from the driver-written request bit? As written, the EEA_S_FAILED check below the poll appears unreachable on a healthy bus.

Quoted 17 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +17 -0
+
+static int eea_negotiate(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev;
+	u32 status;
+
+	ep_dev = edev->ep_dev;
+
+	edev->features = 0;
+
+	cfg_write32(ep_dev->reg, drv_f_idx, 0);
+	cfg_write32(ep_dev->reg, drv_f, lower_32_bits(edev->features));
+	cfg_write32(ep_dev->reg, drv_f_idx, 1);
+	cfg_write32(ep_dev->reg, drv_f, upper_32_bits(edev->features));
+
+	eea_add_status(edev, EEA_S_FEATURE_DONE);
+	status = eea_pci_io_get_status(edev);

drivers/net/ethernet/alibaba/eea/eea_pci.c line 194

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	/* Surprise PCIe Removal */
+	if (status == 0xFF)
+		return -EINVAL;
+
+	if (!(status & EEA_S_FEATURE_DONE))
+		return -ENODEV;
+
+	return 0;
+}

Is this status check tautological?
eea_add_status() reads device_status, ORs in EEA_S_FEATURE_DONE, and writes it back. The very next line reads device_status again, so unless the device clears the bit before the readback (which there is no synchronisation for), the readback will always have EEA_S_FEATURE_DONE set, except in the surprise removal case where the value is 0xFF.
Can this code detect a device that legitimately rejects the offered features, given there is no poll, delay, or wait for the device to react? The asymmetry with eea_pci_set_aq_up(), which does call read_poll_timeout() albeit with the issue noted above, suggests the protocol contract for these two transitions is different. Could the expected device-side behaviour for EEA_S_FEATURE_DONE be spelled out so reviewers can check the handshake?

Quoted 1 line

+

[ ... ]

Quoted 13 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +13 -0
+static int eea_pci_setup(struct pci_dev *pci_dev, struct eea_pci_device *ep_dev)
+{
+	int err, n, ret, len;
+
+	ep_dev->pci_dev = pci_dev;
+
+	err = pci_enable_device(pci_dev);
+	if (err)
+		return err;
+
+	err = pci_request_regions(pci_dev, "EEA");
+	if (err)
+		goto err_disable_dev;

[ ... ]

Quoted 12 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +12 -0
+	ep_dev->reg = pci_iomap(pci_dev, 0, 0);
+	if (!ep_dev->reg) {
+		dev_err(&pci_dev->dev, "Failed to map pci bar!\n");
+		err = -ENOMEM;
+		goto err_release_regions;
+	}
+
+	err = eea_device_reset(&ep_dev->edev);
+	if (err) {
+		dev_err(&pci_dev->dev, "Failed to reset device for setup!\n");
+		goto err_unmap_reg;
+	}

[ ... ]

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +11 -0
+	ep_dev->edev.rx_num = cfg_read32(ep_dev->reg, rx_num_max);
+	ep_dev->edev.tx_num = cfg_read32(ep_dev->reg, tx_num_max);
+
+	if (ep_dev->edev.rx_num > EEA_PCI_Q_MAX_NUM ||
+	    ep_dev->edev.tx_num > EEA_PCI_Q_MAX_NUM) {
+		dev_err(&pci_dev->dev, "Invalid queue num %u %u\n",
+			ep_dev->edev.rx_num,
+			ep_dev->edev.tx_num);
+		err = -EINVAL;
+		goto err_clear_master;
+	}

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_pci.c line 303

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +11 -0
+	/* In our design, the number of hardware interrupts matches the maximum
+	 * number of queues. If pci_alloc_irq_vectors failed, return directly.
+	 *
+	 * 2: adminq, error handle
+	 */
+	n = ep_dev->edev.rx_num + 2;
+	ret = pci_alloc_irq_vectors(ep_dev->pci_dev, n, n, PCI_IRQ_MSIX);
+	if (ret != n) {
+		err = ret;
+		goto err_clear_master;
+	}

The vector count uses rx_num only, but tx_num is also read from the device and validated independently against EEA_PCI_Q_MAX_NUM. If a device ever advertises tx_num > rx_num, would later patches that bind a TX-queue IRQ at an index above rx_num + 1 fail because no vector was allocated? Should this be max(rx_num, tx_num) + 2, or should there be an explicit invariant rejecting tx_num > rx_num here so that the design assumption from the comment is enforced?

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +4 -0
+
+	ep_dev->msix_vec_n = ret;
+
+	return 0;

[ ... ]

Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +28 -0
+static int eea_init_device(struct eea_device *edev)
+{
+	int err;
+
+	err = eea_device_reset(edev);
+	if (err)
+		return err;
+
+	eea_pci_io_set_status(edev, EEA_S_INIT);
+
+	err = eea_negotiate(edev);
+	if (err)
+		goto err;
+
+	/* do net device probe ... */
+
+	return 0;
+err:
+	eea_add_status(edev, EEA_S_FAILED);
+	return err;
+}
+
+static int __eea_pci_probe(struct pci_dev *pci_dev,
+			   struct eea_pci_device *ep_dev)
+{
+	int err;
+
+	pci_set_drvdata(pci_dev, ep_dev);

drivers/net/ethernet/alibaba/eea/eea_pci.c line 384

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	err = eea_pci_setup(pci_dev, ep_dev);
+	if (err)
+		return err;
+
+	err = eea_init_device(&ep_dev->edev);
+	if (err)
+		goto err_pci_rel;
+
+	return 0;

The probe path calls eea_device_reset() twice in succession:
__eea_pci_probe()
-> eea_pci_setup()

       -> eea_device_reset()  /* first reset */
  -> eea_init_device()
       -> eea_device_reset()  /* second reset */

EEA_RESET_TIMEOUT_US is 60 seconds, so a misbehaving or slow device can stall probe for up to 120 seconds. Is the second reset intentional, and if so, could the rationale be added as a comment? Otherwise, would it make sense to drop one of them so that probe has only one reset point?

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +5 -0
+
+err_pci_rel:
+	eea_pci_release_resource(ep_dev);
+	return err;
+}

[ ... ]

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +0 -0
new file mode 100644
index 000000000000..746cce4dd68e
@@ -0,0 +1,50 @@

[ ... ]

Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +28 -0
+struct eea_pci_cap {
+	__u8 cap_vndr;
+	__u8 cap_next;
+	__u8 cap_len;
+	__u8 cfg_type;
+};
+
+struct eea_pci_reset_reg {
+	struct eea_pci_cap cap;
+	__le16 driver;
+	__le16 device;
+};
+
+struct eea_pci_device;
+
+struct eea_device {
+	struct eea_pci_device *ep_dev;
+	struct device         *dma_dev;
+	struct eea_net        *enet;
+
+	u64 features;
+
+	u32 rx_num;
+	u32 tx_num;
+	u32 db_blk_size;
+};
+
+const char *eea_pci_name(struct eea_device *edev);

drivers/net/ethernet/alibaba/eea/eea_pci.h line 50

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +10 -0
+int eea_pci_domain_nr(struct eea_device *edev);
+u16 eea_pci_bdf(struct eea_device *edev);
+
+int eea_device_reset(struct eea_device *dev);
+int eea_pci_set_aq_up(struct eea_device *dev);
+
+u64 eea_pci_device_ts(struct eea_device *edev);
+
+void __iomem *eea_pci_db_addr(struct eea_device *edev, u32 off);
+#endif

A number of symbols introduced here have no callers in this commit:
eea_pci_name()
eea_pci_domain_nr()
eea_pci_bdf()
eea_pci_set_aq_up()
eea_pci_db_addr()
eea_pci_device_ts()
struct eea_pci_cap
struct eea_pci_reset_reg
struct eea_device also references struct eea_net via the enet field, but struct eea_net is not declared anywhere in this commit.
Because these helpers are non-static, the compiler will not warn about unused functions, so the contracts they establish (for example the eea_pci_set_aq_up() handshake noted above) cannot be checked against a real caller in this patch.
Could the series be reorganised so that each helper or type is introduced together with its first user, per the usual kernel convention?

author maintainer
#3 lore raw

Re: [PATCH net-next v43 1/8] eea: introduce PCI framework

Quoted 47 lines · Xuan Zhuo

From https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260514095138.80680-1-xuanzhuo%40linux.alibaba.com

commit 46941a5c3a95ebc5ea79193eb1c2ceab7183da1d
Author: Xuan Zhuo <[email protected]>
eea: introduce PCI framework
This patch adds a basic PCI driver framework for the Alibaba Elastic Ethernet Adapter (EEA), implementing PCI probe, remove, shutdown, the device-status handshake helpers, and an MMIO config layout. A few questions inline below.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +0 -0
new file mode 100644
index 000000000000..65a0ceb73b35
@@ -0,0 +1,487 @@

[ ... ]

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +11 -0
+int eea_device_reset(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev = edev->ep_dev;
+	int err;
+	u8 val;
+
+	eea_pci_io_set_status(edev, 0);
+
+	/* We are no longer waiting for device ack during the shutdown flow. */
+	if (ep_dev->shutdown)
+		return 0;

drivers/net/ethernet/alibaba/eea/eea_pci.c line 129

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	/* A longer timeout is set here to handle edge cases, though it should
+	 * return promptly in most scenarios.
+	 *
+	 * In our case, all replies are handled by the DPU software, so there is
+	 * no race condition between the hardware processes and the register.
+	 */
+	err = read_poll_timeout(cfg_read8, val, (!val || val == 0xFF), 20,
+				EEA_RESET_TIMEOUT_US,
+				false, ep_dev->reg, device_status);

On the shutdown path, ep_dev->shutdown is set to true and eea_device_reset() then returns immediately after writing device_status = 0, skipping the read_poll_timeout() that would otherwise wait for the device to acknowledge the reset:
eea_pci_shutdown():

    ep_dev->shutdown = true;
    /* do net device stop and clear. */
    eea_device_reset(edev);
    pci_clear_master(pci_dev);
Quoted 7 lines

After that, eea_pci_shutdown() calls pci_clear_master(), which only clears the bus-master enable bit and does not drain in-flight or posted DMA writes. Without a flush read of an MMIO register from this function or a synchronous device-side ack, is there a guarantee that the device has stopped issuing DMA before pci_clear_master() runs?
On kexec or warm-reboot, can in-flight DMA after eea_pci_shutdown() returns land in pages that the next kernel has reused?

We prefer to avoid blocking for too long during the shutdown process, which is why read_poll_timeout is skipped here. As for the probe phase, I ensure DMA safety by triggering a reset before setting the master.

Quoted 43 lines
Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +28 -0
+
+	/* Surprise PCIe Removal */
+	if (val == 0xFF)
+		return -EINVAL;
+
+	return err;
+}
+
+int eea_pci_set_aq_up(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev = edev->ep_dev;
+	u8 status = eea_pci_io_get_status(edev);
+	int err;
+	u8 val;
+
+	eea_pci_io_set_status(edev, status | EEA_S_OK);
+
+	/* A longer timeout is set here to handle edge cases, though it should
+	 * return promptly in most scenarios.
+	 *
+	 * In our case, all replies are handled by the DPU software, so there is
+	 * no race condition between the hardware processes and the register.
+	 */
+	err = read_poll_timeout(cfg_read8, val,
+				val & (EEA_S_OK | EEA_S_FAILED),
+				20, EEA_RESET_TIMEOUT_US,
+				false, ep_dev->reg, device_status);
+

drivers/net/ethernet/alibaba/eea/eea_pci.c line 167

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+	/* Surprise PCIe Removal */
+	if (val == 0xFF)
+		return -EINVAL;
+
+	/* device fail */
+	if (val & EEA_S_FAILED)
+		return -EINVAL;
+
+	return err;
+}

Can this handshake actually observe device acknowledgment?
The driver writes status | EEA_S_OK to device_status, then read_poll_timeout() waits for the readback to satisfy (val & (EEA_S_OK | EEA_S_FAILED)). read_poll_timeout() with sleep_before_read = false performs the op() once before sleeping, so the very first cfg_read8() of device_status will return

Quoted 8 lines

the value that was just written, which already has EEA_S_OK set. The condition is met on iteration zero, the 60-second EEA_RESET_TIMEOUT_US never elapses, and EEA_S_FAILED never gets a chance to be observed. For the device to ever indicate failure, would it need to first clear EEA_S_OK and then either re-assert EEA_S_OK on success or set EEA_S_FAILED on failure? Or use a separate ack/done bit that is distinct from the driver-written request bit? As written, the EEA_S_FAILED check below the poll appears unreachable on a healthy bus.

This is a DPU implementation, so all PCI TLP messages are handled and acknowledged by software. Even for PCI registers, the read operation does not simply return the last written value.

Quoted 31 lines
Quoted 17 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +17 -0
+
+static int eea_negotiate(struct eea_device *edev)
+{
+	struct eea_pci_device *ep_dev;
+	u32 status;
+
+	ep_dev = edev->ep_dev;
+
+	edev->features = 0;
+
+	cfg_write32(ep_dev->reg, drv_f_idx, 0);
+	cfg_write32(ep_dev->reg, drv_f, lower_32_bits(edev->features));
+	cfg_write32(ep_dev->reg, drv_f_idx, 1);
+	cfg_write32(ep_dev->reg, drv_f, upper_32_bits(edev->features));
+
+	eea_add_status(edev, EEA_S_FEATURE_DONE);
+	status = eea_pci_io_get_status(edev);

drivers/net/ethernet/alibaba/eea/eea_pci.c line 194

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	/* Surprise PCIe Removal */
+	if (status == 0xFF)
+		return -EINVAL;
+
+	if (!(status & EEA_S_FEATURE_DONE))
+		return -ENODEV;
+
+	return 0;
+}

Is this status check tautological?
eea_add_status() reads device_status, ORs in EEA_S_FEATURE_DONE, and writes it back. The very next line reads device_status again, so unless the device clears the bit before the readback (which there is no synchronisation for),

Quoted 8 lines

the readback will always have EEA_S_FEATURE_DONE set, except in the surprise removal case where the value is 0xFF.
Can this code detect a device that legitimately rejects the offered features, given there is no poll, delay, or wait for the device to react? The asymmetry with eea_pci_set_aq_up(), which does call read_poll_timeout() albeit with the issue noted above, suggests the protocol contract for these two transitions is different. Could the expected device-side behaviour for EEA_S_FEATURE_DONE be spelled out so reviewers can check the handshake?

This is just a framework, for this version no feature is needed to negotiabled.

Quoted 51 lines
Quoted 1 line

+

[ ... ]

Quoted 13 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +13 -0
+static int eea_pci_setup(struct pci_dev *pci_dev, struct eea_pci_device *ep_dev)
+{
+	int err, n, ret, len;
+
+	ep_dev->pci_dev = pci_dev;
+
+	err = pci_enable_device(pci_dev);
+	if (err)
+		return err;
+
+	err = pci_request_regions(pci_dev, "EEA");
+	if (err)
+		goto err_disable_dev;

[ ... ]

Quoted 12 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +12 -0
+	ep_dev->reg = pci_iomap(pci_dev, 0, 0);
+	if (!ep_dev->reg) {
+		dev_err(&pci_dev->dev, "Failed to map pci bar!\n");
+		err = -ENOMEM;
+		goto err_release_regions;
+	}
+
+	err = eea_device_reset(&ep_dev->edev);
+	if (err) {
+		dev_err(&pci_dev->dev, "Failed to reset device for setup!\n");
+		goto err_unmap_reg;
+	}

[ ... ]

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +11 -0
+	ep_dev->edev.rx_num = cfg_read32(ep_dev->reg, rx_num_max);
+	ep_dev->edev.tx_num = cfg_read32(ep_dev->reg, tx_num_max);
+
+	if (ep_dev->edev.rx_num > EEA_PCI_Q_MAX_NUM ||
+	    ep_dev->edev.tx_num > EEA_PCI_Q_MAX_NUM) {
+		dev_err(&pci_dev->dev, "Invalid queue num %u %u\n",
+			ep_dev->edev.rx_num,
+			ep_dev->edev.tx_num);
+		err = -EINVAL;
+		goto err_clear_master;
+	}

[ ... ]

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+	/* In our design, the number of hardware interrupts matches the maximum
+	 * number of queues. If pci_alloc_irq_vectors failed, return directly.
+	 *
+	 * 2: adminq, error handle
+	 */
+	n = ep_dev->edev.rx_num + 2;
+	ret = pci_alloc_irq_vectors(ep_dev->pci_dev, n, n, PCI_IRQ_MSIX);
+	if (ret != n) {
+		err = ret;
+		goto err_clear_master;
Quoted 8 lines

drivers/net/ethernet/alibaba/eea/eea_pci.c

Quoted 1 line
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +1 -0
+	}

The vector count uses rx_num only, but tx_num is also read from the device and validated independently against EEA_PCI_Q_MAX_NUM. If a device ever advertises tx_num > rx_num, would later patches that bind a TX-queue IRQ at an index above rx_num + 1 fail because no vector was allocated? Should this be max(rx_num, tx_num) + 2, or should there be an explicit invariant rejecting tx_num > rx_num here so that the design assumption from the comment is enforced?

For the current design, these issues are out of scope.

Quoted 46 lines
Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +4 -0
+
+	ep_dev->msix_vec_n = ret;
+
+	return 0;

[ ... ]

Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +28 -0
+static int eea_init_device(struct eea_device *edev)
+{
+	int err;
+
+	err = eea_device_reset(edev);
+	if (err)
+		return err;
+
+	eea_pci_io_set_status(edev, EEA_S_INIT);
+
+	err = eea_negotiate(edev);
+	if (err)
+		goto err;
+
+	/* do net device probe ... */
+
+	return 0;
+err:
+	eea_add_status(edev, EEA_S_FAILED);
+	return err;
+}
+
+static int __eea_pci_probe(struct pci_dev *pci_dev,
+			   struct eea_pci_device *ep_dev)
+{
+	int err;
+
+	pci_set_drvdata(pci_dev, ep_dev);

drivers/net/ethernet/alibaba/eea/eea_pci.c line 384

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +10 -0
+
+	err = eea_pci_setup(pci_dev, ep_dev);
+	if (err)
+		return err;
+
+	err = eea_init_device(&ep_dev->edev);
+	if (err)
+		goto err_pci_rel;
+
+	return 0;

The probe path calls eea_device_reset() twice in succession:
__eea_pci_probe()
-> eea_pci_setup()

Quoted 7 lines
       -> eea_device_reset()  /* first reset */
  -> eea_init_device()
       -> eea_device_reset()  /* second reset */

EEA_RESET_TIMEOUT_US is 60 seconds, so a misbehaving or slow device can stall probe for up to 120 seconds. Is the second reset intentional, and if so, could the rationale be added as a comment? Otherwise, would it make sense to drop one of them so that probe has only one reset point?

The first reset is intended to clear any potential DMA remnants from scenarios like kexec. The second reset is performed to ensure the device is in a valid state immediately before the actual probe. While the 60s timeout is a worst-case safeguard, the actual device response should typically complete within 1 second.

Quoted 60 lines
Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c new file +5 -0
+
+err_pci_rel:
+	eea_pci_release_resource(ep_dev);
+	return err;
+}

[ ... ]

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +0 -0
new file mode 100644
index 000000000000..746cce4dd68e
@@ -0,0 +1,50 @@

[ ... ]

Quoted 28 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +28 -0
+struct eea_pci_cap {
+	__u8 cap_vndr;
+	__u8 cap_next;
+	__u8 cap_len;
+	__u8 cfg_type;
+};
+
+struct eea_pci_reset_reg {
+	struct eea_pci_cap cap;
+	__le16 driver;
+	__le16 device;
+};
+
+struct eea_pci_device;
+
+struct eea_device {
+	struct eea_pci_device *ep_dev;
+	struct device         *dma_dev;
+	struct eea_net        *enet;
+
+	u64 features;
+
+	u32 rx_num;
+	u32 tx_num;
+	u32 db_blk_size;
+};
+
+const char *eea_pci_name(struct eea_device *edev);

drivers/net/ethernet/alibaba/eea/eea_pci.h line 50

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.h new file +10 -0
+int eea_pci_domain_nr(struct eea_device *edev);
+u16 eea_pci_bdf(struct eea_device *edev);
+
+int eea_device_reset(struct eea_device *dev);
+int eea_pci_set_aq_up(struct eea_device *dev);
+
+u64 eea_pci_device_ts(struct eea_device *edev);
+
+void __iomem *eea_pci_db_addr(struct eea_device *edev, u32 off);
+#endif

A number of symbols introduced here have no callers in this commit:
eea_pci_name()
eea_pci_domain_nr()
eea_pci_bdf()
eea_pci_set_aq_up()
eea_pci_db_addr()
eea_pci_device_ts()
struct eea_pci_cap
struct eea_pci_reset_reg

Quoted 8 lines

struct eea_device also references struct eea_net via the enet field, but struct eea_net is not declared anywhere in this commit.
Because these helpers are non-static, the compiler will not warn about unused functions, so the contracts they establish (for example the eea_pci_set_aq_up() handshake noted above) cannot be checked against a real caller in this patch.
Could the series be reorganised so that each helper or type is introduced together with its first user, per the usual kernel convention?

If there is a follow-up version, I will do this.

author maintainer
#4 lore raw

PATCH v43 2/8 eea: introduce ring and descriptor structures

In reply to Xuan Zhuo

Add basic driver framework for the Alibaba Elastic Ethernet Adapter(EEA).

This commit introduces the ring and descriptor implementations.

These structures and ring APIs are used by the RX, TX, and admin queues.

---
 drivers/net/ethernet/alibaba/eea/Makefile   |   3 +-
 drivers/net/ethernet/alibaba/eea/eea_desc.h | 138 +++++++++++
 drivers/net/ethernet/alibaba/eea/eea_ring.c | 249 ++++++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_ring.h |  99 ++++++++
 4 files changed, 488 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_desc.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.h
drivers/net/ethernet/alibaba/eea/Makefile +2 -1
index a07f3019ec1f..7d8e7e8c2f3a 100644
@@ -1,3 +1,4 @@
 
 obj-$(CONFIG_ALIBABA_EEA) += eea.o
-eea-y := eea_pci.o
+eea-y :=  eea_ring.o \
+	eea_pci.o
drivers/net/ethernet/alibaba/eea/eea_desc.h new file +138 -0

138 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_ring.c new file +249 -0

249 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_ring.h new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#5 lore raw

Re: [PATCH net-next v43 2/8] eea: introduce ring and descriptor structures

No regressions from Sashiko.

author maintainer
#6 lore raw

PATCH v43 3/8 eea: probe the netdevice and create adminq

In reply to Xuan Zhuo

Add basic driver framework for the Alibaba Elastic Ethernet Adapter(EEA).

This commit creates the netdevice after PCI probe, and initializes the admin queue to send commands to the device.

---
 drivers/net/ethernet/alibaba/eea/Makefile     |   6 +-
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 542 ++++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_adminq.h |  83 +++
 drivers/net/ethernet/alibaba/eea/eea_net.c    | 249 ++++++++
 drivers/net/ethernet/alibaba/eea/eea_net.h    | 137 +++++
 drivers/net/ethernet/alibaba/eea/eea_pci.c    |  35 +-
 drivers/net/ethernet/alibaba/eea/eea_pci.h    |   3 +
 7 files changed, 1047 insertions(+), 8 deletions(-)
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.h
drivers/net/ethernet/alibaba/eea/Makefile +4 -2
index 7d8e7e8c2f3a..a842ac416ae8 100644
@@ -1,4 +1,6 @@
 
 obj-$(CONFIG_ALIBABA_EEA) += eea.o
-eea-y :=  eea_ring.o \
-	eea_pci.o
+eea-y := eea_ring.o \
+	eea_net.o \
+	eea_pci.o \
+	eea_adminq.o
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +542 -0

542 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_adminq.h new file +83 -0

83 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_net.c new file +249 -0

249 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_net.h new file +137 -0

137 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_pci.c +29 -6
index 65a0ceb73b35..bef0ebd6bb20 100644
@@ -8,6 +8,7 @@
 #include <linux/io-64-nonatomic-lo-hi.h>
 #include <linux/iopoll.h>
 
+#include "eea_net.h"
 #include "eea_pci.h"
 
 #define EEA_PCI_DB_OFFSET 4096
@@ -64,7 +65,9 @@ struct eea_pci_device {
 	((void __iomem *)((reg) + offsetof(struct eea_pci_cfg, item)))
 
 #define cfg_write8(reg, item, val) iowrite8(val, cfg_pointer(reg, item))
+#define cfg_write16(reg, item, val) iowrite16(val, cfg_pointer(reg, item))
 #define cfg_write32(reg, item, val) iowrite32(val, cfg_pointer(reg, item))
+#define cfg_write64(reg, item, val) iowrite64_lo_hi(val, cfg_pointer(reg, item))
 
 #define cfg_read8(reg, item) ioread8(cfg_pointer(reg, item))
 #define cfg_read32(reg, item) ioread32(cfg_pointer(reg, item))
@@ -337,6 +340,25 @@ void __iomem *eea_pci_db_addr(struct eea_device *edev, u32 off)
 	return edev->ep_dev->db_base + off;
 }
 
+int eea_pci_active_aq(struct eea_ring *ering, int msix_vec)
+{
+	struct eea_pci_device *ep_dev = ering->edev->ep_dev;
+
+	cfg_write16(ep_dev->reg, aq_size, ering->num);
+	cfg_write16(ep_dev->reg, aq_msix_vector, msix_vec);
+
+	cfg_write64(ep_dev->reg, aq_sq_addr, ering->sq.dma_addr);
+	cfg_write64(ep_dev->reg, aq_cq_addr, ering->cq.dma_addr);
+
+	ering->db = eea_pci_db_addr(ering->edev,
+				    cfg_read32(ep_dev->reg, aq_db_off));
+
+	if (!ering->db)
+		return -EIO;
+
+	return 0;
+}
+
 u64 eea_pci_device_ts(struct eea_device *edev)
 {
 	struct eea_pci_device *ep_dev = edev->ep_dev;
@@ -358,7 +380,9 @@ static int eea_init_device(struct eea_device *edev)
 	if (err)
 		goto err;
 
-	/* do net device probe ... */
+	err = eea_net_probe(edev);
+	if (err)
+		goto err;
 
 	return 0;
 err:
@@ -392,6 +416,9 @@ static void __eea_pci_remove(struct pci_dev *pci_dev)
 {
 	struct eea_pci_device *ep_dev = pci_get_drvdata(pci_dev);
 	struct device *dev = get_device(&ep_dev->pci_dev->dev);
+	struct eea_device *edev = &ep_dev->edev;
+
+	eea_net_remove(edev);
 
 	eea_pci_release_resource(ep_dev);
 
@@ -429,8 +456,6 @@ static void eea_pci_remove(struct pci_dev *pci_dev)
 {
 	struct eea_pci_device *ep_dev = pci_get_drvdata(pci_dev);
 
-	eea_device_reset(&ep_dev->edev);
-
 	__eea_pci_remove(pci_dev);
 
 	pci_set_drvdata(pci_dev, NULL);
@@ -446,9 +471,7 @@ static void eea_pci_shutdown(struct pci_dev *pci_dev)
 
 	ep_dev->shutdown = true;
 
-	/* do net device stop and clear. */
-
-	eea_device_reset(edev);
+	eea_net_shutdown(edev);
 
 	pci_clear_master(pci_dev);
 }
drivers/net/ethernet/alibaba/eea/eea_pci.h +3 -0
index 746cce4dd68e..cfd278e2efde 100644
@@ -10,6 +10,8 @@
 
 #include <linux/pci.h>
 
+#include "eea_ring.h"
+
 struct eea_pci_cap {
 	__u8 cap_vndr;
 	__u8 cap_next;
@@ -43,6 +45,7 @@ u16 eea_pci_bdf(struct eea_device *edev);
 
 int eea_device_reset(struct eea_device *dev);
 int eea_pci_set_aq_up(struct eea_device *dev);
+int eea_pci_active_aq(struct eea_ring *ering, int msix_vec);
 
 u64 eea_pci_device_ts(struct eea_device *edev);
 
Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#7 lore raw

Re: [PATCH net-next v43 3/8] eea: probe the netdevice and create adminq

Sashiko ai review:

commit b9e7d5d9497cc9075fff4db2f0e1c143dbb8d2d8
Author: Xuan Zhuo <[email protected]>
eea: probe the netdevice and create adminq
This patch adds the basic driver framework for the Alibaba Elastic Ethernet Adapter, creating the netdevice after PCI probe and initialising the admin queue used to issue commands to the device. A few questions on the code below.

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +0 -0
new file mode 100644
index 000000000000..dfad1bdbc44d

[ ... ]

Quoted 7 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +7 -0
+static int eea_adminq_submit(struct eea_net *enet, u16 cmd,
+			     dma_addr_t req_addr, dma_addr_t res_addr,
+			     u32 req_size, u32 res_size, u32 *reply_len)
+{
+	struct eea_aq_cdesc *cdesc;
+	struct eea_aq_desc *desc;
+	int ret;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 191

Quoted 13 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +13 -0
+	/* Returns 0 on success, or a negative error code on failure. */
+	ret = le32_to_cpu(cdesc->status);
+
+	eea_ering_cq_ack_desc(enet->adminq.ring, 1);
+
+	if (ret)
+		netdev_err(enet->netdev,
+			   "adminq exec failed. cmd: %d ret %d\n", cmd, ret);
+	else
+		*reply_len = le32_to_cpu(cdesc->reply_len);
+
+	return ret;
+}

The wire protocol header defines:
#define EEA_OK 0
#define EEA_ERR 0xffffffff
cdesc->status is a __le32, but it is stored into a signed int here:
ret = le32_to_cpu(cdesc->status);
When the device reports failure (0xffffffff), ret becomes -1, which is -EPERM. That value then propagates up through eea_adminq_exec() into eea_netdev_init_features() and ultimately out of probe. Should the device's protocol-level error be translated to a more appropriate kernel errno such as -EIO before being returned to the generic layers, given that the wire protocol defines only EEA_OK and EEA_ERR rather than a kernel errno space?
[ ... ]

Quoted 48 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +48 -0
+int eea_create_adminq(struct eea_net *enet, u32 qid)
+{
+	u32 db_size, q_size, num;
+	struct eea_ring *ering;
+	struct eea_aq *aq;
+	int err = -ENOMEM;
+
+	num = enet->edev->rx_num + enet->edev->tx_num;
+	aq = &enet->adminq;
+
+	ering = eea_ering_alloc(qid, 64, enet->edev, sizeof(struct eea_aq_desc),
+				sizeof(struct eea_aq_cdesc), "adminq");
+	if (!ering)
+		return -ENOMEM;
+
+	aq->ring = ering;
+
+	err = eea_pci_active_aq(ering, qid / 2 + 1);
+	if (err)
+		goto err;
+
+	aq->phase = BIT(7);
+	aq->num = 0;
+
+	q_size = sizeof(*aq->q_req_buf) * num;
+	db_size = sizeof(*aq->q_res_buf) * num;
+
+	aq->q_req_size = q_size;
+	aq->q_res_size = db_size;
+
+	err = -ENOMEM;
+
+	aq->q_req_buf = kzalloc(q_size, GFP_KERNEL);
+	if (!aq->q_req_buf)
+		goto err;
+
+	aq->q_res_buf = kzalloc(db_size, GFP_KERNEL);
+	if (!aq->q_res_buf)
+		goto err;
+
+	/* Before we set up the AQ, the device remains in an inactive state, so
+	 * there will be no DMA operations. If the 'set up AQ' process fails, we
+	 * can safely free the DMA-related memory.
+	 */
+	err = eea_pci_set_aq_up(enet->edev);
+	if (err)
+		goto err;
+

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 321

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +10 -0
+	aq->broken = false;
+
+	mutex_init(&aq->lock);
+
+	return 0;
+
+err:
+	eea_destroy_adminq(enet);
+	return err;
+}

By the time eea_pci_set_aq_up() is called, eea_pci_active_aq() has already programmed the SQ/CQ DMA addresses into the device registers and eea_pci_set_aq_up() has signalled EEA_S_OK. If the read_poll_timeout() inside eea_pci_set_aq_up() times out, can the device be assumed to still be quiescent?
The err: label here jumps directly to eea_destroy_adminq(), which calls eea_ering_free() -> dma_free_coherent() without first calling eea_device_reset(). Every other teardown site in this commit resets first, for example eea_adminq_destroy_all_q():

  if (err) {
      /* The device must be reset before unmapping buffers to avoid
       * potential DMA writes after the memory is freed.
       */
      mutex_lock(&enet->adminq.lock);
      eea_device_broken(enet);
      mutex_unlock(&enet->adminq.lock);
      ...

}
and eea_adminq_submit()'s timeout path (via eea_device_broken()), and the err_reset_dev label in eea_net_probe(). Should this err: label also call eea_device_reset(enet->edev) before eea_destroy_adminq() to avoid a DMA-after-free window into the freed SQ/CQ rings? mutex_init(&aq->lock) is called only after the last goto err point, and eea_destroy_adminq() never calls mutex_destroy() on it. Should eea_destroy_adminq() pair the init with mutex_destroy(), and should mutex_init() move earlier so the lock is always initialised on the teardown path?
[ ... ]

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +6 -0
+void eea_adminq_config_host_info(struct eea_net *enet)
+{
+	struct device *dev = enet->edev->dma_dev;
+	struct eea_aq_host_info_cfg *cfg;
+	struct eea_aq_host_info_rep *rep;
+	int rc = -ENOMEM;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 507

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +11 -0
+	cfg->os_type            = cpu_to_le16(EEA_OS_LINUX);
+	cfg->os_dist            = cpu_to_le16(EEA_OS_DISTRO);
+	cfg->drv_type           = cpu_to_le16(EEA_DRV_TYPE);
+
+	cfg->kern_ver_major     = cpu_to_le16(LINUX_VERSION_MAJOR);
+	cfg->kern_ver_minor     = cpu_to_le16(LINUX_VERSION_PATCHLEVEL);
+	cfg->kern_ver_sub_minor = cpu_to_le16(LINUX_VERSION_SUBLEVEL);
+
+	cfg->drv_ver_major      = cpu_to_le16(EEA_VER_MAJOR);
+	cfg->drv_ver_minor      = cpu_to_le16(EEA_VER_MINOR);
+	cfg->drv_ver_sub_minor  = cpu_to_le16(EEA_VER_SUB_MINOR);

The driver carries a private version triplet (EEA_VER_MAJOR/MINOR/ SUB_MINOR = 1.0.0) and reports it to the device. For an upstream driver, the canonical version is the kernel version itself; private driver version numbers tend to fall out of date and have historically been pushed back on by netdev maintainers.
Could this field be dropped, or derived from the kernel version, rather than freezing 1.0.0 into the device-side ABI?

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 516

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +9 -0
+
+	cfg->spec_ver_major     = cpu_to_le16(EEA_SPEC_VER_MAJOR);
+	cfg->spec_ver_minor     = cpu_to_le16(EEA_SPEC_VER_MINOR);
+
+	cfg->pci_bdf            = cpu_to_le16(eea_pci_bdf(enet->edev));
+	cfg->pci_domain         = cpu_to_le32(eea_pci_domain_nr(enet->edev));
+
+	strscpy(cfg->os_ver_str, utsname()->release, sizeof(cfg->os_ver_str));
+	strscpy(cfg->isa_str, utsname()->machine, sizeof(cfg->isa_str));

On every probe the driver unconditionally sends utsname()->release, utsname()->machine, the full Linux kernel version, os_dist, drv_type, the PCI BDF and PCI domain to the device. The kernel release string is set by distros and can include build identifiers.
Could the commit message explain what the firmware does with these strings, and is there a reason this needs to be unconditional rather than gated on a module parameter or kernel option? EEA_OS_DISTRO and EEA_DRV_TYPE are both hardcoded to 0 with no documented enumeration of valid values. Together with EEA_OS_LINUX=1, these become part of the wire ABI introduced in this commit. If these fields are intended to grow (for example to distinguish upstream vs out-of-tree builds, or kernel module vs userspace consumers), can the meaning of value 0 and the reserved range be documented now? If they are not needed, can they be removed before firmware ships against this layout?

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +3 -0
+
+	rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
+			     cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);

[ ... ]

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +0 -0
new file mode 100644
index 000000000000..bb8a49f8c6df

[ ... ]

Quoted 7 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +7 -0
+static int eea_netdev_init_features(struct net_device *netdev,
+				    struct eea_net *enet,
+				    struct eea_device *edev)
+{
+	struct eea_aq_cfg *cfg;
+	int err;
+	u32 mtu;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_net.c line 144

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +9 -0
+	netdev->min_mtu = ETH_MIN_MTU;
+
+	netdev->mtu = mtu;
+
+	/* If jumbo frames are already enabled, then the returned MTU will be a
+	 * jumbo MTU, and the driver will automatically enable jumbo frame
+	 * support by default.
+	 */
+	netdev->max_mtu = mtu;

netdev->max_mtu is set to the same value as netdev->mtu, where mtu came from cfg->mtu in the device's reply to EEA_AQ_CMD_CFG_QUERY. The eea_aq_cfg structure has only a single __le16 mtu field and no separate maximum, and the comment above describes mtu as the current configured MTU rather than the device-supported maximum. With max_mtu == mtu, can a user ever raise the MTU above the value the device happened to advertise at probe time via "ip link set dev X mtu N"? Should the wire ABI being introduced here grow a separate mtu_max field, or should the driver derive a maximum (for example a fixed jumbo cap) for max_mtu?

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +5 -0
+
+err_free:
+	kfree(cfg);
+	return err;
+}

[ ... ]

Quoted 16 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +16 -0
+int eea_net_probe(struct eea_device *edev)
+{
+	struct eea_net *enet;
+	int err = -ENOMEM;
+
+	enet = eea_netdev_alloc(edev, edev->rx_num);
+	if (!enet)
+		return -ENOMEM;
+
+	err = eea_create_adminq(enet, edev->rx_num + edev->tx_num);
+	if (err)
+		goto err_free_netdev;
+
+	eea_adminq_config_host_info(enet);
+
+	err = eea_netdev_init_features(enet->netdev, enet, edev);

drivers/net/ethernet/alibaba/eea/eea_net.c line 204

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +10 -0
+	if (err)
+		goto err_reset_dev;
+
+	netdev_dbg(enet->netdev, "eea probe success.\n");
+
+	/* Queue TX/RX implementation is still in progress. register_netdev is
+	 * deferred until these are completed in subsequent commits.
+	 */
+
+	return 0;

After this commit, eea_net_probe() returns success without calling register_netdev(). A bisect that lands exactly on this commit will see a probed PCI driver that has consumed IRQs and DMA buffers and already issued the HOST_INFO admin command to firmware, but no netdev visible to userspace.
Could this patch be squashed with the later patches that complete the TX/RX paths and call register_netdev(), so a bisected kernel either has a working interface or no driver activation at all?

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +9 -0
+
+err_reset_dev:
+	eea_device_reset(edev);
+	eea_destroy_adminq(enet);
+
+err_free_netdev:
+	free_netdev(enet->netdev);
+	return err;
+}
author maintainer
#8 lore raw

Re: [PATCH net-next v43 3/8] eea: probe the netdevice and create adminq

Quoted 41 lines · Xuan Zhuo

Sashiko ai review:

commit b9e7d5d9497cc9075fff4db2f0e1c143dbb8d2d8
Author: Xuan Zhuo <[email protected]>
eea: probe the netdevice and create adminq
This patch adds the basic driver framework for the Alibaba Elastic Ethernet Adapter, creating the netdevice after PCI probe and initialising the admin queue used to issue commands to the device. A few questions on the code below.

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +0 -0
new file mode 100644
index 000000000000..dfad1bdbc44d

[ ... ]

Quoted 7 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +7 -0
+static int eea_adminq_submit(struct eea_net *enet, u16 cmd,
+			     dma_addr_t req_addr, dma_addr_t res_addr,
+			     u32 req_size, u32 res_size, u32 *reply_len)
+{
+	struct eea_aq_cdesc *cdesc;
+	struct eea_aq_desc *desc;
+	int ret;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 191

Quoted 13 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +13 -0
+	/* Returns 0 on success, or a negative error code on failure. */
+	ret = le32_to_cpu(cdesc->status);
+
+	eea_ering_cq_ack_desc(enet->adminq.ring, 1);
+
+	if (ret)
+		netdev_err(enet->netdev,
+			   "adminq exec failed. cmd: %d ret %d\n", cmd, ret);
+	else
+		*reply_len = le32_to_cpu(cdesc->reply_len);
+
+	return ret;
+}

The wire protocol header defines:
#define EEA_OK 0
#define EEA_ERR 0xffffffff
cdesc->status is a __le32, but it is stored into a signed int here:

Quoted 8 lines

ret = le32_to_cpu(cdesc->status);
When the device reports failure (0xffffffff), ret becomes -1, which is -EPERM. That value then propagates up through eea_adminq_exec() into eea_netdev_init_features() and ultimately out of probe. Should the device's protocol-level error be translated to a more appropriate kernel errno such as -EIO before being returned to the generic layers, given that the wire protocol defines only EEA_OK and EEA_ERR rather than a kernel errno space?

Regarding the status design, we fully align with the standard Linux kernel error codes; therefore, the value returned here is actually -EIO.

Quoted 76 lines

[ ... ]

Quoted 48 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +48 -0
+int eea_create_adminq(struct eea_net *enet, u32 qid)
+{
+	u32 db_size, q_size, num;
+	struct eea_ring *ering;
+	struct eea_aq *aq;
+	int err = -ENOMEM;
+
+	num = enet->edev->rx_num + enet->edev->tx_num;
+	aq = &enet->adminq;
+
+	ering = eea_ering_alloc(qid, 64, enet->edev, sizeof(struct eea_aq_desc),
+				sizeof(struct eea_aq_cdesc), "adminq");
+	if (!ering)
+		return -ENOMEM;
+
+	aq->ring = ering;
+
+	err = eea_pci_active_aq(ering, qid / 2 + 1);
+	if (err)
+		goto err;
+
+	aq->phase = BIT(7);
+	aq->num = 0;
+
+	q_size = sizeof(*aq->q_req_buf) * num;
+	db_size = sizeof(*aq->q_res_buf) * num;
+
+	aq->q_req_size = q_size;
+	aq->q_res_size = db_size;
+
+	err = -ENOMEM;
+
+	aq->q_req_buf = kzalloc(q_size, GFP_KERNEL);
+	if (!aq->q_req_buf)
+		goto err;
+
+	aq->q_res_buf = kzalloc(db_size, GFP_KERNEL);
+	if (!aq->q_res_buf)
+		goto err;
+
+	/* Before we set up the AQ, the device remains in an inactive state, so
+	 * there will be no DMA operations. If the 'set up AQ' process fails, we
+	 * can safely free the DMA-related memory.
+	 */
+	err = eea_pci_set_aq_up(enet->edev);
+	if (err)
+		goto err;
+

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 321

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +10 -0
+	aq->broken = false;
+
+	mutex_init(&aq->lock);
+
+	return 0;
+
+err:
+	eea_destroy_adminq(enet);
+	return err;
+}

By the time eea_pci_set_aq_up() is called, eea_pci_active_aq() has already programmed the SQ/CQ DMA addresses into the device registers and eea_pci_set_aq_up() has signalled EEA_S_OK. If the read_poll_timeout() inside eea_pci_set_aq_up() times out, can the device be assumed to still be quiescent?
The err: label here jumps directly to eea_destroy_adminq(), which calls eea_ering_free() -> dma_free_coherent() without first calling eea_device_reset(). Every other teardown site in this commit resets first, for example eea_adminq_destroy_all_q():

  if (err) {
      /* The device must be reset before unmapping buffers to avoid
       * potential DMA writes after the memory is freed.
       */
      mutex_lock(&enet->adminq.lock);
      eea_device_broken(enet);
      mutex_unlock(&enet->adminq.lock);
      ...
Quoted 11 lines

}
and eea_adminq_submit()'s timeout path (via eea_device_broken()), and the err_reset_dev label in eea_net_probe(). Should this err: label also call eea_device_reset(enet->edev) before eea_destroy_adminq() to avoid a DMA-after-free window into the freed SQ/CQ rings? mutex_init(&aq->lock) is called only after the last goto err point, and eea_destroy_adminq() never calls mutex_destroy() on it. Should eea_destroy_adminq() pair the init with mutex_destroy(), and should mutex_init() move earlier so the lock is always initialised on the teardown path?
[ ... ]

Since this is still during the initialization process, a mutex is not required. Furthermore, even if EEA_S_OK has been signaled to the device, it is still safe to proceed with the release if the device times out for some reason. The AdminQ is entirely driven by the driver side; the device will not read or write to the rings until the driver issues a request via the doorbell.

Quoted 41 lines
Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +6 -0
+void eea_adminq_config_host_info(struct eea_net *enet)
+{
+	struct device *dev = enet->edev->dma_dev;
+	struct eea_aq_host_info_cfg *cfg;
+	struct eea_aq_host_info_rep *rep;
+	int rc = -ENOMEM;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 507

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +11 -0
+	cfg->os_type            = cpu_to_le16(EEA_OS_LINUX);
+	cfg->os_dist            = cpu_to_le16(EEA_OS_DISTRO);
+	cfg->drv_type           = cpu_to_le16(EEA_DRV_TYPE);
+
+	cfg->kern_ver_major     = cpu_to_le16(LINUX_VERSION_MAJOR);
+	cfg->kern_ver_minor     = cpu_to_le16(LINUX_VERSION_PATCHLEVEL);
+	cfg->kern_ver_sub_minor = cpu_to_le16(LINUX_VERSION_SUBLEVEL);
+
+	cfg->drv_ver_major      = cpu_to_le16(EEA_VER_MAJOR);
+	cfg->drv_ver_minor      = cpu_to_le16(EEA_VER_MINOR);
+	cfg->drv_ver_sub_minor  = cpu_to_le16(EEA_VER_SUB_MINOR);

The driver carries a private version triplet (EEA_VER_MAJOR/MINOR/ SUB_MINOR = 1.0.0) and reports it to the device. For an upstream driver, the canonical version is the kernel version itself; private driver version numbers tend to fall out of date and have historically been pushed back on by netdev maintainers.
Could this field be dropped, or derived from the kernel version, rather than freezing 1.0.0 into the device-side ABI?

drivers/net/ethernet/alibaba/eea/eea_adminq.c line 516

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +9 -0
+
+	cfg->spec_ver_major     = cpu_to_le16(EEA_SPEC_VER_MAJOR);
+	cfg->spec_ver_minor     = cpu_to_le16(EEA_SPEC_VER_MINOR);
+
+	cfg->pci_bdf            = cpu_to_le16(eea_pci_bdf(enet->edev));
+	cfg->pci_domain         = cpu_to_le32(eea_pci_domain_nr(enet->edev));
+
+	strscpy(cfg->os_ver_str, utsname()->release, sizeof(cfg->os_ver_str));
+	strscpy(cfg->isa_str, utsname()->machine, sizeof(cfg->isa_str));

On every probe the driver unconditionally sends utsname()->release, utsname()->machine, the full Linux kernel version, os_dist, drv_type, the PCI BDF and PCI domain to the device. The kernel release string is set by distros and can include build identifiers.
Could the commit message explain what the firmware does with these strings, and is there a reason this needs to be unconditional rather than gated on a module parameter or kernel option?

Quoted 8 lines

EEA_OS_DISTRO and EEA_DRV_TYPE are both hardcoded to 0 with no documented enumeration of valid values. Together with EEA_OS_LINUX=1, these become part of the wire ABI introduced in this commit. If these fields are intended to grow (for example to distinguish upstream vs out-of-tree builds, or kernel module vs userspace consumers), can the meaning of value 0 and the reserved range be documented now? If they are not needed, can they be removed before firmware ships against this layout?

Regarding the EEA_OS_DISTRO, EEA_DRV_TYPE, and the version triplet (EEA_VER_MAJOR/MINOR/SUB_MINOR), these are already part of our maintenance plan, and this has been previously discussed in our email thread; please disregard these concerns for now.

To elaborate: unlike standard physical NICs delivered directly to customers, our cloud NICs operate within our own cloud environment. Based on our operational experience, we can implement hardware-based mitigations if a specific driver version is known to have bugs. By reporting the kernel and driver versions to the device, the hardware can identify problematic driver versions and apply workarounds or fallback mechanisms to ensure at least basic functionality, rather than failing entirely. This is a critical design requirement for our cloud infrastructure.

Quoted 29 lines
Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_adminq.c new file +3 -0
+
+	rc = eea_adminq_exec(enet, EEA_AQ_CMD_HOST_INFO,
+			     cfg, sizeof(*cfg), rep, sizeof(*rep), NULL);

[ ... ]

Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +0 -0
new file mode 100644
index 000000000000..bb8a49f8c6df

[ ... ]

Quoted 7 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +7 -0
+static int eea_netdev_init_features(struct net_device *netdev,
+				    struct eea_net *enet,
+				    struct eea_device *edev)
+{
+	struct eea_aq_cfg *cfg;
+	int err;
+	u32 mtu;

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_net.c line 144

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +9 -0
+	netdev->min_mtu = ETH_MIN_MTU;
+
+	netdev->mtu = mtu;
+
+	/* If jumbo frames are already enabled, then the returned MTU will be a
+	 * jumbo MTU, and the driver will automatically enable jumbo frame
+	 * support by default.
+	 */
+	netdev->max_mtu = mtu;

netdev->max_mtu is set to the same value as netdev->mtu, where mtu came from cfg->mtu in the device's reply to EEA_AQ_CMD_CFG_QUERY.

Quoted 8 lines

The eea_aq_cfg structure has only a single __le16 mtu field and no separate maximum, and the comment above describes mtu as the current configured MTU rather than the device-supported maximum. With max_mtu == mtu, can a user ever raise the MTU above the value the device happened to advertise at probe time via "ip link set dev X mtu N"? Should the wire ABI being introduced here grow a separate mtu_max field, or should the driver derive a maximum (for example a fixed jumbo cap) for max_mtu?

The MTU value here represents the maximum MTU. We default to providing the user with the largest possible MTU. In network environments that do not support jumbo frames, we will not return a jumbo MTU; however, if the network environment does support it, we enable it by default so the user's NIC can utilize its full capacity.

Quoted 32 lines
Quoted 5 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +5 -0
+
+err_free:
+	kfree(cfg);
+	return err;
+}

[ ... ]

Quoted 16 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +16 -0
+int eea_net_probe(struct eea_device *edev)
+{
+	struct eea_net *enet;
+	int err = -ENOMEM;
+
+	enet = eea_netdev_alloc(edev, edev->rx_num);
+	if (!enet)
+		return -ENOMEM;
+
+	err = eea_create_adminq(enet, edev->rx_num + edev->tx_num);
+	if (err)
+		goto err_free_netdev;
+
+	eea_adminq_config_host_info(enet);
+
+	err = eea_netdev_init_features(enet->netdev, enet, edev);

drivers/net/ethernet/alibaba/eea/eea_net.c line 204

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +10 -0
+	if (err)
+		goto err_reset_dev;
+
+	netdev_dbg(enet->netdev, "eea probe success.\n");
+
+	/* Queue TX/RX implementation is still in progress. register_netdev is
+	 * deferred until these are completed in subsequent commits.
+	 */
+
+	return 0;
Quoted 8 lines

After this commit, eea_net_probe() returns success without calling register_netdev(). A bisect that lands exactly on this commit will see a probed PCI driver that has consumed IRQs and DMA buffers and already issued the HOST_INFO admin command to firmware, but no netdev visible to userspace.
Could this patch be squashed with the later patches that complete the TX/RX paths and call register_netdev(), so a bisected kernel either has a working interface or no driver activation at all?

The RX and TX paths, along with several other features, are not yet fully implemented. Enabling the netdev prematurely would likely lead to functional issues. The code is structured in separate patches to facilitate the review process. Furthermore, since the netdev will be registered within this same patch series, this is not a concern.

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c new file +9 -0
+
+err_reset_dev:
+	eea_device_reset(edev);
+	eea_destroy_adminq(enet);
+
+err_free_netdev:
+	free_netdev(enet->netdev);
+	return err;
+}
author maintainer
#9 lore raw

PATCH v43 4/8 eea: create/destroy rx,tx queues for netdevice open and stop

In reply to Xuan Zhuo

Add basic driver framework for the Alibaba Elastic Ethernet Adapter(EEA).

This commit introduces the implementation for the netdevice open and stop.

This commit introduces HA to restore the device when error occurs, but in HA scenarios the driver can't ensure to restore the status correctly.

---
 drivers/net/ethernet/alibaba/eea/Makefile  |   4 +-
 drivers/net/ethernet/alibaba/eea/eea_net.c | 563 ++++++++++++++++++++-
 drivers/net/ethernet/alibaba/eea/eea_net.h |  50 +-
 drivers/net/ethernet/alibaba/eea/eea_pci.c | 244 ++++++++-
 drivers/net/ethernet/alibaba/eea/eea_pci.h |  20 +
 drivers/net/ethernet/alibaba/eea/eea_rx.c  | 264 ++++++++++
 drivers/net/ethernet/alibaba/eea/eea_tx.c  | 102 ++++
 7 files changed, 1231 insertions(+), 16 deletions(-)
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_rx.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_tx.c
drivers/net/ethernet/alibaba/eea/Makefile +3 -1
index a842ac416ae8..5f0961002e57 100644
@@ -3,4 +3,6 @@ obj-$(CONFIG_ALIBABA_EEA) += eea.o
 eea-y := eea_ring.o \
 	eea_net.o \
 	eea_pci.o \
-	eea_adminq.o
+	eea_adminq.o \
+	eea_tx.o \
+	eea_rx.o
drivers/net/ethernet/alibaba/eea/eea_net.c +556 -7

619 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_net.h +47 -3

83 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_pci.c +239 -5

343 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_pci.h +20 -0
index cfd278e2efde..6f6ba7d5514d 100644
@@ -10,8 +10,18 @@
 
 #include <linux/pci.h>
 
+#include "eea_net.h"
 #include "eea_ring.h"
 
+enum eea_pci_status {
+	EEA_PCI_STATUS_NONE,
+	EEA_PCI_STATUS_ERR,
+	EEA_PCI_STATUS_READY,
+	EEA_PCI_STATUS_DONE,
+};
+
+struct eea_irq_blk;
+
 struct eea_pci_cap {
 	__u8 cap_vndr;
 	__u8 cap_next;
@@ -34,6 +44,12 @@ struct eea_device {
 
 	u64 features;
 
+	enum eea_pci_status status;
+	bool ha_reset_netdev_running;
+
+	/* ha lock for the race between ha work and pci remove */
+	struct mutex ha_lock;
+
 	u32 rx_num;
 	u32 tx_num;
 	u32 db_blk_size;
@@ -47,6 +63,10 @@ int eea_device_reset(struct eea_device *dev);
 int eea_pci_set_aq_up(struct eea_device *dev);
 int eea_pci_active_aq(struct eea_ring *ering, int msix_vec);
 
+int eea_pci_request_irq(struct eea_device *edev, struct eea_irq_blk *blk,
+			irqreturn_t (*callback)(int irq, void *data));
+void eea_pci_free_irq(struct eea_irq_blk *blk);
+
 u64 eea_pci_device_ts(struct eea_device *edev);
 
 void __iomem *eea_pci_db_addr(struct eea_device *edev, u32 off);
drivers/net/ethernet/alibaba/eea/eea_rx.c new file +264 -0

264 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_tx.c new file +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#10 lore raw

Re: [PATCH net-next v43 4/8] eea: create/destroy rx,tx queues for netdevice open and stop

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +0 -0
index bb8a49f8c6df..cfb18a07e296 100644

[ ... ]

Quoted 30 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +30 -0
+/* resources: ring, buffers, irq */
+int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx)
+{
+	struct eea_net_init_ctx ctx_old = {0};
+	int err, error;
+
+	if (!netif_running(enet->netdev) || !enet->started) {
+		enet->cfg = ctx->cfg;
+		return 0;
+	}
+
+	err = eea_alloc_rxtx_q_mem(ctx);
+	if (err) {
+		netdev_warn(enet->netdev,
+			    "eea reset: alloc q failed. stop reset. err %d\n",
+			    err);
+		return err;
+	}
+
+	eea_stop_rxtx(enet->netdev);
+	eea_hw_unactive_ring(enet);
+
+	eea_unbind_q_and_cfg(enet, &ctx_old);
+	eea_bind_q_and_cfg(enet, ctx);
+
+	err = eea_update_queues(enet);
+	if (err) {
+		netdev_err(enet->netdev,
+			   "eea reset: set real num queues failed. err %d\n",
+			   err);

drivers/net/ethernet/alibaba/eea/eea_net.c line 384

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +10 -0
+		goto err_bind_old;
+	}
+
+	err = eea_hw_active_ring(enet);
+	if (err) {
+		netdev_err(enet->netdev, "eea reset: active new ring. err %d\n",
+			   err);
+		eea_unbind_q_and_cfg(enet, ctx);
+		goto err_free_q;
+	}

On the eea_hw_active_ring() failure branch above, can the netdev be left with mismatched cached state?
The sequence executed by then is:

    eea_unbind_q_and_cfg(enet, &ctx_old);   /* saves OLD cfg into ctx_old */
    eea_bind_q_and_cfg(enet, ctx);          /* enet->cfg = ctx->cfg (NEW) */
    err = eea_update_queues(enet);          /* sets real_num_{rx,tx}_queues

to NEW values, succeeded */
err = eea_hw_active_ring(enet); /* failed */
eea_unbind_q_and_cfg(enet, ctx);
goto err_free_q;
err_free_q then sets enet->started = false but never restores enet->cfg or netdev->real_num_{rx,tx}_queues to the old values, and eea_unbind_q_and_cfg() only nulls enet->rx / enet->tx without reverting cfg.
Looking at eea_unbind_q_and_cfg():

    ctx->cfg = enet->cfg;
    ctx->rx = enet->rx;
    ctx->tx = enet->tx;
    enet->rx = NULL;
    enet->tx = NULL;

If the user later calls ndo_open, eea_netdev_open() reads enet->cfg which still holds the NEW values that the device just rejected. Was a rollback to ctx_old intended on this path as well, similar to the err_bind_old branch?
[ ... ]

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +3 -0
+static void eea_net_ha_reset_remove(struct eea_net *enet,
+				    struct eea_device *edev)
+{

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +0 -0
index fa0eec8af21b..9639f0c5c618 100644

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_net.h struct eea_net { · line 169

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +3 -0
+/* rx apis */
+void enet_rx_stop(struct eea_net_rx *rx);
+void enet_rx_start(struct eea_net_rx *rx);

Every other symbol in this driver uses the eea_ prefix, but enet_rx_start / enet_rx_stop use enet_. Was the inconsistency intentional, or should these be renamed to eea_rx_start / eea_rx_stop for consistency with the rest of the eea_ namespace?

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +3 -0
+
+void eea_free_rx(struct eea_net_rx *rx, struct eea_net_cfg *cfg);
+struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx);

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +0 -0
index bef0ebd6bb20..9872e360dd5d 100644

[ ... ]

Quoted 2 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +2 -0
+static void eea_ha_handle_reset(struct eea_pci_device *ep_dev)
+{

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_pci.c int eea_pci_active_aq(struct eea_ring *ering, int msix_vec) · line 439

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +10 -0
+	if (reset & EEA_PCI_CAP_RESET_FLAG) {
+		dev_warn(&ep_dev->pci_dev->dev, "recv device reset request.\n");
+
+		pci_dev = ep_dev->pci_dev;
+
+		/* The pci remove callback may hold this lock. If the
+		 * pci remove callback is called, then we can ignore the
+		 * ha interrupt.
+		 */
+		if (mutex_trylock(&edev->ha_lock)) {

Is the mutex_trylock() with a silent-skip fallback below the right pattern here?

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +11 -0
+			if (edev->status != EEA_PCI_STATUS_DONE) {
+				dev_err(&ep_dev->pci_dev->dev, "ha: reset device: pci status is %d. skip it.\n",
+					edev->status);
+
+				mutex_unlock(&edev->ha_lock);
+				return;
+			}
+
+			__eea_pci_remove(pci_dev, false);
+			err = __eea_pci_probe(pci_dev, ep_dev, false);
+			if (err)

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_pci.c int eea_pci_active_aq(struct eea_ring *ering, int msix_vec) · line 467

Quoted 8 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +8 -0
+			mutex_unlock(&edev->ha_lock);
+		} else {
+			/* Device removal is in progress, so return directly. */
+			dev_warn(&ep_dev->pci_dev->dev,
+				 "ha device reset: trylock failed.\n");
+		}
+		return;
+	}

When the trylock fails, the work simply logs a warning and returns without rescheduling. The networking subsystem guidance lists this specific pattern (trylock with fallback to skip the work entirely) as a likely bug, with the narrow exception of work items that retry via schedule_work() on failure.
The trylock also fails for any holder of ha_lock, not only pci remove, so a HA reset request that arrives during any concurrent holder is dropped silently and the device is left without recovery. Would it be more appropriate to either reschedule the work via schedule_work() on trylock failure, or to redesign the locking so that the remove path coordinates with the worker via cancel/flush rather than a shared mutex that the worker must avoid?
[ ... ]

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +3 -0
+static int eea_pci_ha_init(struct eea_device *edev, struct pci_dev *pci_dev,
+			   bool pci_probe)
+{

[ ... ]

Quoted 14 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +13 -0
+static int eea_net_reprobe(struct eea_device *edev)
+{
+	struct eea_net *enet = edev->enet;
+	int err = 0;
+
+	enet->edev = edev;
+
+	if (!enet->adminq.ring) {
+		err = eea_create_adminq(enet, edev->rx_num + edev->tx_num);
+		if (err)
+			return err;
+	}
+

drivers/net/ethernet/alibaba/eea/eea_net.c static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs) · line 667

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +10 -0
+	err = eea_alloc_irq_blks(enet);
+	if (err)
+		goto err_destroy_aq;
+
+	rtnl_lock();
+
+	enet->link_err = 0;
+	if (edev->ha_reset_netdev_running &&
+	    netif_running(edev->enet->netdev)) {
+		err = eea_netdev_open(enet->netdev);

On the HA reprobe path, can edev->rx_num change relative to the value used at original probe?
eea_pci_setup() re-reads rx_num/tx_num from device registers each time, and eea_alloc_irq_blks() sizes enet->irq_blks based on the new edev->rx_num:

    num = enet->edev->rx_num;
    irq_blks = kvcalloc(num, sizeof(*blk), GFP_KERNEL);

However, the netdev itself was allocated once with alloc_etherdev_mq(..., pairs) using the original count, and enet->cfg.rx_ring_num is preserved from the previous probe. If the device reports a smaller rx_num after the HA reset, eea_bind_q_and_cfg() will iterate enet->cfg.rx_ring_num entries (OLD) over enet->irq_blks[] (NEW, smaller):

    for (i = 0; i < ctx->cfg.rx_ring_num; i++) {
        blk = &enet->irq_blks[i];
        ...
    }

Should eea_net_reprobe() validate that edev->rx_num and edev->tx_num match the values used at the original alloc_etherdev_mq() and refuse to reprobe (or reinitialise cfg) if they have changed? [ ... ]

author maintainer
#11 lore raw

Re: [PATCH net-next v43 4/8] eea: create/destroy rx,tx queues for netdevice open and stop

Quoted 65 lines · Xuan Zhuo
Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +0 -0
index bb8a49f8c6df..cfb18a07e296 100644

[ ... ]

Quoted 30 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +30 -0
+/* resources: ring, buffers, irq */
+int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx)
+{
+	struct eea_net_init_ctx ctx_old = {0};
+	int err, error;
+
+	if (!netif_running(enet->netdev) || !enet->started) {
+		enet->cfg = ctx->cfg;
+		return 0;
+	}
+
+	err = eea_alloc_rxtx_q_mem(ctx);
+	if (err) {
+		netdev_warn(enet->netdev,
+			    "eea reset: alloc q failed. stop reset. err %d\n",
+			    err);
+		return err;
+	}
+
+	eea_stop_rxtx(enet->netdev);
+	eea_hw_unactive_ring(enet);
+
+	eea_unbind_q_and_cfg(enet, &ctx_old);
+	eea_bind_q_and_cfg(enet, ctx);
+
+	err = eea_update_queues(enet);
+	if (err) {
+		netdev_err(enet->netdev,
+			   "eea reset: set real num queues failed. err %d\n",
+			   err);

drivers/net/ethernet/alibaba/eea/eea_net.c line 384

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +10 -0
+		goto err_bind_old;
+	}
+
+	err = eea_hw_active_ring(enet);
+	if (err) {
+		netdev_err(enet->netdev, "eea reset: active new ring. err %d\n",
+			   err);
+		eea_unbind_q_and_cfg(enet, ctx);
+		goto err_free_q;
+	}

On the eea_hw_active_ring() failure branch above, can the netdev be left with mismatched cached state?
The sequence executed by then is:

    eea_unbind_q_and_cfg(enet, &ctx_old);   /* saves OLD cfg into ctx_old */
    eea_bind_q_and_cfg(enet, ctx);          /* enet->cfg = ctx->cfg (NEW) */
    err = eea_update_queues(enet);          /* sets real_num_{rx,tx}_queues

to NEW values, succeeded */
err = eea_hw_active_ring(enet); /* failed */
eea_unbind_q_and_cfg(enet, ctx);
goto err_free_q;
err_free_q then sets enet->started = false but never restores enet->cfg or netdev->real_num_{rx,tx}_queues to the old values, and eea_unbind_q_and_cfg() only nulls enet->rx / enet->tx without reverting cfg.
Looking at eea_unbind_q_and_cfg():

    ctx->cfg = enet->cfg;
    ctx->rx = enet->rx;
    ctx->tx = enet->tx;
    enet->rx = NULL;
    enet->tx = NULL;
Quoted 4 lines

If the user later calls ndo_open, eea_netdev_open() reads enet->cfg which still holds the NEW values that the device just rejected. Was a rollback to ctx_old intended on this path as well, similar to the err_bind_old branch?

All configurations that reach this point are additive in nature. The failure to apply them to the hardware does not imply that the configuration itself is invalid; rather, it is typically due to hardware issues or memory allocation failures. Therefore, we retain the configuration with the expectation that it may be successfully applied upon the next attempt.

Quoted 10 lines

[ ... ]

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +3 -0
+static void eea_net_ha_reset_remove(struct eea_net *enet,
+				    struct eea_device *edev)
+{

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +0 -0
index fa0eec8af21b..9639f0c5c618 100644

[ ... ]

Quoted 7 lines

drivers/net/ethernet/alibaba/eea/eea_net.h struct eea_net { · line 169

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +3 -0
+/* rx apis */
+void enet_rx_stop(struct eea_net_rx *rx);
+void enet_rx_start(struct eea_net_rx *rx);

Every other symbol in this driver uses the eea_ prefix, but enet_rx_start / enet_rx_stop use enet_. Was the inconsistency intentional, or should these be renamed to eea_rx_start / eea_rx_stop for consistency with the rest of the eea_ namespace?

The enet prefix indicates that this code is not part of the PCI or adminq layers, but is specifically used for eea netdev handling.

Quoted 48 lines
Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_net.h +3 -0
+
+void eea_free_rx(struct eea_net_rx *rx, struct eea_net_cfg *cfg);
+struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx);

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +0 -0
index bef0ebd6bb20..9872e360dd5d 100644

[ ... ]

Quoted 2 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +2 -0
+static void eea_ha_handle_reset(struct eea_pci_device *ep_dev)
+{

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_pci.c int eea_pci_active_aq(struct eea_ring *ering, int msix_vec) · line 439

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +10 -0
+	if (reset & EEA_PCI_CAP_RESET_FLAG) {
+		dev_warn(&ep_dev->pci_dev->dev, "recv device reset request.\n");
+
+		pci_dev = ep_dev->pci_dev;
+
+		/* The pci remove callback may hold this lock. If the
+		 * pci remove callback is called, then we can ignore the
+		 * ha interrupt.
+		 */
+		if (mutex_trylock(&edev->ha_lock)) {

Is the mutex_trylock() with a silent-skip fallback below the right pattern here?

Quoted 11 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +11 -0
+			if (edev->status != EEA_PCI_STATUS_DONE) {
+				dev_err(&ep_dev->pci_dev->dev, "ha: reset device: pci status is %d. skip it.\n",
+					edev->status);
+
+				mutex_unlock(&edev->ha_lock);
+				return;
+			}
+
+			__eea_pci_remove(pci_dev, false);
+			err = __eea_pci_probe(pci_dev, ep_dev, false);
+			if (err)

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_pci.c int eea_pci_active_aq(struct eea_ring *ering, int msix_vec) · line 467

Quoted 8 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +8 -0
+			mutex_unlock(&edev->ha_lock);
+		} else {
+			/* Device removal is in progress, so return directly. */
+			dev_warn(&ep_dev->pci_dev->dev,
+				 "ha device reset: trylock failed.\n");
+		}
+		return;
+	}

When the trylock fails, the work simply logs a warning and returns without rescheduling. The networking subsystem guidance lists this specific pattern (trylock with fallback to skip the work entirely) as a likely bug, with the narrow exception of work items that retry via

Quoted 8 lines

schedule_work() on failure.
The trylock also fails for any holder of ha_lock, not only pci remove, so a HA reset request that arrives during any concurrent holder is dropped silently and the device is left without recovery. Would it be more appropriate to either reschedule the work via schedule_work() on trylock failure, or to redesign the locking so that the remove path coordinates with the worker via cancel/flush rather than a shared mutex that the worker must avoid?

If the system has already entered the PCI remove path, the HA work is no longer necessary, so returning directly after mutex_trylock failure is correct behavior. Furthermore, our design guarantees that an HA interrupt will not be triggered again until the current one is fully processed. If the hardware were to encounter such a demand (i.e., multiple concurrent HA requests), our design strategy is to let the hardware stop functioning entirely rather than attempting to recover again.

Quoted 23 lines

[ ... ]

Quoted 3 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c +3 -0
+static int eea_pci_ha_init(struct eea_device *edev, struct pci_dev *pci_dev,
+			   bool pci_probe)
+{

[ ... ]

Quoted 18 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +17 -0
+static int eea_net_reprobe(struct eea_device *edev)
+{
+	struct eea_net *enet = edev->enet;
+	int err = 0;
+
+	enet->edev = edev;
+
+	if (!enet->adminq.ring) {
+		err = eea_create_adminq(enet, edev->rx_num + edev->tx_num);
+		if (err)
+			return err;
+	}
+
+	err = eea_alloc_irq_blks(enet);
+	if (err)
+		goto err_destroy_aq;
+
Quoted 8 lines

drivers/net/ethernet/alibaba/eea/eea_net.c static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs) · line 667

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +6 -0
+	rtnl_lock();
+
+	enet->link_err = 0;
+	if (edev->ha_reset_netdev_running &&
+	    netif_running(edev->enet->netdev)) {
+		err = eea_netdev_open(enet->netdev);

On the HA reprobe path, can edev->rx_num change relative to the value used at original probe?

This won't happen. According to our hardware design specification, the device parameters (including rx_num and tx_num) are guaranteed to remain constant throughout the entire HA reset process. Therefore, we don't need to perform an explicit validation check for these values during eea_net_reprobe().

author maintainer
#12 lore raw

PATCH v43 5/8 eea: implement packet receive logic

In reply to Xuan Zhuo

Implement the core logic for receiving packets in the EEA RX path, including packet buffering and basic validation.

---
 drivers/net/ethernet/alibaba/eea/eea_net.c |  13 +
 drivers/net/ethernet/alibaba/eea/eea_net.h |   7 +
 drivers/net/ethernet/alibaba/eea/eea_rx.c  | 532 ++++++++++++++++++++-
 3 files changed, 550 insertions(+), 2 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_net.c +13 -0
index cfb18a07e296..bf8581bc27ed 100644
@@ -642,6 +642,15 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
 	return enet;
 }
 
+static void eea_update_ts_off(struct eea_device *edev, struct eea_net *enet)
+{
+	u64 ts;
+
+	ts = eea_pci_device_ts(edev);
+
+	enet->hw_ts_offset = ktime_get_real() - ts;
+}
+
 static int eea_net_reprobe(struct eea_device *edev)
 {
 	struct eea_net *enet = edev->enet;
@@ -659,6 +668,8 @@ static int eea_net_reprobe(struct eea_device *edev)
 	if (err)
 		goto err_destroy_aq;
 
+	eea_update_ts_off(edev, enet);
+
 	rtnl_lock();
 
 	enet->link_err = 0;
@@ -711,6 +722,8 @@ int eea_net_probe(struct eea_device *edev)
 	if (err)
 		goto err_reset_dev;
 
+	eea_update_ts_off(edev, enet);
+
 	netdev_dbg(enet->netdev, "eea probe success.\n");
 
 	/* Queue TX/RX implementation is still in progress. register_netdev is
drivers/net/ethernet/alibaba/eea/eea_net.h +7 -0
index 9639f0c5c618..1ff9ef1a8fbe 100644
@@ -41,6 +41,7 @@ struct eea_rx_meta {
 	struct page *page;
 	dma_addr_t dma;
 	u32 offset;
+	u32 sync_for_cpu;
 	u32 frags;
 
 	struct page *hdr_page;
@@ -54,6 +55,8 @@ struct eea_rx_meta {
 	u32 tailroom;
 
 	u32 len;
+
+	bool in_use;
 };
 
 struct eea_net_rx_pkt_ctx {
@@ -62,6 +65,7 @@ struct eea_net_rx_pkt_ctx {
 	bool data_valid;
 	bool do_drop;
 
+	u32 recv_len;
 	struct sk_buff *head_skb;
 };
 
@@ -154,6 +158,8 @@ struct eea_net {
 
 	u8 duplex;
 	u32 speed;
+
+	u64 hw_ts_offset;
 };
 
 int eea_net_probe(struct eea_device *edev);
@@ -165,6 +171,7 @@ void eea_init_ctx(struct eea_net *enet, struct eea_net_init_ctx *ctx);
 int eea_queues_check_and_reset(struct eea_device *edev);
 
 /* rx apis */
+
 void enet_rx_stop(struct eea_net_rx *rx);
 void enet_rx_start(struct eea_net_rx *rx);
 
drivers/net/ethernet/alibaba/eea/eea_rx.c +530 -2

559 lines not on this page · raw message

Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#13 lore raw

Re: [PATCH net-next v43 5/8] eea: implement packet receive logic

From sashiko:

commit 142959c3285196e5751c147c32a4a954a804d736
Author: Xuan Zhuo <[email protected]>
eea: implement packet receive logic
This commit implements the EEA RX path: page-pool buffer management, per-descriptor metadata handling, packet assembly via build_skb()/ napi_alloc_skb(), and submission through napi_gro_receive(). It also introduces a one-shot hardware-timestamp offset captured at probe time.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +0 -0
index cfb18a07e296..bf8581bc27ed 100644
@@ -642,6 +642,15 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
 	return enet;

drivers/net/ethernet/alibaba/eea/eea_net.c static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs) · line 652

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +8 -0
 }
 
+static void eea_update_ts_off(struct eea_device *edev, struct eea_net *enet)
+{
+	u64 ts;
+
+	ts = eea_pci_device_ts(edev);
+
+	enet->hw_ts_offset = ktime_get_real() - ts;
+}

Is the choice of ktime_get_real() as the anchor for hardware RX timestamps intentional?
Consumers of skb_hwtstamps()->hwtstamp typically expect a stable monotonic timeline; tying the offset to CLOCK_REALTIME means any later settimeofday(), NTP step, leap-second adjustment, or a probe that happens before NTP sync will permanently bias every reported hwtstamp. There is also no ptp_clock_register()/PHC and no periodic resync, so the offset captured here is the one used forever.
Is the capture itself meant to be atomic with respect to scheduling?

	ts = eea_pci_device_ts(edev);
	enet->hw_ts_offset = ktime_get_real() - ts;

eea_pci_device_ts() performs an MMIO read across PCIe and is then followed by ktime_get_real() with no preempt/IRQ disabling, so any transit or preemption delay between the two reads is permanently baked into hw_ts_offset for the lifetime of the device. Does this code handle 48-bit wraparound of the device timestamp counter?
EEA_DESC_TS(desc) masks desc->ts to 48 bits via EEA_DESC_TS_MASK = GENMASK_ULL(47, 0), and hw_ts_offset is taken exactly once here at probe/reprobe. After roughly 3.26 days of device uptime (2^48 ns) the per-packet computation EEA_DESC_TS(desc) + enet->hw_ts_offset will jump backwards by ~2^48 ns relative to wall time, with no wrap detector, no resync, and no cyclecounter/timecounter wrapper.
There is also a width inconsistency between this capture and the per-packet path:

drivers/net/ethernet/alibaba/eea/eea_pci.c:eea_pci_device_ts() {
    return cfg_read64(ep_dev->reg, hw_ts);
}

returns the full 64-bit register, while EEA_DESC_TS(desc) masks the descriptor field to 48 bits. If bits 48..63 of the hw_ts register are ever non-zero, every reported hwtstamp would be off by at least 2^48 ns.

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +2 -0
@@ -711,6 +722,8 @@ int eea_net_probe(struct eea_device *edev)
 	if (err)
 		goto err_reset_dev;
 
+	eea_update_ts_off(edev, enet);
+
 	netdev_dbg(enet->netdev, "eea probe success.\n");
 
 	/* Queue TX/RX implementation is still in progress. register_netdev is

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +0 -0
index b1265048fbc3..9c71a7cf950e 100644

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 388

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +9 -0
+static void process_first_buf(struct eea_net_rx *rx, struct eea_rx_ctx *ctx)
+{
+	struct eea_net *enet = rx->enet;
+	struct sk_buff *skb = NULL;
+
+	if (eea_harden_check_size(ctx, enet))
+		goto err;
+
+	rx->pkt.data_valid = ctx->flags & EEA_DESC_F_DATA_VALID;

Is the EEA_DESC_F_DATA_VALID bit (the source of CHECKSUM_UNNECESSARY) meant to be sampled only on the first descriptor of a multi-descriptor packet?
process_first_buf() is the only place rx->pkt.data_valid is assigned, and process_remain_buf() does not touch it. Meanwhile in eea_submit_skb() the timestamp comes from the EOP descriptor:

    if (rx->pkt.data_valid)
        skb->ip_summed = CHECKSUM_UNNECESSARY;
    if (enet->cfg.ts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
        skb_hwtstamps(skb)->hwtstamp = EEA_DESC_TS(desc) +
            enet->hw_ts_offset;

If the device places per-packet metadata on the EOP descriptor (a common NIC layout), every multi-segment frame would silently fall back to CHECKSUM_NONE. Could the descriptor used for the checksum flag and for the timestamp be documented or made consistent?

Quoted 18 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +18 -0
+
+	if (ctx->hdr_len)
+		skb = eea_rx_build_split_hdr_skb(rx, ctx);
+	else
+		skb = eea_rx_build_skb(rx, ctx);
+
+	if (unlikely(!skb))
+		goto err;
+
+	rx->pkt.head_skb = skb;
+
+	return;
+
+err:
+	rx->pkt.do_drop = true;
+}
+
+static void eea_submit_skb(struct eea_net_rx *rx, struct sk_buff *skb,

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 416

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +10 -0
+			   struct eea_rx_cdesc *desc)
+{
+	struct eea_net *enet = rx->enet;
+
+	if (rx->pkt.data_valid)
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+	if (enet->cfg.ts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
+		skb_hwtstamps(skb)->hwtstamp = EEA_DESC_TS(desc) +
+			enet->hw_ts_offset;

Is the strict equality with HWTSTAMP_FILTER_ALL intentional? The usual driver convention for SIOCSHWTSTAMP is to either reject unsupported filters or upgrade them to ALL, so that consumers requesting more specific filters (PTP_V2_*, NTP_ALL, etc.) still get timestamps on matching frames. With the strict comparison above, anything other than HWTSTAMP_FILTER_ALL yields no timestamps. There is no SIOCSHWTSTAMP setter in this series, so the branch is effectively unreachable today, but it may be worth revisiting together with whatever setter lands later.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +6 -0
+
+	skb_record_rx_queue(skb, rx->index);
+	skb->protocol = eth_type_trans(skb, enet->netdev);
+
+	napi_gro_receive(rx->napi, skb);
+}

[ ... ]

Quoted 17 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +17 -0
+static int eea_cleanrx(struct eea_net_rx *rx, int budget,
+		       struct eea_rx_ctx *ctx)
+{
+	struct eea_rx_cdesc *desc;
+	struct eea_rx_meta *meta;
+	int recv, err;
+
+	for (recv = 0; recv < budget; ) {
+		desc = eea_ering_cq_get_desc(rx->ering);
+		if (!desc)
+			break;
+
+		err = eea_rx_desc_to_ctx(rx, ctx, desc);
+		if (unlikely(err)) {
+			if (ctx->meta)
+				eea_rx_meta_put(rx, ctx->meta);
+

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 496

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +10 -0
+			if (rx->pkt.head_skb)
+				dev_kfree_skb(rx->pkt.head_skb);
+
+			/* A hardware error occurred; we are attempting to
+			 * mitigate the impact. Subsequent packets may be
+			 * corrupted.
+			 */
+			ctx->more = false;
+			goto ack;
+		}

Can this recovery path forward arbitrary mid-payload bytes to the network stack as a fresh L2 frame?
When eea_rx_desc_to_ctx() fails mid-stream (invalid id, or len greater than meta->len), this branch frees rx->pkt.head_skb, forces ctx->more = false, and jumps to ack. The tail of the loop then runs:

    if (!ctx->more) {
        memset(&rx->pkt, 0, sizeof(rx->pkt));
        ++recv;
    }

so no "still inside a device-side packet" indicator survives. The next descriptor from the device — which may be a continuation buffer of the original frame — will be handled by process_first_buf() because rx->pkt.idx == 0. If that continuation satisfies ctx->len >= ETH_HLEN, an skb is built from raw mid-payload bytes and submitted via eth_type_trans()/napi_gro_receive(). Would setting rx->pkt.do_drop = true (and only clearing rx->pkt on the next observed !more) be a safer way to mitigate, given the existing comment already notes "subsequent packets may be corrupted"?

Quoted 34 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +34 -0
+
+		meta = ctx->meta;
+
+		if (unlikely(rx->pkt.do_drop))
+			goto skip;
+
+		eea_rx_meta_dma_sync_for_cpu(rx, meta, ctx->len);
+
+		rx->pkt.recv_len += ctx->len;
+		rx->pkt.recv_len += ctx->hdr_len;
+
+		if (!rx->pkt.idx)
+			process_first_buf(rx, ctx);
+		else
+			process_remain_buf(rx, ctx);
+
+		++rx->pkt.idx;
+
+		if (!ctx->more && rx->pkt.head_skb)
+			eea_submit_skb(rx, rx->pkt.head_skb, desc);
+
+skip:
+		eea_rx_meta_put(rx, meta);
+ack:
+		eea_ering_cq_ack_desc(rx->ering, 1);
+
+		if (!ctx->more) {
+			memset(&rx->pkt, 0, sizeof(rx->pkt));
+			++recv;
+		}
+	}
+
+	return recv;
+}
author maintainer
#14 lore raw

Re: [PATCH net-next v43 5/8] eea: implement packet receive logic

Quoted 52 lines · Xuan Zhuo

From sashiko:

commit 142959c3285196e5751c147c32a4a954a804d736
Author: Xuan Zhuo <[email protected]>
eea: implement packet receive logic
This commit implements the EEA RX path: page-pool buffer management, per-descriptor metadata handling, packet assembly via build_skb()/ napi_alloc_skb(), and submission through napi_gro_receive(). It also introduces a one-shot hardware-timestamp offset captured at probe time.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +0 -0
index cfb18a07e296..bf8581bc27ed 100644
@@ -642,6 +642,15 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
 	return enet;

drivers/net/ethernet/alibaba/eea/eea_net.c static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs) · line 652

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +8 -0
 }
 
+static void eea_update_ts_off(struct eea_device *edev, struct eea_net *enet)
+{
+	u64 ts;
+
+	ts = eea_pci_device_ts(edev);
+
+	enet->hw_ts_offset = ktime_get_real() - ts;
+}

Is the choice of ktime_get_real() as the anchor for hardware RX timestamps intentional?
Consumers of skb_hwtstamps()->hwtstamp typically expect a stable monotonic timeline; tying the offset to CLOCK_REALTIME means any later settimeofday(), NTP step, leap-second adjustment, or a probe that happens before NTP sync will permanently bias every reported hwtstamp. There is also no ptp_clock_register()/PHC and no periodic resync, so the offset captured here is the one used forever.
Is the capture itself meant to be atomic with respect to scheduling?

	ts = eea_pci_device_ts(edev);
	enet->hw_ts_offset = ktime_get_real() - ts;

eea_pci_device_ts() performs an MMIO read across PCIe and is then followed by ktime_get_real() with no preempt/IRQ disabling, so any transit or preemption delay between the two reads is permanently baked into hw_ts_offset for the lifetime of the device. Does this code handle 48-bit wraparound of the device timestamp counter?
EEA_DESC_TS(desc) masks desc->ts to 48 bits via EEA_DESC_TS_MASK = GENMASK_ULL(47, 0), and hw_ts_offset is taken exactly once here at probe/reprobe. After roughly 3.26 days of device uptime (2^48 ns) the per-packet computation EEA_DESC_TS(desc) + enet->hw_ts_offset will jump backwards by ~2^48 ns relative to wall time, with no wrap detector, no resync, and no cyclecounter/timecounter wrapper.
There is also a width inconsistency between this capture and the per-packet path:

Quoted 7 lines
drivers/net/ethernet/alibaba/eea/eea_pci.c:eea_pci_device_ts() {
    return cfg_read64(ep_dev->reg, hw_ts);
}

returns the full 64-bit register, while EEA_DESC_TS(desc) masks the descriptor field to 48 bits. If bits 48..63 of the hw_ts register are ever non-zero, every reported hwtstamp would be off by at least 2^48 ns.

Indeed, this part is currently just a basic architectural framework. I have not included a full PTP implementation in this version, as it is slated for future development. I acknowledge that this implementation is currently incomplete.

Quoted 35 lines
Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_net.c +2 -0
@@ -711,6 +722,8 @@ int eea_net_probe(struct eea_device *edev)
 	if (err)
 		goto err_reset_dev;
 
+	eea_update_ts_off(edev, enet);
+
 	netdev_dbg(enet->netdev, "eea probe success.\n");
 
 	/* Queue TX/RX implementation is still in progress. register_netdev is

[ ... ]

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +0 -0
index b1265048fbc3..9c71a7cf950e 100644

[ ... ]

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 388

Quoted 9 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +9 -0
+static void process_first_buf(struct eea_net_rx *rx, struct eea_rx_ctx *ctx)
+{
+	struct eea_net *enet = rx->enet;
+	struct sk_buff *skb = NULL;
+
+	if (eea_harden_check_size(ctx, enet))
+		goto err;
+
+	rx->pkt.data_valid = ctx->flags & EEA_DESC_F_DATA_VALID;

Is the EEA_DESC_F_DATA_VALID bit (the source of CHECKSUM_UNNECESSARY) meant to be sampled only on the first descriptor of a multi-descriptor packet?
process_first_buf() is the only place rx->pkt.data_valid is assigned, and process_remain_buf() does not touch it. Meanwhile in eea_submit_skb() the timestamp comes from the EOP descriptor:

    if (rx->pkt.data_valid)
        skb->ip_summed = CHECKSUM_UNNECESSARY;
    if (enet->cfg.ts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
        skb_hwtstamps(skb)->hwtstamp = EEA_DESC_TS(desc) +
            enet->hw_ts_offset;
Quoted 4 lines

If the device places per-packet metadata on the EOP descriptor (a common NIC layout), every multi-segment frame would silently fall back to CHECKSUM_NONE. Could the descriptor used for the checksum flag and for the timestamp be documented or made consistent?

On the RX path, for multi-descriptor packets, the information contained in all descriptors is essentially the same. Since they all describe the same packet, we only need to sample EEA_DESC_F_DATA_VALID once. As for the hardware timestamp, we simply retrieve it from the last descriptor as a matter of convenience.

Quoted 81 lines
Quoted 18 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +18 -0
+
+	if (ctx->hdr_len)
+		skb = eea_rx_build_split_hdr_skb(rx, ctx);
+	else
+		skb = eea_rx_build_skb(rx, ctx);
+
+	if (unlikely(!skb))
+		goto err;
+
+	rx->pkt.head_skb = skb;
+
+	return;
+
+err:
+	rx->pkt.do_drop = true;
+}
+
+static void eea_submit_skb(struct eea_net_rx *rx, struct sk_buff *skb,

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 416

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +10 -0
+			   struct eea_rx_cdesc *desc)
+{
+	struct eea_net *enet = rx->enet;
+
+	if (rx->pkt.data_valid)
+		skb->ip_summed = CHECKSUM_UNNECESSARY;
+
+	if (enet->cfg.ts_cfg.rx_filter == HWTSTAMP_FILTER_ALL)
+		skb_hwtstamps(skb)->hwtstamp = EEA_DESC_TS(desc) +
+			enet->hw_ts_offset;

Is the strict equality with HWTSTAMP_FILTER_ALL intentional? The usual driver convention for SIOCSHWTSTAMP is to either reject unsupported filters or upgrade them to ALL, so that consumers requesting more specific filters (PTP_V2_*, NTP_ALL, etc.) still get timestamps on matching frames. With the strict comparison above, anything other than HWTSTAMP_FILTER_ALL yields no timestamps. There is no SIOCSHWTSTAMP setter in this series, so the branch is effectively unreachable today, but it may be worth revisiting together with whatever setter lands later.

Quoted 6 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +6 -0
+
+	skb_record_rx_queue(skb, rx->index);
+	skb->protocol = eth_type_trans(skb, enet->netdev);
+
+	napi_gro_receive(rx->napi, skb);
+}

[ ... ]

Quoted 17 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +17 -0
+static int eea_cleanrx(struct eea_net_rx *rx, int budget,
+		       struct eea_rx_ctx *ctx)
+{
+	struct eea_rx_cdesc *desc;
+	struct eea_rx_meta *meta;
+	int recv, err;
+
+	for (recv = 0; recv < budget; ) {
+		desc = eea_ering_cq_get_desc(rx->ering);
+		if (!desc)
+			break;
+
+		err = eea_rx_desc_to_ctx(rx, ctx, desc);
+		if (unlikely(err)) {
+			if (ctx->meta)
+				eea_rx_meta_put(rx, ctx->meta);
+

drivers/net/ethernet/alibaba/eea/eea_rx.c static int eea_alloc_rx_hdr(struct eea_net_init_ctx *ctx, struct eea_net_rx *rx) · line 496

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +10 -0
+			if (rx->pkt.head_skb)
+				dev_kfree_skb(rx->pkt.head_skb);
+
+			/* A hardware error occurred; we are attempting to
+			 * mitigate the impact. Subsequent packets may be
+			 * corrupted.
+			 */
+			ctx->more = false;
+			goto ack;
+		}

Can this recovery path forward arbitrary mid-payload bytes to the network stack as a fresh L2 frame?
When eea_rx_desc_to_ctx() fails mid-stream (invalid id, or len greater than meta->len), this branch frees rx->pkt.head_skb, forces ctx->more = false, and jumps to ack. The tail of the loop then runs:

    if (!ctx->more) {
        memset(&rx->pkt, 0, sizeof(rx->pkt));
        ++recv;
    }
Quoted 10 lines

so no "still inside a device-side packet" indicator survives. The next descriptor from the device — which may be a continuation buffer of the original frame — will be handled by process_first_buf() because rx->pkt.idx == 0. If that continuation satisfies ctx->len >= ETH_HLEN, an skb is built from raw mid-payload bytes and submitted via eth_type_trans()/napi_gro_receive(). Would setting rx->pkt.do_drop = true (and only clearing rx->pkt on the next observed !more) be a safer way to mitigate, given the existing comment already notes "subsequent packets may be corrupted"?

During multi-fragment processing—specifically, whether a mid-stream exception might cause the driver to misidentify subsequent fragments as the start of a new packet. However, from a driver perspective, there is little we can do in such scenarios; if the hardware state becomes corrupted in this way, it constitutes a critical hardware error that is effectively beyond the driver's recovery capability.

Quoted 34 lines
Quoted 34 lines
drivers/net/ethernet/alibaba/eea/eea_rx.c +34 -0
+
+		meta = ctx->meta;
+
+		if (unlikely(rx->pkt.do_drop))
+			goto skip;
+
+		eea_rx_meta_dma_sync_for_cpu(rx, meta, ctx->len);
+
+		rx->pkt.recv_len += ctx->len;
+		rx->pkt.recv_len += ctx->hdr_len;
+
+		if (!rx->pkt.idx)
+			process_first_buf(rx, ctx);
+		else
+			process_remain_buf(rx, ctx);
+
+		++rx->pkt.idx;
+
+		if (!ctx->more && rx->pkt.head_skb)
+			eea_submit_skb(rx, rx->pkt.head_skb, desc);
+
+skip:
+		eea_rx_meta_put(rx, meta);
+ack:
+		eea_ering_cq_ack_desc(rx->ering, 1);
+
+		if (!ctx->more) {
+			memset(&rx->pkt, 0, sizeof(rx->pkt));
+			++recv;
+		}
+	}
+
+	return recv;
+}
author maintainer
#15 lore raw

PATCH v43 6/8 eea: implement packet transmit logic

In reply to Xuan Zhuo

Implement the core logic for transmitting packets in the EEA TX path, including packet preparation and submission to the underlying transport.

---
 drivers/net/ethernet/alibaba/eea/eea_tx.c | 384 +++++++++++++++++++++-
 1 file changed, 380 insertions(+), 4 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_tx.c +380 -4
index 5a8babfce5de..8b7fc75ead8a 100644
@@ -11,6 +11,11 @@
 #include "eea_pci.h"
 #include "eea_ring.h"
 
+struct eea_sq_free_stats {
+	u64 packets;
+	u64 bytes;
+};
+
 struct eea_tx_meta {
 	struct eea_tx_meta *next;
 
@@ -26,23 +31,394 @@ struct eea_tx_meta {
 	dma_addr_t dma_addr;
 	struct eea_tx_desc *desc;
 	u32 dma_len;
+	bool unmap;
+	bool unmap_single;
 };
 
+static struct eea_tx_meta *eea_tx_meta_get(struct eea_net_tx *tx)
+{
+	struct eea_tx_meta *meta;
+
+	if (!tx->free)
+		return NULL;
+
+	meta = tx->free;
+	tx->free = meta->next;
+
+	return meta;
+}
+
+static void eea_tx_meta_put_and_unmap(struct eea_net_tx *tx,
+				      struct eea_tx_meta *meta)
+{
+	struct eea_tx_meta *head;
+
+	head = meta;
+
+	while (true) {
+		if (meta->unmap) {
+			if (meta->unmap_single)
+				dma_unmap_single(tx->dma_dev, meta->dma_addr,
+						 meta->dma_len, DMA_TO_DEVICE);
+			else
+				dma_unmap_page(tx->dma_dev, meta->dma_addr,
+					       meta->dma_len, DMA_TO_DEVICE);
+		}
+
+		if (meta->next) {
+			meta = meta->next;
+			continue;
+		}
+
+		break;
+	}
+
+	meta->next = tx->free;
+	tx->free = head;
+}
+
+static void eea_meta_free_xmit(struct eea_net_tx *tx,
+			       struct eea_tx_meta *meta,
+			       int budget,
+			       struct eea_tx_cdesc *desc,
+			       struct eea_sq_free_stats *stats)
+{
+	struct sk_buff *skb = meta->skb;
+
+	if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && desc)) {
+		struct skb_shared_hwtstamps ts = {};
+
+		ts.hwtstamp = EEA_DESC_TS(desc) + tx->enet->hw_ts_offset;
+		skb_tstamp_tx(skb, &ts);
+	}
+
+	++stats->packets;
+	napi_consume_skb(meta->skb, budget);
+
+	meta->data = NULL;
+}
+
+static int eea_clean_tx(struct eea_net_tx *tx, int budget)
+{
+	struct eea_sq_free_stats stats = {0};
+	struct eea_tx_cdesc *desc;
+	struct eea_tx_meta *meta;
+	int desc_n;
+	u16 id;
+
+	while (stats.packets < budget) {
+		desc = eea_ering_cq_get_desc(tx->ering);
+		if (!desc)
+			break;
+
+		id = le16_to_cpu(desc->id);
+		if (unlikely(id >= tx->ering->num)) {
+			if (net_ratelimit())
+				netdev_err(tx->enet->netdev, "tx invalid id %d\n",
+					   id);
+			eea_ering_cq_ack_desc(tx->ering, 1);
+			continue;
+		}
+
+		meta = &tx->meta[id];
+
+		if (meta->data) {
+			eea_tx_meta_put_and_unmap(tx, meta);
+			eea_meta_free_xmit(tx, meta, budget, desc, &stats);
+			desc_n = meta->num;
+		} else {
+			if (net_ratelimit())
+				netdev_err(tx->enet->netdev,
+					   "tx meta->data is null. id %d num: %d\n",
+					   meta->id, meta->num);
+			desc_n = 1;
+		}
+
+		eea_ering_cq_ack_desc(tx->ering, desc_n);
+	}
+
+	return stats.packets;
+}
+
 int eea_poll_tx(struct eea_net_tx *tx, int budget)
 {
-	/* Empty function; will be implemented in a subsequent commit. */
-	return budget;
+	struct eea_net *enet = tx->enet;
+	u32 index = tx - enet->tx;
+	struct netdev_queue *txq;
+	int num;
+
+	txq = netdev_get_tx_queue(enet->netdev, index);
+
+	__netif_tx_lock(txq, smp_processor_id());
+
+	num = eea_clean_tx(tx, budget);
+
+	if (netif_tx_queue_stopped(txq) &&
+	    tx->ering->num_free >= MAX_SKB_FRAGS + 2)
+		netif_tx_wake_queue(txq);
+
+	__netif_tx_unlock(txq);
+
+	return num;
+}
+
+static int eea_fill_desc_from_skb(const struct sk_buff *skb,
+				  struct eea_tx_desc *desc)
+{
+	if (skb_is_gso(skb)) {
+		struct skb_shared_info *sinfo = skb_shinfo(skb);
+
+		desc->gso_size = cpu_to_le16(sinfo->gso_size);
+		if (sinfo->gso_type & SKB_GSO_TCPV4)
+			desc->gso_type = EEA_TX_GSO_TCPV4;
+
+		else if (sinfo->gso_type & SKB_GSO_TCPV6)
+			desc->gso_type = EEA_TX_GSO_TCPV6;
+
+		else if (sinfo->gso_type & SKB_GSO_UDP_L4)
+			desc->gso_type = EEA_TX_GSO_UDP_L4;
+
+		else
+			return -EINVAL;
+
+		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
+			desc->gso_type |= EEA_TX_GSO_ECN;
+	} else {
+		desc->gso_type = EEA_TX_GSO_NONE;
+	}
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		desc->csum_start = cpu_to_le16(skb_checksum_start_offset(skb));
+		desc->csum_offset = cpu_to_le16(skb->csum_offset);
+	}
+
+	return 0;
+}
+
+static struct eea_tx_meta *__eea_tx_desc_fill(struct eea_net_tx *tx,
+					      struct eea_tx_meta *head_meta,
+					      dma_addr_t addr, u32 data_len,
+					      u32 dma_len, bool last,
+					      void *data, u16 flags,
+					      bool unmap)
+{
+	struct eea_tx_meta *meta;
+	struct eea_tx_desc *desc;
+
+	meta = eea_tx_meta_get(tx);
+
+	desc = eea_ering_sq_alloc_desc(tx->ering, meta->id, last, flags);
+	desc->addr = cpu_to_le64(addr);
+	desc->len = cpu_to_le16(data_len);
+
+	meta->next     = NULL;
+	meta->dma_len  = dma_len;
+	meta->dma_addr = addr;
+	meta->data     = data;
+	meta->num      = 1;
+	meta->desc     = desc;
+	meta->unmap    = unmap;
+	meta->unmap_single = false;
+
+	if (head_meta) {
+		meta->next = head_meta->next;
+		head_meta->next = meta;
+		++head_meta->num;
+	}
+
+	return meta;
+}
+
+static struct eea_tx_meta *eea_tx_desc_fill(struct eea_net_tx *tx,
+					    struct eea_tx_meta *head_meta,
+					    dma_addr_t addr, u32 length,
+					    bool is_last, void *data, u16 flags)
+{
+	struct eea_tx_meta *meta;
+	u16 len, last;
+
+	WARN_ON_ONCE(length >= 2 * USHRT_MAX);
+
+	/* Since eea does not support BIG TCP, the maximum GSO size is capped at
+	 * 64KB. Consequently, a single skb buffer (head or fragment) will not
+	 * require more than two descriptors
+	 */
+	if (length > USHRT_MAX) {
+		len = USHRT_MAX;
+		last = false;
+	} else {
+		len = length;
+		last = is_last;
+	}
+
+	meta = __eea_tx_desc_fill(tx, head_meta, addr, len, length,
+				  last, data, flags, true);
+
+	if (length > USHRT_MAX) {
+		if (!head_meta)
+			head_meta = meta;
+
+		addr += USHRT_MAX;
+		len = length - USHRT_MAX;
+
+		__eea_tx_desc_fill(tx, head_meta, addr, len, 0, is_last,
+				   NULL, 0, false);
+	}
+
+	return meta;
+}
+
+static int eea_tx_add_skb_frag(struct eea_net_tx *tx,
+			       struct eea_tx_meta *head_meta,
+			       const skb_frag_t *frag, bool is_last)
+{
+	u32 len = skb_frag_size(frag);
+	dma_addr_t addr;
+
+	addr = skb_frag_dma_map(tx->dma_dev, frag, 0, len, DMA_TO_DEVICE);
+	if (unlikely(dma_mapping_error(tx->dma_dev, addr)))
+		return -ENOMEM;
+
+	eea_tx_desc_fill(tx, head_meta, addr, len, is_last, NULL, 0);
+
+	return 0;
+}
+
+static int eea_tx_post_skb(struct eea_net_tx *tx, struct sk_buff *skb)
+{
+	const struct skb_shared_info *shinfo = skb_shinfo(skb);
+	u32 hlen = skb_headlen(skb);
+	struct eea_tx_meta *meta;
+	const skb_frag_t *frag;
+	dma_addr_t addr;
+	u32 len = hlen;
+	int i, err;
+	u16 flags;
+	bool last;
+
+	if (len) {
+		addr = dma_map_single(tx->dma_dev, skb->data, len,
+				      DMA_TO_DEVICE);
+		if (unlikely(dma_mapping_error(tx->dma_dev, addr)))
+			return -ENOMEM;
+
+		last = !shinfo->nr_frags;
+		i = 0;
+	} else {
+		/* The net stack will never submit an skb with an skb->len of
+		 * 0. If the head len is 0, the number of frags must be greater
+		 * than 0.
+		 */
+		frag = &shinfo->frags[0];
+		len = skb_frag_size(frag);
+
+		addr = skb_frag_dma_map(tx->dma_dev, frag, 0, len,
+					DMA_TO_DEVICE);
+		if (unlikely(dma_mapping_error(tx->dma_dev, addr)))
+			return -ENOMEM;
+
+		last = shinfo->nr_frags == 1;
+		i = 1;
+	}
+
+	flags = skb->ip_summed == CHECKSUM_PARTIAL ? EEA_DESC_F_DO_CSUM : 0;
+
+	meta = eea_tx_desc_fill(tx, NULL, addr, len, last, skb, flags);
+	meta->unmap_single = !!hlen;
+
+	err = eea_fill_desc_from_skb(skb, meta->desc);
+	if (err)
+		goto err_cancel;
+
+	for (; i < shinfo->nr_frags; i++) {
+		frag = &shinfo->frags[i];
+		bool is_last = i == (shinfo->nr_frags - 1);
+
+		err = eea_tx_add_skb_frag(tx, meta, frag, is_last);
+		if (err)
+			goto err_cancel;
+	}
+
+	eea_ering_sq_commit_desc(tx->ering);
+
+	return 0;
+
+err_cancel:
+	eea_ering_sq_cancel(tx->ering);
+	eea_tx_meta_put_and_unmap(tx, meta);
+	meta->data = NULL;
+	return err;
+}
+
+static void eea_tx_kick(struct eea_net_tx *tx)
+{
+	eea_ering_kick(tx->ering);
+}
+
+static int eea_tx_check_free_num(struct eea_net_tx *tx,
+				 struct netdev_queue *txq)
+{
+	int n;
+
+	/* MAX_SKB_FRAGS + 1: Covers the skb linear head and all paged fragments
+	 * 1: Extra slot for a head or fragment that exceeds 64KB.
+	 */
+	n = MAX_SKB_FRAGS + 2;
+	return netif_txq_maybe_stop(txq, tx->ering->num_free, n, n);
 }
 
 netdev_tx_t eea_tx_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
-	/* Empty function; will be implemented in a subsequent commit. */
-	dev_kfree_skb_any(skb);
+	struct eea_net *enet = netdev_priv(netdev);
+	int qnum = skb_get_queue_mapping(skb);
+	struct eea_net_tx *tx = &enet->tx[qnum];
+	struct netdev_queue *txq;
+	int err, enable;
+
+	txq = netdev_get_tx_queue(netdev, qnum);
+
+	enable = eea_tx_check_free_num(tx, txq);
+	if (!enable)
+		return NETDEV_TX_BUSY;
+
+	err = eea_tx_post_skb(tx, skb);
+	if (unlikely(err)) {
+		dev_kfree_skb_any(skb);
+	} else {
+		if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
+			skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+		skb_tx_timestamp(skb);
+	}
+
+	/* NETDEV_TX_BUSY is expensive. So stop advancing the TX queue. */
+	eea_tx_check_free_num(tx, txq);
+
+	if (!netdev_xmit_more() || netif_xmit_stopped(txq))
+		eea_tx_kick(tx);
+
 	return NETDEV_TX_OK;
 }
 
 static void eea_free_meta(struct eea_net_tx *tx, struct eea_net_cfg *cfg)
 {
+	struct eea_sq_free_stats stats = {0};
+	struct eea_tx_meta *meta;
+	int i;
+
+	while ((meta = eea_tx_meta_get(tx)))
+		meta->skb = NULL;
+
+	for (i = 0; i < cfg->tx_ring_depth; i++) {
+		meta = &tx->meta[i];
+
+		if (!meta->skb)
+			continue;
+
+		eea_tx_meta_put_and_unmap(tx, meta);
+
+		eea_meta_free_xmit(tx, meta, 0, NULL, &stats);
+	}
+
 	kvfree(tx->meta);
 	tx->meta = NULL;
 }
Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#16 lore raw

Re: [PATCH net-next v43 6/8] eea: implement packet transmit logic

From sashiko:

commit cffb539ce8b8ad9935febc105007a1405d95169b
Author: Xuan Zhuo <[email protected]>
eea: implement packet transmit logic
This commit fills in the previously stubbed eea_tx_xmit() and eea_poll_tx() with the full TX path: building descriptors from skbs, handling DMA mapping/unmapping, GSO and checksum offload setup, and completion processing.

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +0 -0
index 5a8babfce5de..8b7fc75ead8a 100644

[ ... ]

Quoted 22 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +22 -0
+static int eea_fill_desc_from_skb(const struct sk_buff *skb,
+				  struct eea_tx_desc *desc)
+{
+	if (skb_is_gso(skb)) {
+		struct skb_shared_info *sinfo = skb_shinfo(skb);
+
+		desc->gso_size = cpu_to_le16(sinfo->gso_size);
+		if (sinfo->gso_type & SKB_GSO_TCPV4)
+			desc->gso_type = EEA_TX_GSO_TCPV4;
+
+		else if (sinfo->gso_type & SKB_GSO_TCPV6)
+			desc->gso_type = EEA_TX_GSO_TCPV6;
+
+		else if (sinfo->gso_type & SKB_GSO_UDP_L4)
+			desc->gso_type = EEA_TX_GSO_UDP_L4;
+
+		else
+			return -EINVAL;
+
+		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
+			desc->gso_type |= EEA_TX_GSO_ECN;
+	} else {

drivers/net/ethernet/alibaba/eea/eea_tx.c struct eea_tx_meta { · line 196

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +10 -0
+		desc->gso_type = EEA_TX_GSO_NONE;
+	}
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		desc->csum_start = cpu_to_le16(skb_checksum_start_offset(skb));
+		desc->csum_offset = cpu_to_le16(skb->csum_offset);
+	}
+
+	return 0;
+}

Can stale fields in a reused descriptor slot be sent to the device? The SQ ring slots are reused as the ring wraps. Several eea_tx_desc fields are only conditionally written:
- csum_start and csum_offset are only set when

    skb->ip_summed == CHECKSUM_PARTIAL

- gso_size is only set when skb_is_gso(skb)
- gso_type is set here for the head descriptor, but eea_tx_add_skb_frag() and the >USHRT_MAX split path in eea_tx_desc_fill() never write gso_type, gso_size, csum_start or csum_offset on continuation descriptors
- reserved1, reserved2 and reserved3 are never written
After the first ring wrap each reused slot will carry whatever values the previous occupant wrote. Does correctness here rely on the device gating each optional field on EEA_DESC_F_DO_CSUM and on the "more descriptors" flag, and ignoring all reserved bits?
If so, would it be worth either zeroing the descriptor at fill time (for example a memset before populating it) or adding a comment that documents the hardware contract being relied on?
What is the silent drop signal when an unsupported gso_type appears? When skb_is_gso(skb) is true but the type is none of TCPV4, TCPV6 or UDP_L4, this returns -EINVAL, which propagates up through eea_tx_post_skb() into err_cancel and ultimately to dev_kfree_skb_any() in eea_tx_xmit(). There is no kfree_skb_reason(), no per-queue counter and no log message.
Today the four supported types match what is advertised in hw_features and features, so this branch should be unreachable. If a future feature flag is advertised without updating this switch (for example a tunnel GSO type), would the resulting drops be observable from userspace at all?
Would kfree_skb_reason() with a specific drop reason, or restructuring so the unsupported case is structurally unreachable, make this easier to debug?

Quoted 35 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +29 -2
+static int eea_tx_check_free_num(struct eea_net_tx *tx,
+				 struct netdev_queue *txq)
+{
+	int n;
+
+	/* MAX_SKB_FRAGS + 1: Covers the skb linear head and all paged fragments
+	 * 1: Extra slot for a head or fragment that exceeds 64KB.
+	 */
+	n = MAX_SKB_FRAGS + 2;
+	return netif_txq_maybe_stop(txq, tx->ering->num_free, n, n);
 }
 
 netdev_tx_t eea_tx_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
-	/* Empty function; will be implemented in a subsequent commit. */
-	dev_kfree_skb_any(skb);
+	struct eea_net *enet = netdev_priv(netdev);
+	int qnum = skb_get_queue_mapping(skb);
+	struct eea_net_tx *tx = &enet->tx[qnum];
+	struct netdev_queue *txq;
+	int err, enable;
+
+	txq = netdev_get_tx_queue(netdev, qnum);
+
+	enable = eea_tx_check_free_num(tx, txq);
+	if (!enable)
+		return NETDEV_TX_BUSY;
+
+	err = eea_tx_post_skb(tx, skb);
+	if (unlikely(err)) {
+		dev_kfree_skb_any(skb);
+	} else {
+		if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
+			skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+		skb_tx_timestamp(skb);

drivers/net/ethernet/alibaba/eea/eea_tx.c struct eea_tx_meta { · line 400

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +8 -0
+	}
+
+	/* NETDEV_TX_BUSY is expensive. So stop advancing the TX queue. */
+	eea_tx_check_free_num(tx, txq);
+
+	if (!netdev_xmit_more() || netif_xmit_stopped(txq))
+		eea_tx_kick(tx);
+
 	return NETDEV_TX_OK;
 }

Is BQL intended to be wired up here? eea_tx_check_free_num() uses netif_txq_maybe_stop(), which is the BQL-aware helper, but the xmit path never calls netdev_tx_sent_queue() and the completion path in eea_clean_tx() / eea_poll_tx() never calls netdev_tx_completed_queue(). Without the paired byte updates, BQL has no view of in-flight bytes. Also, the stop and start thresholds passed to netif_txq_maybe_stop() are both MAX_SKB_FRAGS + 2, so there is no hysteresis between queue-stop and queue-wake. eea_poll_tx() uses the same threshold for its wake check:

	if (netif_tx_queue_stopped(txq) &&
	    tx->ering->num_free >= MAX_SKB_FRAGS + 2)
		netif_tx_wake_queue(txq);

Was a stop/start gap (e.g. start at 2 * stop) considered to dampen wake/stop oscillation under sustained pressure?

author maintainer
#17 lore raw

Re: [PATCH net-next v43 6/8] eea: implement packet transmit logic

Quoted 52 lines · Xuan Zhuo

From sashiko:

commit cffb539ce8b8ad9935febc105007a1405d95169b
Author: Xuan Zhuo <[email protected]>
eea: implement packet transmit logic
This commit fills in the previously stubbed eea_tx_xmit() and eea_poll_tx() with the full TX path: building descriptors from skbs, handling DMA mapping/unmapping, GSO and checksum offload setup, and completion processing.

Quoted 4 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +0 -0
index 5a8babfce5de..8b7fc75ead8a 100644

[ ... ]

Quoted 22 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +22 -0
+static int eea_fill_desc_from_skb(const struct sk_buff *skb,
+				  struct eea_tx_desc *desc)
+{
+	if (skb_is_gso(skb)) {
+		struct skb_shared_info *sinfo = skb_shinfo(skb);
+
+		desc->gso_size = cpu_to_le16(sinfo->gso_size);
+		if (sinfo->gso_type & SKB_GSO_TCPV4)
+			desc->gso_type = EEA_TX_GSO_TCPV4;
+
+		else if (sinfo->gso_type & SKB_GSO_TCPV6)
+			desc->gso_type = EEA_TX_GSO_TCPV6;
+
+		else if (sinfo->gso_type & SKB_GSO_UDP_L4)
+			desc->gso_type = EEA_TX_GSO_UDP_L4;
+
+		else
+			return -EINVAL;
+
+		if (sinfo->gso_type & SKB_GSO_TCP_ECN)
+			desc->gso_type |= EEA_TX_GSO_ECN;
+	} else {

drivers/net/ethernet/alibaba/eea/eea_tx.c struct eea_tx_meta { · line 196

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +10 -0
+		desc->gso_type = EEA_TX_GSO_NONE;
+	}
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		desc->csum_start = cpu_to_le16(skb_checksum_start_offset(skb));
+		desc->csum_offset = cpu_to_le16(skb->csum_offset);
+	}
+
+	return 0;
+}

Can stale fields in a reused descriptor slot be sent to the device? The SQ ring slots are reused as the ring wraps. Several eea_tx_desc fields are only conditionally written:
- csum_start and csum_offset are only set when

    skb->ip_summed == CHECKSUM_PARTIAL
Quoted 13 lines

- gso_size is only set when skb_is_gso(skb)
- gso_type is set here for the head descriptor, but eea_tx_add_skb_frag() and the >USHRT_MAX split path in eea_tx_desc_fill() never write gso_type, gso_size, csum_start or csum_offset on continuation descriptors
- reserved1, reserved2 and reserved3 are never written
After the first ring wrap each reused slot will carry whatever values the previous occupant wrote. Does correctness here rely on the device gating each optional field on EEA_DESC_F_DO_CSUM and on the "more descriptors" flag, and ignoring all reserved bits? If so, would it be worth either zeroing the descriptor at fill time (for example a memset before populating it) or adding a comment that documents the hardware contract being relied on?

This isn't an issue; the device parses the flags first to determine which fields to process.

Quoted 8 lines

What is the silent drop signal when an unsupported gso_type appears? When skb_is_gso(skb) is true but the type is none of TCPV4, TCPV6 or UDP_L4, this returns -EINVAL, which propagates up through eea_tx_post_skb() into err_cancel and ultimately to dev_kfree_skb_any() in eea_tx_xmit(). There is no kfree_skb_reason(), no per-queue counter and no log message.
Today the four supported types match what is advertised in hw_features and features, so this branch should be unreachable. If a

Yes, so return directly.

Quoted 61 lines

future feature flag is advertised without updating this switch (for example a tunnel GSO type), would the resulting drops be observable from userspace at all?
Would kfree_skb_reason() with a specific drop reason, or restructuring so the unsupported case is structurally unreachable, make this easier to debug?

Quoted 35 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +29 -2
+static int eea_tx_check_free_num(struct eea_net_tx *tx,
+				 struct netdev_queue *txq)
+{
+	int n;
+
+	/* MAX_SKB_FRAGS + 1: Covers the skb linear head and all paged fragments
+	 * 1: Extra slot for a head or fragment that exceeds 64KB.
+	 */
+	n = MAX_SKB_FRAGS + 2;
+	return netif_txq_maybe_stop(txq, tx->ering->num_free, n, n);
 }
 
 netdev_tx_t eea_tx_xmit(struct sk_buff *skb, struct net_device *netdev)
 {
-	/* Empty function; will be implemented in a subsequent commit. */
-	dev_kfree_skb_any(skb);
+	struct eea_net *enet = netdev_priv(netdev);
+	int qnum = skb_get_queue_mapping(skb);
+	struct eea_net_tx *tx = &enet->tx[qnum];
+	struct netdev_queue *txq;
+	int err, enable;
+
+	txq = netdev_get_tx_queue(netdev, qnum);
+
+	enable = eea_tx_check_free_num(tx, txq);
+	if (!enable)
+		return NETDEV_TX_BUSY;
+
+	err = eea_tx_post_skb(tx, skb);
+	if (unlikely(err)) {
+		dev_kfree_skb_any(skb);
+	} else {
+		if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
+			skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
+		skb_tx_timestamp(skb);

drivers/net/ethernet/alibaba/eea/eea_tx.c struct eea_tx_meta { · line 400

Quoted 10 lines
drivers/net/ethernet/alibaba/eea/eea_tx.c +8 -0
+	}
+
+	/* NETDEV_TX_BUSY is expensive. So stop advancing the TX queue. */
+	eea_tx_check_free_num(tx, txq);
+
+	if (!netdev_xmit_more() || netif_xmit_stopped(txq))
+		eea_tx_kick(tx);
+
 	return NETDEV_TX_OK;
 }

Is BQL intended to be wired up here? eea_tx_check_free_num() uses netif_txq_maybe_stop(), which is the BQL-aware helper, but the xmit path never calls netdev_tx_sent_queue() and the completion path in eea_clean_tx() / eea_poll_tx() never calls netdev_tx_completed_queue(). Without the paired byte updates, BQL has no view of in-flight bytes. Also, the stop and start thresholds passed to netif_txq_maybe_stop() are both MAX_SKB_FRAGS + 2, so there is no hysteresis between queue-stop and queue-wake. eea_poll_tx() uses the same threshold for its wake check:

Quoted 5 lines
	if (netif_tx_queue_stopped(txq) &&
	    tx->ering->num_free >= MAX_SKB_FRAGS + 2)
		netif_tx_wake_queue(txq);

Was a stop/start gap (e.g. start at 2 * stop) considered to dampen wake/stop oscillation under sustained pressure?

BQL is not supported in this version.

author maintainer
#18 lore raw

PATCH v43 7/8 eea: introduce ethtool support

In reply to Xuan Zhuo

Add basic driver framework for the Alibaba Elastic Ethernet Adapter(EEA).

This commit introduces ethtool support.

---
 drivers/net/ethernet/alibaba/eea/Makefile     |   1 +
 .../net/ethernet/alibaba/eea/eea_ethtool.c    | 273 ++++++++++++++++++
 .../net/ethernet/alibaba/eea/eea_ethtool.h    |  48 +++
 drivers/net/ethernet/alibaba/eea/eea_net.c    |   1 +
 drivers/net/ethernet/alibaba/eea/eea_net.h    |   5 +
 drivers/net/ethernet/alibaba/eea/eea_rx.c     |  32 +-
 drivers/net/ethernet/alibaba/eea/eea_tx.c     |  22 ++
 7 files changed, 377 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.h
drivers/net/ethernet/alibaba/eea/Makefile +1 -0
index 5f0961002e57..c38db22cca34 100644
@@ -4,5 +4,6 @@ eea-y := eea_ring.o \
 	eea_net.o \
 	eea_pci.o \
 	eea_adminq.o \
+	eea_ethtool.o \
 	eea_tx.o \
 	eea_rx.o
drivers/net/ethernet/alibaba/eea/eea_ethtool.c new file +273 -0

273 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_ethtool.h new file +48 -0

48 lines not on this page · raw message

drivers/net/ethernet/alibaba/eea/eea_net.c +1 -0
index bf8581bc27ed..f4505eed8bdd 100644
@@ -624,6 +624,7 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
 	}
 
 	netdev->netdev_ops = &eea_netdev;
+	netdev->ethtool_ops = &eea_ethtool_ops;
 	SET_NETDEV_DEV(netdev, edev->dma_dev);
 
 	enet = netdev_priv(netdev);
drivers/net/ethernet/alibaba/eea/eea_net.h +5 -0
index 1ff9ef1a8fbe..6a5b2f908c76 100644
@@ -12,6 +12,7 @@
 #include <linux/netdevice.h>
 
 #include "eea_adminq.h"
+#include "eea_ethtool.h"
 #include "eea_ring.h"
 
 #define EEA_VER_MAJOR		1
@@ -33,6 +34,8 @@ struct eea_net_tx {
 	u32 index;
 
 	char name[16];
+
+	struct eea_tx_stats stats;
 };
 
 struct eea_rx_meta {
@@ -87,6 +90,8 @@ struct eea_net_rx {
 
 	struct napi_struct *napi;
 
+	struct eea_rx_stats stats;
+
 	char name[16];
 
 	struct eea_net_rx_pkt_ctx pkt;
drivers/net/ethernet/alibaba/eea/eea_rx.c +27 -5
index 9c71a7cf950e..a3f0d2a79ad8 100644
@@ -29,6 +29,8 @@ struct eea_rx_ctx {
 	bool more;
 
 	struct eea_rx_meta *meta;
+
+	struct eea_rx_ctx_stats stats;
 };
 
 static struct eea_rx_meta *eea_rx_meta_get(struct eea_net_rx *rx)
@@ -232,6 +234,7 @@ static int eea_harden_check_overflow(struct eea_rx_ctx *ctx,
 	if (unlikely(ctx->len > max_len)) {
 		pr_debug("%s: rx error: len %u exceeds truesize %u\n",
 			 enet->netdev->name, ctx->len, max_len);
+		++ctx->stats.length_errors;
 		return -EINVAL;
 	}
 
@@ -250,6 +253,7 @@ static int eea_harden_check_size(struct eea_rx_ctx *ctx, struct eea_net *enet)
 		if (unlikely(ctx->hdr_len < ETH_HLEN)) {
 			pr_debug("%s: short hdr %u\n", enet->netdev->name,
 				 ctx->hdr_len);
+			++ctx->stats.length_errors;
 			return -EINVAL;
 		}
 
@@ -257,6 +261,7 @@ static int eea_harden_check_size(struct eea_rx_ctx *ctx, struct eea_net *enet)
 			pr_debug("%s: rx error: hdr len %u exceeds hdr buffer size %u\n",
 				 enet->netdev->name, ctx->hdr_len,
 				 enet->cfg.split_hdr);
+			++ctx->stats.length_errors;
 			return -EINVAL;
 		}
 
@@ -265,6 +270,7 @@ static int eea_harden_check_size(struct eea_rx_ctx *ctx, struct eea_net *enet)
 
 	if (unlikely(ctx->len < ETH_HLEN)) {
 		pr_debug("%s: short packet %u\n", enet->netdev->name, ctx->len);
+		++ctx->stats.length_errors;
 		return -EINVAL;
 	}
 
@@ -373,6 +379,7 @@ static void process_remain_buf(struct eea_net_rx *rx, struct eea_rx_ctx *ctx)
 
 err:
 	dev_kfree_skb(rx->pkt.head_skb);
+	++ctx->stats.drops;
 	rx->pkt.do_drop = true;
 	rx->pkt.head_skb = NULL;
 }
@@ -400,6 +407,7 @@ static void process_first_buf(struct eea_net_rx *rx, struct eea_rx_ctx *ctx)
 	return;
 
 err:
+	++ctx->stats.drops;
 	rx->pkt.do_drop = true;
 }
 
@@ -460,6 +468,8 @@ static int eea_rx_desc_to_ctx(struct eea_net_rx *rx,
 	if (ctx->flags & EEA_DESC_F_SPLIT_HDR) {
 		ctx->hdr_len = le16_to_cpu(desc->len_ex) &
 			EEA_RX_CDESC_HDR_LEN_MASK;
+		ctx->stats.split_hdr_bytes += ctx->hdr_len;
+		++ctx->stats.split_hdr_packets;
 	}
 
 	ctx->more = ctx->flags & EEA_RING_DESC_F_MORE;
@@ -484,8 +494,10 @@ static int eea_cleanrx(struct eea_net_rx *rx, int budget,
 			if (ctx->meta)
 				eea_rx_meta_put(rx, ctx->meta);
 
-			if (rx->pkt.head_skb)
+			if (rx->pkt.head_skb) {
 				dev_kfree_skb(rx->pkt.head_skb);
+				++ctx->stats.drops;
+			}
 
 			/* A hardware error occurred; we are attempting to
 			 * mitigate the impact. Subsequent packets may be
@@ -512,13 +524,17 @@ static int eea_cleanrx(struct eea_net_rx *rx, int budget,
 
 		++rx->pkt.idx;
 
-		if (!ctx->more && rx->pkt.head_skb)
+		if (!ctx->more && rx->pkt.head_skb) {
 			eea_submit_skb(rx, rx->pkt.head_skb, desc);
+			ctx->stats.bytes += rx->pkt.recv_len;
+			++ctx->stats.packets;
+		}
 
 skip:
 		eea_rx_meta_put(rx, meta);
 ack:
 		eea_ering_cq_ack_desc(rx->ering, 1);
+		++ctx->stats.descs;
 
 		if (!ctx->more) {
 			memset(&rx->pkt, 0, sizeof(rx->pkt));
@@ -537,7 +553,7 @@ static void eea_rx_dma_sync_hdr(struct eea_net_rx *rx, dma_addr_t addr)
 }
 
 /* Only be called from napi. */
-static void eea_rx_post(struct eea_net_rx *rx)
+static void eea_rx_post(struct eea_net_rx *rx, struct eea_rx_ctx *ctx)
 {
 	u32 tailroom, headroom, room, len;
 	struct eea_rx_meta *meta;
@@ -586,8 +602,10 @@ static void eea_rx_post(struct eea_net_rx *rx)
 		++num;
 	}
 
-	if (num)
+	if (num) {
 		eea_ering_kick(rx->ering);
+		++ctx->stats.kicks;
+	}
 }
 
 static int eea_poll(struct napi_struct *napi, int budget)
@@ -608,12 +626,14 @@ static int eea_poll(struct napi_struct *napi, int budget)
 		 * buffers are exhausted. Therefore, we should proactively
 		 * pre-fill the buffers to avoid starvation.
 		 */
-		eea_rx_post(rx);
+		eea_rx_post(rx, &ctx);
 
 		if (rx->ering->num - rx->ering->num_free < budget)
 			busy = true;
 	}
 
+	eea_update_rx_stats(&rx->stats, &ctx.stats);
+
 	busy |= received >= budget;
 
 	if (busy)
@@ -751,6 +771,8 @@ struct eea_net_rx *eea_alloc_rx(struct eea_net_init_ctx *ctx, u32 idx)
 	rx->index = idx;
 	snprintf(rx->name, sizeof(rx->name), "rx.%u", idx);
 
+	u64_stats_init(&rx->stats.syncp);
+
 	/* ering */
 	ering = eea_ering_alloc(idx * 2, ctx->cfg.rx_ring_depth, ctx->edev,
 				ctx->cfg.rx_sq_desc_size,
drivers/net/ethernet/alibaba/eea/eea_tx.c +22 -0
index 8b7fc75ead8a..85fb0e9ca5ba 100644
@@ -93,6 +93,7 @@ static void eea_meta_free_xmit(struct eea_net_tx *tx,
 	}
 
 	++stats->packets;
+	stats->bytes += meta->skb->len;
 	napi_consume_skb(meta->skb, budget);
 
 	meta->data = NULL;
@@ -137,6 +138,13 @@ static int eea_clean_tx(struct eea_net_tx *tx, int budget)
 		eea_ering_cq_ack_desc(tx->ering, desc_n);
 	}
 
+	if (stats.packets) {
+		u64_stats_update_begin(&tx->stats.syncp);
+		u64_stats_add(&tx->stats.bytes, stats.bytes);
+		u64_stats_add(&tx->stats.packets, stats.packets);
+		u64_stats_update_end(&tx->stats.syncp);
+	}
+
 	return stats.packets;
 }
 
@@ -341,6 +349,10 @@ static int eea_tx_post_skb(struct eea_net_tx *tx, struct sk_buff *skb)
 
 	eea_ering_sq_commit_desc(tx->ering);
 
+	u64_stats_update_begin(&tx->stats.syncp);
+	u64_stats_add(&tx->stats.descs, meta->num);
+	u64_stats_update_end(&tx->stats.syncp);
+
 	return 0;
 
 err_cancel:
@@ -353,6 +365,10 @@ static int eea_tx_post_skb(struct eea_net_tx *tx, struct sk_buff *skb)
 static void eea_tx_kick(struct eea_net_tx *tx)
 {
 	eea_ering_kick(tx->ering);
+
+	u64_stats_update_begin(&tx->stats.syncp);
+	u64_stats_inc(&tx->stats.kicks);
+	u64_stats_update_end(&tx->stats.syncp);
 }
 
 static int eea_tx_check_free_num(struct eea_net_tx *tx,
@@ -383,6 +399,10 @@ netdev_tx_t eea_tx_xmit(struct sk_buff *skb, struct net_device *netdev)
 
 	err = eea_tx_post_skb(tx, skb);
 	if (unlikely(err)) {
+		u64_stats_update_begin(&tx->stats.syncp);
+		u64_stats_inc(&tx->stats.drops);
+		u64_stats_update_end(&tx->stats.syncp);
+
 		dev_kfree_skb_any(skb);
 	} else {
 		if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
@@ -444,6 +464,8 @@ int eea_alloc_tx(struct eea_net_init_ctx *ctx, struct eea_net_tx *tx, u32 idx)
 	struct eea_ring *ering;
 	u32 i;
 
+	u64_stats_init(&tx->stats.syncp);
+
 	snprintf(tx->name, sizeof(tx->name), "tx.%u", idx);
 
 	ering = eea_ering_alloc(idx * 2 + 1, ctx->cfg.tx_ring_depth, ctx->edev,
Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#19 lore raw

Re: [PATCH net-next v43 7/8] eea: introduce ethtool support

No regressions from Sashiko.

author maintainer
#20 lore raw

PATCH v43 8/8 eea: introduce callback for ndo_get_stats64 and register netdev

In reply to Xuan Zhuo

This commit adds support for ndo_get_stats64 to provide accurate interface statistics. With the TX and RX data paths now fully functional, it is appropriate to register the netdevice and expose the interface to userspace.

Registered the network device via register_netdev, and updated the corresponding unregister_netdev and dev_close routines to ensure synchronization.

---
 drivers/net/ethernet/alibaba/eea/eea_net.c | 83 ++++++++++++++++++++--
 drivers/net/ethernet/alibaba/eea/eea_net.h |  5 ++
 2 files changed, 84 insertions(+), 4 deletions(-)
drivers/net/ethernet/alibaba/eea/eea_net.c +79 -4
index f4505eed8bdd..63e68580de94 100644
@@ -112,6 +112,11 @@ static void eea_bind_q_and_cfg(struct eea_net *enet,
 	struct eea_net_tx *tx;
 	int i;
 
+	/* Since 'ndo_get_stats64' is not called in softirq context, there is no
+	 * need to use 'spin_lock_bh'.
+	 */
+	spin_lock(&enet->stats_lock);
+
 	enet->cfg = ctx->cfg;
 	enet->rx = ctx->rx;
 	enet->tx = ctx->tx;
@@ -131,6 +136,8 @@ static void eea_bind_q_and_cfg(struct eea_net *enet,
 
 		blk->rx = rx;
 	}
+
+	spin_unlock(&enet->stats_lock);
 }
 
 static void eea_unbind_q_and_cfg(struct eea_net *enet,
@@ -140,6 +147,8 @@ static void eea_unbind_q_and_cfg(struct eea_net *enet,
 	struct eea_net_rx *rx;
 	int i;
 
+	spin_lock(&enet->stats_lock);
+
 	ctx->cfg = enet->cfg;
 	ctx->rx = enet->rx;
 	ctx->tx = enet->tx;
@@ -156,6 +165,8 @@ static void eea_unbind_q_and_cfg(struct eea_net *enet,
 
 		blk->rx = NULL;
 	}
+
+	spin_unlock(&enet->stats_lock);
 }
 
 static void eea_free_rxtx_q_mem(struct eea_net_init_ctx *ctx)
@@ -342,6 +353,60 @@ static int eea_netdev_open(struct net_device *netdev)
 	return err;
 }
 
+/* Statistics may be reset to zero upon device reset. This is expected behavior
+ * for now and will be addressed in the future.
+ */
+static void eea_stats(struct net_device *netdev, struct rtnl_link_stats64 *tot)
+{
+	struct eea_net *enet = netdev_priv(netdev);
+	u64 packets, bytes, drop, lerr;
+	u32 start;
+	int i;
+
+	spin_lock(&enet->stats_lock);
+
+	if (enet->rx) {
+		for (i = 0; i < enet->cfg.rx_ring_num; i++) {
+			struct eea_net_rx *rx = enet->rx[i];
+
+			do {
+				start = u64_stats_fetch_begin(&rx->stats.syncp);
+				packets = u64_stats_read(&rx->stats.packets);
+				bytes = u64_stats_read(&rx->stats.bytes);
+				drop = u64_stats_read(&rx->stats.drops);
+				lerr = u64_stats_read(&rx->stats.length_errors);
+			} while (u64_stats_fetch_retry(&rx->stats.syncp,
+						       start));
+
+			tot->rx_packets       += packets;
+			tot->rx_bytes         += bytes;
+			tot->rx_dropped       += drop;
+			tot->rx_length_errors += lerr;
+			tot->rx_errors        += lerr;
+		}
+	}
+
+	if (enet->tx) {
+		for (i = 0; i < enet->cfg.tx_ring_num; i++) {
+			struct eea_net_tx *tx = &enet->tx[i];
+
+			do {
+				start = u64_stats_fetch_begin(&tx->stats.syncp);
+				packets = u64_stats_read(&tx->stats.packets);
+				bytes = u64_stats_read(&tx->stats.bytes);
+				drop = u64_stats_read(&tx->stats.drops);
+			} while (u64_stats_fetch_retry(&tx->stats.syncp,
+						       start));
+
+			tot->tx_packets += packets;
+			tot->tx_bytes   += bytes;
+			tot->tx_dropped += drop;
+		}
+	}
+
+	spin_unlock(&enet->stats_lock);
+}
+
 /* resources: ring, buffers, irq */
 int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx)
 {
@@ -349,7 +414,9 @@ int eea_reset_hw_resources(struct eea_net *enet, struct eea_net_init_ctx *ctx)
 	int err, error;
 
 	if (!netif_running(enet->netdev) || !enet->started) {
+		spin_lock(&enet->stats_lock);
 		enet->cfg = ctx->cfg;
+		spin_unlock(&enet->stats_lock);
 		return 0;
 	}
 
@@ -607,6 +674,7 @@ static const struct net_device_ops eea_netdev = {
 	.ndo_stop           = eea_netdev_stop,
 	.ndo_start_xmit     = eea_tx_xmit,
 	.ndo_validate_addr  = eth_validate_addr,
+	.ndo_get_stats64    = eea_stats,
 	.ndo_features_check = passthru_features_check,
 };
 
@@ -640,6 +708,8 @@ static struct eea_net *eea_netdev_alloc(struct eea_device *edev, u32 pairs)
 		return NULL;
 	}
 
+	spin_lock_init(&enet->stats_lock);
+
 	return enet;
 }
 
@@ -725,11 +795,13 @@ int eea_net_probe(struct eea_device *edev)
 
 	eea_update_ts_off(edev, enet);
 
-	netdev_dbg(enet->netdev, "eea probe success.\n");
+	netif_carrier_off(enet->netdev);
 
-	/* Queue TX/RX implementation is still in progress. register_netdev is
-	 * deferred until these are completed in subsequent commits.
-	 */
+	err = register_netdev(enet->netdev);
+	if (err)
+		goto err_reset_dev;
+
+	netdev_dbg(enet->netdev, "eea probe success.\n");
 
 	return 0;
 
@@ -781,6 +853,8 @@ void eea_net_remove(struct eea_device *edev, bool ha)
 		return;
 	}
 
+	unregister_netdev(netdev);
+
 	if (!enet->wait_pci_ready) {
 		eea_device_reset(edev);
 		eea_destroy_adminq(enet);
@@ -801,6 +875,7 @@ void eea_net_shutdown(struct eea_device *edev)
 	rtnl_lock();
 
 	netif_device_detach(netdev);
+	dev_close(netdev);
 
 	if (!enet->wait_pci_ready) {
 		eea_device_reset(edev);
drivers/net/ethernet/alibaba/eea/eea_net.h +5 -0
index 6a5b2f908c76..848bb90bccf8 100644
@@ -165,6 +165,11 @@ struct eea_net {
 	u32 speed;
 
 	u64 hw_ts_offset;
+
+	/* Protect the tx and rx of struct eea_net, when eea_stats accesses the
+	 * stats from rx and tx queues.
+	 */
+	spinlock_t stats_lock;
 };
 
 int eea_net_probe(struct eea_device *edev);
Signature · 1 line
2.32.0.3.g01195cf9f
author maintainer
#21 lore raw

Re: [PATCH net-next v43 8/8] eea: introduce callback for ndo_get_stats64 and register netdev

https://idealab.alibaba-inc.com/ideaTalk#/ideaTALK/chat?sessionId=252ca245-ee4a-45d8-a859-d20100fe3f91

Sashiko comments linear growth in the stats counters.

However, I plan to introduce qstats (queue-specific statistics) in a future update, which will be a more appropriate place for such tracking. I intend to defer this feature until that implementation; it will not be included in the current version.

author maintainer
#22 lore raw
In reply to Xuan Zhuo

Hi Paolo,

Could you please clarify if this patch set is under embargo?

Also, I noticed that this version is very similar to the previous one. Could you advise on how you would like me to proceed?

Thanks

Quoted 263 lines · Xuan Zhuo

Add a driver framework for EEA that will be available in the future.

This driver is currently quite minimal, implementing only fundamental core functionalities. Key features include: I/O queue management via adminq, basic PCI-layer operations, and essential RX/TX data communication capabilities. It also supports the creation, initialization, and management of network devices (netdev). Furthermore, the ring structures for both I/O queues and adminq have been abstracted into a simple, unified, and reusable library implementation, facilitating future extension and maintenance.

v43:
1. fix the comments from sashiko

v42:
1. fix the comments from Jakub
2. fix the comments from sashiko

v41:
1. make https://sashiko.dev/ happy

v40:
1. fix comments from https://sashiko.dev/

v39:
1. fix comments from https://sashiko.dev/#/patchset/20260407122001.22265-1-xuanzhuo%40linux.alibaba.com

v38:
1. fix comments from https://sashiko.dev/#/patchset/20260404135144.33166-1-xuanzhuo%40linux.alibaba.com

v36:
1. fix comments from https://sashiko.dev/#/patchset/20260323074441.91691-1-xuanzhuo%40linux.alibaba.com

v35:
1. fix comments from https://netdev-ai.bots.linux.dev/ai-review.html?id=24371ffc-a1ea-46e1-a6b3-b8cbcbb52efb

v34:
1. fix the comments from https://sashiko.dev/#/patchset/20260317015257.79494-1-xuanzhuo%40linux.alibaba.com

v33:
1. fix the comments. old version refers enet_bind_new_q_and_cfg, but that is changed to eea_bind_q_and_cfg.

v32:
1. remove unused parameters from eea_net_ha_reset_remove and eea_create_pp
2. call skb_mark_for_recycle for new skb for frag_list skbs

v31:
1. remove unused parameter "enet" from eex_rx_post()

v30:
1. fix some small problems

v29:
Address AI-generated review suggestions from the previous version.

v28:
Address AI-generated review suggestions from the previous version.

v27:
Address AI-generated review suggestions from the previous version.

v26:
Adopting suggestions from the previous AI review, another significant change is the introduction of an IRQ block to implement IRQ proxying. With this design, when an IRQ occurs, we no longer invoke the RX data structure directly -- instead, the IRQ block serves as an intermediary proxy. This approach offers several advantages: IRQ resources no longer need to be reallocated during reset operations, and IRQs are decoupled from RX structures. Consequently, when certain errors occur, we can fall back and safely reuse the original memory resources.

v25:
I have adopted most of the suggestions from the AI's feedback. However, I believe some of the feedback is incorrect. I have already replied in the previous thread. http://lore.kernel.org/all/[email protected]

v24:
1. Add null checks for enet->rx and enet->tx in eea_get_ethtool_stat to prevent errors when reading rx = enet->rx[i] in case enet->rx is null. tx is similar. With rtnl protection in place, this check is sufficient.
2. Use 'received' as the return value in eea_poll.

v23:
I have moved netif_set_real_num_queues() out of eea_start_rxtx(), so eea_start_rxtx() is now a void function. I believe enet_bind_new_q_and_cfg() is a more suitable place to include netif_set_real_num_queues(). In eea_active_ring_and_irq(), I first execute request_irq() before interacting with the hardware to create queues. Therefore, during the NIC setup process, all driver-internal operations (memory allocation, IRQ initialization, sysfs configuration, etc.) will be completed before the final notification to the hardware.

v22:
1. Use the budget from the NAPI poll function as the parameter for napi_consume_skb.
2. Stop the TX queue when the remaining ring slots cannot hold an SKB.

v21:
Fix two issues from the previous version:
1, a DMA unmap operation was missing.
2, RCU APIs were not used in eea_stats. Although the standard practice when
using RCU would require adding the __rcu annotation to both the rx and tx fields, in many cases these fields are read without needing RCU protection. Therefore, I do not want to add the __rcu annotation. Instead, I use a spin lock to protect modifications to rx and tx.

v20:
Fix the partially initialized structure passed to db. @Jakub
http://lore.kernel.org/all/[email protected]

v19:
fix the comments from @Simon Horman

v18:
v17 with [PATCH] prefix.

v17:
1. In eea_adminq_dev_status, uniformly use enet->cfg.rx_ring_num.
2. Add a struct eea_net_cfg *cfg parameter to eea_free_rx and eea_free_tx. When called in the normal path, pass enet->cfg as the argument; when called during initialization, pass the temporary cfg instead.
3. Move the .ndo_get_stats64 callback into eea_net.c.
4. In the .ndo_get_stats64 callback, add a comment explaining how the TX and RX statistics are protected by RCU.

/* This function is protected by RCU. Here uses enet->tx and enet->rx
* to check whether the TX and RX structures are safe to access. In
* eea_free_rxtx_q_mem, before freeing the TX and RX resources, enet->rx
* and enet->tx are set to NULL, and synchronize_net is called. */

v16:
1. follow the advices from @ALOK TIWARI
http://lore.kernel.org/all/[email protected]

v15:
1. remove 'default m' from eea kconfig
2. free the resources when open failed.

v14:
1. some tiny fixes

v13:
1. fix some tiny fixes @Simon

v12:
I encountered some issues with sending the v11 patches, as they were quite messy. Therefore, I'm resending them as v12.

v11:
1. remove auto clean __free(kfree)
2. some tiny fixes

v10:
1. name the jump labels after the target @Jakub
2. rm __GFP_ZERO from dma_alloc_coherent @Jakub
v9:
1. some fixes for ethtool from http://lore.kernel.org/all/[email protected]

v8: 1. rename eea_net_tmp to eea_net_init_ctx
2. rm code that allocs memory to destroy queues
3. some other minor changes

v7: 1. remove the irrelative code from ethtool commit
2. build every commits with W12

v6: Split the big one commit to five commits
v5: Thanks for the comments from Kalesh Anakkur Purayil, ALOK TIWARI
v4: Thanks for the comments from Troy Mitchell, Przemek Kitszel, Andrew Lunn, Kalesh Anakkur Purayil
v3: Thanks for the comments from Paolo Abenchi
v2: Thanks for the comments from Simon Horman and Andrew Lunn
v1: Thanks for the comments from Simon Horman and Andrew Lunn

Xuan Zhuo (8):
eea: introduce PCI framework
eea: introduce ring and descriptor structures
eea: probe the netdevice and create adminq
eea: create/destroy rx,tx queues for netdevice open and stop
eea: implement packet receive logic
eea: implement packet transmit logic
eea: introduce ethtool support
eea: introduce callback for ndo_get_stats64 and register netdev

 MAINTAINERS                                   |   8 +
 drivers/net/ethernet/Kconfig                  |   1 +
 drivers/net/ethernet/Makefile                 |   1 +
 drivers/net/ethernet/alibaba/Kconfig          |  28 +
 drivers/net/ethernet/alibaba/Makefile         |   5 +
 drivers/net/ethernet/alibaba/eea/Makefile     |   9 +
 drivers/net/ethernet/alibaba/eea/eea_adminq.c | 542 +++++++++++
 drivers/net/ethernet/alibaba/eea/eea_adminq.h |  83 ++
 drivers/net/ethernet/alibaba/eea/eea_desc.h   | 138 +++
 .../net/ethernet/alibaba/eea/eea_ethtool.c    | 273 ++++++
 .../net/ethernet/alibaba/eea/eea_ethtool.h    |  48 +
 drivers/net/ethernet/alibaba/eea/eea_net.c    | 887 ++++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_net.h    | 198 ++++
 drivers/net/ethernet/alibaba/eea/eea_pci.c    | 744 +++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_pci.h    |  73 ++
 drivers/net/ethernet/alibaba/eea/eea_ring.c   | 249 +++++
 drivers/net/ethernet/alibaba/eea/eea_ring.h   |  99 ++
 drivers/net/ethernet/alibaba/eea/eea_rx.c     | 814 ++++++++++++++++
 drivers/net/ethernet/alibaba/eea/eea_tx.c     | 500 ++++++++++
 19 files changed, 4700 insertions(+)
 create mode 100644 drivers/net/ethernet/alibaba/Kconfig
 create mode 100644 drivers/net/ethernet/alibaba/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/Makefile
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_adminq.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_desc.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ethtool.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_net.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_pci.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_ring.h
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_rx.c
 create mode 100644 drivers/net/ethernet/alibaba/eea/eea_tx.c

--
2.32.0.3.g01195cf9f

maintainer
#23 lore raw
In reply to Xuan Zhuo
Quoted 10 lines · Xuan Zhuo

Add a driver framework for EEA that will be available in the future.

This driver is currently quite minimal, implementing only fundamental core functionalities. Key features include: I/O queue management via adminq, basic PCI-layer operations, and essential RX/TX data communication capabilities. It also supports the creation, initialization, and management of network devices (netdev). Furthermore, the ring structures for both I/O queues and adminq have been abstracted into a simple, unified, and reusable library implementation, facilitating future extension and maintenance.

I went over all the sashiko feedback and your replies, and I think pending concerns are better handled as follow-up as needed.

Thanks,

Paolo

#24 lore raw
In reply to Xuan Zhuo
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:

Hello:

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

Quoted 11 lines · On Thu, 14 May 2026 17:51:30 +0800 you wrote:

Add a driver framework for EEA that will be available in the future.

This driver is currently quite minimal, implementing only fundamental core functionalities. Key features include: I/O queue management via adminq, basic PCI-layer operations, and essential RX/TX data communication capabilities. It also supports the creation, initialization, and management of network devices (netdev). Furthermore, the ring structures for both I/O queues and adminq have been abstracted into a simple, unified, and reusable library implementation, facilitating future extension and maintenance.

Quoted 1 line

[...]

Here is the summary with links:
- [net-next,v43,1/8] eea: introduce PCI framework

    https://git.kernel.org/netdev/net-next/c/4f68ffc45e94
  - [net-next,v43,2/8] eea: introduce ring and descriptor structures
    https://git.kernel.org/netdev/net-next/c/039ce329dfe6
  - [net-next,v43,3/8] eea: probe the netdevice and create adminq
    https://git.kernel.org/netdev/net-next/c/4c45a51e5bf5
  - [net-next,v43,4/8] eea: create/destroy rx,tx queues for netdevice open and stop
    https://git.kernel.org/netdev/net-next/c/aa8bca4cf200
  - [net-next,v43,5/8] eea: implement packet receive logic
    https://git.kernel.org/netdev/net-next/c/df9cad6baf43
  - [net-next,v43,6/8] eea: implement packet transmit logic
    https://git.kernel.org/netdev/net-next/c/aef5055e9764
  - [net-next,v43,7/8] eea: introduce ethtool support
    https://git.kernel.org/netdev/net-next/c/5f4f7bc0ed11
  - [net-next,v43,8/8] eea: introduce callback for ndo_get_stats64 and register netdev
    https://git.kernel.org/netdev/net-next/c/4e88fb3234c8

You are awesome, thank you!

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