1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
8 #include <rte_malloc.h>
11 #include "bnxt_hwrm.h"
12 #include "bnxt_ring.h"
20 uint64_t bnxt_get_tx_port_offloads(struct bnxt *bp)
22 uint64_t tx_offload_capa;
24 tx_offload_capa = RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
25 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
26 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
27 RTE_ETH_TX_OFFLOAD_TCP_TSO |
28 RTE_ETH_TX_OFFLOAD_QINQ_INSERT |
29 RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
31 if (bp->fw_cap & BNXT_FW_CAP_VLAN_TX_INSERT)
32 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT;
34 if (BNXT_TUNNELED_OFFLOADS_CAP_ALL_EN(bp))
35 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
37 if (BNXT_TUNNELED_OFFLOADS_CAP_VXLAN_EN(bp))
38 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO;
39 if (BNXT_TUNNELED_OFFLOADS_CAP_GRE_EN(bp))
40 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO;
41 if (BNXT_TUNNELED_OFFLOADS_CAP_NGE_EN(bp))
42 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO;
43 if (BNXT_TUNNELED_OFFLOADS_CAP_IPINIP_EN(bp))
44 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO;
46 return tx_offload_capa;
49 void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
51 if (txq && txq->cp_ring && txq->cp_ring->hw_stats)
52 txq->cp_ring->hw_stats = NULL;
55 static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
57 struct rte_mbuf **sw_ring;
60 if (!txq || !txq->tx_ring)
63 sw_ring = txq->tx_ring->tx_buf_ring;
65 for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {
67 rte_pktmbuf_free_seg(sw_ring[i]);
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(struct rte_eth_dev *dev, uint16_t queue_idx)
87 struct bnxt_tx_queue *txq = dev->data->tx_queues[queue_idx];
90 if (is_bnxt_in_error(txq->bp))
93 /* Free TX ring hardware descriptors */
94 bnxt_free_hwrm_tx_ring(txq->bp, txq->queue_id);
95 bnxt_tx_queue_release_mbufs(txq);
97 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
98 rte_free(txq->tx_ring->tx_ring_struct);
99 rte_free(txq->tx_ring);
102 /* Free TX completion ring hardware descriptors */
104 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
105 rte_free(txq->cp_ring->cp_ring_struct);
106 rte_free(txq->cp_ring);
109 bnxt_free_txq_stats(txq);
110 rte_memzone_free(txq->mz);
115 dev->data->tx_queues[queue_idx] = NULL;
119 int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
122 unsigned int socket_id,
123 const struct rte_eth_txconf *tx_conf)
125 struct bnxt *bp = eth_dev->data->dev_private;
126 struct bnxt_tx_queue *txq;
129 rc = is_bnxt_in_error(bp);
133 if (queue_idx >= bnxt_max_rings(bp)) {
135 "Cannot create Tx ring %d. Only %d rings available\n",
136 queue_idx, bp->max_tx_rings);
140 if (nb_desc < BNXT_MIN_RING_DESC || nb_desc > MAX_TX_DESC_CNT) {
141 PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc);
145 if (eth_dev->data->tx_queues) {
146 txq = eth_dev->data->tx_queues[queue_idx];
148 bnxt_tx_queue_release_op(eth_dev, queue_idx);
150 txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
151 RTE_CACHE_LINE_SIZE, socket_id);
153 PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!");
158 eth_dev->data->tx_queues[queue_idx] = txq;
160 txq->free = rte_zmalloc_socket(NULL,
161 sizeof(struct rte_mbuf *) * nb_desc,
162 RTE_CACHE_LINE_SIZE, socket_id);
164 PMD_DRV_LOG(ERR, "allocation of tx mbuf free array failed!");
168 txq->nb_tx_desc = nb_desc;
169 txq->tx_free_thresh =
170 RTE_MIN(rte_align32pow2(nb_desc) / 4, RTE_BNXT_MAX_TX_BURST);
171 txq->offloads = eth_dev->data->dev_conf.txmode.offloads |
174 txq->tx_deferred_start = tx_conf->tx_deferred_start;
176 rc = bnxt_init_tx_ring_struct(txq, socket_id);
180 txq->queue_id = queue_idx;
181 txq->port_id = eth_dev->data->port_id;
183 /* Allocate TX ring hardware descriptors */
184 if (bnxt_alloc_rings(bp, socket_id, queue_idx, txq, NULL, txq->cp_ring,
186 PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for tx_ring failed!");
191 if (bnxt_init_one_tx_ring(txq)) {
192 PMD_DRV_LOG(ERR, "bnxt_init_one_tx_ring failed!");
199 bnxt_tx_queue_release_op(eth_dev, queue_idx);