[PATCH] net/mlx5: fix Tx completion index wrap

Bing Zhao bingz at nvidia.com
Tue Nov 17 10:31:28 CET 2026


The Tx CQ consumer index is kept as a 16-bit counter and written into the
24-bit CQ doorbell. Once the counter passes 65535, the doorbell wraps to
zero while the device producer continues, so the CQ is reported in overrun
and Tx stalls.

Widen both CQ indices to 32 bits and mask the doorbell with the 24-bit
consumer index mask. The producer index must widen too because it is
assigned from the consumer index.

Fixes: 1d88ba171942 ("net/mlx5: refactor Tx data path")
Cc: stable at dpdk.org

Signed-off-by: Bing Zhao <bingz at nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo at nvidia.com>
---
 drivers/net/mlx5/mlx5_tx.c  | 2 +-
 drivers/net/mlx5/mlx5_tx.h  | 4 ++--
 drivers/net/mlx5/mlx5_txq.c | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_tx.c b/drivers/net/mlx5/mlx5_tx.c
index 89e38091b4..ca3e68646b 100644
--- a/drivers/net/mlx5/mlx5_tx.c
+++ b/drivers/net/mlx5/mlx5_tx.c
@@ -251,7 +251,7 @@ mlx5_tx_handle_completion(struct mlx5_txq_data *__rte_restrict txq)
 	if (likely(ring_doorbell)) {
 		/* Ring doorbell to notify hardware. */
 		rte_compiler_barrier();
-		*txq->cq_db = rte_cpu_to_be_32(txq->cq_ci);
+		*txq->cq_db = rte_cpu_to_be_32(txq->cq_ci & MLX5_CI_MASK);
 		mlx5_tx_comp_flush(txq, last_cqe);
 	}
 }
diff --git a/drivers/net/mlx5/mlx5_tx.h b/drivers/net/mlx5/mlx5_tx.h
index 69a18f8a49..5a5581abd1 100644
--- a/drivers/net/mlx5/mlx5_tx.h
+++ b/drivers/net/mlx5/mlx5_tx.h
@@ -126,9 +126,9 @@ struct __rte_cache_aligned mlx5_txq_data {
 	uint16_t wqe_comp; /* WQE index since last completion request. */
 	uint16_t wqe_thres; /* WQE threshold to request completion in CQ. */
 	/* WQ related fields. */
-	uint16_t cq_ci; /* Consumer index for completion queue. */
-	uint16_t cq_pi; /* Production index for completion queue. */
 	uint16_t cqe_s; /* Number of CQ elements. */
+	uint32_t cq_ci; /* Consumer index for completion queue (doorbell takes low 24 bits). */
+	uint32_t cq_pi; /* Production index for completion queue. */
 	uint16_t cqe_m; /* Mask for CQ indices. */
 	/* CQ related fields. */
 	uint16_t elts_n:4; /* elts[] length (in log2). */
diff --git a/drivers/net/mlx5/mlx5_txq.c b/drivers/net/mlx5/mlx5_txq.c
index f9b254c6c5..693c7f516e 100644
--- a/drivers/net/mlx5/mlx5_txq.c
+++ b/drivers/net/mlx5/mlx5_txq.c
@@ -171,7 +171,7 @@ txq_sync_cq(struct mlx5_txq_data *txq)
 	}
 	/* Resync CQE and WQE (WQ in reset state). */
 	rte_io_wmb();
-	*txq->cq_db = rte_cpu_to_be_32(txq->cq_ci);
+	*txq->cq_db = rte_cpu_to_be_32(txq->cq_ci & MLX5_CI_MASK);
 	txq->cq_pi = txq->cq_ci;
 	rte_io_wmb();
 }
-- 
2.34.1


More information about the dev mailing list