mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next v12 0/5] net: mana: concurrent HWC requests
@ 2026-11-24 15:40 Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it Wei Hu
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

The MANA hardware channel starts with room for one request. This series
lets the driver use the depth reported by the PF. It tests the new
channel before publishing it and keeps the depth-one channel when the
reported geometry cannot be used.

Changes since v11:
- Split doorbell validation into a standalone fix. Once ESTABLISH_HWC
  has submitted queue addresses, retain the HWC mappings until the PF
  acknowledges DESTROY_HWC. Bound automatic PCI reprobes after an
  unacknowledged teardown; a still-bound device can retry in place.
- Drop the v11 early returns from CQ and QP destruction. RDMA core can
  release these objects on process exit; the driver must still remove its
  callbacks and release the backing. PD, MR/MW and DM destruction can
  finish locally after a normal posted-command timeout. At that boundary
  the PF has drained old client DMA and invalidated outstanding requests.
  An unposted request or a reset notification is not such a guarantee.
- Publish a batch of requests with one SQ doorbell. Do not post the next
  batch until the previous one finishes. Check posted deadlines before
  accepting or returning a reply so a late CREATE cannot supply a handle.
  A queued caller can detect the timeout even if the sender has not run.
- Check the full-width depth against the 4 KiB descriptor rings. Enforce
  the negotiated transmit and receive limits and remove the redundant
  RDMA minimum-size check. Restore a tested depth-one channel only after
  acknowledged teardown of the failed candidate.

Validation: targeted GCC and Clang W=1 builds and strict 80-column
checkpatch on the series. Bounded host tests cover a two-request batch,
replies before, at and after deadline, RDMA cleanup, unacknowledged HWC
teardown, depth fallback and request sizing. No new hardware, performance
or full-kernel test is claimed.

Previous revision:
https://lore.kernel.org/all/cover.1794751992.git.weh@linux.microsoft.com/

Long Li (5):
  net: mana: validate the HWC doorbell before ringing it
  net: mana: keep HWC queues until the PF acknowledges teardown
  net: mana: protect the HWC response buffer until the sender returns
  net: mana: support concurrent HWC requests
  net: mana: use the reported HWC queue depth

 drivers/infiniband/hw/mana/main.c             |   15 +-
 drivers/infiniband/hw/mana/mr.c               |    6 +-
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |    6 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  165 ++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    |  144 ++-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 1081 +++++++++++++----
 drivers/net/ethernet/microsoft/mana/mana_en.c |    4 +-
 .../net/ethernet/microsoft/mana/shm_channel.c |   58 +-
 include/net/mana/gdma.h                       |   19 +
 include/net/mana/hw_channel.h                 |   66 +-
 include/net/mana/shm_channel.h                |   10 +-
 11 files changed, 1240 insertions(+), 334 deletions(-)


base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
@ 2026-11-24 15:40 ` Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown Wei Hu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

From: Long Li <longli@microsoft.com>
Date: Mon, 24 Aug 2026 20:04:01 +0000

The HWC gets its doorbell page from an initialization event. Unlike a
registered device, it uses that page without checking that it fits in
BAR0. The EQ can also try to rearm before a page has been assigned.

Check the page before storing it and skip doorbell writes until a page
is available. Fail setup on a bad page rather than waiting for another
event on an EQ that cannot be rearmed.

Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Wei Hu <weh@microsoft.com>
---
 .../net/ethernet/microsoft/mana/gdma_main.c   | 25 +++++++++++++------
 .../net/ethernet/microsoft/mana/hw_channel.c  | 19 ++++++++++++++
 include/net/mana/gdma.h                       |  1 +
 include/net/mana/hw_channel.h                 |  1 +
 4 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index d6ae89c2ccddce5cca264fa499ddd1cbdee8cf85..673a4754c9dd00a8a0b4436e27ce1c433d85c2ff 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -547,13 +547,28 @@ static int mana_gd_disable_queue(struct gdma_queue *queue)
 #define DOORBELL_OFFSET_EQ	0xFF8
 #define DOORBELL_OFFSET_DIM	0x820
 
+bool mana_gd_is_valid_doorbell(struct gdma_context *gc, u32 db_id)
+{
+	if (!gc->db_page_size || gc->db_page_off >= gc->bar0_size)
+		return false;
+
+	/* The page size comes from a 16-bit register field. */
+	return db_id != INVALID_DOORBELL &&
+	       gc->db_page_size * ((u64)db_id + 1) <=
+	       gc->bar0_size - gc->db_page_off;
+}
+
 static void mana_gd_ring_doorbell(struct gdma_context *gc, u32 db_index,
 				  enum gdma_queue_type q_type, u32 qid,
 				  u32 tail_ptr, u8 num_req, u8 client_offset)
 {
-	void __iomem *addr = gc->db_page_base + gc->db_page_size * db_index;
 	union gdma_doorbell_entry e = {};
+	void __iomem *addr;
+
+	if (unlikely(db_index == INVALID_DOORBELL))
+		return;
 
+	addr = gc->db_page_base + gc->db_page_size * db_index;
 	addr += client_offset;
 
 	switch (q_type) {
@@ -1533,13 +1548,7 @@ int mana_gd_register_device(struct gdma_dev *gd)
 		return err ? err : -EPROTO;
 	}
 
-	/* Validate that doorbell page for db_id is within the BAR0 region.
-	 * In mana_gd_ring_doorbell(), the address is calculated as:
-	 *   addr = db_page_base + db_page_size * db_id
-	 *        = (bar0_va + db_page_off) + (db_page_size * db_id)
-	 * So we need: db_page_off + db_page_size * (db_id + 1) <= bar0_size
-	 */
-	if (gc->db_page_off + gc->db_page_size * ((u64)resp.db_id + 1) > gc->bar0_size) {
+	if (!mana_gd_is_valid_doorbell(gc, resp.db_id)) {
 		dev_err(gc->dev, "Doorbell ID %u out of range\n", resp.db_id);
 		return -EPROTO;
 	}
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index fb9f38f65911ca9e4171f03ff7f9c8f2a40b5b28..130b249318f208ae8369c98facf5113a3743cfd4 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -123,6 +123,15 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 	switch (event->type) {
 	case GDMA_EQE_HWC_INIT_EQ_ID_DB:
 		eq_db.as_uint32 = event->details[0];
+		if (!mana_gd_is_valid_doorbell(gd->gdma_context,
+					       eq_db.doorbell)) {
+			dev_err(hwc->dev, "Invalid HWC doorbell %u\n",
+				eq_db.doorbell);
+			WRITE_ONCE(hwc->hwc_init_error, -EPROTO);
+			complete(&hwc->hwc_init_eqe_comp);
+			break;
+		}
+
 		hwc->cq->gdma_eq->id = eq_db.eq_id;
 		gd->doorbell = eq_db.doorbell;
 		break;
@@ -182,6 +191,10 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 		break;
 
 	case GDMA_EQE_HWC_INIT_DONE:
+		if (gd->doorbell == INVALID_DOORBELL) {
+			dev_err(hwc->dev, "Missing HWC doorbell\n");
+			WRITE_ONCE(hwc->hwc_init_error, -EPROTO);
+		}
 		complete(&hwc->hwc_init_eqe_comp);
 		break;
 
@@ -676,6 +689,8 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
 	struct gdma_queue *cq = hwc->cq->gdma_cq;
 	int err;
 
+	gc->hwc.doorbell = INVALID_DOORBELL;
+	WRITE_ONCE(hwc->hwc_init_error, 0);
 	init_completion(&hwc->hwc_init_eqe_comp);
 
 	err = mana_smc_setup_hwc(&gc->shm_channel, false,
@@ -690,6 +705,10 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
 	if (!wait_for_completion_timeout(&hwc->hwc_init_eqe_comp, 60 * HZ))
 		return -ETIMEDOUT;
 
+	err = READ_ONCE(hwc->hwc_init_error);
+	if (err)
+		return err;
+
 	*q_depth = hwc->hwc_init_q_depth_max;
 	*max_req_msg_size = hwc->hwc_init_max_req_msg_size;
 	*max_resp_msg_size = hwc->hwc_init_max_resp_msg_size;
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index 1f0f9897b806dc90d81cc9b9ba2c405bf5cb920b..bde68d6a99f01634f456a9b16eb74fba566e788c 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -1179,6 +1179,7 @@ int mana_gd_post_and_ring(struct gdma_queue *queue,
 int mana_gd_alloc_res_map(u32 res_avail, struct gdma_resource *r);
 void mana_gd_free_res_map(struct gdma_resource *r);
 
+bool mana_gd_is_valid_doorbell(struct gdma_context *gc, u32 db_id);
 void mana_gd_wq_ring_doorbell(struct gdma_context *gc,
 			      struct gdma_queue *queue);
 void mana_gd_wq_ring_doorbell_ext(struct gdma_context *gc, struct gdma_queue *queue,
diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h
index 1ab2d66c891e42f3a847e62acf75b69fcf7ffb1e..113b01325137bfbab4a0b4c42f1ee883dbcbedb5 100644
--- a/include/net/mana/hw_channel.h
+++ b/include/net/mana/hw_channel.h
@@ -186,6 +186,7 @@ struct hw_channel_context {
 	u32 hwc_init_max_req_msg_size;
 	u32 hwc_init_max_resp_msg_size;
 
+	int hwc_init_error;
 	struct completion hwc_init_eqe_comp;
 
 	struct hwc_wq *rxq;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it Wei Hu
@ 2026-11-24 15:40 ` Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 3/5] net: mana: protect the HWC response buffer until the sender returns Wei Hu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

From: Long Li <longli@microsoft.com>
Date: Mon, 7 Sep 2026 20:51:55 -0700

Once ESTABLISH_HWC submits queue addresses, a failed response does not
give the memory back to the driver. Serialize setup and teardown on the
shared mailbox. If DESTROY_HWC fails, stop IRQ callbacks and keep the
queues for another destroy attempt rather than freeing their DMA.

On teardown, withdraw the CQ table and wait for readers before freeing
the HWC queues. Use the same table bound for allocation and dispatch.

A failed PCI probe has no context left to retry the destroy. Do not
start another automatic probe that could lose another set of coherent
allocations. A failed resume can keep the binding and retry in place.

Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Wei Hu <weh@microsoft.com>
---
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |   4 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |  41 +++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    | 132 +++++++++----
 .../net/ethernet/microsoft/mana/hw_channel.c  | 187 +++++++++++++++---
 drivers/net/ethernet/microsoft/mana/mana_en.c |   4 +-
 .../net/ethernet/microsoft/mana/shm_channel.c |  58 +++++-
 include/net/mana/gdma.h                       |   4 +
 include/net/mana/hw_channel.h                 |   8 +
 include/net/mana/shm_channel.h                |  10 +-
 9 files changed, 369 insertions(+), 79 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/gdma_cdx.c b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
