Skip to contentSkip to conversation

net: mana: Add support for the CDX bus

PATCH Applied Manish Awasthi 6 participants 22 messages Sep 24 – Oct 6

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover net: mana: Add support for the CDX bus

This series adds CDX bus support to the MANA driver.

The shared GDMA and Ethernet code currently builds together with the PCI transport. To add another bus without duplicating the driver or adding configuration checks throughout the shared code, this series separates the bus-specific operations and builds each transport independently.

Patch 1 introduces gdma_bus_ops and routes bus-specific interrupt, reset, service, and setup operations through it.

Patch 2 moves the PCI-specific code from gdma_main.c into gdma_pci.c without changing PCI behavior.

Patch 3 builds the shared code as gdma_core.ko and the PCI transport as mana.ko. The PCI module keeps its existing name, device table, and mana.eth/mana.rdma auxiliary-device identities.

Patch 4 adds the CDX transport as mana_cdx.ko for device ID 0x00C2.

Manish Awasthi (4):
net: mana: Introduce gdma_bus_ops for bus-specific operations
net: mana: Move PCI transport code into gdma_pci.c
net: mana: Build the PCI transport as a separate module
net: mana: Add support for CDX device ID 0x00C2

 drivers/net/ethernet/microsoft/Kconfig        |   26 +-
 drivers/net/ethernet/microsoft/Makefile       |    2 +-
 drivers/net/ethernet/microsoft/mana/Makefile  |    9 +-
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |  340 ++++++
 .../net/ethernet/microsoft/mana/gdma_main.c   | 1063 +++--------------
 .../net/ethernet/microsoft/mana/gdma_pci.c    |  917 ++++++++++++++
 drivers/net/ethernet/microsoft/mana/mana_en.c |   18 +-
 include/net/mana/gdma.h                       |  106 +-
 8 files changed, 1552 insertions(+), 929 deletions(-)
 create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_cdx.c
 create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_pci.c

base-commit: 87b80c2f6b05cad9f0ff9136709c62a0f59923e3

Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/4 net: mana: Introduce gdma_bus_ops for bus-specific operations

Introduce per-device gdma_bus_ops for interrupt allocation, IRQ lookup, reset, servicing, and bus-specific capabilities. Route the shared GDMA code through these callbacks and provide the PCI implementation.

Move common device bring-up and teardown into mana_gd_setup() and mana_gd_cleanup(), including hardware-channel initialization, device enumeration, interrupt-pool sizing, and servicing workqueue management. Record the vPort count for transport-specific queue sizing and keep shared IRQ context bookkeeping in the core.

This prepares the driver for additional bus transports without duplicating the core or adding configuration checks throughout it.

---
 .../net/ethernet/microsoft/mana/gdma_main.c   | 907 ++++++++++--------
 drivers/net/ethernet/microsoft/mana/mana_en.c |  10 +-
 include/net/mana/gdma.h                       | 102 +-
 3 files changed, 630 insertions(+), 389 deletions(-)
drivers/net/ethernet/microsoft/mana/gdma_main.c +530 -377
index 8e9bfc1d6a2a..b076760b2dc5 100644
@@ -2,49 +2,42 @@
 /* Copyright (c) 2021, Microsoft Corporation. */
 
 #include <linux/bitfield.h>
+#include <linux/cpumask.h>
 #include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/list.h>
 #include <linux/module.h>
-#include <linux/pci.h>
 #include <linux/sizes.h>
 #include <linux/utsname.h>
 #include <linux/version.h>
 #include <linux/msi.h>
 #include <linux/irqdomain.h>
 #include <linux/export.h>
+#include <linux/pci.h>
+#include <linux/slab.h>
+#include <linux/topology.h>
 #include <linux/uaccess.h>
+#include <linux/xarray.h>
 
 #include <net/mana/mana.h>
 #include <net/mana/hw_channel.h>
 
 struct dentry *mana_debugfs_root;
 
-struct mana_dev_recovery {
-	struct list_head list;
-	struct pci_dev *pdev;
-	enum gdma_eqe_type type;
-};
-
-static struct mana_dev_recovery_work {
-	struct list_head dev_list;
-	struct delayed_work work;
-
-	/* Lock for dev_list above */
-	spinlock_t lock;
-} mana_dev_recovery_work;
-
-static u32 mana_gd_r32(struct gdma_context *g, u64 offset)
+/*
+ * True if the underlying bus can allocate MSI-X vectors after probe time.
+ * Buses that size their vector pool at probe install no callback.
+ */
+static bool mana_gd_msix_can_alloc_dyn(struct gdma_context *gc)
 {
-	return readl(g->bar0_va + offset);
-}
+	if (!gc->bus_ops || !gc->bus_ops->msix_can_alloc_dyn)
+		return false;
 
-static u64 mana_gd_r64(struct gdma_context *g, u64 offset)
-{
-	return readq(g->bar0_va + offset);
+	return gc->bus_ops->msix_can_alloc_dyn(gc);
 }
 
-static int mana_gd_init_pf_regs(struct pci_dev *pdev)
+static int mana_gd_init_pf_regs(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	u64 remaining_barsize;
 	u64 sriov_base_off;
 	u64 sriov_shm_off;
@@ -102,9 +95,8 @@ static int mana_gd_init_pf_regs(struct pci_dev *pdev)
 	return 0;
 }
 
-static int mana_gd_init_vf_regs(struct pci_dev *pdev)
+static int mana_gd_init_vf_regs(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	u64 shm_off;
 
 	gc->db_page_size = mana_gd_r32(gc, GDMA_REG_DB_PAGE_SIZE) & 0xFFFF;
@@ -148,14 +140,12 @@ static int mana_gd_init_vf_regs(struct pci_dev *pdev)
 	return 0;
 }
 
-static int mana_gd_init_registers(struct pci_dev *pdev)
+int mana_gd_init_registers(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
-
 	if (gc->is_pf && !gc->is_pf2)
-		return mana_gd_init_pf_regs(pdev);
+		return mana_gd_init_pf_regs(gc);
 	else
-		return mana_gd_init_vf_regs(pdev);
+		return mana_gd_init_vf_regs(gc);
 }
 
 /* Suppress logging when we set timeout to zero */
@@ -176,9 +166,8 @@ bool mana_need_log(struct gdma_context *gc, int err)
 	return true;
 }
 
-static int mana_gd_query_max_resources(struct pci_dev *pdev)
+int mana_gd_query_max_resources(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	struct gdma_query_max_resources_resp resp = {};
 	struct gdma_general_req req = {};
 	unsigned int max_num_queues;
@@ -194,7 +183,7 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
 	 * MSI-X allocation; on non-dyn platforms msi_sharing is
 	 * unconditionally true (set in mana_gd_setup_hwc_irqs).
 	 */
-	if (pci_msix_can_alloc_dyn(to_pci_dev(gc->dev)))
+	if (mana_gd_msix_can_alloc_dyn(gc))
 		gc->msi_sharing = false;
 
 	mana_gd_init_req_hdr(&req.hdr, GDMA_QUERY_MAX_RESOURCES,
@@ -207,7 +196,11 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
 		return err ? err : -EPROTO;
 	}
 
-	if (!pci_msix_can_alloc_dyn(pdev)) {
+	if (!mana_gd_msix_can_alloc_dyn(gc)) {
+		/* Buses that size their vector pool at probe time cannot grow
+		 * it afterwards, so never raise num_msix_usable above what has
+		 * already been allocated.
+		 */
 		if (gc->num_msix_usable > resp.max_msix)
 			gc->num_msix_usable = resp.max_msix;
 	} else {
@@ -221,20 +214,24 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
 
 	/* MSI-X vectors are allocated by index into the device MSI-X table, so
 	 * never ask for more than the table holds. It can be smaller than both
-	 * resp.max_msix and the CPU count.
+	 * resp.max_msix and the CPU count. A bus that cannot report a table
+	 * size installs no callback and skips the clamp.
 	 */
-	err = pci_msix_vec_count(pdev);
-	if (err <= 0) {
-		dev_err(gc->dev, "Failed to query MSI-X table size: %d\n", err);
-		return err < 0 ? err : -ENOSPC;
-	}
-	msix_vec_count = err;
+	if (gc->bus_ops && gc->bus_ops->msix_vec_count) {
+		err = gc->bus_ops->msix_vec_count(gc);
+		if (err <= 0) {
+			dev_err(gc->dev,
+				"Failed to query MSI-X table size: %d\n", err);
+			return err < 0 ? err : -ENOSPC;
+		}
+		msix_vec_count = err;
 
-	if (gc->num_msix_usable > msix_vec_count) {
-		dev_info(gc->dev,
-			 "Limiting MSI-X vectors from %u to table size %u\n",
-			 gc->num_msix_usable, msix_vec_count);
-		gc->num_msix_usable = msix_vec_count;
+		if (gc->num_msix_usable > msix_vec_count) {
+			dev_info(gc->dev,
+				 "Limiting MSI-X vectors from %u to table size %u\n",
+				 gc->num_msix_usable, msix_vec_count);
+			gc->num_msix_usable = msix_vec_count;
+		}
 	}
 
 	if (gc->num_msix_usable <= 1)
@@ -286,6 +283,8 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
 	if (num_ports > MAX_PORTS_IN_MANA_DEV)
 		num_ports = MAX_PORTS_IN_MANA_DEV;
 
+	gc->num_ports = num_ports;
+
 	/*
 	 * Adjust the per-vPort max queue count to allow dedicated
 	 * MSIx for each vPort. Prefer at least MANA_DEF_NUM_QUEUES,
@@ -317,9 +316,8 @@ static int mana_gd_query_max_resources(struct pci_dev *pdev)
 	return 0;
 }
 
-static int mana_gd_query_hwc_timeout(struct pci_dev *pdev, u32 *timeout_val)
+static int mana_gd_query_hwc_timeout(struct gdma_context *gc, u32 *timeout_val)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	struct gdma_query_hwc_timeout_resp resp = {};
 	struct gdma_query_hwc_timeout_req req = {};
 	int err;
@@ -336,9 +334,8 @@ static int mana_gd_query_hwc_timeout(struct pci_dev *pdev, u32 *timeout_val)
 	return 0;
 }
 
-static int mana_gd_detect_devices(struct pci_dev *pdev)
+int mana_gd_detect_devices(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	struct gdma_list_devices_resp resp = {};
 	struct gdma_general_req req = {};
 	struct gdma_dev_id dev;
@@ -657,187 +654,31 @@ void mana_gd_ring_dim(struct gdma_queue *cq, u32 mod_usec, bool mod_usec_vld,
 }
 EXPORT_SYMBOL_NS(mana_gd_ring_dim, "NET_MANA");
 
-#define MANA_SERVICE_PERIOD 10
-
-static void mana_serv_rescan(struct pci_dev *pdev)
-{
-	struct pci_bus *parent;
-
-	pci_lock_rescan_remove();
-
-	parent = pdev->bus;
-	if (!parent) {
-		dev_err(&pdev->dev, "MANA service: no parent bus\n");
-		goto out;
-	}
-
-	pci_stop_and_remove_bus_device(pdev);
-	pci_rescan_bus(parent);
-
-out:
-	pci_unlock_rescan_remove();
-}
-
-static void mana_serv_fpga(struct pci_dev *pdev)
-{
-	struct pci_bus *bus, *parent;
-
-	pci_lock_rescan_remove();
-
-	bus = pdev->bus;
-	if (!bus) {
-		dev_err(&pdev->dev, "MANA service: no bus\n");
-		goto out;
-	}
-
-	parent = bus->parent;
-	if (!parent) {
-		dev_err(&pdev->dev, "MANA service: no parent bus\n");
-		goto out;
-	}
-
-	pci_stop_and_remove_bus_device(bus->self);
-
-	msleep(MANA_SERVICE_PERIOD * 1000);
-
-	pci_rescan_bus(parent);
-
-out:
-	pci_unlock_rescan_remove();
-}
-
-static void mana_serv_reset(struct pci_dev *pdev)
-{
-	struct gdma_context *gc = pci_get_drvdata(pdev);
-	struct hw_channel_context *hwc;
-	int ret;
-
-	if (!gc) {
-		/* Perform PCI rescan on device if GC is not set up */
-		dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n");
-		mana_serv_rescan(pdev);
-		return;
-	}
-
-	hwc = gc->hwc.driver_data;
-	if (!hwc) {
-		dev_err(&pdev->dev, "MANA service: no HWC\n");
-		goto out;
-	}
-
-	/* HWC is not responding in this case, so don't wait */
-	hwc->hwc_timeout = 0;
-
-	dev_info(&pdev->dev, "MANA reset cycle start\n");
-
-	mana_gd_suspend(pdev, PMSG_SUSPEND);
-
-	msleep(MANA_SERVICE_PERIOD * 1000);
-
-	ret = mana_gd_resume(pdev);
-	if (ret == -ETIMEDOUT || ret == -EPROTO) {
-		/* Perform PCI rescan on device if we failed on HWC */
-		dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n");
-		mana_serv_rescan(pdev);
-		return;
-	}
-
-	if (ret)
-		dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret);
-	else
-		dev_info(&pdev->dev, "MANA reset cycle completed\n");
-
-out:
-	clear_bit(GC_IN_SERVICE, &gc->flags);
-}
-
-static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev)
-{
-	switch (type) {
-	case GDMA_EQE_HWC_FPGA_RECONFIG:
-		mana_serv_fpga(pdev);
-		break;
-
-	case GDMA_EQE_HWC_RESET_REQUEST:
-		mana_serv_reset(pdev);
-		break;
-
-	default:
-		dev_err(&pdev->dev, "MANA service: unknown type %d\n", type);
-		break;
-	}
-}
-
-static void mana_recovery_delayed_func(struct work_struct *w)
-{
-	struct mana_dev_recovery_work *work;
-	struct mana_dev_recovery *dev;
-	unsigned long flags;
-
-	work = container_of(w, struct mana_dev_recovery_work, work.work);
-
-	spin_lock_irqsave(&work->lock, flags);
-
-	while (!list_empty(&work->dev_list)) {
-		dev = list_first_entry(&work->dev_list,
-				       struct mana_dev_recovery, list);
-		list_del(&dev->list);
-		spin_unlock_irqrestore(&work->lock, flags);
-
-		mana_do_service(dev->type, dev->pdev);
-		pci_dev_put(dev->pdev);
-		kfree(dev);
-
-		spin_lock_irqsave(&work->lock, flags);
-	}
-
-	spin_unlock_irqrestore(&work->lock, flags);
-}
-
-static void mana_serv_func(struct work_struct *w)
+/*
+ * Queue device servicing or recovery on buses that support it.
+ *
+ * Servicing tears the device down and brings it back up, so it depends on
+ * bus-level facilities the GDMA core does not have. Buses that provide no
+ * servicing path install no callback and the request is rejected.
+ */
+int mana_schedule_serv_work(struct gdma_context *gc, enum gdma_eqe_type type)
 {
-	struct mana_serv_work *mns_wk;
-	struct pci_dev *pdev;
-
-	mns_wk = container_of(w, struct mana_serv_work, serv_work);
-	pdev = mns_wk->pdev;
-
-	if (pdev)
-		mana_do_service(mns_wk->type, pdev);
+	if (!gc->bus_ops || !gc->bus_ops->schedule_serv_work)
+		return -EOPNOTSUPP;
 
-	pci_dev_put(pdev);
-	kfree(mns_wk);
-	module_put(THIS_MODULE);
+	return gc->bus_ops->schedule_serv_work(gc, type);
 }
 
