Skip to contentSkip to conversation

net/mlx5: fix Tx completion index wrap

PATCH New Bing Zhao 1 participant 1 message Nov 17 Network drivers

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH 1/1 net/mlx5: fix Tx completion index wrap

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")
---
 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(-)
drivers/net/mlx5/mlx5_tx.c +1 -1
index 89e38091b4..ca3e68646b 100644
@@ -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);
 	}
 }
drivers/net/mlx5/mlx5_tx.h +2 -2
index 69a18f8a49..5a5581abd1 100644
@@ -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). */
drivers/net/mlx5/mlx5_txq.c +1 -1
index f9b254c6c5..693c7f516e 100644
@@ -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();
 }
Signature · 1 line
2.34.1