index 0d01e3d2f0d96f67dda17f40a8266bf663697c0d..2e0dcb902d7e263fad7341a1756441ec10d8339d 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
@@ -279,7 +279,7 @@ unmap_bar:
 	iounmap(bar0_va);
 free_gc:
 	dev_set_drvdata(&cdx_dev->dev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 clear_master:
 	cdx_clear_master(cdx_dev);
 	return err;
@@ -298,7 +298,7 @@ static int mana_cdx_gd_remove(struct cdx_device *cdx_dev)
 	iounmap(gc->bar0_va);
 
 	dev_set_drvdata(&cdx_dev->dev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 	return 0;
 }
 
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index 673a4754c9dd00a8a0b4436e27ce1c433d85c2ff..2d495db51d7463e260d32f9a52870df578ef0bee 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -11,6 +11,7 @@
 #include <linux/irqdomain.h>
 #include <linux/export.h>
 #include <linux/uaccess.h>
+#include <linux/vmalloc.h>
 
 #include <net/mana/mana.h>
 #include <net/mana/hw_channel.h>
@@ -775,9 +776,15 @@ void mana_gd_free_service_wq(struct gdma_context *gc)
 static void mana_gd_schedule_eq_cqs(struct gdma_queue *eq)
 {
 	struct gdma_context *gc = eq->gdma_dev->gdma_context;
+	struct gdma_queue **cq_table;
 	struct gdma_queue *cq;
 	u8 i;
 
+	/* The IRQ's RCU read-side section protects this table snapshot. */
+	cq_table = smp_load_acquire(&gc->cq_table);
+	if (!cq_table)
+		return;
+
 	for (i = 0; i < GDMA_EQ_MAX_CHILD_CQ; i++) {
 		cq = rcu_dereference(eq->eq.child_cq[i]);
 
@@ -785,7 +792,7 @@ static void mana_gd_schedule_eq_cqs(struct gdma_queue *eq)
 			continue;
 
 		if (cq->id >= READ_ONCE(gc->max_num_cqs) ||
-		    !gc->cq_table || gc->cq_table[cq->id] != cq)
+		    READ_ONCE(cq_table[cq->id]) != cq)
 			continue;
 
 		if (cq->cq.callback)
@@ -800,6 +807,7 @@ static void mana_gd_process_eqe(struct gdma_queue *eq)
 	union gdma_eqe_info eqe_info;
 	enum gdma_eqe_type type;
 	struct gdma_event event;
+	struct gdma_queue **cq_table;
 	struct gdma_queue *cq;
 	struct gdma_eqe *eqe;
 	u32 cq_id;
@@ -811,11 +819,16 @@ static void mana_gd_process_eqe(struct gdma_queue *eq)
 	switch (type) {
 	case GDMA_EQE_COMPLETION:
 		cq_id = eqe->details[0] & 0xFFFFFF;
-		if (WARN_ON_ONCE(cq_id >= gc->max_num_cqs))
+		/* HWC teardown unpublishes this table and waits for these
+		 * RCU readers before freeing it, then fences its own EQ.
+		 */
+		cq_table = smp_load_acquire(&gc->cq_table);
+		if (!cq_table || cq_id >= READ_ONCE(gc->max_num_cqs))
 			break;
 
-		cq = gc->cq_table[cq_id];
-		if (WARN_ON_ONCE(!cq || cq->type != GDMA_CQ || cq->id != cq_id))
+		cq = READ_ONCE(cq_table[cq_id]);
+		if (!cq || WARN_ON_ONCE(cq->type != GDMA_CQ ||
+					cq->id != cq_id))
 			break;
 
 		if (cq->cq.callback)
@@ -1047,23 +1060,32 @@ out:
 	return err;
 }
 
-static void mana_gd_destroy_eq(struct gdma_context *gc, bool flush_evenets,
+static void mana_gd_destroy_eq(struct gdma_context *gc, bool flush_events,
 			       struct gdma_queue *queue)
 {
 	int err;
 
-	if (flush_evenets) {
+	if (queue->eq.msix_index == INVALID_PCI_MSIX_INDEX)
+		return;
+
+	if (flush_events) {
 		err = mana_gd_test_eq(gc, queue);
 		if (err && mana_need_log(gc, err))
 			dev_warn(gc->dev, "Failed to flush EQ: %d\n", err);
 	}
 
 	mana_gd_deregister_irq(queue);
+	queue->eq.msix_index = INVALID_PCI_MSIX_INDEX;
 
 	if (queue->eq.disable_needed)
 		mana_gd_disable_queue(queue);
 }
 
+void mana_gd_fence_eq(struct gdma_context *gc, struct gdma_queue *queue)
+{
+	mana_gd_destroy_eq(gc, false, queue);
+}
+
 static int mana_gd_create_eq(struct gdma_dev *gd,
 			     const struct gdma_queue_spec *spec,
 			     bool create_hwq, struct gdma_queue *queue)
@@ -2136,6 +2158,13 @@ void mana_gd_cleanup(struct gdma_context *gc)
 }
 EXPORT_SYMBOL_NS(mana_gd_cleanup, "NET_MANA");
 
+void mana_gd_free_context(struct gdma_context *gc)
+{
+	mana_hwc_free_retained_channel(gc);
+	vfree(gc);
+}
+EXPORT_SYMBOL_NS(mana_gd_free_context, "NET_MANA");
+
 static int __init gdma_core_init(void)
 {
 	mana_debugfs_root = debugfs_create_dir("mana", NULL);
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
index 208dadbcf977ca965fb48a37bef0db7b5019d7f1..cec2e548f36ea70bd821bc085f77ac94e78b4541 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
@@ -19,7 +19,6 @@
 struct mana_dev_recovery {
 	struct list_head list;
 	struct pci_dev *pdev;
-	enum gdma_eqe_type type;
 };
 
 static struct mana_dev_recovery_work {
@@ -32,49 +31,84 @@ static struct 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);
+static struct pci_driver mana_driver;
 
 #define MANA_SERVICE_PERIOD 10
 
-static void mana_serv_rescan(struct pci_dev *pdev)
-{
-	struct pci_bus *parent;
+enum mana_rescan_reason {
+	MANA_RESCAN_PROBE,
+	MANA_RESCAN_RESET,
+	MANA_RESCAN_FPGA,
+};
 
-	pci_lock_rescan_remove();
+/* The rescan/remove lock serializes service removals. A synchronous
+ * ->remove() on this task can veto the scan, including for a sibling
+ * removed along with the upstream bridge.
+ */
+static struct task_struct *mana_rescan_task;
 
-	parent = pdev->bus;
-	if (!parent) {
-		dev_err(&pdev->dev, "MANA service: no parent bus\n");
-		goto out;
-	}
+static int mana_check_unbound(struct pci_dev *pdev, void *data)
+{
+	bool *unbound = data;
 
-	pci_stop_and_remove_bus_device(pdev);
-	pci_rescan_bus(parent);
+	if (READ_ONCE(pdev->driver) ||
+	    !pci_match_id(mana_driver.id_table, pdev))
+		return 0;
 
-out:
-	pci_unlock_rescan_remove();
+	*unbound = true;
+	return 1;
 }
 
-static void mana_serv_fpga(struct pci_dev *pdev)
+static void mana_serv_rescan(struct pci_dev *pdev,
+			     enum mana_rescan_reason reason)
 {
-	struct pci_bus *bus, *parent;
+	struct pci_dev *target = pdev;
+	struct pci_bus *parent;
+	bool unbound = false;
 
 	pci_lock_rescan_remove();
-
-	bus = pdev->bus;
-	if (!bus) {
-		dev_err(&pdev->dev, "MANA service: no bus\n");
+	if (!device_is_registered(&pdev->dev))
 		goto out;
+
+	scoped_guard(device, &pdev->dev) {
+		if (reason == MANA_RESCAN_PROBE) {
+			if (pdev->dev.driver)
+				goto out;
+		} else if (pdev->driver != &mana_driver) {
+			goto out;
+		} else if (reason == MANA_RESCAN_FPGA) {
+			struct gdma_context *gc = pci_get_drvdata(pdev);
+
+			/* An unbound sibling cannot veto the bridge rescan in
+			 * ->remove(). Its last probe may have lost HWC DMA.
+			 */
+			target = pci_upstream_bridge(pdev);
+			if (target)
+				pci_walk_bus(target->subordinate,
+					     mana_check_unbound, &unbound);
+			if (unbound) {
+				dev_err(&pdev->dev,
+					"Unbound MANA function, skipping bridge rescan\n");
+				clear_bit(GC_IN_SERVICE, &gc->flags);
+				goto out;
+			}
+		}
 	}
 
-	parent = bus->parent;
-	if (!parent) {
+	if (!target || !target->bus) {
 		dev_err(&pdev->dev, "MANA service: no parent bus\n");
 		goto out;
 	}
 
-	pci_stop_and_remove_bus_device(bus->self);
+	parent = target->bus;
+	WRITE_ONCE(mana_rescan_task, current);
+	pci_stop_and_remove_bus_device(target);
+	if (!READ_ONCE(mana_rescan_task))
+		goto out;
+	WRITE_ONCE(mana_rescan_task, NULL);
 
-	msleep(MANA_SERVICE_PERIOD * 1000);
+	if (reason == MANA_RESCAN_FPGA)
+		msleep(MANA_SERVICE_PERIOD * 1000);
 
 	pci_rescan_bus(parent);
 
@@ -82,19 +116,18 @@ out:
 	pci_unlock_rescan_remove();
 }
 
-static void mana_serv_reset(struct pci_dev *pdev)
+/* Return true if recovery needs to escalate to PCI re-enumeration. */
+static bool mana_serv_reset(struct pci_dev *pdev)
 {
-	struct gdma_context *gc = pci_get_drvdata(pdev);
 	struct hw_channel_context *hwc;
+	struct gdma_context *gc;
 	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;
-	}
+	guard(device)(&pdev->dev);
+	if (pdev->driver != &mana_driver)
+		return false;
 
+	gc = pci_get_drvdata(pdev);
 	hwc = gc->hwc.driver_data;
 	if (!hwc) {
 		dev_err(&pdev->dev, "MANA service: no HWC\n");
@@ -114,8 +147,7 @@ static void mana_serv_reset(struct pci_dev *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;
+		return true;
 	}
 
 	if (ret)
@@ -125,17 +157,19 @@ static void mana_serv_reset(struct pci_dev *pdev)
 
 out:
 	clear_bit(GC_IN_SERVICE, &gc->flags);
+	return false;
 }
 
 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);
+		mana_serv_rescan(pdev, MANA_RESCAN_FPGA);
 		break;
 
 	case GDMA_EQE_HWC_RESET_REQUEST:
-		mana_serv_reset(pdev);
+		if (mana_serv_reset(pdev))
+			mana_serv_rescan(pdev, MANA_RESCAN_RESET);
 		break;
 
 	default:
@@ -160,7 +194,7 @@ static void mana_recovery_delayed_func(struct work_struct *w)
 		list_del(&dev->list);
 		spin_unlock_irqrestore(&work->lock, flags);
 
-		mana_do_service(dev->type, dev->pdev);
+		mana_serv_rescan(dev->pdev, MANA_RESCAN_PROBE);
 		pci_dev_put(dev->pdev);
 		kfree(dev);
 
@@ -632,8 +666,16 @@ unmap_bar:
 	xa_destroy(&gc->irq_contexts);
 	pci_iounmap(pdev, bar0_va);
 free_gc:
+	/* No binding remains to retry DESTROY. Do not start another probe
+	 * which could abandon another set of coherent allocations.
+	 */
+	if (gc->hwc.driver_data) {
+		dev_err(&pdev->dev,
+			"HWC teardown failed, disabling probe recovery\n");
+		err = -ENOTRECOVERABLE;
+	}
 	pci_set_drvdata(pdev, NULL);
-	vfree(gc);
+	mana_gd_free_context(gc);
 release_region:
 	pci_release_regions(pdev);
 disable_dev:
@@ -658,7 +700,6 @@ disable_dev:
 			return err;
 
 		dev->pdev = pci_dev_get(pdev);
-		dev->type = GDMA_EQE_HWC_RESET_REQUEST;
 
 		spin_lock_irqsave(&mana_dev_recovery_work.lock, flags);
 		list_add_tail(&dev->list, &mana_dev_recovery_work.dev_list);
@@ -682,11 +723,16 @@ static void mana_gd_remove(struct pci_dev *pdev)
 
 	mana_gd_cleanup(gc);
 
+	if (gc->hwc.driver_data && READ_ONCE(mana_rescan_task) == current) {
+		dev_err(gc->dev, "HWC teardown failed, skipping PCI rescan\n");
+		WRITE_ONCE(mana_rescan_task, NULL);
+	}
+
 	xa_destroy(&gc->irq_contexts);
 
 	pci_iounmap(pdev, gc->bar0_va);
 
-	vfree(gc);
+	mana_gd_free_context(gc);
 
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
@@ -714,7 +760,7 @@ static int mana_gd_resume(struct pci_dev *pdev)
 
 	err = mana_gd_setup(gc);
 	if (err)
-		return err;
+		goto check_hwc;
 
 	err = mana_probe(&gc->mana, true);
 	if (err)
@@ -728,6 +774,10 @@ static int mana_gd_resume(struct pci_dev *pdev)
 
 cleanup_gd:
 	mana_gd_cleanup(gc);
+check_hwc:
+	/* Keep the binding and DMA handles for a later DESTROY retry. */
+	if (gc->hwc.driver_data)
+		return -ENOTRECOVERABLE;
 	return err;
 }
 
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index 130b249318f208ae8369c98facf5113a3743cfd4..39a0ed32e43c7953885146b647249db6e03fb8bb 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -143,7 +143,7 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 
 		switch (type) {
 		case HWC_INIT_DATA_CQID:
-			hwc->cq->gdma_cq->id = val;
+			WRITE_ONCE(hwc->hwc_init_cq_id, val);
 			break;
 
 		case HWC_INIT_DATA_RQID:
@@ -167,7 +167,11 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 			break;
 
 		case HWC_INIT_DATA_MAX_NUM_CQS:
-			gd->gdma_context->max_num_cqs = val;
+			/* Store only; establish_channel() commits it to
+			 * max_num_cqs once, so a later event cannot grow the
+			 * bound past the allocation; pairs with READ_ONCE().
+			 */
+			WRITE_ONCE(hwc->hwc_init_max_num_cqs, val);
 			break;
 
 		case HWC_INIT_DATA_PDID:
@@ -395,9 +399,43 @@ static void mana_hwc_comp_event(void *ctx, struct gdma_queue *q_self)
 	mana_gd_ring_cq(q_self, SET_ARM_BIT);
 }
 
+static int mana_hwc_publish_cq(struct gdma_context *gc,
+			       struct gdma_queue *cq)
+{
+	struct gdma_queue **cq_table = READ_ONCE(gc->cq_table);
+	u32 id = READ_ONCE(cq->id);
+
+	if (!cq_table || id >= READ_ONCE(gc->max_num_cqs) ||
+	    READ_ONCE(cq_table[id]))
+		return -EINVAL;
+
+	WRITE_ONCE(cq_table[id], cq);
+
+	return 0;
+}
+
+static void mana_hwc_unpublish_cq(struct gdma_context *gc,
+				  struct gdma_queue *cq)
+{
+	struct gdma_queue **cq_table = READ_ONCE(gc->cq_table);
+	u32 id;
+
+	if (!cq_table || !cq)
+		return;
+
+	id = READ_ONCE(cq->id);
+	if (id < READ_ONCE(gc->max_num_cqs) &&
+	    READ_ONCE(cq_table[id]) == cq)
+		WRITE_ONCE(cq_table[id], NULL);
+}
+
 static void mana_hwc_destroy_cq(struct gdma_context *gc, struct hwc_cq *hwc_cq)
 {
-	kfree(hwc_cq->comp_buf);
+	/* Fence callbacks first, but keep the parent EQ alive until CQ
+	 * destruction has detached its child entry.
+	 */
+	if (hwc_cq->gdma_eq)
+		mana_gd_fence_eq(gc, hwc_cq->gdma_eq);
 
 	if (hwc_cq->gdma_cq)
 		mana_gd_destroy_queue(gc, hwc_cq->gdma_cq);
@@ -405,6 +443,7 @@ static void mana_hwc_destroy_cq(struct gdma_context *gc, struct hwc_cq *hwc_cq)
 	if (hwc_cq->gdma_eq)
 		mana_gd_destroy_queue(gc, hwc_cq->gdma_eq);
 
+	kfree(hwc_cq->comp_buf);
 	kfree(hwc_cq);
 }
 
@@ -687,6 +726,9 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
 	struct gdma_queue *sq = hwc->txq->gdma_wq;
 	struct gdma_queue *eq = hwc->cq->gdma_eq;
 	struct gdma_queue *cq = hwc->cq->gdma_cq;
+	struct gdma_queue **cq_table;
+	u32 num_cqs;
+	u32 cq_id;
 	int err;
 
 	gc->hwc.doorbell = INVALID_DOORBELL;
@@ -698,7 +740,7 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
 				 cq->mem_info.dma_handle,
 				 rq->mem_info.dma_handle,
 				 sq->mem_info.dma_handle,
-				 eq->eq.msix_index);
+				 eq->eq.msix_index, &hwc->setup_active);
 	if (err)
 		return err;
 
@@ -713,15 +755,45 @@ static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
 	*max_req_msg_size = hwc->hwc_init_max_req_msg_size;
 	*max_resp_msg_size = hwc->hwc_init_max_resp_msg_size;
 
-	/* Both were set in mana_hwc_init_event_handler(). */
-	if (WARN_ON(cq->id >= gc->max_num_cqs))
+	/* Snapshot the device-reported count and id once, so the same value
+	 * sizes, bounds and indexes cq_table even across the sleeping
+	 * vcalloc() and a concurrent init event.
+	 */
+	num_cqs = READ_ONCE(hwc->hwc_init_max_num_cqs);
+	cq_id = READ_ONCE(hwc->hwc_init_cq_id);
+
+	/* Both operands come from untrusted HWC bootstrap events; a missing
+	 * MAX_NUM_CQS leaves num_cqs at 0.  Reject rather than WARN_ON() so a
+	 * malformed device response cannot panic a panic_on_warn guest.
+	 */
+	if (cq_id >= num_cqs) {
+		dev_err_ratelimited(hwc->dev,
+				    "HWC: bad CQ id %u >= max %u\n",
+				    cq_id, num_cqs);
 		return -EPROTO;
+	}
+
+	/* Init events remain enabled, so commit the validated CQ ID once. */
+	WRITE_ONCE(cq->id, cq_id);
 
-	gc->cq_table = vcalloc(gc->max_num_cqs, sizeof(struct gdma_queue *));
-	if (!gc->cq_table)
+	cq_table = vcalloc(num_cqs, sizeof(*cq_table));
+	if (!cq_table)
 		return -ENOMEM;
 
-	gc->cq_table[cq->id] = cq;
+	/* Publish the bound and the initialised table together; the release
+	 * pairs with smp_load_acquire() in mana_gd_process_eqe().
+	 */
+	WRITE_ONCE(gc->max_num_cqs, num_cqs);
+	/* Pairs with smp_load_acquire() in mana_gd_process_eqe(). */
+	smp_store_release(&gc->cq_table, cq_table);
+
+	err = mana_hwc_publish_cq(gc, cq);
+	if (err) {
+		dev_err_ratelimited(hwc->dev,
+				    "HWC: failed to publish CQ %u: %d\n",
+				    cq_id, err);
+		return err;
+	}
 
 	return 0;
 }
@@ -770,6 +842,18 @@ out:
 	return err;
 }
 
+static void mana_hwc_clear_cq_table(struct gdma_context *gc)
+{
+	struct gdma_queue **cq_table;
+
+	cq_table = READ_ONCE(gc->cq_table);
+	WRITE_ONCE(gc->max_num_cqs, 0);
+	/* Stop new table readers before waiting for prior RCU readers. */
+	smp_store_release(&gc->cq_table, NULL);
+	synchronize_rcu();
+	vfree(cq_table);
+}
+
 int mana_hwc_create_channel(struct gdma_context *gc)
 {
 	u32 max_req_msg_size, max_resp_msg_size;
@@ -778,6 +862,13 @@ int mana_hwc_create_channel(struct gdma_context *gc)
 	u16 q_depth_max;
 	int err;
 
+	/* Retry a retained context before assigning queues to the PF again. */
+	if (gd->driver_data) {
+		mana_hwc_destroy_channel(gc);
+		if (gd->driver_data)
+			return -ETIMEDOUT;
+	}
+
 	hwc = kzalloc_obj(*hwc);
 	if (!hwc)
 		return -ENOMEM;
@@ -827,25 +918,45 @@ out:
 	return err;
 }
 
+static void mana_hwc_fence_channel(struct gdma_context *gc,
+				   struct hw_channel_context *hwc)
+{
+	if (!hwc->cq)
+		return;
+
+	if (hwc->cq->gdma_eq)
+		mana_gd_fence_eq(gc, hwc->cq->gdma_eq);
+
+	if (hwc->cq->gdma_cq)
+		mana_hwc_unpublish_cq(gc, hwc->cq->gdma_cq);
+}
+
 void mana_hwc_destroy_channel(struct gdma_context *gc)
 {
 	struct hw_channel_context *hwc = gc->hwc.driver_data;
+	int err;
 
 	if (!hwc)
 		return;
 
-	/* gc->max_num_cqs is set in mana_hwc_init_event_handler(). If it's
-	 * non-zero, the HWC worked and we should tear down the HWC here.
+	/* An unacknowledged destroy leaves the PF's mappings live.  Fence
+	 * software dispatch, but retain every PF-visible allocation.
 	 */
-	if (gc->max_num_cqs > 0) {
-		mana_smc_teardown_hwc(&gc->shm_channel, false);
-		WRITE_ONCE(gc->max_num_cqs, 0);
+	err = mana_smc_teardown_hwc(&gc->shm_channel, false,
+				    &hwc->setup_active);
+	if (err) {
+		dev_err(hwc->dev,
+			"HWC teardown failed: %d, retaining PF-visible resources\n",
+			err);
+		mana_hwc_fence_channel(gc, hwc);
+		return;
 	}
 
-	if (hwc->cq)
-		mana_gd_detach_cq(gc, hwc->cq->gdma_cq);
+	mana_hwc_clear_cq_table(gc);
 
-	synchronize_rcu();
+	/* Fence the EQ before releasing the remaining HWC state. */
+	if (hwc->cq)
+		mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq);
 
 	if (hwc->txq)
 		mana_hwc_destroy_wq(hwc, hwc->txq);
@@ -853,9 +964,6 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
 	if (hwc->rxq)
 		mana_hwc_destroy_wq(hwc, hwc->rxq);
 
-	if (hwc->cq)
-		mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq);
-
 	kfree(hwc->caller_ctx);
 	hwc->caller_ctx = NULL;
 
@@ -871,9 +979,44 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
 	kfree(hwc);
 	gc->hwc.driver_data = NULL;
 	gc->hwc.gdma_context = NULL;
+}
 
