1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
8 #include <rte_malloc.h>
12 #include "bnxt_ring.h"
20 void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
22 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
28 static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
30 struct bnxt_sw_tx_bd *sw_ring;
33 sw_ring = txq->tx_ring->tx_buf_ring;
35 for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {
36 if (sw_ring[i].mbuf) {
37 rte_pktmbuf_free(sw_ring[i].mbuf);
38 sw_ring[i].mbuf = NULL;
44 void bnxt_free_tx_mbufs(struct bnxt *bp)
46 struct bnxt_tx_queue *txq;
49 for (i = 0; i < (int)bp->tx_nr_rings; i++) {
50 txq = bp->tx_queues[i];
51 bnxt_tx_queue_release_mbufs(txq);
55 void bnxt_tx_queue_release_op(void *tx_queue)
57 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
60 /* Free TX ring hardware descriptors */
61 bnxt_tx_queue_release_mbufs(txq);
62 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
64 /* Free TX completion ring hardware descriptors */
65 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
67 bnxt_free_txq_stats(txq);
73 int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
76 unsigned int socket_id,
77 const struct rte_eth_txconf *tx_conf)
79 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
80 struct bnxt_tx_queue *txq;
83 if (queue_idx >= bp->max_tx_rings) {
85 "Cannot create Tx ring %d. Only %d rings available\n",
86 queue_idx, bp->max_tx_rings);
90 if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
91 PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc);
96 if (eth_dev->data->tx_queues) {
97 txq = eth_dev->data->tx_queues[queue_idx];
99 bnxt_tx_queue_release_op(txq);
103 txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
104 RTE_CACHE_LINE_SIZE, socket_id);
106 PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!");
111 txq->nb_tx_desc = nb_desc;
112 txq->tx_free_thresh = tx_conf->tx_free_thresh;
114 rc = bnxt_init_tx_ring_struct(txq, socket_id);
118 txq->queue_id = queue_idx;
119 txq->port_id = eth_dev->data->port_id;
121 /* Allocate TX ring hardware descriptors */
122 if (bnxt_alloc_rings(bp, queue_idx, txq->tx_ring, NULL, txq->cp_ring,
124 PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for tx_ring failed!");
125 bnxt_tx_queue_release_op(txq);
130 if (bnxt_init_one_tx_ring(txq)) {
131 PMD_DRV_LOG(ERR, "bnxt_init_one_tx_ring failed!");
132 bnxt_tx_queue_release_op(txq);
137 eth_dev->data->tx_queues[queue_idx] = txq;