4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_malloc.h>
40 #include "bnxt_ring.h"
48 void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
50 struct bnxt_cp_ring_info *cpr = txq->cp_ring;
52 /* 'Unreserve' rte_memzone */
58 static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
60 struct bnxt_sw_tx_bd *sw_ring;
63 sw_ring = txq->tx_ring->tx_buf_ring;
65 for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {
66 if (sw_ring[i].mbuf) {
67 rte_pktmbuf_free(sw_ring[i].mbuf);
68 sw_ring[i].mbuf = NULL;
74 void bnxt_free_tx_mbufs(struct bnxt *bp)
76 struct bnxt_tx_queue *txq;
79 for (i = 0; i < (int)bp->tx_nr_rings; i++) {
80 txq = bp->tx_queues[i];
81 bnxt_tx_queue_release_mbufs(txq);
85 void bnxt_tx_queue_release_op(void *tx_queue)
87 struct bnxt_tx_queue *txq = (struct bnxt_tx_queue *)tx_queue;
90 /* Free TX ring hardware descriptors */
91 bnxt_tx_queue_release_mbufs(txq);
92 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
94 /* Free TX completion ring hardware descriptors */
95 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
97 bnxt_free_txq_stats(txq);
103 int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
106 unsigned int socket_id,
107 const struct rte_eth_txconf *tx_conf)
109 struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
110 struct bnxt_tx_queue *txq;
112 if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) {
113 RTE_LOG(ERR, PMD, "nb_desc %d is invalid", nb_desc);
117 if (eth_dev->data->tx_queues) {
118 txq = eth_dev->data->tx_queues[queue_idx];
120 bnxt_tx_queue_release_op(txq);
124 txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
125 RTE_CACHE_LINE_SIZE, socket_id);
127 RTE_LOG(ERR, PMD, "bnxt_tx_queue allocation failed!");
131 txq->nb_tx_desc = nb_desc;
132 txq->tx_free_thresh = tx_conf->tx_free_thresh;
134 bnxt_init_tx_ring_struct(txq);
136 txq->queue_id = queue_idx;
137 txq->port_id = eth_dev->data->port_id;
139 /* Allocate TX ring hardware descriptors */
140 if (bnxt_alloc_rings(bp, queue_idx, txq->tx_ring, NULL, txq->cp_ring,
142 RTE_LOG(ERR, PMD, "ring_dma_zone_reserve for tx_ring failed!");
143 bnxt_tx_queue_release_op(txq);
147 if (bnxt_init_one_tx_ring(txq)) {
148 RTE_LOG(ERR, PMD, "bnxt_init_one_tx_ring failed!");
149 bnxt_tx_queue_release_op(txq);
153 eth_dev->data->tx_queues[queue_idx] = txq;