-	vfree(gc->cq_table);
-	gc->cq_table = NULL;
+static void mana_hwc_free_retained_wq(struct hwc_wq *wq)
+{
+	if (!wq)
+		return;
+
+	kfree(wq->msg_buf);
+	kfree(wq->gdma_wq);
+	kfree(wq);
+}
+
+/* Final disposal after IRQ and service-work teardown, not a retry path.
+ * Free only software state: unacknowledged HWC DMA allocations stay live.
+ */
+void mana_hwc_free_retained_channel(struct gdma_context *gc)
+{
+	struct hw_channel_context *hwc = gc->hwc.driver_data;
+
+	if (!hwc)
+		return;
+
+	gc->hwc.driver_data = NULL;
+	mana_hwc_clear_cq_table(gc);
+
+	if (hwc->cq) {
+		kfree(hwc->cq->gdma_eq);
+		kfree(hwc->cq->gdma_cq);
+		kfree(hwc->cq->comp_buf);
+		kfree(hwc->cq);
+	}
+
+	mana_hwc_free_retained_wq(hwc->txq);
+	mana_hwc_free_retained_wq(hwc->rxq);
+	kfree(hwc->caller_ctx);
+	mana_gd_free_res_map(&hwc->inflight_msg_res);
+	kfree(hwc);
+	gc->hwc.gdma_context = NULL;
 }
 
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 7e9223143fc75ff82a45bcdd6f320564b1befa15..744e6ceb7d2b9d88bc9dd3be83a6b280da30b5a5 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -2736,8 +2736,8 @@ static void mana_destroy_txq(struct mana_port_context *apc)
 		if (apc->tx_qp[i]->txq.napi_initialized) {
 			/* Detach the CQ only after the WQ object is destroyed,
 			 * so a completion EQE that arrives before then still
-			 * finds the CQ in cq_table[] rather than hitting the
-			 * WARN in mana_gd_process_eqe(). One grace period then
+			 * finds the CQ in cq_table[] rather than being dropped
+			 * by mana_gd_process_eqe(). One grace period then
 			 * covers both mana_gd_intr() and NAPI users.
 			 */
 			mana_gd_detach_cq(gc, apc->tx_qp[i]->tx_cq.gdma_cq);
diff --git a/drivers/net/ethernet/microsoft/mana/shm_channel.c b/drivers/net/ethernet/microsoft/mana/shm_channel.c
index d21b5db06e5092d82249fb1053d07f65aa38490c..df9d05062dd57b465bfab5dba0c476867526ed3b 100644
--- a/drivers/net/ethernet/microsoft/mana/shm_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/shm_channel.c
@@ -125,13 +125,24 @@ static int mana_smc_read_response(struct shm_channel *sc, u32 msg_type,
 void mana_smc_init(struct shm_channel *sc, struct device *dev,
 		   void __iomem *base)
 {
+	/* The first call precedes channel publication. Later calls refresh the
+	 * BAR mapping after reset or resume without reinitializing a live lock.
+	 */
+	if (!sc->transaction_lock_initialized) {
+		mutex_init(&sc->transaction_lock);
+		sc->transaction_lock_initialized = true;
+	}
+
+	mutex_lock(&sc->transaction_lock);
 	sc->dev = dev;
 	sc->base = base;
+	mutex_unlock(&sc->transaction_lock);
 }
 
-int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
-		       u64 cq_addr, u64 rq_addr, u64 sq_addr,
-		       u32 eq_msix_index)
+static int mana_smc_setup_hwc_locked(struct shm_channel *sc, bool reset_vf,
+				     u64 eq_addr, u64 cq_addr, u64 rq_addr,
+				     u64 sq_addr, u32 eq_msix_index,
+				     bool *submitted)
 {
 	union smc_proto_hdr *hdr;
 	u16 all_addr_h4bits = 0;
@@ -144,6 +155,9 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 	int err;
 	int i;
 
+	lockdep_assert_held(&sc->transaction_lock);
+	*submitted = false;
+
 	/* Ensure VF already has possession of shared memory */
 	err = mana_smc_poll_register(sc->base, false);
 	if (err) {
@@ -229,6 +243,7 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 	/* Write 256-message buffer to shared memory (final 32-bit write
 	 * triggers HW to set possession bit to PF).
 	 */
+	*submitted = true;
 	dword = (u32 *)shm_buf;
 	for (i = 0; i < SMC_APERTURE_DWORDS; i++)
 		writel(*dword++, sc->base + i * SMC_BASIC_UNIT);
@@ -248,11 +263,32 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 	return 0;
 }
 
-int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf)
+int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
+		       u64 cq_addr, u64 rq_addr, u64 sq_addr,
+		       u32 eq_msix_index, bool *submitted)
+{
+	int err;
+
+	mutex_lock(&sc->transaction_lock);
+	err = mana_smc_setup_hwc_locked(sc, reset_vf, eq_addr, cq_addr,
+					rq_addr, sq_addr, eq_msix_index,
+					submitted);
+	mutex_unlock(&sc->transaction_lock);
+
+	return err;
+}
+
+static int mana_smc_teardown_hwc_locked(struct shm_channel *sc, bool reset_vf,
+					bool *setup_active)
 {
 	union smc_proto_hdr hdr = {};
 	int err;
 
+	lockdep_assert_held(&sc->transaction_lock);
+
+	if (!*setup_active)
+		return 0;
+
 	/* Ensure already has possession of shared memory */
 	err = mana_smc_poll_register(sc->base, false);
 	if (err) {
@@ -283,5 +319,19 @@ int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf)
 		return err;
 	}
 
+	*setup_active = false;
+
 	return 0;
 }
+
+int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf,
+			  bool *setup_active)
+{
+	int err;
+
+	mutex_lock(&sc->transaction_lock);
+	err = mana_smc_teardown_hwc_locked(sc, reset_vf, setup_active);
+	mutex_unlock(&sc->transaction_lock);
+
+	return err;
+}
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index bde68d6a99f01634f456a9b16eb74fba566e788c..2da086a3b8f721d51827553d78261240c8d69a6f 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -600,6 +600,9 @@ int mana_gd_create_mana_wq_cq(struct gdma_dev *gd,
 
 void mana_gd_destroy_queue(struct gdma_context *gc, struct gdma_queue *queue);
 
+/* Remove an EQ from interrupt dispatch without freeing its queue memory. */
+void mana_gd_fence_eq(struct gdma_context *gc, struct gdma_queue *queue);
+
 int mana_gd_poll_cq(struct gdma_queue *cq, struct gdma_comp *comp, int num_cqe);
 
 void mana_gd_ring_cq(struct gdma_queue *cq, u8 arm_bit);
@@ -1150,6 +1153,7 @@ int mana_gd_verify_vf_version(struct gdma_context *gc);
 int mana_gd_query_max_resources(struct gdma_context *gc);
 int mana_gd_setup(struct gdma_context *gc);
 void mana_gd_cleanup(struct gdma_context *gc);
+void mana_gd_free_context(struct gdma_context *gc);
 int mana_gd_detect_devices(struct gdma_context *gc);
 int mana_gd_init_registers(struct gdma_context *gc);
 irqreturn_t mana_gd_intr(int irq, void *arg);
diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h
index 113b01325137bfbab4a0b4c42f1ee883dbcbedb5..fc2c26f809047703244ffd30ff4a7a115c682617 100644
--- a/include/net/mana/hw_channel.h
+++ b/include/net/mana/hw_channel.h
@@ -185,6 +185,8 @@ struct hw_channel_context {
 	u16 hwc_init_q_depth_max;
 	u32 hwc_init_max_req_msg_size;
 	u32 hwc_init_max_resp_msg_size;
+	u32 hwc_init_max_num_cqs;
+	u32 hwc_init_cq_id;
 
 	int hwc_init_error;
 	struct completion hwc_init_eqe_comp;
@@ -200,11 +202,17 @@ struct hw_channel_context {
 	u32 dest_vrcq_id;
 	u32 hwc_timeout;
 
+	/* Once ESTABLISH_HWC submits the queue addresses, a setup error
+	 * does not release them. The PF may still use the rings and buffers
+	 * until it acknowledges DESTROY_HWC.
+	 */
+	bool setup_active;
 	struct hwc_caller_ctx *caller_ctx;
 };
 
 int mana_hwc_create_channel(struct gdma_context *gc);
 void mana_hwc_destroy_channel(struct gdma_context *gc);
+void mana_hwc_free_retained_channel(struct gdma_context *gc);
 
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 			  const void *req, u32 resp_len, void *resp);
diff --git a/include/net/mana/shm_channel.h b/include/net/mana/shm_channel.h
index dbabcfb95daf3e87b39a657e3a5f23a1508d4f31..c8daa61fa759e167a97059887fb88a8b9626ed8f 100644
--- a/include/net/mana/shm_channel.h
+++ b/include/net/mana/shm_channel.h
@@ -4,6 +4,8 @@
 #ifndef _SHM_CHANNEL_H
 #define _SHM_CHANNEL_H
 
+#include <linux/mutex.h>
+
 #define SMC_APERTURE_BITS 256
 #define SMC_BASIC_UNIT (sizeof(u32))
 #define SMC_APERTURE_DWORDS (SMC_APERTURE_BITS / (SMC_BASIC_UNIT * 8))
@@ -13,6 +15,9 @@
 struct shm_channel {
 	struct device *dev;
 	void __iomem *base;
+	/* Protects base and complete aperture request/response transactions. */
+	struct mutex transaction_lock;
+	bool transaction_lock_initialized;
 };
 
 void mana_smc_init(struct shm_channel *sc, struct device *dev,
@@ -20,8 +25,9 @@ void mana_smc_init(struct shm_channel *sc, struct device *dev,
 
 int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
 		       u64 cq_addr, u64 rq_addr, u64 sq_addr,
-		       u32 eq_msix_index);
+		       u32 eq_msix_index, bool *submitted);
 
-int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf);
+int mana_smc_teardown_hwc(struct shm_channel *sc, bool reset_vf,
+			  bool *setup_active);
 
 #endif /* _SHM_CHANNEL_H */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v12 3/5] net: mana: protect the HWC response buffer until the sender returns
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown Wei Hu
@ 2026-11-24 15:40 ` Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests Wei Hu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

From: Long Li <longli@microsoft.com>
Date: Mon, 7 Sep 2026 20:51:56 -0700

A response can race with a sender that has timed out. Clear the output
pointer under the same lock used to copy the response, so the handler
cannot write to the caller's buffer after the sender returns.

Reset the completion and result under that lock when assigning a slot.
If the response wins the race with timeout, return its result. This
does not change admission or prevent reuse of the message ID.

Fixes: ca9c54d2d6a5 ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)")
Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Wei Hu <weh@microsoft.com>
---
 .../net/ethernet/microsoft/mana/hw_channel.c  | 125 +++++++++++++-----
 include/net/mana/hw_channel.h                 |   4 +-
 2 files changed, 95 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index 39a0ed32e43c7953885146b647249db6e03fb8bb..a98e58b83f9c75bf8b40183c73a9286670d4aef4 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -9,6 +9,7 @@
 static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)
 {
 	struct gdma_resource *r = &hwc->inflight_msg_res;
+	struct hwc_caller_ctx *ctx;
 	unsigned long flags;
 	u32 index;
 
@@ -19,8 +20,17 @@ static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)
 	index = find_first_zero_bit(hwc->inflight_msg_res.map,
 				    hwc->inflight_msg_res.size);
 
+	ctx = &hwc->caller_ctx[index];
+	spin_lock(&ctx->lock);
+	reinit_completion(&ctx->comp_event);
+	ctx->output_buf = NULL;
+	ctx->output_buflen = 0;
+	ctx->error = -EINPROGRESS;
+	ctx->status_code = 0;
+
 	bitmap_set(hwc->inflight_msg_res.map, index, 1);
 
+	spin_unlock(&ctx->lock);
 	spin_unlock_irqrestore(&r->lock, flags);
 
 	*msg_id = index;
@@ -90,14 +100,21 @@ static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
 	}
 
 	ctx = hwc->caller_ctx + msg_id;
-	err = mana_hwc_verify_resp_msg(ctx, resp_msg, resp_len);
-	if (err)
-		goto out;
 
-	ctx->status_code = resp_msg->status;
+	spin_lock(&ctx->lock);
+	if (!ctx->output_buf) {
+		spin_unlock(&ctx->lock);
+		mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
+		return;
+	}
 
-	memcpy(ctx->output_buf, resp_msg, resp_len);
-out:
+	err = mana_hwc_verify_resp_msg(ctx, resp_msg, resp_len);
+	if (!err) {
+		ctx->status_code = resp_msg->status;
+		memcpy(ctx->output_buf, resp_msg, resp_len);
+	}
+
+	ctx->output_buf = NULL;
 	ctx->error = err;
 
 	/* Must post rx wqe before complete(), otherwise the next rx may
@@ -106,6 +123,7 @@ out:
 	mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
 
 	complete(&ctx->comp_event);
+	spin_unlock(&ctx->lock);
 }
 
 static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
@@ -709,8 +727,10 @@ static int mana_hwc_test_channel(struct hw_channel_context *hwc, u16 q_depth,
 	if (!ctx)
 		return -ENOMEM;
 
-	for (i = 0; i < q_depth; ++i)
+	for (i = 0; i < q_depth; ++i) {
 		init_completion(&ctx[i].comp_event);
+		spin_lock_init(&ctx[i].lock);
+	}
 
 	hwc->caller_ctx = ctx;
 
@@ -1019,6 +1039,37 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)
 	gc->hwc.gdma_context = NULL;
 }
 
+static int mana_hwc_response_status(struct hw_channel_context *hwc,
+				    u32 command, int error, u32 status)
+{
+	if (error)
+		return error;
+
+	if (!status || status == GDMA_STATUS_MORE_ENTRIES)
+		return 0;
+
+	if (status == GDMA_STATUS_CMD_UNSUPPORTED)
+		return -EOPNOTSUPP;
+
+	if (command != MANA_QUERY_PHY_STAT)
+		dev_err(hwc->dev, "Command 0x%x failed with status: 0x%x\n",
+			command, status);
+
+	return -EPROTO;
+}
+
+static void mana_hwc_finish_request(struct hw_channel_context *hwc,
+				    struct hwc_caller_ctx *ctx, u16 msg_id)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&ctx->lock, flags);
+	ctx->output_buf = NULL;
+	spin_unlock_irqrestore(&ctx->lock, flags);
+
+	mana_hwc_put_msg_index(hwc, msg_id);
+}
+
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 			  const void *req, u32 resp_len, void *resp)
 {
@@ -1026,26 +1077,32 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 	struct hwc_wq *txq = hwc->txq;
 	struct gdma_req_hdr *req_msg;
 	struct hwc_caller_ctx *ctx;
+	unsigned long flags;
 	u32 dest_vrcq;
 	u32 dest_vrq;
 	u32 command;
+	u32 status;
 	u16 msg_id;
 	int err;
 
-	mana_hwc_get_msg_index(hwc, &msg_id);
+	err = mana_hwc_get_msg_index(hwc, &msg_id);
+	if (err)
+		return err;
 
 	tx_wr = &txq->msg_buf->reqs[msg_id];
+	ctx = hwc->caller_ctx + msg_id;
 
 	if (req_len > tx_wr->buf_len) {
 		dev_err(hwc->dev, "HWC: req msg size: %d > %d\n", req_len,
 			tx_wr->buf_len);
-		err = -EINVAL;
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return -EINVAL;
 	}
 
-	ctx = hwc->caller_ctx + msg_id;
+	spin_lock_irqsave(&ctx->lock, flags);
 	ctx->output_buf = resp;
 	ctx->output_buflen = resp_len;
+	spin_unlock_irqrestore(&ctx->lock, flags);
 
 	req_msg = (struct gdma_req_hdr *)tx_wr->buf_va;
 	if (req)
@@ -1067,11 +1124,24 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 	err = mana_hwc_post_tx_wqe(txq, tx_wr, dest_vrq, dest_vrcq, false);
 	if (err) {
 		dev_err(hwc->dev, "HWC: Failed to post send WQE: %d\n", err);
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return err;
 	}
 
 	if (!wait_for_completion_timeout(&ctx->comp_event,
-					 (msecs_to_jiffies(hwc->hwc_timeout)))) {
+					 msecs_to_jiffies(hwc->hwc_timeout))) {
+		spin_lock_irqsave(&ctx->lock, flags);
+		ctx->output_buf = NULL;
+		err = ctx->error;
+		status = ctx->status_code;
+		spin_unlock_irqrestore(&ctx->lock, flags);
+
+		if (err != -EINPROGRESS) {
+			mana_hwc_finish_request(hwc, ctx, msg_id);
+			return mana_hwc_response_status(hwc, command, err,
+							status);
+		}
+
 		if (hwc->hwc_timeout != 0)
 			dev_err(hwc->dev, "Command 0x%x timed out: %u ms\n",
 				command, hwc->hwc_timeout);
@@ -1080,27 +1150,16 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 		if (hwc->hwc_timeout > 1)
 			hwc->hwc_timeout = 1;
 
-		err = -ETIMEDOUT;
-		goto out;
+		mana_hwc_finish_request(hwc, ctx, msg_id);
+		return -ETIMEDOUT;
 	}
 
-	if (ctx->error) {
-		err = ctx->error;
-		goto out;
-	}
+	spin_lock_irqsave(&ctx->lock, flags);
+	ctx->output_buf = NULL;
+	err = ctx->error;
+	status = ctx->status_code;
+	spin_unlock_irqrestore(&ctx->lock, flags);
 
-	if (ctx->status_code && ctx->status_code != GDMA_STATUS_MORE_ENTRIES) {
-		if (ctx->status_code == GDMA_STATUS_CMD_UNSUPPORTED) {
-			err = -EOPNOTSUPP;
-			goto out;
-		}
-		if (command != MANA_QUERY_PHY_STAT)
-			dev_err(hwc->dev, "Command 0x%x failed with status: 0x%x\n",
-				command, ctx->status_code);
-		err = -EPROTO;
-		goto out;
-	}
-out:
-	mana_hwc_put_msg_index(hwc, msg_id);
-	return err;
+	mana_hwc_finish_request(hwc, ctx, msg_id);
+	return mana_hwc_response_status(hwc, command, err, status);
 }
diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h
index fc2c26f809047703244ffd30ff4a7a115c682617..bcaf276976a81dca825ee08804a3b2fa5ee24a9a 100644
--- a/include/net/mana/hw_channel.h
+++ b/include/net/mana/hw_channel.h
@@ -168,10 +168,12 @@ struct hwc_wq {
 
 struct hwc_caller_ctx {
 	struct completion comp_event;
+	/* Protects initialization, output storage and response state. */
+	spinlock_t lock;
 	void *output_buf;
 	u32 output_buflen;
 
-	u32 error; /* Linux error code */
+	int error; /* Linux error code */
 	u32 status_code;
 };
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
                   ` (2 preceding siblings ...)
  2026-11-24 15:40 ` [PATCH net-next v12 3/5] net: mana: protect the HWC response buffer until the sender returns Wei Hu
@ 2026-11-24 15:40 ` Wei Hu
  2026-11-24 15:40 ` [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth Wei Hu
  2026-11-24 15:44 ` [PATCH net-next v12 0/5] net: mana: concurrent HWC requests netdev-bot+sinfo
  5 siblings, 0 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

