From: Daniil Bobryshev <[email protected]>

The Rx burst and rx_queue_count() pick the CQE validity check by the
CQE compression layout of the queue: the validity iteration count in
the enhanced layout, the owner bit otherwise. Both open-code the same
ternary.

Move it into mlx5_rxq_check_cqe() and use the helper in
mlx5_rx_poll_len() and rx_queue_count(). The CQ size is passed by the
caller, as for check_cqe(), so the Rx burst keeps using the value it
already has.

No functional change.

Signed-off-by: Daniil Bobryshev <[email protected]>
---
v2:
- new patch: helper for the Rx CQE check, as discussed for v1.

The helper is a plain inline function, as the coding style asks for new
code. Built with gcc 13.3 for x86_64, it is inlined into both callers.

 drivers/net/mlx5/mlx5_rx.c |  8 ++------
 drivers/net/mlx5/mlx5_rx.h | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_rx.c b/drivers/net/mlx5/mlx5_rx.c
index f55b96aeb..d3d23e3b0 100644
--- a/drivers/net/mlx5/mlx5_rx.c
+++ b/drivers/net/mlx5/mlx5_rx.c
@@ -94,9 +94,7 @@ rx_queue_count(struct mlx5_rxq_data *rxq)
                cq_ci = rxq->cq_ci;
        }
        cqe = &(*rxq->cqes)[cq_ci & cqe_cnt];
-       while ((rxq->cqe_comp_layout ?
-               check_cqe_iteration(cqe, rxq->cqe_n, cq_ci) :
-               check_cqe(cqe, cqe_n, cq_ci)) != MLX5_CQE_STATUS_HW_OWN) {
+       while (mlx5_rxq_check_cqe(rxq, cqe, cqe_n, cq_ci) != 
MLX5_CQE_STATUS_HW_OWN) {
                int8_t op_own;
                unsigned int n;
 
@@ -797,9 +795,7 @@ mlx5_rx_poll_len(struct mlx5_rxq_data *rxq, volatile struct 
mlx5_cqe *cqe,
                        int8_t op_own;
                        uint32_t cq_ci;
 
-                       ret = (rxq->cqe_comp_layout) ?
-                               check_cqe_iteration(cqe, rxq->cqe_n, 
rxq->cq_ci) :
-                               check_cqe(cqe, cqe_n, rxq->cq_ci);
+                       ret = mlx5_rxq_check_cqe(rxq, cqe, cqe_n, rxq->cq_ci);
                        if (unlikely(ret != MLX5_CQE_STATUS_SW_OWN)) {
                                if (unlikely(ret == MLX5_CQE_STATUS_ERR ||
                                             rxq->err_state)) {
diff --git a/drivers/net/mlx5/mlx5_rx.h b/drivers/net/mlx5/mlx5_rx.h
index 0d1eee61b..dca0defee 100644
--- a/drivers/net/mlx5/mlx5_rx.h
+++ b/drivers/net/mlx5/mlx5_rx.h
@@ -346,6 +346,32 @@ void mlx5_rxq_sync_cq(struct mlx5_rxq_data *rxq);
 
 static int mlx5_rxq_mprq_enabled(struct mlx5_rxq_data *rxq);
 
+/**
+ * Check whether Rx CQE is valid, with the check matching the CQE compression
+ * layout of the queue: validity iteration count in the enhanced layout,
+ * owner bit otherwise.
+ *
+ * @param rxq
+ *   Pointer to Rx queue structure.
+ * @param cqe
+ *   Pointer to CQE.
+ * @param cqes_n
+ *   Size of completion queue.
+ * @param ci
+ *   Consumer index.
+ *
+ * @return
+ *   The CQE status.
+ */
+static inline enum mlx5_cqe_status
+mlx5_rxq_check_cqe(struct mlx5_rxq_data *rxq, volatile struct mlx5_cqe *cqe,
+                  const uint16_t cqes_n, const uint32_t ci)
+{
+       return rxq->cqe_comp_layout ?
+              check_cqe_iteration(cqe, rxq->cqe_n, ci) :
+              check_cqe(cqe, cqes_n, ci);
+}
+
 /**
  * Query LKey for an address on Rx. No need to flush local caches
  * as the Rx mempool database entries are valid for the lifetime of the queue.
-- 
2.54.0 (Apple Git-157)

Reply via email to