-int mana_schedule_serv_work(struct gdma_context *gc, enum gdma_eqe_type type)
+/* The servicing workqueue is owned by the GDMA core because the queueing
+ * sites live here and in mana_en.c, which every transport shares. Each bus
+ * driver creates it during setup and destroys it during cleanup.
+ */
+int mana_gd_alloc_service_wq(struct gdma_context *gc)
 {
-	struct mana_serv_work *mns_wk;
-
-	if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) {
-		dev_info(gc->dev, "Already in service\n");
-		return -EBUSY;
-	}
-
-	if (!try_module_get(THIS_MODULE)) {
-		dev_info(gc->dev, "Module is unloading\n");
-		clear_bit(GC_IN_SERVICE, &gc->flags);
-		return -ENODEV;
-	}
-
-	mns_wk = kzalloc_obj(*mns_wk, GFP_ATOMIC);
-	if (!mns_wk) {
-		module_put(THIS_MODULE);
-		clear_bit(GC_IN_SERVICE, &gc->flags);
+	gc->service_wq = alloc_ordered_workqueue("gdma_service_wq", 0);
+	if (!gc->service_wq)
 		return -ENOMEM;
-	}
 
-	dev_info(gc->dev, "Start MANA service type:%d\n", type);
-	mns_wk->pdev = to_pci_dev(gc->dev);
-	mns_wk->type = type;
-	pci_dev_get(mns_wk->pdev);
-	INIT_WORK(&mns_wk->serv_work, mana_serv_func);
-	schedule_work(&mns_wk->serv_work);
 	return 0;
 }
 
@@ -904,6 +745,15 @@ ssize_t mana_gd_read_ring(struct gdma_queue *q, char __user *buf,
 	return copied;
 }
 
+void mana_gd_free_service_wq(struct gdma_context *gc)
+{
+	if (!gc->service_wq)
+		return;
+
+	destroy_workqueue(gc->service_wq);
+	gc->service_wq = NULL;
+}
+
 static void mana_gd_process_eqe(struct gdma_queue *eq)
 {
 	u32 head = eq->head % (eq->queue_size / GDMA_EQE_SIZE);
@@ -975,7 +825,7 @@ static void mana_gd_process_eqe(struct gdma_queue *eq)
 	}
 }
 
-static void mana_gd_process_eq_events(void *arg)
+void mana_gd_process_eq_events(void *arg)
 {
 	u32 owner_bits, new_bits, old_bits;
 	union gdma_eqe_info eqe_info;
@@ -1530,9 +1380,8 @@ void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue)
 }
 EXPORT_SYMBOL_NS(mana_gd_destroy_queue, "NET_MANA");
 
-int mana_gd_verify_vf_version(struct pci_dev *pdev)
+int mana_gd_verify_vf_version(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	struct gdma_verify_ver_resp resp = {};
 	struct gdma_verify_ver_req req = {};
 	struct hw_channel_context *hwc;
@@ -1546,6 +1395,8 @@ int mana_gd_verify_vf_version(struct pci_dev *pdev)
 	req.protocol_ver_max = GDMA_PROTOCOL_LAST;
 
 	req.gd_drv_cap_flags1 = GDMA_DRV_CAP_FLAGS1;
+	if (gc->bus_ops)
+		req.gd_drv_cap_flags1 |= gc->bus_ops->drv_cap_flags1;
 	req.gd_drv_cap_flags2 = GDMA_DRV_CAP_FLAGS2;
 	req.gd_drv_cap_flags3 = GDMA_DRV_CAP_FLAGS3;
 	req.gd_drv_cap_flags4 = GDMA_DRV_CAP_FLAGS4;
@@ -1574,7 +1425,7 @@ int mana_gd_verify_vf_version(struct pci_dev *pdev)
 			   &gc->pf_cap_flags1);
 
 	if (resp.pf_cap_flags1 & GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG) {
-		err = mana_gd_query_hwc_timeout(pdev, &hwc->hwc_timeout);
+		err = mana_gd_query_hwc_timeout(gc, &hwc->hwc_timeout);
 		if (err) {
 			dev_err(gc->dev, "Failed to set the hwc timeout %d\n", err);
 			return err;
@@ -1873,7 +1724,7 @@ int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe)
 }
 EXPORT_SYMBOL_NS(mana_gd_poll_cq, "NET_MANA");
 
-static irqreturn_t mana_gd_intr(int irq, void *arg)
+irqreturn_t mana_gd_intr(int irq, void *arg)
 {
 	struct gdma_irq_context *gic = arg;
 	struct list_head *eq_list = &gic->eq_list;
@@ -1888,11 +1739,25 @@ static irqreturn_t mana_gd_intr(int irq, void *arg)
 	return IRQ_HANDLED;
 }
 
+/*
+ * Reset the device using whatever mechanism the bus provides.
+ */
+int mana_gd_dev_reset(struct gdma_context *gc)
+{
+	if (!gc->bus_ops || !gc->bus_ops->dev_reset)
+		return -EOPNOTSUPP;
+
+	return gc->bus_ops->dev_reset(gc);
+}
+
+/*
+ * Release a reference on the IRQ context backing an MSI vector, freeing
+ * the vector once the last user is gone.
+ */
 void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi)
 {
-	struct pci_dev *dev = to_pci_dev(gc->dev);
+	const struct gdma_bus_ops *ops = gc->bus_ops;
 	struct gdma_irq_context *gic;
-	struct msi_map irq_map;
 	int irq;
 
 	mutex_lock(&gc->gic_mutex);
@@ -1917,11 +1782,8 @@ void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi)
 	irq_update_affinity_hint(irq, NULL);
 	free_irq(irq, gic);
 
-	if (gic->dyn_msix) {
-		irq_map.virq = irq;
-		irq_map.index = msi;
-		pci_msix_free_irq(dev, irq_map);
-	}
+	if (gic->dyn_msix)
+		ops->msix_free(gc, msi, irq);
 
 	xa_erase(&gc->irq_contexts, msi);
 	kfree(gic);
@@ -1944,12 +1806,10 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
 					 bool use_msi_bitmap,
 					 int *msi_requested)
 {
-	struct pci_dev *dev = to_pci_dev(gc->dev);
+	const struct gdma_bus_ops *ops = gc->bus_ops;
 	struct gdma_irq_context *gic;
-	struct msi_map irq_map = { };
-	int irq;
-	int msi;
-	int err;
+	bool dyn_msix = false;
+	int msi, irq, err;
 
 	mutex_lock(&gc->gic_mutex);
 
@@ -1975,27 +1835,34 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
 		goto out;
 	}
 
-	irq = pci_irq_vector(dev, msi);
+	irq = ops->msix_virq(gc, msi);
 	if (irq == -EINVAL) {
-		irq_map = pci_msix_alloc_irq_at(dev, msi, NULL);
-		if (!irq_map.virq) {
-			err = irq_map.index;
-			dev_err(gc->dev,
-				"Failed to alloc irq_map msi %d err %d\n",
-				msi, err);
-			gic = ERR_PTR(err);
+		/* A bus that sizes its vector pool up front has nothing left
+		 * to hand out once every vector has been claimed.
+		 */
+		if (!ops->msix_alloc_at) {
+			dev_err(gc->dev, "No IRQ for MSI %d\n", msi);
+			gic = ERR_PTR(-ENOENT);
+			goto out;
+		}
+
+		irq = ops->msix_alloc_at(gc, &msi);
+		if (irq < 0) {
+			dev_err(gc->dev, "Failed to alloc irq msi %d err %d\n",
+				*msi_requested, irq);
+			gic = ERR_PTR(irq);
 			goto out;
 		}
-		irq = irq_map.virq;
-		msi = irq_map.index;
+
+		dyn_msix = true;
 		*msi_requested = msi;
 	}
 
 	gic = kzalloc_obj(*gic);
 	if (!gic) {
 		gic = ERR_PTR(-ENOMEM);
-		if (irq_map.virq)
-			pci_msix_free_irq(dev, irq_map);
+		if (dyn_msix)
+			ops->msix_free(gc, msi, irq);
 		goto out;
 	}
 
@@ -2006,11 +1873,11 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
 	spin_lock_init(&gic->lock);
 
 	if (!gic->msi)
-		snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@pci:%s",
-			 pci_name(dev));
+		snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_hwc@%s:%s",
+			 ops->bus_name, dev_name(gc->dev));
 	else
-		snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_msi%d@pci:%s",
-			 gic->msi, pci_name(dev));
+		snprintf(gic->name, MANA_IRQ_NAME_SZ, "mana_msi%d@%s:%s",
+			 gic->msi, ops->bus_name, dev_name(gc->dev));
 
 	err = request_irq(irq, mana_gd_intr, 0, gic->name, gic);
 	if (err) {
@@ -2018,12 +1885,12 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
 			irq, gic->name);
 		kfree(gic);
 		gic = ERR_PTR(err);
-		if (irq_map.virq)
-			pci_msix_free_irq(dev, irq_map);
+		if (dyn_msix)
+			ops->msix_free(gc, msi, irq);
 		goto out;
 	}
 
-	gic->dyn_msix = !!irq_map.virq;
+	gic->dyn_msix = dyn_msix;
 	refcount_set(&gic->refcount, 1);
 	gic->bitmap_refs = use_msi_bitmap ? 1 : 0;
 
@@ -2034,8 +1901,8 @@ struct gdma_irq_context *mana_gd_get_gic(struct gdma_context *gc,
 		free_irq(irq, gic);
 		kfree(gic);
 		gic = ERR_PTR(err);
-		if (irq_map.virq)
-			pci_msix_free_irq(dev, irq_map);
+		if (dyn_msix)
+			ops->msix_free(gc, msi, irq);
 		goto out;
 	}
 
@@ -2067,20 +1934,340 @@ void mana_gd_free_res_map(struct gdma_resource *r)
 	r->size = 0;
 }
 