From: Long Li <longli@microsoft.com>
Date: Mon, 7 Sep 2026 20:51:57 -0700

Queue competing callers and publish their SQ entries with one doorbell.
Wait for that batch's replies and senders before posting the next. No
new request can reach the PF after an unanswered command's deadline,
even if its sender hasn't run yet. Do not reuse the ID or TX buffer
until the sender has finished and the reply has arrived.

On normal response timeout the PF drains old client DMA and invalidates
outstanding commands. Check for an unanswered command's deadline under
the slot lock before accepting or consuming a reply. This lets a queued
caller detect the timeout even when the owner hasn't run. Stop posting,
wake the senders and discard their unconsumed replies.

Allow RDMA teardown of old objects to finish locally without a destroy
reply. Neither a failed post nor an external reset request establishes
DMA quiescence.

Drain senders before destroying the channel. Keep the HWC mappings
until the PF acknowledges teardown.

Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Wei Hu <weh@microsoft.com>
---
 drivers/infiniband/hw/mana/main.c             |   3 +-
 drivers/infiniband/hw/mana/mr.c               |   6 +-
 .../net/ethernet/microsoft/mana/gdma_cdx.c    |   2 +
 .../net/ethernet/microsoft/mana/gdma_main.c   |  97 ++-
 .../net/ethernet/microsoft/mana/gdma_pci.c    |  12 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 710 ++++++++++++------
 include/net/mana/gdma.h                       |  14 +
 include/net/mana/hw_channel.h                 |  43 +-
 8 files changed, 604 insertions(+), 283 deletions(-)

diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 858bbc325eb29fbb677499e251941a5909ccf29d..60a9f15e5e8c1d0c807ded7177d8da909a0626da 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -100,7 +100,8 @@ static int mana_gd_destroy_pd(struct mana_ib_dev *mdev, u64 pd_handle)
 
 	req.pd_handle = pd_handle;
 
-	return mana_gd_send_request(mdev_to_gc(mdev), sizeof(req), &req, sizeof(resp), &resp);
+	return mana_gd_send_teardown_request(mdev_to_gc(mdev), sizeof(req),
+					     &req, sizeof(resp), &resp);
 }
 
 int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
diff --git a/drivers/infiniband/hw/mana/mr.c b/drivers/infiniband/hw/mana/mr.c
index 1233685b4b8906210a7648823265bccb6efaf578..9810aee3381e81fb63b96b73f8249d2cb629ad3b 100644
--- a/drivers/infiniband/hw/mana/mr.c
+++ b/drivers/infiniband/hw/mana/mr.c
@@ -94,7 +94,8 @@ static int mana_ib_gd_destroy_mr(struct mana_ib_dev *dev, u64 mr_handle)
 
 	req.mr_handle = mr_handle;
 
-	return mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
+	return mana_gd_send_teardown_request(gc, sizeof(req), &req,
+					     sizeof(resp), &resp);
 }
 
 struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *ibpd, u64 start, u64 length,
@@ -428,7 +429,8 @@ static int mana_ib_gd_destroy_dm(struct mana_ib_dev *mdev, struct mana_ib_dm *dm
 	mana_gd_init_req_hdr(&req.hdr, GDMA_DESTROY_DM, sizeof(req), sizeof(resp));
 	req.dm_handle = dm->dm_handle;
 
-	return mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
+	return mana_gd_send_teardown_request(gc, sizeof(req), &req,
+					     sizeof(resp), &resp);
 }
 
 int mana_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs)
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_cdx.c b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
index 2e0dcb902d7e263fad7341a1756441ec10d8339d..1f124cfbdefdcde94f9ea3d0e78eb1e9170d77c2 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_cdx.c
@@ -221,6 +221,8 @@ static int mana_cdx_gd_probe(struct cdx_device *cdx_dev)
 
 	mutex_init(&gc->eq_test_event_mutex);
 	mutex_init(&gc->gic_mutex);
+	spin_lock_init(&gc->hwc_lock);
+	init_waitqueue_head(&gc->hwc_drain_waitq);
 	dev_set_drvdata(&cdx_dev->dev, gc);
 	gc->bar0_pa = cdx_resource_start(cdx_dev, 0);
 	gc->bar0_size = cdx_resource_len(cdx_dev, 0);
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index 2d495db51d7463e260d32f9a52870df578ef0bee..0ada3861e259f1301bb6c243ca9c5e7d89abe25d 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -142,22 +142,21 @@ int mana_gd_init_registers(struct gdma_context *gc)
 		return mana_gd_init_vf_regs(gc);
 }
 
-/* Suppress logging when we set timeout to zero */
+/* Once admission is closed, follow-on request failures are expected. */
 bool mana_need_log(struct gdma_context *gc, int err)
 {
 	struct hw_channel_context *hwc;
+	unsigned long flags;
+	bool log;
 
-	if (err != -ETIMEDOUT)
-		return true;
-
-	if (!gc)
+	if (!gc || (err != -ETIMEDOUT && err != -ENODEV))
 		return true;
 
+	spin_lock_irqsave(&gc->hwc_lock, flags);
 	hwc = gc->hwc.driver_data;
-	if (hwc && hwc->hwc_timeout == 0)
-		return false;
-
-	return true;
+	log = hwc && READ_ONCE(hwc->state) == HWC_READY;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
+	return log;
 }
 
 int mana_gd_query_max_resources(struct gdma_context *gc)
@@ -310,7 +309,8 @@ int mana_gd_query_max_resources(struct gdma_context *gc)
 	return 0;
 }
 
-static int mana_gd_query_hwc_timeout(struct gdma_context *gc, u32 *timeout_val)
+static int mana_gd_query_hwc_timeout(struct gdma_context *gc, u32 timeout_ms,
+				     u32 *new_timeout_ms)
 {
 	struct gdma_query_hwc_timeout_resp resp = {};
 	struct gdma_query_hwc_timeout_req req = {};
@@ -318,12 +318,12 @@ static int mana_gd_query_hwc_timeout(struct gdma_context *gc, u32 *timeout_val)
 
 	mana_gd_init_req_hdr(&req.hdr, GDMA_QUERY_HWC_TIMEOUT,
 			     sizeof(req), sizeof(resp));
-	req.timeout_ms = *timeout_val;
+	req.timeout_ms = timeout_ms;
 	err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
 	if (err || resp.hdr.status)
 		return err ? err : -EPROTO;
 
-	*timeout_val = resp.timeout_ms;
+	*new_timeout_ms = resp.timeout_ms;
 
 	return 0;
 }
@@ -375,15 +375,47 @@ int mana_gd_detect_devices(struct gdma_context *gc)
 	return gc->mana.dev_id.type == 0 ? -ENODEV : 0;
 }
 
+static int mana_gd_send(struct gdma_context *gc, u32 req_len, const void *req,
+			u32 resp_len, void *resp, bool teardown)
+{
+	struct hw_channel_context *hwc;
+	unsigned long flags;
+	int err;
+
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	hwc = gc->hwc.driver_data;
+	if (!hwc) {
+		spin_unlock_irqrestore(&gc->hwc_lock, flags);
+		return -ENODEV;
+	}
+	hwc->active_senders++;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
+
+	err = mana_hwc_send_request(hwc, req_len, req, resp_len, resp,
+				    teardown);
+
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	if (--hwc->active_senders == 0)
+		wake_up(&gc->hwc_drain_waitq);
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
+
+	return err;
+}
+
 int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
 			 u32 resp_len, void *resp)
 {
-	struct hw_channel_context *hwc = gc->hwc.driver_data;
-
-	return mana_hwc_send_request(hwc, req_len, req, resp_len, resp);
+	return mana_gd_send(gc, req_len, req, resp_len, resp, false);
 }
 EXPORT_SYMBOL_NS(mana_gd_send_request, "NET_MANA");
 
+int mana_gd_send_teardown_request(struct gdma_context *gc, u32 req_len,
+				  const void *req, u32 resp_len, void *resp)
+{
+	return mana_gd_send(gc, req_len, req, resp_len, resp, true);
+}
+EXPORT_SYMBOL_NS(mana_gd_send_teardown_request, "NET_MANA");
+
 int mana_gd_alloc_memory(struct gdma_context *gc, unsigned int length,
 			 struct gdma_mem_info *gmi, bool allow_scatter)
 {
@@ -1011,7 +1043,9 @@ static void mana_gd_deregister_irq(struct gdma_queue *queue)
 	synchronize_rcu();
 }
 
-int mana_gd_test_eq(struct gdma_context *gc, struct gdma_queue *eq)
+static int mana_gd_test_eq_request(struct gdma_context *gc,
+				   struct hw_channel_context *hwc,
+				   struct gdma_queue *eq)
 {
 	struct gdma_generate_test_event_req req = {};
 	struct gdma_general_resp resp = {};
@@ -1029,9 +1063,14 @@ int mana_gd_test_eq(struct gdma_context *gc, struct gdma_queue *eq)
 	req.hdr.dev_id = eq->gdma_dev->dev_id;
 	req.queue_index = eq->id;
 
-	err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
+	if (hwc)
+		err = mana_hwc_send_request(hwc, sizeof(req), &req,
+					    sizeof(resp), &resp, false);
+	else
+		err = mana_gd_send_request(gc, sizeof(req), &req,
+					   sizeof(resp), &resp);
 	if (err) {
-		if (mana_need_log(gc, err))
+		if (hwc || mana_need_log(gc, err))
 			dev_err(dev, "test_eq failed: %d\n", err);
 		goto out;
 	}
@@ -1060,6 +1099,16 @@ out:
 	return err;
 }
 
+int mana_gd_test_eq(struct gdma_context *gc, struct gdma_queue *eq)
+{
+	return mana_gd_test_eq_request(gc, NULL, eq);
+}
+
+int mana_gd_test_hwc_eq(struct hw_channel_context *hwc, struct gdma_queue *eq)
+{
+	return mana_gd_test_eq_request(hwc->gdma_dev->gdma_context, hwc, eq);
+}
+
 static void mana_gd_destroy_eq(struct gdma_context *gc, bool flush_events,
 			       struct gdma_queue *queue)
 {
@@ -1295,6 +1344,7 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,
 	if (gmi->nr_pages == 0 && !MANA_PAGE_ALIGNED(gmi->virt_addr))
 		return -EINVAL;
 
+	/* The caller must keep the HWC alive throughout queue creation. */
 	hwc = gc->hwc.driver_data;
 	req_msg_size = struct_size(req, page_addr_list, num_page);
 	if (req_msg_size > hwc->max_req_msg_size)
@@ -1497,9 +1547,12 @@ int mana_gd_verify_vf_version(struct gdma_context *gc)
 	struct gdma_verify_ver_resp resp = {};
 	struct gdma_verify_ver_req req = {};
 	struct hw_channel_context *hwc;
+	u32 timeout_ms;
 	int err;
 
+	/* The setup caller must exclude concurrent HWC teardown. */
 	hwc = gc->hwc.driver_data;
+
 	mana_gd_init_req_hdr(&req.hdr, GDMA_VERIFY_VF_DRIVER_VERSION,
 			     sizeof(req), sizeof(resp));
 
@@ -1537,12 +1590,16 @@ int mana_gd_verify_vf_version(struct gdma_context *gc)
 			   &gc->pf_cap_flags1);
 
 	if (resp.pf_cap_flags1 & GDMA_DRV_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG) {
-		err = mana_gd_query_hwc_timeout(gc, &hwc->hwc_timeout);
+		err = mana_gd_query_hwc_timeout(gc,
+						mana_hwc_timeout_read(hwc),
+						&timeout_ms);
 		if (err) {
 			dev_err(gc->dev, "Failed to set the hwc timeout %d\n", err);
 			return err;
 		}
-		dev_dbg(gc->dev, "set the hwc timeout to %u\n", hwc->hwc_timeout);
+		mana_hwc_timeout_update(hwc, timeout_ms);
+		dev_dbg(gc->dev, "set the hwc timeout to %u\n",
+			mana_hwc_timeout_read(hwc));
 	}
 	return 0;
 }
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_pci.c b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
index cec2e548f36ea70bd821bc085f77ac94e78b4541..5220147f153a2cede28efc6407e6254765677541 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_pci.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_pci.c
@@ -14,7 +14,6 @@
 #include <linux/xarray.h>
 
 #include <net/mana/mana.h>
