LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_txr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 420 0.0 %
Date: 2026-12-01 19:01:22 Functions: 0 17 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 274 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 | RTE_MBUF_F_TX_TCP_CKSUM |
     118                 :            :                                 RTE_MBUF_F_TX_UDP_CKSUM | RTE_MBUF_F_TX_IP_CKSUM |
     119                 :            :                                 RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_OUTER_IP_CKSUM |
     120                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GRE | RTE_MBUF_F_TX_TUNNEL_VXLAN |
     121                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GENEVE | RTE_MBUF_F_TX_IEEE1588_TMST |
     122                 :            :                                 RTE_MBUF_F_TX_QINQ | RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE |
     123                 :          0 :                                 RTE_MBUF_F_TX_UDP_SEG) ||
     124   [ #  #  #  #  :          0 :              (BNXT_TRUFLOW_EN(txq->bp) &&
          #  #  #  #  #  
                #  #  # ]
     125   [ #  #  #  #  :          0 :               (txq->bp->tx_cfa_action || txq->vfr_tx_cfa_action)))
          #  #  #  #  #  
                #  #  # ]
     126                 :          0 :                 return true;
     127                 :            :         return false;
     128                 :            : }
     129                 :            : 
     130                 :            : /* Used for verifying TSO segments during TCP Segmentation Offload or
     131                 :            :  * UDP Fragmentation Offload. tx_pkt->tso_segsz stores the number of
     132                 :            :  * segments or fragments in those cases.
     133                 :            :  */
     134                 :            : static bool
     135                 :          0 : bnxt_zero_data_len_tso_segsz(struct rte_mbuf *tx_pkt, bool data_len_chk, bool tso_segsz_check)
     136                 :            : {
     137                 :            :         const char *type_str;
     138                 :            : 
     139                 :            :         /* Minimum TSO seg_size should be 4 */
     140   [ #  #  #  # ]:          0 :         if (tso_segsz_check && tx_pkt->tso_segsz < 4) {
     141                 :            :                 type_str = "Unsupported TSO Seg size";
     142                 :          0 :                 goto dump_pkt;
     143                 :            :         }
     144                 :            : 
     145   [ #  #  #  # ]:          0 :         if (data_len_chk && tx_pkt->data_len == 0) {
     146                 :            :                 type_str = "Data len == 0";
     147                 :          0 :                 goto dump_pkt;
     148                 :            :         }
     149                 :            :         return false;
     150                 :          0 : dump_pkt:
     151                 :          0 :         PMD_DRV_LOG_LINE(ERR, "Error! Tx pkt %s == 0", type_str);
     152                 :          0 :         rte_pktmbuf_dump(stdout, tx_pkt, 64);
     153                 :          0 :         rte_dump_stack();
     154                 :          0 :         return true;
     155                 :            : }
     156                 :            : 
     157                 :            : static bool
     158         [ #  # ]:          0 : bnxt_check_pkt_needs_ts(struct rte_mbuf *m)
     159                 :            : {
     160                 :            :         const struct rte_ether_hdr *eth_hdr;
     161                 :            :         struct rte_ether_hdr _eth_hdr;
     162                 :            :         uint16_t eth_type, proto;
     163                 :            :         uint32_t off = 0;
     164                 :            :         /*
     165                 :            :          * Check that the received packet is a eCPRI packet
     166                 :            :          */
     167                 :            :         eth_hdr = rte_pktmbuf_read(m, off, sizeof(_eth_hdr), &_eth_hdr);
     168         [ #  # ]:          0 :         eth_type = rte_be_to_cpu_16(eth_hdr->ether_type);
     169                 :            :         off += sizeof(*eth_hdr);
     170         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_ECPRI)
     171                 :            :                 return true;
     172                 :            :         /* Check for single tagged and double tagged VLANs */
     173         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_VLAN) {
     174                 :            :                 const struct rte_vlan_hdr *vh;
     175                 :            :                 struct rte_vlan_hdr vh_copy;
     176                 :            : 
     177                 :            :                 vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     178         [ #  # ]:          0 :                 if (unlikely(vh == NULL))
     179                 :          0 :                         return false;
     180                 :            :                 off += sizeof(*vh);
     181         [ #  # ]:          0 :                 proto = rte_be_to_cpu_16(vh->eth_proto);
     182         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_ECPRI)
     183                 :            :                         return true;
     184         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_VLAN) {
     185                 :            :                         const struct rte_vlan_hdr *vh;
     186                 :            :                         struct rte_vlan_hdr vh_copy;
     187                 :            : 
     188                 :            :                         vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     189         [ #  # ]:          0 :                         if (unlikely(vh == NULL))
     190                 :          0 :                                 return false;
     191                 :            :                         off += sizeof(*vh);
     192         [ #  # ]:          0 :                         proto = rte_be_to_cpu_16(vh->eth_proto);
     193         [ #  # ]:          0 :                         if (proto == RTE_ETHER_TYPE_ECPRI)
     194                 :            :                                 return true;
     195                 :            :                 }
     196                 :            :         }
     197                 :            :         return false;
     198                 :            : }
     199                 :            : 
     200                 :            : static bool
     201                 :            : bnxt_invalid_nb_segs(struct rte_mbuf *tx_pkt)
     202                 :            : {
     203                 :            :         uint16_t nb_segs = 1;
     204                 :            :         struct rte_mbuf *m_seg;
     205                 :            : 
     206                 :          0 :         m_seg = tx_pkt->next;
     207         [ #  # ]:          0 :         while (m_seg) {
     208                 :          0 :                 nb_segs++;
     209                 :          0 :                 m_seg = m_seg->next;
     210                 :            :         }
     211                 :            : 
     212                 :          0 :         return (nb_segs != tx_pkt->nb_segs);
     213                 :            : }
     214                 :            : 
     215                 :          0 : static int bnxt_invalid_mbuf(struct rte_mbuf *mbuf)
     216                 :            : {
     217                 :          0 :         uint32_t mbuf_size = sizeof(struct rte_mbuf) + mbuf->priv_size;
     218                 :            :         const char *reason;
     219                 :            : 
     220   [ #  #  #  # ]:          0 :         if (unlikely(rte_eal_iova_mode() != RTE_IOVA_VA &&
     221                 :            :                      rte_eal_iova_mode() != RTE_IOVA_PA))
     222                 :            :                 return 0;
     223                 :            : 
     224         [ #  # ]:          0 :         if (unlikely(rte_mbuf_check(mbuf, 1, &reason)))
     225                 :            :                 return -EINVAL;
     226                 :            : 
     227         [ #  # ]:          0 :         if (unlikely(mbuf->ol_flags & RTE_MBUF_F_EXTERNAL))
     228                 :            :                 return 0;
     229                 :            : 
     230   [ #  #  #  # ]:          0 :         if (unlikely((mbuf->buf_iova < mbuf_size ||
     231                 :            :                       (mbuf->buf_iova != rte_mempool_virt2iova(mbuf) + mbuf_size))))
     232                 :          0 :                 return -EINVAL;
     233                 :            : 
     234                 :            :         return 0;
     235                 :            : }
     236                 :            : 
     237                 :          0 : static int bnxt_start_xmit(struct rte_mbuf *tx_pkt,
     238                 :            :                                 struct bnxt_tx_queue *txq,
     239                 :            :                                 uint16_t *coal_pkts,
     240                 :            :                                 struct tx_bd_long **last_txbd)
     241                 :            : {
     242                 :          0 :         struct tx_bd_long *last_txbd_save = *last_txbd;
     243                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     244                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     245                 :          0 :         uint16_t tx_raw_prod_save = txr->tx_raw_prod;
     246                 :            :         uint32_t outer_tpid_bd = 0;
     247                 :            :         struct tx_bd_long *txbd;
     248                 :            :         struct tx_bd_long_hi *txbd1 = NULL;
     249                 :            :         uint32_t vlan_tag_flags;
     250                 :            :         bool long_bd = false;
     251                 :            :         unsigned short nr_bds;
     252                 :            :         uint16_t prod, idx;
     253                 :            :         bool pkt_needs_ts = 0;
     254                 :            :         struct rte_mbuf *m_seg;
     255                 :            :         struct rte_mbuf **tx_buf;
     256                 :            :         static const uint32_t lhint_arr[4] = {
     257                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT512,
     258                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT1K,
     259                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K,
     260                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K
     261                 :            :         };
     262                 :            :         int rc = 0;
     263                 :            : 
     264         [ #  # ]:          0 :         if (unlikely(is_bnxt_in_error(txq->bp))) {
     265                 :            :                 rc = -EIO;
     266                 :          0 :                 goto ret;
     267                 :            :         }
     268                 :            : 
     269         [ #  # ]:          0 :         if (unlikely(bnxt_invalid_mbuf(tx_pkt))) {
     270                 :            :                 rc = -EINVAL;
     271                 :          0 :                 goto drop;
     272                 :            :         }
     273                 :            : 
     274         [ #  # ]:          0 :         if (unlikely(bnxt_invalid_nb_segs(tx_pkt))) {
     275                 :            :                 rc = -EINVAL;
     276                 :          0 :                 goto drop;
     277                 :            :         }
     278                 :            : 
     279                 :            :         long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq);
     280                 :          0 :         nr_bds = long_bd + tx_pkt->nb_segs;
     281                 :            : 
     282         [ #  # ]:          0 :         if (unlikely(bnxt_tx_avail(txq) < nr_bds)) {
     283                 :            :                 rc = -ENOMEM;
     284                 :          0 :                 goto ret;
     285                 :            :         }
     286                 :            : 
     287                 :            :         /* Check if number of Tx descriptors is above HW limit */
     288         [ #  # ]:          0 :         if (unlikely(nr_bds > BNXT_MAX_TSO_SEGS)) {
     289                 :          0 :                 PMD_DRV_LOG_LINE(ERR,
     290                 :            :                             "Num descriptors %d exceeds HW limit", nr_bds);
     291                 :            :                 rc = -EINVAL;
     292                 :          0 :                 goto drop;
     293                 :            :         }
     294                 :            : 
     295                 :            :         /* If packet length is less than minimum packet size, pad it */
     296         [ #  # ]:          0 :         if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) {
     297                 :          0 :                 uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt);
     298                 :          0 :                 char *seg = rte_pktmbuf_append(tx_pkt, pad);
     299                 :            : 
     300         [ #  # ]:          0 :                 if (!seg) {
     301                 :          0 :                         PMD_DRV_LOG_LINE(ERR,
     302                 :            :                                     "Failed to pad mbuf by %d bytes",
     303                 :            :                                     pad);
     304                 :            :                         rc = -ENOMEM;
     305                 :          0 :                         goto ret;
     306                 :            :                 }
     307                 :            : 
     308                 :            :                 /* Note: data_len, pkt len are updated in rte_pktmbuf_append */
     309                 :          0 :                 memset(seg, 0, pad);
     310                 :            :         }
     311                 :            : 
     312                 :            :         /* Check non zero data_len */
     313         [ #  # ]:          0 :         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, true, false))) {
     314                 :            :                 rc = -EINVAL;
     315                 :          0 :                 goto drop;
     316                 :            :         }
     317                 :            : 
     318   [ #  #  #  # ]:          0 :         if (unlikely(txq->bp->ptp_cfg != NULL && txq->bp->ptp_all_rx_tstamp == 1))
     319                 :          0 :                 pkt_needs_ts = bnxt_check_pkt_needs_ts(tx_pkt);
     320                 :            : 
     321                 :          0 :         prod = RING_IDX(ring, txr->tx_raw_prod);
     322                 :          0 :         tx_buf = &txr->tx_buf_ring[prod];
     323                 :          0 :         *tx_buf = tx_pkt;
     324                 :          0 :         txr->nr_bds[prod] = nr_bds;
     325                 :            : 
     326                 :          0 :         txbd = &txr->tx_desc_ring[prod];
     327                 :          0 :         txbd->opaque = *coal_pkts;
     328                 :          0 :         txbd->flags_type = nr_bds << TX_BD_LONG_FLAGS_BD_CNT_SFT;
     329                 :          0 :         txbd->flags_type |= TX_BD_SHORT_FLAGS_COAL_NOW;
     330                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_NO_CMPL;
     331                 :          0 :         txbd->len = tx_pkt->data_len;
     332         [ #  # ]:          0 :         if (tx_pkt->pkt_len >= 2048)
     333                 :          0 :                 txbd->flags_type |= TX_BD_LONG_FLAGS_LHINT_GTE2K;
     334                 :            :         else
     335                 :          0 :                 txbd->flags_type |= lhint_arr[tx_pkt->pkt_len >> 9];
     336         [ #  # ]:          0 :         if (tx_pkt->ol_flags & RTE_MBUF_F_EXTERNAL)
     337                 :          0 :                 txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(tx_pkt, uint64_t, 0));
     338                 :            :         else
     339                 :          0 :                 txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(tx_pkt));
     340                 :          0 :         *last_txbd = txbd;
     341                 :            : 
     342         [ #  # ]:          0 :         if (long_bd) {
     343                 :          0 :                 txbd->flags_type |= TX_BD_LONG_TYPE_TX_BD_LONG;
     344                 :            :                 vlan_tag_flags = 0;
     345                 :            : 
     346                 :            :                 /* HW can accelerate only outer vlan in QinQ mode */
     347         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_QINQ) {
     348                 :          0 :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     349                 :          0 :                                 tx_pkt->vlan_tci_outer;
     350                 :          0 :                         outer_tpid_bd = txq->bp->outer_tpid_bd &
     351                 :            :                                 BNXT_OUTER_TPID_BD_MASK;
     352                 :          0 :                         vlan_tag_flags |= outer_tpid_bd;
     353         [ #  # ]:          0 :                 } else if (tx_pkt->ol_flags & RTE_MBUF_F_TX_VLAN) {
     354                 :            :                         /* shurd: Should this mask at
     355                 :            :                          * TX_BD_LONG_CFA_META_VLAN_VID_MASK?
     356                 :            :                          */
     357                 :            :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     358                 :          0 :                                 tx_pkt->vlan_tci;
     359                 :            :                         /* Currently supports 8021Q, 8021AD vlan offloads
     360                 :            :                          * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
     361                 :            :                          */
     362                 :            :                         /* DPDK only supports 802.11q VLAN packets */
     363                 :          0 :                         vlan_tag_flags |=
     364                 :            :                                         TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
     365                 :            :                 }
     366                 :            : 
     367                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     368                 :            : 
     369                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     370                 :          0 :                 txbd1 = (struct tx_bd_long_hi *)&txr->tx_desc_ring[prod];
     371                 :          0 :                 txbd1->lflags = 0;
     372                 :          0 :                 txbd1->cfa_meta = vlan_tag_flags;
     373                 :            :                 /* Legacy tx_bd_long_hi->mss =
     374                 :            :                  * tx_bd_long_hi->kid_or_ts_high_mss
     375                 :            :                  */
     376                 :          0 :                 txbd1->kid_or_ts_high_mss = 0;
     377                 :            : 
     378         [ #  # ]:          0 :                 if (txq->vfr_tx_cfa_action) {
     379                 :          0 :                         txbd1->cfa_action = txq->vfr_tx_cfa_action & 0xffff;
     380                 :          0 :                         txbd1->cfa_action_high = (txq->vfr_tx_cfa_action >> 16) &
     381                 :            :                                 TX_BD_LONG_CFA_ACTION_HIGH_MASK;
     382                 :            :                 } else {
     383                 :          0 :                         txbd1->cfa_action = txq->bp->tx_cfa_action & 0xffff;
     384                 :          0 :                         txbd1->cfa_action_high = (txq->bp->tx_cfa_action >> 16) &
     385                 :            :                                 TX_BD_LONG_CFA_ACTION_HIGH_MASK;
     386                 :            :                 }
     387                 :            : 
     388         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_SEG ||
     389                 :            :                     tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_SEG) {
     390                 :            :                         uint16_t hdr_size;
     391                 :            : 
     392                 :            :                         /* TSO */
     393                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO |
     394                 :            :                                          TX_BD_LONG_LFLAGS_T_IPID |
     395                 :            :                                          TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM |
     396                 :            :                                          TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
     397                 :          0 :                         hdr_size = tx_pkt->l2_len + tx_pkt->l3_len +
     398                 :          0 :                                         tx_pkt->l4_len;
     399         [ #  # ]:          0 :                         hdr_size += (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
     400                 :          0 :                                     tx_pkt->outer_l2_len +
     401                 :          0 :                                     tx_pkt->outer_l3_len : 0;
     402                 :            :                         /* The hdr_size is multiple of 16bit units not 8bit.
     403                 :            :                          * Hence divide by 2.
     404                 :            :                          * Also legacy hdr_size = kid_or_ts_low_hdr_size.
     405                 :            :                          */
     406                 :          0 :                         txbd1->kid_or_ts_low_hdr_size = hdr_size >> 1;
     407                 :          0 :                         txbd1->kid_or_ts_high_mss = tx_pkt->tso_segsz;
     408         [ #  # ]:          0 :                         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, false, true))) {
     409                 :            :                                 rc = -EINVAL;
     410                 :          0 :                                 goto drop;
     411                 :            :                         }
     412                 :            : 
     413         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_CKSUM) ==
     414                 :          0 :                            PKT_TX_OIP_IIP_TCP_CKSUM ||
     415         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_OIP_IIP_UDP_CKSUM) ==
     416                 :            :                            PKT_TX_OIP_IIP_UDP_CKSUM) {
     417                 :            :                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
     418                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
     419         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_CKSUM) ==
     420                 :          0 :                            PKT_TX_IIP_TCP_CKSUM ||
     421         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_IIP_UDP_CKSUM) ==
     422                 :            :                            PKT_TX_IIP_UDP_CKSUM) {
     423                 :            :                         /* (Inner) IP, (Inner) TCP/UDP CSO */
     424                 :          0 :                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
     425         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_CKSUM) ==
     426                 :          0 :                            PKT_TX_OIP_TCP_CKSUM ||
     427         [ #  # ]:          0 :                            (tx_pkt->ol_flags & PKT_TX_OIP_UDP_CKSUM) ==
     428                 :            :                            PKT_TX_OIP_UDP_CKSUM) {
     429                 :            :                         /* Outer IP, (Inner) TCP/UDP CSO */
     430                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
     431         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_CKSUM) ==
     432                 :            :                            PKT_TX_OIP_IIP_CKSUM) {
     433                 :            :                         /* Outer IP, Inner IP CSO */
     434                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_CHKSUM;
     435         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_CKSUM) ==
     436                 :          0 :                            RTE_MBUF_F_TX_TCP_CKSUM ||
     437         [ #  # ]:          0 :                            (tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_CKSUM) ==
     438                 :            :                            RTE_MBUF_F_TX_UDP_CKSUM) {
     439                 :            :                         /* TCP/UDP CSO */
     440                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
     441         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) ==
     442                 :            :                            RTE_MBUF_F_TX_IP_CKSUM) {
     443                 :            :                         /* IP CSO */
     444                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_IP_CHKSUM;
     445         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ==
     446                 :            :                            RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
     447                 :            :                         /* IP CSO */
     448                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
     449         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) ==
     450         [ #  # ]:          0 :                            RTE_MBUF_F_TX_IEEE1588_TMST || pkt_needs_ts) {
     451                 :            :                         /* PTP */
     452                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_STAMP;
     453                 :            :                 }
     454                 :            :         } else {
     455                 :          0 :                 txbd->flags_type |= TX_BD_SHORT_TYPE_TX_BD_SHORT;
     456                 :            :         }
     457                 :            : 
     458                 :          0 :         m_seg = tx_pkt->next;
     459         [ #  # ]:          0 :         while (m_seg) {
     460                 :            :                 /* Check non zero data_len */
     461         [ #  # ]:          0 :                 if (unlikely(bnxt_zero_data_len_tso_segsz(m_seg, true, false))) {
     462                 :            :                         rc = -EINVAL;
     463                 :          0 :                         goto drop;
     464                 :            :                 }
     465                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     466                 :            : 
     467                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     468                 :          0 :                 tx_buf = &txr->tx_buf_ring[prod];
     469                 :          0 :                 *tx_buf = m_seg;
     470                 :            : 
     471                 :          0 :                 txbd = &txr->tx_desc_ring[prod];
     472         [ #  # ]:          0 :                 if (m_seg->ol_flags & RTE_MBUF_F_EXTERNAL)
     473                 :          0 :                         txbd->address = rte_cpu_to_le_64(rte_pktmbuf_mtod_offset(m_seg,
     474                 :            :                                                                                  uint64_t,
     475                 :            :                                                                                  0));
     476                 :            :                 else
     477                 :          0 :                         txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(m_seg));
     478                 :          0 :                 txbd->flags_type = TX_BD_SHORT_TYPE_TX_BD_SHORT;
     479                 :          0 :                 txbd->len = m_seg->data_len;
     480                 :            : 
     481                 :          0 :                 m_seg = m_seg->next;
     482                 :            :         }
     483                 :            : 
     484                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_PACKET_END;
     485                 :            : 
     486                 :          0 :         txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     487                 :            : 
     488                 :          0 :         return 0;
     489                 :            : drop:
     490                 :            :         /* Roll back any descriptors and tx_buf_ring slots that were written
     491                 :            :          * for this packet before the failure was detected.  Walking from the
     492                 :            :          * saved producer index up to (but not including) the current one is
     493                 :            :          * safe because we hold the Tx lock and the HW has not been notified
     494                 :            :          * (the doorbell is only rung after bnxt_start_xmit() returns
     495                 :            :          * successfully).
     496                 :            :          */
     497                 :            :         idx = tx_raw_prod_save;
     498                 :            : 
     499         [ #  # ]:          0 :         while (idx != txr->tx_raw_prod) {
     500                 :          0 :                 uint16_t slot = RING_IDX(ring, idx);
     501                 :            : 
     502                 :          0 :                 txr->tx_buf_ring[slot] = NULL;
     503                 :          0 :                 txr->tx_desc_ring[slot].address = 0;
     504                 :          0 :                 idx = RING_NEXT(idx);
     505                 :            :         }
     506                 :          0 :         txr->tx_raw_prod = tx_raw_prod_save;
     507                 :          0 :         *last_txbd = last_txbd_save;
     508                 :          0 :         rte_pktmbuf_free(tx_pkt);
     509                 :            : ret:
     510                 :            :         return rc;
     511                 :            : }
     512                 :            : 
     513                 :          0 : static void bnxt_tx_coal_cmp_fast(struct bnxt_tx_queue *txq, int nr_cons)
     514                 :            : {
     515                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     516                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     517                 :          0 :         struct rte_mbuf **free = txq->free;
     518                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     519                 :            :         unsigned int blk = 0;
     520                 :            :         int cons, bds;
     521                 :            : 
     522         [ #  # ]:          0 :         for (cons = 0; cons < nr_cons; cons++) {
     523                 :            :                 struct rte_mbuf **tx_buf;
     524                 :            :                 unsigned short nr_bds;
     525                 :            : 
     526                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     527         [ #  # ]:          0 :                 nr_bds = (*tx_buf)->nb_segs +
     528                 :          0 :                          bnxt_xmit_need_long_bd(*tx_buf, txq);
     529         [ #  # ]:          0 :                 for (bds = 0; bds < nr_bds; bds++) {
     530         [ #  # ]:          0 :                         if (*tx_buf) {
     531                 :          0 :                                 free[blk++] = *tx_buf;
     532                 :            :                                 /*
     533                 :            :                                  * Each BD also tracks a consumer index.
     534                 :            :                                  * Update cons, otherwise it will fall behind.
     535                 :            :                                  */
     536                 :          0 :                                 cons++;
     537                 :          0 :                                 *tx_buf = NULL;
     538                 :            :                         }
     539                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     540                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     541                 :            :                 }
     542                 :            :         }
     543         [ #  # ]:          0 :         if (blk)
     544         [ #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
     545                 :            : 
     546                 :          0 :         txr->tx_raw_cons = raw_cons;
     547                 :          0 : }
     548                 :            : 
     549                 :            : /*
     550                 :            :  * Transmit completion function for use when RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
     551                 :            :  * is enabled.
     552                 :            :  */
     553                 :          0 : static void bnxt_tx_cmp_fast(struct bnxt_tx_queue *txq, int nb_tx,
     554                 :            :                               bool tx_coal_cmp)
     555                 :            : {
     556                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     557                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     558                 :          0 :         struct rte_mbuf **free = txq->free;
     559                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     560                 :            :         unsigned int blk = 0;
     561                 :            :         int i, j;
     562                 :            : 
     563         [ #  # ]:          0 :         if (tx_coal_cmp)
     564                 :          0 :                 return bnxt_tx_coal_cmp_fast(txq, nb_tx);
     565                 :            : 
     566         [ #  # ]:          0 :         for (i = 0; i < nb_tx; i++) {
     567                 :            :                 struct rte_mbuf **tx_buf;
     568                 :            :                 unsigned short nr_bds;
     569                 :            : 
     570                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     571         [ #  # ]:          0 :                 nr_bds = (*tx_buf)->nb_segs +
     572                 :          0 :                          bnxt_xmit_need_long_bd(*tx_buf, txq);
     573         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     574         [ #  # ]:          0 :                         if (*tx_buf) {
     575                 :            :                                 /* Add mbuf to the bulk free array */
     576                 :          0 :                                 free[blk++] = *tx_buf;
     577                 :          0 :                                 *tx_buf = NULL;
     578                 :            :                         }
     579                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     580                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     581                 :            :                 }
     582                 :            :         }
     583         [ #  # ]:          0 :         if (blk)
     584         [ #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
     585                 :            : 
     586                 :          0 :         txr->tx_raw_cons = raw_cons;
     587                 :            : }
     588                 :            : 
     589                 :          0 : static void bnxt_tx_coal_cmp(struct bnxt_tx_queue *txq, int nr_cons)
     590                 :            : {
     591                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     592                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     593                 :            :         struct rte_mempool *pool = NULL;
     594                 :          0 :         struct rte_mbuf **free = txq->free;
     595                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     596                 :            :         unsigned int blk = 0;
     597                 :            :         int cons, bds;
     598                 :            : 
     599         [ #  # ]:          0 :         for (cons = 0; cons < nr_cons; cons++) {
     600                 :            :                 struct rte_mbuf *mbuf;
     601                 :            :                 struct rte_mbuf **tx_buf;
     602                 :            :                 unsigned short nr_bds;
     603                 :            : 
     604                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     605                 :          0 :                 nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
     606                 :            :                 /* Clear the now stale number of buffer descriptors */
     607                 :          0 :                 txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
     608                 :            : 
     609         [ #  # ]:          0 :                 for (bds = 0; bds < nr_bds; bds++) {
     610                 :          0 :                         mbuf = *tx_buf;
     611                 :          0 :                         *tx_buf = NULL;
     612                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     613                 :            :                         /*
     614                 :            :                          * Each BD also tracks a consumer index. So update the cons.
     615                 :            :                          * Otherwise the cons will fall behind.
     616                 :            :                          */
     617                 :          0 :                         cons++;
     618                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     619         [ #  # ]:          0 :                         if (!mbuf)      /* long_bd's tx_buf ? */
     620                 :          0 :                                 continue;
     621                 :            : 
     622                 :            :                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
     623         [ #  # ]:          0 :                         if (unlikely(!mbuf))
     624                 :          0 :                                 continue;
     625                 :            : 
     626                 :            :                         /* EW - no need to unmap DMA memory? */
     627                 :            : 
     628         [ #  # ]:          0 :                         if (likely(mbuf->pool == pool)) {
     629                 :            :                                 /* Add mbuf to the bulk free array */
     630                 :          0 :                                 free[blk++] = mbuf;
     631                 :            :                         } else {
     632                 :            :                                 /* Found an mbuf from a different pool. Free
     633                 :            :                                  * mbufs accumulated so far to the previous
     634                 :            :                                  * pool
     635                 :            :                                  */
     636         [ #  # ]:          0 :                                 if (likely(pool != NULL))
     637                 :            :                                         rte_mempool_put_bulk(pool,
     638                 :            :                                                              (void *)free,
     639                 :            :                                                              blk);
     640                 :            : 
     641                 :            :                                 /* Start accumulating mbufs in a new pool */
     642                 :          0 :                                 free[0] = mbuf;
     643                 :          0 :                                 pool = mbuf->pool;
     644                 :            :                                 blk = 1;
     645                 :            :                         }
     646                 :            :                 }
     647                 :            :         }
     648         [ #  # ]:          0 :         if (blk)
     649                 :            :                 rte_mempool_put_bulk(pool, (void *)free, blk);
     650                 :            : 
     651                 :          0 :         txr->tx_raw_cons = raw_cons;
     652                 :          0 : }
     653                 :            : 
     654                 :          0 : static void bnxt_tx_cmp(struct bnxt_tx_queue *txq, int nb_tx, bool tx_coal_cmp)
     655                 :            : {
     656                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     657                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     658                 :            :         struct rte_mempool *pool = NULL;
     659                 :          0 :         struct rte_mbuf **free = txq->free;
     660                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     661                 :            :         unsigned int blk = 0;
     662                 :            :         int i, j;
     663                 :            : 
     664         [ #  # ]:          0 :         if (tx_coal_cmp)
     665                 :          0 :                 return bnxt_tx_coal_cmp(txq, nb_tx);
     666                 :            : 
     667         [ #  # ]:          0 :         for (i = 0; i < nb_tx; i++) {
     668                 :            :                 struct rte_mbuf *mbuf;
     669                 :            :                 struct rte_mbuf **tx_buf;
     670                 :            :                 unsigned short nr_bds;
     671                 :            : 
     672                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     673                 :          0 :                 nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
     674                 :            :                 /* Clear the now stale number of buffer descriptors */
     675                 :          0 :                 txr->nr_bds[RING_IDX(ring, raw_cons)] = 0;
     676                 :            : 
     677         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     678                 :          0 :                         mbuf = *tx_buf;
     679                 :          0 :                         *tx_buf = NULL;
     680                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     681                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     682         [ #  # ]:          0 :                         if (!mbuf)      /* long_bd's tx_buf ? */
     683                 :          0 :                                 continue;
     684                 :            : 
     685                 :            :                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
     686         [ #  # ]:          0 :                         if (unlikely(!mbuf))
     687                 :          0 :                                 continue;
     688                 :            : 
     689                 :            :                         /* EW - no need to unmap DMA memory? */
     690                 :            : 
     691         [ #  # ]:          0 :                         if (likely(mbuf->pool == pool)) {
     692                 :            :                                 /* Add mbuf to the bulk free array */
     693                 :          0 :                                 free[blk++] = mbuf;
     694                 :            :                         } else {
     695                 :            :                                 /* Found an mbuf from a different pool. Free
     696                 :            :                                  * mbufs accumulated so far to the previous
     697                 :            :                                  * pool
     698                 :            :                                  */
     699         [ #  # ]:          0 :                                 if (likely(pool != NULL))
     700                 :            :                                         rte_mempool_put_bulk(pool,
     701                 :            :                                                              (void *)free,
     702                 :            :                                                              blk);
     703                 :            : 
     704                 :            :                                 /* Start accumulating mbufs in a new pool */
     705                 :          0 :                                 free[0] = mbuf;
     706                 :          0 :                                 pool = mbuf->pool;
     707                 :            :                                 blk = 1;
     708                 :            :                         }
     709                 :            :                 }
     710                 :            :         }
     711         [ #  # ]:          0 :         if (blk)
     712                 :            :                 rte_mempool_put_bulk(pool, (void *)free, blk);
     713                 :            : 
     714                 :          0 :         txr->tx_raw_cons = raw_cons;
     715                 :            : }
     716                 :            : 
     717                 :            : static bool bnxt_is_tx_cmpl_type(uint16_t type)
     718                 :            : {
     719                 :          0 :         return (type == CMPL_BASE_TYPE_TX_L2_PKT_TS ||
     720                 :          0 :                 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