-/*
- * Spread on CPUs with the following heuristics:
- *
- * 1. No more than one IRQ per CPU, if possible;
- * 2. NUMA locality is the second priority;
- * 3. Sibling dislocality is the last priority.
- *
- * Let's consider this topology:
- *
- * Node            0               1
- * Core        0       1       2       3
- * CPU       0   1   2   3   4   5   6   7
- *
- * The most performant IRQ distribution based on the above topology
+/* Bring up the GDMA context on a probed device: create the debugfs directory,
+ * map the shared-memory registers, start the hardware channel and size the
+ * interrupt pool. Every step here is common to all buses; the ones that are
+ * not are reached through gdma_bus_ops.
+ */
+int mana_gd_setup(struct gdma_context *gc)
+{
+	int err;
+
+	gc->mana_pci_debugfs = debugfs_create_dir(dev_name(gc->dev),
+						  mana_debugfs_root);
+
+	err = mana_gd_init_registers(gc);
+	if (err)
+		goto remove_debugfs;
+
+	mana_smc_init(&gc->shm_channel, gc->dev, gc->shm_base);
+
+	err = mana_gd_alloc_service_wq(gc);
+	if (err)
+		goto remove_debugfs;
+
+	err = gc->bus_ops->setup_hwc_irqs(gc);
+	if (err) {
+		dev_err(gc->dev, "Failed to setup IRQs for HWC creation: %d\n",
+			err);
+		goto free_workqueue;
+	}
+
+	err = mana_hwc_create_channel(gc);
+	if (err)
+		goto remove_irq;
+
+	err = mana_gd_verify_vf_version(gc);
+	if (err)
+		goto destroy_hwc;
+
+	err = mana_gd_detect_devices(gc);
+	if (err)
+		goto destroy_hwc;
+
+	err = mana_gd_query_max_resources(gc);
+	if (err)
+		goto destroy_hwc;
+
+	err = gc->bus_ops->setup_remaining_irqs(gc);
+	if (err)
+		goto destroy_hwc;
+
+	dev_dbg(gc->dev, "mana gdma setup successful\n");
+	return 0;
+
+destroy_hwc:
+	mana_hwc_destroy_channel(gc);
+remove_irq:
+	gc->bus_ops->remove_irqs(gc);
+free_workqueue:
+	mana_gd_free_service_wq(gc);
+remove_debugfs:
+	debugfs_remove_recursive(gc->mana_pci_debugfs);
+	gc->mana_pci_debugfs = NULL;
+	dev_err(gc->dev, "%s failed (error %d)\n", __func__, err);
+	return err;
+}
+
+void mana_gd_cleanup(struct gdma_context *gc)
+{
+	mana_hwc_destroy_channel(gc);
+
+	gc->bus_ops->remove_irqs(gc);
+
+	mana_gd_free_service_wq(gc);
+
+	debugfs_remove_recursive(gc->mana_pci_debugfs);
+	gc->mana_pci_debugfs = NULL;
+
+	dev_dbg(gc->dev, "mana gdma cleanup successful\n");
+}
+
+struct mana_dev_recovery {
+	struct list_head list;
+	struct pci_dev *pdev;
+	enum gdma_eqe_type type;
+};
+
+static struct mana_dev_recovery_work {
+	struct list_head dev_list;
+	struct delayed_work work;
+
+	/* Lock for dev_list above */
+	spinlock_t lock;
+} mana_dev_recovery_work;
+
+static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state);
+static int mana_gd_resume(struct pci_dev *pdev);
+
+#define MANA_SERVICE_PERIOD 10
+
+static void mana_serv_rescan(struct pci_dev *pdev)
+{
+	struct pci_bus *parent;
+
+	pci_lock_rescan_remove();
+
+	parent = pdev->bus;
+	if (!parent) {
+		dev_err(&pdev->dev, "MANA service: no parent bus\n");
+		goto out;
+	}
+
+	pci_stop_and_remove_bus_device(pdev);
+	pci_rescan_bus(parent);
+
+out:
+	pci_unlock_rescan_remove();
+}
+
+static void mana_serv_fpga(struct pci_dev *pdev)
+{
+	struct pci_bus *bus, *parent;
+
+	pci_lock_rescan_remove();
+
+	bus = pdev->bus;
+	if (!bus) {
+		dev_err(&pdev->dev, "MANA service: no bus\n");
+		goto out;
+	}
+
+	parent = bus->parent;
+	if (!parent) {
+		dev_err(&pdev->dev, "MANA service: no parent bus\n");
+		goto out;
+	}
+
+	pci_stop_and_remove_bus_device(bus->self);
+
+	msleep(MANA_SERVICE_PERIOD * 1000);
+
+	pci_rescan_bus(parent);
+
+out:
+	pci_unlock_rescan_remove();
+}
+
+static void mana_serv_reset(struct pci_dev *pdev)
+{
+	struct gdma_context *gc = pci_get_drvdata(pdev);
+	struct hw_channel_context *hwc;
+	int ret;
+
+	if (!gc) {
+		/* Perform PCI rescan on device if GC is not set up */
+		dev_err(&pdev->dev, "MANA service: GC not setup, rescanning\n");
+		mana_serv_rescan(pdev);
+		return;
+	}
+
+	hwc = gc->hwc.driver_data;
+	if (!hwc) {
+		dev_err(&pdev->dev, "MANA service: no HWC\n");
+		goto out;
+	}
+
+	/* HWC is not responding in this case, so don't wait */
+	hwc->hwc_timeout = 0;
+
+	dev_info(&pdev->dev, "MANA reset cycle start\n");
+
+	mana_gd_suspend(pdev, PMSG_SUSPEND);
+
+	msleep(MANA_SERVICE_PERIOD * 1000);
+
+	ret = mana_gd_resume(pdev);
+	if (ret == -ETIMEDOUT || ret == -EPROTO) {
+		/* Perform PCI rescan on device if we failed on HWC */
+		dev_err(&pdev->dev, "MANA service: resume failed, rescanning\n");
+		mana_serv_rescan(pdev);
+		return;
+	}
+
+	if (ret)
+		dev_info(&pdev->dev, "MANA reset cycle failed err %d\n", ret);
+	else
+		dev_info(&pdev->dev, "MANA reset cycle completed\n");
+
+out:
+	clear_bit(GC_IN_SERVICE, &gc->flags);
+}
+
+static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev)
+{
+	switch (type) {
+	case GDMA_EQE_HWC_FPGA_RECONFIG:
+		mana_serv_fpga(pdev);
+		break;
+
+	case GDMA_EQE_HWC_RESET_REQUEST:
+		mana_serv_reset(pdev);
+		break;
+
+	default:
+		dev_err(&pdev->dev, "MANA service: unknown type %d\n", type);
+		break;
+	}
+}
+
+static void mana_recovery_delayed_func(struct work_struct *w)
+{
+	struct mana_dev_recovery_work *work;
+	struct mana_dev_recovery *dev;
+	unsigned long flags;
+
+	work = container_of(w, struct mana_dev_recovery_work, work.work);
+
+	spin_lock_irqsave(&work->lock, flags);
+
+	while (!list_empty(&work->dev_list)) {
+		dev = list_first_entry(&work->dev_list,
+				       struct mana_dev_recovery, list);
+		list_del(&dev->list);
+		spin_unlock_irqrestore(&work->lock, flags);
+
+		mana_do_service(dev->type, dev->pdev);
+		pci_dev_put(dev->pdev);
+		kfree(dev);
+
+		spin_lock_irqsave(&work->lock, flags);
+	}
+
+	spin_unlock_irqrestore(&work->lock, flags);
+}
+
+static void mana_serv_func(struct work_struct *w)
+{
+	struct mana_serv_work *mns_wk;
+	struct pci_dev *pdev;
+
+	mns_wk = container_of(w, struct mana_serv_work, serv_work);
+	pdev = mns_wk->pdev;
+
+	if (pdev)
+		mana_do_service(mns_wk->type, pdev);
+
+	pci_dev_put(pdev);
+	kfree(mns_wk);
+	module_put(THIS_MODULE);
+}
+
+static int mana_pci_schedule_serv_work(struct gdma_context *gc,
+				       enum gdma_eqe_type type)
+{
+	struct mana_serv_work *mns_wk;
+
+	if (test_and_set_bit(GC_IN_SERVICE, &gc->flags)) {
+		dev_info(gc->dev, "Already in service\n");
+		return -EBUSY;
+	}
+
+	if (!try_module_get(THIS_MODULE)) {
+		dev_info(gc->dev, "Module is unloading\n");
+		clear_bit(GC_IN_SERVICE, &gc->flags);
+		return -ENODEV;
+	}
+
+	mns_wk = kzalloc(sizeof(*mns_wk), GFP_ATOMIC);
+	if (!mns_wk) {
+		module_put(THIS_MODULE);
+		clear_bit(GC_IN_SERVICE, &gc->flags);
+		return -ENOMEM;
+	}
+
+	dev_info(gc->dev, "Start MANA service type:%d\n", type);
+	mns_wk->pdev = to_pci_dev(gc->dev);
+	mns_wk->type = type;
+	pci_dev_get(mns_wk->pdev);
+	INIT_WORK(&mns_wk->serv_work, mana_serv_func);
+	schedule_work(&mns_wk->serv_work);
+	return 0;
+}
+
+static bool mana_pci_msix_can_alloc_dyn(struct gdma_context *gc)
+{
+	return pci_msix_can_alloc_dyn(to_pci_dev(gc->dev));
+}
+
+static int mana_pci_msix_virq(struct gdma_context *gc, int msi)
+{
+	return pci_irq_vector(to_pci_dev(gc->dev), msi);
+}
+
+static int mana_pci_msix_alloc_at(struct gdma_context *gc, int *msi)
+{
+	struct msi_map irq_map;
+
+	irq_map = pci_msix_alloc_irq_at(to_pci_dev(gc->dev), *msi, NULL);
+	if (!irq_map.virq)
+		return irq_map.index;
+
+	*msi = irq_map.index;
+	return irq_map.virq;
+}
+
+static void mana_pci_msix_free(struct gdma_context *gc, int msi, int irq)
+{
+	struct msi_map irq_map = { .virq = irq, .index = msi };
+
+	pci_msix_free_irq(to_pci_dev(gc->dev), irq_map);
+}
+
+static int mana_pci_msix_vec_count(struct gdma_context *gc)
+{
+	return pci_msix_vec_count(to_pci_dev(gc->dev));
+}
+
+static int mana_pci_dev_reset(struct gdma_context *gc)
+{
+	return pcie_flr(to_pci_dev(gc->dev));
+}
+
+/*
+ * Spread on CPUs with the following heuristics:
+ *
+ * 1. No more than one IRQ per CPU, if possible;
+ * 2. NUMA locality is the second priority;
+ * 3. Sibling dislocality is the last priority.
+ *
+ * Let's consider this topology:
+ *
+ * Node            0               1
+ * Core        0       1       2       3
+ * CPU       0   1   2   3   4   5   6   7
+ *
+ * The most performant IRQ distribution based on the above topology
  * and heuristics may look like this:
  *
  * IRQ     Nodes   Cores   CPUs
@@ -2396,101 +2583,52 @@ static void mana_gd_remove_irqs(struct pci_dev *pdev)
 	gc->num_msix_usable = 0;
 }
 
-static int mana_gd_setup(struct pci_dev *pdev)
+static int mana_pci_setup_hwc_irqs(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
-	int err;
-
-	gc->mana_pci_debugfs = debugfs_create_dir(pci_name(pdev),
-						  mana_debugfs_root);
-
-	err = mana_gd_init_registers(pdev);
-	if (err)
-		goto remove_debugfs;
-
-	mana_smc_init(&gc->shm_channel, gc->dev, gc->shm_base);
-
-	gc->service_wq = alloc_ordered_workqueue("gdma_service_wq", 0);
-	if (!gc->service_wq) {
-		err = -ENOMEM;
-		goto remove_debugfs;
-	}
-
-	err = mana_gd_setup_hwc_irqs(pdev);
-	if (err) {
-		dev_err(gc->dev, "Failed to setup IRQs for HWC creation: %d\n",
-			err);
-		goto free_workqueue;
-	}
-
-	err = mana_hwc_create_channel(gc);
-	if (err)
-		goto remove_irq;
-
-	err = mana_gd_verify_vf_version(pdev);
-	if (err)
-		goto destroy_hwc;
-
-	err = mana_gd_detect_devices(pdev);
-	if (err)
-		goto destroy_hwc;
+	return mana_gd_setup_hwc_irqs(to_pci_dev(gc->dev));
+}
 
-	err = mana_gd_query_max_resources(pdev);
-	if (err)
-		goto destroy_hwc;
+static int mana_pci_setup_remaining_irqs(struct gdma_context *gc)
+{
+	int err;
 
-	err = mana_gd_setup_remaining_irqs(pdev);
+	err = mana_gd_setup_remaining_irqs(to_pci_dev(gc->dev));
 	if (err) {
 		dev_err(gc->dev, "Failed to setup remaining IRQs: %d", err);
-		goto destroy_hwc;
+		return err;
 	}
 
 	if (!gc->msi_sharing) {
 		gc->msi_bitmap = bitmap_zalloc(gc->num_msix_usable, GFP_KERNEL);
-		if (!gc->msi_bitmap) {
-			err = -ENOMEM;
-			goto destroy_hwc;
-		}
+		if (!gc->msi_bitmap)
+			return -ENOMEM;
 		/* Set bit for HWC */
 		set_bit(0, gc->msi_bitmap);
 	}
 
-	dev_dbg(&pdev->dev, "mana gdma setup successful\n");
 	return 0;
-
-destroy_hwc:
-	mana_hwc_destroy_channel(gc);
-remove_irq:
-	mana_gd_remove_irqs(pdev);
-free_workqueue:
-	destroy_workqueue(gc->service_wq);
-	gc->service_wq = NULL;
-remove_debugfs:
-	debugfs_remove_recursive(gc->mana_pci_debugfs);
-	gc->mana_pci_debugfs = NULL;
-	dev_err(&pdev->dev, "%s failed (error %d)\n", __func__, err);
-	return err;
 }
 
-static void mana_gd_cleanup_device(struct pci_dev *pdev)
+static void mana_pci_remove_irqs(struct gdma_context *gc)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
-
-	mana_hwc_destroy_channel(gc);
-
-	mana_gd_remove_irqs(pdev);
-
-	if (gc->service_wq) {
-		destroy_workqueue(gc->service_wq);
-		gc->service_wq = NULL;
-	}
-
-	debugfs_remove_recursive(gc->mana_pci_debugfs);
-	gc->mana_pci_debugfs = NULL;
-
-	dev_dbg(&pdev->dev, "mana gdma cleanup successful\n");
+	mana_gd_remove_irqs(to_pci_dev(gc->dev));
 }
 
+static const struct gdma_bus_ops mana_pci_bus_ops = {
+	.bus_name		= "pci",
+	.msix_can_alloc_dyn	= mana_pci_msix_can_alloc_dyn,
+	.msix_virq		= mana_pci_msix_virq,
+	.msix_alloc_at		= mana_pci_msix_alloc_at,
+	.msix_free		= mana_pci_msix_free,
+	.msix_vec_count		= mana_pci_msix_vec_count,
+	.setup_hwc_irqs		= mana_pci_setup_hwc_irqs,
+	.setup_remaining_irqs	= mana_pci_setup_remaining_irqs,
+	.remove_irqs		= mana_pci_remove_irqs,
+	.dev_reset		= mana_pci_dev_reset,
+	.schedule_serv_work	= mana_pci_schedule_serv_work,
+	.drv_cap_flags1		= GDMA_DRV_CAP_FLAGS1_PCI,
+};
+
 static bool mana_is_pf(unsigned short dev_id)
 {
 	return dev_id == MANA_PF_DEVICE_ID || dev_id == MANA_PF2_DEVICE_ID;
@@ -2546,9 +2684,10 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	gc->bar0_va = bar0_va;
 	gc->dev = &pdev->dev;
+	gc->bus_ops = &mana_pci_bus_ops;
 	xa_init(&gc->irq_contexts);
 
-	err = mana_gd_setup(pdev);
+	err = mana_gd_setup(gc);
 	if (err)
 		goto unmap_bar;
 
@@ -2576,7 +2715,7 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 cleanup_mana:
 	mana_remove(&gc->mana, false);
 cleanup_gd:
-	mana_gd_cleanup_device(pdev);
+	mana_gd_cleanup(gc);
 unmap_bar:
 	xa_destroy(&gc->irq_contexts);
 	pci_iounmap(pdev, bar0_va);
@@ -2629,7 +2768,7 @@ static void mana_gd_remove(struct pci_dev *pdev)
 	mana_rdma_remove(&gc->mana_ib);
 	mana_remove(&gc->mana, false);
 
-	mana_gd_cleanup_device(pdev);
+	mana_gd_cleanup(gc);
 
 	xa_destroy(&gc->irq_contexts);
 
@@ -2644,24 +2783,24 @@ static void mana_gd_remove(struct pci_dev *pdev)
 }
 
 /* The 'state' parameter is not used. */
