LCOV - code coverage report
Current view: top level - drivers/net/bnxt - bnxt_txr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 306 0.0 %
Date: 2024-03-01 20:19:12 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 184 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 :         for (i = 0; i < (int)bp->tx_nr_rings; i++) {
      28                 :          0 :                 struct bnxt_tx_queue *txq = bp->tx_queues[i];
      29                 :            : 
      30         [ #  # ]:          0 :                 if (!txq)
      31                 :          0 :                         continue;
      32                 :            : 
      33                 :          0 :                 bnxt_free_ring(txq->tx_ring->tx_ring_struct);
      34                 :          0 :                 rte_free(txq->tx_ring->tx_ring_struct);
      35                 :          0 :                 rte_free(txq->tx_ring);
      36                 :            : 
      37                 :          0 :                 bnxt_free_ring(txq->cp_ring->cp_ring_struct);
      38                 :          0 :                 rte_free(txq->cp_ring->cp_ring_struct);
      39                 :          0 :                 rte_free(txq->cp_ring);
      40                 :            : 
      41                 :          0 :                 rte_memzone_free(txq->mz);
      42                 :          0 :                 txq->mz = NULL;
      43                 :            : 
      44                 :          0 :                 rte_free(txq);
      45                 :          0 :                 bp->tx_queues[i] = NULL;
      46                 :            :         }
      47                 :          0 : }
      48                 :            : 
      49                 :          0 : int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq)
      50                 :            : {
      51                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
      52                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
      53                 :            : 
      54                 :          0 :         txq->tx_wake_thresh = ring->ring_size / 2;
      55                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
      56                 :            : 
      57                 :          0 :         return 0;
      58                 :            : }
      59                 :            : 
      60                 :          0 : int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id)
      61                 :            : {
      62                 :            :         struct bnxt_cp_ring_info *cpr;
      63                 :            :         struct bnxt_tx_ring_info *txr;
      64                 :            :         struct bnxt_ring *ring;
      65                 :            : 
      66                 :          0 :         txr = rte_zmalloc_socket("bnxt_tx_ring",
      67                 :            :                                  sizeof(struct bnxt_tx_ring_info),
      68                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
      69         [ #  # ]:          0 :         if (txr == NULL)
      70                 :            :                 return -ENOMEM;
      71                 :          0 :         txq->tx_ring = txr;
      72                 :            : 
      73                 :          0 :         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
      74                 :            :                                   sizeof(struct bnxt_ring),
      75                 :            :                                   RTE_CACHE_LINE_SIZE, socket_id);
      76         [ #  # ]:          0 :         if (ring == NULL)
      77                 :            :                 return -ENOMEM;
      78                 :          0 :         txr->tx_ring_struct = ring;
      79                 :          0 :         ring->ring_size = rte_align32pow2(txq->nb_tx_desc);
      80                 :          0 :         ring->ring_mask = ring->ring_size - 1;
      81                 :          0 :         ring->bd = (void *)txr->tx_desc_ring;
      82                 :          0 :         ring->bd_dma = txr->tx_desc_mapping;
      83                 :          0 :         ring->vmem_size = ring->ring_size * sizeof(struct rte_mbuf *);
      84                 :          0 :         ring->vmem = (void **)&txr->tx_buf_ring;
      85                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
      86                 :            : 
      87                 :          0 :         cpr = rte_zmalloc_socket("bnxt_tx_ring",
      88                 :            :                                  sizeof(struct bnxt_cp_ring_info),
      89                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
      90         [ #  # ]:          0 :         if (cpr == NULL)
      91                 :            :                 return -ENOMEM;
      92                 :          0 :         txq->cp_ring = cpr;
      93                 :            : 
      94                 :          0 :         ring = rte_zmalloc_socket("bnxt_tx_ring_struct",
      95                 :            :                                   sizeof(struct bnxt_ring),
      96                 :            :                                   RTE_CACHE_LINE_SIZE, socket_id);
      97         [ #  # ]:          0 :         if (ring == NULL)
      98                 :            :                 return -ENOMEM;
      99                 :          0 :         cpr->cp_ring_struct = ring;
     100                 :          0 :         ring->ring_size = txr->tx_ring_struct->ring_size;
     101                 :          0 :         ring->ring_mask = ring->ring_size - 1;
     102                 :          0 :         ring->bd = (void *)cpr->cp_desc_ring;
     103                 :          0 :         ring->bd_dma = cpr->cp_desc_mapping;
     104                 :          0 :         ring->vmem_size = 0;
     105                 :          0 :         ring->vmem = NULL;
     106                 :          0 :         ring->fw_ring_id = INVALID_HW_RING_ID;
     107                 :            : 
     108                 :          0 :         return 0;
     109                 :            : }
     110                 :            : 
     111                 :            : static bool
     112                 :            : bnxt_xmit_need_long_bd(struct rte_mbuf *tx_pkt, struct bnxt_tx_queue *txq)
     113                 :            : {
     114         [ #  # ]:          0 :         if (tx_pkt->ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_TCP_CKSUM |
     115                 :            :                                 RTE_MBUF_F_TX_UDP_CKSUM | RTE_MBUF_F_TX_IP_CKSUM |
     116                 :            :                                 RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_OUTER_IP_CKSUM |
     117                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GRE | RTE_MBUF_F_TX_TUNNEL_VXLAN |
     118                 :            :                                 RTE_MBUF_F_TX_TUNNEL_GENEVE | RTE_MBUF_F_TX_IEEE1588_TMST |
     119                 :          0 :                                 RTE_MBUF_F_TX_QINQ) ||
     120   [ #  #  #  #  :          0 :              (BNXT_TRUFLOW_EN(txq->bp) &&
             #  #  #  # ]
     121   [ #  #  #  #  :          0 :               (txq->bp->tx_cfa_action || txq->vfr_tx_cfa_action)))
             #  #  #  # ]
     122                 :          0 :                 return true;
     123                 :            :         return false;
     124                 :            : }
     125                 :            : 
     126                 :            : /* Used for verifying TSO segments during TCP Segmentation Offload or
     127                 :            :  * UDP Fragmentation Offload. tx_pkt->tso_segsz stores the number of
     128                 :            :  * segments or fragments in those cases.
     129                 :            :  */
     130                 :            : static bool
     131                 :          0 : bnxt_zero_data_len_tso_segsz(struct rte_mbuf *tx_pkt, uint8_t data_len_chk)
     132                 :            : {
     133                 :            :         const char *type_str = "Data len";
     134                 :          0 :         uint16_t len_to_check = tx_pkt->data_len;
     135                 :            : 
     136         [ #  # ]:          0 :         if (data_len_chk == 0) {
     137                 :            :                 type_str = "TSO Seg size";
     138                 :          0 :                 len_to_check = tx_pkt->tso_segsz;
     139                 :            :         }
     140                 :            : 
     141         [ #  # ]:          0 :         if (len_to_check == 0) {
     142                 :          0 :                 PMD_DRV_LOG(ERR, "Error! Tx pkt %s == 0\n", type_str);
     143                 :          0 :                 rte_pktmbuf_dump(stdout, tx_pkt, 64);
     144                 :          0 :                 rte_dump_stack();
     145                 :          0 :                 return true;
     146                 :            :         }
     147                 :            :         return false;
     148                 :            : }
     149                 :            : 
     150                 :            : static bool
     151         [ #  # ]:          0 : bnxt_check_pkt_needs_ts(struct rte_mbuf *m)
     152                 :            : {
     153                 :            :         const struct rte_ether_hdr *eth_hdr;
     154                 :            :         struct rte_ether_hdr _eth_hdr;
     155                 :            :         uint16_t eth_type, proto;
     156                 :            :         uint32_t off = 0;
     157                 :            :         /*
     158                 :            :          * Check that the received packet is a eCPRI packet
     159                 :            :          */
     160                 :            :         eth_hdr = rte_pktmbuf_read(m, off, sizeof(_eth_hdr), &_eth_hdr);
     161         [ #  # ]:          0 :         eth_type = rte_be_to_cpu_16(eth_hdr->ether_type);
     162                 :            :         off += sizeof(*eth_hdr);
     163         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_ECPRI)
     164                 :            :                 return true;
     165                 :            :         /* Check for single tagged and double tagged VLANs */
     166         [ #  # ]:          0 :         if (eth_type == RTE_ETHER_TYPE_VLAN) {
     167                 :            :                 const struct rte_vlan_hdr *vh;
     168                 :            :                 struct rte_vlan_hdr vh_copy;
     169                 :            : 
     170                 :            :                 vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     171         [ #  # ]:          0 :                 if (unlikely(vh == NULL))
     172                 :          0 :                         return false;
     173                 :            :                 off += sizeof(*vh);
     174         [ #  # ]:          0 :                 proto = rte_be_to_cpu_16(vh->eth_proto);
     175         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_ECPRI)
     176                 :            :                         return true;
     177         [ #  # ]:          0 :                 if (proto == RTE_ETHER_TYPE_VLAN) {
     178                 :            :                         const struct rte_vlan_hdr *vh;
     179                 :            :                         struct rte_vlan_hdr vh_copy;
     180                 :            : 
     181                 :            :                         vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
     182         [ #  # ]:          0 :                         if (unlikely(vh == NULL))
     183                 :          0 :                                 return false;
     184                 :            :                         off += sizeof(*vh);
     185         [ #  # ]:          0 :                         proto = rte_be_to_cpu_16(vh->eth_proto);
     186         [ #  # ]:          0 :                         if (proto == RTE_ETHER_TYPE_ECPRI)
     187                 :            :                                 return true;
     188                 :            :                 }
     189                 :            :         }
     190                 :            :         return false;
     191                 :            : }
     192                 :            : 
     193                 :          0 : static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt,
     194                 :            :                                 struct bnxt_tx_queue *txq,
     195                 :            :                                 uint16_t *coal_pkts,
     196                 :            :                                 struct tx_bd_long **last_txbd)
     197                 :            : {
     198                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     199                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     200                 :            :         uint32_t outer_tpid_bd = 0;
     201                 :            :         struct tx_bd_long *txbd;
     202                 :            :         struct tx_bd_long_hi *txbd1 = NULL;
     203                 :            :         uint32_t vlan_tag_flags;
     204                 :            :         bool long_bd = false;
     205                 :            :         unsigned short nr_bds;
     206                 :            :         uint16_t prod;
     207                 :            :         bool pkt_needs_ts = 0;
     208                 :            :         struct rte_mbuf *m_seg;
     209                 :            :         struct rte_mbuf **tx_buf;
     210                 :            :         static const uint32_t lhint_arr[4] = {
     211                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT512,
     212                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT1K,
     213                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K,
     214                 :            :                 TX_BD_LONG_FLAGS_LHINT_LT2K
     215                 :            :         };
     216                 :            : 
     217         [ #  # ]:          0 :         if (unlikely(is_bnxt_in_error(txq->bp)))
     218                 :            :                 return -EIO;
     219                 :            : 
     220                 :            :         long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq);
     221                 :          0 :         nr_bds = long_bd + tx_pkt->nb_segs;
     222                 :            : 
     223         [ #  # ]:          0 :         if (unlikely(bnxt_tx_avail(txq) < nr_bds))
     224                 :            :                 return -ENOMEM;
     225                 :            : 
     226                 :            :         /* Check if number of Tx descriptors is above HW limit */
     227         [ #  # ]:          0 :         if (unlikely(nr_bds > BNXT_MAX_TSO_SEGS)) {
     228                 :          0 :                 PMD_DRV_LOG(ERR,
     229                 :            :                             "Num descriptors %d exceeds HW limit\n", nr_bds);
     230                 :          0 :                 return -ENOSPC;
     231                 :            :         }
     232                 :            : 
     233                 :            :         /* If packet length is less than minimum packet size, pad it */
     234         [ #  # ]:          0 :         if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) < BNXT_MIN_PKT_SIZE)) {
     235                 :          0 :                 uint8_t pad = BNXT_MIN_PKT_SIZE - rte_pktmbuf_pkt_len(tx_pkt);
     236                 :          0 :                 char *seg = rte_pktmbuf_append(tx_pkt, pad);
     237                 :            : 
     238         [ #  # ]:          0 :                 if (!seg) {
     239                 :          0 :                         PMD_DRV_LOG(ERR,
     240                 :            :                                     "Failed to pad mbuf by %d bytes\n",
     241                 :            :                                     pad);
     242                 :          0 :                         return -ENOMEM;
     243                 :            :                 }
     244                 :            : 
     245                 :            :                 /* Note: data_len, pkt len are updated in rte_pktmbuf_append */
     246                 :          0 :                 memset(seg, 0, pad);
     247                 :            :         }
     248                 :            : 
     249                 :            :         /* Check non zero data_len */
     250         [ #  # ]:          0 :         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, 1)))
     251                 :            :                 return -EIO;
     252                 :            : 
     253   [ #  #  #  # ]:          0 :         if (unlikely(txq->bp->ptp_cfg != NULL && txq->bp->ptp_all_rx_tstamp == 1))
     254                 :          0 :                 pkt_needs_ts = bnxt_check_pkt_needs_ts(tx_pkt);
     255                 :            : 
     256                 :          0 :         prod = RING_IDX(ring, txr->tx_raw_prod);
     257                 :          0 :         tx_buf = &txr->tx_buf_ring[prod];
     258                 :          0 :         *tx_buf = tx_pkt;
     259                 :          0 :         txr->nr_bds[prod] = nr_bds;
     260                 :            : 
     261                 :          0 :         txbd = &txr->tx_desc_ring[prod];
     262                 :          0 :         txbd->opaque = *coal_pkts;
     263                 :          0 :         txbd->flags_type = nr_bds << TX_BD_LONG_FLAGS_BD_CNT_SFT;
     264                 :          0 :         txbd->flags_type |= TX_BD_SHORT_FLAGS_COAL_NOW;
     265                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_NO_CMPL;
     266                 :          0 :         txbd->len = tx_pkt->data_len;
     267         [ #  # ]:          0 :         if (tx_pkt->pkt_len >= 2048)
     268                 :          0 :                 txbd->flags_type |= TX_BD_LONG_FLAGS_LHINT_GTE2K;
     269                 :            :         else
     270                 :          0 :                 txbd->flags_type |= lhint_arr[tx_pkt->pkt_len >> 9];
     271                 :          0 :         txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(tx_pkt));
     272                 :          0 :         *last_txbd = txbd;
     273                 :            : 
     274         [ #  # ]:          0 :         if (long_bd) {
     275                 :          0 :                 txbd->flags_type |= TX_BD_LONG_TYPE_TX_BD_LONG;
     276                 :            :                 vlan_tag_flags = 0;
     277                 :            : 
     278                 :            :                 /* HW can accelerate only outer vlan in QinQ mode */
     279         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_QINQ) {
     280                 :          0 :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     281                 :          0 :                                 tx_pkt->vlan_tci_outer;
     282                 :          0 :                         outer_tpid_bd = txq->bp->outer_tpid_bd &
     283                 :            :                                 BNXT_OUTER_TPID_BD_MASK;
     284                 :          0 :                         vlan_tag_flags |= outer_tpid_bd;
     285         [ #  # ]:          0 :                 } else if (tx_pkt->ol_flags & RTE_MBUF_F_TX_VLAN) {
     286                 :            :                         /* shurd: Should this mask at
     287                 :            :                          * TX_BD_LONG_CFA_META_VLAN_VID_MASK?
     288                 :            :                          */
     289                 :            :                         vlan_tag_flags = TX_BD_LONG_CFA_META_KEY_VLAN_TAG |
     290                 :          0 :                                 tx_pkt->vlan_tci;
     291                 :            :                         /* Currently supports 8021Q, 8021AD vlan offloads
     292                 :            :                          * QINQ1, QINQ2, QINQ3 vlan headers are deprecated
     293                 :            :                          */
     294                 :            :                         /* DPDK only supports 802.11q VLAN packets */
     295                 :          0 :                         vlan_tag_flags |=
     296                 :            :                                         TX_BD_LONG_CFA_META_VLAN_TPID_TPID8100;
     297                 :            :                 }
     298                 :            : 
     299                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     300                 :            : 
     301                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     302                 :          0 :                 txbd1 = (struct tx_bd_long_hi *)&txr->tx_desc_ring[prod];
     303                 :          0 :                 txbd1->lflags = 0;
     304                 :          0 :                 txbd1->cfa_meta = vlan_tag_flags;
     305                 :            :                 /* Legacy tx_bd_long_hi->mss =
     306                 :            :                  * tx_bd_long_hi->kid_or_ts_high_mss
     307                 :            :                  */
     308                 :          0 :                 txbd1->kid_or_ts_high_mss = 0;
     309                 :            : 
     310         [ #  # ]:          0 :                 if (txq->vfr_tx_cfa_action)
     311                 :          0 :                         txbd1->cfa_action = txq->vfr_tx_cfa_action;
     312                 :            :                 else
     313                 :          0 :                         txbd1->cfa_action = txq->bp->tx_cfa_action;
     314                 :            : 
     315         [ #  # ]:          0 :                 if (tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_SEG ||
     316                 :            :                     tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_SEG) {
     317                 :            :                         uint16_t hdr_size;
     318                 :            : 
     319                 :            :                         /* TSO */
     320                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_LSO |
     321                 :            :                                          TX_BD_LONG_LFLAGS_T_IPID;
     322                 :          0 :                         hdr_size = tx_pkt->l2_len + tx_pkt->l3_len +
     323                 :          0 :                                         tx_pkt->l4_len;
     324         [ #  # ]:          0 :                         hdr_size += (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
     325                 :          0 :                                     tx_pkt->outer_l2_len +
     326                 :          0 :                                     tx_pkt->outer_l3_len : 0;
     327                 :            :                         /* The hdr_size is multiple of 16bit units not 8bit.
     328                 :            :                          * Hence divide by 2.
     329                 :            :                          * Also legacy hdr_size = kid_or_ts_low_hdr_size.
     330                 :            :                          */
     331                 :          0 :                         txbd1->kid_or_ts_low_hdr_size = hdr_size >> 1;
     332                 :          0 :                         txbd1->kid_or_ts_high_mss = tx_pkt->tso_segsz;
     333         [ #  # ]:          0 :                         if (unlikely(bnxt_zero_data_len_tso_segsz(tx_pkt, 0)))
     334                 :            :                                 return -EIO;
     335                 :            : 
     336         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_UDP_CKSUM) ==
     337                 :            :                            PKT_TX_OIP_IIP_TCP_UDP_CKSUM) {
     338                 :            :                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
     339                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
     340         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_TCP_CKSUM) ==
     341                 :            :                            PKT_TX_OIP_IIP_TCP_CKSUM) {
     342                 :            :                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
     343                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
     344                 :            :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_UDP_CKSUM) ==
     345                 :            :                            PKT_TX_OIP_IIP_UDP_CKSUM) {
     346                 :            :                         /* Outer IP, Inner IP, Inner TCP/UDP CSO */
     347                 :            :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_TCP_UDP_CHKSUM;
     348         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_UDP_CKSUM) ==
     349                 :            :                            PKT_TX_IIP_TCP_UDP_CKSUM) {
     350                 :            :                         /* (Inner) IP, (Inner) TCP/UDP CSO */
     351                 :          0 :                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
     352                 :            :                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_UDP_CKSUM) ==
     353                 :            :                            PKT_TX_IIP_UDP_CKSUM) {
     354                 :            :                         /* (Inner) IP, (Inner) TCP/UDP CSO */
     355                 :            :                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
     356         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_IIP_TCP_CKSUM) ==
     357                 :            :                            PKT_TX_IIP_TCP_CKSUM) {
     358                 :            :                         /* (Inner) IP, (Inner) TCP/UDP CSO */
     359                 :          0 :                         txbd1->lflags |= TX_BD_FLG_IP_TCP_UDP_CHKSUM;
     360         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_UDP_CKSUM) ==
     361                 :            :                            PKT_TX_OIP_TCP_UDP_CKSUM) {
     362                 :            :                         /* Outer IP, (Inner) TCP/UDP CSO */
     363                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
     364                 :            :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_UDP_CKSUM) ==
     365                 :            :                            PKT_TX_OIP_UDP_CKSUM) {
     366                 :            :                         /* Outer IP, (Inner) TCP/UDP CSO */
     367                 :            :                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
     368         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_TCP_CKSUM) ==
     369                 :            :                            PKT_TX_OIP_TCP_CKSUM) {
     370                 :            :                         /* Outer IP, (Inner) TCP/UDP CSO */
     371                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_TCP_UDP_CHKSUM;
     372         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_OIP_IIP_CKSUM) ==
     373                 :            :                            PKT_TX_OIP_IIP_CKSUM) {
     374                 :            :                         /* Outer IP, Inner IP CSO */
     375                 :          0 :                         txbd1->lflags |= TX_BD_FLG_TIP_IP_CHKSUM;
     376         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & PKT_TX_TCP_UDP_CKSUM) ==
     377                 :            :                            PKT_TX_TCP_UDP_CKSUM) {
     378                 :            :                         /* TCP/UDP CSO */
     379                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
     380         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_TCP_CKSUM) ==
     381                 :            :                            RTE_MBUF_F_TX_TCP_CKSUM) {
     382                 :            :                         /* TCP/UDP CSO */
     383                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
     384                 :            :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_UDP_CKSUM) ==
     385                 :            :                            RTE_MBUF_F_TX_UDP_CKSUM) {
     386                 :            :                         /* TCP/UDP CSO */
     387                 :            :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_TCP_UDP_CHKSUM;
     388         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) ==
     389                 :            :                            RTE_MBUF_F_TX_IP_CKSUM) {
     390                 :            :                         /* IP CSO */
     391                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_IP_CHKSUM;
     392         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) ==
     393                 :            :                            RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
     394                 :            :                         /* IP CSO */
     395                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_T_IP_CHKSUM;
     396         [ #  # ]:          0 :                 } else if ((tx_pkt->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST) ==
     397         [ #  # ]:          0 :                            RTE_MBUF_F_TX_IEEE1588_TMST || pkt_needs_ts) {
     398                 :            :                         /* PTP */
     399                 :          0 :                         txbd1->lflags |= TX_BD_LONG_LFLAGS_STAMP;
     400                 :            :                 }
     401                 :            :         } else {
     402                 :          0 :                 txbd->flags_type |= TX_BD_SHORT_TYPE_TX_BD_SHORT;
     403                 :            :         }
     404                 :            : 
     405                 :          0 :         m_seg = tx_pkt->next;
     406         [ #  # ]:          0 :         while (m_seg) {
     407                 :            :                 /* Check non zero data_len */
     408         [ #  # ]:          0 :                 if (unlikely(bnxt_zero_data_len_tso_segsz(m_seg, 1)))
     409                 :            :                         return -EIO;
     410                 :          0 :                 txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     411                 :            : 
     412                 :          0 :                 prod = RING_IDX(ring, txr->tx_raw_prod);
     413                 :          0 :                 tx_buf = &txr->tx_buf_ring[prod];
     414                 :          0 :                 *tx_buf = m_seg;
     415                 :            : 
     416                 :          0 :                 txbd = &txr->tx_desc_ring[prod];
     417                 :          0 :                 txbd->address = rte_cpu_to_le_64(rte_mbuf_data_iova(m_seg));
     418                 :          0 :                 txbd->flags_type = TX_BD_SHORT_TYPE_TX_BD_SHORT;
     419                 :          0 :                 txbd->len = m_seg->data_len;
     420                 :            : 
     421                 :          0 :                 m_seg = m_seg->next;
     422                 :            :         }
     423                 :            : 
     424                 :          0 :         txbd->flags_type |= TX_BD_LONG_FLAGS_PACKET_END;
     425                 :            : 
     426                 :          0 :         txr->tx_raw_prod = RING_NEXT(txr->tx_raw_prod);
     427                 :            : 
     428                 :          0 :         return 0;
     429                 :            : }
     430                 :            : 
     431                 :            : /*
     432                 :            :  * Transmit completion function for use when RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE
     433                 :            :  * is enabled.
     434                 :            :  */
     435                 :          0 : static void bnxt_tx_cmp_fast(struct bnxt_tx_queue *txq, int nr_pkts)
     436                 :            : {
     437                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     438                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     439                 :          0 :         struct rte_mbuf **free = txq->free;
     440                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     441                 :            :         unsigned int blk = 0;
     442                 :            :         int i, j;
     443                 :            : 
     444         [ #  # ]:          0 :         for (i = 0; i < nr_pkts; i++) {
     445                 :            :                 struct rte_mbuf **tx_buf;
     446                 :            :                 unsigned short nr_bds;
     447                 :            : 
     448                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     449         [ #  # ]:          0 :                 nr_bds = (*tx_buf)->nb_segs +
     450                 :          0 :                          bnxt_xmit_need_long_bd(*tx_buf, txq);
     451         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     452         [ #  # ]:          0 :                         if (*tx_buf) {
     453                 :            :                                 /* Add mbuf to the bulk free array */
     454                 :          0 :                                 free[blk++] = *tx_buf;
     455                 :          0 :                                 *tx_buf = NULL;
     456                 :            :                         }
     457                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     458                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     459                 :            :                 }
     460                 :            :         }
     461         [ #  # ]:          0 :         if (blk)
     462         [ #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void *)free, blk);
     463                 :            : 
     464                 :          0 :         txr->tx_raw_cons = raw_cons;
     465                 :          0 : }
     466                 :            : 
     467                 :          0 : static void bnxt_tx_cmp(struct bnxt_tx_queue *txq, int nr_pkts)
     468                 :            : {
     469                 :          0 :         struct bnxt_tx_ring_info *txr = txq->tx_ring;
     470                 :          0 :         struct bnxt_ring *ring = txr->tx_ring_struct;
     471                 :            :         struct rte_mempool *pool = NULL;
     472                 :          0 :         struct rte_mbuf **free = txq->free;
     473                 :          0 :         uint16_t raw_cons = txr->tx_raw_cons;
     474                 :            :         unsigned int blk = 0;
     475                 :            :         int i, j;
     476                 :            : 
     477         [ #  # ]:          0 :         for (i = 0; i < nr_pkts; i++) {
     478                 :            :                 struct rte_mbuf *mbuf;
     479                 :            :                 struct rte_mbuf **tx_buf;
     480                 :            :                 unsigned short nr_bds;
     481                 :            : 
     482                 :          0 :                 tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     483                 :          0 :                 nr_bds = txr->nr_bds[RING_IDX(ring, raw_cons)];
     484         [ #  # ]:          0 :                 for (j = 0; j < nr_bds; j++) {
     485                 :          0 :                         mbuf = *tx_buf;
     486                 :          0 :                         *tx_buf = NULL;
     487                 :          0 :                         raw_cons = RING_NEXT(raw_cons);
     488                 :          0 :                         tx_buf = &txr->tx_buf_ring[RING_IDX(ring, raw_cons)];
     489         [ #  # ]:          0 :                         if (!mbuf)      /* long_bd's tx_buf ? */
     490                 :          0 :                                 continue;
     491                 :            : 
     492                 :            :                         mbuf = rte_pktmbuf_prefree_seg(mbuf);
     493         [ #  # ]:          0 :                         if (unlikely(!mbuf))
     494                 :          0 :                                 continue;
     495                 :            : 
     496                 :            :                         /* EW - no need to unmap DMA memory? */
     497                 :            : 
     498         [ #  # ]:          0 :                         if (likely(mbuf->pool == pool)) {
     499                 :            :                                 /* Add mbuf to the bulk free array */
     500                 :          0 :                                 free[blk++] = mbuf;
     501                 :            :                         } else {
     502                 :            :                                 /* Found an mbuf from a different pool. Free
     503                 :            :                                  * mbufs accumulated so far to the previous
     504                 :            :                                  * pool
     505                 :            :                                  */
     506         [ #  # ]:          0 :                                 if (likely(pool != NULL))
     507                 :            :                                         rte_mempool_put_bulk(pool,
     508                 :            :                                                              (void *)free,
     509                 :            :                                                              blk);
     510                 :            : 
     511                 :            :                                 /* Start accumulating mbufs in a new pool */
     512                 :          0 :                                 free[0] = mbuf;
     513                 :          0 :                                 pool = mbuf->pool;
     514                 :            :                                 blk = 1;
     515                 :            :                         }
     516                 :            :                 }
     517                 :            :         }
     518         [ #  # ]:          0 :         if (blk)
     519                 :            :                 rte_mempool_put_bulk(pool, (void *)free, blk);
     520                 :            : 
     521                 :          0 :         txr->tx_raw_cons = raw_cons;
     522                 :          0 : }
     523                 :            : 
     524                 :          0 : static int bnxt_handle_tx_cp(struct bnxt_tx_queue *txq)
     525                 :            : {
     526                 :            :         uint32_t nb_tx_pkts = 0, cons, ring_mask, opaque;
     527                 :          0 :         struct bnxt_cp_ring_info *cpr = txq->cp_ring;
     528         [ #  # ]:          0 :         uint32_t raw_cons = cpr->cp_raw_cons;
     529                 :            :         struct bnxt_ring *cp_ring_struct;
     530                 :            :         struct tx_cmpl *txcmp;
     531                 :            : 
     532         [ #  # ]:          0 :         if (bnxt_tx_bds_in_hw(txq) < txq->tx_free_thresh)
     533                 :            :                 return 0;
     534                 :            : 
     535                 :          0 :         cp_ring_struct = cpr->cp_ring_struct;
     536                 :          0 :         ring_mask = cp_ring_struct->ring_mask;
     537                 :            : 
     538                 :            :         do {
     539                 :          0 :                 cons = RING_CMPL(ring_mask, raw_cons);
     540                 :          0 :                 txcmp = (struct tx_cmpl *)&cpr->cp_desc_ring[cons];
     541                 :            : 
     542         [ #  # ]:          0 :                 if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
     543                 :            :                         break;
     544                 :            : 
     545                 :          0 :                 opaque = rte_le_to_cpu_32(txcmp->opaque);
     546                 :            : 
     547         [ #  # ]:          0 :                 if (CMP_TYPE(txcmp) == TX_CMPL_TYPE_TX_L2)
     548                 :          0 :                         nb_tx_pkts += opaque;
     549                 :            :                 else
     550                 :          0 :                         RTE_LOG_DP(ERR, BNXT,
     551                 :            :                                         "Unhandled CMP type %02x\n",
     552                 :            :                                         CMP_TYPE(txcmp));
     553                 :          0 :                 raw_cons = NEXT_RAW_CMP(raw_cons);
     554         [ #  # ]:          0 :         } while (nb_tx_pkts < ring_mask);
     555                 :            : 
     556         [ #  # ]:          0 :         if (nb_tx_pkts) {
     557         [ #  # ]:          0 :                 if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE)
     558                 :          0 :                         bnxt_tx_cmp_fast(txq, nb_tx_pkts);
     559                 :            :                 else
     560                 :          0 :                         bnxt_tx_cmp(txq, nb_tx_pkts);
     561                 :          0 :                 cpr->cp_raw_cons = raw_cons;
     562                 :          0 :                 bnxt_db_cq(cpr);
     563                 :            :         }
     564                 :            : 
     565                 :          0 :         return nb_tx_pkts;
     566                 :            : }
     567                 :            : 
     568                 :          0 : uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     569                 :            :                                uint16_t nb_pkts)
     570                 :            : {
     571                 :            :         struct bnxt_tx_queue *txq = tx_queue;
     572                 :            :         uint16_t rc;
     573                 :            : 
     574                 :          0 :         pthread_mutex_lock(&txq->txq_lock);
     575                 :          0 :         rc = _bnxt_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
     576                 :          0 :         pthread_mutex_unlock(&txq->txq_lock);
     577                 :            : 
     578                 :          0 :         return rc;
     579                 :            : }
     580                 :            : 
     581                 :          0 : uint16_t _bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     582                 :            :                          uint16_t nb_pkts)
     583                 :            : {
     584                 :            :         int rc;
     585                 :            :         uint16_t nb_tx_pkts = 0;
     586                 :          0 :         uint16_t coal_pkts = 0;
     587                 :            :         struct bnxt_tx_queue *txq = tx_queue;
     588                 :          0 :         struct tx_bd_long *last_txbd = NULL;
     589                 :            : 
     590                 :            :         /* Handle TX completions */
     591                 :          0 :         bnxt_handle_tx_cp(txq);
     592                 :            : 
     593                 :            :         /* Tx queue was stopped; wait for it to be restarted */
     594         [ #  # ]:          0 :         if (unlikely(!txq->tx_started)) {
     595                 :          0 :                 PMD_DRV_LOG(DEBUG, "Tx q stopped;return\n");
     596                 :          0 :                 return 0;
     597                 :            :         }
     598                 :            : 
     599                 :            :         /* Handle TX burst request */
     600         [ #  # ]:          0 :         for (nb_tx_pkts = 0; nb_tx_pkts < nb_pkts; nb_tx_pkts++) {
     601                 :          0 :                 coal_pkts++;
     602                 :          0 :                 rc = bnxt_start_xmit(tx_pkts[nb_tx_pkts], txq,
     603                 :            :                                      &coal_pkts, &last_txbd);
     604                 :            : 
     605         [ #  # ]:          0 :                 if (unlikely(rc))
     606                 :            :                         break;
     607                 :            :         }
     608                 :            : 
     609         [ #  # ]:          0 :         if (likely(nb_tx_pkts)) {
     610                 :            :                 /* Request a completion on the last packet */
     611                 :          0 :                 last_txbd->flags_type &= ~TX_BD_LONG_FLAGS_NO_CMPL;
     612         [ #  # ]:          0 :                 bnxt_db_write(&txq->tx_ring->tx_db, txq->tx_ring->tx_raw_prod);
     613                 :            :         }
     614                 :            : 
     615                 :            :         return nb_tx_pkts;
     616                 :            : }
     617                 :            : 
     618                 :          0 : int bnxt_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     619                 :            : {
     620                 :          0 :         struct bnxt *bp = dev->data->dev_private;
     621                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
     622                 :            :         int rc = 0;
     623                 :            : 
     624                 :          0 :         rc = is_bnxt_in_error(bp);
     625         [ #  # ]:          0 :         if (rc)
     626                 :            :                 return rc;
     627                 :            : 
     628                 :            :         /* reset the previous stats for the tx_queue since the counters
     629                 :            :          * will be cleared when the queue is started.
     630                 :            :          */
     631                 :          0 :         memset(&bp->prev_tx_ring_stats[tx_queue_id], 0,
     632                 :            :                sizeof(struct bnxt_ring_stats));
     633                 :            : 
     634                 :          0 :         bnxt_free_hwrm_tx_ring(bp, tx_queue_id);
     635                 :          0 :         rc = bnxt_alloc_hwrm_tx_ring(bp, tx_queue_id);
     636         [ #  # ]:          0 :         if (rc)
     637                 :            :                 return rc;
     638                 :            : 
     639                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
     640                 :          0 :         txq->tx_started = true;
     641                 :          0 :         PMD_DRV_LOG(DEBUG, "Tx queue started\n");
     642                 :            : 
     643                 :          0 :         return 0;
     644                 :            : }
     645                 :            : 
     646                 :          0 : int bnxt_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
     647                 :            : {
     648                 :          0 :         struct bnxt *bp = dev->data->dev_private;
     649                 :          0 :         struct bnxt_tx_queue *txq = bp->tx_queues[tx_queue_id];
     650                 :            :         int rc = 0;
     651                 :            : 
     652                 :          0 :         rc = is_bnxt_in_error(bp);
     653         [ #  # ]:          0 :         if (rc)
     654                 :            :                 return rc;
     655                 :            : 
     656                 :            :         /* Handle TX completions */
     657                 :          0 :         bnxt_handle_tx_cp(txq);
     658                 :            : 
     659                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
     660                 :          0 :         txq->tx_started = false;
     661                 :          0 :         PMD_DRV_LOG(DEBUG, "Tx queue stopped\n");
     662                 :            : 
     663                 :          0 :         return 0;
     664                 :            : }
     665                 :            : 
     666                 :            : /* Sweep the Tx completion queue till HWRM_DONE for ring flush is received.
     667                 :            :  * The mbufs will not be freed in this call.
     668                 :            :  * They will be freed during ring free as a part of mem cleanup.
     669                 :            :  */
     670                 :          0 : int bnxt_flush_tx_cmp(struct bnxt_cp_ring_info *cpr)
     671                 :            : {
     672                 :          0 :         uint32_t raw_cons = cpr->cp_raw_cons;
     673                 :            :         uint32_t cons;
     674                 :            :         uint32_t nb_tx_pkts = 0;
     675                 :            :         struct tx_cmpl *txcmp;
     676                 :          0 :         struct cmpl_base *cp_desc_ring = cpr->cp_desc_ring;
     677                 :          0 :         struct bnxt_ring *cp_ring_struct = cpr->cp_ring_struct;
     678                 :          0 :         uint32_t ring_mask = cp_ring_struct->ring_mask;
     679                 :            :         uint32_t opaque = 0;
     680                 :            : 
     681                 :            :         do {
     682                 :          0 :                 cons = RING_CMPL(ring_mask, raw_cons);
     683                 :          0 :                 txcmp = (struct tx_cmpl *)&cp_desc_ring[cons];
     684                 :            : 
     685         [ #  # ]:          0 :                 if (!bnxt_cpr_cmp_valid(txcmp, raw_cons, ring_mask + 1))
     686                 :            :                         break;
     687                 :            : 
     688                 :          0 :                 opaque = rte_cpu_to_le_32(txcmp->opaque);
     689                 :          0 :                 raw_cons = NEXT_RAW_CMP(raw_cons);
     690                 :            : 
     691         [ #  # ]:          0 :                 if (CMP_TYPE(txcmp) == TX_CMPL_TYPE_TX_L2)
     692                 :          0 :                         nb_tx_pkts += opaque;
     693         [ #  # ]:          0 :                 else if (CMP_TYPE(txcmp) == HWRM_CMPL_TYPE_HWRM_DONE)
     694                 :            :                         return 1;
     695         [ #  # ]:          0 :         } while (nb_tx_pkts < ring_mask);
     696                 :            : 
     697         [ #  # ]:          0 :         if (nb_tx_pkts) {
     698                 :          0 :                 cpr->cp_raw_cons = raw_cons;
     699                 :          0 :                 bnxt_db_cq(cpr);
     700                 :            :         }
     701                 :            : 
     702                 :            :         return 0;
     703                 :            : }

Generated by: LCOV version 1.14