LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_txr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 419 0.0 %
Date: 2026-11-01 19:11:22 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 277 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_byteorder.h>
       9                 :            : #include <rte_malloc.h>
      10                 :            : 
      11                 :            : #include "bnxt.h"
      12                 :            : #include "bnxt_hwrm.h"
      13                 :            : #include "bnxt_ring.h"
      14                 :            : #include "bnxt_txq.h"
      15                 :            : #include "bnxt_txr.h"
      16                 :            : #include "hsi_struct_def_dpdk.h"
      17                 :            : #include <stdbool.h>
      18                 :            : 
      19                 :            : /*
      20                 :            :  * TX Ring handling
      21                 :            :  */
      22                 :            : 
      23                 :          0 : void bnxt_free_tx_rings(struct bnxt *bp)
      24                 :            : {
      25                 :            :         int i;
      26                 :            : 
      27   [ #  #  #  # ]:          0 :         if (!bp->tx_queues || !bp->eth_dev->data->tx_queues)
      28                 :            :                 return;
      29                 :            : 
      30         [ #  # ]:          0 :         for (i = 0; i < (int)bp->tx_nr_rings; i++) {
      31                 :          0 :                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
      32                 :            : 
      33         [ #  # ]:          0 :                 if (!txq)
      34                 :          0 :                         continue;
      35                 :            : 
      36                 :          0 :                 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
      37                 :          0 :                 rte_free(txq->tx_ring->tx_ring_struct);
      38                 :          0 :                 rte_free(txq->tx_ring);
      39                 :            : 
      40                 :          0 :                 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
      41                 :          0 :                 rte_free(txq->cp_ring->cp_ring_struct);
      42                 :          0 :                 rte_free(txq->cp_ring);
      43                 :            : 
      44                 :          0 :                 rte_memzone_free(txq->mz);
      45                 :          0 :                 txq->mz = NULL;
      46                 :            : 
      47                 :          0 :                 rte_free(txq);
      48                 :          0 :                 bp->tx_queues[i] = NULL;
      49                 :            :         }
      50                 :            : }
      51                 :            : 
      52                 :          0 : int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq)
      53                 :            : {
      54                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
      55                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
      56                 :            : 
      57                 :          0 :         txq->tx_wake_thresh = ring->ring_size / 2;
      58                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
      59                 :            : 
      60                 :          0 :         return 0;
      61                 :            : }
      62                 :            : 
      63                 :          0 : int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id)
      64                 :            : {
      65                 :            :         struct bnxt_cp_ring_info *cpr;
      66                 :            :         struct bnxt_tx_ring_info *txr;
      67                 :            :         struct bnxt_ring *ring;
      68                 :            : 
      69                 :          0 :         txr = rte_zmalloc_socket("bnxt_tx_ring",
      70                 :            :                                  sizeof(struct bnxt_tx_ring_info),
      71                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
      72         [ #  # ]:          0 :         if (txr == NULL)
      73                 :            :                 return -ENOMEM;
      74                 :          0 :         txq->tx_ring = txr;
      75                 :            : 
      76                 :          0 :         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
      77                 :            :                                   sizeof(struct bnxt_ring),
      78                 :            :                                   RTE_CACHE_LINE_SIZE, socket_id);
      79         [ #  # ]:          0 :         if (ring == NULL)
      80                 :            :                 return -ENOMEM;
      81                 :          0 :         txr->tx_ring_struct = ring;
      82                 :          0 :         ring->ring_size = rte_align32pow2(txq->nb_tx_desc);
      83                 :          0 :         ring->ring_mask = ring->ring_size - 1;
      84                 :          0 :         ring->bd = (void *)txr->tx_desc_ring;
      85                 :          0 :         ring->bd_dma = txr->tx_desc_mapping;
      86                 :          0 :         ring->vmem_size = ring->ring_size * sizeof(struct rte_mbuf *);
      87                 :          0 :         ring->vmem = (void **)&txr->tx_buf_ring;
      88                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
      89                 :            : 
      90                 :          0 :         cpr = rte_zmalloc_socket("bnxt_tx_ring",
      91                 :            :                                  sizeof(struct bnxt_cp_ring_info),
      92                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
      93         [ #  # ]:          0 :         if (cpr == NULL)
      94                 :            :                 return -ENOMEM;
      95                 :          0 :         txq->cp_ring = cpr;
      96                 :            : 
      97                 :          0 :         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
      98                 :            :                                   sizeof(struct bnxt_ring),
      99                 :            :                                   RTE_CACHE_LINE_SIZE, socket_id);
     100         [ #  # ]:          0 :         if (ring == NULL)
     101                 :            :                 return -ENOMEM;
     102                 :          0 :         cpr->cp_ring_struct = ring;
     103                 :          0 :         ring->ring_size = txr->tx_ring_struct->ring_size;
     104                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     105                 :          0 :         ring->bd = (void *)cpr->cp_desc_ring;
     106                 :          0 :         ring->bd_dma = cpr->cp_desc_mapping;
     107                 :          0 :         ring->vmem_size = 0;
     108                 :          0 :         ring->vmem = NULL;
     109                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     110                 :            : 
     111                 :          0 :         return 0;
     112                 :            : }
     113                 :            : 
     114                 :            : static bool
     115                 :            : bnxt_xmit_need_long_bd(struct rte_mbuf *tx_pkt, struct bnxt_tx_queue *txq)
     116                 :            : {
     117         [ #  # ]:          0 :         if (tx_pkt->ol_flags & (RTE_MBUF_F_TX_TCP_SEG |
     118                 :            :                                 RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_OUTER_IP_CKSUM |
     119                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GRE | RTE_MBUF_F_TX_TUNNEL_VXLAN |
     120                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GENEVE | RTE_MBUF_F_TX_IEEE1588_TMST |
     121                 :            :                                 RTE_MBUF_F_TX_QINQ | RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE |
     122                 :          0 :                                 RTE_MBUF_F_TX_UDP_SEG) ||
     123   [ #  #  #  #  :          0 :              (BNXT_TRUFLOW_EN(txq->bp) &&
          #  #  #  #  #  
                #  #  # ]
     124   [ #  #  #  #  :          0 :               (txq->bp->tx_cfa_action || txq->vfr_tx_cfa_action)))
          #  #  #  #  #  
                #  #  # ]
     125                 :          0 :                 return true;
     126                 :            :         return false;
     127                 :            : }
     128                 :            : 
     129                 :            : /* Used for verifying TSO segments during TCP Segmentation Offload or
     130                 :            :  * UDP Fragmentation Offload. tx_pkt->tso_segsz stores the number of
     131                 :            :  * segments or fragments in those cases.
     132                 :            :  */
     133                 :            : static bool
     134                 :          0 : bnxt_zero_data_len_tso_segsz(struct rte_mbuf *tx_pkt, bool data_len_chk, bool tso_segsz_check)
     135                 :            : {
     136                 :            :         const char *type_str;
     137                 :            : 
     138                 :            :         /* Minimum TSO seg_size should be 4 */
     139   [ #  #  #  # ]:          0 :         if (tso_segsz_check && tx_pkt->tso_segsz < 4) {
     140                 :            :                 type_str = "Unsupported TSO Seg size";
     141                 :          0 :                 goto dump_pkt;
     142                 :            :         }
     143                 :            : 
     144   [ #  #  #  # ]:          0 :         if (data_len_chk && tx_pkt->data_len == 0) {
     145                 :            :                 type_str = "Data len == 0";
     146                 :          0 :                 goto dump_pkt;
     147                 :            :         }
     148                 :            :         return false;
     149                 :          0 : dump_pkt:
     150                 :          0 :         PMD_DRV_LOG_LINE(ERR, "Error! Tx pkt %s == 0", type_str);
     151                 :          0 :         rte_pktmbuf_dump(stdout, tx_pkt, 64);
     152                 :          0 :         rte_dump_stack();
     153                 :          0 :         return true;
     154                 :            : }
     155                 :            : 
     156                 :            : static bool
     157         [ #  # ]:          0 : bnxt_check_pkt_needs_ts(struct rte_mbuf *m)
     158                 :            : {
     159                 :            :         const struct rte_ether_hdr *eth_hdr;
     160                 :            :         struct rte_ether_hdr _eth_hdr;
     161                 :            :         uint16_t eth_type, proto;
     162                 :            :         uint32_t off = 0;
     163                 :            :         /*
     164                 :            :          * Check that the received packet is a eCPRI packet
     165                 :            :          */
     166                 :            :         eth_hdr = rte_pktmbuf_read(m, off, sizeof(_eth_hdr), &_eth_hdr);
     167         [ #  # ]:          0 :         eth_type = rte_be_to_cpu_16(eth_hdr->ether_type);
     168                 :            :         off += sizeof(*eth_hdr);
     169         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_ECPRI)
     170                 :            :                 return true;
     171                 :            :         /* Check for single tagged and double tagged VLANs */
     172         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_VLAN) {
     173                 :            :                 const struct rte_vlan_hdr *vh;
     174                 :            :                 struct rte_vlan_hdr vh_copy;
     175                 :            : 
     176                 :            :                 vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     177         [ #  # ]:          0 :                 if (unlikely(vh == NULL))
     178                 :          0 :                         return false;
     179                 :            :                 off += sizeof(*vh);
     180         [ #  # ]:          0 :                 proto = rte_be_to_cpu_16(vh->eth_proto);
     181         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_ECPRI)
     182                 :            :                         return true;
     183         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_VLAN) {
     184                 :            :                         const struct rte_vlan_hdr *vh;
     185                 :            :                         struct rte_vlan_hdr vh_copy;
     186                 :            : 
     187                 :            :                         vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     188         [ #  # ]:          0 :                         if (unlikely(vh == NULL))
     189                 :          0 :                                 return false;
     190                 :            :                         off += sizeof(*vh);
     191         [ #  # ]:          0 :                         proto = rte_be_to_cpu_16(vh->eth_proto);
     192         [ #  # ]:          0 :                         if (proto == RTE_ETHER_TYPE_ECPRI)
     193                 :            :                                 return true;
     194                 :            :                 }
     195                 :            :         }
     196                 :            :         return false;
     197                 :            : }
     198                 :            : 
     199                 :            : static bool
     200                 :            : bnxt_invalid_nb_segs(struct rte_mbuf *tx_pkt)
     201                 :            : {
     202                 :            :         uint16_t nb_segs = 1;
     203                 :            :         struct rte_mbuf *m_seg;
     204                 :            : 
     205                 :          0 :         m_seg = tx_pkt->next;
     206         [ #  # ]:          0 :         while (m_seg) {
     207                 :          0 :                 nb_segs++;
     208                 :          0 :                 m_seg = m_seg->next;
     209                 :            :         }
     210                 :            : 
     211                 :          0 :         return (nb_segs != tx_pkt->nb_segs);
     212                 :            : }
     213                 :            : 
     214                 :          0 : static int bnxt_invalid_mbuf(struct rte_mbuf *mbuf)
     215                 :            : {
     216                 :          0 :         uint32_t mbuf_size = sizeof(struct rte_mbuf) + mbuf->priv_size;
     217                 :            :         const char *reason;
     218                 :            : 
     219   [ #  #  #  # ]:          0 :         if (unlikely(rte_eal_iova_mode() != RTE_IOVA_VA &&
     220                 :            :                      rte_eal_iova_mode() != RTE_IOVA_PA))
     221                 :            :                 return 0;
     222                 :            : 
     223         [ #  # ]:          0 :         if (unlikely(rte_mbuf_check(mbuf, 1, &reason)))
     224                 :            :                 return -EINVAL;
     225                 :            : 
     226         [ #  # ]:          0 :         if (unlikely(mbuf->ol_flags & RTE_MBUF_F_EXTERNAL))
     227                 :            :                 return 0;
     228                 :            : 
     229   [ #  #  #  # ]:          0 :         if (unlikely((mbuf->buf_iova < mbuf_size ||
     230                 :            :                       (mbuf->buf_iova != rte_mempool_virt2iova(mbuf) + mbuf_size))))
     231                 :          0 :                 return -EINVAL;
     232                 :            : 
     233                 :            :         return 0;
     234                 :            : }
     235                 :            : 
     236                 :          0 : static int bnxt_start_xmit(struct rte_mbuf *tx_pkt,
     237                 :            :                                 struct bnxt_tx_queue *txq,
     238                 :            :                                 uint16_t *coal_pkts,
     239                 :            :                                 struct tx_bd_long **last_txbd)
     240                 :            : {
     241                 :          0 :         struct tx_bd_long *last_txbd_save = *last_txbd;
     242                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     243                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     244                 :          0 :         uint16_t tx_raw_prod_save = txr->tx_raw_prod;
     245                 :            :         uint32_t outer_tpid_bd = 0;
     246                 :            :         struct tx_bd_long *txbd;
     247                 :            :         struct tx_bd_long_hi *txbd1 = NULL;
     248                 :            :         uint32_t vlan_tag_flags;
     249                 :            :         bool long_bd = false;
     250                 :            :         unsigned short nr_bds;
     251                 :            :         uint16_t prod, idx;
     252                 :            :         bool pkt_needs_ts = 0;
     253                 :            :         struct rte_mbuf *m_seg;
     254                 :            :         struct rte_mbuf **tx_buf;
     255                 :            :         static const uint32_t lhint_arr[4] = {
     256                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT512,
     257                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT1K,
     258                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K,
     259                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K
     260                 :            :         };
     261                 :            :         int rc = 0;
     262                 :            : 
     263         [ #  # ]:          0 :         if (unlikely(is_bnxt_in_error(txq->bp))) {
     264                 :            :                 rc = -EIO;
     265                 :          0 :                 goto ret;
     266                 :            :         }
     267                 :            : 
     268         [ #  # ]:          0 :         if (unlikely(bnxt_invalid_mbuf(tx_pkt))) {
     269                 :            :                 rc = -EINVAL;
     270                 :          0 :                 goto drop;
     271                 :            :         }
     272                 :            : 
     273         [ #  # ]:          0 :         if (unlikely(bnxt_invalid_nb_segs(tx_pkt))) {
     274                 :            :                 rc = -EINVAL;
     275                 :          0 :                 goto drop;
     276                 :            :         }
     277                 :            : 
     278                 :            :         long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq);
     279                 :          0 :         nr_bds = long_bd + tx_pkt->nb_segs;
     280                 :            : 
     281         [ #  # ]:          0 :         if (unlikely(bnxt_tx_avail(txq) < nr_bds)) {
     282                 :            :                 rc = -ENOMEM;
     283                 :          0 :                 goto ret;
     284                 :            :         }
     285                 :            : 
     286                 :            :         /* Check if number of Tx descriptors is above HW limit */
     287         [ #  # ]:          0 :         if (unlikely(nr_bds > BNXT_MAX_TSO_SEGS)) {
     288                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
     289                 :            :                             "Num descriptors %d exceeds HW limit", nr_bds);
     290                 :            :                 rc = -EINVAL;
     291                 :          0 :                 goto drop;
     292                 :            :         }
     293                 :            : 
     294                 :            :         /* If packet length is less than minimum packet size, pad it */
     295         [ #  # ]:          0 :         if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) {
     296                 :          0 :                 uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt);
     297                 :          0 :                 char *seg = rte_pktmbuf_append(tx_pkt, pad);
     298                 :            : 
     299         [ #  # ]:          0 :                 if (!seg) {
     300                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
     301                 :            :                                     "Failed to pad mbuf by %d bytes",
     302                 :            :                                     pad);
     303                 :            :                         rc = -ENOMEM;
     304                 :          0 :                         goto ret;
     305                 :            :                 }
     306                 :            : 
     307                 :            :                 /* Note: data_len, pkt len are updated in rte_pktmbuf_append */
     308                 :          0 :                 memset(seg, 0, pad);
     309                 :            :         }
     310                 :            : 
     311                 :            :         /* Check non zero data_len */
     312         [ #  # ]:          0 :         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, true, false))) {
     313                 :            :                 rc = -EINVAL;
     314                 :          0 :                 goto drop;
     315                 :            :         }
     316                 :            : 
     317   [ #  #  #  # ]:          0 :         if (unlikely(txq->bp->ptp_cfg != NULL && txq->bp->ptp_all_rx_tstamp == 1))
     318                 :          0 :                 pkt_needs_ts = bnxt_check_pkt_needs_ts(tx_pkt);
     319                 :            : 
     320                 :          0 :         prod = RING_IDX(ring, txr->tx_raw_prod);
     321                 :          0 :         tx_buf = &txr->tx_buf_ring[prod];
     322                 :          0 :         *tx_buf = tx_pkt;
     323                 :          0 :         txr->nr_bds[prod] = nr_bds;
     324                 :            : 
     325                 :          0 :         txbd = &txr->tx_desc_ring[prod];
     326                 :          0 :         txbd->opaque = *coal_pkts;
     327                 :          0 :         txbd->flags_type = nr_bds << TX_BD_LONG_FLAGS_BD_CNT_SFT;
     328                 :          0 :         txbd->flags_type |= TX_BD_SHORT_FLAGS_COAL_NOW;
     329                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_NO_CMPL;
     330                 :          0 :         txbd->len = tx_pkt->data_len;
     331         [ #  # ]:          0 :         if (tx_pkt->pkt_len >= 2048)
     332                 :          0 :                 txbd->flags_type |= TX_BD_LONG_FLAGS_LHINT_GTE2K;
     333                 :            :         else
     334                 :          0 :                 txbd->flags_type |= lhint_arr[tx_pkt->pkt_len >> 9];
     335         [ #  # ]:          0 :         if (tx_pkt->ol_flags & RTE_MBUF_F_EXTERNAL)
     336                 :          0 :                 txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(tx_pkt, uint64_t, 0));
     337                 :            :         else
     338                 :          0 :                 txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(tx_pkt));
     339                 :          0 :         *last_txbd = txbd;
     340                 :            : 
     341         [ #  # ]:          0 :         if (long_bd) {
     342                 :          0 :                 txbd->flags_type |= TX_BD_LONG_TYPE_TX_BD_LONG;
     343                 :            :                 vlan_tag_flags = 0;
     344                 :            : 
     345                 :            :                 /* HW can accelerate only outer vlan in QinQ mode */
     346         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_QINQ) {
     347                 :          0 :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     348                 :          0 :                                 tx_pkt->vlan_tci_outer;
     349                 :          0 :                         outer_tpid_bd = txq->bp->outer_tpid_bd &
     350                 :            :                                 BNXT_OUTER_TPID_BD_MASK;
     351                 :          0 :                         vlan_tag_flags |= outer_tpid_bd;
     352         [ #  # ]:          0 :                 } else if (tx_pkt->ol_flags & RTE_MBUF_F_TX_VLAN) {
     353                 :            :                         /* shurd: Should this mask at
     354                 :            :                          * TX_BD_LONG_CFA_META_VLAN_VID_MASK?
     355                 :            :                          */
     356                 :            :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     357                 :          0 :                                 tx_pkt->vlan_tci;
     358                 :            :                         /* Currently supports 8021Q, 8021AD vlan offloads
     359                 :            :                          * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
     360                 :            :                          */
     361                 :            :                         /* DPDK only supports 802.11q VLAN packets */
     362                 :          0 :                         vlan_tag_flags |=
     363                 :            :                                         TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
     364                 :            :                 }
     365                 :            : 
     366                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     367                 :            : 
     368                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     369                 :          0 :                 txbd1 = (struct tx_bd_long_hi *)&txr->tx_desc_ring[prod];
     370                 :          0 :                 txbd1->lflags = 0;
     371                 :          0 :                 txbd1->cfa_meta = vlan_tag_flags;
     372                 :            :                 /* Legacy tx_bd_long_hi->mss =
     373                 :            :                  * tx_bd_long_hi->kid_or_ts_high_mss
     374                 :            :                  */
     375                 :          0 :                 txbd1->kid_or_ts_high_mss = 0;
     376                 :            : 
     377         [ #  # ]:          0 :                 if (txq->vfr_tx_cfa_action) {
     378                 :          0 :                         txbd1->cfa_action = txq->vfr_tx_cfa_action & 0xffff;
     379                 :          0 :                         txbd1->cfa_action_high = (txq->vfr_tx_cfa_action >> 16) &
     380                 :            :                                 TX_BD_LONG_CFA_ACTION_HIGH_MASK;
     381                 :            :                 } else {
     382                 :          0 :                         txbd1->cfa_action = txq->bp->tx_cfa_action & 0xffff;
     383                 :          0 :                         txbd1->cfa_action_high = (txq->bp->tx_cfa_action >> 16) &
     384                 :            :                                 TX_BD_LONG_CFA_ACTION_HIGH_MASK;
     385                 :            :                 }
     386                 :            : 
     387         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_SEG ||
     388                 :            :                     tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_SEG) {
     389                 :            :                         uint16_t hdr_size;
     390                 :            : 
     391                 :            :                         /* TSO */
     392                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO |
     393                 :            :                                          TX_BD_LONG_LFLAGS_T_IPID |
     394                 :            :                                          TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM |
     395                 :            :                                          TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
     396                 :          0 :                         hdr_size = tx_pkt->l2_len + tx_pkt->l3_len +
     397                 :          0 :                                         tx_pkt->l4_len;
     398         [ #  # ]:          0 :                         hdr_size += (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
     399                 :          0 :                                     tx_pkt->outer_l2_len +
     400                 :          0 :                                     tx_pkt->outer_l3_len : 0;
     401                 :            :                         /* The hdr_size is multiple of 16bit units not 8bit.
     402                 :            :                          * Hence divide by 2.
     403                 :            :                          * Also legacy hdr_size = kid_or_ts_low_hdr_size.
     404                 :            :                          */
     405                 :          0 :                         txbd1->kid_or_ts_low_hdr_size = hdr_size >> 1;
     406                 :          0 :                         txbd1->kid_or_ts_high_mss = tx_pkt->tso_segsz;
     407         [ #  # ]:          0 :                         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, false, true))) {
     408                 :            :                                 rc = -EINVAL;
     409                 :          0 :                                 goto drop;
     410                 :            :                         }
     411                 :            : 
     412         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_CKSUM) ==
     413                 :          0 :                            PKT_TX_OIP_IIP_TCP_CKSUM ||
     414         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_OIP_IIP_UDP_CKSUM) ==
     415                 :            :                            PKT_TX_OIP_IIP_UDP_CKSUM) {
     416                 :            :                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
     417                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
     418         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_CKSUM) ==
     419                 :          0 :                            PKT_TX_IIP_TCP_CKSUM ||
     420         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_IIP_UDP_CKSUM) ==
     421                 :            :                            PKT_TX_IIP_UDP_CKSUM) {
     422                 :            :                         /* (Inner) IP, (Inner) TCP/UDP CSO */
     423                 :          0 :                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
     424         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_CKSUM) ==
     425                 :          0 :                            PKT_TX_OIP_TCP_CKSUM ||
     426         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_OIP_UDP_CKSUM) ==
     427                 :            :                            PKT_TX_OIP_UDP_CKSUM) {
     428                 :            :                         /* Outer IP, (Inner) TCP/UDP CSO */
     429                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
     430         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_CKSUM) ==
     431                 :            :                            PKT_TX_OIP_IIP_CKSUM) {
     432                 :            :                         /* Outer IP, Inner IP CSO */
     433                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_CHKSUM;
     434         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_CKSUM) ==
     435                 :          0 :                            RTE_MBUF_F_TX_TCP_CKSUM ||
     436         [ #  # ]:          0 :                            (tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_CKSUM) ==
     437                 :            :                            RTE_MBUF_F_TX_UDP_CKSUM) {
     438                 :            :                         /* TCP/UDP CSO */
     439                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
     440         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) ==
     441                 :            :                            RTE_MBUF_F_TX_IP_CKSUM) {
     442                 :            :                         /* IP CSO */
     443                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_IP_CHKSUM;
     444         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ==
     445                 :            :                            RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
     446                 :            :                         /* IP CSO */
     447                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
     448         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) ==
     449         [ #  # ]:          0 :                            RTE_MBUF_F_TX_IEEE1588_TMST || pkt_needs_ts) {
     450                 :            :                         /* PTP */
     451                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_STAMP;
     452                 :            :                 }
     453                 :            :         } else {
     454                 :          0 :                 txbd->flags_type |= TX_BD_SHORT_TYPE_TX_BD_SHORT;
     455                 :            :         }
     456                 :            : 
     457                 :          0 :         m_seg = tx_pkt->next;
     458         [ #  # ]:          0 :         while (m_seg) {
     459                 :            :                 /* Check non zero data_len */
     460         [ #  # ]:          0 :                 if (unlikely(bnxt_zero_data_len_tso_segsz(m_seg, true, false))) {
     461                 :            :                         rc = -EINVAL;
     462                 :          0 :                         goto drop;
     463                 :            :                 }
     464                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     465                 :            : 
     466                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     467                 :          0 :                 tx_buf = &txr->tx_buf_ring[prod];
     468                 :          0 :                 *tx_buf = m_seg;
     469                 :            : 
     470                 :          0 :                 txbd = &txr->tx_desc_ring[prod];
     471         [ #  # ]:          0 :                 if (m_seg->ol_flags & RTE_MBUF_F_EXTERNAL)
     472                 :          0 :                         txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(m_seg,
     473                 :            :                                                                                  uint64_t,
     474                 :            :                                                                                  0));
     475                 :            :                 else
     476                 :          0 :                         txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(m_seg));
     477                 :          0 :                 txbd->flags_type = TX_BD_SHORT_TYPE_TX_BD_SHORT;
     478                 :          0 :                 txbd->len = m_seg->data_len;
     479                 :            : 
     480                 :          0 :                 m_seg = m_seg->next;
     481                 :            :         }
     482                 :            : 
     483                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_PACKET_END;
     484                 :            : 
     485                 :          0 :         txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     486                 :            : 
     487                 :          0 :         return 0;
     488                 :            : drop:
     489                 :            :         /* Roll back any descriptors and tx_buf_ring slots that were written
     490                 :            :          * for this packet before the failure was detected.  Walking from the
     491                 :            :          * saved producer index up to (but not including) the current one is
     492                 :            :          * safe because we hold the Tx lock and the HW has not been notified
     493                 :            :          * (the doorbell is only rung after bnxt_start_xmit() returns
     494                 :            :          * successfully).
     495                 :            :          */
     496                 :            :         idx = tx_raw_prod_save;
     497                 :            : 
     498         [ #  # ]:          0 :         while (idx != txr->tx_raw_prod) {
     499                 :          0 :                 uint16_t slot = RING_IDX(ring, idx);
     500                 :            : 
     501                 :          0 :                 txr->tx_buf_ring[slot] = NULL;
     502                 :          0 :                 txr->tx_desc_ring[slot].address = 0;
     503                 :          0 :                 idx = RING_NEXT(idx);
     504                 :            :         }
     505                 :          0 :         txr->tx_raw_prod = tx_raw_prod_save;
     506                 :          0 :         *last_txbd = last_txbd_save;
     507                 :          0 :         rte_pktmbuf_free(tx_pkt);
     508                 :            : ret:
     509                 :            :         return rc;
     510                 :            : }
     511                 :            : 
     512                 :          0 : static void bnxt_tx_coal_cmp_fast(struct bnxt_tx_queue *txq, int nr_cons)
     513                 :            : {
     514                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     515                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     516                 :          0 :         struct rte_mbuf **free = txq->free;
     517                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     518                 :            :         unsigned int blk = 0;
     519                 :            :         int cons, bds;
     520                 :            : 
     521         [ #  # ]:          0 :         for (cons = 0; cons < nr_cons; cons++) {
     522                 :            :                 struct rte_mbuf **tx_buf;
     523                 :            :                 unsigned short nr_bds;
     524                 :            : 
     525                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     526         [ #  # ]:          0 :                 nr_bds = (*tx_buf)->nb_segs +
     527                 :          0 :                          bnxt_xmit_need_long_bd(*tx_buf, txq);
     528         [ #  # ]:          0 :                 for (bds = 0; bds < nr_bds; bds++) {
     529         [ #  # ]:          0 :                         if (*tx_buf) {
     530                 :          0 :                                 free[blk++] = *tx_buf;
     531                 :            :                                 /*
     532                 :            :                                  * Each BD also tracks a consumer index.
     533                 :            :                                  * Update cons, otherwise it will fall behind.
     534                 :            :                                  */
     535                 :          0 :                                 cons++;
     536                 :          0 :                                 *tx_buf = NULL;
     537                 :            :                         }
     538                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     539                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     540                 :            :                 }
     541                 :            :         }
     542         [ #  # ]:          0 :         if (blk)
     543         [ #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
     544                 :            : 
     545                 :          0 :         txr->tx_raw_cons = raw_cons;
     546                 :          0 : }
     547                 :            : 
     548                 :            : /*
     549                 :            :  * Transmit completion function for use when RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
     550                 :            :  * is enabled.
     551                 :            :  */
     552                 :          0 : static void bnxt_tx_cmp_fast(struct bnxt_tx_queue *txq, int nb_tx,
     553                 :            :                               bool tx_coal_cmp)
     554                 :            : {
     555                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     556                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     557                 :          0 :         struct rte_mbuf **free = txq->free;
     558                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     559                 :            :         unsigned int blk = 0;
     560                 :            :         int i, j;
     561                 :            : 
     562         [ #  # ]:          0 :         if (tx_coal_cmp)
     563                 :          0 :                 return bnxt_tx_coal_cmp_fast(txq, nb_tx);
     564                 :            : 
     565         [ #  # ]:          0 :         for (i = 0; i < nb_tx; i++) {
     566                 :            :                 struct rte_mbuf **tx_buf;
     567                 :            :                 unsigned short nr_bds;
     568                 :            : 
     569                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     570         [ #  # ]:          0 :                 nr_bds = (*tx_buf)->nb_segs +
     571                 :          0 :                          bnxt_xmit_need_long_bd(*tx_buf, txq);
     572         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     573         [ #  # ]:          0 :                         if (*tx_buf) {
     574                 :            :                                 /* Add mbuf to the bulk free array */
     575                 :          0 :                                 free[blk++] = *tx_buf;
     576                 :          0 :                                 *tx_buf = NULL;
     577                 :            :                         }
     578                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     579                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     580                 :            :                 }
     581                 :            :         }
     582         [ #  # ]:          0 :         if (blk)
     583         [ #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
     584                 :            : 
     585                 :          0 :         txr->tx_raw_cons = raw_cons;
     586                 :            : }
     587                 :            : 
     588                 :          0 : static void bnxt_tx_coal_cmp(struct bnxt_tx_queue *txq, int nr_cons)
     589                 :            : {
     590                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     591                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     592                 :            :         struct rte_mempool *pool = NULL;
     593                 :          0 :         struct rte_mbuf **free = txq->free;
     594                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     595                 :            :         unsigned int blk = 0;
     596                 :            :         int cons, bds;
     597                 :            : 
     598         [ #  # ]:          0 :         for (cons = 0; cons < nr_cons; cons++) {
     599                 :            :                 struct rte_mbuf *mbuf;
     600                 :            :                 struct rte_mbuf **tx_buf;
     601                 :            :                 unsigned short nr_bds;
     602                 :            : 
     603                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     604                 :          0 :                 nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
     605                 :            :                 /* Clear the now stale number of buffer descriptors */
     606                 :          0 :                 txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
     607                 :            : 
     608         [ #  # ]:          0 :                 for (bds = 0; bds < nr_bds; bds++) {
     609                 :          0 :                         mbuf = *tx_buf;
     610                 :          0 :                         *tx_buf = NULL;
     611                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     612                 :            :                         /*
     613                 :            :                          * Each BD also tracks a consumer index. So update the cons.
     614                 :            :                          * Otherwise the cons will fall behind.
     615                 :            :                          */
     616                 :          0 :                         cons++;
     617                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     618         [ #  # ]:          0 :                         if (!mbuf)      /* long_bd's tx_buf ? */
     619                 :          0 :                                 continue;
     620                 :            : 
     621                 :            :                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
     622         [ #  # ]:          0 :                         if (unlikely(!mbuf))
     623                 :          0 :                                 continue;
     624                 :            : 
     625                 :            :                         /* EW - no need to unmap DMA memory? */
     626                 :            : 
     627         [ #  # ]:          0 :                         if (likely(mbuf->pool == pool)) {
     628                 :            :                                 /* Add mbuf to the bulk free array */
     629                 :          0 :                                 free[blk++] = mbuf;
     630                 :            :                         } else {
     631                 :            :                                 /* Found an mbuf from a different pool. Free
     632                 :            :                                  * mbufs accumulated so far to the previous
     633                 :            :                                  * pool
     634                 :            :                                  */
     635         [ #  # ]:          0 :                                 if (likely(pool != NULL))
     636                 :            :                                         rte_mempool_put_bulk(pool,
     637                 :            :                                                              (void *)free,
     638                 :            :                                                              blk);
     639                 :            : 
     640                 :            :                                 /* Start accumulating mbufs in a new pool */
     641                 :          0 :                                 free[0] = mbuf;
     642                 :          0 :                                 pool = mbuf->pool;
     643                 :            :                                 blk = 1;
     644                 :            :                         }
     645                 :            :                 }
     646                 :            :         }
     647         [ #  # ]:          0 :         if (blk)
     648                 :            :                 rte_mempool_put_bulk(pool, (void *)free, blk);
     649                 :            : 
     650                 :          0 :         txr->tx_raw_cons = raw_cons;
     651                 :          0 : }
     652                 :            : 
     653                 :          0 : static void bnxt_tx_cmp(struct bnxt_tx_queue *txq, int nb_tx, bool tx_coal_cmp)
     654                 :            : {
     655                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     656                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     657                 :            :         struct rte_mempool *pool = NULL;
     658                 :          0 :         struct rte_mbuf **free = txq->free;
     659                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     660                 :            :         unsigned int blk = 0;
     661                 :            :         int i, j;
     662                 :            : 
     663         [ #  # ]:          0 :         if (tx_coal_cmp)
     664                 :          0 :                 return bnxt_tx_coal_cmp(txq, nb_tx);
     665                 :            : 
     666         [ #  # ]:          0 :         for (i = 0; i < nb_tx; i++) {
     667                 :            :                 struct rte_mbuf *mbuf;
     668                 :            :                 struct rte_mbuf **tx_buf;
     669                 :            :                 unsigned short nr_bds;
     670                 :            : 
     671                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     672                 :          0 :                 nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
     673                 :            :                 /* Clear the now stale number of buffer descriptors */
     674                 :          0 :                 txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
     675                 :            : 
     676         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     677                 :          0 :                         mbuf = *tx_buf;
     678                 :          0 :                         *tx_buf = NULL;
     679                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     680                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     681         [ #  # ]:          0 :                         if (!mbuf)      /* long_bd's tx_buf ? */
     682                 :          0 :                                 continue;
     683                 :            : 
     684                 :            :                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
     685         [ #  # ]:          0 :                         if (unlikely(!mbuf))
     686                 :          0 :                                 continue;
     687                 :            : 
     688                 :            :                         /* EW - no need to unmap DMA memory? */
     689                 :            : 
     690         [ #  # ]:          0 :                         if (likely(mbuf->pool == pool)) {
     691                 :            :                                 /* Add mbuf to the bulk free array */
     692                 :          0 :                                 free[blk++] = mbuf;
     693                 :            :                         } else {
     694                 :            :                                 /* Found an mbuf from a different pool. Free
     695                 :            :                                  * mbufs accumulated so far to the previous
     696                 :            :                                  * pool
     697                 :            :                                  */
     698         [ #  # ]:          0 :                                 if (likely(pool != NULL))
     699                 :            :                                         rte_mempool_put_bulk(pool,
     700                 :            :                                                              (void *)free,
     701                 :            :                                                              blk);
     702                 :            : 
     703                 :            :                                 /* Start accumulating mbufs in a new pool */
     704                 :          0 :                                 free[0] = mbuf;
     705                 :          0 :                                 pool = mbuf->pool;
     706                 :            :                                 blk = 1;
     707                 :            :                         }
     708                 :            :                 }
     709                 :            :         }
     710         [ #  # ]:          0 :         if (blk)
     711                 :            :                 rte_mempool_put_bulk(pool, (void *)free, blk);
     712                 :            : 
     713                 :          0 :         txr->tx_raw_cons = raw_cons;
     714                 :            : }
     715                 :            : 
     716                 :            : static bool bnxt_is_tx_cmpl_type(uint16_t type)
     717                 :            : {
     718                 :            :         return (type == CMPL_BASE_TYPE_TX_L2_PKT_TS ||
     719                 :          0 :                 type == CMPL_BASE_TYPE_TX_L2_COAL ||
     720                 :            :                 type == CMPL_BASE_TYPE_TX_L2);
     721                 :            : }
     722                 :            : 
     723                 :            : static void bnxt_get_tx_ts_p7(struct bnxt *bp, struct tx_cmpl_packet_timestamp *txcmp)
     724                 :            : {
     725                 :            :         uint64_t tx_timestamp;
     726                 :            : 
     727                 :          0 :         if (!(bp->fw_cap & BNXT_FW_CAP_TX_TS_CMP))
     728                 :            :                 return;
     729                 :            : 
     730   [ #  #  #  # ]:          0 :         if (!bp->ptp_cfg || !bp->ieee_1588)
     731                 :            :                 return;
     732                 :            : 
     733                 :          0 :         tx_timestamp = rte_le_to_cpu_16(txcmp->ts_ns_mid);
     734                 :          0 :         bp->ptp_cfg->tx_timestamp = (tx_timestamp << 32) | rte_le_to_cpu_32(txcmp->ts_ns_lo);
     735                 :            : }
     736                 :            : 
     737                 :          0 : static int bnxt_handle_tx_cp(struct bnxt_tx_queue *txq)
     738                 :            : {
     739                 :            :         uint32_t nb_tx_pkts = 0, cons, ring_mask, opaque;
     740                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
     741         [ #  # ]:          0 :         uint32_t raw_cons = cpr->cp_raw_cons;
     742                 :            :         struct bnxt_ring *cp_ring_struct;
     743                 :            :         uint32_t tx_ring_mask;
     744                 :            :         bool tx_coal_cmp = false;
     745                 :            :         struct tx_cmpl *txcmp;
     746                 :            : 
     747         [ #  # ]:          0 :         if (bnxt_tx_bds_in_hw(txq) < txq->tx_free_thresh)
     748                 :            :                 return 0;
     749                 :            : 
     750                 :          0 :         cp_ring_struct = cpr->cp_ring_struct;
     751                 :          0 :         ring_mask = cp_ring_struct->ring_mask;
     752                 :            :         tx_ring_mask = txq->tx_ring->tx_ring_struct->ring_mask;
     753                 :            : 
     754                 :            :         do {
     755                 :          0 :                 cons = RING_CMPL(ring_mask, raw_cons);
     756                 :          0 :                 txcmp = (struct tx_cmpl *)&cpr->cp_desc_ring[cons];
     757                 :            : 
     758         [ #  # ]:          0 :                 if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
     759                 :            :                         break;
     760                 :            : 
     761                 :          0 :                 uint16_t errors_v = rte_le_to_cpu_16(txcmp->errors_v);
     762                 :            : 
     763         [ #  # ]:          0 :                 if (unlikely(errors_v & TX_CMPL_ERRORS_DMA_ERROR))
     764                 :          0 :                         rte_atomic_store_explicit(&txq->tx_dma_err,
     765                 :            :                                 rte_atomic_load_explicit(&txq->tx_dma_err,
     766                 :            :                                                          rte_memory_order_relaxed) + 1,
     767                 :            :                                 rte_memory_order_relaxed);
     768                 :            : 
     769         [ #  # ]:          0 :                 if (CMP_TYPE(txcmp) == CMPL_BASE_TYPE_TX_L2_COAL) {
     770                 :            :                         struct tx_cmpl_coal *txcmp_c = (struct tx_cmpl_coal *)txcmp;
     771                 :            : 
     772                 :          0 :                         nb_tx_pkts = (rte_le_to_cpu_32(txcmp_c->sq_cons_idx) -
     773                 :          0 :                                       (txq->tx_ring->tx_raw_cons & tx_ring_mask)) & tx_ring_mask;
     774                 :          0 :                         raw_cons = NEXT_RAW_CMP(raw_cons);
     775                 :            :                         tx_coal_cmp = true;
     776                 :          0 :                         break;
     777                 :            :                 }
     778                 :            : 
     779      [ #  #  # ]:          0 :                 opaque = rte_le_to_cpu_32(txcmp->opaque);
     780                 :            : 
     781         [ #  # ]:          0 :                 if (bnxt_is_tx_cmpl_type(CMP_TYPE(txcmp)))
     782                 :          0 :                         nb_tx_pkts += opaque;
     783                 :            :                 else
     784                 :          0 :                         RTE_LOG_DP_LINE(ERR, BNXT,
     785                 :            :                                         "Unhandled CMP type %02x",
     786                 :            :                                         CMP_TYPE(txcmp));
     787         [ #  # ]:          0 :                 if (CMP_TYPE(txcmp) == CMPL_BASE_TYPE_TX_L2_PKT_TS)
     788         [ #  # ]:          0 :                         bnxt_get_tx_ts_p7(txq->bp, (struct tx_cmpl_packet_timestamp *)txcmp);
     789                 :          0 :                 raw_cons = NEXT_RAW_CMP(raw_cons);
     790         [ #  # ]:          0 :         } while (nb_tx_pkts < ring_mask);
     791                 :            : 
     792         [ #  # ]:          0 :         if (nb_tx_pkts) {
     793         [ #  # ]:          0 :                 if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
     794                 :          0 :                         bnxt_tx_cmp_fast(txq, nb_tx_pkts, tx_coal_cmp);
     795                 :            :                 else
     796                 :          0 :                         bnxt_tx_cmp(txq, nb_tx_pkts, tx_coal_cmp);
     797                 :          0 :                 cpr->cp_raw_cons = raw_cons;
     798                 :          0 :                 bnxt_db_cq(cpr);
     799                 :            :         }
     800                 :            : 
     801                 :          0 :         return nb_tx_pkts;
     802                 :            : }
     803                 :            : 
     804                 :          0 : uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     805                 :            :                                uint16_t nb_pkts)
     806                 :            : {
     807                 :            :         struct bnxt_tx_queue *txq = tx_queue;
     808                 :            :         uint16_t rc;
     809                 :            : 
     810                 :          0 :         pthread_mutex_lock(&txq->txq_lock);
     811                 :          0 :         rc = _bnxt_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
     812                 :          0 :         pthread_mutex_unlock(&txq->txq_lock);
     813                 :            : 
     814                 :          0 :         return rc;
     815                 :            : }
     816                 :            : 
     817                 :          0 : uint16_t _bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     818                 :            :                          uint16_t nb_pkts)
     819                 :            : {
     820                 :            :         int rc;
     821                 :            :         uint16_t nb_tx_pkts = 0;
     822                 :          0 :         uint16_t coal_pkts = 0;
     823                 :            :         struct bnxt_tx_queue *txq = tx_queue;
     824                 :          0 :         struct tx_bd_long *last_txbd = NULL;
     825                 :            :         uint8_t dropped = 0;
     826                 :            : 
     827                 :            :         /* Handle TX completions */
     828                 :          0 :         bnxt_handle_tx_cp(txq);
     829                 :            : 
     830                 :            :         /* Tx queue was stopped; wait for it to be restarted */
     831         [ #  # ]:          0 :         if (unlikely(!txq->tx_started)) {
     832                 :          0 :                 PMD_DRV_LOG_LINE(DEBUG, "Tx q stopped;return");
     833                 :          0 :                 return 0;
     834                 :            :         }
     835                 :            : 
     836                 :            :         /* Handle TX burst request */
     837         [ #  # ]:          0 :         for (nb_tx_pkts = 0; nb_tx_pkts < nb_pkts; nb_tx_pkts++) {
     838                 :          0 :                 coal_pkts++;
     839                 :          0 :                 rc = bnxt_start_xmit(tx_pkts[nb_tx_pkts], txq,
     840                 :            :                                      &coal_pkts, &last_txbd);
     841                 :            : 
     842         [ #  # ]:          0 :                 if (unlikely(rc)) {
     843         [ #  # ]:          0 :                         if (rc == -EINVAL) {
     844                 :          0 :                                 coal_pkts--;
     845                 :          0 :                                 rte_atomic_fetch_add_explicit(&txq->tx_mbuf_drop, 1,
     846                 :            :                                                               rte_memory_order_relaxed);
     847                 :          0 :                                 dropped++;
     848                 :          0 :                                 continue;
     849                 :            :                         }
     850                 :            :                         break;
     851                 :            :                 }
     852                 :            :         }
     853                 :            : 
     854                 :            :         /* last_txbd is used to check for if any packets have been sent in
     855                 :            :          * the burst as bnxt_start_xmit will update it to the most recent
     856                 :            :          * non-dropped buffer descriptor in the burst.
     857                 :            :          */
     858         [ #  # ]:          0 :         if (likely(last_txbd != NULL)) {
     859                 :            :                 /* Request a completion on the last packet */
     860                 :          0 :                 last_txbd->flags_type &= ~TX_BD_LONG_FLAGS_NO_CMPL;
     861         [ #  # ]:          0 :                 bnxt_db_write(&txq->tx_ring->tx_db, txq->tx_ring->tx_raw_prod);
     862                 :            :         }
     863                 :            : 
     864                 :          0 :         return RTE_MIN((uint16_t)(nb_tx_pkts + dropped), nb_pkts);
     865                 :            : 
     866                 :            : }
     867                 :            : 
     868                 :          0 : int bnxt_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     869                 :            : {
     870                 :          0 :         struct bnxt *bp = dev->data->dev_private;
     871                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
     872                 :            :         int rc = 0;
     873                 :            : 
     874                 :          0 :         rc = is_bnxt_in_error(bp);
     875         [ #  # ]:          0 :         if (rc)
     876                 :            :                 return rc;
     877                 :            : 
     878                 :            :         /* reset the previous stats for the tx_queue since the counters
     879                 :            :          * will be cleared when the queue is started.
     880                 :            :          */
     881                 :          0 :         memset(&bp->prev_tx_ring_stats[tx_queue_id], 0,
     882                 :            :                sizeof(struct bnxt_ring_stats));
     883                 :            : 
     884                 :          0 :         bnxt_free_hwrm_tx_ring(bp, tx_queue_id);
     885                 :          0 :         rc = bnxt_alloc_hwrm_tx_ring(bp, tx_queue_id);
     886         [ #  # ]:          0 :         if (rc)
     887                 :            :                 return rc;
     888                 :            : 
     889                 :            :         /* reset the previous stats for the tx_queue since the counters
     890                 :            :          * will be cleared when the queue is started.
     891                 :            :          */
     892   [ #  #  #  # ]:          0 :         if (BNXT_TPA_V2_P7(bp))
     893                 :          0 :                 memset(&bp->prev_tx_ring_stats_ext[tx_queue_id], 0,
     894                 :            :                        sizeof(struct bnxt_ring_stats_ext));
     895                 :            :         else
     896                 :          0 :                 memset(&bp->prev_tx_ring_stats[tx_queue_id], 0,
     897                 :            :                        sizeof(struct bnxt_ring_stats));
     898                 :            : 
     899                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     900                 :          0 :         txq->tx_started = true;
     901                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "Tx queue started");
     902                 :            : 
     903                 :          0 :         return 0;
     904                 :            : }
     905                 :            : 
     906                 :          0 : int bnxt_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     907                 :            : {
     908                 :          0 :         struct bnxt *bp = dev->data->dev_private;
     909                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
     910                 :            :         int rc = 0;
     911                 :            : 
     912                 :          0 :         rc = is_bnxt_in_error(bp);
     913         [ #  # ]:          0 :         if (rc)
     914                 :            :                 return rc;
     915                 :            : 
     916                 :            :         /* Handle TX completions */
     917                 :          0 :         bnxt_handle_tx_cp(txq);
     918                 :            : 
     919                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     920                 :          0 :         txq->tx_started = false;
     921                 :          0 :         PMD_DRV_LOG_LINE(DEBUG, "Tx queue stopped");
     922                 :            : 
     923                 :          0 :         return 0;
     924                 :            : }
     925                 :            : 
     926                 :            : static bool bnxt_is_tx_mpc_flush_cmpl_type(uint16_t type)
     927                 :            : {
     928                 :            :         return (type == CMPL_BASE_TYPE_TX_L2_PKT_TS ||
     929                 :            :                 type == CMPL_BASE_TYPE_TX_L2_COAL ||
     930                 :            :                 type == CMPL_BASE_TYPE_TX_L2 ||
     931                 :          0 :                 type == CMPL_BASE_TYPE_MID_PATH_SHORT ||
     932                 :            :                 type == CMPL_BASE_TYPE_MID_PATH_LONG);
     933                 :            : }
     934                 :            : 
     935                 :            : /* Sweep the Tx completion queue till HWRM_DONE for ring flush is received.
     936                 :            :  * The mbufs will not be freed in this call.
     937                 :            :  * They will be freed during ring free as a part of mem cleanup.
     938                 :            :  */
     939                 :          0 : int bnxt_flush_tx_cmp(struct bnxt_cp_ring_info *cpr)
     940                 :            : {
     941                 :          0 :         uint32_t raw_cons = cpr->cp_raw_cons;
     942                 :            :         uint32_t cons;
     943                 :            :         uint32_t nb_tx_pkts = 0;
     944                 :            :         struct tx_cmpl *txcmp;
     945                 :          0 :         struct cmpl_base *cp_desc_ring = cpr->cp_desc_ring;
     946                 :          0 :         struct bnxt_ring *cp_ring_struct = cpr->cp_ring_struct;
     947                 :          0 :         uint32_t ring_mask = cp_ring_struct->ring_mask;
     948                 :            :         uint32_t opaque = 0;
     949                 :            : 
     950                 :            :         do {
     951                 :          0 :                 cons = RING_CMPL(ring_mask, raw_cons);
     952                 :          0 :                 txcmp = (struct tx_cmpl *)&cp_desc_ring[cons];
     953                 :            : 
     954         [ #  # ]:          0 :                 if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
     955                 :            :                         break;
     956                 :            : 
     957                 :          0 :                 opaque = rte_cpu_to_le_32(txcmp->opaque);
     958                 :          0 :                 raw_cons = NEXT_RAW_CMP(raw_cons);
     959                 :            : 
     960   [ #  #  #  # ]:          0 :                 if (bnxt_is_tx_mpc_flush_cmpl_type(CMP_TYPE(txcmp)))
     961                 :          0 :                         nb_tx_pkts += opaque;
     962         [ #  # ]:          0 :                 else if (CMP_TYPE(txcmp) == HWRM_CMPL_TYPE_HWRM_DONE)
     963                 :            :                         return 1;
     964         [ #  # ]:          0 :         } while (nb_tx_pkts < ring_mask);
     965                 :            : 
     966         [ #  # ]:          0 :         if (nb_tx_pkts) {
     967                 :          0 :                 cpr->cp_raw_cons = raw_cons;
     968                 :          0 :                 bnxt_db_cq(cpr);
     969                 :            :         }
     970                 :            : 
     971                 :            :         return 0;
     972                 :            : }

Generated by: LCOV version 1.14