-int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state)
+static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state)
 {
 	struct gdma_context *gc = pci_get_drvdata(pdev);
 
 	mana_rdma_remove(&gc->mana_ib);
 	mana_remove(&gc->mana, true);
 
-	mana_gd_cleanup_device(pdev);
+	mana_gd_cleanup(gc);
 
 	return 0;
 }
 
-int mana_gd_resume(struct pci_dev *pdev)
+static int mana_gd_resume(struct pci_dev *pdev)
 {
 	struct gdma_context *gc = pci_get_drvdata(pdev);
 	int err;
 
-	err = mana_gd_setup(pdev);
+	err = mana_gd_setup(gc);
 	if (err)
 		return err;
 
@@ -2676,7 +2815,7 @@ int mana_gd_resume(struct pci_dev *pdev)
 	return err;
 
 cleanup_gd:
-	mana_gd_cleanup_device(pdev);
+	mana_gd_cleanup(gc);
 	return err;
 }
 
@@ -2690,7 +2829,7 @@ static void mana_gd_shutdown(struct pci_dev *pdev)
 	mana_rdma_remove(&gc->mana_ib);
 	mana_remove(&gc->mana, true);
 
-	mana_gd_cleanup_device(pdev);
+	mana_gd_cleanup(gc);
 
 	pci_disable_device(pdev);
 }
@@ -2734,26 +2873,19 @@ static struct pci_driver mana_driver = {
 	.sriov_configure = mana_sriov_configure,
 };
 
-static int __init mana_driver_init(void)
-{
-	int err;
+MODULE_DEVICE_TABLE(pci, mana_id_table);
 
+static int mana_pci_driver_register(void)
+{
 	INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list);
 	spin_lock_init(&mana_dev_recovery_work.lock);
-	INIT_DELAYED_WORK(&mana_dev_recovery_work.work, mana_recovery_delayed_func);
-
-	mana_debugfs_root = debugfs_create_dir("mana", NULL);
-
-	err = pci_register_driver(&mana_driver);
-	if (err) {
-		debugfs_remove(mana_debugfs_root);
-		mana_debugfs_root = NULL;
-	}
+	INIT_DELAYED_WORK(&mana_dev_recovery_work.work,
+			  mana_recovery_delayed_func);
 
-	return err;
+	return pci_register_driver(&mana_driver);
 }
 
-static void __exit mana_driver_exit(void)
+static void mana_pci_driver_unregister(void)
 {
 	struct mana_dev_recovery *dev;
 	unsigned long flags;
@@ -2771,6 +2903,29 @@ static void __exit mana_driver_exit(void)
 	spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags);
 
 	pci_unregister_driver(&mana_driver);
+}
+
+static int __init mana_driver_init(void)
+{
+	int err;
+
+	mana_debugfs_root = debugfs_create_dir("mana", NULL);
+
+	err = mana_pci_driver_register();
+	if (err)
+		goto err_debugfs;
+
+	return 0;
+
+err_debugfs:
+	debugfs_remove(mana_debugfs_root);
+	mana_debugfs_root = NULL;
+	return err;
+}
+
+static void __exit mana_driver_exit(void)
+{
+	mana_pci_driver_unregister();
 
 	debugfs_remove(mana_debugfs_root);
 
@@ -2780,7 +2935,5 @@ static void __exit mana_driver_exit(void)
 module_init(mana_driver_init);
 module_exit(mana_driver_exit);
 
-MODULE_DEVICE_TABLE(pci, mana_id_table);
-
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver");
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -4
index 591fb4191d90..62b89b3d6072 100644
@@ -9,7 +9,6 @@
 #include <linux/ethtool.h>
 #include <linux/filter.h>
 #include <linux/mm.h>
-#include <linux/pci.h>
 #include <linux/export.h>
 #include <linux/skbuff.h>
 
@@ -20,6 +19,7 @@
 #include <net/xdp.h>
 
 #include <net/mana/mana.h>
+
 #include <net/mana/mana_auxiliary.h>
 #include <net/mana/hw_channel.h>
 
@@ -3725,10 +3725,9 @@ static int mana_dealloc_queues(struct net_device *ndev)
 				tsleep <<= 1;
 			}
 			if (atomic_read(&txq->pending_sends)) {
-				err =
-				    pcie_flr(to_pci_dev(gd->gdma_context->dev));
+				err = mana_gd_dev_reset(gd->gdma_context);
 				if (err) {
-					netdev_err(ndev, "flr failed %d with %d pkts pending in txq %u\n",
+					netdev_err(ndev, "device reset failed %d with %d pkts pending in txq %u\n",
 						   err,
 					    atomic_read(&txq->pending_sends),
 					    txq->gdma_txq_id);
@@ -4031,6 +4030,9 @@ int mana_rdma_service_event(struct gdma_context *gc, enum gdma_service_type even
 		return 0;
 	}
 
+	if (!gc->service_wq)
+		return -EOPNOTSUPP;
+
 	serv_work = kzalloc_obj(*serv_work, GFP_ATOMIC);
 	if (!serv_work)
 		return -ENOMEM;
include/net/mana/gdma.h +94 -8

154 lines not on this page · raw message

Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH net-next 1/4] net: mana: Introduce gdma_bus_ops for bus-specific operations

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

Introduce per-device gdma_bus_ops for interrupt allocation, IRQ lookup, reset, servicing, and bus-specific capabilities. Route the shared GDMA code through these callbacks and provide the PCI implementation.

Move common device bring-up and teardown into mana_gd_setup() and mana_gd_cleanup(), including hardware-channel initialization, device enumeration, interrupt-pool sizing, and servicing workqueue management. Record the vPort count for transport-specific queue sizing and keep shared IRQ context bookkeeping in the core.

Quoted 4 lines

This prepares the driver for additional bus transports without duplicating the core or adding configuration checks throughout it.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH net-next 1/4] net: mana: Introduce gdma_bus_ops for bus-specific operations

In reply to Manish Awasthi
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] mana_rdma_service_event() (mana_en.c:4033) gains if (!gc->service_wq) return -EOPNOTSUPP;, and the commit message does…
- [Low] The comment added above mana_gd_put_gic() (gdma_main.c:1754-1755) says it frees 'the vector once the last user is gone'.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but PCI reset servicing is not serialized against device unbind or removal.
- [Medium] This problem wasn't introduced by this patch, but mana_dealloc_queues() calls mana_gd_dev_reset() (mana_en.c:3728) when…

--

net: mana: Introduce gdma_bus_ops for bus-specific operations

This commit adds a per-device gdma_bus_ops table. The shared GDMA core now reaches interrupt allocation, IRQ lookup, device reset, servicing and bus-specific capability bits through these callbacks, and the commit provides a PCI implementation. It also moves common bring-up and teardown, including the servicing workqueue, into mana_gd_setup() and mana_gd_cleanup().

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -0
index 8e9bfc1d6a2ae..b076760b2dc50 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -0
@@ -1888,11 +1739,25 @@ static irqreturn_t mana_gd_intr(int irq, void *arg)

[ ... ]

Quoted 6 lines

+/*
+ * Release a reference on the IRQ context backing an MSI vector, freeing
+ * the vector once the last user is gone.
+ */
void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi) {

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_main.c void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi) · line 1786

Quoted 11 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +2 -5
@@ -1917,11 +1782,8 @@ void mana_gd_put_gic(struct gdma_context *gc, bool use_msi_bitmap, int msi)
 	irq_update_affinity_hint(irq, NULL);
 	free_irq(irq, gic);
 
-	if (gic->dyn_msix) {
-		irq_map.virq = irq;
-		irq_map.index = msi;
-		pci_msix_free_irq(dev, irq_map);
-	}
+	if (gic->dyn_msix)
+		ops->msix_free(gc, msi, irq);

[Severity: Low]
This isn't a bug, but is the new comment above mana_gd_put_gic() accurate?

On the last reference, free_irq() always runs. The vector itself is released through ops->msix_free() only when gic->dyn_msix is set.

Preallocated vectors, such as in the non-dynamic PCI case, stay allocated until the bus remove_irqs callback tears them down in bulk. Would wording like "freeing the IRQ, and the vector if it was allocated dynamically" be closer to what the code does?

[ ... ]

Quoted 1 line
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -0
@@ -2067,20 +1934,340 @@ void mana_gd_free_res_map(struct gdma_resource *r)

[ ... ]

Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +5 -0
+static void mana_serv_reset(struct pci_dev *pdev)
+{
+	struct gdma_context *gc = pci_get_drvdata(pdev);
+	struct hw_channel_context *hwc;
+	int ret;

[ ... ]

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +10 -0
+	/* HWC is not responding in this case, so don't wait */
+	hwc->hwc_timeout = 0;
+
+	dev_info(&pdev->dev, "MANA reset cycle start\n");
+
+	mana_gd_suspend(pdev, PMSG_SUSPEND);
+
+	msleep(MANA_SERVICE_PERIOD * 1000);
+
+	ret = mana_gd_resume(pdev);

[ ... ]

Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +3 -0
+out:
+	clear_bit(GC_IN_SERVICE, &gc->flags);
+}

[ ... ]

Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +3 -0
+static int mana_pci_schedule_serv_work(struct gdma_context *gc,
+				       enum gdma_eqe_type type)
+{

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_main.c void mana_gd_free_res_map(struct gdma_resource *r) · line 2216

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +4 -0
+	INIT_WORK(&mns_wk->serv_work, mana_serv_func);
+	schedule_work(&mns_wk->serv_work);
+	return 0;
+}

[Severity: High]
This is a pre-existing issue, since this patch only moves and renames the code, but is this servicing work serialized against device removal?

mana_pci_schedule_serv_work() queues mana_serv_func() on the system workqueue. It holds only a pci_dev reference and a module reference, and neither of those keeps the vzalloc'd gdma_context alive.

The worker then runs:

mana_serv_func()
mana_do_service()

    mana_serv_reset()
      gc = pci_get_drvdata(pdev)
      hwc->hwc_timeout = 0
      mana_gd_suspend()
      msleep(MANA_SERVICE_PERIOD * 1000)
      mana_gd_resume()
      clear_bit(GC_IN_SERVICE, &gc->flags)

It holds neither device_lock() nor pci_lock_rescan_remove() at any point in that sequence.

mana_gd_remove() does not flush or cancel this work, and it does not check GC_IN_SERVICE before freeing gc:

mana_gd_remove() {
    ...
	mana_gd_cleanup(gc);

	xa_destroy(&gc->irq_contexts);

	pci_iounmap(pdev, gc->bar0_va);

	vfree(gc);
    ...
}

Suppose a sysfs unbind or a vPCI hot-remove happens during the 10 second sleep. Could mana_gd_resume() then read NULL drvdata and dereference it in mana_gd_setup(gc), or use the freed gc? The clear_bit() that follows would also write into freed memory.

Destroying gc->service_wq in mana_gd_cleanup() doesn't drain this worker, because the work runs on the system workqueue.

The later patch "net: mana: Move PCI transport code into gdma_pci.c" moves this code unchanged, so the race is still present at the end of the series.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +0 -0
index 591fb4191d90d..62b89b3d60729 100644

[ ... ]

drivers/net/ethernet/microsoft/mana/mana_en.c static int mana_dealloc_queues(struct net_device *ndev) · line 3733

