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

Generated by: LCOV version 1.14