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 if (txq && txq->cp_ring && txq->cp_ring->hw_stats)
23 txq->cp_ring->hw_stats = NULL;
26 static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
28 struct bnxt_sw_tx_bd *sw_ring;
34 sw_ring = txq->tx_ring->tx_buf_ring;
36 for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {
37 if (sw_ring[i].mbuf) {
38 rte_pktmbuf_free(sw_ring[i].mbuf);
39 sw_ring[i].mbuf = NULL;
45 void bnxt_free_tx_mbufs(struct bnxt *bp)
47 struct bnxt_tx_queue *txq;
50 for (i = 0; i < (int)bp->tx_nr_rings; i++) {
51 txq = bp->tx_queues[i];
52 bnxt_tx_queue_release_mbufs(txq);
56 void bnxt_tx_queue_release_op(void *tx_queue)
58 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
61 if (is_bnxt_in_error(txq->bp))
64 /* Free TX ring hardware descriptors */
65 bnxt_tx_queue_release_mbufs(txq);
66 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
68 /* Free TX completion ring hardware descriptors */
69 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
71 bnxt_free_txq_stats(txq);
72 rte_memzone_free(txq->mz);
80 int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
83 unsigned int socket_id,
84 const struct rte_eth_txconf *tx_conf)
86 struct bnxt *bp = eth_dev->data->dev_private;
87 struct bnxt_tx_queue *txq;
90 rc = is_bnxt_in_error(bp);
94 if (queue_idx >= bp->max_tx_rings) {
96 "Cannot create Tx ring %d. Only %d rings available\n",
97 queue_idx, bp->max_tx_rings);
101 if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
102 PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc);
107 if (eth_dev->data->tx_queues) {
108 txq = eth_dev->data->tx_queues[queue_idx];
110 bnxt_tx_queue_release_op(txq);
114 txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
115 RTE_CACHE_LINE_SIZE, socket_id);
117 PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!");
122 txq->free = rte_zmalloc_socket(NULL,
123 sizeof(struct rte_mbuf *) * nb_desc,
124 RTE_CACHE_LINE_SIZE, socket_id);
126 PMD_DRV_LOG(ERR, "allocation of tx mbuf free array failed!");
132 txq->nb_tx_desc = nb_desc;
133 txq->tx_free_thresh = tx_conf->tx_free_thresh;
134 txq->tx_deferred_start = tx_conf->tx_deferred_start;
136 rc = bnxt_init_tx_ring_struct(txq, socket_id);
140 txq->queue_id = queue_idx;
141 txq->port_id = eth_dev->data->port_id;
143 /* Allocate TX ring hardware descriptors */
144 if (bnxt_alloc_rings(bp, queue_idx, txq, NULL, txq->cp_ring, NULL,
146 PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for tx_ring failed!");
147 bnxt_tx_queue_release_op(txq);
152 if (bnxt_init_one_tx_ring(txq)) {
153 PMD_DRV_LOG(ERR, "bnxt_init_one_tx_ring failed!");
154 bnxt_tx_queue_release_op(txq);
159 eth_dev->data->tx_queues[queue_idx] = txq;
161 if (txq->tx_deferred_start)
162 txq->tx_started = false;
164 txq->tx_started = true;