LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_txq.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 98 0.0 %
Date: 2025-02-01 18:54:23 Functions: 0 6 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 60 0.0 %

           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         [ #  # ]:          0 :         if (bp->fw_cap & BNXT_FW_CAP_UDP_GSO)
      46                 :          0 :                 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_UDP_TSO;
      47                 :            : 
      48                 :          0 :         return tx_offload_capa;
      49                 :            : }
      50                 :            : 
      51                 :          0 : void bnxt_free_txq_stats(struct bnxt_tx_queue *txq)
      52                 :            : {
      53   [ #  #  #  #  :          0 :         if (txq && txq->cp_ring && txq->cp_ring->hw_stats)
                   #  # ]
      54                 :          0 :                 txq->cp_ring->hw_stats = NULL;
      55                 :          0 : }
      56                 :            : 
      57                 :          0 : static void bnxt_tx_queue_release_mbufs(struct bnxt_tx_queue *txq)
      58                 :            : {
      59                 :            :         struct rte_mbuf **sw_ring;
      60                 :            :         uint16_t i;
      61                 :            : 
      62   [ #  #  #  # ]:          0 :         if (!txq || !txq->tx_ring)
      63                 :            :                 return;
      64                 :            : 
      65                 :          0 :         sw_ring = txq->tx_ring->tx_buf_ring;
      66         [ #  # ]:          0 :         if (sw_ring) {
      67         [ #  # ]:          0 :                 for (i = 0; i < txq->tx_ring->tx_ring_struct->ring_size; i++) {
      68         [ #  # ]:          0 :                         if (sw_ring[i]) {
      69                 :            :                                 rte_pktmbuf_free_seg(sw_ring[i]);
      70                 :          0 :                                 sw_ring[i] = NULL;
      71                 :            :                         }
      72                 :            :                 }
      73                 :            :         }
      74                 :            : }
      75                 :            : 
      76                 :          0 : void bnxt_free_tx_mbufs(struct bnxt *bp)
      77                 :            : {
      78                 :            :         struct bnxt_tx_queue *txq;
      79                 :            :         int i;
      80                 :            : 
      81         [ #  # ]:          0 :         for (i = 0; i < (int)bp->tx_nr_rings; i++) {
      82                 :          0 :                 txq = bp->tx_queues[i];
      83                 :          0 :                 bnxt_tx_queue_release_mbufs(txq);
      84                 :            :         }
      85                 :          0 : }
      86                 :            : 
      87                 :          0 : void bnxt_tx_queue_release_op(struct rte_eth_dev *dev, uint16_t queue_idx)
      88                 :            : {
      89                 :          0 :         struct bnxt_tx_queue *txq = dev->data->tx_queues[queue_idx];
      90                 :            : 
      91         [ #  # ]:          0 :         if (txq) {
      92         [ #  # ]:          0 :                 if (is_bnxt_in_error(txq->bp))
      93                 :            :                         return;
      94                 :            : 
      95                 :            :                 /* Free TX ring hardware descriptors */
      96                 :          0 :                 bnxt_free_hwrm_tx_ring(txq->bp, txq->queue_id);
      97                 :          0 :                 bnxt_tx_queue_release_mbufs(txq);
      98         [ #  # ]:          0 :                 if (txq->tx_ring) {
      99                 :          0 :                         bnxt_free_ring(txq->tx_ring->tx_ring_struct);
     100                 :          0 :                         rte_free(txq->tx_ring->tx_ring_struct);
     101                 :          0 :                         rte_free(txq->tx_ring->nr_bds);
     102                 :          0 :                         rte_free(txq->tx_ring);
     103                 :            :                 }
     104                 :            : 
     105                 :            :                 /* Free TX completion ring hardware descriptors */
     106         [ #  # ]:          0 :                 if (txq->cp_ring) {
     107                 :          0 :                         bnxt_free_txq_stats(txq);
     108                 :          0 :                         bnxt_free_ring(txq->cp_ring->cp_ring_struct);
     109                 :          0 :                         rte_free(txq->cp_ring->cp_ring_struct);
     110                 :          0 :                         rte_free(txq->cp_ring);
     111                 :            :                 }
     112                 :            : 
     113                 :          0 :                 rte_memzone_free(txq->mz);
     114                 :          0 :                 txq->mz = NULL;
     115                 :            : 
     116                 :          0 :                 rte_free(txq->free);
     117                 :          0 :                 pthread_mutex_destroy(&txq->txq_lock);
     118                 :          0 :                 rte_free(txq);
     119                 :          0 :                 dev->data->tx_queues[queue_idx] = NULL;
     120                 :            :         }
     121                 :            : }
     122                 :            : 
     123                 :          0 : int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev,
     124                 :            :                                uint16_t queue_idx,
     125                 :            :                                uint16_t nb_desc,
     126                 :            :                                unsigned int socket_id,
     127                 :            :                                const struct rte_eth_txconf *tx_conf)
     128                 :            : {
     129                 :          0 :         struct bnxt *bp = eth_dev->data->dev_private;
     130                 :            :         struct bnxt_tx_queue *txq;
     131                 :            :         int rc = 0;
     132                 :            : 
     133                 :          0 :         rc = is_bnxt_in_error(bp);
     134         [ #  # ]:          0 :         if (rc)
     135                 :            :                 return rc;
     136                 :            : 
     137         [ #  # ]:          0 :         if (queue_idx >= bnxt_max_rings(bp)) {
     138                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
     139                 :            :                         "Cannot create Tx ring %d. Only %d rings available",
     140                 :            :                         queue_idx, bp->max_tx_rings);
     141                 :          0 :                 return -EINVAL;
     142                 :            :         }
     143                 :            : 
     144         [ #  # ]:          0 :         if (nb_desc < BNXT_MIN_RING_DESC || nb_desc > MAX_TX_DESC_CNT) {
     145                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "nb_desc %d is invalid", nb_desc);
     146                 :          0 :                 return -EINVAL;
     147                 :            :         }
     148                 :            : 
     149         [ #  # ]:          0 :         if (eth_dev->data->tx_queues) {
     150                 :          0 :                 txq = eth_dev->data->tx_queues[queue_idx];
     151         [ #  # ]:          0 :                 if (txq)
     152                 :          0 :                         bnxt_tx_queue_release_op(eth_dev, queue_idx);
     153                 :            :         }
     154                 :          0 :         txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue),
     155                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
     156         [ #  # ]:          0 :         if (!txq) {
     157                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "bnxt_tx_queue allocation failed!");
     158                 :          0 :                 return -ENOMEM;
     159                 :            :         }
     160                 :            : 
     161                 :          0 :         txq->bp = bp;
     162                 :          0 :         eth_dev->data->tx_queues[queue_idx] = txq;
     163                 :            : 
     164                 :          0 :         txq->free = rte_zmalloc_socket(NULL,
     165                 :            :                                        sizeof(struct rte_mbuf *) * nb_desc,
     166                 :            :                                        RTE_CACHE_LINE_SIZE, socket_id);
     167         [ #  # ]:          0 :         if (!txq->free) {
     168                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "allocation of tx mbuf free array failed!");
     169                 :            :                 rc = -ENOMEM;
     170                 :          0 :                 goto err;
     171                 :            :         }
     172                 :          0 :         txq->nb_tx_desc = nb_desc;
     173                 :          0 :         txq->tx_free_thresh =
     174                 :          0 :                 RTE_MIN(rte_align32pow2(nb_desc) / 4, RTE_BNXT_MAX_TX_BURST);
     175                 :          0 :         txq->offloads = eth_dev->data->dev_conf.txmode.offloads |
     176                 :          0 :                         tx_conf->offloads;
     177                 :            : 
     178                 :          0 :         txq->tx_deferred_start = tx_conf->tx_deferred_start;
     179                 :            : 
     180                 :          0 :         rc = bnxt_init_tx_ring_struct(txq, socket_id);
     181         [ #  # ]:          0 :         if (rc)
     182                 :          0 :                 goto err;
     183                 :            : 
     184                 :          0 :         txq->queue_id = queue_idx;
     185                 :          0 :         txq->port_id = eth_dev->data->port_id;
     186                 :            : 
     187                 :            :         /* Allocate TX ring hardware descriptors */
     188         [ #  # ]:          0 :         if (bnxt_alloc_rings(bp, socket_id, queue_idx, txq, NULL, txq->cp_ring,
     189                 :            :                              NULL, "txr")) {
     190                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "ring_dma_zone_reserve for tx_ring failed!");
     191                 :            :                 rc = -ENOMEM;
     192                 :          0 :                 goto err;
     193                 :            :         }
     194                 :            : 
     195         [ #  # ]:          0 :         if (bnxt_init_one_tx_ring(txq)) {
     196                 :          0 :                 PMD_DRV_LOG_LINE(ERR, "bnxt_init_one_tx_ring failed!");
     197                 :            :                 rc = -ENOMEM;
     198                 :          0 :                 goto err;
     199                 :            :         }
     200                 :            : 
     201                 :          0 :         return pthread_mutex_init(&txq->txq_lock, NULL);
     202                 :          0 : err:
     203                 :          0 :         bnxt_tx_queue_release_op(eth_dev, queue_idx);
     204                 :          0 :         return rc;
     205                 :            : }

Generated by: LCOV version 1.14