Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2014-2023 Broadcom 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include <inttypes.h> 7 : : 8 : : #include <rte_malloc.h> 9 : : 10 : : #include "bnxt.h" 11 : : #include "bnxt_hwrm.h" 12 : : #include "bnxt_ring.h" 13 : : #include "bnxt_txq.h" 14 : : #include "bnxt_txr.h" 15 : : 16 : : /* 17 : : * TX Queues 18 : : */ 19 : : 20 : 0 : uint64_t bnxt_get_tx_port_offloads(struct bnxt *bp) 21 : : { 22 : : uint64_t tx_offload_capa; 23 : : 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; 30 : : 31 [ # # ]: 0 : if (bp->fw_cap & BNXT_FW_CAP_VLAN_TX_INSERT) 32 : : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_VLAN_INSERT; 33 : : 34 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_ALL_EN(bp)) 35 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM; 36 : : 37 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_VXLAN_EN(bp)) 38 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO; 39 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_GRE_EN(bp)) 40 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO; 41 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_NGE_EN(bp)) 42 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO; 43 [ # # ]: 0 : if (BNXT_TUNNELED_OFFLOADS_CAP_IPINIP_EN(bp)) 44 : 0 : tx_offload_capa |= RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO; 45 : : 46 : 0 : return tx_offload_capa; 47 : : } 48 : : 49 : 0 : void bnxt_free_txq_stats(struct bnxt_tx_queue *txq) 50 : : { 51 [ # # # # : 0 : if (txq && txq->cp_ring && txq->cp_ring->hw_stats) # # ] 52 : 0 : txq->cp_ring->hw_stats = NULL; 53 : 0 : } 54 : : 55 : 0 : static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq) 56 : : { 57 : : struct rte_mbuf **sw_ring; 58 : : uint16_t i; 59 : : 60 [ # # # # ]: 0 : if (!txq || !txq->tx_ring) 61 : : return; 62 : : 63 : 0 : sw_ring = txq->tx_ring->tx_buf_ring; 64 [ # # ]: 0 : if (sw_ring) { 65 [ # # ]: 0 : for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) { 66 [ # # ]: 0 : if (sw_ring[i]) { 67 : : rte_pktmbuf_free_seg(sw_ring[i]); 68 : 0 : sw_ring[i] = NULL; 69 : : } 70 : : } 71 : : } 72 : : } 73 : : 74 : 0 : void bnxt_free_tx_mbufs(struct bnxt *bp) 75 : : { 76 : : struct bnxt_tx_queue *txq; 77 : : int i; 78 : : 79 [ # # ]: 0 : for (i = 0; i < (int)bp->tx_nr_rings; i++) { 80 : 0 : txq = bp->tx_queues[i]; 81 : 0 : bnxt_tx_queue_release_mbufs(txq); 82 : : } 83 : 0 : } 84 : : 85 : 0 : void bnxt_tx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx) 86 : : { 87 : 0 : struct bnxt_tx_queue *txq = dev->data->tx_queues[queue_idx]; 88 : : 89 [ # # ]: 0 : if (txq) { 90 [ # # ]: 0 : if (is_bnxt_in_error(txq->bp)) 91 : : return; 92 : : 93 : : /* Free TX ring hardware descriptors */ 94 : 0 : bnxt_free_hwrm_tx_ring(txq->bp, txq->queue_id); 95 : 0 : bnxt_tx_queue_release_mbufs(txq); 96 [ # # ]: 0 : if (txq->tx_ring) { 97 : 0 : bnxt_free_ring(txq->tx_ring->tx_ring_struct); 98 : 0 : rte_free(txq->tx_ring->tx_ring_struct); 99 : 0 : rte_free(txq->tx_ring->nr_bds); 100 : 0 : rte_free(txq->tx_ring); 101 : : } 102 : : 103 : : /* Free TX completion ring hardware descriptors */ 104 [ # # ]: 0 : if (txq->cp_ring) { 105 : 0 : bnxt_free_ring(txq->cp_ring->cp_ring_struct); 106 : 0 : rte_free(txq->cp_ring->cp_ring_struct); 107 : 0 : rte_free(txq->cp_ring); 108 : : } 109 : : 110 : 0 : bnxt_free_txq_stats(txq); 111 : 0 : rte_memzone_free(txq->mz); 112 : 0 : txq->mz = NULL; 113 : : 114 : 0 : rte_free(txq->free); 115 : 0 : rte_free(txq); 116 : 0 : dev->data->tx_queues[queue_idx] = NULL; 117 : : } 118 : : } 119 : : 120 : 0 : int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev, 121 : : uint16_t queue_idx, 122 : : uint16_t nb_desc, 123 : : unsigned int socket_id, 124 : : const struct rte_eth_txconf *tx_conf) 125 : : { 126 : 0 : struct bnxt *bp = eth_dev->data->dev_private; 127 : : struct bnxt_tx_queue *txq; 128 : : int rc = 0; 129 : : 130 : 0 : rc = is_bnxt_in_error(bp); 131 [ # # ]: 0 : if (rc) 132 : : return rc; 133 : : 134 [ # # ]: 0 : if (queue_idx >= bnxt_max_rings(bp)) { 135 : 0 : PMD_DRV_LOG(ERR, 136 : : "Cannot create Tx ring %d. Only %d rings available\n", 137 : : queue_idx, bp->max_tx_rings); 138 : 0 : return -EINVAL; 139 : : } 140 : : 141 [ # # ]: 0 : if (nb_desc < BNXT_MIN_RING_DESC || nb_desc > MAX_TX_DESC_CNT) { 142 : 0 : PMD_DRV_LOG(ERR, "nb_desc %d is invalid", nb_desc); 143 : 0 : return -EINVAL; 144 : : } 145 : : 146 [ # # ]: 0 : if (eth_dev->data->tx_queues) { 147 : 0 : txq = eth_dev->data->tx_queues[queue_idx]; 148 [ # # ]: 0 : if (txq) 149 : 0 : bnxt_tx_queue_release_op(eth_dev, queue_idx); 150 : : } 151 : 0 : txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue), 152 : : RTE_CACHE_LINE_SIZE, socket_id); 153 [ # # ]: 0 : if (!txq) { 154 : 0 : PMD_DRV_LOG(ERR, "bnxt_tx_queue allocation failed!"); 155 : 0 : return -ENOMEM; 156 : : } 157 : : 158 : 0 : txq->bp = bp; 159 : 0 : eth_dev->data->tx_queues[queue_idx] = txq; 160 : : 161 : 0 : txq->free = rte_zmalloc_socket(NULL, 162 : : sizeof(struct rte_mbuf *) * nb_desc, 163 : : RTE_CACHE_LINE_SIZE, socket_id); 164 [ # # ]: 0 : if (!txq->free) { 165 : 0 : PMD_DRV_LOG(ERR, "allocation of tx mbuf free array failed!"); 166 : : rc = -ENOMEM; 167 : 0 : goto err; 168 : : } 169 : 0 : txq->nb_tx_desc = nb_desc; 170 : 0 : txq->tx_free_thresh = 171 : 0 : RTE_MIN(rte_align32pow2(nb_desc) / 4, RTE_BNXT_MAX_TX_BURST); 172 : 0 : txq->offloads = eth_dev->data->dev_conf.txmode.offloads | 173 : 0 : tx_conf->offloads; 174 : : 175 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start; 176 : : 177 : 0 : rc = bnxt_init_tx_ring_struct(txq, socket_id); 178 [ # # ]: 0 : if (rc) 179 : 0 : goto err; 180 : : 181 : 0 : txq->queue_id = queue_idx; 182 : 0 : txq->port_id = eth_dev->data->port_id; 183 : : 184 : : /* Allocate TX ring hardware descriptors */ 185 [ # # ]: 0 : if (bnxt_alloc_rings(bp, socket_id, queue_idx, txq, NULL, txq->cp_ring, 186 : : NULL, "txr")) { 187 : 0 : PMD_DRV_LOG(ERR, "ring_dma_zone_reserve for tx_ring failed!"); 188 : : rc = -ENOMEM; 189 : 0 : goto err; 190 : : } 191 : : 192 [ # # ]: 0 : if (bnxt_init_one_tx_ring(txq)) { 193 : 0 : PMD_DRV_LOG(ERR, "bnxt_init_one_tx_ring failed!"); 194 : : rc = -ENOMEM; 195 : 0 : goto err; 196 : : } 197 : : 198 : : return 0; 199 : 0 : err: 200 : 0 : bnxt_tx_queue_release_op(eth_dev, queue_idx); 201 : 0 : return rc; 202 : : }