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.

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 | 17 ++++++++++---
 3 files changed, 49 insertions(+), 14 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..1442d5d119 100644
--- a/drivers/net/sxe2/sxe2_txrx_vec.c
+++ b/drivers/net/sxe2/sxe2_txrx_vec.c
@@ -8,6 +8,14 @@
 #include "sxe2_ethdev.h"
 #include "sxe2_common_log.h"
 
+static void sxe2_tx_queue_mbufs_release_vec(struct sxe2_tx_queue *txq);
+
+static const struct sxe2_txq_ops sxe2_tx_vec_ops = {
+       .queue_reset      = sxe2_tx_queue_reset_vec,
+       .mbufs_release    = sxe2_tx_queue_mbufs_release_vec,
+       .buffer_ring_free = sxe2_tx_buffer_ring_free,
+};
+
 int32_t __rte_cold sxe2_rx_vec_support_check(struct rte_eth_dev *dev, uint32_t 
*vec_flags)
 {
        struct sxe2_rx_queue *rxq;
@@ -230,10 +238,13 @@ int32_t __rte_cold sxe2_tx_queues_vec_prepare(struct 
rte_eth_dev *dev)
        for (i = 0; i < dev->data->nb_tx_queues; ++i) {
                txq = dev->data->tx_queues[i];
                if (txq == NULL) {
-                       PMD_LOG_INFO(TX, "Failed to prepare tx queue, txq[%d] 
is NULL", i);
-                       continue;
+                       PMD_LOG_ERR(TX, "Failed to prepare tx queue, txq[%d] is 
NULL", i);
+                       ret = -EINVAL;
+                       goto l_end;
                }
-               txq->ops.mbufs_release = sxe2_tx_queue_mbufs_release_vec;
+               txq->ops = sxe2_tx_vec_ops;
+               txq->ops.queue_reset(txq);
        }
+l_end:
        return ret;
 }
-- 
2.52.0

Reply via email to