From: Jie Liu <[email protected]>

Extract the descriptor ring reset loop into a sxe2_tx_queue_desc_ring_reset
helper and reuse it from both the scalar and vectorized queue reset paths.
Add a sxe2_tx_queue_reset_vec entry point for vectorized queues, export
sxe2_tx_buffer_ring_free for reuse outside the module (clearing the buffer
ring pointer after freeing it), and add sxe2_tx_vec_ops_get to build the
vectorized Tx queue operations table used by the vector path setup.

Fixes: e2a4ee85a5bd ("net/sxe2: add queue setup and control")
Cc: [email protected]
Cc: [email protected]

Signed-off-by: Jie Liu <[email protected]>
---
 drivers/net/sxe2/sxe2_tx.c       | 42 +++++++++++++++++++++++---------
 drivers/net/sxe2/sxe2_tx.h       |  4 +++
 drivers/net/sxe2/sxe2_txrx_vec.c | 16 +++++++++++-
 drivers/net/sxe2/sxe2_txrx_vec.h |  1 +
 4 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/drivers/net/sxe2/sxe2_tx.c b/drivers/net/sxe2/sxe2_tx.c
index f49238ceef..94a6e9afc7 100644
--- a/drivers/net/sxe2/sxe2_tx.c
+++ b/drivers/net/sxe2/sxe2_tx.c
@@ -19,6 +19,17 @@ static void *sxe2_tx_doorbell_addr_get(struct sxe2_adapter 
*adapter, uint16_t qu
                                     queue_id);
 }
 