Quoted 13 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +2 -3
@@ -3725,10 +3725,9 @@ static int mana_dealloc_queues(struct net_device *ndev)
 				tsleep <<= 1;
 			}
 			if (atomic_read(&txq->pending_sends)) {
-				err =
-				    pcie_flr(to_pci_dev(gd->gdma_context->dev));
+				err = mana_gd_dev_reset(gd->gdma_context);
 				if (err) {
-					netdev_err(ndev, "flr failed %d with %d pkts pending in txq %u\n",
+					netdev_err(ndev, "device reset failed %d with %d pkts pending in txq %u\n",
 						   err,
 					    atomic_read(&txq->pending_sends),
 					    txq->gdma_txq_id);

[Severity: Medium]
This isn't a bug introduced by this patch, but what happens if the reset fails here? The failure is only logged, and mana_dealloc_queues() then carries on:

		for (i = 0; i < apc->num_queues; i++) {
			txq = &apc->tx_qp[i]->txq;
			while ((skb = skb_dequeue(&txq->pending_skbs))) {
				mana_unmap_skb(skb, apc);
				dev_kfree_skb_any(skb);
			}
			atomic_set(&txq->pending_sends, 0);
		}

If the device was never actually reset, it still owns those pending TX WQEs. Could it later DMA-read the buffers that were just unmapped and freed?

For PCI, pcie_flr() returns before issuing the FLR only when pci_dev_config_accessible() or pci_dev_reset_iommu_prepare() fails.

The new -EOPNOTSUPP return in mana_gd_dev_reset() can't be reached in this series, because both PCI and CDX implement dev_reset. So this patch doesn't make the path newly reachable.

[ ... ]

drivers/net/ethernet/microsoft/mana/mana_en.c int mana_rdma_service_event(struct gdma_context *gc, enum gdma_service_type even · line 4038

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/mana_en.c +3 -0
@@ -4031,6 +4030,9 @@ int mana_rdma_service_event(struct gdma_context *gc, enum gdma_service_type even
 		return 0;
 	}
 
+	if (!gc->service_wq)
+		return -EOPNOTSUPP;
+
 	serv_work = kzalloc_obj(*serv_work, GFP_ATOMIC);
 	if (!serv_work)
 		return -ENOMEM;

[Severity: Low]
Can this check ever be true? The commit message doesn't mention it.

mana_gd_setup() calls mana_gd_alloc_service_wq() before setup_hwc_irqs() and mana_hwc_create_channel(). mana_gd_cleanup() destroys the HWC and the IRQs before it calls mana_gd_free_service_wq().

mana_rdma_service_event() is only called from the HWC event handler. It looks like it can never run while gc->service_wq is NULL.

On a related note, the comment added above mana_gd_alloc_service_wq() says:

/* The servicing workqueue is owned by the GDMA core because the queueing
* sites live here and in mana_en.c, which every transport shares. Each bus
* driver creates it during setup and destroys it during cleanup. */

The workqueue is created and destroyed by the core mana_gd_setup() and mana_gd_cleanup(), not by the bus drivers.

gdma_main.c also never queues work on gc->service_wq. The only user is mana_rdma_service_event(), and mana_pci_schedule_serv_work() uses schedule_work() on the system workqueue.

Could the comment be updated to match the code, and the check dropped if it can't be reached?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924173054.589291-1-mawasthi%40linux.microsoft.com
maintainer Reviewed-by on v1 1/4
#4 lore raw

RE: [PATCH net-next 1/4] net: mana: Introduce gdma_bus_ops for bus-specific operations

In reply to Manish Awasthi
Quoted 30 lines

-----Original Message-----
From: Manish Awasthi <[email protected]>
Sent: Thursday, September 24, 2026 1:31 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Gupta, Nipun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Paul Rosswurm <[email protected]>; Manish Awasthi <[email protected]>
Subject: [PATCH net-next 1/4] net: mana: Introduce gdma_bus_ops for bus- specific operations

Introduce per-device gdma_bus_ops for interrupt allocation, IRQ lookup, reset, servicing, and bus-specific capabilities. Route the shared GDMA code through these callbacks and provide the PCI implementation.

Move common device bring-up and teardown into mana_gd_setup() and mana_gd_cleanup(), including hardware-channel initialization, device enumeration, interrupt-pool sizing, and servicing workqueue management. Record the vPort count for transport-specific queue sizing and keep shared IRQ context bookkeeping in the core.

Quoted 4 lines

This prepares the driver for additional bus transports without duplicating the core or adding configuration checks throughout it.

#5 lore raw

PATCH 2/4 net: mana: Move PCI transport code into gdma_pci.c

In reply to Manish Awasthi

Move PCI transport code and driver callbacks from gdma_main.c into gdma_pci.c. Keep shared IRQ bookkeeping in the core and update build wiring.

---
 drivers/net/ethernet/microsoft/mana/Makefile  |   3 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   | 899 -----------------
 .../net/ethernet/microsoft/mana/gdma_pci.c    | 909 ++++++++++++++++++
 include/net/mana/gdma.h                       |   3 +
 4 files changed, 914 insertions(+), 900 deletions(-)
 create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_pci.c
drivers/net/ethernet/microsoft/mana/Makefile +2 -1
index e16a4221f571..6705bf65c92c 100644
@@ -3,4 +3,5 @@
 # Makefile for the Microsoft Azure Network Adapter driver
 
 obj-$(CONFIG_MICROSOFT_MANA) += mana.o
-mana-objs := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o
+mana-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o \
+	  gdma_pci.o
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -899

919 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +909 -0

909 lines not on this page · raw message

include/net/mana/gdma.h +3 -0
index cdec5558304f..238ff8b9f067 100644
@@ -1175,4 +1175,7 @@ int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver,
 			     u16 *max_num_vports, u8 *bm_hostmode);
 int mana_gd_dev_reset(struct gdma_context *gc);
 
+int mana_pci_driver_register(void);
+void mana_pci_driver_unregister(void);
+
 #endif /* _GDMA_H */
Signature · 1 line
2.54.0
#6 lore raw

Re: [PATCH net-next 2/4] net: mana: Move PCI transport code into gdma_pci.c

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Move PCI transport code and driver callbacks from gdma_main.c into gdma_pci.c. Keep shared IRQ bookkeeping in the core and update build wiring.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH net-next 2/4] net: mana: Move PCI transport code into gdma_pci.c

In reply to Manish Awasthi
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The include lists no longer match what each file uses.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is moved verbatim into gdma_pci.c and is still present at the end of the series.
- [High] This problem wasn't introduced by this patch, but it is moved verbatim and still present at the end of the series.
- [Medium] This problem wasn't introduced by this patch, but it is carried over verbatim.
- [Medium] This problem wasn't introduced by this patch, but it is carried over verbatim.
- [Low] This problem wasn't introduced by this patch, but it is carried over verbatim.

--

net: mana: Move PCI transport code into gdma_pci.c

This commit moves the PCI transport code, the MSI-X setup, the recovery work and the pci_driver callbacks out of gdma_main.c and into a new file, gdma_pci.c. mana_pci_driver_register() and mana_pci_driver_unregister() are now exported through gdma.h, and the Makefile builds gdma_pci.o.

Quoted 16 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -3
index b076760b2dc50..531170e58a62d 100644
@@ -2,10 +2,7 @@
 /* Copyright (c) 2021, Microsoft Corporation. */
 
 #include <linux/bitfield.h>
-#include <linux/cpumask.h>
 #include <linux/debugfs.h>
-#include <linux/delay.h>
-#include <linux/list.h>
 #include <linux/module.h>
 #include <linux/sizes.h>
 #include <linux/utsname.h>

drivers/net/ethernet/microsoft/mana/gdma_main.c line 20

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_main.c +0 -4
@@ -13,11 +10,7 @@
 #include <linux/msi.h>
 #include <linux/irqdomain.h>
 #include <linux/export.h>
-#include <linux/pci.h>
-#include <linux/slab.h>
-#include <linux/topology.h>
 #include <linux/uaccess.h>
-#include <linux/xarray.h>

[Severity: Low]
The code that stays in gdma_main.c still uses APIs from several of the headers removed here:

- xa_load()/xa_store()/xa_erase()/xa_err(), for example in

    mana_gd_get_gic() and mana_gd_put_gic()

- kzalloc()/kzalloc_obj()/kfree()
- list_add_rcu()/list_del_rcu()
- num_online_cpus()

Does gdma_main.c now build only because <net/mana/gdma.h> pulls in list.h, slab.h, xarray.h and cpumask.h indirectly, through netdevice.h and dma-mapping.h?

It also looks like the includes are unbalanced the other way. <linux/msi.h> and <linux/irqdomain.h> are still included here, but no msi or irq_domain users are left after the MSI-X code moved out. The new gdma_pci.c includes <linux/debugfs.h> but does not use any debugfs API.

The commit message doesn't mention the include changes. Could gdma_main.c keep direct includes for what it still uses, and could the unused includes be dropped?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +0 -0
new file mode 100644
index 0000000000000..4f6a77f55e5a7
@@ -0,0 +1,909 @@

[ ... ]

Quoted 5 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +5 -0
+static void mana_serv_reset(struct pci_dev *pdev)
+{
+	struct gdma_context *gc = pci_get_drvdata(pdev);
+	struct hw_channel_context *hwc;
+	int ret;

[ ... ]

Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +7 -0
+	dev_info(&pdev->dev, "MANA reset cycle start\n");
+
+	mana_gd_suspend(pdev, PMSG_SUSPEND);
+
+	msleep(MANA_SERVICE_PERIOD * 1000);
+
+	ret = mana_gd_resume(pdev);

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_pci.c line 128

Quoted 3 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +3 -0
+out:
+	clear_bit(GC_IN_SERVICE, &gc->flags);
+}

[Severity: High]
This isn't a bug introduced by this patch, since the code moves over unchanged, but what keeps gc alive across this 10 second window?

mana_pci_schedule_serv_work() queues mana_serv_func() on the system workqueue. It holds only a pci_dev reference and a module reference. mana_serv_reset() holds neither device_lock(&pdev->dev) nor pci_lock_rescan_remove() across the suspend/msleep/resume sequence. mana_gd_remove() never cancels or flushes this work, and it ignores GC_IN_SERVICE.

If a sysfs unbind or a Hyper-V vPCI eject overlaps the sleep:

CPU0 (mana_serv_func) CPU1 (unbind / eject)
mana_serv_reset()
mana_gd_suspend()
msleep()
mana_gd_remove()
mana_gd_cleanup(gc) /* again */ vfree(gc)
driver core clears drvdata
mana_gd_resume(pdev)
mana_gd_setup(gc) /* NULL or freed */
clear_bit(GC_IN_SERVICE, &gc->flags)

Could this cause a NULL dereference in mana_gd_setup(), or a write to vfree'd memory from clear_bit()?

HWC reset and FPGA events in mana_gd_process_eqe() can schedule this work, and so can HWC timeouts in mana_gf_stats_work_handler().

Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +2 -0
+static void mana_do_service(enum gdma_eqe_type type, struct pci_dev *pdev)
+{

[ ... ]

Quoted 7 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +7 -0
+static void mana_recovery_delayed_func(struct work_struct *w)
+{
+	struct mana_dev_recovery_work *work;
+	struct mana_dev_recovery *dev;
+	unsigned long flags;
+
+	work = container_of(w, struct mana_dev_recovery_work, work.work);

drivers/net/ethernet/microsoft/mana/gdma_pci.c line 163

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +10 -0
+
+	spin_lock_irqsave(&work->lock, flags);
+
+	while (!list_empty(&work->dev_list)) {
+		dev = list_first_entry(&work->dev_list,
+				       struct mana_dev_recovery, list);
+		list_del(&dev->list);
+		spin_unlock_irqrestore(&work->lock, flags);
+
+		mana_do_service(dev->type, dev->pdev);

[Severity: Medium]
This is a pre-existing issue, but can this loop keep running without ever returning while the device keeps failing probe?

For an entry queued by a failed probe, drvdata is NULL, so the call chain is:

mana_recovery_delayed_func()
mana_do_service()

    mana_serv_reset()          /* gc == NULL */
      mana_serv_rescan()
        pci_stop_and_remove_bus_device()
        pci_rescan_bus()
          mana_gd_probe()      /* synchronous, fails again */
            list_add_tail(&dev->list, &mana_dev_recovery_work.dev_list);
            schedule_delayed_work(...);

mana_driver sets no async probe_type, so the re-probe happens inside this work item.

Because the while loop re-checks the live dev_list, it picks up the new entry right away and skips the MANA_SERVICE_PERIOD back-off. If the hardware stays unresponsive, would disable_delayed_work_sync() in mana_pci_driver_unregister() then wait on this work indefinitely?

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +8 -0
+		pci_dev_put(dev->pdev);
+		kfree(dev);
+
+		spin_lock_irqsave(&work->lock, flags);
+	}
+
+	spin_unlock_irqrestore(&work->lock, flags);
+}

[ ... ]

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +8 -0
+static int mana_irq_setup_numa_aware(unsigned int *irqs, unsigned int len,
+				     int node, bool skip_first_cpu)
+{
+	const struct cpumask *next, *prev = cpu_none_mask;
+	cpumask_var_t cpus __free(free_cpumask_var);
+	int cpu, weight;
+
+	if (!alloc_cpumask_var(&cpus, GFP_KERNEL))

drivers/net/ethernet/microsoft/mana/gdma_pci.c line 318

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +10 -0
+		return -ENOMEM;
+
+	rcu_read_lock();
+	for_each_numa_hop_mask(next, node) {
+		weight = cpumask_weight_andnot(next, prev);
+		while (weight > 0) {
+			cpumask_andnot(cpus, next, prev);
+			for_each_cpu(cpu, cpus) {
+				cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu));
+				--weight;

[Severity: Low]
This is a pre-existing issue, but only the outer while loop checks weight > 0. The inner for_each_cpu() loop can keep assigning IRQs after the hop's budget is used up.

Take five online CPUs. The local node has sibling groups {0,1} and {2}, after an SMT sibling went offline, and the remote node has {4,5}. On the dynamic path, num_msix_usable=5 and skip_first_cpu=true:

local hop, weight = 3

    pass 1: skip {0,1}, assign {2}      weight = 1
    pass 2: assign {0,1}                weight = 0
            assign {2}                  weight = -1
  remote hop, weight = 2
            assign {4,5}

That puts 4 vectors, including the HWC one, on the 3 local CPUs and only 1 on the 2 remote CPUs. Should the inner loop also stop once weight reaches zero?

[ ... ]

Quoted 2 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +2 -0
+static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
+{

[ ... ]

Quoted 17 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +17 -0
+	err = mana_rdma_probe(&gc->mana_ib);
+	if (err)
+		goto cleanup_mana;
+
+	/*
+	 * If a hardware reset event has occurred over HWC during probe,
+	 * rollback and perform hardware reset procedure.
+	 */
+	if (test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) {
+		err = -EPROTO;
+		goto cleanup_mana_rdma;
+	}
+
+	return 0;
+
+cleanup_mana_rdma:
+	mana_rdma_remove(&gc->mana_ib);

drivers/net/ethernet/microsoft/mana/gdma_pci.c line 727

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +10 -0
+cleanup_mana:
+	mana_remove(&gc->mana, false);
+cleanup_gd:
+	mana_gd_cleanup(gc);
+unmap_bar:
+	xa_destroy(&gc->irq_contexts);
+	pci_iounmap(pdev, bar0_va);
+free_gc:
+	pci_set_drvdata(pdev, NULL);
+	vfree(gc);

[Severity: High]
This is a pre-existing issue, but can service work start while this probe is still running?

In mana_gd_process_eqe(), the first GDMA_EQE_HWC_FPGA_RECONFIG or GDMA_EQE_HWC_RESET_REQUEST event during probe sets GC_PROBE_SUCCEEDED. A second event then finds the bit already set and queues service work:

mana_gd_process_eqe() {
    ...
	if (!test_and_set_bit(GC_PROBE_SUCCEEDED, &gc->flags)) {
		...
		break;
	}
	mana_schedule_serv_work(gc, type);
    ...
}

GC_IN_SERVICE is still clear at that point, so mana_serv_func() gets queued.

A single HWC fault is enough on another path. mana_probe() schedules gf_stats_work, and mana_gf_stats_work_handler() calls mana_schedule_serv_work(gc, GDMA_EQE_HWC_RESET_REQUEST) on -ETIMEDOUT. mana_rdma_probe() may still be running when that happens.

The worker's mana_serv_reset() finds gc through pci_get_drvdata(), which probe sets early. It then runs mana_gd_suspend() while probe is still initialising. If probe instead fails with -EPROTO here, or with -ETIMEDOUT, the labels above run mana_gd_cleanup() and vfree(gc). The worker is still using gc at that point and finishes with clear_bit(GC_IN_SERVICE, &gc->flags).

Is anything supposed to synchronize this error path with a service work item that has already been queued?

[ ... ]

Quoted 9 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +9 -0
+void mana_pci_driver_unregister(void)
+{
+	struct mana_dev_recovery *dev;
+	unsigned long flags;
+
+	disable_delayed_work_sync(&mana_dev_recovery_work.work);
+
+	spin_lock_irqsave(&mana_dev_recovery_work.lock, flags);
+	while (!list_empty(&mana_dev_recovery_work.dev_list)) {

drivers/net/ethernet/microsoft/mana/gdma_pci.c line 909

Quoted 10 lines
drivers/net/ethernet/microsoft/mana/gdma_pci.c new file +10 -0
+		dev = list_first_entry(&mana_dev_recovery_work.dev_list,
+				       struct mana_dev_recovery, list);
+		list_del(&dev->list);
+		pci_dev_put(dev->pdev);
+		kfree(dev);
+	}
+	spin_unlock_irqrestore(&mana_dev_recovery_work.lock, flags);
+
+	pci_unregister_driver(&mana_driver);
+}

[Severity: Medium]
This is a pre-existing issue, but can a recovery entry leak here?

The delayed work is disabled and dev_list is drained before pci_unregister_driver() is called. The driver is still registered in between, so a probe can still run from a sysfs bind or an external rescan or hotplug.

If that probe fails with -ETIMEDOUT or -EPROTO, mana_gd_probe() allocates a mana_dev_recovery entry, takes pci_dev_get(pdev) and adds the entry to dev_list. Its schedule_delayed_work() call is a no-op on the disabled work, and nothing drains the list again.

Would that leak both the mana_dev_recovery allocation and the pci_dev reference?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924173054.589291-1-mawasthi%40linux.microsoft.com
maintainer Reviewed-by on v1 2/4
#8 lore raw

RE: [PATCH net-next 2/4] net: mana: Move PCI transport code into gdma_pci.c

In reply to Manish Awasthi
Quoted 20 lines

-----Original Message-----
From: Manish Awasthi <[email protected]>
Sent: Thursday, September 24, 2026 1:31 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Gupta, Nipun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Paul Rosswurm <[email protected]>; Manish Awasthi <[email protected]>
Subject: [PATCH net-next 2/4] net: mana: Move PCI transport code into gdma_pci.c

Quoted 5 lines

Move PCI transport code and driver callbacks from gdma_main.c into gdma_pci.c. Keep shared IRQ bookkeeping in the core and update build wiring.

#9 lore raw

PATCH 3/4 net: mana: Build the PCI transport as a separate module

In reply to Manish Awasthi

Build the shared GDMA and Ethernet code as gdma_core.ko, selected by MICROSOFT_GDMA_CORE. Build the PCI transport separately as mana.ko and export the required core symbols.

Preserve the PCI module name, device table, and mana.eth/mana.rdma auxiliary-device names. Each transport registers its own bus driver.

---
 drivers/net/ethernet/microsoft/Kconfig        | 12 ++++++---
 drivers/net/ethernet/microsoft/Makefile       |  2 +-
 drivers/net/ethernet/microsoft/mana/Makefile  |  7 ++++--
 .../net/ethernet/microsoft/mana/gdma_main.c   | 25 ++++++-------------
 .../net/ethernet/microsoft/mana/gdma_pci.c    | 11 ++++++--
 drivers/net/ethernet/microsoft/mana/mana_en.c |  7 +++++-
 include/net/mana/gdma.h                       |  3 ---
 7 files changed, 36 insertions(+), 31 deletions(-)
drivers/net/ethernet/microsoft/Kconfig +8 -4
index e9be18c92ca5..ee5bc1c1bf59 100644
@@ -15,15 +15,19 @@ config NET_VENDOR_MICROSOFT
 
 if NET_VENDOR_MICROSOFT
 
+config MICROSOFT_GDMA_CORE
+	tristate
+	select AUXILIARY_BUS
+	select DIMLIB
+	select PAGE_POOL
+	select NET_SHAPER
+
 config MICROSOFT_MANA
 	tristate "Microsoft Azure Network Adapter (MANA) support"
 	depends on PCI_MSI
 	depends on X86_64 || (ARM64 && !CPU_BIG_ENDIAN)
 	depends on PCI_HYPERV
-	select AUXILIARY_BUS
-	select DIMLIB
-	select PAGE_POOL
-	select NET_SHAPER
+	select MICROSOFT_GDMA_CORE
 	help
 	  This driver supports Microsoft Azure Network Adapter (MANA).
 	  So far, the driver is only supported on X86_64.
drivers/net/ethernet/microsoft/Makefile +1 -1
index d2ddc218135f..c3b6dafdf473 100644
@@ -2,4 +2,4 @@
 # Makefile for the Microsoft Azure network device driver.
 #
 
-obj-$(CONFIG_MICROSOFT_MANA) += mana/
+obj-$(CONFIG_MICROSOFT_GDMA_CORE) += mana/
drivers/net/ethernet/microsoft/mana/Makefile +5 -2
index 6705bf65c92c..72c03fb6e441 100644
@@ -2,6 +2,9 @@
 #
 # Makefile for the Microsoft Azure Network Adapter driver
 
+obj-$(CONFIG_MICROSOFT_GDMA_CORE) += gdma_core.o
+gdma_core-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o \
+	       mana_bpf.o
+
 obj-$(CONFIG_MICROSOFT_MANA) += mana.o
-mana-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o mana_bpf.o \
-	  gdma_pci.o
+mana-y := gdma_pci.o
drivers/net/ethernet/microsoft/mana/gdma_main.c +7 -18
index 531170e58a62..ae0ed700b3b9 100644
@@ -1991,6 +1991,7 @@ int mana_gd_setup(struct gdma_context *gc)
 	dev_err(gc->dev, "%s failed (error %d)\n", __func__, err);
 	return err;
 }
+EXPORT_SYMBOL_NS(mana_gd_setup, "NET_MANA");
 
 void mana_gd_cleanup(struct gdma_context *gc)
 {
@@ -2005,36 +2006,24 @@ void mana_gd_cleanup(struct gdma_context *gc)
 
 	dev_dbg(gc->dev, "mana gdma cleanup successful\n");
 }
+EXPORT_SYMBOL_NS(mana_gd_cleanup, "NET_MANA");
 
-static int __init mana_driver_init(void)
+static int __init gdma_core_init(void)
 {
-	int err;
-
 	mana_debugfs_root = debugfs_create_dir("mana", NULL);
 
-	err = mana_pci_driver_register();
-	if (err)
-		goto err_debugfs;
-
 	return 0;
-
-err_debugfs:
-	debugfs_remove(mana_debugfs_root);
-	mana_debugfs_root = NULL;
-	return err;
 }
 
-static void __exit mana_driver_exit(void)
+static void __exit gdma_core_exit(void)
 {
-	mana_pci_driver_unregister();
-
 	debugfs_remove(mana_debugfs_root);
 
 	mana_debugfs_root = NULL;
 }
 
-module_init(mana_driver_init);
-module_exit(mana_driver_exit);
+module_init(gdma_core_init);
+module_exit(gdma_core_exit);
 
 MODULE_LICENSE("Dual BSD/GPL");
-MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver");
+MODULE_DESCRIPTION("Microsoft Azure Network Adapter GDMA core");
drivers/net/ethernet/microsoft/mana/gdma_pci.c +9 -2
index 4f6a77f55e5a..92a1e66e18b7 100644
@@ -878,7 +878,7 @@ static struct pci_driver mana_driver = {
 
 MODULE_DEVICE_TABLE(pci, mana_id_table);
 
-int mana_pci_driver_register(void)
+static int __init mana_driver_init(void)
 {
 	INIT_LIST_HEAD(&mana_dev_recovery_work.dev_list);
 	spin_lock_init(&mana_dev_recovery_work.lock);
@@ -888,7 +888,7 @@ int mana_pci_driver_register(void)
 	return pci_register_driver(&mana_driver);
 }
 
-void mana_pci_driver_unregister(void)
+static void __exit mana_driver_exit(void)
 {
 	struct mana_dev_recovery *dev;
 	unsigned long flags;
@@ -907,3 +907,10 @@ void mana_pci_driver_unregister(void)
 
 	pci_unregister_driver(&mana_driver);
 }
+
+module_init(mana_driver_init);
+module_exit(mana_driver_exit);
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION("Microsoft Azure Network Adapter driver");
+MODULE_IMPORT_NS("NET_MANA");
drivers/net/ethernet/microsoft/mana/mana_en.c +6 -1
index 62b89b3d6072..16a9d192c099 100644
@@ -3957,7 +3957,8 @@ static int add_adev(struct gdma_dev *gd, const char *name)
 
 	/* madev is owned by the auxiliary device */
 	madev = NULL;
-	ret = auxiliary_device_add(adev);
+	/* Keep the established mana.{eth,rdma} auxiliary match names. */
+	ret = __auxiliary_device_add(adev, "mana");
 	if (ret)
 		goto add_fail;
 
@@ -4194,6 +4195,7 @@ int mana_probe(struct gdma_dev *gd, bool resuming)
 
 	return err;
 }
+EXPORT_SYMBOL_NS(mana_probe, "NET_MANA");
 
 void mana_remove(struct gdma_dev *gd, bool suspending)
 {
@@ -4272,6 +4274,7 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
 	kfree(ac);
 	dev_dbg(dev, "%s succeeded\n", __func__);
 }
+EXPORT_SYMBOL_NS(mana_remove, "NET_MANA");
 
 int mana_rdma_probe(struct gdma_dev *gd)
 {
@@ -4307,6 +4310,7 @@ int mana_rdma_probe(struct gdma_dev *gd)
 
 	return err;
 }
+EXPORT_SYMBOL_NS(mana_rdma_probe, "NET_MANA");
 
 void mana_rdma_remove(struct gdma_dev *gd)
 {
@@ -4327,6 +4331,7 @@ void mana_rdma_remove(struct gdma_dev *gd)
 
 	mana_gd_deregister_device(gd);
 }
+EXPORT_SYMBOL_NS(mana_rdma_remove, "NET_MANA");
 
 struct net_device *mana_get_primary_netdev(struct mana_context *ac,
 					   u32 port_index,
include/net/mana/gdma.h +0 -3
index 238ff8b9f067..cdec5558304f 100644
@@ -1175,7 +1175,4 @@ int mana_gd_query_device_cfg(struct gdma_context *gc, u32 proto_major_ver,
 			     u16 *max_num_vports, u8 *bm_hostmode);
 int mana_gd_dev_reset(struct gdma_context *gc);
 
-int mana_pci_driver_register(void);
-void mana_pci_driver_unregister(void);
-
 #endif /* _GDMA_H */
Signature · 1 line
2.54.0
#10 lore raw

Re: [PATCH net-next 3/4] net: mana: Build the PCI transport as a separate module

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Build the shared GDMA and Ethernet code as gdma_core.ko, selected by MICROSOFT_GDMA_CORE. Build the PCI transport separately as mana.ko and export the required core symbols.

Preserve the PCI module name, device table, and mana.eth/mana.rdma auxiliary-device names. Each transport registers its own bus driver.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
maintainer Reviewed-by on v1 3/4
#11 lore raw

RE: [PATCH net-next 3/4] net: mana: Build the PCI transport as a separate module

In reply to Manish Awasthi
Quoted 20 lines

-----Original Message-----
From: Manish Awasthi <[email protected]>
Sent: Thursday, September 24, 2026 1:31 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Gupta, Nipun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Paul Rosswurm <[email protected]>; Manish Awasthi <[email protected]>
Subject: [PATCH net-next 3/4] net: mana: Build the PCI transport as a separate module

Quoted 8 lines

Build the shared GDMA and Ethernet code as gdma_core.ko, selected by MICROSOFT_GDMA_CORE. Build the PCI transport separately as mana.ko and export the required core symbols.

Preserve the PCI module name, device table, and mana.eth/mana.rdma auxiliary-device names. Each transport registers its own bus driver.

#12 lore raw

PATCH 4/4 net: mana: Add support for CDX device ID 0x00C2

In reply to Manish Awasthi

Add the CDX transport as mana_cdx.ko for device ID 0x00C2, using the shared gdma_core.ko. Allocate interrupts at probe, limit queues to available vectors, use 32-bit DMA, and keep CDX auxiliary devices separate from PCI.

---
 drivers/net/ethernet/microsoft/Kconfig        |  14 +
 drivers/net/ethernet/microsoft/mana/Makefile  |   3 +
 .../net/ethernet/microsoft/mana/gdma_cdx.c    | 340 ++++++++++++++++++
 .../net/ethernet/microsoft/mana/gdma_pci.c    |   1 +
 drivers/net/ethernet/microsoft/mana/mana_en.c |   5 +-
 include/net/mana/gdma.h                       |   4 +
 6 files changed, 365 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/microsoft/mana/gdma_cdx.c
drivers/net/ethernet/microsoft/Kconfig +14 -0
index ee5bc1c1bf59..7e4b77f7f29c 100644
@@ -35,4 +35,18 @@ config MICROSOFT_MANA
 	  To compile this driver as a module, choose M here.
 	  The module will be called mana.
 
+config MICROSOFT_MANA_CDX
+	tristate "Microsoft Azure Network Adapter (MANA) support for the CDX bus"
+	depends on CDX_BUS
+	depends on GENERIC_MSI_IRQ
+	depends on 64BIT && !CPU_BIG_ENDIAN
+	select MICROSOFT_GDMA_CORE
+	help
+	  This driver supports the Microsoft Azure Network Adapter (MANA) on
+	  systems where it is integrated into the SoC and presented on the CDX
+	  bus rather than discovered over PCI.
+
+	  To compile this driver as a module, choose M here.
+	  The module will be called mana_cdx.
+
 endif #NET_VENDOR_MICROSOFT
drivers/net/ethernet/microsoft/mana/Makefile +3 -0
index 72c03fb6e441..64926015f734 100644
@@ -8,3 +8,6 @@ gdma_core-y := gdma_main.o shm_channel.o hw_channel.o mana_en.o mana_ethtool.o \
 
 obj-$(CONFIG_MICROSOFT_MANA) += mana.o
 mana-y := gdma_pci.o
+
+obj-$(CONFIG_MICROSOFT_MANA_CDX) += mana_cdx.o
+mana_cdx-y := gdma_cdx.o
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +340 -0

340 lines not on this page · raw message

drivers/net/ethernet/microsoft/mana/gdma_pci.c +1 -0
index 92a1e66e18b7..ed8925296c8a 100644
@@ -619,6 +619,7 @@ static void mana_pci_remove_irqs(struct gdma_context *gc)
 
 static const struct gdma_bus_ops mana_pci_bus_ops = {
 	.bus_name		= "pci",
+	.adev_prefix		= "mana",
 	.msix_can_alloc_dyn	= mana_pci_msix_can_alloc_dyn,
 	.msix_virq		= mana_pci_msix_virq,
 	.msix_alloc_at		= mana_pci_msix_alloc_at,
drivers/net/ethernet/microsoft/mana/mana_en.c +3 -2
index 16a9d192c099..2ba48a1c4b15 100644
@@ -3957,8 +3957,9 @@ static int add_adev(struct gdma_dev *gd, const char *name)
 
 	/* madev is owned by the auxiliary device */
 	madev = NULL;
-	/* Keep the established mana.{eth,rdma} auxiliary match names. */
-	ret = __auxiliary_device_add(adev, "mana");
+	/* Keep match names independent of the common module's name. */
+	ret = __auxiliary_device_add(adev,
+				     gd->gdma_context->bus_ops->adev_prefix);
 	if (ret)
 		goto add_fail;
 
include/net/mana/gdma.h +4 -0
index cdec5558304f..c610fc1067e0 100644
@@ -432,6 +432,7 @@ struct gdma_context;
  * instance in gdma_context.bus_ops at probe time.
  *
  * @bus_name: Bus token used to build the per-vector IRQ names.
+ * @adev_prefix: Prefix used for auxiliary-device match names.
  * @msix_can_alloc_dyn: True if the bus can allocate MSI-X vectors after
  *	probe time. Buses that size their vector pool at probe and cannot
  *	grow it later leave this NULL.
@@ -459,6 +460,7 @@ struct gdma_context;
  */
 struct gdma_bus_ops {
 	const char *bus_name;
+	const char *adev_prefix;
 	bool (*msix_can_alloc_dyn)(struct gdma_context *gc);
 	int (*msix_virq)(struct gdma_context *gc, int msi);
 	int (*msix_alloc_at)(struct gdma_context *gc, int *msi);
@@ -684,6 +686,8 @@ struct gdma_eqe {
 #define MANA_PF2_DEVICE_ID 0x00C1
 #define MANA_VF_DEVICE_ID 0x00BA
 
+#define MANA_CDX_DEVICE_ID 0x00C2
+
 struct gdma_posted_wqe_info {
 	u32 wqe_size_in_bu;
 };
Signature · 1 line
2.54.0
#13 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines

Add the CDX transport as mana_cdx.ko for device ID 0x00C2, using the shared gdma_core.ko. Allocate interrupts at probe, limit queues to available vectors, use 32-bit DMA, and keep CDX auxiliary devices separate from PCI.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#14 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

In reply to Manish Awasthi
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The CDX transport installs .dev_reset = mana_cdx_dev_reset (-> cdx_dev_reset()) but has no way to recover afterwards.
- [Low] mana_cdx_setup_hwc_irqs() skips IRQ affinity hints.
- [Low] The comment in mana_gd_query_max_resources() (gdma_main.c)
says: "Only reset on platforms that support dynamic MSI-X allocation;…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the shared HWC bootstrap path that the new CDX transport now reaches trusts a device-…

--

net: mana: Add support for CDX device ID 0x00C2

This adds a CDX bus transport for MANA, built as mana_cdx.ko on top of the shared gdma_core.ko, for device ID 0x00C2. It allocates the whole MSI pool at probe time, limits the queue count to the available vectors, restricts DMA to 32 bits, and adds a per-bus auxiliary device name prefix so the CDX auxiliary devices stay separate from the PCI ones.

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +0 -0
new file mode 100644
index 0000000000000..0d01e3d2f0d96
@@ -0,0 +1,340 @@

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 26

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +4 -0
+static int mana_cdx_dev_reset(struct gdma_context *gc)
+{
+	return cdx_dev_reset(gc->dev);
+}

[Severity: Medium]
Can this reset leave the whole function unusable, with no recovery short of a manual rebind?

mana_dealloc_queues() calls it when a TX queue still has pending_sends after the drain timeout:

mana_tx_timeout()
-> queue_reset_work

    -> mana_per_port_queue_reset_work_handler()
      -> mana_dealloc_queues()
        -> mana_gd_dev_reset()
          -> mana_cdx_dev_reset()
            -> cdx_dev_reset()

The detach paths can reach mana_dealloc_queues() too.

drivers/cdx/controller/mc_cdx_pcol.h documents MC_CMD_CDX_DEVICE_RESET like this:

* After this call completes, device DMA and interrupts are quiesced, devices
* logic is reset in a hardware-specific way and DMA bus mastering is disabled.

That resets the HWC, all EQs, the other vPorts and RDMA, but the driver keeps treating all of them as live. There is no re-init path on CDX:

- Bus mastering is only turned on by cdx_set_master() in mana_cdx_gd_probe().
- MSI is only enabled in mana_cdx_setup_hwc_irqs().
- gdma_cdx_driver has no reset_prepare or reset_done callbacks.
- mana_cdx_bus_ops has no schedule_serv_work.

So would the HWC requests that follow (mana_disable_vport_rx(), vPort object teardown, re-attach) all time out? And when mana_gf_stats_work_handler() detects the HWC timeout, would its servicing request just be rejected with -EOPNOTSUPP?

On PCI, the same reset through pcie_flr() is backed by HWC-timeout recovery through mana_pci_schedule_serv_work().

CDX also still advertises stall-SQ recovery to firmware through the common GDMA_DRV_CAP_FLAGS1:

	 GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \

Without a dev_reset op, mana_gd_dev_reset() would return -EOPNOTSUPP, and a stall in one queue would not reset the whole function.

There is a second trigger. reset_store() in drivers/cdx/cdx.c calls cdx_dev_reset() on a bound device, and Documentation/ABI/testing/sysfs-bus-cdx says the driver gets notified. With no reset_prepare/reset_done here, wouldn't a sysfs reset leave the device in the same state?

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 92

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +8 -0
+	xa_init(&gc->irq_contexts);
+
+	/* No IRQ affinity hint is applied here. The PCI transport spreads its
+	 * vectors over the NUMA node local to the device; the CDX platforms
+	 * this driver targets are single-node, so there is nothing to spread
+	 * over. Affinity management can be added when a multi-node CDX host
+	 * exists to validate it against.
+	 */

[Severity: Low]
Is the reason given in this comment accurate? The PCI transport does more than spread over the local node. mana_irq_setup_numa_aware() skips SMT siblings and puts each vector on a different physical core:

	cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu));
	...
	irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu));

mana_irq_setup_linear() also pins vector i to CPU i.

A single-node multi-core SoC still has cores to spread over. On CDX, the EQ interrupts keep the default affinity and get no per-queue CPU placement.

Could the comment, and the commit message, describe this difference from PCI accurately?

[ ... ]

Quoted 13 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +13 -0
+static int mana_cdx_setup_remaining_irqs(struct gdma_context *gc)
+{
+	unsigned int max_queues_vport;
+
+	/* mana_gd_query_max_resources() may turn MSI sharing back on and round
+	 * the per-vPort queue count up to MANA_DEF_NUM_QUEUES. CDX sizes its
+	 * vector pool at probe time and cannot grow it later, and the HWC
+	 * vector must stay private, so give every vPort a private slice of the
+	 * remaining vectors instead. gc->max_num_queues is already capped at
+	 * num_msix_usable - 1 by the core.
+	 */
+	gc->msi_sharing = false;
+	max_queues_vport = (gc->num_msix_usable - 1) / gc->num_ports;

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 181

Quoted 1 line
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +1 -0
+	gc->max_num_queues_vport = min(gc->max_num_queues, max_queues_vport);

[Severity: Low]
This isn't a bug, but after this patch the comment in mana_gd_query_max_resources() in gdma_main.c is no longer accurate:

* not before. Only reset on platforms that support dynamic
* MSI-X allocation; on non-dyn platforms msi_sharing is
* unconditionally true (set in mana_gd_setup_hwc_irqs).

CDX leaves msix_can_alloc_dyn NULL, so it is a non-dyn bus. Even so, mana_cdx_setup_hwc_irqs() sets msi_sharing to false. The core may set it back to true, and then mana_cdx_setup_remaining_irqs() forces it to false again and overwrites max_num_queues_vport.

Should the core comment be updated? It may also help to document in the core that a transport is expected to override msi_sharing and max_num_queues_vport in setup_remaining_irqs.

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 252

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +8 -0
+	/* gc->is_pf is intentionally left clear: this device uses the VF
+	 * register layout, and the vPort and MAC filter registration that
+	 * is_pf selects is not required on this bus.
+	 */
+
+	err = mana_gd_setup(gc);
+	if (err)
+		goto unmap_bar;

[Severity: High]
This issue was not introduced by this patch, but the shared HWC bootstrap path that CDX now enters here uses a doorbell index supplied by the device without checking its bounds.

mana_hwc_init_event_handler() in hw_channel.c stores the 16-bit doorbell directly from the EQE:

	case GDMA_EQE_HWC_INIT_EQ_ID_DB:
		eq_db.as_uint32 = event->details[0];
		hwc->cq->gdma_eq->id = eq_db.eq_id;
		gd->doorbell = eq_db.doorbell;

mana_hwc_establish_channel() checks cq->id against max_num_cqs, but it never checks the doorbell. mana_gd_ring_doorbell() then computes the MMIO address:

	void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;

db_page_size is at least 4KB and the doorbell can be as large as 0xFFFF. Could the next mana_gd_ring_eq() or mana_gd_ring_cq() then write far past the ioremapped BAR0, into unmapped vmalloc space or another mapping?

mana_gd_register_device() already has this check for the regular doorbell:

	if (gc->db_page_off + gc->db_page_size * ((u64)resp.db_id + 1) > gc->bar0_size) {

Should the HWC path apply the same check? This affects the PCI transport as well.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924173054.589291-1-mawasthi%40linux.microsoft.com
#15 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

thanks for review. Comments inline.

Quoted 52 lines

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The CDX transport installs .dev_reset = mana_cdx_dev_reset (-> cdx_dev_reset()) but has no way to recover afterwards.
- [Low] mana_cdx_setup_hwc_irqs() skips IRQ affinity hints.
- [Low] The comment in mana_gd_query_max_resources() (gdma_main.c)
says: "Only reset on platforms that support dynamic MSI-X allocation;…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the shared HWC bootstrap path that the new CDX transport now reaches trusts a device-…

--

net: mana: Add support for CDX device ID 0x00C2

This adds a CDX bus transport for MANA, built as mana_cdx.ko on top of the shared gdma_core.ko, for device ID 0x00C2. It allocates the whole MSI pool at probe time, limits the queue count to the available vectors, restricts DMA to 32 bits, and adds a per-bus auxiliary device name prefix so the CDX auxiliary devices stay separate from the PCI ones.

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +0 -0
new file mode 100644
index 0000000000000..0d01e3d2f0d96
@@ -0,0 +1,340 @@

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 26

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +4 -0
+static int mana_cdx_dev_reset(struct gdma_context *gc)
+{
+	return cdx_dev_reset(gc->dev);
+}

[Severity: Medium]
Can this reset leave the whole function unusable, with no recovery short of a manual rebind?

mana_dealloc_queues() calls it when a TX queue still has pending_sends after the drain timeout:

Quoted 8 lines

mana_tx_timeout()
-> queue_reset_work

    -> mana_per_port_queue_reset_work_handler()
      -> mana_dealloc_queues()
        -> mana_gd_dev_reset()
          -> mana_cdx_dev_reset()
            -> cdx_dev_reset()

This version of the driver doesn't support recovery after mana_cdx_dev_reset.

Quoted 17 lines

The detach paths can reach mana_dealloc_queues() too.

drivers/cdx/controller/mc_cdx_pcol.h documents MC_CMD_CDX_DEVICE_RESET like this:

* After this call completes, device DMA and interrupts are quiesced, devices
* logic is reset in a hardware-specific way and DMA bus mastering is disabled.

That resets the HWC, all EQs, the other vPorts and RDMA, but the driver keeps treating all of them as live. There is no re-init path on CDX:

- Bus mastering is only turned on by cdx_set_master() in mana_cdx_gd_probe().
- MSI is only enabled in mana_cdx_setup_hwc_irqs().
- gdma_cdx_driver has no reset_prepare or reset_done callbacks.
- mana_cdx_bus_ops has no schedule_serv_work.

Quoted 5 lines

So would the HWC requests that follow (mana_disable_vport_rx(), vPort object teardown, re-attach) all time out? And when mana_gf_stats_work_handler() detects the HWC timeout, would its servicing request just be rejected with -EOPNOTSUPP?

The first HWC request after reset call will wait for default timeout and subsequent commands will fail after 1ms. A future patch will change the tx timeout recovery to reset the timeout to 0 after dev_reset for both pci and cdx.

Quoted 10 lines

On PCI, the same reset through pcie_flr() is backed by HWC-timeout recovery through mana_pci_schedule_serv_work().

CDX also still advertises stall-SQ recovery to firmware through the common GDMA_DRV_CAP_FLAGS1:

	 GDMA_DRV_CAP_FLAG_1_HANDLE_STALL_SQ_RECOVERY | \

Without a dev_reset op, mana_gd_dev_reset() would return -EOPNOTSUPP, and a stall in one queue would not reset the whole function.

This flag represents the capability of the driver to support ndo_tx_timeout for cdx.

Quoted 9 lines

There is a second trigger. reset_store() in drivers/cdx/cdx.c calls cdx_dev_reset() on a bound device, and Documentation/ABI/testing/sysfs-bus-cdx says the driver gets notified. With no reset_prepare/reset_done here, wouldn't a sysfs reset leave the device in the same state?

[ ... ]

Quoted 9 lines

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 92

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +8 -0
+	xa_init(&gc->irq_contexts);
+
+	/* No IRQ affinity hint is applied here. The PCI transport spreads its
+	 * vectors over the NUMA node local to the device; the CDX platforms
+	 * this driver targets are single-node, so there is nothing to spread
+	 * over. Affinity management can be added when a multi-node CDX host
+	 * exists to validate it against.
+	 */

The support for reset_prepare/reset_done will be added in future.

Quoted 101 lines

[Severity: Low]
Is the reason given in this comment accurate? The PCI transport does more than spread over the local node. mana_irq_setup_numa_aware() skips SMT siblings and puts each vector on a different physical core:

	cpumask_andnot(cpus, cpus, topology_sibling_cpumask(cpu));
	...
	irq_set_affinity_and_hint(*irqs++, topology_sibling_cpumask(cpu));

mana_irq_setup_linear() also pins vector i to CPU i.

A single-node multi-core SoC still has cores to spread over. On CDX, the EQ interrupts keep the default affinity and get no per-queue CPU placement.

Could the comment, and the commit message, describe this difference from PCI accurately?

[ ... ]

Quoted 13 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +13 -0
+static int mana_cdx_setup_remaining_irqs(struct gdma_context *gc)
+{
+	unsigned int max_queues_vport;
+
+	/* mana_gd_query_max_resources() may turn MSI sharing back on and round
+	 * the per-vPort queue count up to MANA_DEF_NUM_QUEUES. CDX sizes its
+	 * vector pool at probe time and cannot grow it later, and the HWC
+	 * vector must stay private, so give every vPort a private slice of the
+	 * remaining vectors instead. gc->max_num_queues is already capped at
+	 * num_msix_usable - 1 by the core.
+	 */
+	gc->msi_sharing = false;
+	max_queues_vport = (gc->num_msix_usable - 1) / gc->num_ports;

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 181

Quoted 1 line
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +1 -0
+	gc->max_num_queues_vport = min(gc->max_num_queues, max_queues_vport);

[Severity: Low]
This isn't a bug, but after this patch the comment in mana_gd_query_max_resources() in gdma_main.c is no longer accurate:

* not before. Only reset on platforms that support dynamic
* MSI-X allocation; on non-dyn platforms msi_sharing is
* unconditionally true (set in mana_gd_setup_hwc_irqs).

CDX leaves msix_can_alloc_dyn NULL, so it is a non-dyn bus. Even so, mana_cdx_setup_hwc_irqs() sets msi_sharing to false. The core may set it back to true, and then mana_cdx_setup_remaining_irqs() forces it to false again and overwrites max_num_queues_vport.

Should the core comment be updated? It may also help to document in the core that a transport is expected to override msi_sharing and max_num_queues_vport in setup_remaining_irqs.

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 252

Quoted 8 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +8 -0
+	/* gc->is_pf is intentionally left clear: this device uses the VF
+	 * register layout, and the vPort and MAC filter registration that
+	 * is_pf selects is not required on this bus.
+	 */
+
+	err = mana_gd_setup(gc);
+	if (err)
+		goto unmap_bar;

[Severity: High]
This issue was not introduced by this patch, but the shared HWC bootstrap path that CDX now enters here uses a doorbell index supplied by the device without checking its bounds.

mana_hwc_init_event_handler() in hw_channel.c stores the 16-bit doorbell directly from the EQE:

	case GDMA_EQE_HWC_INIT_EQ_ID_DB:
		eq_db.as_uint32 = event->details[0];
		hwc->cq->gdma_eq->id = eq_db.eq_id;
		gd->doorbell = eq_db.doorbell;

mana_hwc_establish_channel() checks cq->id against max_num_cqs, but it never checks the doorbell. mana_gd_ring_doorbell() then computes the MMIO address:

	void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;

db_page_size is at least 4KB and the doorbell can be as large as 0xFFFF. Could the next mana_gd_ring_eq() or mana_gd_ring_cq() then write far past the ioremapped BAR0, into unmapped vmalloc space or another mapping?

mana_gd_register_device() already has this check for the regular doorbell:

	if (gc->db_page_off + gc->db_page_size * ((u64)resp.db_id + 1) > gc->bar0_size) {

Should the HWC path apply the same check? This affects the PCI transport as well.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260924173054.589291-1-mawasthi%40linux.microsoft.com
reviewer
#16 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

Quoted 62 lines · Manish Awasthi

thanks for review. Comments inline.

Quoted 52 lines

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The CDX transport installs .dev_reset = mana_cdx_dev_reset (-> cdx_dev_reset()) but has no way to recover afterwards.
- [Low] mana_cdx_setup_hwc_irqs() skips IRQ affinity hints.
- [Low] The comment in mana_gd_query_max_resources() (gdma_main.c)
says: "Only reset on platforms that support dynamic MSI-X allocation;…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the shared HWC bootstrap path that the new CDX transport now reaches trusts a device-…

--

net: mana: Add support for CDX device ID 0x00C2

This adds a CDX bus transport for MANA, built as mana_cdx.ko on top of the shared gdma_core.ko, for device ID 0x00C2. It allocates the whole MSI pool at probe time, limits the queue count to the available vectors, restricts DMA to 32 bits, and adds a per-bus auxiliary device name prefix so the CDX auxiliary devices stay separate from the PCI ones.

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +0 -0
new file mode 100644
index 0000000000000..0d01e3d2f0d96
@@ -0,0 +1,340 @@

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 26

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +4 -0
+static int mana_cdx_dev_reset(struct gdma_context *gc)
+{
+	return cdx_dev_reset(gc->dev);
+}

[Severity: Medium]
Can this reset leave the whole function unusable, with no recovery short of a manual rebind?

mana_dealloc_queues() calls it when a TX queue still has pending_sends after the drain timeout:

Quoted 8 lines

mana_tx_timeout()
-> queue_reset_work

    -> mana_per_port_queue_reset_work_handler()
      -> mana_dealloc_queues()
        -> mana_gd_dev_reset()
          -> mana_cdx_dev_reset()
            -> cdx_dev_reset()
Quoted 1 line

This version of the driver doesn't support recovery after mana_cdx_dev_reset.

I don't think it needs to delay progress of this patchset. But I am curious to know if there are plans to add such support.

...

#17 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

Quoted 63 lines · Manish Awasthi
Quoted 62 lines

thanks for review. Comments inline.

Quoted 60 lines

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The CDX transport installs .dev_reset = mana_cdx_dev_reset (-> cdx_dev_reset()) but has no way to recover afterwards.
- [Low] mana_cdx_setup_hwc_irqs() skips IRQ affinity hints.
- [Low] The comment in mana_gd_query_max_resources() (gdma_main.c)
says: "Only reset on platforms that support dynamic MSI-X allocation;…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the shared HWC bootstrap path that the new CDX transport now reaches trusts a device-…

--

net: mana: Add support for CDX device ID 0x00C2

This adds a CDX bus transport for MANA, built as mana_cdx.ko on top of the shared gdma_core.ko, for device ID 0x00C2. It allocates the whole MSI pool at probe time, limits the queue count to the available vectors, restricts DMA to 32 bits, and adds a per-bus auxiliary device name prefix so the CDX auxiliary devices stay separate from the PCI ones.

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +0 -0
new file mode 100644
index 0000000000000..0d01e3d2f0d96
@@ -0,0 +1,340 @@

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 26

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +4 -0
+static int mana_cdx_dev_reset(struct gdma_context *gc)
+{
+	return cdx_dev_reset(gc->dev);
+}

[Severity: Medium]
Can this reset leave the whole function unusable, with no recovery short of a manual rebind?

mana_dealloc_queues() calls it when a TX queue still has pending_sends after the drain timeout:

mana_tx_timeout()
-> queue_reset_work

    -> mana_per_port_queue_reset_work_handler()
      -> mana_dealloc_queues()
        -> mana_gd_dev_reset()
          -> mana_cdx_dev_reset()
            -> cdx_dev_reset()
Quoted 5 lines
Quoted 1 line

This version of the driver doesn't support recovery after mana_cdx_dev_reset.

I don't think it needs to delay progress of this patchset. But I am curious to know if there are plans to add such support.

It is possible to have similar recovery support as the pci in this path after cdx_dev_reset() and we do have plans to add it in future.

Quoted 1 line

...

reviewer
#18 lore raw

Re: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

Quoted 63 lines · Manish Awasthi
Quoted 63 lines · Manish Awasthi
Quoted 62 lines

thanks for review. Comments inline.

Quoted 60 lines

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The CDX transport installs .dev_reset = mana_cdx_dev_reset (-> cdx_dev_reset()) but has no way to recover afterwards.
- [Low] mana_cdx_setup_hwc_irqs() skips IRQ affinity hints.
- [Low] The comment in mana_gd_query_max_resources() (gdma_main.c)
says: "Only reset on platforms that support dynamic MSI-X allocation;…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the shared HWC bootstrap path that the new CDX transport now reaches trusts a device-…

--

net: mana: Add support for CDX device ID 0x00C2

This adds a CDX bus transport for MANA, built as mana_cdx.ko on top of the shared gdma_core.ko, for device ID 0x00C2. It allocates the whole MSI pool at probe time, limits the queue count to the available vectors, restricts DMA to 32 bits, and adds a per-bus auxiliary device name prefix so the CDX auxiliary devices stay separate from the PCI ones.

Quoted 6 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +0 -0
new file mode 100644
index 0000000000000..0d01e3d2f0d96
@@ -0,0 +1,340 @@

[ ... ]

drivers/net/ethernet/microsoft/mana/gdma_cdx.c line 26

Quoted 4 lines
drivers/net/ethernet/microsoft/mana/gdma_cdx.c new file +4 -0
+static int mana_cdx_dev_reset(struct gdma_context *gc)
+{
+	return cdx_dev_reset(gc->dev);
+}

[Severity: Medium]
Can this reset leave the whole function unusable, with no recovery short of a manual rebind?

mana_dealloc_queues() calls it when a TX queue still has pending_sends after the drain timeout:

mana_tx_timeout()
-> queue_reset_work

    -> mana_per_port_queue_reset_work_handler()
      -> mana_dealloc_queues()
        -> mana_gd_dev_reset()
          -> mana_cdx_dev_reset()
            -> cdx_dev_reset()
Quoted 7 lines
Quoted 5 lines
Quoted 1 line

This version of the driver doesn't support recovery after mana_cdx_dev_reset.

I don't think it needs to delay progress of this patchset. But I am curious to know if there are plans to add such support.

It is possible to have similar recovery support as the pci in this path after cdx_dev_reset() and we do have plans to add it in future.

Nice. Thanks for the response.

Quoted 1 line
Quoted 1 line

...

maintainer Reviewed-by on v1 4/4
#19 lore raw

RE: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

In reply to Manish Awasthi
Quoted 20 lines

-----Original Message-----
From: Manish Awasthi <[email protected]>
Sent: Thursday, September 24, 2026 1:31 PM
To: KY Srinivasan <[email protected]>; Haiyang Zhang <[email protected]>; [email protected]; Dexuan Cui <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Konstantin Taranov <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; Gupta, Nipun <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Paul Rosswurm <[email protected]>; Manish Awasthi <[email protected]>
Subject: [PATCH net-next 4/4] net: mana: Add support for CDX device ID 0x00C2

Quoted 6 lines

Add the CDX transport as mana_cdx.ko for device ID 0x00C2, using the shared
gdma_core.ko. Allocate interrupts at probe, limit queues to available vectors, use 32-bit DMA, and keep CDX auxiliary devices separate from PCI.

reviewer Reviewed-by on the v1 series
#20 lore raw
In reply to Manish Awasthi
Quoted 17 lines · Manish Awasthi

This series adds CDX bus support to the MANA driver.

The shared GDMA and Ethernet code currently builds together with the PCI transport. To add another bus without duplicating the driver or adding configuration checks throughout the shared code, this series separates the bus-specific operations and builds each transport independently.

Patch 1 introduces gdma_bus_ops and routes bus-specific interrupt, reset, service, and setup operations through it.

Patch 2 moves the PCI-specific code from gdma_main.c into gdma_pci.c without changing PCI behavior.

Patch 3 builds the shared code as gdma_core.ko and the PCI transport as mana.ko. The PCI module keeps its existing name, device table, and mana.eth/mana.rdma auxiliary-device identities.

Quoted 7 lines

Patch 4 adds the CDX transport as mana_cdx.ko for device ID 0x00C2.

Manish Awasthi (4):
net: mana: Introduce gdma_bus_ops for bus-specific operations
net: mana: Move PCI transport code into gdma_pci.c
net: mana: Build the PCI transport as a separate module
net: mana: Add support for CDX device ID 0x00C2

For the series:

#21 lore raw
In reply to Manish Awasthi
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Thu, 24 Sep 2026 17:30:50 +0000 you wrote:

This series adds CDX bus support to the MANA driver.

The shared GDMA and Ethernet code currently builds together with the PCI transport. To add another bus without duplicating the driver or adding configuration checks throughout the shared code, this series separates the bus-specific operations and builds each transport independently.

[...]

Here is the summary with links:
- [net-next,1/4] net: mana: Introduce gdma_bus_ops for bus-specific operations

    https://git.kernel.org/netdev/net-next/c/c03e69c95a18
  - [net-next,2/4] net: mana: Move PCI transport code into gdma_pci.c
    https://git.kernel.org/netdev/net-next/c/34520ae5dd57
  - [net-next,3/4] net: mana: Build the PCI transport as a separate module
    https://git.kernel.org/netdev/net-next/c/445927de07cd
  - [net-next,4/4] net: mana: Add support for CDX device ID 0x00C2
    https://git.kernel.org/netdev/net-next/c/3d6792ea4605

You are awesome, thank you!

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