-#include <net/mana/hw_channel.h>
 
 struct mana_dev_recovery {
 	struct list_head list;
@@ -119,7 +118,6 @@ out:
 /* Return true if recovery needs to escalate to PCI re-enumeration. */
 static bool mana_serv_reset(struct pci_dev *pdev)
 {
-	struct hw_channel_context *hwc;
 	struct gdma_context *gc;
 	int ret;
 
@@ -128,14 +126,14 @@ static bool mana_serv_reset(struct pci_dev *pdev)
 		return false;
 
 	gc = pci_get_drvdata(pdev);
-	hwc = gc->hwc.driver_data;
-	if (!hwc) {
+	if (!gc->hwc.driver_data) {
 		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;
+	/* A service notification is not a DMA fence. Keep the normal HWC
+	 * response window for cleanup, including when all slots are in use.
+	 */
 
 	dev_info(&pdev->dev, "MANA reset cycle start\n");
 
@@ -616,6 +614,8 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	mutex_init(&gc->eq_test_event_mutex);
 	mutex_init(&gc->gic_mutex);
+	spin_lock_init(&gc->hwc_lock);
+	init_waitqueue_head(&gc->hwc_drain_waitq);
 	pci_set_drvdata(pdev, gc);
 	gc->bar0_pa = pci_resource_start(pdev, 0);
 	gc->bar0_size = pci_resource_len(pdev, 0);
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index a98e58b83f9c75bf8b40183c73a9286670d4aef4..cf1b9c75b10e2f2bc3f8da06f1adc2d7af3d2b97 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -6,61 +6,103 @@
 #include <net/mana/hw_channel.h>
 #include <linux/vmalloc.h>
 
-static int mana_hwc_get_msg_index(struct hw_channel_context *hwc, u16 *msg_id)
-{
-	struct gdma_resource *r = &hwc->inflight_msg_res;
-	struct hwc_caller_ctx *ctx;
-	unsigned long flags;
-	u32 index;
-
-	down(&hwc->sema);
-
-	spin_lock_irqsave(&r->lock, flags);
-
-	index = find_first_zero_bit(hwc->inflight_msg_res.map,
-				    hwc->inflight_msg_res.size);
-
-	ctx = &hwc->caller_ctx[index];
-	spin_lock(&ctx->lock);
-	reinit_completion(&ctx->comp_event);
-	ctx->output_buf = NULL;
-	ctx->output_buflen = 0;
-	ctx->error = -EINPROGRESS;
-	ctx->status_code = 0;
+/* Private send outcome; don't confuse a local errno with DMA retirement. */
+enum { HWC_DMA_DRAINED = 1 };
 
-	bitmap_set(hwc->inflight_msg_res.map, index, 1);
-
-	spin_unlock(&ctx->lock);
-	spin_unlock_irqrestore(&r->lock, flags);
-
-	*msg_id = index;
+u32 mana_hwc_timeout_read(const struct hw_channel_context *hwc)
+{
+	return READ_ONCE(hwc->hwc_timeout);
+}
 
-	return 0;
+/* Add a tick so starting near the next tick cannot shorten the PF window. */
+static unsigned long mana_hwc_window(u32 ms)
+{
+	return msecs_to_jiffies(ms) + 1;
 }
 
-static void mana_hwc_put_msg_index(struct hw_channel_context *hwc, u16 msg_id)
+static void mana_hwc_fail_pending(struct hw_channel_context *hwc, int result)
 {
 	struct gdma_resource *r = &hwc->inflight_msg_res;
-	unsigned long flags;
-
-	spin_lock_irqsave(&r->lock, flags);
-	bitmap_clear(hwc->inflight_msg_res.map, msg_id, 1);
-	spin_unlock_irqrestore(&r->lock, flags);
+	unsigned int i;
+
+	lockdep_assert_held(&r->lock);
+	for_each_set_bit(i, r->map, r->size) {
+		struct hwc_caller_ctx *ctx = &hwc->caller_ctx[i];
+
+		/* Retirement also invalidates a reply not yet consumed. An
+		 * ordinary stop has no such guarantee: keep a completed reply.
+		 */
+		if (!ctx->sender)
+			continue;
+		if (ctx->error != -EINPROGRESS && result != HWC_DMA_DRAINED)
+			continue;
+		ctx->error = result;
+		complete(&ctx->comp_event);
+	}
+}
 
-	up(&hwc->sema);
+/* Only unanswered posted requests have a running response timer. Sample it
+ * under the same lock that accepts a reply or hands it to the caller.
+ */
+static unsigned long mana_hwc_check_deadlines(struct hw_channel_context *hwc)
+{
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	unsigned long remaining = MAX_SCHEDULE_TIMEOUT;
+	unsigned long now = jiffies;
+	unsigned int i;
+
+	lockdep_assert_held(&r->lock);
+	if (hwc->state != HWC_READY)
+		return remaining;
+
+	for_each_set_bit(i, r->map, r->size) {
+		struct hwc_caller_ctx *ctx = &hwc->caller_ctx[i];
+
+		if (!ctx->pending)
+			continue;
+		if (time_after_eq(now, ctx->deadline)) {
+			/* At a posted command's normal response timeout, the
+			 * PF has drained old client DMA and interrupt writes.
+			 * Unanswered commands have no effect; a late CREATE
+			 * cannot grant access. A failed post or a reset
+			 * notification alone gives no such guarantee.
+			 */
+			WRITE_ONCE(hwc->state, HWC_TIMED_OUT);
+			mana_hwc_fail_pending(hwc, HWC_DMA_DRAINED);
+			wake_up_all(&hwc->admission_waitq);
+			dev_err(hwc->dev, "HWC request %u timed out\n", i);
+			break;
+		}
+		remaining = min(remaining, ctx->deadline - now);
+	}
+	return remaining;
 }
 
-static int mana_hwc_verify_resp_msg(const struct hwc_caller_ctx *caller_ctx,
-				    const struct gdma_resp_hdr *resp_msg,
-				    u32 resp_len)
+void mana_hwc_timeout_update(struct hw_channel_context *hwc, u32 timeout_ms)
 {
-	if (resp_len < sizeof(*resp_msg))
-		return -EPROTO;
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	unsigned long deadline;
+	unsigned int i;
 
-	if (resp_len > caller_ctx->output_buflen)
-		return -EPROTO;
+	/* Zero isn't a response window. Keep the last normal timeout and
+	 * never shorten the deadline of an already posted request.
+	 */
+	if (!timeout_ms)
+		return;
 
-	return 0;
+	guard(spinlock_irqsave)(&r->lock);
+	mana_hwc_check_deadlines(hwc);
+	WRITE_ONCE(hwc->hwc_timeout, timeout_ms);
+	if (hwc->state != HWC_READY)
+		return;
+
+	for_each_set_bit(i, r->map, r->size) {
+		struct hwc_caller_ctx *ctx = &hwc->caller_ctx[i];
+
+		deadline = ctx->posted_at + mana_hwc_window(timeout_ms);
+		if (ctx->pending && time_after(deadline, ctx->deadline))
+			ctx->deadline = deadline;
+	}
 }
 
 static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq,
@@ -86,44 +128,60 @@ static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq,
 	return err;
 }
 
+static int mana_hwc_refill(struct hw_channel_context *hwc,
+			   struct hwc_work_request *rx)
+{
+	int err;
+
+	lockdep_assert_held(&hwc->inflight_msg_res.lock);
+	err = mana_hwc_post_rx_wqe(hwc->rxq, rx);
+	rx->refill_needed = !!err;
+	return err;
+}
+
 static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
 				 struct hwc_work_request *rx_req, u16 msg_id)
 {
-	const struct gdma_resp_hdr *resp_msg = rx_req->buf_va;
+	struct gdma_resource *r = &hwc->inflight_msg_res;
 	struct hwc_caller_ctx *ctx;
-	int err;
 
-	if (!test_bit(msg_id, hwc->inflight_msg_res.map)) {
-		dev_err(hwc->dev, "hwc_rx: invalid msg_id = %u\n", msg_id);
-		mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
-		return;
+	spin_lock(&r->lock);
+	mana_hwc_check_deadlines(hwc);
+	if (msg_id >= r->size || !test_bit(msg_id, r->map)) {
+		dev_err_ratelimited(hwc->dev, "Unexpected HWC response ID %u\n",
+				    msg_id);
+		goto repost;
 	}
 
-	ctx = hwc->caller_ctx + msg_id;
-
-	spin_lock(&ctx->lock);
-	if (!ctx->output_buf) {
-		spin_unlock(&ctx->lock);
-		mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
-		return;
-	}
+	ctx = &hwc->caller_ctx[msg_id];
+	if (!ctx->pending)
+		goto repost;
 
-	err = mana_hwc_verify_resp_msg(ctx, resp_msg, resp_len);
-	if (!err) {
-		ctx->status_code = resp_msg->status;
-		memcpy(ctx->output_buf, resp_msg, resp_len);
+	ctx->pending = false;
+	if (!ctx->sender) {
+		__clear_bit(msg_id, r->map);
+		goto repost;
 	}
+	if (ctx->error != -EINPROGRESS)
+		goto repost;
 
-	ctx->output_buf = NULL;
-	ctx->error = err;
-
-	/* Must post rx wqe before complete(), otherwise the next rx may
-	 * hit no_wqe error.
+	/* Hold one RQ buffer with this occupied slot. The sender replenishes
+	 * the RQ before releasing the slot for another SQ submission.
 	 */
-	mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
-
+	ctx->reply = rx_req;
+	ctx->reply_len = resp_len;
+	ctx->error = 0;
 	complete(&ctx->comp_event);
-	spin_unlock(&ctx->lock);
+	goto out;
+
+repost:
+	if (hwc->state == HWC_READY)
+		mana_hwc_refill(hwc, rx_req);
+	else
+		rx_req->refill_needed = true;
+out:
+	spin_unlock(&r->lock);
+	wake_up_all(&hwc->admission_waitq);
 }
 
 static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
@@ -227,7 +285,7 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 
 		switch (type) {
 		case HWC_DATA_CFG_HWC_TIMEOUT:
-			hwc->hwc_timeout = val;
+			mana_hwc_timeout_update(hwc, val);
 			break;
 
 		case HWC_DATA_HW_LINK_CONNECT:
@@ -314,17 +372,7 @@ static void mana_hwc_rx_event_handler(void *ctx, u32 gdma_rxq_id,
 	 * modify it between reads.
 	 */
 	msg_id = READ_ONCE(resp->response.hwc_msg_id);
-	if (msg_id >= hwc->num_inflight_msg) {
-		dev_err(hwc->dev, "HWC RX: wrong msg_id=%u\n", msg_id);
-		return;
-	}
-
 	mana_hwc_handle_resp(hwc, rx_oob->tx_oob_data_size, rx_req, msg_id);
-
-	/* Can no longer use 'resp', because the buffer is posted to the HW
-	 * in mana_hwc_handle_resp() above.
-	 */
-	resp = NULL;
 }
 
 static void mana_hwc_tx_event_handler(void *ctx, u32 gdma_txq_id,
@@ -647,10 +695,10 @@ out:
 	return err;
 }
 
-static int mana_hwc_post_tx_wqe(const struct hwc_wq *hwc_txq,
-				struct hwc_work_request *req,
-				u32 dest_virt_rq_id, u32 dest_virt_rcq_id,
-				bool dest_pf)
+static int mana_hwc_stage_tx_wqe(const struct hwc_wq *hwc_txq,
+				 struct hwc_work_request *req,
+				 u32 dest_virt_rq_id, u32 dest_virt_rcq_id,
+				 bool dest_pf)
 {
 	struct device *dev = hwc_txq->hwc->dev;
 	struct hwc_tx_oob *tx_oob;
@@ -686,7 +734,7 @@ static int mana_hwc_post_tx_wqe(const struct hwc_wq *hwc_txq,
 	req->wqe_req.inline_oob_data = tx_oob;
 	req->wqe_req.client_data_unit = 0;
 
-	err = mana_gd_post_and_ring(hwc_txq->gdma_wq, &req->wqe_req, NULL);
+	err = mana_gd_post_work_request(hwc_txq->gdma_wq, &req->wqe_req, NULL);
 	if (err)
 		dev_err(dev, "Failed to post WQE on HWC SQ: %d\n", err);
 	return err;
@@ -697,51 +745,52 @@ static int mana_hwc_init_inflight_msg(struct hw_channel_context *hwc,
 {
 	int err;
 
-	sema_init(&hwc->sema, num_msg);
-
 	err = mana_gd_alloc_res_map(num_msg, &hwc->inflight_msg_res);
 	if (err)
 		dev_err(hwc->dev, "Failed to init inflight_msg_res: %d\n", err);
 	return err;
 }
 
-static int mana_hwc_test_channel(struct hw_channel_context *hwc, u16 q_depth,
-				 u32 max_req_msg_size, u32 max_resp_msg_size)
+static int mana_hwc_test_channel(struct hw_channel_context *hwc)
 {
-	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 	struct hwc_wq *hwc_rxq = hwc->rxq;
 	struct hwc_work_request *req;
 	struct hwc_caller_ctx *ctx;
+	unsigned long flags;
 	int err;
 	int i;
 
 	/* Post all WQEs on the RQ */
-	for (i = 0; i < q_depth; i++) {
+	for (i = 0; i < hwc->num_inflight_msg; i++) {
 		req = &hwc_rxq->msg_buf->reqs[i];
 		err = mana_hwc_post_rx_wqe(hwc_rxq, req);
 		if (err)
 			return err;
 	}
 
-	ctx = kzalloc_objs(*ctx, q_depth);
+	ctx = kzalloc_objs(*ctx, hwc->num_inflight_msg);
 	if (!ctx)
 		return -ENOMEM;
 
-	for (i = 0; i < q_depth; ++i) {
+	for (i = 0; i < hwc->num_inflight_msg; ++i)
 		init_completion(&ctx[i].comp_event);
-		spin_lock_init(&ctx[i].lock);
-	}
 
 	hwc->caller_ctx = ctx;
 
-	return mana_gd_test_eq(gc, hwc->cq->gdma_eq);
+	/* Setup owns hwc directly; runtime publication follows this test. */
+	spin_lock_irqsave(&hwc->inflight_msg_res.lock, flags);
+	WRITE_ONCE(hwc->state, HWC_READY);
+	spin_unlock_irqrestore(&hwc->inflight_msg_res.lock, flags);
+
+	return mana_gd_test_hwc_eq(hwc, hwc->cq->gdma_eq);
 }
 
-static int mana_hwc_establish_channel(struct gdma_context *gc, u16 *q_depth,
+static int mana_hwc_establish_channel(struct hw_channel_context *hwc,
+				      u16 *q_depth,
 				      u32 *max_req_msg_size,
 				      u32 *max_resp_msg_size)
 {
-	struct hw_channel_context *hwc = gc->hwc.driver_data;
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 	struct gdma_queue *rq = hwc->rxq->gdma_wq;
 	struct gdma_queue *sq = hwc->txq->gdma_wq;
 	struct gdma_queue *eq = hwc->cq->gdma_eq;
@@ -874,68 +923,78 @@ static void mana_hwc_clear_cq_table(struct gdma_context *gc)
 	vfree(cq_table);
 }
 
-int mana_hwc_create_channel(struct gdma_context *gc)
+static int mana_hwc_publish_channel(struct hw_channel_context *hwc)
+{
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
+	unsigned long flags;
+	int err = 0;
+
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	if (WARN_ON_ONCE(gc->hwc.driver_data))
+		err = -EBUSY;
+	else
+		gc->hwc.driver_data = hwc;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
+
+	return err;
+}
+
+static struct hw_channel_context *
+mana_hwc_unpublish_channel(struct gdma_context *gc)
 {
-	u32 max_req_msg_size, max_resp_msg_size;
-	struct gdma_dev *gd = &gc->hwc;
 	struct hw_channel_context *hwc;
-	u16 q_depth_max;
-	int err;
+	unsigned long flags;
 
-	/* Retry a retained context before assigning queues to the PF again. */
-	if (gd->driver_data) {
-		mana_hwc_destroy_channel(gc);
-		if (gd->driver_data)
-			return -ETIMEDOUT;
-	}
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	hwc = gc->hwc.driver_data;
+	gc->hwc.driver_data = NULL;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
 
-	hwc = kzalloc_obj(*hwc);
-	if (!hwc)
-		return -ENOMEM;
+	return hwc;
+}
 
-	gd->gdma_context = gc;
-	gd->driver_data = hwc;
-	hwc->gdma_dev = gd;
-	hwc->dev = gc->dev;
-	hwc->hwc_timeout = HW_CHANNEL_WAIT_RESOURCE_TIMEOUT_MS;
+static void mana_hwc_retain_channel(struct hw_channel_context *hwc)
+{
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
+	unsigned long flags;
 
-	/* HWC's instance number is always 0. */
-	gd->dev_id.as_uint32 = 0;
-	gd->dev_id.type = GDMA_DEVICE_HWC;
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	if (WARN_ON_ONCE(gc->hwc.driver_data))
+		dev_err(hwc->dev, "HWC retention slot is already occupied\n");
+	else
+		gc->hwc.driver_data = hwc;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
+}
 
-	gd->pdid = INVALID_PDID;
-	gd->doorbell = INVALID_DOORBELL;
+static bool mana_hwc_senders_drained(struct gdma_context *gc,
+				     struct hw_channel_context *hwc)
+{
+	unsigned long flags;
+	bool drained;
 
-	/* mana_hwc_init_queues() only creates the required data structures,
-	 * and doesn't touch the HWC device.
-	 */
-	err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
-				   HW_CHANNEL_MAX_REQUEST_SIZE,
-				   HW_CHANNEL_MAX_RESPONSE_SIZE);
-	if (err) {
-		dev_err(hwc->dev, "Failed to initialize HWC: %d\n", err);
-		goto out;
-	}
+	spin_lock_irqsave(&gc->hwc_lock, flags);
+	drained = hwc->active_senders == 0;
+	spin_unlock_irqrestore(&gc->hwc_lock, flags);
 
-	err = mana_hwc_establish_channel(gc, &q_depth_max, &max_req_msg_size,
-					 &max_resp_msg_size);
-	if (err) {
-		dev_err(hwc->dev, "Failed to establish HWC: %d\n", err);
-		goto out;
-	}
+	return drained;
+}
 
-	err = mana_hwc_test_channel(gc->hwc.driver_data,
-				    HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
-				    max_req_msg_size, max_resp_msg_size);
-	if (err) {
-		dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
-		goto out;
+static void mana_hwc_stop_channel(struct hw_channel_context *hwc)
+{
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	unsigned long flags;
+
+	if (hwc->num_inflight_msg) {
+		spin_lock_irqsave(&r->lock, flags);
+		mana_hwc_check_deadlines(hwc);
+		WRITE_ONCE(hwc->state, HWC_STOPPED);
+		mana_hwc_fail_pending(hwc, -ENODEV);
+		spin_unlock_irqrestore(&r->lock, flags);
+		wake_up_all(&hwc->admission_waitq);
 	}
 
-	return 0;
-out:
-	mana_hwc_destroy_channel(gc);
-	return err;
+	wait_event(gc->hwc_drain_waitq, mana_hwc_senders_drained(gc, hwc));
 }
 
 static void mana_hwc_fence_channel(struct gdma_context *gc,
@@ -951,13 +1010,12 @@ static void mana_hwc_fence_channel(struct gdma_context *gc,
 		mana_hwc_unpublish_cq(gc, hwc->cq->gdma_cq);
 }
 
-void mana_hwc_destroy_channel(struct gdma_context *gc)
+static bool mana_hwc_release_channel(struct hw_channel_context *hwc)
 {
-	struct hw_channel_context *hwc = gc->hwc.driver_data;
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 	int err;
 
-	if (!hwc)
-		return;
+	mana_hwc_stop_channel(hwc);
 
 	/* An unacknowledged destroy leaves the PF's mappings live.  Fence
 	 * software dispatch, but retain every PF-visible allocation.
@@ -969,7 +1027,8 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
 			"HWC teardown failed: %d, retaining PF-visible resources\n",
 			err);
 		mana_hwc_fence_channel(gc, hwc);
-		return;
+		mana_hwc_retain_channel(hwc);
+		return false;
 	}
 
 	mana_hwc_clear_cq_table(gc);
@@ -994,11 +1053,10 @@ void mana_hwc_destroy_channel(struct gdma_context *gc)
 	hwc->gdma_dev->doorbell = INVALID_DOORBELL;
 	hwc->gdma_dev->pdid = INVALID_PDID;
 
-	hwc->hwc_timeout = 0;
-
 	kfree(hwc);
-	gc->hwc.driver_data = NULL;
 	gc->hwc.gdma_context = NULL;
+
+	return true;
 }
 
 static void mana_hwc_free_retained_wq(struct hwc_wq *wq)
@@ -1016,12 +1074,12 @@ static void mana_hwc_free_retained_wq(struct hwc_wq *wq)
  */
 void mana_hwc_free_retained_channel(struct gdma_context *gc)
 {
-	struct hw_channel_context *hwc = gc->hwc.driver_data;
+	struct hw_channel_context *hwc = mana_hwc_unpublish_channel(gc);
 
 	if (!hwc)
 		return;
 
-	gc->hwc.driver_data = NULL;
+	mana_hwc_stop_channel(hwc);
 	mana_hwc_clear_cq_table(gc);
 
 	if (hwc->cq) {
@@ -1039,11 +1097,96 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)
 	gc->hwc.gdma_context = NULL;
 }
 
-static int mana_hwc_response_status(struct hw_channel_context *hwc,
-				    u32 command, int error, u32 status)
+static int mana_hwc_create_bootstrap_channel(struct hw_channel_context *hwc)
+{
+	u32 max_req_msg_size, max_resp_msg_size;
+	u16 q_depth_max;
+	int err;
+
+	err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
+				   HW_CHANNEL_MAX_REQUEST_SIZE,
+				   HW_CHANNEL_MAX_RESPONSE_SIZE);
+	if (err) {
+		dev_err(hwc->dev, "Failed to initialize HWC: %d\n", err);
+		return err;
+	}
+
+	err = mana_hwc_establish_channel(hwc, &q_depth_max, &max_req_msg_size,
+					 &max_resp_msg_size);
+	if (err) {
+		dev_err(hwc->dev, "Failed to establish HWC: %d\n", err);
+		return err;
+	}
+
+	err = mana_hwc_test_channel(hwc);
+	if (err)
+		dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
+
+	return err;
+}
+
+int mana_hwc_create_channel(struct gdma_context *gc)
+{
+	struct gdma_dev *gd = &gc->hwc;
+	struct hw_channel_context *hwc;
+	int err;
+
+	/* Retry a retained context before assigning queues to the PF again. */
+	if (gd->driver_data) {
+		mana_hwc_destroy_channel(gc);
+		if (gd->driver_data)
+			return -ETIMEDOUT;
+	}
+
+	hwc = kzalloc_obj(*hwc);
+	if (!hwc)
+		return -ENOMEM;
+
+	gd->gdma_context = gc;
+	hwc->gdma_dev = gd;
+	hwc->dev = gc->dev;
+	WRITE_ONCE(hwc->hwc_timeout, HW_CHANNEL_WAIT_RESOURCE_TIMEOUT_MS);
+	init_waitqueue_head(&hwc->admission_waitq);
+	INIT_LIST_HEAD(&hwc->submissions);
+
+	/* HWC's instance number is always 0. */
+	gd->dev_id.as_uint32 = 0;
+	gd->dev_id.type = GDMA_DEVICE_HWC;
+
+	gd->pdid = INVALID_PDID;
+	gd->doorbell = INVALID_DOORBELL;
+
+	err = mana_hwc_create_bootstrap_channel(hwc);
+	if (err) {
+		mana_hwc_release_channel(hwc);
+		return err;
+	}
+
+	err = mana_hwc_publish_channel(hwc);
+	if (err) {
+		mana_hwc_release_channel(hwc);
+		return err;
+	}
+
+	return 0;
+}
+
+void mana_hwc_destroy_channel(struct gdma_context *gc)
 {
-	if (error)
-		return error;
+	struct hw_channel_context *hwc;
+
+	hwc = mana_hwc_unpublish_channel(gc);
+	if (!hwc)
+		return;
+
+	mana_hwc_release_channel(hwc);
+}
+
+static int mana_hwc_response_result(struct hw_channel_context *hwc,
+				    u32 command, int err, u32 status)
+{
+	if (err)
+		return err;
 
 	if (!status || status == GDMA_STATUS_MORE_ENTRIES)
 		return 0;
@@ -1058,108 +1201,183 @@ static int mana_hwc_response_status(struct hw_channel_context *hwc,
 	return -EPROTO;
 }
 
-static void mana_hwc_finish_request(struct hw_channel_context *hwc,
-				    struct hwc_caller_ctx *ctx, u16 msg_id)
+/* Owned by the sender until its entry is removed under the map lock. */
+struct hwc_submission {
+	struct list_head entry;
+	const struct gdma_req_hdr *req;
+	u32 len;
+	unsigned int id;
+	int err;
+};
+
+static int mana_hwc_stage(struct hw_channel_context *hwc,
+			  struct hwc_submission *sub, unsigned int id)
 {
-	unsigned long flags;
+	struct hwc_work_request *tx = &hwc->txq->msg_buf->reqs[id];
+	struct gdma_req_hdr *hdr;
 
-	spin_lock_irqsave(&ctx->lock, flags);
-	ctx->output_buf = NULL;
-	spin_unlock_irqrestore(&ctx->lock, flags);
+	if (sub->len > tx->buf_len)
+		return -EMSGSIZE;
 
-	mana_hwc_put_msg_index(hwc, msg_id);
+	hdr = memcpy(tx->buf_va, sub->req, sub->len);
+	hdr->req.hwc_msg_id = id;
+	tx->msg_size = sub->len;
+	return mana_hwc_stage_tx_wqe(hwc->txq, tx, hwc->dest_vrq_id,
+				     hwc->dest_vrcq_id, false);
 }
 
-int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
-			  const void *req, u32 resp_len, void *resp)
+static void mana_hwc_post_batch(struct hw_channel_context *hwc)
 {
-	struct hwc_work_request *tx_wr;
-	struct hwc_wq *txq = hwc->txq;
-	struct gdma_req_hdr *req_msg;
-	struct hwc_caller_ctx *ctx;
-	unsigned long flags;
-	u32 dest_vrcq;
-	u32 dest_vrq;
-	u32 command;
-	u32 status;
-	u16 msg_id;
-	int err;
-
-	err = mana_hwc_get_msg_index(hwc, &msg_id);
-	if (err)
-		return err;
-
-	tx_wr = &txq->msg_buf->reqs[msg_id];
-	ctx = hwc->caller_ctx + msg_id;
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	unsigned int avail = r->size, count = 0, i;
+	unsigned long posted_at, deadline;
+	struct hwc_submission *sub;
+	int rx_err = 0;
+
+	lockdep_assert_held(&r->lock);
+	/* All replies from the previous batch have been taken. Retry any RQ
+	 * refill that failed before allowing another command to use it.
+	 */
+	for (i = 0; i < r->size; i++) {
+		struct hwc_work_request *rx = &hwc->rxq->msg_buf->reqs[i];
+		int err;
+
+		if (!rx->refill_needed)
+			continue;
+		err = mana_hwc_refill(hwc, rx);
+		if (err) {
+			avail--;
+			rx_err = err;
+		}
+	}
 
-	if (req_len > tx_wr->buf_len) {
-		dev_err(hwc->dev, "HWC: req msg size: %d > %d\n", req_len,
-			tx_wr->buf_len);
-		mana_hwc_finish_request(hwc, ctx, msg_id);
-		return -EINVAL;
+	for (i = 0; i < r->size && !list_empty(&hwc->submissions); i++) {
+		sub = list_first_entry(&hwc->submissions, struct hwc_submission,
+				       entry);
+		sub->err = avail ? mana_hwc_stage(hwc, sub, count) : rx_err;
+		if (!sub->err)
+			sub->id = count++;
+		list_del_init(&sub->entry);
+		if (count && count == avail)
+			break;
+	}
+	if (count) {
+		/* One tail write publishes the whole batch. No other SQ tail
+		 * can be written until this batch's slots are all released.
+		 */
+		mana_gd_wq_ring_doorbell(hwc->gdma_dev->gdma_context,
+					 hwc->txq->gdma_wq);
+		posted_at = jiffies;
+		deadline = posted_at + mana_hwc_window(hwc->hwc_timeout);
+		for (i = 0; i < count; i++) {
+			struct hwc_caller_ctx *ctx = &hwc->caller_ctx[i];
+
+			ctx->posted_at = posted_at;
+			ctx->deadline = deadline;
+			reinit_completion(&ctx->comp_event);
+			ctx->error = -EINPROGRESS;
+			ctx->sender = true;
+			ctx->pending = true;
+			__set_bit(i, r->map);
+		}
 	}
+	wake_up_all(&hwc->admission_waitq);
+}
 
-	spin_lock_irqsave(&ctx->lock, flags);
-	ctx->output_buf = resp;
-	ctx->output_buflen = resp_len;
-	spin_unlock_irqrestore(&ctx->lock, flags);
+/* Return zero on transfer, otherwise wait for an owner or a posted deadline. */
+static long mana_hwc_admit(struct hw_channel_context *hwc,
+			   struct hwc_submission *sub)
+{
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	unsigned long remaining;
 
-	req_msg = (struct gdma_req_hdr *)tx_wr->buf_va;
-	if (req)
-		memcpy(req_msg, req, req_len);
+	guard(spinlock_irqsave)(&r->lock);
+	if (!list_empty(&sub->entry) && hwc->state == HWC_READY &&
+	    bitmap_empty(r->map, r->size))
+		mana_hwc_post_batch(hwc);
+	if (list_empty(&sub->entry))
+		return 0;
 
-	req_msg->req.hwc_msg_id = msg_id;
+	remaining = mana_hwc_check_deadlines(hwc);
+	if (hwc->state == HWC_READY)
+		return remaining;
 
-	tx_wr->msg_size = req_len;
-	command = req_msg->req.msg_type;
+	sub->err = hwc->state == HWC_TIMED_OUT ? HWC_DMA_DRAINED : -ENODEV;
+	list_del_init(&sub->entry);
+	return 0;
+}
 
-	/* The hardware reports the HWC destination queues through
-	 * HWC_INIT_DATA_DEST_RQ_ID and HWC_INIT_DATA_DEST_CQ_ID, and
-	 * always supplies values that are valid for this function, so no
-	 * PF-specific handling is needed here.
-	 */
-	dest_vrq = hwc->dest_vrq_id;
-	dest_vrcq = hwc->dest_vrcq_id;
+static int mana_hwc_wait_for_response(struct hw_channel_context *hwc,
+				      unsigned int id, u32 command,
+				      u32 resp_len, struct gdma_resp_hdr *resp)
+{
+	struct gdma_resource *r = &hwc->inflight_msg_res;
+	struct hwc_caller_ctx *ctx = &hwc->caller_ctx[id];
+	unsigned long flags, remaining;
+	u32 status = 0;
+	int err;
 
-	err = mana_hwc_post_tx_wqe(txq, tx_wr, dest_vrq, dest_vrcq, false);
-	if (err) {
-		dev_err(hwc->dev, "HWC: Failed to post send WQE: %d\n", err);
-		mana_hwc_finish_request(hwc, ctx, msg_id);
-		return err;
+	spin_lock_irqsave(&r->lock, flags);
+	for (;;) {
+		remaining = mana_hwc_check_deadlines(hwc);
+		if (ctx->error != -EINPROGRESS)
+			break;
+		spin_unlock_irqrestore(&r->lock, flags);
+		wait_for_completion_timeout(&ctx->comp_event, remaining);
+		spin_lock_irqsave(&r->lock, flags);
 	}
-
-	if (!wait_for_completion_timeout(&ctx->comp_event,
-					 msecs_to_jiffies(hwc->hwc_timeout))) {
-		spin_lock_irqsave(&ctx->lock, flags);
-		ctx->output_buf = NULL;
-		err = ctx->error;
-		status = ctx->status_code;
-		spin_unlock_irqrestore(&ctx->lock, flags);
-
-		if (err != -EINPROGRESS) {
-			mana_hwc_finish_request(hwc, ctx, msg_id);
-			return mana_hwc_response_status(hwc, command, err,
-							status);
+	err = ctx->error;
+	if (!err) {
+		if (ctx->reply_len < sizeof(*resp) ||
+		    ctx->reply_len > resp_len ||
+		    ctx->reply_len > ctx->reply->buf_len) {
+			err = -EPROTO;
+		} else {
+			memcpy(resp, ctx->reply->buf_va, ctx->reply_len);
+			status = resp->status;
 		}
+	}
+	if (ctx->reply && hwc->state == HWC_READY)
+		mana_hwc_refill(hwc, ctx->reply);
+	ctx->reply = NULL;
+	ctx->sender = false;
+	if (!ctx->pending)
+		__clear_bit(id, r->map);
+	spin_unlock_irqrestore(&r->lock, flags);
+	wake_up_all(&hwc->admission_waitq);
+	return mana_hwc_response_result(hwc, command, err, status);
+}
 
-		if (hwc->hwc_timeout != 0)
-			dev_err(hwc->dev, "Command 0x%x timed out: %u ms\n",
-				command, hwc->hwc_timeout);
+int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
+			  const void *req, u32 resp_len, void *resp,
+			  bool teardown)
+{
+	const struct gdma_req_hdr *hdr = req;
+	struct hwc_submission sub = { .req = req, .len = req_len };
+	DEFINE_WAIT(wait);
+	long remaining;
+	int err;
 
-		/* Reduce further waiting if HWC no response */
-		if (hwc->hwc_timeout > 1)
-			hwc->hwc_timeout = 1;
+	if (!hdr || req_len < sizeof(*hdr) || !resp)
+		return -EINVAL;
 
-		mana_hwc_finish_request(hwc, ctx, msg_id);
-		return -ETIMEDOUT;
+	scoped_guard(spinlock_irqsave, &hwc->inflight_msg_res.lock)
+		list_add_tail(&sub.entry, &hwc->submissions);
+	for (;;) {
+		prepare_to_wait(&hwc->admission_waitq, &wait,
+				TASK_UNINTERRUPTIBLE);
+		remaining = mana_hwc_admit(hwc, &sub);
+		if (!remaining)
+			break;
+		schedule_timeout(remaining);
 	}
-
-	spin_lock_irqsave(&ctx->lock, flags);
-	ctx->output_buf = NULL;
-	err = ctx->error;
-	status = ctx->status_code;
-	spin_unlock_irqrestore(&ctx->lock, flags);
-
-	mana_hwc_finish_request(hwc, ctx, msg_id);
-	return mana_hwc_response_status(hwc, command, err, status);
+	finish_wait(&hwc->admission_waitq, &wait);
+	err = sub.err;
+	if (!err)
+		err = mana_hwc_wait_for_response(hwc, sub.id, hdr->req.msg_type,
+						 resp_len, resp);
+
+	if (err == HWC_DMA_DRAINED)
+		return teardown ? 0 : -ETIMEDOUT;
+	return err;
 }
diff --git a/include/net/mana/gdma.h b/include/net/mana/gdma.h
index 2da086a3b8f721d51827553d78261240c8d69a6f..7c07b286bd948894dcb95138700842dffcb23129 100644
--- a/include/net/mana/gdma.h
+++ b/include/net/mana/gdma.h
@@ -548,6 +548,12 @@ struct gdma_context {
 	/* Hardware communication channel (HWC) */
 	struct gdma_dev		hwc;
 
+	/* Sender drain; the final wakeup runs under hwc_lock. */
+	wait_queue_head_t	hwc_drain_waitq;
+
+	/* Protects HWC publication and active sender references. */
+	spinlock_t		hwc_lock;
+
 	/* Azure network adapter */
 	struct gdma_dev		mana;
 
@@ -1197,6 +1203,14 @@ void mana_gd_free_memory(struct gdma_mem_info *gmi);
 int mana_gd_send_request(struct gdma_context *gc, u32 req_len, const void *req,
 			 u32 resp_len, void *resp);
 
+/* For software teardown of an object whose lifetime excludes HWC replacement.
+ * A posted response timeout retires that generation. Return zero for local
+ * cleanup in that case, without filling resp or implying a PF response.
+ * Callers needing response fields must use mana_gd_send_request().
+ */
+int mana_gd_send_teardown_request(struct gdma_context *gc, u32 req_len,
+				  const void *req, u32 resp_len, void *resp);
+
 int mana_gd_destroy_dma_region(struct gdma_context *gc, u64 dma_region_handle);
 void mana_register_debugfs(void);
 void mana_unregister_debugfs(void);
diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h
index bcaf276976a81dca825ee08804a3b2fa5ee24a9a..c154264f0f7c30efb989243ce2d9282aefbc61a8 100644
--- a/include/net/mana/hw_channel.h
+++ b/include/net/mana/hw_channel.h
@@ -114,6 +114,7 @@ struct hwc_work_request {
 	void *buf_sge_addr;
 	u32 buf_len;
 	u32 msg_size;
+	bool refill_needed;
 
 	struct gdma_wqe_request wqe_req;
 	struct hwc_tx_oob tx_oob;
@@ -168,13 +169,24 @@ struct hwc_wq {
 
 struct hwc_caller_ctx {
 	struct completion comp_event;
-	/* Protects initialization, output storage and response state. */
-	spinlock_t lock;
-	void *output_buf;
-	u32 output_buflen;
+	/* Completed RQ buffer, not yet consumed by the sender. */
+	struct hwc_work_request *reply;
+	u32 reply_len;
+	int error;
 
-	int error; /* Linux error code */
-	u32 status_code;
+	/* The ID and TX buffer belong to the sender until it has taken its
+	 * result, and to the device until the corresponding response arrives.
+	 */
+	bool sender;
+	bool pending;
+	unsigned long posted_at;
+	unsigned long deadline;
+};
+
+enum hwc_channel_state {
+	HWC_STOPPED,
+	HWC_READY,
+	HWC_TIMED_OUT,
 };
 
 struct hw_channel_context {
@@ -197,8 +209,13 @@ struct hw_channel_context {
 	struct hwc_wq *txq;
 	struct hwc_cq *cq;
 
-	struct semaphore sema;
+	wait_queue_head_t admission_waitq;
+	struct list_head submissions;
+	/* The map lock serializes slot ownership, SQ publication, response
+	 * delivery, timeout changes and the transition to a faulted channel.
+	 */
 	struct gdma_resource inflight_msg_res;
+	enum hwc_channel_state state;
 
 	u32 dest_vrq_id;
 	u32 dest_vrcq_id;
@@ -209,6 +226,10 @@ struct hw_channel_context {
 	 * until it acknowledges DESTROY_HWC.
 	 */
 	bool setup_active;
+
+	/* mana_gd_send_request() callers, including waiters; under hwc_lock. */
+	unsigned int active_senders;
+
 	struct hwc_caller_ctx *caller_ctx;
 };
 
@@ -217,6 +238,12 @@ void mana_hwc_destroy_channel(struct gdma_context *gc);
 void mana_hwc_free_retained_channel(struct gdma_context *gc);
 
 int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
-			  const void *req, u32 resp_len, void *resp);
+			  const void *req, u32 resp_len, void *resp,
+			  bool teardown);
+int mana_gd_test_hwc_eq(struct hw_channel_context *hwc,
+			struct gdma_queue *eq);
+
+u32 mana_hwc_timeout_read(const struct hw_channel_context *hwc);
+void mana_hwc_timeout_update(struct hw_channel_context *hwc, u32 timeout_ms);
 
 #endif /* _HW_CHANNEL_H */

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
                   ` (3 preceding siblings ...)
  2026-11-24 15:40 ` [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests Wei Hu
@ 2026-11-24 15:40 ` Wei Hu
  2026-11-24 15:44 ` [PATCH net-next v12 0/5] net: mana: concurrent HWC requests netdev-bot+sinfo
  5 siblings, 0 replies; 7+ messages in thread
From: Wei Hu @ 2026-11-24 15:40 UTC (permalink / raw)
  To: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen
  Cc: netdev, linux-rdma, linux-hyperv, linux-kernel, gargaditya,
	kees+treewide, kees, mawasthi, weh, edumazet, shacharr

From: Long Li <longli@microsoft.com>
Date: Mon, 24 Aug 2026 20:04:01 +0000

The bootstrap channel handles one request at a time. Rebuild it at the
depth reported by the PF if all four descriptor rings still fit in
4 KiB and the message sizes match the bootstrap allocations. Otherwise
keep the bootstrap queues and enforce the reported transmit and receive
limits.

Test the new channel before publishing it. If the test fails, restore
and test a depth-one channel without changing the firmware timeout. Do
not reuse the queues if the PF did not acknowledge teardown.

Signed-off-by: Long Li <longli@microsoft.com>
Signed-off-by: Wei Hu <weh@microsoft.com>
---
 drivers/infiniband/hw/mana/main.c             |  12 +-
 .../net/ethernet/microsoft/mana/gdma_main.c   |   2 +-
 .../net/ethernet/microsoft/mana/hw_channel.c  | 286 +++++++++++++++---
 include/net/mana/hw_channel.h                 |  16 +-
 4 files changed, 260 insertions(+), 56 deletions(-)

diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 60a9f15e5e8c1d0c807ded7177d8da909a0626da..baf894342c156d1e4e71ec0476c829ee90957c82 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -415,28 +415,31 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem
 	unsigned int create_req_msg_size;
 	struct hw_channel_context *hwc;
 	struct ib_block_iter biter;
-	size_t max_pgs_add_cmd = 0;
+	size_t max_pgs_add_cmd;
 	size_t max_pgs_create_cmd;
 	struct gdma_context *gc;
 	size_t num_pages_total;
 	unsigned int tail = 0;
+	u32 req_limit;
 	u64 *page_addr_list;
 	void *request_buf;
 	int err = 0;
 
 	gc = mdev_to_gc(dev);
 	hwc = gc->hwc.driver_data;
+	req_limit = mana_hwc_get_max_req_size(hwc);
 
 	num_pages_total = ib_umem_num_dma_blocks(umem, page_sz);
 
 	max_pgs_create_cmd =
-		(hwc->max_req_msg_size - sizeof(*create_req)) / sizeof(u64);
+		(req_limit - sizeof(*create_req)) / sizeof(u64);
+	max_pgs_add_cmd = (req_limit - sizeof(*add_req)) / sizeof(u64);
 	num_pages_to_handle =
 		min_t(size_t, num_pages_total, max_pgs_create_cmd);
 	create_req_msg_size =
 		struct_size(create_req, page_addr_list, num_pages_to_handle);
 
-	request_buf = kzalloc(hwc->max_req_msg_size, GFP_KERNEL);
+	request_buf = kzalloc(req_limit, GFP_KERNEL);
 	if (!request_buf)
 		return -ENOMEM;
 
@@ -479,9 +482,6 @@ static int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem
 			if (err)
 				goto out;
 
-			max_pgs_add_cmd = (hwc->max_req_msg_size -
-				sizeof(*add_req)) / sizeof(u64);
-
 			add_req = request_buf;
 			add_req->dma_region_handle = *gdma_region;
 			add_req->reserved3 = 0;
diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index 0ada3861e259f1301bb6c243ca9c5e7d89abe25d..cf680263d3bbe7c9a0127bdf45a4bcad373b54e5 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -1347,7 +1347,7 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,
 	/* The caller must keep the HWC alive throughout queue creation. */
 	hwc = gc->hwc.driver_data;
 	req_msg_size = struct_size(req, page_addr_list, num_page);
-	if (req_msg_size > hwc->max_req_msg_size)
+	if (req_msg_size > mana_hwc_get_max_req_size(hwc))
 		return -EINVAL;
 
 	req = kzalloc(req_msg_size, GFP_KERNEL);
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index cf1b9c75b10e2f2bc3f8da06f1adc2d7af3d2b97..c78c2baf7048d83215da7e0e1927b88b209a60d5 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -4,6 +4,7 @@
 #include <net/mana/gdma.h>
 #include <net/mana/mana.h>
 #include <net/mana/hw_channel.h>
+#include <linux/sizes.h>
 #include <linux/vmalloc.h>
 
 /* Private send outcome; don't confuse a local errno with DMA retirement. */
@@ -231,7 +232,8 @@ static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
 			break;
 
 		case HWC_INIT_DATA_QUEUE_DEPTH:
-			hwc->hwc_init_q_depth_max = (u16)val;
+			/* Preserve the full 24-bit report for validation. */
+			hwc->hwc_init_q_depth_max = val;
 			break;
 
 		case HWC_INIT_DATA_MAX_REQUEST:
@@ -594,7 +596,8 @@ static int mana_hwc_alloc_dma_buf(struct hw_channel_context *hwc, u16 q_depth,
 
 	dma_buf->num_reqs = q_depth;
 
-	buf_size = MANA_PAGE_ALIGN(q_depth * max_msg_size);
+	/* mana_gd_alloc_memory() requires a power-of-two length. */
+	buf_size = roundup_pow_of_two(MANA_PAGE_ALIGN(q_depth * max_msg_size));
 
 	gmi = &dma_buf->mem_info;
 	err = mana_gd_alloc_memory(gc, buf_size, gmi, false);
@@ -785,10 +788,15 @@ static int mana_hwc_test_channel(struct hw_channel_context *hwc)
 	return mana_gd_test_hwc_eq(hwc, hwc->cq->gdma_eq);
 }
 
-static int mana_hwc_establish_channel(struct hw_channel_context *hwc,
-				      u16 *q_depth,
-				      u32 *max_req_msg_size,
-				      u32 *max_resp_msg_size)
+struct mana_hwc_init_report {
+	u32 queue_depth;
+	u32 max_req_msg_size;
+	u32 max_resp_msg_size;
+};
+
+static int
+mana_hwc_establish_channel(struct hw_channel_context *hwc,
+			   struct mana_hwc_init_report *report)
 {
 	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 	struct gdma_queue *rq = hwc->rxq->gdma_wq;
@@ -800,6 +808,15 @@ static int mana_hwc_establish_channel(struct hw_channel_context *hwc,
 	u32 cq_id;
 	int err;
 
+	hwc->hwc_init_q_depth_max = 0;
+	hwc->hwc_init_max_req_msg_size = 0;
+	hwc->hwc_init_max_resp_msg_size = 0;
+	hwc->hwc_init_max_num_cqs = 0;
+	hwc->hwc_init_cq_id = 0;
+	gc->hwc.pdid = INVALID_PDID;
+	hwc->dest_vrq_id = 0;
+	hwc->dest_vrcq_id = 0;
+
 	gc->hwc.doorbell = INVALID_DOORBELL;
 	WRITE_ONCE(hwc->hwc_init_error, 0);
 	init_completion(&hwc->hwc_init_eqe_comp);
@@ -820,9 +837,9 @@ static int mana_hwc_establish_channel(struct hw_channel_context *hwc,
 	if (err)
 		return err;
 
-	*q_depth = hwc->hwc_init_q_depth_max;
-	*max_req_msg_size = hwc->hwc_init_max_req_msg_size;
-	*max_resp_msg_size = hwc->hwc_init_max_resp_msg_size;
+	report->queue_depth = hwc->hwc_init_q_depth_max;
+	report->max_req_msg_size = hwc->hwc_init_max_req_msg_size;
+	report->max_resp_msg_size = hwc->hwc_init_max_resp_msg_size;
 
 	/* Snapshot the device-reported count and id once, so the same value
 	 * sizes, bounds and indexes cq_table even across the sleeping
@@ -872,6 +889,9 @@ static int mana_hwc_init_queues(struct hw_channel_context *hwc, u16 q_depth,
 {
 	int err;
 
+	if (q_depth > U16_MAX / 2)
+		return -EINVAL;
+
 	err = mana_hwc_init_inflight_msg(hwc, q_depth);
 	if (err)
 		return err;
@@ -904,10 +924,11 @@ static int mana_hwc_init_queues(struct hw_channel_context *hwc, u16 q_depth,
 
 	hwc->num_inflight_msg = q_depth;
 	hwc->max_req_msg_size = max_req_msg_size;
+	hwc->max_resp_msg_size = max_resp_msg_size;
 
 	return 0;
 out:
-	/* mana_hwc_create_channel() will do the cleanup.*/
+	/* The setup path tears down any partially initialized queues. */
 	return err;
 }
 
@@ -923,6 +944,33 @@ static void mana_hwc_clear_cq_table(struct gdma_context *gc)
 	vfree(cq_table);
 }
 
+/* Setup is private; runtime teardown has unpublished and drained senders. */
+static void mana_hwc_destroy_queues(struct hw_channel_context *hwc)
+{
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
+
+	mana_hwc_clear_cq_table(gc);
+
+	if (hwc->cq) {
+		mana_hwc_destroy_cq(gc, hwc->cq);
+		hwc->cq = NULL;
+	}
+
+	if (hwc->txq) {
+		mana_hwc_destroy_wq(hwc, hwc->txq);
+		hwc->txq = NULL;
+	}
+	if (hwc->rxq) {
+		mana_hwc_destroy_wq(hwc, hwc->rxq);
+		hwc->rxq = NULL;
+	}
+
+	kfree(hwc->caller_ctx);
+	hwc->caller_ctx = NULL;
+	mana_gd_free_res_map(&hwc->inflight_msg_res);
+	hwc->num_inflight_msg = 0;
+}
+
 static int mana_hwc_publish_channel(struct hw_channel_context *hwc)
 {
 	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
@@ -1010,45 +1058,38 @@ static void mana_hwc_fence_channel(struct gdma_context *gc,
 		mana_hwc_unpublish_cq(gc, hwc->cq->gdma_cq);
 }
 
-static bool mana_hwc_release_channel(struct hw_channel_context *hwc)
+static int mana_hwc_teardown_queues(struct hw_channel_context *hwc)
 {
 	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 	int err;
 
 	mana_hwc_stop_channel(hwc);
-
-	/* An unacknowledged destroy leaves the PF's mappings live.  Fence
-	 * software dispatch, but retain every PF-visible allocation.
-	 */
 	err = mana_smc_teardown_hwc(&gc->shm_channel, false,
 				    &hwc->setup_active);
 	if (err) {
+		hwc->teardown_failed = true;
 		dev_err(hwc->dev,
 			"HWC teardown failed: %d, retaining PF-visible resources\n",
 			err);
 		mana_hwc_fence_channel(gc, hwc);
-		mana_hwc_retain_channel(hwc);
-		return false;
+		return err;
 	}
 
-	mana_hwc_clear_cq_table(gc);
+	mana_hwc_destroy_queues(hwc);
 
-	/* Fence the EQ before releasing the remaining HWC state. */
-	if (hwc->cq)
-		mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq);
-
-	if (hwc->txq)
-		mana_hwc_destroy_wq(hwc, hwc->txq);
-
-	if (hwc->rxq)
-		mana_hwc_destroy_wq(hwc, hwc->rxq);
-
-	kfree(hwc->caller_ctx);
-	hwc->caller_ctx = NULL;
+	return 0;
+}
 
-	mana_gd_free_res_map(&hwc->inflight_msg_res);
+static bool mana_hwc_release_channel(struct hw_channel_context *hwc)
+{
+	struct gdma_context *gc = hwc->gdma_dev->gdma_context;
 
-	hwc->num_inflight_msg = 0;
+	if (hwc->teardown_failed || mana_hwc_teardown_queues(hwc)) {
+		/* Leave any retry to the next destroy, not this unwind. */
+		hwc->teardown_failed = false;
+		mana_hwc_retain_channel(hwc);
+		return false;
+	}
 
 	hwc->gdma_dev->doorbell = INVALID_DOORBELL;
 	hwc->gdma_dev->pdid = INVALID_PDID;
@@ -1097,32 +1138,177 @@ void mana_hwc_free_retained_channel(struct gdma_context *gc)
 	gc->hwc.gdma_context = NULL;
 }
 
-static int mana_hwc_create_bootstrap_channel(struct hw_channel_context *hwc)
+static int
+mana_hwc_validate_report(struct hw_channel_context *hwc,
+			 const struct mana_hwc_init_report *report,
+			 u32 expected_depth, bool check_depth,
+			 bool require_exact_msg_sizes)
+{
+	if (!report->queue_depth || !report->max_req_msg_size ||
+	    !report->max_resp_msg_size) {
+		dev_err(hwc->dev,
+			"HWC: invalid maxima depth=%u req=%u resp=%u\n",
+			report->queue_depth, report->max_req_msg_size,
+			report->max_resp_msg_size);
+		return -EPROTO;
+	}
+
+	if (require_exact_msg_sizes &&
+	    (report->max_req_msg_size != HW_CHANNEL_MAX_REQUEST_SIZE ||
+	     report->max_resp_msg_size != HW_CHANNEL_MAX_RESPONSE_SIZE)) {
+		dev_err(hwc->dev,
+			"HWC: rebuilt message maxima req=%u resp=%u, expected %u/%u\n",
+			report->max_req_msg_size, report->max_resp_msg_size,
+			HW_CHANNEL_MAX_REQUEST_SIZE,
+			HW_CHANNEL_MAX_RESPONSE_SIZE);
+		return -EPROTO;
+	}
+
+	if (check_depth && report->queue_depth != expected_depth) {
+		dev_err(hwc->dev, "HWC: rebuilt depth %u, expected %u\n",
+			report->queue_depth, expected_depth);
+		return -EPROTO;
+	}
+
+	return 0;
+}
+
+static int mana_hwc_finish_channel(struct hw_channel_context *hwc,
+				   const struct mana_hwc_init_report *report)
 {
-	u32 max_req_msg_size, max_resp_msg_size;
-	u16 q_depth_max;
 	int err;
 
-	err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
+	/* MAX_REQUEST sizes the RQ; MAX_RESPONSE sizes the SQ. */
+	hwc->rx_msg_size_limit = report->max_req_msg_size;
+	hwc->tx_msg_size_limit = report->max_resp_msg_size;
+
+	err = mana_hwc_test_channel(hwc);
+	if (err)
+		dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
+
+	return err;
+}
+
+static int mana_hwc_build_channel(struct hw_channel_context *hwc, u16 q_depth,
+				  struct mana_hwc_init_report *report)
+{
+	int err;
+
+	err = mana_hwc_init_queues(hwc, q_depth,
 				   HW_CHANNEL_MAX_REQUEST_SIZE,
 				   HW_CHANNEL_MAX_RESPONSE_SIZE);
 	if (err) {
-		dev_err(hwc->dev, "Failed to initialize HWC: %d\n", err);
+		dev_err(hwc->dev, "Failed to initialize HWC depth %u: %d\n",
+			q_depth, err);
 		return err;
 	}
 
-	err = mana_hwc_establish_channel(hwc, &q_depth_max, &max_req_msg_size,
-					 &max_resp_msg_size);
-	if (err) {
-		dev_err(hwc->dev, "Failed to establish HWC: %d\n", err);
+	err = mana_hwc_establish_channel(hwc, report);
+	if (err)
+		dev_err(hwc->dev, "Failed to establish HWC depth %u: %d\n",
+			q_depth, err);
+
+	return err;
+}
+
+static int
+mana_hwc_restore_bootstrap(struct hw_channel_context *hwc,
+			   struct mana_hwc_init_report *report)
+{
+	int err;
+
+	err = mana_hwc_build_channel(hwc,
+				     HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
+				     report);
+	if (err)
 		return err;
-	}
 
-	err = mana_hwc_test_channel(hwc);
+	err = mana_hwc_validate_report(hwc, report, 0, false, false);
 	if (err)
-		dev_err(hwc->dev, "Failed to test HWC: %d\n", err);
+		return err;
 
-	return err;
+	return mana_hwc_finish_channel(hwc, report);
+}
+
+static int mana_hwc_rebuild_channel(struct hw_channel_context *hwc,
+				    u16 q_depth,
+				    struct mana_hwc_init_report *report)
+{
+	int cleanup_err;
+	int err;
+
+	err = mana_hwc_teardown_queues(hwc);
+	if (err)
+		return err;
+
+	err = mana_hwc_build_channel(hwc, q_depth, report);
+	if (!err)
+		err = mana_hwc_validate_report(hwc, report, q_depth,
+					       true, true);
+	if (!err)
+		err = mana_hwc_finish_channel(hwc, report);
+	if (!err)
+		return 0;
+
+	dev_warn(hwc->dev,
+		 "HWC depth %u rebuild failed, restoring bootstrap: %d\n",
+		 q_depth, err);
+
+	cleanup_err = mana_hwc_teardown_queues(hwc);
+	if (cleanup_err)
+		return cleanup_err;
+
+	return mana_hwc_restore_bootstrap(hwc, report);
+}
+
+static bool mana_hwc_depth_fits(u32 depth)
+{
+	/* ESTABLISH_HWC supplies addresses, not ring sizes. The PF uses the
+	 * same 4 KiB descriptor rings after rebuild: depth changes how many
+	 * requests may be outstanding, not where the rings wrap.
+	 */
+	return depth <= SZ_4K / GDMA_MAX_SQE_SIZE &&
+	       depth <= SZ_4K / GDMA_MAX_RQE_SIZE &&
+	       depth <= SZ_4K / (2 * GDMA_CQE_SIZE) &&
+	       depth <= SZ_4K / (2 * GDMA_EQE_SIZE);
+}
+
+static int mana_hwc_prepare_channel(struct hw_channel_context *hwc)
+{
+	struct mana_hwc_init_report report;
+	u16 rebuild_depth;
+	int err;
+
+	err = mana_hwc_build_channel(hwc,
+				     HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH,
+				     &report);
+	if (err)
+		return err;
+
+	err = mana_hwc_validate_report(hwc, &report, 0, false, false);
+	if (err)
+		return err;
+
+	if (!mana_hwc_depth_fits(report.queue_depth)) {
+		dev_warn(hwc->dev,
+			 "HWC depth %u exceeds ring capacity, keeping bootstrap\n",
+			 report.queue_depth);
+	} else if (report.queue_depth >
+		   HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH &&
+		   (report.max_req_msg_size != HW_CHANNEL_MAX_REQUEST_SIZE ||
+		    report.max_resp_msg_size != HW_CHANNEL_MAX_RESPONSE_SIZE)) {
+		dev_warn(hwc->dev,
+			 "HWC maxima req=%u resp=%u differ from rebuild policy %u/%u, keeping bootstrap\n",
+			 report.max_req_msg_size, report.max_resp_msg_size,
+			 HW_CHANNEL_MAX_REQUEST_SIZE,
+			 HW_CHANNEL_MAX_RESPONSE_SIZE);
+	} else if (report.queue_depth >
+		   HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH) {
+		rebuild_depth = report.queue_depth;
+		return mana_hwc_rebuild_channel(hwc, rebuild_depth, &report);
+	}
+
+	return mana_hwc_finish_channel(hwc, &report);
 }
 
 int mana_hwc_create_channel(struct gdma_context *gc)
@@ -1156,7 +1342,7 @@ int mana_hwc_create_channel(struct gdma_context *gc)
 	gd->pdid = INVALID_PDID;
 	gd->doorbell = INVALID_DOORBELL;
 
-	err = mana_hwc_create_bootstrap_channel(hwc);
+	err = mana_hwc_prepare_channel(hwc);
 	if (err) {
 		mana_hwc_release_channel(hwc);
 		return err;
@@ -1206,6 +1392,7 @@ struct hwc_submission {
 	struct list_head entry;
 	const struct gdma_req_hdr *req;
 	u32 len;
+	u32 resp_len;
 	unsigned int id;
 	int err;
 };
@@ -1216,7 +1403,8 @@ static int mana_hwc_stage(struct hw_channel_context *hwc,
 	struct hwc_work_request *tx = &hwc->txq->msg_buf->reqs[id];
 	struct gdma_req_hdr *hdr;
 
-	if (sub->len > tx->buf_len)
+	if (sub->len > min(hwc->tx_msg_size_limit, tx->buf_len) ||
+	    sub->resp_len > min(hwc->rx_msg_size_limit, hwc->max_req_msg_size))
 		return -EMSGSIZE;
 
 	hdr = memcpy(tx->buf_va, sub->req, sub->len);
@@ -1353,7 +1541,9 @@ int mana_hwc_send_request(struct hw_channel_context *hwc, u32 req_len,
 			  bool teardown)
 {
 	const struct gdma_req_hdr *hdr = req;
-	struct hwc_submission sub = { .req = req, .len = req_len };
+	struct hwc_submission sub = {
+		.req = req, .len = req_len, .resp_len = resp_len,
+	};
 	DEFINE_WAIT(wait);
 	long remaining;
 	int err;
diff --git a/include/net/mana/hw_channel.h b/include/net/mana/hw_channel.h
index c154264f0f7c30efb989243ce2d9282aefbc61a8..23df7222e833988ec0e46be9b64904755d4a3571 100644
--- a/include/net/mana/hw_channel.h
+++ b/include/net/mana/hw_channel.h
@@ -4,6 +4,8 @@
 #ifndef _HW_CHANNEL_H
 #define _HW_CHANNEL_H
 
+#include <linux/minmax.h>
+
 #define DEFAULT_LOG2_THROTTLING_FOR_ERROR_EQ  4
 
 #define HW_CHANNEL_MAX_REQUEST_SIZE  0x1000
@@ -195,8 +197,12 @@ struct hw_channel_context {
 
 	u16 num_inflight_msg;
 	u32 max_req_msg_size;
+	u32 max_resp_msg_size;
+	/* Immutable reported maxima for the final RQ and SQ directions. */
+	u32 rx_msg_size_limit;
+	u32 tx_msg_size_limit;
 
-	u16 hwc_init_q_depth_max;
+	u32 hwc_init_q_depth_max;
 	u32 hwc_init_max_req_msg_size;
 	u32 hwc_init_max_resp_msg_size;
 	u32 hwc_init_max_num_cqs;
@@ -226,6 +232,7 @@ struct hw_channel_context {
 	 * until it acknowledges DESTROY_HWC.
 	 */
 	bool setup_active;
+	bool teardown_failed;
 
 	/* mana_gd_send_request() callers, including waiters; under hwc_lock. */
 	unsigned int active_senders;
@@ -233,6 +240,13 @@ struct hw_channel_context {
 	struct hwc_caller_ctx *caller_ctx;
 };
 
+/* Host-to-PF requests are bounded by the negotiated TX limit and SQ stride. */
+static inline u32
+mana_hwc_get_max_req_size(const struct hw_channel_context *hwc)
+{
+	return min(hwc->tx_msg_size_limit, hwc->max_resp_msg_size);
+}
+
 int mana_hwc_create_channel(struct gdma_context *gc);
 void mana_hwc_destroy_channel(struct gdma_context *gc);
 void mana_hwc_free_retained_channel(struct gdma_context *gc);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v12 0/5] net: mana: concurrent HWC requests
  2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
                   ` (4 preceding siblings ...)
  2026-11-24 15:40 ` [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth Wei Hu
@ 2026-11-24 15:44 ` netdev-bot+sinfo
  5 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sinfo @ 2026-11-24 15:44 UTC (permalink / raw)
  To: Wei Hu
  Cc: longli, kotaranov, kuba, davem, pabeni, edumazet, andrew+netdev,
	jgg, leon, haiyangz, wei.liu, decui, shradhagupta, horms, ernis,
	stephen, netdev, linux-rdma, linux-hyperv, linux-kernel,
	gargaditya, kees+treewide, kees, mawasthi, weh, edumazet,
	shacharr

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-24 15:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 15:40 [PATCH net-next v12 0/5] net: mana: concurrent HWC requests Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 1/5] net: mana: validate the HWC doorbell before ringing it Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 2/5] net: mana: keep HWC queues until the PF acknowledges teardown Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 3/5] net: mana: protect the HWC response buffer until the sender returns Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 4/5] net: mana: support concurrent HWC requests Wei Hu
2026-11-24 15:40 ` [PATCH net-next v12 5/5] net: mana: use the reported HWC queue depth Wei Hu
2026-11-24 15:44 ` [PATCH net-next v12 0/5] net: mana: concurrent HWC requests netdev-bot+sinfo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®