+static void sxe2_tx_queue_desc_ring_reset(struct sxe2_tx_queue *txq)
+{
+       uint16_t i;
+       static const union sxe2_tx_data_desc zeroed_desc = {{0}};
+
+       for (i = 0; i < txq->ring_depth; i++) {
+               txq->desc_ring[i] = zeroed_desc;
+               txq->desc_ring[i].wb.dd = 
rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DESC_DONE);
+       }
+}
+
 static void sxe2_tx_tail_init(struct sxe2_adapter *adapter, struct 
sxe2_tx_queue *txq)
 {
        txq->tdt_reg_addr = sxe2_tx_doorbell_addr_get(adapter, txq->queue_id);
@@ -28,20 +39,12 @@ static void sxe2_tx_tail_init(struct sxe2_adapter *adapter, 
struct sxe2_tx_queue
 void __rte_cold sxe2_tx_queue_reset(struct sxe2_tx_queue *txq)
 {
        uint16_t prev, i;
-       volatile union sxe2_tx_data_desc *txd;
-       static const union sxe2_tx_data_desc zeroed_desc = {{0}};
        struct sxe2_tx_buffer *tx_buffer = txq->buffer_ring;
 
-       for (i = 0; i < txq->ring_depth; i++)
-               txq->desc_ring[i] = zeroed_desc;
+       sxe2_tx_queue_desc_ring_reset(txq);
 
        prev = txq->ring_depth - 1;
        for (i = 0; i < txq->ring_depth; i++) {
-               txd = &txq->desc_ring[i];
-               if (txd == NULL)
-                       continue;
-
-               txd->wb.dd = rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DESC_DONE);
                tx_buffer[i].mbuf       = NULL;
                tx_buffer[i].last_id    = i;
                tx_buffer[prev].next_id = i;
@@ -56,6 +59,21 @@ void __rte_cold sxe2_tx_queue_reset(struct sxe2_tx_queue 
*txq)
        txq->next_rs       = txq->rs_thresh  - 1;
 }
 
+void __rte_cold sxe2_tx_queue_reset_vec(struct sxe2_tx_queue *txq)
+{
+       sxe2_tx_queue_desc_ring_reset(txq);
+
+       memset(txq->buffer_ring, 0,
+               sizeof(struct sxe2_tx_buffer) * txq->ring_depth);
+
+       txq->desc_used_num = 0;
+       txq->desc_free_num = txq->ring_depth - 1;
+       txq->next_use      = 0;
+       txq->next_clean    = txq->ring_depth - 1;
+       txq->next_dd       = txq->rs_thresh  - 1;
+       txq->next_rs       = txq->rs_thresh  - 1;
+}
+
 void __rte_cold sxe2_tx_queue_mbufs_release(struct sxe2_tx_queue *txq)
 {
        uint32_t i;
@@ -70,10 +88,12 @@ void __rte_cold sxe2_tx_queue_mbufs_release(struct 
sxe2_tx_queue *txq)
        }
 }
 
-static void sxe2_tx_buffer_ring_free(struct sxe2_tx_queue *txq)
+void __rte_cold sxe2_tx_buffer_ring_free(struct sxe2_tx_queue *txq)
 {
-       if (txq != NULL && txq->buffer_ring != NULL)
+       if (txq != NULL && txq->buffer_ring != NULL) {
                rte_free(txq->buffer_ring);
+               txq->buffer_ring = NULL;
+       }
 }
 
 const struct sxe2_txq_ops sxe2_default_txq_ops = {
diff --git a/drivers/net/sxe2/sxe2_tx.h b/drivers/net/sxe2/sxe2_tx.h
index f4823126b3..bc5ff1c2bc 100644
--- a/drivers/net/sxe2/sxe2_tx.h
+++ b/drivers/net/sxe2/sxe2_tx.h
@@ -9,6 +9,10 @@
 
 void __rte_cold sxe2_tx_queue_reset(struct sxe2_tx_queue *txq);
 
+void __rte_cold sxe2_tx_queue_reset_vec(struct sxe2_tx_queue *txq);
+
+void __rte_cold sxe2_tx_buffer_ring_free(struct sxe2_tx_queue *txq);
+
 int32_t __rte_cold sxe2_tx_queue_start(struct rte_eth_dev *dev, uint16_t 
queue_id);
 
 void sxe2_tx_queue_mbufs_release(struct sxe2_tx_queue *txq);
diff --git a/drivers/net/sxe2/sxe2_txrx_vec.c b/drivers/net/sxe2/sxe2_txrx_vec.c
index cf004f5eb2..9cfa565548 100644
--- a/drivers/net/sxe2/sxe2_txrx_vec.c
+++ b/drivers/net/sxe2/sxe2_txrx_vec.c
@@ -8,6 +8,19 @@
 #include "sxe2_ethdev.h"
 #include "sxe2_common_log.h"
 
+static void sxe2_tx_queue_mbufs_release_vec(struct sxe2_tx_queue *txq);
+
+struct sxe2_txq_ops sxe2_tx_vec_ops_get(void)
+{
+       static const struct sxe2_txq_ops ops = {
+               .queue_reset      = sxe2_tx_queue_reset_vec,
+               .mbufs_release    = sxe2_tx_queue_mbufs_release_vec,
+               .buffer_ring_free = sxe2_tx_buffer_ring_free,
+       };
+
+       return ops;
+}
+
 int32_t __rte_cold sxe2_rx_vec_support_check(struct rte_eth_dev *dev, uint32_t 
*vec_flags)
 {
        struct sxe2_rx_queue *rxq;
@@ -233,7 +246,8 @@ int32_t __rte_cold sxe2_tx_queues_vec_prepare(struct 
rte_eth_dev *dev)
                        PMD_LOG_INFO(TX, "Failed to prepare tx queue, txq[%d] 
is NULL", i);
                        continue;
                }
-               txq->ops.mbufs_release = sxe2_tx_queue_mbufs_release_vec;
+               txq->ops = sxe2_tx_vec_ops_get();
+               txq->ops.queue_reset(txq);
        }
        return ret;
 }
diff --git a/drivers/net/sxe2/sxe2_txrx_vec.h b/drivers/net/sxe2/sxe2_txrx_vec.h
index c139aed776..b9bc4f9c27 100644
--- a/drivers/net/sxe2/sxe2_txrx_vec.h
+++ b/drivers/net/sxe2/sxe2_txrx_vec.h
@@ -89,6 +89,7 @@ uint16_t sxe2_rx_pkts_scattered_vec_neon_offload(void 
*rx_queue, struct rte_mbuf
 uint16_t sxe2_tx_pkts_vec_neon_simple(void *tx_queue, struct rte_mbuf 
**tx_pkts, uint16_t nb_pkts);
 uint16_t sxe2_tx_pkts_vec_neon(void *tx_queue, struct rte_mbuf **tx_pkts, 
uint16_t nb_pkts);
 #endif
+struct sxe2_txq_ops sxe2_tx_vec_ops_get(void);
 int32_t __rte_cold sxe2_tx_vec_support_check(struct rte_eth_dev *dev, uint32_t 
*vec_flags);
 int32_t __rte_cold sxe2_tx_queues_vec_prepare(struct rte_eth_dev *dev);
 int32_t __rte_cold sxe2_rx_vec_support_check(struct rte_eth_dev *dev, uint32_t 
*vec_flags);
-- 
2.52.0

Reply via email to