LCOV - code coverage report
Current view: top level - drivers/net/txgbe - txgbe_rxtx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1950 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 95 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1120 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
       3                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <sys/queue.h>
       7                 :            : 
       8                 :            : #include <stdio.h>
       9                 :            : #include <stdlib.h>
      10                 :            : #include <string.h>
      11                 :            : #include <errno.h>
      12                 :            : #include <stdint.h>
      13                 :            : #include <stdarg.h>
      14                 :            : #include <unistd.h>
      15                 :            : #include <inttypes.h>
      16                 :            : 
      17                 :            : #include <rte_byteorder.h>
      18                 :            : #include <rte_common.h>
      19                 :            : #include <rte_cycles.h>
      20                 :            : #include <rte_log.h>
      21                 :            : #include <rte_debug.h>
      22                 :            : #include <rte_ethdev.h>
      23                 :            : #include <ethdev_driver.h>
      24                 :            : #include <rte_security_driver.h>
      25                 :            : #include <rte_memzone.h>
      26                 :            : #include <rte_atomic.h>
      27                 :            : #include <rte_mempool.h>
      28                 :            : #include <rte_malloc.h>
      29                 :            : #include <rte_mbuf.h>
      30                 :            : #include <rte_ether.h>
      31                 :            : #include <rte_prefetch.h>
      32                 :            : #include <rte_udp.h>
      33                 :            : #include <rte_tcp.h>
      34                 :            : #include <rte_sctp.h>
      35                 :            : #include <rte_string_fns.h>
      36                 :            : #include <rte_errno.h>
      37                 :            : #include <rte_ip.h>
      38                 :            : #include <rte_net.h>
      39                 :            : #include <rte_vect.h>
      40                 :            : 
      41                 :            : #include "txgbe_logs.h"
      42                 :            : #include "base/txgbe.h"
      43                 :            : #include "txgbe_ethdev.h"
      44                 :            : #include "txgbe_rxtx.h"
      45                 :            : 
      46                 :            : #ifdef RTE_LIBRTE_IEEE1588
      47                 :            : #define TXGBE_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
      48                 :            : #else
      49                 :            : #define TXGBE_TX_IEEE1588_TMST 0
      50                 :            : #endif
      51                 :            : 
      52                 :            : /* Bit Mask to indicate what bits required for building TX context */
      53                 :            : static const u64 TXGBE_TX_OFFLOAD_MASK = (RTE_MBUF_F_TX_IP_CKSUM |
      54                 :            :                 RTE_MBUF_F_TX_OUTER_IPV6 |
      55                 :            :                 RTE_MBUF_F_TX_OUTER_IPV4 |
      56                 :            :                 RTE_MBUF_F_TX_IPV6 |
      57                 :            :                 RTE_MBUF_F_TX_IPV4 |
      58                 :            :                 RTE_MBUF_F_TX_VLAN |
      59                 :            :                 RTE_MBUF_F_TX_L4_MASK |
      60                 :            :                 RTE_MBUF_F_TX_TCP_SEG |
      61                 :            :                 RTE_MBUF_F_TX_TUNNEL_MASK |
      62                 :            :                 RTE_MBUF_F_TX_OUTER_IP_CKSUM |
      63                 :            :                 RTE_MBUF_F_TX_OUTER_UDP_CKSUM |
      64                 :            : #ifdef RTE_LIB_SECURITY
      65                 :            :                 RTE_MBUF_F_TX_SEC_OFFLOAD |
      66                 :            : #endif
      67                 :            :                 TXGBE_TX_IEEE1588_TMST);
      68                 :            : 
      69                 :            : #define TXGBE_TX_OFFLOAD_NOTSUP_MASK \
      70                 :            :                 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ TXGBE_TX_OFFLOAD_MASK)
      71                 :            : 
      72                 :            : /*
      73                 :            :  * Prefetch a cache line into all cache levels.
      74                 :            :  */
      75                 :            : #define rte_txgbe_prefetch(p)   rte_prefetch0(p)
      76                 :            : 
      77                 :            : static int
      78                 :            : txgbe_is_vf(struct rte_eth_dev *dev)
      79                 :            : {
      80                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
      81                 :            : 
      82                 :          0 :         switch (hw->mac.type) {
      83                 :            :         case txgbe_mac_raptor_vf:
      84                 :            :                 return 1;
      85                 :            :         default:
      86                 :            :                 return 0;
      87                 :            :         }
      88                 :            : }
      89                 :            : 
      90                 :            : /*********************************************************************
      91                 :            :  *
      92                 :            :  *  TX functions
      93                 :            :  *
      94                 :            :  **********************************************************************/
      95                 :            : 
      96                 :            : /*
      97                 :            :  * Check for descriptors with their DD bit set and free mbufs.
      98                 :            :  * Return the total number of buffers freed.
      99                 :            :  */
     100                 :            : static __rte_always_inline int
     101                 :            : txgbe_tx_free_bufs(struct txgbe_tx_queue *txq)
     102                 :            : {
     103                 :            :         struct txgbe_tx_entry *txep;
     104                 :            :         uint32_t status;
     105                 :            :         int i, nb_free = 0;
     106                 :            :         struct rte_mbuf *m, *free[RTE_TXGBE_TX_MAX_FREE_BUF_SZ];
     107                 :            : 
     108                 :            :         /* check DD bit on threshold descriptor */
     109                 :          0 :         status = txq->tx_ring[txq->tx_next_dd].dw3;
     110   [ #  #  #  # ]:          0 :         if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
     111   [ #  #  #  # ]:          0 :                 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
     112                 :          0 :                         txgbe_set32_masked(txq->tdc_reg_addr,
     113                 :            :                                 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
     114                 :            :                 return 0;
     115                 :            :         }
     116                 :            : 
     117                 :            :         /*
     118                 :            :          * first buffer to free from S/W ring is at index
     119                 :            :          * tx_next_dd - (tx_free_thresh-1)
     120                 :            :          */
     121                 :          0 :         txep = &txq->sw_ring[txq->tx_next_dd - (txq->tx_free_thresh - 1)];
     122   [ #  #  #  # ]:          0 :         for (i = 0; i < txq->tx_free_thresh; ++i, ++txep) {
     123                 :            :                 /* free buffers one at a time */
     124                 :          0 :                 m = rte_pktmbuf_prefree_seg(txep->mbuf);
     125                 :          0 :                 txep->mbuf = NULL;
     126                 :            : 
     127   [ #  #  #  # ]:          0 :                 if (unlikely(m == NULL))
     128                 :          0 :                         continue;
     129                 :            : 
     130   [ #  #  #  #  :          0 :                 if (nb_free >= RTE_TXGBE_TX_MAX_FREE_BUF_SZ ||
             #  #  #  # ]
     131   [ #  #  #  # ]:          0 :                     (nb_free > 0 && m->pool != free[0]->pool)) {
     132   [ #  #  #  # ]:          0 :                         rte_mempool_put_bulk(free[0]->pool,
     133                 :            :                                              (void **)free, nb_free);
     134                 :            :                         nb_free = 0;
     135                 :            :                 }
     136                 :            : 
     137                 :          0 :                 free[nb_free++] = m;
     138                 :            :         }
     139                 :            : 
     140   [ #  #  #  # ]:          0 :         if (nb_free > 0)
     141   [ #  #  #  # ]:          0 :                 rte_mempool_put_bulk(free[0]->pool, (void **)free, nb_free);
     142                 :            : 
     143                 :            :         /* buffers were freed, update counters */
     144                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_free_thresh);
     145                 :          0 :         txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_free_thresh);
     146   [ #  #  #  # ]:          0 :         if (txq->tx_next_dd >= txq->nb_tx_desc)
     147                 :          0 :                 txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
     148                 :            : 
     149                 :          0 :         return txq->tx_free_thresh;
     150                 :            : }
     151                 :            : 
     152                 :            : /* Populate 4 descriptors with data from 4 mbufs */
     153                 :            : static inline void
     154                 :          0 : tx4(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
     155                 :            : {
     156                 :            :         uint64_t buf_dma_addr;
     157                 :            :         uint32_t pkt_len;
     158                 :            :         int i;
     159                 :            : 
     160         [ #  # ]:          0 :         for (i = 0; i < 4; ++i, ++txdp, ++pkts) {
     161         [ #  # ]:          0 :                 buf_dma_addr = rte_mbuf_data_iova(*pkts);
     162                 :          0 :                 pkt_len = (*pkts)->data_len;
     163         [ #  # ]:          0 :                 if (pkt_len < RTE_ETHER_HDR_LEN)
     164                 :            :                         pkt_len = TXGBE_FRAME_SIZE_DFT;
     165                 :            : 
     166                 :            :                 /* write data to descriptor */
     167                 :          0 :                 txdp->qw0 = rte_cpu_to_le_64(buf_dma_addr);
     168                 :          0 :                 txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
     169                 :            :                                         TXGBE_TXD_DATLEN(pkt_len));
     170                 :          0 :                 txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
     171                 :            : 
     172                 :          0 :                 rte_prefetch0(&(*pkts)->pool);
     173                 :            :         }
     174                 :          0 : }
     175                 :            : 
     176                 :            : /* Populate 1 descriptor with data from 1 mbuf */
     177                 :            : static inline void
     178                 :            : tx1(volatile struct txgbe_tx_desc *txdp, struct rte_mbuf **pkts)
     179                 :            : {
     180                 :            :         uint64_t buf_dma_addr;
     181                 :            :         uint32_t pkt_len;
     182                 :            : 
     183                 :            :         buf_dma_addr = rte_mbuf_data_iova(*pkts);
     184                 :          0 :         pkt_len = (*pkts)->data_len;
     185         [ #  # ]:          0 :         if (pkt_len < RTE_ETHER_HDR_LEN)
     186                 :            :                 pkt_len = TXGBE_FRAME_SIZE_DFT;
     187                 :            : 
     188                 :            :         /* write data to descriptor */
     189                 :          0 :         txdp->qw0 = cpu_to_le64(buf_dma_addr);
     190                 :          0 :         txdp->dw2 = cpu_to_le32(TXGBE_TXD_FLAGS |
     191                 :            :                                 TXGBE_TXD_DATLEN(pkt_len));
     192                 :          0 :         txdp->dw3 = cpu_to_le32(TXGBE_TXD_PAYLEN(pkt_len));
     193                 :            : 
     194                 :          0 :         rte_prefetch0(&(*pkts)->pool);
     195                 :            : }
     196                 :            : 
     197                 :            : /*
     198                 :            :  * Fill H/W descriptor ring with mbuf data.
     199                 :            :  * Copy mbuf pointers to the S/W ring.
     200                 :            :  */
     201                 :            : static inline void
     202                 :          0 : txgbe_tx_fill_hw_ring(struct txgbe_tx_queue *txq, struct rte_mbuf **pkts,
     203                 :            :                       uint16_t nb_pkts)
     204                 :            : {
     205                 :          0 :         volatile struct txgbe_tx_desc *txdp = &txq->tx_ring[txq->tx_tail];
     206                 :          0 :         struct txgbe_tx_entry *txep = &txq->sw_ring[txq->tx_tail];
     207                 :            :         const int N_PER_LOOP = 4;
     208                 :            :         const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
     209                 :            :         int mainpart, leftover;
     210                 :            :         int i, j;
     211                 :            : 
     212                 :            :         /*
     213                 :            :          * Process most of the packets in chunks of N pkts.  Any
     214                 :            :          * leftover packets will get processed one at a time.
     215                 :            :          */
     216                 :          0 :         mainpart = (nb_pkts & ((uint32_t)~N_PER_LOOP_MASK));
     217                 :          0 :         leftover = (nb_pkts & ((uint32_t)N_PER_LOOP_MASK));
     218         [ #  # ]:          0 :         for (i = 0; i < mainpart; i += N_PER_LOOP) {
     219                 :            :                 /* Copy N mbuf pointers to the S/W ring */
     220         [ #  # ]:          0 :                 for (j = 0; j < N_PER_LOOP; ++j)
     221                 :          0 :                         (txep + i + j)->mbuf = *(pkts + i + j);
     222                 :          0 :                 tx4(txdp + i, pkts + i);
     223                 :            :         }
     224                 :            : 
     225         [ #  # ]:          0 :         if (unlikely(leftover > 0)) {
     226         [ #  # ]:          0 :                 for (i = 0; i < leftover; ++i) {
     227                 :          0 :                         (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
     228         [ #  # ]:          0 :                         tx1(txdp + mainpart + i, pkts + mainpart + i);
     229                 :            :                 }
     230                 :            :         }
     231                 :          0 : }
     232                 :            : 
     233                 :            : static inline uint16_t
     234                 :          0 : tx_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     235                 :            :              uint16_t nb_pkts)
     236                 :            : {
     237                 :            :         struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
     238                 :            :         uint16_t n = 0;
     239                 :            : 
     240                 :            :         /*
     241                 :            :          * Begin scanning the H/W ring for done descriptors when the
     242                 :            :          * number of available descriptors drops below tx_free_thresh.  For
     243                 :            :          * each done descriptor, free the associated buffer.
     244                 :            :          */
     245         [ #  # ]:          0 :         if (txq->nb_tx_free < txq->tx_free_thresh)
     246                 :            :                 txgbe_tx_free_bufs(txq);
     247                 :            : 
     248                 :            :         /* Only use descriptors that are available */
     249                 :          0 :         nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
     250         [ #  # ]:          0 :         if (unlikely(nb_pkts == 0))
     251                 :            :                 return 0;
     252                 :            : 
     253                 :            :         /* Use exactly nb_pkts descriptors */
     254                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
     255                 :            : 
     256                 :            :         /*
     257                 :            :          * At this point, we know there are enough descriptors in the
     258                 :            :          * ring to transmit all the packets.  This assumes that each
     259                 :            :          * mbuf contains a single segment, and that no new offloads
     260                 :            :          * are expected, which would require a new context descriptor.
     261                 :            :          */
     262                 :            : 
     263                 :            :         /*
     264                 :            :          * See if we're going to wrap-around. If so, handle the top
     265                 :            :          * of the descriptor ring first, then do the bottom.  If not,
     266                 :            :          * the processing looks just like the "bottom" part anyway...
     267                 :            :          */
     268         [ #  # ]:          0 :         if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
     269                 :          0 :                 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
     270                 :          0 :                 txgbe_tx_fill_hw_ring(txq, tx_pkts, n);
     271                 :          0 :                 txq->tx_tail = 0;
     272                 :            :         }
     273                 :            : 
     274                 :            :         /* Fill H/W descriptor ring with mbuf data */
     275                 :          0 :         txgbe_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
     276                 :          0 :         txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
     277                 :            : 
     278                 :            :         /*
     279                 :            :          * Check for wrap-around. This would only happen if we used
     280                 :            :          * up to the last descriptor in the ring, no more, no less.
     281                 :            :          */
     282         [ #  # ]:          0 :         if (txq->tx_tail >= txq->nb_tx_desc)
     283                 :          0 :                 txq->tx_tail = 0;
     284                 :            : 
     285                 :            :         PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
     286                 :            :                    (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
     287                 :            :                    (uint16_t)txq->tx_tail, (uint16_t)nb_pkts);
     288                 :            : 
     289                 :            :         /* update tail pointer */
     290                 :            :         rte_wmb();
     291                 :          0 :         txgbe_set32_relaxed(txq->tdt_reg_addr, txq->tx_tail);
     292                 :            : 
     293                 :          0 :         return nb_pkts;
     294                 :            : }
     295                 :            : 
     296                 :            : uint16_t
     297                 :          0 : txgbe_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
     298                 :            :                        uint16_t nb_pkts)
     299                 :            : {
     300                 :            :         uint16_t nb_tx;
     301                 :            : 
     302                 :            :         /* Try to transmit at least chunks of TX_MAX_BURST pkts */
     303         [ #  # ]:          0 :         if (likely(nb_pkts <= RTE_PMD_TXGBE_TX_MAX_BURST))
     304                 :          0 :                 return tx_xmit_pkts(tx_queue, tx_pkts, nb_pkts);
     305                 :            : 
     306                 :            :         /* transmit more than the max burst, in chunks of TX_MAX_BURST */
     307                 :            :         nb_tx = 0;
     308         [ #  # ]:          0 :         while (nb_pkts) {
     309                 :            :                 uint16_t ret, n;
     310                 :            : 
     311                 :          0 :                 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_TX_MAX_BURST);
     312                 :          0 :                 ret = tx_xmit_pkts(tx_queue, &tx_pkts[nb_tx], n);
     313                 :          0 :                 nb_tx = (uint16_t)(nb_tx + ret);
     314                 :          0 :                 nb_pkts = (uint16_t)(nb_pkts - ret);
     315         [ #  # ]:          0 :                 if (ret < n)
     316                 :            :                         break;
     317                 :            :         }
     318                 :            : 
     319                 :            :         return nb_tx;
     320                 :            : }
     321                 :            : 
     322                 :            : static uint16_t
     323                 :          0 : txgbe_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
     324                 :            :                     uint16_t nb_pkts)
     325                 :            : {
     326                 :            :         struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
     327                 :            :         uint16_t nb_tx = 0;
     328                 :            : 
     329         [ #  # ]:          0 :         while (nb_pkts) {
     330                 :            :                 uint16_t ret, num;
     331                 :            : 
     332                 :          0 :                 num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_free_thresh);
     333                 :          0 :                 ret = txgbe_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx], num);
     334                 :          0 :                 nb_tx += ret;
     335                 :          0 :                 nb_pkts -= ret;
     336         [ #  # ]:          0 :                 if (ret < num)
     337                 :            :                         break;
     338                 :            :         }
     339                 :            : 
     340                 :          0 :         return nb_tx;
     341                 :            : }
     342                 :            : 
     343                 :            : static inline void
     344                 :          0 : txgbe_set_xmit_ctx(struct txgbe_tx_queue *txq,
     345                 :            :                 volatile struct txgbe_tx_ctx_desc *ctx_txd,
     346                 :            :                 uint64_t ol_flags, union txgbe_tx_offload tx_offload,
     347                 :            :                 __rte_unused uint64_t *mdata)
     348                 :            : {
     349                 :            :         union txgbe_tx_offload tx_offload_mask;
     350                 :            :         uint32_t type_tucmd_mlhl;
     351                 :            :         uint32_t mss_l4len_idx;
     352                 :            :         uint32_t ctx_idx;
     353                 :            :         uint32_t vlan_macip_lens;
     354                 :            :         uint32_t tunnel_seed;
     355                 :            : 
     356                 :          0 :         ctx_idx = txq->ctx_curr;
     357                 :          0 :         tx_offload_mask.data[0] = 0;
     358                 :          0 :         tx_offload_mask.data[1] = 0;
     359                 :            : 
     360                 :            :         /* Specify which HW CTX to upload. */
     361                 :          0 :         mss_l4len_idx = TXGBE_TXD_IDX(ctx_idx);
     362                 :            :         type_tucmd_mlhl = TXGBE_TXD_CTXT;
     363                 :            : 
     364                 :          0 :         tx_offload_mask.ptid |= ~0;
     365                 :          0 :         type_tucmd_mlhl |= TXGBE_TXD_PTID(tx_offload.ptid);
     366                 :            : 
     367                 :            :         /* check if TCP segmentation required for this packet */
     368         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
     369                 :          0 :                 tx_offload_mask.l2_len |= ~0;
     370                 :          0 :                 tx_offload_mask.l3_len |= ~0;
     371                 :          0 :                 tx_offload_mask.l4_len |= ~0;
     372                 :          0 :                 tx_offload_mask.tso_segsz |= ~0;
     373                 :          0 :                 mss_l4len_idx |= TXGBE_TXD_MSS(tx_offload.tso_segsz);
     374                 :          0 :                 mss_l4len_idx |= TXGBE_TXD_L4LEN(tx_offload.l4_len);
     375                 :            :         } else { /* no TSO, check if hardware checksum is needed */
     376         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
     377                 :          0 :                         tx_offload_mask.l2_len |= ~0;
     378                 :          0 :                         tx_offload_mask.l3_len |= ~0;
     379                 :            :                 }
     380                 :            : 
     381   [ #  #  #  # ]:          0 :                 switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
     382                 :          0 :                 case RTE_MBUF_F_TX_UDP_CKSUM:
     383                 :          0 :                         mss_l4len_idx |=
     384                 :            :                                 TXGBE_TXD_L4LEN(sizeof(struct rte_udp_hdr));
     385                 :          0 :                         tx_offload_mask.l2_len |= ~0;
     386                 :          0 :                         tx_offload_mask.l3_len |= ~0;
     387                 :          0 :                         break;
     388                 :          0 :                 case RTE_MBUF_F_TX_TCP_CKSUM:
     389                 :          0 :                         mss_l4len_idx |=
     390                 :            :                                 TXGBE_TXD_L4LEN(sizeof(struct rte_tcp_hdr));
     391                 :          0 :                         tx_offload_mask.l2_len |= ~0;
     392                 :          0 :                         tx_offload_mask.l3_len |= ~0;
     393                 :          0 :                         break;
     394                 :          0 :                 case RTE_MBUF_F_TX_SCTP_CKSUM:
     395                 :          0 :                         mss_l4len_idx |=
     396                 :            :                                 TXGBE_TXD_L4LEN(sizeof(struct rte_sctp_hdr));
     397                 :          0 :                         tx_offload_mask.l2_len |= ~0;
     398                 :          0 :                         tx_offload_mask.l3_len |= ~0;
     399                 :          0 :                         break;
     400                 :            :                 default:
     401                 :            :                         break;
     402                 :            :                 }
     403                 :            :         }
     404                 :            : 
     405                 :          0 :         vlan_macip_lens = TXGBE_TXD_IPLEN(tx_offload.l3_len >> 1);
     406                 :            : 
     407         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
     408                 :          0 :                 tx_offload_mask.outer_tun_len |= ~0;
     409                 :          0 :                 tx_offload_mask.outer_l2_len |= ~0;
     410                 :          0 :                 tx_offload_mask.outer_l3_len |= ~0;
     411                 :          0 :                 tx_offload_mask.l2_len |= ~0;
     412                 :          0 :                 tunnel_seed = TXGBE_TXD_ETUNLEN(tx_offload.outer_tun_len >> 1);
     413                 :          0 :                 tunnel_seed |= TXGBE_TXD_EIPLEN(tx_offload.outer_l3_len >> 2);
     414                 :            : 
     415      [ #  #  # ]:          0 :                 switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
     416                 :            :                 case RTE_MBUF_F_TX_TUNNEL_IPIP:
     417                 :            :                         /* for non UDP / GRE tunneling, set to 0b */
     418                 :            :                         break;
     419                 :            :                 case RTE_MBUF_F_TX_TUNNEL_VXLAN:
     420                 :            :                 case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
     421                 :            :                 case RTE_MBUF_F_TX_TUNNEL_GENEVE:
     422                 :            :                         tunnel_seed |= TXGBE_TXD_ETYPE_UDP;
     423                 :            :                         break;
     424                 :          0 :                 case RTE_MBUF_F_TX_TUNNEL_GRE:
     425                 :          0 :                         tunnel_seed |= TXGBE_TXD_ETYPE_GRE;
     426                 :          0 :                         break;
     427                 :          0 :                 default:
     428                 :            :                         PMD_TX_LOG(ERR, "Tunnel type not supported");
     429                 :          0 :                         return;
     430                 :            :                 }
     431                 :          0 :                 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.outer_l2_len);
     432                 :            :         } else {
     433                 :            :                 tunnel_seed = 0;
     434                 :          0 :                 vlan_macip_lens |= TXGBE_TXD_MACLEN(tx_offload.l2_len);
     435                 :            :         }
     436                 :            : 
     437         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_VLAN) {
     438                 :          0 :                 tx_offload_mask.vlan_tci |= ~0;
     439                 :          0 :                 vlan_macip_lens |= TXGBE_TXD_VLAN(tx_offload.vlan_tci);
     440                 :            :         }
     441                 :            : 
     442                 :            : #ifdef RTE_LIB_SECURITY
     443         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD) {
     444                 :            :                 union txgbe_crypto_tx_desc_md *md =
     445                 :            :                                 (union txgbe_crypto_tx_desc_md *)mdata;
     446                 :          0 :                 tunnel_seed |= TXGBE_TXD_IPSEC_SAIDX(md->sa_idx);
     447                 :          0 :                 type_tucmd_mlhl |= md->enc ?
     448         [ #  # ]:          0 :                         (TXGBE_TXD_IPSEC_ESP | TXGBE_TXD_IPSEC_ESPENC) : 0;
     449                 :          0 :                 type_tucmd_mlhl |= TXGBE_TXD_IPSEC_ESPLEN(md->pad_len);
     450                 :          0 :                 tx_offload_mask.sa_idx |= ~0;
     451                 :          0 :                 tx_offload_mask.sec_pad_len |= ~0;
     452                 :            :         }
     453                 :            : #endif
     454                 :            : 
     455                 :          0 :         txq->ctx_cache[ctx_idx].flags = ol_flags;
     456                 :          0 :         txq->ctx_cache[ctx_idx].tx_offload.data[0] =
     457                 :          0 :                 tx_offload_mask.data[0] & tx_offload.data[0];
     458                 :          0 :         txq->ctx_cache[ctx_idx].tx_offload.data[1] =
     459                 :          0 :                 tx_offload_mask.data[1] & tx_offload.data[1];
     460                 :          0 :         txq->ctx_cache[ctx_idx].tx_offload_mask = tx_offload_mask;
     461                 :            : 
     462                 :          0 :         ctx_txd->dw0 = rte_cpu_to_le_32(vlan_macip_lens);
     463                 :          0 :         ctx_txd->dw1 = rte_cpu_to_le_32(tunnel_seed);
     464                 :          0 :         ctx_txd->dw2 = rte_cpu_to_le_32(type_tucmd_mlhl);
     465                 :          0 :         ctx_txd->dw3 = rte_cpu_to_le_32(mss_l4len_idx);
     466                 :            : }
     467                 :            : 
     468                 :            : /*
     469                 :            :  * Check which hardware context can be used. Use the existing match
     470                 :            :  * or create a new context descriptor.
     471                 :            :  */
     472                 :            : static inline uint32_t
     473                 :          0 : what_ctx_update(struct txgbe_tx_queue *txq, uint64_t flags,
     474                 :            :                    union txgbe_tx_offload tx_offload)
     475                 :            : {
     476                 :            :         /* If match with the current used context */
     477   [ #  #  #  #  :          0 :         if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
                   #  # ]
     478                 :            :                    (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
     479                 :            :                     (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
     480                 :            :                      & tx_offload.data[0])) &&
     481                 :            :                    (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
     482                 :            :                     (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
     483                 :            :                      & tx_offload.data[1]))))
     484                 :            :                 return txq->ctx_curr;
     485                 :            : 
     486                 :            :         /* What if match with the next context  */
     487                 :          0 :         txq->ctx_curr ^= 1;
     488   [ #  #  #  #  :          0 :         if (likely(txq->ctx_cache[txq->ctx_curr].flags == flags &&
                   #  # ]
     489                 :            :                    (txq->ctx_cache[txq->ctx_curr].tx_offload.data[0] ==
     490                 :            :                     (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[0]
     491                 :            :                      & tx_offload.data[0])) &&
     492                 :            :                    (txq->ctx_cache[txq->ctx_curr].tx_offload.data[1] ==
     493                 :            :                     (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data[1]
     494                 :            :                      & tx_offload.data[1]))))
     495                 :          0 :                 return txq->ctx_curr;
     496                 :            : 
     497                 :            :         /* Mismatch, use the previous context */
     498                 :            :         return TXGBE_CTX_NUM;
     499                 :            : }
     500                 :            : 
     501                 :            : static inline uint32_t
     502                 :          0 : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
     503                 :            : {
     504                 :            :         uint32_t tmp = 0;
     505                 :            : 
     506         [ #  # ]:          0 :         if ((ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_L4_NO_CKSUM) {
     507                 :            :                 tmp |= TXGBE_TXD_CC;
     508                 :            :                 tmp |= TXGBE_TXD_L4CS;
     509                 :            :         }
     510         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
     511                 :            :                 tmp |= TXGBE_TXD_CC;
     512                 :          0 :                 tmp |= TXGBE_TXD_IPCS;
     513                 :            :         }
     514         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) {
     515                 :            :                 tmp |= TXGBE_TXD_CC;
     516                 :          0 :                 tmp |= TXGBE_TXD_EIPCS;
     517                 :            :         }
     518         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
     519                 :          0 :                 tmp |= TXGBE_TXD_CC;
     520                 :            :                 /* implies IPv4 cksum */
     521         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_IPV4)
     522                 :          0 :                         tmp |= TXGBE_TXD_IPCS;
     523                 :          0 :                 tmp |= TXGBE_TXD_L4CS;
     524                 :            :         }
     525         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_VLAN)
     526                 :          0 :                 tmp |= TXGBE_TXD_CC;
     527                 :            : 
     528                 :          0 :         return tmp;
     529                 :            : }
     530                 :            : 
     531                 :            : static inline uint32_t
     532                 :            : tx_desc_ol_flags_to_cmdtype(uint64_t ol_flags)
     533                 :            : {
     534                 :            :         uint32_t cmdtype = 0;
     535                 :            : 
     536         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_VLAN)
     537                 :            :                 cmdtype |= TXGBE_TXD_VLE;
     538         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
     539                 :          0 :                 cmdtype |= TXGBE_TXD_TSE;
     540         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_MACSEC)
     541                 :          0 :                 cmdtype |= TXGBE_TXD_LINKSEC;
     542                 :            :         return cmdtype;
     543                 :            : }
     544                 :            : 
     545                 :            : static inline uint32_t
     546                 :          0 : tx_desc_ol_flags_to_ptype(uint64_t oflags)
     547                 :            : {
     548                 :            :         uint32_t ptype;
     549                 :            :         bool tun;
     550                 :            : 
     551                 :            :         /* Only support flags in TXGBE_TX_OFFLOAD_MASK */
     552                 :          0 :         tun = !!(oflags & RTE_MBUF_F_TX_TUNNEL_MASK);
     553                 :            : 
     554                 :            :         /* L2 level */
     555                 :            :         ptype = RTE_PTYPE_L2_ETHER;
     556         [ #  # ]:          0 :         if (oflags & RTE_MBUF_F_TX_VLAN)
     557         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER_VLAN);
     558                 :            : 
     559         [ #  # ]:          0 :         if (oflags & RTE_MBUF_F_TX_QINQ) /* tunnel + QINQ is not supported */
     560                 :          0 :                 ptype |= RTE_PTYPE_L2_ETHER_VLAN;
     561                 :            : 
     562                 :            :         /* L3 level */
     563         [ #  # ]:          0 :         if (oflags & (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IP_CKSUM))
     564                 :          0 :                 ptype |= RTE_PTYPE_L3_IPV4;
     565         [ #  # ]:          0 :         else if (oflags & (RTE_MBUF_F_TX_OUTER_IPV6))
     566                 :          0 :                 ptype |= RTE_PTYPE_L3_IPV6;
     567                 :            : 
     568         [ #  # ]:          0 :         if (oflags & (RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_IP_CKSUM))
     569         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV4 : RTE_PTYPE_L3_IPV4);
     570         [ #  # ]:          0 :         else if (oflags & (RTE_MBUF_F_TX_IPV6))
     571         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L3_IPV6 : RTE_PTYPE_L3_IPV6);
     572                 :            : 
     573                 :            :         /* L4 level */
     574   [ #  #  #  # ]:          0 :         switch (oflags & (RTE_MBUF_F_TX_L4_MASK)) {
     575                 :          0 :         case RTE_MBUF_F_TX_TCP_CKSUM:
     576         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
     577                 :          0 :                 break;
     578                 :          0 :         case RTE_MBUF_F_TX_UDP_CKSUM:
     579         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L4_UDP : RTE_PTYPE_L4_UDP);
     580                 :          0 :                 break;
     581                 :          0 :         case RTE_MBUF_F_TX_SCTP_CKSUM:
     582         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L4_SCTP : RTE_PTYPE_L4_SCTP);
     583                 :          0 :                 break;
     584                 :            :         }
     585                 :            : 
     586         [ #  # ]:          0 :         if (oflags & RTE_MBUF_F_TX_TCP_SEG)
     587         [ #  # ]:          0 :                 ptype |= (tun ? RTE_PTYPE_INNER_L4_TCP : RTE_PTYPE_L4_TCP);
     588                 :            : 
     589                 :            :         /* Tunnel */
     590   [ #  #  #  #  :          0 :         switch (oflags & RTE_MBUF_F_TX_TUNNEL_MASK) {
                      # ]
     591                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_VXLAN:
     592                 :            :         case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
     593                 :          0 :                 ptype |= RTE_PTYPE_TUNNEL_GRENAT;
     594                 :          0 :                 break;
     595                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_GRE:
     596                 :          0 :                 ptype |= RTE_PTYPE_TUNNEL_GRE;
     597                 :          0 :                 break;
     598                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_GENEVE:
     599                 :          0 :                 ptype |= RTE_PTYPE_TUNNEL_GENEVE;
     600                 :          0 :                 break;
     601                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_IPIP:
     602                 :            :         case RTE_MBUF_F_TX_TUNNEL_IP:
     603                 :          0 :                 ptype |= RTE_PTYPE_TUNNEL_IP;
     604                 :          0 :                 break;
     605                 :            :         }
     606                 :            : 
     607                 :          0 :         return ptype;
     608                 :            : }
     609                 :            : 
     610                 :            : static inline uint8_t
     611                 :            : tx_desc_ol_flags_to_ptid(uint64_t oflags)
     612                 :            : {
     613                 :            :         uint32_t ptype;
     614                 :            : 
     615                 :          0 :         ptype = tx_desc_ol_flags_to_ptype(oflags);
     616                 :            : 
     617                 :          0 :         return txgbe_encode_ptype(ptype);
     618                 :            : }
     619                 :            : 
     620                 :            : #ifndef DEFAULT_TX_FREE_THRESH
     621                 :            : #define DEFAULT_TX_FREE_THRESH 32
     622                 :            : #endif
     623                 :            : 
     624                 :            : /* Reset transmit descriptors after they have been used */
     625                 :            : static inline int
     626                 :          0 : txgbe_xmit_cleanup(struct txgbe_tx_queue *txq)
     627                 :            : {
     628                 :          0 :         struct txgbe_tx_entry *sw_ring = txq->sw_ring;
     629                 :          0 :         volatile struct txgbe_tx_desc *txr = txq->tx_ring;
     630                 :          0 :         uint16_t last_desc_cleaned = txq->last_desc_cleaned;
     631                 :          0 :         uint16_t nb_tx_desc = txq->nb_tx_desc;
     632                 :            :         uint16_t desc_to_clean_to;
     633                 :            :         uint16_t nb_tx_to_clean;
     634                 :            :         uint32_t status;
     635                 :            : 
     636                 :            :         /* Determine the last descriptor needing to be cleaned */
     637                 :          0 :         desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_free_thresh);
     638         [ #  # ]:          0 :         if (desc_to_clean_to >= nb_tx_desc)
     639                 :          0 :                 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
     640                 :            : 
     641                 :            :         /* Check to make sure the last descriptor to clean is done */
     642                 :          0 :         desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
     643                 :          0 :         status = txr[desc_to_clean_to].dw3;
     644         [ #  # ]:          0 :         if (!(status & rte_cpu_to_le_32(TXGBE_TXD_DD))) {
     645                 :            :                 PMD_TX_FREE_LOG(DEBUG,
     646                 :            :                                 "TX descriptor %4u is not done"
     647                 :            :                                 "(port=%d queue=%d)",
     648                 :            :                                 desc_to_clean_to,
     649                 :            :                                 txq->port_id, txq->queue_id);
     650         [ #  # ]:          0 :                 if (txq->nb_tx_free >> 1 < txq->tx_free_thresh)
     651                 :          0 :                         txgbe_set32_masked(txq->tdc_reg_addr,
     652                 :            :                                 TXGBE_TXCFG_FLUSH, TXGBE_TXCFG_FLUSH);
     653                 :            :                 /* Failed to clean any descriptors, better luck next time */
     654                 :          0 :                 return -(1);
     655                 :            :         }
     656                 :            : 
     657                 :            :         /* Figure out how many descriptors will be cleaned */
     658         [ #  # ]:          0 :         if (last_desc_cleaned > desc_to_clean_to)
     659                 :          0 :                 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
     660                 :            :                                                         desc_to_clean_to);
     661                 :            :         else
     662                 :          0 :                 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
     663                 :            :                                                 last_desc_cleaned);
     664                 :            : 
     665                 :            :         PMD_TX_FREE_LOG(DEBUG,
     666                 :            :                         "Cleaning %4u TX descriptors: %4u to %4u "
     667                 :            :                         "(port=%d queue=%d)",
     668                 :            :                         nb_tx_to_clean, last_desc_cleaned, desc_to_clean_to,
     669                 :            :                         txq->port_id, txq->queue_id);
     670                 :            : 
     671                 :            :         /*
     672                 :            :          * The last descriptor to clean is done, so that means all the
     673                 :            :          * descriptors from the last descriptor that was cleaned
     674                 :            :          * up to the last descriptor with the RS bit set
     675                 :            :          * are done. Only reset the threshold descriptor.
     676                 :            :          */
     677                 :          0 :         txr[desc_to_clean_to].dw3 = 0;
     678                 :            : 
     679                 :            :         /* Update the txq to reflect the last descriptor that was cleaned */
     680                 :          0 :         txq->last_desc_cleaned = desc_to_clean_to;
     681                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
     682                 :            : 
     683                 :            :         /* No Error */
     684                 :          0 :         return 0;
     685                 :            : }
     686                 :            : 
     687                 :            : #define GRE_CHECKSUM_PRESENT    0x8000
     688                 :            : #define GRE_KEY_PRESENT         0x2000
     689                 :            : #define GRE_SEQUENCE_PRESENT    0x1000
     690                 :            : #define GRE_EXT_LEN             4
     691                 :            : #define GRE_SUPPORTED_FIELDS    (GRE_CHECKSUM_PRESENT | GRE_KEY_PRESENT |\
     692                 :            :                                  GRE_SEQUENCE_PRESENT)
     693                 :            : 
     694                 :            : static inline uint8_t
     695                 :          0 : txgbe_get_tun_len(struct rte_mbuf *mbuf)
     696                 :            : {
     697                 :            :         struct txgbe_genevehdr genevehdr;
     698                 :            :         const struct txgbe_genevehdr *gh;
     699                 :            :         const struct txgbe_grehdr *grh;
     700                 :            :         struct txgbe_grehdr grehdr;
     701                 :            :         uint8_t tun_len;
     702                 :            : 
     703   [ #  #  #  # ]:          0 :         switch (mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
     704                 :            :         case RTE_MBUF_F_TX_TUNNEL_IPIP:
     705                 :            :                 tun_len = 0;
     706                 :            :                 break;
     707                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_VXLAN:
     708                 :            :         case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
     709                 :            :                 tun_len = sizeof(struct txgbe_udphdr)
     710                 :            :                         + sizeof(struct txgbe_vxlanhdr);
     711                 :          0 :                 break;
     712                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_GRE:
     713                 :            :                 tun_len = sizeof(struct txgbe_grehdr);
     714                 :          0 :                 grh = rte_pktmbuf_read(mbuf,
     715         [ #  # ]:          0 :                         mbuf->outer_l2_len + mbuf->outer_l3_len,
     716                 :            :                         sizeof(grehdr), &grehdr);
     717         [ #  # ]:          0 :                 if (grh->flags & rte_cpu_to_be_16(GRE_SUPPORTED_FIELDS))
     718                 :            :                         tun_len += GRE_EXT_LEN;
     719                 :            :                 break;
     720                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_GENEVE:
     721                 :          0 :                 gh = rte_pktmbuf_read(mbuf, mbuf->outer_l2_len +
     722         [ #  # ]:          0 :                         mbuf->outer_l3_len + sizeof(struct txgbe_udphdr),
     723                 :            :                         sizeof(genevehdr), &genevehdr);
     724                 :          0 :                 tun_len = sizeof(struct txgbe_udphdr)
     725                 :            :                         + sizeof(struct txgbe_genevehdr)
     726                 :          0 :                         + (gh->opt_len << 2);
     727                 :          0 :                 break;
     728                 :            :         default:
     729                 :            :                 tun_len = 0;
     730                 :            :         }
     731                 :            : 
     732                 :          0 :         return tun_len;
     733                 :            : }
     734                 :            : 
     735                 :            : static inline void
     736                 :          0 : txgbe_fix_offload_len(union txgbe_tx_offload *ol)
     737                 :            : {
     738                 :          0 :         uint8_t ptid = ol->ptid;
     739                 :            : 
     740         [ #  # ]:          0 :         if (ptid & TXGBE_PTID_PKT_TUN) {
     741         [ #  # ]:          0 :                 if (ol->outer_l2_len == 0)
     742                 :          0 :                         ol->outer_l2_len = sizeof(struct rte_ether_hdr);
     743         [ #  # ]:          0 :                 if (ol->outer_l3_len == 0) {
     744         [ #  # ]:          0 :                         if (ptid & TXGBE_PTID_TUN_IPV6)
     745                 :          0 :                                 ol->outer_l3_len = sizeof(struct rte_ipv6_hdr);
     746                 :            :                         else
     747                 :          0 :                                 ol->outer_l3_len = sizeof(struct rte_ipv4_hdr);
     748                 :            :                 }
     749         [ #  # ]:          0 :                 if ((ptid & 0xF) == 0) {
     750                 :          0 :                         ol->l3_len = 0;
     751                 :          0 :                         ol->l4_len = 0;
     752                 :            :                 } else {
     753                 :          0 :                         goto inner;
     754                 :            :                 }
     755                 :            :         }
     756                 :            : 
     757         [ #  # ]:          0 :         if ((ptid & 0xF0) == TXGBE_PTID_PKT_MAC) {
     758         [ #  # ]:          0 :                 if (ol->l2_len == 0)
     759                 :          0 :                         ol->l2_len = sizeof(struct rte_ether_hdr);
     760                 :          0 :                 ol->l3_len = 0;
     761                 :          0 :                 ol->l4_len = 0;
     762         [ #  # ]:          0 :         } else if ((ptid & 0xF0) == TXGBE_PTID_PKT_IP) {
     763         [ #  # ]:          0 :                 if (ol->l2_len == 0)
     764                 :          0 :                         ol->l2_len = sizeof(struct rte_ether_hdr);
     765                 :          0 : inner:
     766         [ #  # ]:          0 :                 if (ol->l3_len == 0) {
     767         [ #  # ]:          0 :                         if (ptid & TXGBE_PTID_PKT_IPV6)
     768                 :          0 :                                 ol->l3_len = sizeof(struct rte_ipv6_hdr);
     769                 :            :                         else
     770                 :          0 :                                 ol->l3_len = sizeof(struct rte_ipv4_hdr);
     771                 :            :                 }
     772   [ #  #  #  #  :          0 :                 switch (ptid & 0x7) {
                      # ]
     773                 :          0 :                 case 0x1:
     774                 :            :                 case 0x2:
     775                 :          0 :                         ol->l4_len = 0;
     776                 :          0 :                         break;
     777                 :          0 :                 case 0x3:
     778         [ #  # ]:          0 :                         if (ol->l4_len == 0)
     779                 :          0 :                                 ol->l4_len =  sizeof(struct rte_udp_hdr);
     780                 :            :                         break;
     781                 :          0 :                 case 0x4:
     782         [ #  # ]:          0 :                         if (ol->l4_len == 0)
     783                 :          0 :                                 ol->l4_len =  sizeof(struct rte_tcp_hdr);
     784                 :            :                         break;
     785                 :          0 :                 case 0x5:
     786         [ #  # ]:          0 :                         if (ol->l4_len == 0)
     787                 :          0 :                                 ol->l4_len =  sizeof(struct rte_sctp_hdr);
     788                 :            :                         break;
     789                 :            :                 default:
     790                 :            :                         break;
     791                 :            :                 }
     792                 :            :         }
     793                 :          0 : }
     794                 :            : 
     795                 :            : static inline uint8_t
     796                 :            : txgbe_parse_tun_ptid(struct rte_mbuf *tx_pkt, uint8_t tun_len)
     797                 :            : {
     798                 :            :         uint64_t inner_l2_len;
     799                 :            :         uint8_t ptid = 0;
     800                 :            : 
     801                 :          0 :         inner_l2_len = tx_pkt->l2_len - tun_len;
     802                 :            : 
     803                 :            :         switch (inner_l2_len) {
     804                 :            :         case 0:
     805                 :            :                 ptid = TXGBE_PTID_TUN_EIG;
     806                 :            :                 break;
     807                 :            :         case sizeof(struct rte_ether_hdr):
     808                 :            :                 ptid = TXGBE_PTID_TUN_EIGM;
     809                 :            :                 break;
     810                 :            :         case sizeof(struct rte_ether_hdr) + sizeof(struct rte_vlan_hdr):
     811                 :            :                 ptid = TXGBE_PTID_TUN_EIGMV;
     812                 :            :                 break;
     813                 :            :         default:
     814                 :            :                 ptid = TXGBE_PTID_TUN_EI;
     815                 :            :         }
     816                 :            : 
     817                 :            :         return ptid;
     818                 :            : }
     819                 :            : 
     820                 :            : static inline bool
     821                 :            : txgbe_check_pkt_err(struct rte_mbuf *tx_pkt)
     822                 :            : {
     823                 :            :         uint32_t total_len = 0, nb_seg = 0;
     824                 :            :         struct rte_mbuf *mseg;
     825                 :            : 
     826                 :            :         mseg = tx_pkt;
     827                 :            :         do {
     828         [ #  # ]:          0 :                 if (mseg->data_len == 0)
     829                 :            :                         return true;
     830                 :          0 :                 total_len += mseg->data_len;
     831                 :          0 :                 nb_seg++;
     832                 :          0 :                 mseg = mseg->next;
     833         [ #  # ]:          0 :         } while (mseg != NULL);
     834                 :            : 
     835   [ #  #  #  # ]:          0 :         if (tx_pkt->pkt_len != total_len || tx_pkt->pkt_len == 0)
     836                 :            :                 return true;
     837                 :            : 
     838   [ #  #  #  # ]:          0 :         if (tx_pkt->nb_segs != nb_seg || tx_pkt->nb_segs > 64)
     839                 :            :                 return true;
     840                 :            : 
     841                 :            :         return false;
     842                 :            : }
     843                 :            : 
     844                 :            : uint16_t
     845                 :          0 : txgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     846                 :            :                 uint16_t nb_pkts)
     847                 :            : {
     848                 :            :         struct txgbe_tx_queue *txq;
     849                 :            :         struct txgbe_tx_entry *sw_ring;
     850                 :            :         struct txgbe_tx_entry *txe, *txn;
     851                 :            :         volatile struct txgbe_tx_desc *txr;
     852                 :            :         volatile struct txgbe_tx_desc *txd;
     853                 :            :         struct rte_mbuf     *tx_pkt;
     854                 :            :         struct rte_mbuf     *m_seg;
     855                 :            :         uint64_t buf_dma_addr;
     856                 :            :         uint32_t olinfo_status;
     857                 :            :         uint32_t cmd_type_len;
     858                 :            :         uint32_t pkt_len;
     859                 :            :         uint16_t slen;
     860                 :            :         uint64_t ol_flags;
     861                 :            :         uint16_t tx_id;
     862                 :            :         uint16_t tx_last;
     863                 :            :         uint16_t nb_tx;
     864                 :            :         uint16_t nb_used;
     865                 :            :         uint64_t tx_ol_req;
     866                 :            :         uint32_t ctx = 0;
     867                 :            :         uint32_t new_ctx;
     868                 :            :         union txgbe_tx_offload tx_offload;
     869                 :            : #ifdef RTE_LIB_SECURITY
     870                 :            :         uint8_t use_ipsec;
     871                 :            : #endif
     872                 :            : 
     873                 :            :         txq = tx_queue;
     874         [ #  # ]:          0 :         if (txq->resetting)
     875                 :            :                 return 0;
     876                 :            : 
     877                 :          0 :         tx_offload.data[0] = 0;
     878                 :          0 :         tx_offload.data[1] = 0;
     879                 :            :         txq = tx_queue;
     880                 :          0 :         sw_ring = txq->sw_ring;
     881                 :          0 :         txr     = txq->tx_ring;
     882                 :          0 :         tx_id   = txq->tx_tail;
     883                 :          0 :         txe = &sw_ring[tx_id];
     884                 :            : 
     885                 :            :         /* Determine if the descriptor ring needs to be cleaned. */
     886         [ #  # ]:          0 :         if (txq->nb_tx_free < txq->tx_free_thresh)
     887                 :          0 :                 txgbe_xmit_cleanup(txq);
     888                 :            : 
     889                 :          0 :         rte_prefetch0(&txe->mbuf->pool);
     890                 :            : 
     891                 :            :         /* TX loop */
     892         [ #  # ]:          0 :         for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
     893                 :            :                 new_ctx = 0;
     894                 :          0 :                 tx_pkt = *tx_pkts++;
     895                 :          0 :                 if (txgbe_check_pkt_err(tx_pkt)) {
     896                 :          0 :                         rte_pktmbuf_free(tx_pkt);
     897                 :          0 :                         txq->desc_error++;
     898                 :          0 :                         continue;
     899                 :            :                 }
     900                 :            : 
     901                 :          0 :                 pkt_len = tx_pkt->pkt_len;
     902                 :            : 
     903                 :            :                 /*
     904                 :            :                  * Determine how many (if any) context descriptors
     905                 :            :                  * are needed for offload functionality.
     906                 :            :                  */
     907                 :          0 :                 ol_flags = tx_pkt->ol_flags;
     908                 :            : #ifdef RTE_LIB_SECURITY
     909   [ #  #  #  # ]:          0 :                 use_ipsec = txq->using_ipsec && (ol_flags & RTE_MBUF_F_TX_SEC_OFFLOAD);
     910                 :            : #endif
     911                 :            : 
     912                 :            :                 /* If hardware offload required */
     913                 :          0 :                 tx_ol_req = ol_flags & TXGBE_TX_OFFLOAD_MASK;
     914         [ #  # ]:          0 :                 if (tx_ol_req) {
     915                 :          0 :                         tx_offload.ptid = tx_desc_ol_flags_to_ptid(tx_ol_req);
     916                 :          0 :                         tx_offload.l2_len = tx_pkt->l2_len;
     917                 :          0 :                         tx_offload.l3_len = tx_pkt->l3_len;
     918                 :          0 :                         tx_offload.l4_len = tx_pkt->l4_len;
     919                 :          0 :                         tx_offload.vlan_tci = tx_pkt->vlan_tci;
     920                 :          0 :                         tx_offload.tso_segsz = tx_pkt->tso_segsz;
     921                 :          0 :                         tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
     922                 :          0 :                         tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
     923                 :          0 :                         tx_offload.outer_tun_len = txgbe_get_tun_len(tx_pkt);
     924         [ #  # ]:          0 :                         if (tx_offload.ptid & TXGBE_PTID_PKT_TUN)
     925         [ #  # ]:          0 :                                 tx_offload.ptid |= txgbe_parse_tun_ptid(tx_pkt,
     926                 :            :                                                         tx_offload.outer_tun_len);
     927                 :          0 :                         txgbe_fix_offload_len(&tx_offload);
     928                 :            : 
     929                 :            : #ifdef RTE_LIB_SECURITY
     930         [ #  # ]:          0 :                         if (use_ipsec) {
     931                 :            :                                 union txgbe_crypto_tx_desc_md *ipsec_mdata =
     932                 :            :                                         (union txgbe_crypto_tx_desc_md *)
     933                 :            :                                                 rte_security_dynfield(tx_pkt);
     934                 :          0 :                                 tx_offload.sa_idx = ipsec_mdata->sa_idx;
     935                 :          0 :                                 tx_offload.sec_pad_len = ipsec_mdata->pad_len;
     936                 :            :                         }
     937                 :            : #endif
     938                 :            : 
     939                 :            :                         /* If new context need be built or reuse the exist ctx*/
     940                 :          0 :                         ctx = what_ctx_update(txq, tx_ol_req, tx_offload);
     941                 :            :                         /* Only allocate context descriptor if required */
     942                 :          0 :                         new_ctx = (ctx == TXGBE_CTX_NUM);
     943                 :          0 :                         ctx = txq->ctx_curr;
     944                 :            :                 }
     945                 :            : 
     946                 :            :                 /*
     947                 :            :                  * Keep track of how many descriptors are used this loop
     948                 :            :                  * This will always be the number of segments + the number of
     949                 :            :                  * Context descriptors required to transmit the packet
     950                 :            :                  */
     951                 :          0 :                 nb_used = (uint16_t)(tx_pkt->nb_segs + new_ctx);
     952                 :            : 
     953                 :            :                 /*
     954                 :            :                  * The number of descriptors that must be allocated for a
     955                 :            :                  * packet is the number of segments of that packet, plus 1
     956                 :            :                  * Context Descriptor for the hardware offload, if any.
     957                 :            :                  * Determine the last TX descriptor to allocate in the TX ring
     958                 :            :                  * for the packet, starting from the current position (tx_id)
     959                 :            :                  * in the ring.
     960                 :            :                  */
     961                 :          0 :                 tx_last = (uint16_t)(tx_id + nb_used - 1);
     962                 :            : 
     963                 :            :                 /* Circular ring */
     964         [ #  # ]:          0 :                 if (tx_last >= txq->nb_tx_desc)
     965                 :          0 :                         tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
     966                 :            : 
     967                 :            :                 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
     968                 :            :                            " tx_first=%u tx_last=%u",
     969                 :            :                            (uint16_t)txq->port_id,
     970                 :            :                            (uint16_t)txq->queue_id,
     971                 :            :                            (uint32_t)pkt_len,
     972                 :            :                            (uint16_t)tx_id,
     973                 :            :                            (uint16_t)tx_last);
     974                 :            : 
     975                 :            :                 /*
     976                 :            :                  * Make sure there are enough TX descriptors available to
     977                 :            :                  * transmit the entire packet.
     978                 :            :                  * nb_used better be less than or equal to txq->tx_free_thresh
     979                 :            :                  */
     980         [ #  # ]:          0 :                 if (nb_used > txq->nb_tx_free) {
     981                 :            :                         PMD_TX_FREE_LOG(DEBUG,
     982                 :            :                                         "Not enough free TX descriptors "
     983                 :            :                                         "nb_used=%4u nb_free=%4u "
     984                 :            :                                         "(port=%d queue=%d)",
     985                 :            :                                         nb_used, txq->nb_tx_free,
     986                 :            :                                         txq->port_id, txq->queue_id);
     987                 :            : 
     988         [ #  # ]:          0 :                         if (txgbe_xmit_cleanup(txq) != 0) {
     989                 :            :                                 /* Could not clean any descriptors */
     990         [ #  # ]:          0 :                                 if (nb_tx == 0)
     991                 :            :                                         return 0;
     992                 :          0 :                                 goto end_of_tx;
     993                 :            :                         }
     994                 :            : 
     995                 :            :                         /* nb_used better be <= txq->tx_free_thresh */
     996         [ #  # ]:          0 :                         if (unlikely(nb_used > txq->tx_free_thresh)) {
     997                 :            :                                 PMD_TX_FREE_LOG(DEBUG,
     998                 :            :                                         "The number of descriptors needed to "
     999                 :            :                                         "transmit the packet exceeds the "
    1000                 :            :                                         "RS bit threshold. This will impact "
    1001                 :            :                                         "performance."
    1002                 :            :                                         "nb_used=%4u nb_free=%4u "
    1003                 :            :                                         "tx_free_thresh=%4u. "
    1004                 :            :                                         "(port=%d queue=%d)",
    1005                 :            :                                         nb_used, txq->nb_tx_free,
    1006                 :            :                                         txq->tx_free_thresh,
    1007                 :            :                                         txq->port_id, txq->queue_id);
    1008                 :            :                                 /*
    1009                 :            :                                  * Loop here until there are enough TX
    1010                 :            :                                  * descriptors or until the ring cannot be
    1011                 :            :                                  * cleaned.
    1012                 :            :                                  */
    1013         [ #  # ]:          0 :                                 while (nb_used > txq->nb_tx_free) {
    1014         [ #  # ]:          0 :                                         if (txgbe_xmit_cleanup(txq) != 0) {
    1015                 :            :                                                 /*
    1016                 :            :                                                  * Could not clean any
    1017                 :            :                                                  * descriptors
    1018                 :            :                                                  */
    1019         [ #  # ]:          0 :                                                 if (nb_tx == 0)
    1020                 :            :                                                         return 0;
    1021                 :          0 :                                                 goto end_of_tx;
    1022                 :            :                                         }
    1023                 :            :                                 }
    1024                 :            :                         }
    1025                 :            :                 }
    1026                 :            : 
    1027                 :            :                 /*
    1028                 :            :                  * By now there are enough free TX descriptors to transmit
    1029                 :            :                  * the packet.
    1030                 :            :                  */
    1031                 :            : 
    1032                 :            :                 /*
    1033                 :            :                  * Set common flags of all TX Data Descriptors.
    1034                 :            :                  *
    1035                 :            :                  * The following bits must be set in all Data Descriptors:
    1036                 :            :                  *   - TXGBE_TXD_DTYP_DATA
    1037                 :            :                  *   - TXGBE_TXD_DCMD_DEXT
    1038                 :            :                  *
    1039                 :            :                  * The following bits must be set in the first Data Descriptor
    1040                 :            :                  * and are ignored in the other ones:
    1041                 :            :                  *   - TXGBE_TXD_DCMD_IFCS
    1042                 :            :                  *   - TXGBE_TXD_MAC_1588
    1043                 :            :                  *   - TXGBE_TXD_DCMD_VLE
    1044                 :            :                  *
    1045                 :            :                  * The following bits must only be set in the last Data
    1046                 :            :                  * Descriptor:
    1047                 :            :                  *   - TXGBE_TXD_CMD_EOP
    1048                 :            :                  *
    1049                 :            :                  * The following bits can be set in any Data Descriptor, but
    1050                 :            :                  * are only set in the last Data Descriptor:
    1051                 :            :                  *   - TXGBE_TXD_CMD_RS
    1052                 :            :                  */
    1053                 :            :                 cmd_type_len = TXGBE_TXD_FCS;
    1054                 :            : 
    1055                 :            : #ifdef RTE_LIBRTE_IEEE1588
    1056                 :            :                 if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
    1057                 :            :                         cmd_type_len |= TXGBE_TXD_1588;
    1058                 :            : #endif
    1059                 :            : 
    1060                 :            :                 olinfo_status = 0;
    1061         [ #  # ]:          0 :                 if (tx_ol_req) {
    1062         [ #  # ]:          0 :                         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
    1063                 :            :                                 /* when TSO is on, paylen in descriptor is the
    1064                 :            :                                  * not the packet len but the tcp payload len
    1065                 :            :                                  */
    1066                 :          0 :                                 pkt_len -= (tx_offload.l2_len +
    1067                 :          0 :                                         tx_offload.l3_len + tx_offload.l4_len);
    1068                 :          0 :                                 pkt_len -=
    1069                 :          0 :                                         (tx_pkt->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
    1070                 :          0 :                                         ? tx_offload.outer_l2_len +
    1071         [ #  # ]:          0 :                                           tx_offload.outer_l3_len : 0;
    1072                 :            :                         }
    1073                 :            : 
    1074                 :            :                         /*
    1075                 :            :                          * Setup the TX Advanced Context Descriptor if required
    1076                 :            :                          */
    1077         [ #  # ]:          0 :                         if (new_ctx) {
    1078                 :            :                                 volatile struct txgbe_tx_ctx_desc *ctx_txd;
    1079                 :            : 
    1080                 :          0 :                                 ctx_txd = (volatile struct txgbe_tx_ctx_desc *)
    1081                 :          0 :                                     &txr[tx_id];
    1082                 :            : 
    1083                 :          0 :                                 txn = &sw_ring[txe->next_id];
    1084                 :          0 :                                 rte_prefetch0(&txn->mbuf->pool);
    1085                 :            : 
    1086         [ #  # ]:          0 :                                 if (txe->mbuf != NULL) {
    1087                 :            :                                         rte_pktmbuf_free_seg(txe->mbuf);
    1088                 :          0 :                                         txe->mbuf = NULL;
    1089                 :            :                                 }
    1090                 :            : 
    1091                 :          0 :                                 txgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
    1092                 :            :                                         tx_offload,
    1093                 :            :                                         rte_security_dynfield(tx_pkt));
    1094                 :            : 
    1095                 :          0 :                                 txe->last_id = tx_last;
    1096                 :          0 :                                 tx_id = txe->next_id;
    1097                 :            :                                 txe = txn;
    1098                 :            :                         }
    1099                 :            : 
    1100                 :            :                         /*
    1101                 :            :                          * Setup the TX Advanced Data Descriptor,
    1102                 :            :                          * This path will go through
    1103                 :            :                          * whatever new/reuse the context descriptor
    1104                 :            :                          */
    1105                 :          0 :                         cmd_type_len  |= tx_desc_ol_flags_to_cmdtype(ol_flags);
    1106                 :            :                         olinfo_status |=
    1107                 :          0 :                                 tx_desc_cksum_flags_to_olinfo(ol_flags);
    1108                 :          0 :                         olinfo_status |= TXGBE_TXD_IDX(ctx);
    1109                 :            :                 }
    1110                 :            : 
    1111                 :          0 :                 olinfo_status |= TXGBE_TXD_PAYLEN(pkt_len);
    1112                 :            : #ifdef RTE_LIB_SECURITY
    1113         [ #  # ]:          0 :                 if (use_ipsec)
    1114                 :          0 :                         olinfo_status |= TXGBE_TXD_IPSEC;
    1115                 :            : #endif
    1116                 :            : 
    1117                 :            :                 m_seg = tx_pkt;
    1118                 :            :                 do {
    1119                 :          0 :                         txd = &txr[tx_id];
    1120                 :          0 :                         txn = &sw_ring[txe->next_id];
    1121                 :          0 :                         rte_prefetch0(&txn->mbuf->pool);
    1122                 :            : 
    1123         [ #  # ]:          0 :                         if (txe->mbuf != NULL)
    1124                 :            :                                 rte_pktmbuf_free_seg(txe->mbuf);
    1125                 :          0 :                         txe->mbuf = m_seg;
    1126                 :            : 
    1127                 :            :                         /*
    1128                 :            :                          * Set up Transmit Data Descriptor.
    1129                 :            :                          */
    1130         [ #  # ]:          0 :                         slen = m_seg->data_len;
    1131                 :            :                         buf_dma_addr = rte_mbuf_data_iova(m_seg);
    1132                 :          0 :                         txd->qw0 = rte_cpu_to_le_64(buf_dma_addr);
    1133                 :          0 :                         txd->dw2 = rte_cpu_to_le_32(cmd_type_len | slen);
    1134                 :          0 :                         txd->dw3 = rte_cpu_to_le_32(olinfo_status);
    1135                 :          0 :                         txe->last_id = tx_last;
    1136                 :          0 :                         tx_id = txe->next_id;
    1137                 :            :                         txe = txn;
    1138                 :          0 :                         m_seg = m_seg->next;
    1139         [ #  # ]:          0 :                 } while (m_seg != NULL);
    1140                 :            : 
    1141                 :            :                 /*
    1142                 :            :                  * The last packet data descriptor needs End Of Packet (EOP)
    1143                 :            :                  */
    1144                 :          0 :                 cmd_type_len |= TXGBE_TXD_EOP;
    1145                 :          0 :                 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
    1146                 :            : 
    1147                 :          0 :                 txd->dw2 |= rte_cpu_to_le_32(cmd_type_len);
    1148                 :            :         }
    1149                 :            : 
    1150                 :          0 : end_of_tx:
    1151                 :            : 
    1152                 :            :         rte_wmb();
    1153                 :            : 
    1154                 :            :         /*
    1155                 :            :          * Set the Transmit Descriptor Tail (TDT)
    1156                 :            :          */
    1157                 :            :         PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
    1158                 :            :                    (uint16_t)txq->port_id, (uint16_t)txq->queue_id,
    1159                 :            :                    (uint16_t)tx_id, (uint16_t)nb_tx);
    1160                 :          0 :         txgbe_set32_relaxed(txq->tdt_reg_addr, tx_id);
    1161                 :          0 :         txq->tx_tail = tx_id;
    1162                 :            : 
    1163                 :          0 :         return nb_tx;
    1164                 :            : }
    1165                 :            : 
    1166                 :            : /*********************************************************************
    1167                 :            :  *
    1168                 :            :  *  TX prep functions
    1169                 :            :  *
    1170                 :            :  **********************************************************************/
    1171                 :            : uint16_t
    1172                 :          0 : txgbe_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
    1173                 :            : {
    1174                 :            :         int i, ret;
    1175                 :            :         uint64_t ol_flags;
    1176                 :            :         struct rte_mbuf *m;
    1177                 :            :         struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
    1178                 :            : 
    1179         [ #  # ]:          0 :         for (i = 0; i < nb_pkts; i++) {
    1180                 :          0 :                 m = tx_pkts[i];
    1181                 :          0 :                 ol_flags = m->ol_flags;
    1182                 :            : 
    1183                 :            :                 /**
    1184                 :            :                  * Check if packet meets requirements for number of segments
    1185                 :            :                  *
    1186                 :            :                  * NOTE: for txgbe it's always (40 - WTHRESH) for both TSO and
    1187                 :            :                  *       non-TSO
    1188                 :            :                  */
    1189                 :            : 
    1190         [ #  # ]:          0 :                 if (m->nb_segs > TXGBE_TX_MAX_SEG - txq->wthresh) {
    1191                 :          0 :                         rte_errno = -EINVAL;
    1192                 :          0 :                         return i;
    1193                 :            :                 }
    1194                 :            : 
    1195         [ #  # ]:          0 :                 if (ol_flags & TXGBE_TX_OFFLOAD_NOTSUP_MASK) {
    1196                 :          0 :                         rte_errno = -ENOTSUP;
    1197                 :          0 :                         return i;
    1198                 :            :                 }
    1199                 :            : 
    1200                 :            : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
    1201                 :            :                 ret = rte_validate_tx_offload(m);
    1202                 :            :                 if (ret != 0) {
    1203                 :            :                         rte_errno = ret;
    1204                 :            :                         return i;
    1205                 :            :                 }
    1206                 :            : #endif
    1207                 :            :                 ret = rte_net_intel_cksum_prepare(m);
    1208         [ #  # ]:          0 :                 if (ret != 0) {
    1209                 :          0 :                         rte_errno = ret;
    1210                 :          0 :                         return i;
    1211                 :            :                 }
    1212                 :            :         }
    1213                 :            : 
    1214                 :          0 :         return i;
    1215                 :            : }
    1216                 :            : 
    1217                 :            : /*********************************************************************
    1218                 :            :  *
    1219                 :            :  *  RX functions
    1220                 :            :  *
    1221                 :            :  **********************************************************************/
    1222                 :            : /* @note: fix txgbe_dev_supported_ptypes_get() if any change here. */
    1223                 :            : static inline uint32_t
    1224                 :            : txgbe_rxd_pkt_info_to_pkt_type(uint32_t pkt_info, uint16_t ptid_mask)
    1225                 :            : {
    1226                 :          0 :         uint16_t ptid = TXGBE_RXD_PTID(pkt_info);
    1227                 :            : 
    1228                 :          0 :         ptid &= ptid_mask;
    1229                 :            : 
    1230                 :          0 :         return txgbe_decode_ptype(ptid);
    1231                 :            : }
    1232                 :            : 
    1233                 :            : static inline uint64_t
    1234                 :            : txgbe_rxd_pkt_info_to_pkt_flags(uint32_t pkt_info)
    1235                 :            : {
    1236                 :            :         static alignas(RTE_CACHE_LINE_SIZE) uint64_t ip_rss_types_map[16] = {
    1237                 :            :                 0, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH, RTE_MBUF_F_RX_RSS_HASH,
    1238                 :            :                 0, RTE_MBUF_F_RX_RSS_HASH, 0, RTE_MBUF_F_RX_RSS_HASH,
    1239                 :            :                 RTE_MBUF_F_RX_RSS_HASH, 0, 0, 0,
    1240                 :            :                 0, 0, 0,  RTE_MBUF_F_RX_FDIR,
    1241                 :            :         };
    1242                 :            : #ifdef RTE_LIBRTE_IEEE1588
    1243                 :            :         static uint64_t ip_pkt_etqf_map[8] = {
    1244                 :            :                 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
    1245                 :            :                 0, 0, 0, 0,
    1246                 :            :         };
    1247                 :            :         int etfid = txgbe_etflt_id(TXGBE_RXD_PTID(pkt_info));
    1248                 :            :         if (likely(-1 != etfid))
    1249                 :            :                 return ip_pkt_etqf_map[etfid] |
    1250                 :            :                        ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
    1251                 :            :         else
    1252                 :            :                 return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
    1253                 :            : #else
    1254                 :          0 :         return ip_rss_types_map[TXGBE_RXD_RSSTYPE(pkt_info)];
    1255                 :            : #endif
    1256                 :            : }
    1257                 :            : 
    1258                 :            : static inline uint64_t
    1259                 :            : rx_desc_status_to_pkt_flags(uint32_t rx_status, uint64_t vlan_flags)
    1260                 :            : {
    1261                 :            :         uint64_t pkt_flags;
    1262                 :            : 
    1263                 :            :         /*
    1264                 :            :          * Check if VLAN present only.
    1265                 :            :          * Do not check whether L3/L4 rx checksum done by NIC or not,
    1266                 :            :          * That can be found from rte_eth_rxmode.offloads flag
    1267                 :            :          */
    1268                 :          0 :         pkt_flags = (rx_status & TXGBE_RXD_STAT_VLAN &&
    1269   [ #  #  #  #  :          0 :                      vlan_flags & RTE_MBUF_F_RX_VLAN_STRIPPED)
                   #  # ]
    1270                 :          0 :                     ? vlan_flags : 0;
    1271                 :            : 
    1272                 :            : #ifdef RTE_LIBRTE_IEEE1588
    1273                 :            :         if (rx_status & TXGBE_RXD_STAT_1588)
    1274                 :            :                 pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
    1275                 :            : #endif
    1276                 :            :         return pkt_flags;
    1277                 :            : }
    1278                 :            : 
    1279                 :            : static inline uint64_t
    1280                 :          0 : rx_desc_error_to_pkt_flags(uint32_t rx_status)
    1281                 :            : {
    1282                 :            :         uint64_t pkt_flags = 0;
    1283                 :            : 
    1284                 :            :         /* checksum offload can't be disabled */
    1285         [ #  # ]:          0 :         if (rx_status & TXGBE_RXD_STAT_IPCS) {
    1286                 :            :                 pkt_flags |= (rx_status & TXGBE_RXD_ERR_IPCS
    1287         [ #  # ]:          0 :                                 ? RTE_MBUF_F_RX_IP_CKSUM_BAD : RTE_MBUF_F_RX_IP_CKSUM_GOOD);
    1288                 :            :         }
    1289                 :            : 
    1290         [ #  # ]:          0 :         if (rx_status & TXGBE_RXD_STAT_L4CS) {
    1291                 :          0 :                 pkt_flags |= (rx_status & TXGBE_RXD_ERR_L4CS
    1292         [ #  # ]:          0 :                                 ? RTE_MBUF_F_RX_L4_CKSUM_BAD : RTE_MBUF_F_RX_L4_CKSUM_GOOD);
    1293                 :            :         }
    1294                 :            : 
    1295         [ #  # ]:          0 :         if (rx_status & TXGBE_RXD_STAT_EIPCS &&
    1296                 :            :             rx_status & TXGBE_RXD_ERR_EIPCS) {
    1297                 :          0 :                 pkt_flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
    1298                 :            :         }
    1299                 :            : 
    1300                 :            : #ifdef RTE_LIB_SECURITY
    1301         [ #  # ]:          0 :         if (rx_status & TXGBE_RXD_STAT_SECP) {
    1302                 :          0 :                 pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD;
    1303         [ #  # ]:          0 :                 if (rx_status & TXGBE_RXD_ERR_SECERR)
    1304                 :          0 :                         pkt_flags |= RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED;
    1305                 :            :         }
    1306                 :            : #endif
    1307                 :            : 
    1308                 :          0 :         return pkt_flags;
    1309                 :            : }
    1310                 :            : 
    1311                 :            : /*
    1312                 :            :  * LOOK_AHEAD defines how many desc statuses to check beyond the
    1313                 :            :  * current descriptor.
    1314                 :            :  * It must be a pound define for optimal performance.
    1315                 :            :  * Do not change the value of LOOK_AHEAD, as the txgbe_rx_scan_hw_ring
    1316                 :            :  * function only works with LOOK_AHEAD=8.
    1317                 :            :  */
    1318                 :            : #define LOOK_AHEAD 8
    1319                 :            : #if (LOOK_AHEAD != 8)
    1320                 :            : #error "PMD TXGBE: LOOK_AHEAD must be 8\n"
    1321                 :            : #endif
    1322                 :            : static inline int
    1323                 :          0 : txgbe_rx_scan_hw_ring(struct txgbe_rx_queue *rxq)
    1324                 :            : {
    1325                 :            :         volatile struct txgbe_rx_desc *rxdp;
    1326                 :            :         struct txgbe_rx_entry *rxep;
    1327                 :            :         struct rte_mbuf *mb;
    1328                 :            :         uint16_t pkt_len;
    1329                 :            :         uint64_t pkt_flags;
    1330                 :            :         int nb_dd;
    1331                 :            :         uint32_t s[LOOK_AHEAD];
    1332                 :            :         uint32_t pkt_info[LOOK_AHEAD];
    1333                 :            :         int i, j, nb_rx = 0;
    1334                 :            :         uint32_t status;
    1335                 :            : 
    1336                 :            :         /* get references to current descriptor and S/W ring entry */
    1337                 :          0 :         rxdp = &rxq->rx_ring[rxq->rx_tail];
    1338                 :          0 :         rxep = &rxq->sw_ring[rxq->rx_tail];
    1339                 :            : 
    1340                 :          0 :         status = rxdp->qw1.lo.status;
    1341                 :            :         /* check to make sure there is at least 1 packet to receive */
    1342         [ #  # ]:          0 :         if (!(status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
    1343                 :            :                 return 0;
    1344                 :            : 
    1345                 :            :         /*
    1346                 :            :          * Scan LOOK_AHEAD descriptors at a time to determine which descriptors
    1347                 :            :          * reference packets that are ready to be received.
    1348                 :            :          */
    1349         [ #  # ]:          0 :         for (i = 0; i < RTE_PMD_TXGBE_RX_MAX_BURST;
    1350                 :          0 :              i += LOOK_AHEAD, rxdp += LOOK_AHEAD, rxep += LOOK_AHEAD) {
    1351                 :            :                 /* Read desc statuses backwards to avoid race condition */
    1352         [ #  # ]:          0 :                 for (j = 0; j < LOOK_AHEAD; j++)
    1353                 :          0 :                         s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status);
    1354                 :            : 
    1355                 :            :                 rte_atomic_thread_fence(rte_memory_order_acquire);
    1356                 :            : 
    1357                 :            :                 /* Compute how many status bits were set */
    1358         [ #  # ]:          0 :                 for (nb_dd = 0; nb_dd < LOOK_AHEAD &&
    1359         [ #  # ]:          0 :                                 (s[nb_dd] & TXGBE_RXD_STAT_DD); nb_dd++)
    1360                 :            :                         ;
    1361                 :            : 
    1362         [ #  # ]:          0 :                 for (j = 0; j < nb_dd; j++)
    1363                 :          0 :                         pkt_info[j] = rte_le_to_cpu_32(rxdp[j].qw0.dw0);
    1364                 :            : 
    1365                 :          0 :                 nb_rx += nb_dd;
    1366                 :            : 
    1367                 :            :                 /* Translate descriptor info to mbuf format */
    1368         [ #  # ]:          0 :                 for (j = 0; j < nb_dd; ++j) {
    1369                 :          0 :                         mb = rxep[j].mbuf;
    1370                 :          0 :                         pkt_len = rte_le_to_cpu_16(rxdp[j].qw1.hi.len) -
    1371                 :          0 :                                   rxq->crc_len;
    1372                 :          0 :                         mb->data_len = pkt_len;
    1373                 :          0 :                         mb->pkt_len = pkt_len;
    1374                 :          0 :                         mb->vlan_tci = rte_le_to_cpu_16(rxdp[j].qw1.hi.tag);
    1375                 :            : 
    1376                 :            :                         /* convert descriptor fields to rte mbuf flags */
    1377         [ #  # ]:          0 :                         pkt_flags = rx_desc_status_to_pkt_flags(s[j],
    1378                 :            :                                         rxq->vlan_flags);
    1379                 :          0 :                         pkt_flags |= rx_desc_error_to_pkt_flags(s[j]);
    1380                 :          0 :                         pkt_flags |=
    1381                 :          0 :                                 txgbe_rxd_pkt_info_to_pkt_flags(pkt_info[j]);
    1382                 :          0 :                         mb->ol_flags = pkt_flags;
    1383                 :          0 :                         mb->packet_type =
    1384                 :            :                                 txgbe_rxd_pkt_info_to_pkt_type(pkt_info[j],
    1385                 :          0 :                                 rxq->pkt_type_mask);
    1386                 :            : 
    1387         [ #  # ]:          0 :                         if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH))
    1388                 :          0 :                                 mb->hash.rss =
    1389                 :          0 :                                         rte_le_to_cpu_32(rxdp[j].qw0.dw1);
    1390         [ #  # ]:          0 :                         else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
    1391                 :          0 :                                 mb->hash.fdir.hash =
    1392                 :          0 :                                         rte_le_to_cpu_16(rxdp[j].qw0.hi.csum) &
    1393                 :            :                                         TXGBE_ATR_HASH_MASK;
    1394                 :          0 :                                 mb->hash.fdir.id =
    1395                 :          0 :                                         rte_le_to_cpu_16(rxdp[j].qw0.hi.ipid);
    1396                 :            :                         }
    1397                 :            :                 }
    1398                 :            : 
    1399                 :            :                 /* Move mbuf pointers from the S/W ring to the stage */
    1400         [ #  # ]:          0 :                 for (j = 0; j < LOOK_AHEAD; ++j)
    1401                 :          0 :                         rxq->rx_stage[i + j] = rxep[j].mbuf;
    1402                 :            : 
    1403                 :            :                 /* stop if all requested packets could not be received */
    1404         [ #  # ]:          0 :                 if (nb_dd != LOOK_AHEAD)
    1405                 :            :                         break;
    1406                 :            :         }
    1407                 :            : 
    1408                 :            :         /* clear software ring entries so we can cleanup correctly */
    1409         [ #  # ]:          0 :         for (i = 0; i < nb_rx; ++i)
    1410                 :          0 :                 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
    1411                 :            : 
    1412                 :            :         return nb_rx;
    1413                 :            : }
    1414                 :            : 
    1415                 :            : static inline int
    1416                 :          0 : txgbe_rx_alloc_bufs(struct txgbe_rx_queue *rxq, bool reset_mbuf)
    1417                 :            : {
    1418                 :            :         volatile struct txgbe_rx_desc *rxdp;
    1419                 :            :         struct txgbe_rx_entry *rxep;
    1420                 :            :         struct rte_mbuf *mb;
    1421                 :            :         uint16_t alloc_idx;
    1422                 :            :         __le64 dma_addr;
    1423                 :            :         int diag, i;
    1424                 :            : 
    1425                 :            :         /* allocate buffers in bulk directly into the S/W ring */
    1426                 :          0 :         alloc_idx = rxq->rx_free_trigger - (rxq->rx_free_thresh - 1);
    1427                 :          0 :         rxep = &rxq->sw_ring[alloc_idx];
    1428         [ #  # ]:          0 :         diag = rte_mempool_get_bulk(rxq->mb_pool, (void *)rxep,
    1429                 :            :                                     rxq->rx_free_thresh);
    1430         [ #  # ]:          0 :         if (unlikely(diag != 0))
    1431                 :            :                 return -ENOMEM;
    1432                 :            : 
    1433                 :          0 :         rxdp = &rxq->rx_ring[alloc_idx];
    1434         [ #  # ]:          0 :         for (i = 0; i < rxq->rx_free_thresh; ++i) {
    1435                 :            :                 /* populate the static rte mbuf fields */
    1436                 :          0 :                 mb = rxep[i].mbuf;
    1437         [ #  # ]:          0 :                 if (reset_mbuf)
    1438                 :          0 :                         mb->port = rxq->port_id;
    1439                 :            : 
    1440                 :            :                 rte_mbuf_refcnt_set(mb, 1);
    1441                 :          0 :                 mb->data_off = RTE_PKTMBUF_HEADROOM;
    1442                 :            : 
    1443                 :            :                 /* populate the descriptors */
    1444                 :            :                 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mb));
    1445                 :          0 :                 TXGBE_RXD_HDRADDR(&rxdp[i], 0);
    1446                 :          0 :                 TXGBE_RXD_PKTADDR(&rxdp[i], dma_addr);
    1447                 :            :         }
    1448                 :            : 
    1449                 :            :         /* update state of internal queue structure */
    1450                 :          0 :         rxq->rx_free_trigger = rxq->rx_free_trigger + rxq->rx_free_thresh;
    1451         [ #  # ]:          0 :         if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
    1452                 :          0 :                 rxq->rx_free_trigger = rxq->rx_free_thresh - 1;
    1453                 :            : 
    1454                 :            :         /* no errors */
    1455                 :            :         return 0;
    1456                 :            : }
    1457                 :            : 
    1458                 :            : static inline uint16_t
    1459                 :            : txgbe_rx_fill_from_stage(struct txgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
    1460                 :            :                          uint16_t nb_pkts)
    1461                 :            : {
    1462                 :          0 :         struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
    1463                 :            :         int i;
    1464                 :            : 
    1465                 :            :         /* how many packets are ready to return? */
    1466                 :          0 :         nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
    1467                 :            : 
    1468                 :            :         /* copy mbuf pointers to the application's packet list */
    1469   [ #  #  #  # ]:          0 :         for (i = 0; i < nb_pkts; ++i)
    1470                 :          0 :                 rx_pkts[i] = stage[i];
    1471                 :            : 
    1472                 :            :         /* update internal queue state */
    1473                 :          0 :         rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
    1474                 :          0 :         rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
    1475                 :            : 
    1476                 :            :         return nb_pkts;
    1477                 :            : }
    1478                 :            : 
    1479                 :            : static inline uint16_t
    1480                 :          0 : txgbe_rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
    1481                 :            :              uint16_t nb_pkts)
    1482                 :            : {
    1483                 :            :         struct txgbe_rx_queue *rxq = (struct txgbe_rx_queue *)rx_queue;
    1484                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
    1485                 :            :         uint16_t nb_rx = 0;
    1486                 :            : 
    1487                 :            :         /* Any previously recv'd pkts will be returned from the Rx stage */
    1488         [ #  # ]:          0 :         if (rxq->rx_nb_avail)
    1489                 :          0 :                 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
    1490                 :            : 
    1491                 :            :         /* Scan the H/W ring for packets to receive */
    1492                 :          0 :         nb_rx = (uint16_t)txgbe_rx_scan_hw_ring(rxq);
    1493                 :            : 
    1494                 :            :         /* update internal queue state */
    1495                 :          0 :         rxq->rx_next_avail = 0;
    1496                 :          0 :         rxq->rx_nb_avail = nb_rx;
    1497                 :          0 :         rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
    1498                 :            : 
    1499                 :            :         /* if required, allocate new buffers to replenish descriptors */
    1500         [ #  # ]:          0 :         if (rxq->rx_tail > rxq->rx_free_trigger) {
    1501                 :            :                 uint16_t cur_free_trigger = rxq->rx_free_trigger;
    1502                 :            : 
    1503         [ #  # ]:          0 :                 if (txgbe_rx_alloc_bufs(rxq, true) != 0) {
    1504                 :            :                         int i, j;
    1505                 :            : 
    1506                 :            :                         PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
    1507                 :            :                                    "queue_id=%u", (uint16_t)rxq->port_id,
    1508                 :            :                                    (uint16_t)rxq->queue_id);
    1509                 :            : 
    1510                 :          0 :                         dev->data->rx_mbuf_alloc_failed +=
    1511                 :          0 :                                 rxq->rx_free_thresh;
    1512                 :            : 
    1513                 :            :                         /*
    1514                 :            :                          * Need to rewind any previous receives if we cannot
    1515                 :            :                          * allocate new buffers to replenish the old ones.
    1516                 :            :                          */
    1517                 :          0 :                         rxq->rx_nb_avail = 0;
    1518                 :          0 :                         rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
    1519         [ #  # ]:          0 :                         for (i = 0, j = rxq->rx_tail; i < nb_rx; ++i, ++j)
    1520                 :          0 :                                 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
    1521                 :            : 
    1522                 :            :                         return 0;
    1523                 :            :                 }
    1524                 :            : 
    1525                 :            :                 /* update tail pointer */
    1526                 :            :                 rte_wmb();
    1527                 :          0 :                 txgbe_set32_relaxed(rxq->rdt_reg_addr, cur_free_trigger);
    1528                 :            :         }
    1529                 :            : 
    1530         [ #  # ]:          0 :         if (rxq->rx_tail >= rxq->nb_rx_desc)
    1531                 :          0 :                 rxq->rx_tail = 0;
    1532                 :            : 
    1533                 :            :         /* received any packets this loop? */
    1534         [ #  # ]:          0 :         if (rxq->rx_nb_avail)
    1535                 :          0 :                 return txgbe_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
    1536                 :            : 
    1537                 :            :         return 0;
    1538                 :            : }
    1539                 :            : 
    1540                 :            : /* split requests into chunks of size RTE_PMD_TXGBE_RX_MAX_BURST */
    1541                 :            : uint16_t
    1542                 :          0 : txgbe_recv_pkts_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
    1543                 :            :                            uint16_t nb_pkts)
    1544                 :            : {
    1545                 :            :         uint16_t nb_rx;
    1546                 :            : 
    1547         [ #  # ]:          0 :         if (unlikely(nb_pkts == 0))
    1548                 :            :                 return 0;
    1549                 :            : 
    1550         [ #  # ]:          0 :         if (likely(nb_pkts <= RTE_PMD_TXGBE_RX_MAX_BURST))
    1551                 :          0 :                 return txgbe_rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
    1552                 :            : 
    1553                 :            :         /* request is relatively large, chunk it up */
    1554                 :            :         nb_rx = 0;
    1555         [ #  # ]:          0 :         while (nb_pkts) {
    1556                 :            :                 uint16_t ret, n;
    1557                 :            : 
    1558                 :          0 :                 n = (uint16_t)RTE_MIN(nb_pkts, RTE_PMD_TXGBE_RX_MAX_BURST);
    1559                 :          0 :                 ret = txgbe_rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
    1560                 :          0 :                 nb_rx = (uint16_t)(nb_rx + ret);
    1561                 :          0 :                 nb_pkts = (uint16_t)(nb_pkts - ret);
    1562         [ #  # ]:          0 :                 if (ret < n)
    1563                 :            :                         break;
    1564                 :            :         }
    1565                 :            : 
    1566                 :            :         return nb_rx;
    1567                 :            : }
    1568                 :            : 
    1569                 :            : uint16_t
    1570                 :          0 : txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
    1571                 :            :                 uint16_t nb_pkts)
    1572                 :            : {
    1573                 :            :         struct txgbe_rx_queue *rxq;
    1574                 :            :         volatile struct txgbe_rx_desc *rx_ring;
    1575                 :            :         volatile struct txgbe_rx_desc *rxdp;
    1576                 :            :         struct txgbe_rx_entry *sw_ring;
    1577                 :            :         struct txgbe_rx_entry *rxe;
    1578                 :            :         struct rte_mbuf *rxm;
    1579                 :            :         struct rte_mbuf *nmb;
    1580                 :            :         struct txgbe_rx_desc rxd;
    1581                 :            :         uint64_t dma_addr;
    1582                 :            :         uint32_t staterr;
    1583                 :            :         uint32_t pkt_info;
    1584                 :            :         uint16_t pkt_len;
    1585                 :            :         uint16_t rx_id;
    1586                 :            :         uint16_t nb_rx;
    1587                 :            :         uint16_t nb_hold;
    1588                 :            :         uint64_t pkt_flags;
    1589                 :            : 
    1590                 :            :         nb_rx = 0;
    1591                 :            :         nb_hold = 0;
    1592                 :            :         rxq = rx_queue;
    1593                 :          0 :         rx_id = rxq->rx_tail;
    1594                 :          0 :         rx_ring = rxq->rx_ring;
    1595                 :          0 :         sw_ring = rxq->sw_ring;
    1596                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
    1597         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
    1598                 :            :                 /*
    1599                 :            :                  * The order of operations here is important as the DD status
    1600                 :            :                  * bit must not be read after any other descriptor fields.
    1601                 :            :                  * rx_ring and rxdp are pointing to volatile data so the order
    1602                 :            :                  * of accesses cannot be reordered by the compiler. If they were
    1603                 :            :                  * not volatile, they could be reordered which could lead to
    1604                 :            :                  * using invalid descriptor fields when read from rxd.
    1605                 :            :                  *
    1606                 :            :                  * Meanwhile, to prevent the CPU from executing out of order, we
    1607                 :            :                  * need to use a proper memory barrier to ensure the memory
    1608                 :            :                  * ordering below.
    1609                 :            :                  */
    1610                 :          0 :                 rxdp = &rx_ring[rx_id];
    1611                 :          0 :                 staterr = rxdp->qw1.lo.status;
    1612         [ #  # ]:          0 :                 if (!(staterr & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD)))
    1613                 :            :                         break;
    1614                 :            : 
    1615                 :            :                 /*
    1616                 :            :                  * Use acquire fence to ensure that status_error which includes
    1617                 :            :                  * DD bit is loaded before loading of other descriptor words.
    1618                 :            :                  */
    1619                 :            :                 rte_atomic_thread_fence(rte_memory_order_acquire);
    1620                 :            : 
    1621                 :          0 :                 rxd = *rxdp;
    1622                 :            : 
    1623                 :            :                 /*
    1624                 :            :                  * End of packet.
    1625                 :            :                  *
    1626                 :            :                  * If the TXGBE_RXD_STAT_EOP flag is not set, the RX packet
    1627                 :            :                  * is likely to be invalid and to be dropped by the various
    1628                 :            :                  * validation checks performed by the network stack.
    1629                 :            :                  *
    1630                 :            :                  * Allocate a new mbuf to replenish the RX ring descriptor.
    1631                 :            :                  * If the allocation fails:
    1632                 :            :                  *    - arrange for that RX descriptor to be the first one
    1633                 :            :                  *      being parsed the next time the receive function is
    1634                 :            :                  *      invoked [on the same queue].
    1635                 :            :                  *
    1636                 :            :                  *    - Stop parsing the RX ring and return immediately.
    1637                 :            :                  *
    1638                 :            :                  * This policy do not drop the packet received in the RX
    1639                 :            :                  * descriptor for which the allocation of a new mbuf failed.
    1640                 :            :                  * Thus, it allows that packet to be later retrieved if
    1641                 :            :                  * mbuf have been freed in the mean time.
    1642                 :            :                  * As a side effect, holding RX descriptors instead of
    1643                 :            :                  * systematically giving them back to the NIC may lead to
    1644                 :            :                  * RX ring exhaustion situations.
    1645                 :            :                  * However, the NIC can gracefully prevent such situations
    1646                 :            :                  * to happen by sending specific "back-pressure" flow control
    1647                 :            :                  * frames to its peer(s).
    1648                 :            :                  */
    1649                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
    1650                 :            :                            "ext_err_stat=0x%08x pkt_len=%u",
    1651                 :            :                            (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
    1652                 :            :                            (uint16_t)rx_id, (uint32_t)staterr,
    1653                 :            :                            (uint16_t)rte_le_to_cpu_16(rxd.qw1.hi.len));
    1654                 :            : 
    1655                 :          0 :                 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
    1656         [ #  # ]:          0 :                 if (nmb == NULL) {
    1657                 :            :                         PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
    1658                 :            :                                    "queue_id=%u", (uint16_t)rxq->port_id,
    1659                 :            :                                    (uint16_t)rxq->queue_id);
    1660                 :          0 :                         dev->data->rx_mbuf_alloc_failed++;
    1661                 :          0 :                         break;
    1662                 :            :                 }
    1663                 :            : 
    1664                 :          0 :                 nb_hold++;
    1665                 :          0 :                 rxe = &sw_ring[rx_id];
    1666                 :          0 :                 rx_id++;
    1667         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc)
    1668                 :            :                         rx_id = 0;
    1669                 :            : 
    1670                 :            :                 /* Prefetch next mbuf while processing current one. */
    1671                 :          0 :                 rte_txgbe_prefetch(sw_ring[rx_id].mbuf);
    1672                 :            : 
    1673                 :            :                 /*
    1674                 :            :                  * When next RX descriptor is on a cache-line boundary,
    1675                 :            :                  * prefetch the next 4 RX descriptors and the next 8 pointers
    1676                 :            :                  * to mbufs.
    1677                 :            :                  */
    1678         [ #  # ]:          0 :                 if ((rx_id & 0x3) == 0) {
    1679                 :          0 :                         rte_txgbe_prefetch(&rx_ring[rx_id]);
    1680                 :            :                         rte_txgbe_prefetch(&sw_ring[rx_id]);
    1681                 :            :                 }
    1682                 :            : 
    1683                 :          0 :                 rxm = rxe->mbuf;
    1684                 :          0 :                 rxe->mbuf = nmb;
    1685                 :            :                 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
    1686                 :          0 :                 TXGBE_RXD_HDRADDR(rxdp, 0);
    1687                 :          0 :                 TXGBE_RXD_PKTADDR(rxdp, dma_addr);
    1688                 :            : 
    1689                 :            :                 /*
    1690                 :            :                  * Initialize the returned mbuf.
    1691                 :            :                  * 1) setup generic mbuf fields:
    1692                 :            :                  *    - number of segments,
    1693                 :            :                  *    - next segment,
    1694                 :            :                  *    - packet length,
    1695                 :            :                  *    - RX port identifier.
    1696                 :            :                  * 2) integrate hardware offload data, if any:
    1697                 :            :                  *    - RSS flag & hash,
    1698                 :            :                  *    - IP checksum flag,
    1699                 :            :                  *    - VLAN TCI, if any,
    1700                 :            :                  *    - error flags.
    1701                 :            :                  */
    1702                 :          0 :                 pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.qw1.hi.len) -
    1703                 :          0 :                                       rxq->crc_len);
    1704                 :          0 :                 rxm->data_off = RTE_PKTMBUF_HEADROOM;
    1705                 :          0 :                 rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
    1706                 :          0 :                 rxm->nb_segs = 1;
    1707                 :          0 :                 rxm->next = NULL;
    1708                 :          0 :                 rxm->pkt_len = pkt_len;
    1709                 :          0 :                 rxm->data_len = pkt_len;
    1710                 :          0 :                 rxm->port = rxq->port_id;
    1711                 :            : 
    1712                 :            :                 pkt_info = rte_le_to_cpu_32(rxd.qw0.dw0);
    1713                 :            :                 /* Only valid if RTE_MBUF_F_RX_VLAN set in pkt_flags */
    1714                 :          0 :                 rxm->vlan_tci = rte_le_to_cpu_16(rxd.qw1.hi.tag);
    1715                 :            : 
    1716         [ #  # ]:          0 :                 pkt_flags = rx_desc_status_to_pkt_flags(staterr,
    1717                 :            :                                         rxq->vlan_flags);
    1718                 :          0 :                 pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
    1719                 :          0 :                 pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
    1720                 :          0 :                 rxm->ol_flags = pkt_flags;
    1721                 :          0 :                 rxm->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
    1722                 :          0 :                                                        rxq->pkt_type_mask);
    1723                 :            : 
    1724         [ #  # ]:          0 :                 if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH)) {
    1725                 :          0 :                         rxm->hash.rss = rte_le_to_cpu_32(rxd.qw0.dw1);
    1726         [ #  # ]:          0 :                 } else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
    1727                 :          0 :                         rxm->hash.fdir.hash =
    1728                 :          0 :                                 rte_le_to_cpu_16(rxd.qw0.hi.csum) &
    1729                 :            :                                 TXGBE_ATR_HASH_MASK;
    1730                 :          0 :                         rxm->hash.fdir.id = rte_le_to_cpu_16(rxd.qw0.hi.ipid);
    1731                 :            :                 }
    1732                 :            :                 /*
    1733                 :            :                  * Store the mbuf address into the next entry of the array
    1734                 :            :                  * of returned packets.
    1735                 :            :                  */
    1736                 :          0 :                 rx_pkts[nb_rx++] = rxm;
    1737                 :            :         }
    1738                 :          0 :         rxq->rx_tail = rx_id;
    1739                 :            : 
    1740                 :            :         /*
    1741                 :            :          * If the number of free RX descriptors is greater than the RX free
    1742                 :            :          * threshold of the queue, advance the Receive Descriptor Tail (RDT)
    1743                 :            :          * register.
    1744                 :            :          * Update the RDT with the value of the last processed RX descriptor
    1745                 :            :          * minus 1, to guarantee that the RDT register is never equal to the
    1746                 :            :          * RDH register, which creates a "full" ring situation from the
    1747                 :            :          * hardware point of view...
    1748                 :            :          */
    1749                 :          0 :         nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
    1750         [ #  # ]:          0 :         if (nb_hold > rxq->rx_free_thresh) {
    1751                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
    1752                 :            :                            "nb_hold=%u nb_rx=%u",
    1753                 :            :                            (uint16_t)rxq->port_id, (uint16_t)rxq->queue_id,
    1754                 :            :                            (uint16_t)rx_id, (uint16_t)nb_hold,
    1755                 :            :                            (uint16_t)nb_rx);
    1756         [ #  # ]:          0 :                 rx_id = (uint16_t)((rx_id == 0) ?
    1757                 :          0 :                                 (rxq->nb_rx_desc - 1) : (rx_id - 1));
    1758                 :          0 :                 txgbe_set32(rxq->rdt_reg_addr, rx_id);
    1759                 :            :                 nb_hold = 0;
    1760                 :            :         }
    1761                 :          0 :         rxq->nb_rx_hold = nb_hold;
    1762                 :          0 :         return nb_rx;
    1763                 :            : }
    1764                 :            : 
    1765                 :            : /**
    1766                 :            :  * txgbe_fill_cluster_head_buf - fill the first mbuf of the returned packet
    1767                 :            :  *
    1768                 :            :  * Fill the following info in the HEAD buffer of the Rx cluster:
    1769                 :            :  *    - RX port identifier
    1770                 :            :  *    - hardware offload data, if any:
    1771                 :            :  *      - RSS flag & hash
    1772                 :            :  *      - IP checksum flag
    1773                 :            :  *      - VLAN TCI, if any
    1774                 :            :  *      - error flags
    1775                 :            :  * @head HEAD of the packet cluster
    1776                 :            :  * @desc HW descriptor to get data from
    1777                 :            :  * @rxq Pointer to the Rx queue
    1778                 :            :  */
    1779                 :            : static inline void
    1780                 :          0 : txgbe_fill_cluster_head_buf(struct rte_mbuf *head, struct txgbe_rx_desc *desc,
    1781                 :            :                 struct txgbe_rx_queue *rxq, uint32_t staterr)
    1782                 :            : {
    1783                 :            :         uint32_t pkt_info;
    1784                 :            :         uint64_t pkt_flags;
    1785                 :            : 
    1786                 :          0 :         head->port = rxq->port_id;
    1787                 :            : 
    1788                 :            :         /* The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
    1789                 :            :          * set in the pkt_flags field.
    1790                 :            :          */
    1791                 :          0 :         head->vlan_tci = rte_le_to_cpu_16(desc->qw1.hi.tag);
    1792                 :          0 :         pkt_info = rte_le_to_cpu_32(desc->qw0.dw0);
    1793         [ #  # ]:          0 :         pkt_flags = rx_desc_status_to_pkt_flags(staterr, rxq->vlan_flags);
    1794                 :          0 :         pkt_flags |= rx_desc_error_to_pkt_flags(staterr);
    1795                 :          0 :         pkt_flags |= txgbe_rxd_pkt_info_to_pkt_flags(pkt_info);
    1796                 :          0 :         head->ol_flags = pkt_flags;
    1797                 :          0 :         head->packet_type = txgbe_rxd_pkt_info_to_pkt_type(pkt_info,
    1798                 :          0 :                                                 rxq->pkt_type_mask);
    1799                 :            : 
    1800         [ #  # ]:          0 :         if (likely(pkt_flags & RTE_MBUF_F_RX_RSS_HASH)) {
    1801                 :          0 :                 head->hash.rss = rte_le_to_cpu_32(desc->qw0.dw1);
    1802         [ #  # ]:          0 :         } else if (pkt_flags & RTE_MBUF_F_RX_FDIR) {
    1803                 :          0 :                 head->hash.fdir.hash = rte_le_to_cpu_16(desc->qw0.hi.csum)
    1804                 :          0 :                                 & TXGBE_ATR_HASH_MASK;
    1805                 :          0 :                 head->hash.fdir.id = rte_le_to_cpu_16(desc->qw0.hi.ipid);
    1806                 :            :         }
    1807                 :          0 : }
    1808                 :            : 
    1809                 :            : /**
    1810                 :            :  * txgbe_recv_pkts_lro - receive handler for and LRO case.
    1811                 :            :  *
    1812                 :            :  * @rx_queue Rx queue handle
    1813                 :            :  * @rx_pkts table of received packets
    1814                 :            :  * @nb_pkts size of rx_pkts table
    1815                 :            :  * @bulk_alloc if TRUE bulk allocation is used for a HW ring refilling
    1816                 :            :  *
    1817                 :            :  * Handles the Rx HW ring completions when RSC feature is configured. Uses an
    1818                 :            :  * additional ring of txgbe_rsc_entry's that will hold the relevant RSC info.
    1819                 :            :  *
    1820                 :            :  * We use the same logic as in Linux and in FreeBSD txgbe drivers:
    1821                 :            :  * 1) When non-EOP RSC completion arrives:
    1822                 :            :  *    a) Update the HEAD of the current RSC aggregation cluster with the new
    1823                 :            :  *       segment's data length.
    1824                 :            :  *    b) Set the "next" pointer of the current segment to point to the segment
    1825                 :            :  *       at the NEXTP index.
    1826                 :            :  *    c) Pass the HEAD of RSC aggregation cluster on to the next NEXTP entry
    1827                 :            :  *       in the sw_rsc_ring.
    1828                 :            :  * 2) When EOP arrives we just update the cluster's total length and offload
    1829                 :            :  *    flags and deliver the cluster up to the upper layers. In our case - put it
    1830                 :            :  *    in the rx_pkts table.
    1831                 :            :  *
    1832                 :            :  * Returns the number of received packets/clusters (according to the "bulk
    1833                 :            :  * receive" interface).
    1834                 :            :  */
    1835                 :            : static inline uint16_t
    1836                 :          0 : txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts,
    1837                 :            :                     bool bulk_alloc)
    1838                 :            : {
    1839                 :            :         struct txgbe_rx_queue *rxq = rx_queue;
    1840                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
    1841                 :          0 :         volatile struct txgbe_rx_desc *rx_ring = rxq->rx_ring;
    1842                 :          0 :         struct txgbe_rx_entry *sw_ring = rxq->sw_ring;
    1843                 :          0 :         struct txgbe_scattered_rx_entry *sw_sc_ring = rxq->sw_sc_ring;
    1844                 :          0 :         uint16_t rx_id = rxq->rx_tail;
    1845                 :            :         uint16_t nb_rx = 0;
    1846                 :          0 :         uint16_t nb_hold = rxq->nb_rx_hold;
    1847                 :            :         uint16_t prev_id = rxq->rx_tail;
    1848                 :            : 
    1849         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
    1850                 :            :                 bool eop;
    1851                 :            :                 struct txgbe_rx_entry *rxe;
    1852                 :            :                 struct txgbe_scattered_rx_entry *sc_entry;
    1853                 :            :                 struct txgbe_scattered_rx_entry *next_sc_entry = NULL;
    1854                 :            :                 struct txgbe_rx_entry *next_rxe = NULL;
    1855                 :            :                 struct rte_mbuf *first_seg;
    1856                 :            :                 struct rte_mbuf *rxm;
    1857                 :            :                 struct rte_mbuf *nmb = NULL;
    1858                 :            :                 struct txgbe_rx_desc rxd;
    1859                 :            :                 uint16_t data_len;
    1860                 :            :                 uint16_t next_id;
    1861                 :            :                 volatile struct txgbe_rx_desc *rxdp;
    1862                 :            :                 uint32_t staterr;
    1863                 :            : 
    1864                 :          0 : next_desc:
    1865                 :            :                 /*
    1866                 :            :                  * "Volatile" only prevents caching of the variable marked
    1867                 :            :                  * volatile. Most important, "volatile" cannot prevent the CPU
    1868                 :            :                  * from executing out of order. So, it is necessary to use a
    1869                 :            :                  * proper memory barrier to ensure the memory ordering below.
    1870                 :            :                  */
    1871                 :          0 :                 rxdp = &rx_ring[rx_id];
    1872                 :          0 :                 staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status);
    1873                 :            : 
    1874         [ #  # ]:          0 :                 if (!(staterr & TXGBE_RXD_STAT_DD))
    1875                 :            :                         break;
    1876                 :            : 
    1877                 :            :                 /*
    1878                 :            :                  * Use acquire fence to ensure that status_error which includes
    1879                 :            :                  * DD bit is loaded before loading of other descriptor words.
    1880                 :            :                  */
    1881                 :            :                 rte_atomic_thread_fence(rte_memory_order_acquire);
    1882                 :            : 
    1883                 :          0 :                 rxd = *rxdp;
    1884                 :            : 
    1885                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
    1886                 :            :                                   "staterr=0x%x data_len=%u",
    1887                 :            :                            rxq->port_id, rxq->queue_id, rx_id, staterr,
    1888                 :            :                            rte_le_to_cpu_16(rxd.qw1.hi.len));
    1889                 :            : 
    1890         [ #  # ]:          0 :                 if (!bulk_alloc) {
    1891                 :          0 :                         nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
    1892         [ #  # ]:          0 :                         if (nmb == NULL) {
    1893                 :            :                                 PMD_RX_LOG(DEBUG, "RX mbuf alloc failed "
    1894                 :            :                                                   "port_id=%u queue_id=%u",
    1895                 :            :                                            rxq->port_id, rxq->queue_id);
    1896                 :            : 
    1897                 :          0 :                                 dev->data->rx_mbuf_alloc_failed++;
    1898                 :          0 :                                 break;
    1899                 :            :                         }
    1900         [ #  # ]:          0 :                 } else if (nb_hold > rxq->rx_free_thresh) {
    1901                 :          0 :                         uint16_t next_rdt = rxq->rx_free_trigger;
    1902                 :            : 
    1903         [ #  # ]:          0 :                         if (!txgbe_rx_alloc_bufs(rxq, false)) {
    1904                 :            :                                 rte_wmb();
    1905                 :          0 :                                 txgbe_set32_relaxed(rxq->rdt_reg_addr,
    1906                 :            :                                                             next_rdt);
    1907                 :          0 :                                 nb_hold -= rxq->rx_free_thresh;
    1908                 :            :                         } else {
    1909                 :            :                                 PMD_RX_LOG(DEBUG, "RX bulk alloc failed "
    1910                 :            :                                                   "port_id=%u queue_id=%u",
    1911                 :            :                                            rxq->port_id, rxq->queue_id);
    1912                 :            : 
    1913                 :          0 :                                 dev->data->rx_mbuf_alloc_failed++;
    1914                 :          0 :                                 break;
    1915                 :            :                         }
    1916                 :            :                 }
    1917                 :            : 
    1918                 :          0 :                 nb_hold++;
    1919                 :          0 :                 rxe = &sw_ring[rx_id];
    1920                 :          0 :                 eop = staterr & TXGBE_RXD_STAT_EOP;
    1921                 :            : 
    1922                 :          0 :                 next_id = rx_id + 1;
    1923         [ #  # ]:          0 :                 if (next_id == rxq->nb_rx_desc)
    1924                 :            :                         next_id = 0;
    1925                 :            : 
    1926                 :            :                 /* Prefetch next mbuf while processing current one. */
    1927                 :          0 :                 rte_txgbe_prefetch(sw_ring[next_id].mbuf);
    1928                 :            : 
    1929                 :            :                 /*
    1930                 :            :                  * When next RX descriptor is on a cache-line boundary,
    1931                 :            :                  * prefetch the next 4 RX descriptors and the next 4 pointers
    1932                 :            :                  * to mbufs.
    1933                 :            :                  */
    1934         [ #  # ]:          0 :                 if ((next_id & 0x3) == 0) {
    1935                 :          0 :                         rte_txgbe_prefetch(&rx_ring[next_id]);
    1936                 :            :                         rte_txgbe_prefetch(&sw_ring[next_id]);
    1937                 :            :                 }
    1938                 :            : 
    1939                 :          0 :                 rxm = rxe->mbuf;
    1940                 :            : 
    1941         [ #  # ]:          0 :                 if (!bulk_alloc) {
    1942                 :            :                         __le64 dma =
    1943                 :            :                           rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
    1944                 :            :                         /*
    1945                 :            :                          * Update RX descriptor with the physical address of the
    1946                 :            :                          * new data buffer of the new allocated mbuf.
    1947                 :            :                          */
    1948                 :          0 :                         rxe->mbuf = nmb;
    1949                 :            : 
    1950                 :          0 :                         rxm->data_off = RTE_PKTMBUF_HEADROOM;
    1951                 :          0 :                         TXGBE_RXD_HDRADDR(rxdp, 0);
    1952                 :          0 :                         TXGBE_RXD_PKTADDR(rxdp, dma);
    1953                 :            :                 } else {
    1954                 :          0 :                         rxe->mbuf = NULL;
    1955                 :            :                 }
    1956                 :            : 
    1957                 :            :                 /*
    1958                 :            :                  * Set data length & data buffer address of mbuf.
    1959                 :            :                  */
    1960                 :          0 :                 data_len = rte_le_to_cpu_16(rxd.qw1.hi.len);
    1961                 :          0 :                 rxm->data_len = data_len;
    1962                 :            : 
    1963         [ #  # ]:          0 :                 if (!eop) {
    1964                 :            :                         uint16_t nextp_id;
    1965                 :            :                         /*
    1966                 :            :                          * Get next descriptor index:
    1967                 :            :                          *  - For RSC it's in the NEXTP field.
    1968                 :            :                          *  - For a scattered packet - it's just a following
    1969                 :            :                          *    descriptor.
    1970                 :            :                          */
    1971         [ #  # ]:          0 :                         if (TXGBE_RXD_RSCCNT(rxd.qw0.dw0))
    1972                 :          0 :                                 nextp_id = TXGBE_RXD_NEXTP(staterr);
    1973                 :            :                         else
    1974                 :            :                                 nextp_id = next_id;
    1975                 :            : 
    1976                 :          0 :                         next_sc_entry = &sw_sc_ring[nextp_id];
    1977                 :          0 :                         next_rxe = &sw_ring[nextp_id];
    1978                 :            :                         rte_txgbe_prefetch(next_rxe);
    1979                 :            :                 }
    1980                 :            : 
    1981                 :          0 :                 sc_entry = &sw_sc_ring[rx_id];
    1982                 :          0 :                 first_seg = sc_entry->fbuf;
    1983                 :          0 :                 sc_entry->fbuf = NULL;
    1984                 :            : 
    1985                 :            :                 /*
    1986                 :            :                  * If this is the first buffer of the received packet,
    1987                 :            :                  * set the pointer to the first mbuf of the packet and
    1988                 :            :                  * initialize its context.
    1989                 :            :                  * Otherwise, update the total length and the number of segments
    1990                 :            :                  * of the current scattered packet, and update the pointer to
    1991                 :            :                  * the last mbuf of the current packet.
    1992                 :            :                  */
    1993         [ #  # ]:          0 :                 if (first_seg == NULL) {
    1994                 :            :                         first_seg = rxm;
    1995                 :          0 :                         first_seg->pkt_len = data_len;
    1996                 :          0 :                         first_seg->nb_segs = 1;
    1997                 :            :                 } else {
    1998                 :          0 :                         first_seg->pkt_len += data_len;
    1999                 :          0 :                         first_seg->nb_segs++;
    2000                 :            :                 }
    2001                 :            : 
    2002                 :            :                 prev_id = rx_id;
    2003                 :            :                 rx_id = next_id;
    2004                 :            : 
    2005                 :            :                 /*
    2006                 :            :                  * If this is not the last buffer of the received packet, update
    2007                 :            :                  * the pointer to the first mbuf at the NEXTP entry in the
    2008                 :            :                  * sw_sc_ring and continue to parse the RX ring.
    2009                 :            :                  */
    2010         [ #  # ]:          0 :                 if (!eop && next_rxe) {
    2011                 :          0 :                         rxm->next = next_rxe->mbuf;
    2012                 :          0 :                         next_sc_entry->fbuf = first_seg;
    2013                 :          0 :                         goto next_desc;
    2014                 :            :                 }
    2015                 :            : 
    2016                 :            :                 /* Initialize the first mbuf of the returned packet */
    2017                 :          0 :                 txgbe_fill_cluster_head_buf(first_seg, &rxd, rxq, staterr);
    2018                 :            : 
    2019                 :            :                 /*
    2020                 :            :                  * Deal with the case, when HW CRC srip is disabled.
    2021                 :            :                  * That can't happen when LRO is enabled, but still could
    2022                 :            :                  * happen for scattered RX mode.
    2023                 :            :                  */
    2024                 :          0 :                 first_seg->pkt_len -= rxq->crc_len;
    2025         [ #  # ]:          0 :                 if (unlikely(rxm->data_len <= rxq->crc_len)) {
    2026                 :            :                         struct rte_mbuf *lp;
    2027                 :            : 
    2028         [ #  # ]:          0 :                         for (lp = first_seg; lp->next != rxm; lp = lp->next)
    2029                 :            :                                 ;
    2030                 :            : 
    2031                 :          0 :                         first_seg->nb_segs--;
    2032                 :          0 :                         lp->data_len -= rxq->crc_len - rxm->data_len;
    2033         [ #  # ]:          0 :                         lp->next = NULL;
    2034                 :            :                         rte_pktmbuf_free_seg(rxm);
    2035                 :            :                 } else {
    2036                 :          0 :                         rxm->data_len -= rxq->crc_len;
    2037                 :            :                 }
    2038                 :            : 
    2039                 :            :                 /* Prefetch data of first segment, if configured to do so. */
    2040                 :          0 :                 rte_packet_prefetch((char *)first_seg->buf_addr +
    2041                 :            :                         first_seg->data_off);
    2042                 :            : 
    2043                 :            :                 /*
    2044                 :            :                  * Store the mbuf address into the next entry of the array
    2045                 :            :                  * of returned packets.
    2046                 :            :                  */
    2047                 :          0 :                 rx_pkts[nb_rx++] = first_seg;
    2048                 :            :         }
    2049                 :            : 
    2050                 :            :         /*
    2051                 :            :          * Record index of the next RX descriptor to probe.
    2052                 :            :          */
    2053                 :          0 :         rxq->rx_tail = rx_id;
    2054                 :            : 
    2055                 :            :         /*
    2056                 :            :          * If the number of free RX descriptors is greater than the RX free
    2057                 :            :          * threshold of the queue, advance the Receive Descriptor Tail (RDT)
    2058                 :            :          * register.
    2059                 :            :          * Update the RDT with the value of the last processed RX descriptor
    2060                 :            :          * minus 1, to guarantee that the RDT register is never equal to the
    2061                 :            :          * RDH register, which creates a "full" ring situation from the
    2062                 :            :          * hardware point of view...
    2063                 :            :          */
    2064   [ #  #  #  # ]:          0 :         if (!bulk_alloc && nb_hold > rxq->rx_free_thresh) {
    2065                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
    2066                 :            :                            "nb_hold=%u nb_rx=%u",
    2067                 :            :                            rxq->port_id, rxq->queue_id, rx_id, nb_hold, nb_rx);
    2068                 :            : 
    2069                 :            :                 rte_wmb();
    2070                 :          0 :                 txgbe_set32_relaxed(rxq->rdt_reg_addr, prev_id);
    2071                 :            :                 nb_hold = 0;
    2072                 :            :         }
    2073                 :            : 
    2074                 :          0 :         rxq->nb_rx_hold = nb_hold;
    2075                 :          0 :         return nb_rx;
    2076                 :            : }
    2077                 :            : 
    2078                 :            : uint16_t
    2079                 :          0 : txgbe_recv_pkts_lro_single_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
    2080                 :            :                                  uint16_t nb_pkts)
    2081                 :            : {
    2082                 :          0 :         return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, false);
    2083                 :            : }
    2084                 :            : 
    2085                 :            : uint16_t
    2086                 :          0 : txgbe_recv_pkts_lro_bulk_alloc(void *rx_queue, struct rte_mbuf **rx_pkts,
    2087                 :            :                                uint16_t nb_pkts)
    2088                 :            : {
    2089                 :          0 :         return txgbe_recv_pkts_lro(rx_queue, rx_pkts, nb_pkts, true);
    2090                 :            : }
    2091                 :            : 
    2092                 :            : uint64_t
    2093                 :          0 : txgbe_get_rx_queue_offloads(struct rte_eth_dev *dev __rte_unused)
    2094                 :            : {
    2095                 :          0 :         return RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    2096                 :            : }
    2097                 :            : 
    2098                 :            : uint64_t
    2099                 :          0 : txgbe_get_rx_port_offloads(struct rte_eth_dev *dev)
    2100                 :            : {
    2101                 :            :         uint64_t offloads;
    2102         [ #  # ]:          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    2103                 :            :         struct rte_eth_dev_sriov *sriov = &RTE_ETH_DEV_SRIOV(dev);
    2104                 :            : 
    2105                 :            :         offloads = RTE_ETH_RX_OFFLOAD_IPV4_CKSUM  |
    2106                 :            :                    RTE_ETH_RX_OFFLOAD_UDP_CKSUM   |
    2107                 :            :                    RTE_ETH_RX_OFFLOAD_TCP_CKSUM   |
    2108                 :            :                    RTE_ETH_RX_OFFLOAD_KEEP_CRC    |
    2109                 :            :                    RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
    2110                 :            :                    RTE_ETH_RX_OFFLOAD_RSS_HASH |
    2111                 :            :                    RTE_ETH_RX_OFFLOAD_SCATTER;
    2112                 :            : 
    2113                 :            :         if (!txgbe_is_vf(dev))
    2114                 :            :                 offloads |= (RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
    2115                 :            :                              RTE_ETH_RX_OFFLOAD_QINQ_STRIP |
    2116                 :            :                              RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
    2117                 :            : 
    2118                 :            :         /*
    2119                 :            :          * RSC is only supported by PF devices in a non-SR-IOV
    2120                 :            :          * mode.
    2121                 :            :          */
    2122   [ #  #  #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor && !sriov->active)
    2123                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_TCP_LRO;
    2124                 :            : 
    2125         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor)
    2126                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
    2127                 :            : 
    2128                 :          0 :         offloads |= RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
    2129                 :            : 
    2130                 :            : #ifdef RTE_LIB_SECURITY
    2131         [ #  # ]:          0 :         if (dev->security_ctx)
    2132                 :          0 :                 offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
    2133                 :            : #endif
    2134                 :            : 
    2135                 :          0 :         return offloads;
    2136                 :            : }
    2137                 :            : 
    2138                 :            : static void __rte_cold
    2139                 :          0 : txgbe_tx_queue_release_mbufs(struct txgbe_tx_queue *txq)
    2140                 :            : {
    2141                 :            :         unsigned int i;
    2142                 :            : 
    2143         [ #  # ]:          0 :         if (txq->sw_ring != NULL) {
    2144         [ #  # ]:          0 :                 for (i = 0; i < txq->nb_tx_desc; i++) {
    2145         [ #  # ]:          0 :                         if (txq->sw_ring[i].mbuf != NULL) {
    2146                 :            :                                 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
    2147                 :          0 :                                 txq->sw_ring[i].mbuf = NULL;
    2148                 :            :                         }
    2149                 :            :                 }
    2150                 :            :         }
    2151                 :          0 : }
    2152                 :            : 
    2153                 :            : static int
    2154                 :          0 : txgbe_tx_done_cleanup_full(struct txgbe_tx_queue *txq, uint32_t free_cnt)
    2155                 :            : {
    2156                 :          0 :         struct txgbe_tx_entry *swr_ring = txq->sw_ring;
    2157                 :            :         uint16_t i, tx_last, tx_id;
    2158                 :            :         uint16_t nb_tx_free_last;
    2159                 :            :         uint16_t nb_tx_to_clean;
    2160                 :            :         uint32_t pkt_cnt;
    2161                 :            : 
    2162                 :            :         /* Start free mbuf from the next of tx_tail */
    2163                 :          0 :         tx_last = txq->tx_tail;
    2164                 :          0 :         tx_id  = swr_ring[tx_last].next_id;
    2165                 :            : 
    2166   [ #  #  #  # ]:          0 :         if (txq->nb_tx_free == 0 && txgbe_xmit_cleanup(txq))
    2167                 :            :                 return 0;
    2168                 :            : 
    2169                 :          0 :         nb_tx_to_clean = txq->nb_tx_free;
    2170                 :            :         nb_tx_free_last = txq->nb_tx_free;
    2171         [ #  # ]:          0 :         if (!free_cnt)
    2172                 :          0 :                 free_cnt = txq->nb_tx_desc;
    2173                 :            : 
    2174                 :            :         /* Loop through swr_ring to count the amount of
    2175                 :            :          * freeable mubfs and packets.
    2176                 :            :          */
    2177         [ #  # ]:          0 :         for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
    2178                 :          0 :                 for (i = 0; i < nb_tx_to_clean &&
    2179   [ #  #  #  # ]:          0 :                         pkt_cnt < free_cnt &&
    2180                 :          0 :                         tx_id != tx_last; i++) {
    2181         [ #  # ]:          0 :                         if (swr_ring[tx_id].mbuf != NULL) {
    2182                 :            :                                 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
    2183                 :          0 :                                 swr_ring[tx_id].mbuf = NULL;
    2184                 :            : 
    2185                 :            :                                 /*
    2186                 :            :                                  * last segment in the packet,
    2187                 :            :                                  * increment packet count
    2188                 :            :                                  */
    2189                 :          0 :                                 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
    2190                 :            :                         }
    2191                 :            : 
    2192                 :          0 :                         tx_id = swr_ring[tx_id].next_id;
    2193                 :            :                 }
    2194                 :            : 
    2195         [ #  # ]:          0 :                 if (pkt_cnt < free_cnt) {
    2196         [ #  # ]:          0 :                         if (txgbe_xmit_cleanup(txq))
    2197                 :            :                                 break;
    2198                 :            : 
    2199                 :          0 :                         nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
    2200                 :            :                         nb_tx_free_last = txq->nb_tx_free;
    2201                 :            :                 }
    2202                 :            :         }
    2203                 :            : 
    2204                 :          0 :         return (int)pkt_cnt;
    2205                 :            : }
    2206                 :            : 
    2207                 :            : static int
    2208                 :          0 : txgbe_tx_done_cleanup_simple(struct txgbe_tx_queue *txq,
    2209                 :            :                         uint32_t free_cnt)
    2210                 :            : {
    2211                 :            :         int i, n, cnt;
    2212                 :            : 
    2213   [ #  #  #  # ]:          0 :         if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
    2214                 :          0 :                 free_cnt = txq->nb_tx_desc;
    2215                 :            : 
    2216                 :          0 :         cnt = free_cnt - free_cnt % txq->tx_free_thresh;
    2217                 :            : 
    2218         [ #  # ]:          0 :         for (i = 0; i < cnt; i += n) {
    2219         [ #  # ]:          0 :                 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_free_thresh)
    2220                 :            :                         break;
    2221                 :            : 
    2222                 :            :                 n = txgbe_tx_free_bufs(txq);
    2223                 :            : 
    2224         [ #  # ]:          0 :                 if (n == 0)
    2225                 :            :                         break;
    2226                 :            :         }
    2227                 :            : 
    2228                 :          0 :         return i;
    2229                 :            : }
    2230                 :            : 
    2231                 :            : int
    2232                 :          0 : txgbe_dev_tx_done_cleanup(void *tx_queue, uint32_t free_cnt)
    2233                 :            : {
    2234                 :            :         struct txgbe_tx_queue *txq = (struct txgbe_tx_queue *)tx_queue;
    2235         [ #  # ]:          0 :         if (txq->offloads == 0 &&
    2236                 :            : #ifdef RTE_LIB_SECURITY
    2237         [ #  # ]:          0 :                 !(txq->using_ipsec) &&
    2238                 :            : #endif
    2239         [ #  # ]:          0 :                 txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST)
    2240                 :          0 :                 return txgbe_tx_done_cleanup_simple(txq, free_cnt);
    2241                 :            : 
    2242                 :          0 :         return txgbe_tx_done_cleanup_full(txq, free_cnt);
    2243                 :            : }
    2244                 :            : 
    2245                 :            : static void __rte_cold
    2246                 :          0 : txgbe_tx_free_swring(struct txgbe_tx_queue *txq)
    2247                 :            : {
    2248         [ #  # ]:          0 :         if (txq != NULL &&
    2249         [ #  # ]:          0 :             txq->sw_ring != NULL)
    2250                 :          0 :                 rte_free(txq->sw_ring);
    2251                 :          0 : }
    2252                 :            : 
    2253                 :            : static void __rte_cold
    2254                 :          0 : txgbe_tx_queue_release(struct txgbe_tx_queue *txq)
    2255                 :            : {
    2256   [ #  #  #  # ]:          0 :         if (txq != NULL && txq->ops != NULL) {
    2257                 :          0 :                 txq->ops->release_mbufs(txq);
    2258                 :          0 :                 txq->ops->free_swring(txq);
    2259                 :          0 :                 rte_memzone_free(txq->mz);
    2260                 :          0 :                 rte_free(txq);
    2261                 :            :         }
    2262                 :          0 : }
    2263                 :            : 
    2264                 :            : void __rte_cold
    2265                 :          0 : txgbe_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    2266                 :            : {
    2267                 :          0 :         txgbe_tx_queue_release(dev->data->tx_queues[qid]);
    2268                 :          0 : }
    2269                 :            : 
    2270                 :            : /* (Re)set dynamic txgbe_tx_queue fields to defaults */
    2271                 :            : static void __rte_cold
    2272                 :          0 : txgbe_reset_tx_queue(struct txgbe_tx_queue *txq)
    2273                 :            : {
    2274                 :            :         static const struct txgbe_tx_desc zeroed_desc = {0};
    2275                 :          0 :         struct txgbe_tx_entry *txe = txq->sw_ring;
    2276                 :            :         uint16_t prev, i;
    2277                 :            : 
    2278                 :            :         /* Zero out HW ring memory */
    2279         [ #  # ]:          0 :         for (i = 0; i < txq->nb_tx_desc; i++)
    2280                 :          0 :                 txq->tx_ring[i] = zeroed_desc;
    2281                 :            : 
    2282                 :            :         /* Initialize SW ring entries */
    2283                 :          0 :         prev = (uint16_t)(txq->nb_tx_desc - 1);
    2284         [ #  # ]:          0 :         for (i = 0; i < txq->nb_tx_desc; i++) {
    2285                 :          0 :                 volatile struct txgbe_tx_desc *txd = &txq->tx_ring[i];
    2286                 :            : 
    2287                 :          0 :                 txd->dw3 = rte_cpu_to_le_32(TXGBE_TXD_DD);
    2288                 :          0 :                 txe[i].mbuf = NULL;
    2289                 :          0 :                 txe[i].last_id = i;
    2290                 :          0 :                 txe[prev].next_id = i;
    2291                 :            :                 prev = i;
    2292                 :            :         }
    2293                 :            : 
    2294                 :          0 :         txq->tx_next_dd = (uint16_t)(txq->tx_free_thresh - 1);
    2295                 :          0 :         txq->tx_tail = 0;
    2296                 :            : 
    2297                 :            :         /*
    2298                 :            :          * Always allow 1 descriptor to be un-allocated to avoid
    2299                 :            :          * a H/W race condition
    2300                 :            :          */
    2301                 :          0 :         txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
    2302                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
    2303                 :          0 :         txq->ctx_curr = 0;
    2304                 :          0 :         memset((void *)&txq->ctx_cache, 0,
    2305                 :            :                 TXGBE_CTX_NUM * sizeof(struct txgbe_ctx_info));
    2306                 :          0 : }
    2307                 :            : 
    2308                 :            : static const struct txgbe_txq_ops def_txq_ops = {
    2309                 :            :         .release_mbufs = txgbe_tx_queue_release_mbufs,
    2310                 :            :         .free_swring = txgbe_tx_free_swring,
    2311                 :            :         .reset = txgbe_reset_tx_queue,
    2312                 :            : };
    2313                 :            : 
    2314                 :            : /* Takes an ethdev and a queue and sets up the tx function to be used based on
    2315                 :            :  * the queue parameters. Used in tx_queue_setup by primary process and then
    2316                 :            :  * in dev_init by secondary process when attaching to an existing ethdev.
    2317                 :            :  */
    2318                 :            : void __rte_cold
    2319                 :          0 : txgbe_set_tx_function(struct rte_eth_dev *dev, struct txgbe_tx_queue *txq)
    2320                 :            : {
    2321                 :            :         /* Use a simple Tx queue (no offloads, no multi segs) if possible */
    2322         [ #  # ]:          0 :         if (txq->offloads == 0 &&
    2323                 :            : #ifdef RTE_LIB_SECURITY
    2324         [ #  # ]:          0 :                         !(txq->using_ipsec) &&
    2325                 :            : #endif
    2326         [ #  # ]:          0 :                         txq->tx_free_thresh >= RTE_PMD_TXGBE_TX_MAX_BURST) {
    2327                 :          0 :                 PMD_INIT_LOG(DEBUG, "Using simple tx code path");
    2328                 :          0 :                 dev->tx_pkt_prepare = NULL;
    2329   [ #  #  #  # ]:          0 :                 if (txq->tx_free_thresh <= RTE_TXGBE_TX_MAX_FREE_BUF_SZ &&
    2330         [ #  # ]:          0 :                                 rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128 &&
    2331         [ #  # ]:          0 :                                 (rte_eal_process_type() != RTE_PROC_PRIMARY ||
    2332                 :          0 :                                         txgbe_txq_vec_setup(txq) == 0)) {
    2333                 :          0 :                         PMD_INIT_LOG(DEBUG, "Vector tx enabled.");
    2334                 :          0 :                         dev->tx_pkt_burst = txgbe_xmit_pkts_vec;
    2335                 :            :                 } else {
    2336                 :          0 :                         dev->tx_pkt_burst = txgbe_xmit_pkts_simple;
    2337                 :            :                 }
    2338                 :            :         } else {
    2339                 :          0 :                 PMD_INIT_LOG(DEBUG, "Using full-featured tx code path");
    2340                 :          0 :                 PMD_INIT_LOG(DEBUG,
    2341                 :            :                                 " - offloads = 0x%" PRIx64,
    2342                 :            :                                 txq->offloads);
    2343                 :          0 :                 PMD_INIT_LOG(DEBUG,
    2344                 :            :                                 " - tx_free_thresh = %lu [RTE_PMD_TXGBE_TX_MAX_BURST=%lu]",
    2345                 :            :                                 (unsigned long)txq->tx_free_thresh,
    2346                 :            :                                 (unsigned long)RTE_PMD_TXGBE_TX_MAX_BURST);
    2347                 :          0 :                 dev->tx_pkt_burst = txgbe_xmit_pkts;
    2348                 :          0 :                 dev->tx_pkt_prepare = txgbe_prep_pkts;
    2349                 :            :         }
    2350                 :          0 : }
    2351                 :            : 
    2352                 :            : uint64_t
    2353                 :          0 : txgbe_get_tx_queue_offloads(struct rte_eth_dev *dev)
    2354                 :            : {
    2355                 :            :         RTE_SET_USED(dev);
    2356                 :            : 
    2357                 :          0 :         return 0;
    2358                 :            : }
    2359                 :            : 
    2360                 :            : uint64_t
    2361         [ #  # ]:          0 : txgbe_get_tx_port_offloads(struct rte_eth_dev *dev)
    2362                 :            : {
    2363                 :            :         uint64_t tx_offload_capa;
    2364                 :            : 
    2365                 :            :         tx_offload_capa =
    2366                 :            :                 RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
    2367                 :            :                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM  |
    2368                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM   |
    2369                 :            :                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM   |
    2370                 :            :                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM  |
    2371                 :            :                 RTE_ETH_TX_OFFLOAD_TCP_TSO     |
    2372                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_TSO         |
    2373                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_TNL_TSO  |
    2374                 :            :                 RTE_ETH_TX_OFFLOAD_IP_TNL_TSO   |
    2375                 :            :                 RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO        |
    2376                 :            :                 RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO  |
    2377                 :            :                 RTE_ETH_TX_OFFLOAD_IPIP_TNL_TSO |
    2378                 :            :                 RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO       |
    2379                 :            :                 RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
    2380                 :            : 
    2381                 :            :         if (!txgbe_is_vf(dev))
    2382                 :            :                 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_QINQ_INSERT;
    2383                 :            : 
    2384                 :            :         tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
    2385                 :            : 
    2386                 :          0 :         tx_offload_capa |= RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM;
    2387                 :            : 
    2388                 :            : #ifdef RTE_LIB_SECURITY
    2389         [ #  # ]:          0 :         if (dev->security_ctx)
    2390                 :          0 :                 tx_offload_capa |= RTE_ETH_TX_OFFLOAD_SECURITY;
    2391                 :            : #endif
    2392                 :          0 :         return tx_offload_capa;
    2393                 :            : }
    2394                 :            : 
    2395                 :            : int __rte_cold
    2396                 :          0 : txgbe_dev_tx_queue_setup(struct rte_eth_dev *dev,
    2397                 :            :                          uint16_t queue_idx,
    2398                 :            :                          uint16_t nb_desc,
    2399                 :            :                          unsigned int socket_id,
    2400                 :            :                          const struct rte_eth_txconf *tx_conf)
    2401                 :            : {
    2402                 :            :         const struct rte_memzone *tz;
    2403                 :            :         struct txgbe_tx_queue *txq;
    2404                 :            :         struct txgbe_hw     *hw;
    2405                 :            :         uint16_t tx_free_thresh;
    2406                 :            :         uint64_t offloads;
    2407                 :            : 
    2408                 :          0 :         PMD_INIT_FUNC_TRACE();
    2409                 :          0 :         hw = TXGBE_DEV_HW(dev);
    2410                 :            : 
    2411                 :          0 :         offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
    2412                 :            : 
    2413                 :            :         /*
    2414                 :            :          * Validate number of transmit descriptors.
    2415                 :            :          * It must not exceed hardware maximum, and must be multiple
    2416                 :            :          * of TXGBE_ALIGN.
    2417                 :            :          */
    2418         [ #  # ]:          0 :         if (nb_desc % TXGBE_TXD_ALIGN != 0 ||
    2419         [ #  # ]:          0 :             nb_desc > TXGBE_RING_DESC_MAX ||
    2420                 :            :             nb_desc < TXGBE_RING_DESC_MIN) {
    2421                 :            :                 return -EINVAL;
    2422                 :            :         }
    2423                 :            : 
    2424                 :            :         /*
    2425                 :            :          * The TX descriptor ring will be cleaned after txq->tx_free_thresh
    2426                 :            :          * descriptors are used or if the number of descriptors required
    2427                 :            :          * to transmit a packet is greater than the number of free TX
    2428                 :            :          * descriptors.
    2429                 :            :          * One descriptor in the TX ring is used as a sentinel to avoid a
    2430                 :            :          * H/W race condition, hence the maximum threshold constraints.
    2431                 :            :          * When set to zero use default values.
    2432                 :            :          */
    2433         [ #  # ]:          0 :         tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
    2434                 :            :                         tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
    2435         [ #  # ]:          0 :         if (tx_free_thresh >= (nb_desc - 3)) {
    2436                 :          0 :                 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the number of "
    2437                 :            :                              "TX descriptors minus 3. (tx_free_thresh=%u "
    2438                 :            :                              "port=%d queue=%d)",
    2439                 :            :                              (unsigned int)tx_free_thresh,
    2440                 :            :                              (int)dev->data->port_id, (int)queue_idx);
    2441                 :          0 :                 return -(EINVAL);
    2442                 :            :         }
    2443                 :            : 
    2444         [ #  # ]:          0 :         if ((nb_desc % tx_free_thresh) != 0) {
    2445                 :          0 :                 PMD_INIT_LOG(ERR, "tx_free_thresh must be a divisor of the "
    2446                 :            :                              "number of TX descriptors. (tx_free_thresh=%u "
    2447                 :            :                              "port=%d queue=%d)", (unsigned int)tx_free_thresh,
    2448                 :            :                              (int)dev->data->port_id, (int)queue_idx);
    2449                 :          0 :                 return -(EINVAL);
    2450                 :            :         }
    2451                 :            : 
    2452                 :            :         /* Free memory prior to re-allocation if needed... */
    2453         [ #  # ]:          0 :         if (dev->data->tx_queues[queue_idx] != NULL) {
    2454                 :          0 :                 txgbe_tx_queue_release(dev->data->tx_queues[queue_idx]);
    2455                 :          0 :                 dev->data->tx_queues[queue_idx] = NULL;
    2456                 :            :         }
    2457                 :            : 
    2458                 :            :         /* First allocate the tx queue data structure */
    2459                 :          0 :         txq = rte_zmalloc_socket("ethdev TX queue",
    2460                 :            :                                  sizeof(struct txgbe_tx_queue),
    2461                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
    2462         [ #  # ]:          0 :         if (txq == NULL)
    2463                 :            :                 return -ENOMEM;
    2464                 :            : 
    2465                 :            :         /*
    2466                 :            :          * Allocate TX ring hardware descriptors. A memzone large enough to
    2467                 :            :          * handle the maximum ring size is allocated in order to allow for
    2468                 :            :          * resizing in later calls to the queue setup function.
    2469                 :            :          */
    2470                 :          0 :         tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
    2471                 :            :                         sizeof(struct txgbe_tx_desc) * TXGBE_RING_DESC_MAX,
    2472                 :            :                         TXGBE_ALIGN, socket_id);
    2473         [ #  # ]:          0 :         if (tz == NULL) {
    2474                 :          0 :                 txgbe_tx_queue_release(txq);
    2475                 :          0 :                 return -ENOMEM;
    2476                 :            :         }
    2477                 :            : 
    2478                 :          0 :         txq->mz = tz;
    2479                 :          0 :         txq->nb_tx_desc = nb_desc;
    2480                 :          0 :         txq->tx_free_thresh = tx_free_thresh;
    2481                 :          0 :         txq->pthresh = tx_conf->tx_thresh.pthresh;
    2482                 :          0 :         txq->hthresh = tx_conf->tx_thresh.hthresh;
    2483                 :          0 :         txq->wthresh = tx_conf->tx_thresh.wthresh;
    2484                 :          0 :         txq->queue_id = queue_idx;
    2485         [ #  # ]:          0 :         txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
    2486                 :          0 :                 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
    2487                 :          0 :         txq->port_id = dev->data->port_id;
    2488                 :          0 :         txq->offloads = offloads;
    2489                 :          0 :         txq->ops = &def_txq_ops;
    2490                 :          0 :         txq->tx_deferred_start = tx_conf->tx_deferred_start;
    2491                 :            : #ifdef RTE_LIB_SECURITY
    2492                 :          0 :         txq->using_ipsec = !!(dev->data->dev_conf.txmode.offloads &
    2493                 :            :                         RTE_ETH_TX_OFFLOAD_SECURITY);
    2494                 :            : #endif
    2495                 :            : 
    2496                 :            :         /* Modification to set tail pointer for virtual function
    2497                 :            :          * if vf is detected.
    2498                 :            :          */
    2499         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor_vf) {
    2500                 :          0 :                 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXWP(queue_idx));
    2501                 :          0 :                 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw, TXGBE_TXCFG(queue_idx));
    2502                 :            :         } else {
    2503                 :          0 :                 txq->tdt_reg_addr = TXGBE_REG_ADDR(hw,
    2504                 :            :                                                 TXGBE_TXWP(txq->reg_idx));
    2505                 :          0 :                 txq->tdc_reg_addr = TXGBE_REG_ADDR(hw,
    2506                 :            :                                                 TXGBE_TXCFG(txq->reg_idx));
    2507                 :            :         }
    2508                 :            : 
    2509                 :          0 :         txq->tx_ring_phys_addr = TMZ_PADDR(tz);
    2510                 :          0 :         txq->tx_ring = (struct txgbe_tx_desc *)TMZ_VADDR(tz);
    2511                 :            : 
    2512                 :            :         /* Allocate software ring */
    2513                 :          0 :         txq->sw_ring = rte_zmalloc_socket("txq->sw_ring",
    2514                 :            :                                 sizeof(struct txgbe_tx_entry) * nb_desc,
    2515                 :            :                                 RTE_CACHE_LINE_SIZE, socket_id);
    2516         [ #  # ]:          0 :         if (txq->sw_ring == NULL) {
    2517                 :          0 :                 txgbe_tx_queue_release(txq);
    2518                 :          0 :                 return -ENOMEM;
    2519                 :            :         }
    2520                 :          0 :         PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%" PRIx64,
    2521                 :            :                      txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
    2522                 :            : 
    2523                 :            :         /* set up scalar TX function as appropriate */
    2524                 :          0 :         txgbe_set_tx_function(dev, txq);
    2525                 :            : 
    2526                 :          0 :         txq->ops->reset(txq);
    2527                 :          0 :         txq->desc_error = 0;
    2528                 :            : 
    2529                 :          0 :         dev->data->tx_queues[queue_idx] = txq;
    2530                 :            : 
    2531                 :          0 :         return 0;
    2532                 :            : }
    2533                 :            : 
    2534                 :            : /**
    2535                 :            :  * txgbe_free_sc_cluster - free the not-yet-completed scattered cluster
    2536                 :            :  *
    2537                 :            :  * The "next" pointer of the last segment of (not-yet-completed) RSC clusters
    2538                 :            :  * in the sw_rsc_ring is not set to NULL but rather points to the next
    2539                 :            :  * mbuf of this RSC aggregation (that has not been completed yet and still
    2540                 :            :  * resides on the HW ring). So, instead of calling for rte_pktmbuf_free() we
    2541                 :            :  * will just free first "nb_segs" segments of the cluster explicitly by calling
    2542                 :            :  * an rte_pktmbuf_free_seg().
    2543                 :            :  *
    2544                 :            :  * @m scattered cluster head
    2545                 :            :  */
    2546                 :            : static void __rte_cold
    2547                 :          0 : txgbe_free_sc_cluster(struct rte_mbuf *m)
    2548                 :            : {
    2549                 :          0 :         uint16_t i, nb_segs = m->nb_segs;
    2550                 :            :         struct rte_mbuf *next_seg;
    2551                 :            : 
    2552         [ #  # ]:          0 :         for (i = 0; i < nb_segs; i++) {
    2553                 :          0 :                 next_seg = m->next;
    2554                 :            :                 rte_pktmbuf_free_seg(m);
    2555                 :            :                 m = next_seg;
    2556                 :            :         }
    2557                 :          0 : }
    2558                 :            : 
    2559                 :            : static void __rte_cold
    2560                 :          0 : txgbe_rx_queue_release_mbufs(struct txgbe_rx_queue *rxq)
    2561                 :            : {
    2562                 :            :         unsigned int i;
    2563                 :            : 
    2564                 :            :         /* SSE Vector driver has a different way of releasing mbufs. */
    2565         [ #  # ]:          0 :         if (rxq->rx_using_sse) {
    2566                 :          0 :                 txgbe_rx_queue_release_mbufs_vec(rxq);
    2567                 :          0 :                 return;
    2568                 :            :         }
    2569                 :            : 
    2570         [ #  # ]:          0 :         if (rxq->sw_ring != NULL) {
    2571         [ #  # ]:          0 :                 for (i = 0; i < rxq->nb_rx_desc; i++) {
    2572         [ #  # ]:          0 :                         if (rxq->sw_ring[i].mbuf != NULL) {
    2573                 :            :                                 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
    2574                 :          0 :                                 rxq->sw_ring[i].mbuf = NULL;
    2575                 :            :                         }
    2576                 :            :                 }
    2577         [ #  # ]:          0 :                 if (rxq->rx_nb_avail) {
    2578         [ #  # ]:          0 :                         for (i = 0; i < rxq->rx_nb_avail; ++i) {
    2579                 :            :                                 struct rte_mbuf *mb;
    2580                 :            : 
    2581         [ #  # ]:          0 :                                 mb = rxq->rx_stage[rxq->rx_next_avail + i];
    2582                 :            :                                 rte_pktmbuf_free_seg(mb);
    2583                 :            :                         }
    2584                 :          0 :                         rxq->rx_nb_avail = 0;
    2585                 :            :                 }
    2586                 :            :         }
    2587                 :            : 
    2588         [ #  # ]:          0 :         if (rxq->sw_sc_ring)
    2589         [ #  # ]:          0 :                 for (i = 0; i < rxq->nb_rx_desc; i++)
    2590         [ #  # ]:          0 :                         if (rxq->sw_sc_ring[i].fbuf) {
    2591                 :          0 :                                 txgbe_free_sc_cluster(rxq->sw_sc_ring[i].fbuf);
    2592                 :          0 :                                 rxq->sw_sc_ring[i].fbuf = NULL;
    2593                 :            :                         }
    2594                 :            : }
    2595                 :            : 
    2596                 :            : static void __rte_cold
    2597                 :          0 : txgbe_rx_queue_release(struct txgbe_rx_queue *rxq)
    2598                 :            : {
    2599         [ #  # ]:          0 :         if (rxq != NULL) {
    2600                 :          0 :                 txgbe_rx_queue_release_mbufs(rxq);
    2601                 :          0 :                 rte_free(rxq->sw_ring);
    2602                 :          0 :                 rte_free(rxq->sw_sc_ring);
    2603                 :          0 :                 rte_memzone_free(rxq->mz);
    2604                 :          0 :                 rte_free(rxq);
    2605                 :            :         }
    2606                 :          0 : }
    2607                 :            : 
    2608                 :            : void __rte_cold
    2609                 :          0 : txgbe_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    2610                 :            : {
    2611                 :          0 :         txgbe_rx_queue_release(dev->data->rx_queues[qid]);
    2612                 :          0 : }
    2613                 :            : 
    2614                 :            : /*
    2615                 :            :  * Check if Rx Burst Bulk Alloc function can be used.
    2616                 :            :  * Return
    2617                 :            :  *        0: the preconditions are satisfied and the bulk allocation function
    2618                 :            :  *           can be used.
    2619                 :            :  *  -EINVAL: the preconditions are NOT satisfied and the default Rx burst
    2620                 :            :  *           function must be used.
    2621                 :            :  */
    2622                 :            : static inline int __rte_cold
    2623                 :          0 : check_rx_burst_bulk_alloc_preconditions(struct txgbe_rx_queue *rxq)
    2624                 :            : {
    2625                 :            :         int ret = 0;
    2626                 :            : 
    2627                 :            :         /*
    2628                 :            :          * Make sure the following pre-conditions are satisfied:
    2629                 :            :          *   rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST
    2630                 :            :          *   rxq->rx_free_thresh < rxq->nb_rx_desc
    2631                 :            :          *   (rxq->nb_rx_desc % rxq->rx_free_thresh) == 0
    2632                 :            :          * Scattered packets are not supported.  This should be checked
    2633                 :            :          * outside of this function.
    2634                 :            :          */
    2635         [ #  # ]:          0 :         if (!(rxq->rx_free_thresh >= RTE_PMD_TXGBE_RX_MAX_BURST)) {
    2636                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
    2637                 :            :                              "rxq->rx_free_thresh=%d, "
    2638                 :            :                              "RTE_PMD_TXGBE_RX_MAX_BURST=%d",
    2639                 :            :                              rxq->rx_free_thresh, RTE_PMD_TXGBE_RX_MAX_BURST);
    2640                 :            :                 ret = -EINVAL;
    2641         [ #  # ]:          0 :         } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
    2642                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
    2643                 :            :                              "rxq->rx_free_thresh=%d, "
    2644                 :            :                              "rxq->nb_rx_desc=%d",
    2645                 :            :                              rxq->rx_free_thresh, rxq->nb_rx_desc);
    2646                 :            :                 ret = -EINVAL;
    2647         [ #  # ]:          0 :         } else if (!((rxq->nb_rx_desc % rxq->rx_free_thresh) == 0)) {
    2648                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
    2649                 :            :                              "rxq->nb_rx_desc=%d, "
    2650                 :            :                              "rxq->rx_free_thresh=%d",
    2651                 :            :                              rxq->nb_rx_desc, rxq->rx_free_thresh);
    2652                 :            :                 ret = -EINVAL;
    2653                 :            :         }
    2654                 :            : 
    2655                 :          0 :         return ret;
    2656                 :            : }
    2657                 :            : 
    2658                 :            : /* Reset dynamic txgbe_rx_queue fields back to defaults */
    2659                 :            : static void __rte_cold
    2660                 :          0 : txgbe_reset_rx_queue(struct txgbe_adapter *adapter, struct txgbe_rx_queue *rxq)
    2661                 :            : {
    2662                 :            :         static const struct txgbe_rx_desc zeroed_desc = {
    2663                 :            :                                                 {{0}, {0} }, {{0}, {0} } };
    2664                 :            :         unsigned int i;
    2665                 :          0 :         uint16_t len = rxq->nb_rx_desc;
    2666                 :            : 
    2667                 :            :         /*
    2668                 :            :          * By default, the Rx queue setup function allocates enough memory for
    2669                 :            :          * TXGBE_RING_DESC_MAX.  The Rx Burst bulk allocation function requires
    2670                 :            :          * extra memory at the end of the descriptor ring to be zero'd out.
    2671                 :            :          */
    2672         [ #  # ]:          0 :         if (adapter->rx_bulk_alloc_allowed)
    2673                 :            :                 /* zero out extra memory */
    2674                 :          0 :                 len += RTE_PMD_TXGBE_RX_MAX_BURST;
    2675                 :            : 
    2676                 :            :         /*
    2677                 :            :          * Zero out HW ring memory. Zero out extra memory at the end of
    2678                 :            :          * the H/W ring so look-ahead logic in Rx Burst bulk alloc function
    2679                 :            :          * reads extra memory as zeros.
    2680                 :            :          */
    2681         [ #  # ]:          0 :         for (i = 0; i < len; i++)
    2682                 :          0 :                 rxq->rx_ring[i] = zeroed_desc;
    2683                 :            : 
    2684                 :            :         /*
    2685                 :            :          * initialize extra software ring entries. Space for these extra
    2686                 :            :          * entries is always allocated
    2687                 :            :          */
    2688                 :          0 :         memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
    2689         [ #  # ]:          0 :         for (i = rxq->nb_rx_desc; i < len; ++i)
    2690                 :          0 :                 rxq->sw_ring[i].mbuf = &rxq->fake_mbuf;
    2691                 :            : 
    2692                 :          0 :         rxq->rx_nb_avail = 0;
    2693                 :          0 :         rxq->rx_next_avail = 0;
    2694                 :          0 :         rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
    2695                 :          0 :         rxq->rx_tail = 0;
    2696                 :          0 :         rxq->nb_rx_hold = 0;
    2697                 :          0 :         rte_pktmbuf_free(rxq->pkt_first_seg);
    2698                 :          0 :         rxq->pkt_first_seg = NULL;
    2699                 :          0 :         rxq->pkt_last_seg = NULL;
    2700                 :            : 
    2701                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
    2702                 :          0 :         rxq->rxrearm_start = 0;
    2703                 :          0 :         rxq->rxrearm_nb = 0;
    2704                 :            : #endif
    2705                 :          0 : }
    2706                 :            : 
    2707                 :            : int __rte_cold
    2708                 :          0 : txgbe_dev_rx_queue_setup(struct rte_eth_dev *dev,
    2709                 :            :                          uint16_t queue_idx,
    2710                 :            :                          uint16_t nb_desc,
    2711                 :            :                          unsigned int socket_id,
    2712                 :            :                          const struct rte_eth_rxconf *rx_conf,
    2713                 :            :                          struct rte_mempool *mp)
    2714                 :            : {
    2715                 :            :         const struct rte_memzone *rz;
    2716                 :            :         struct txgbe_rx_queue *rxq;
    2717                 :            :         struct txgbe_hw     *hw;
    2718                 :            :         uint16_t len;
    2719                 :          0 :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
    2720                 :            :         uint64_t offloads;
    2721                 :            : 
    2722                 :          0 :         PMD_INIT_FUNC_TRACE();
    2723                 :          0 :         hw = TXGBE_DEV_HW(dev);
    2724                 :            : 
    2725                 :          0 :         offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
    2726                 :            : 
    2727                 :            :         /*
    2728                 :            :          * Validate number of receive descriptors.
    2729                 :            :          * It must not exceed hardware maximum, and must be multiple
    2730                 :            :          * of TXGBE_ALIGN.
    2731                 :            :          */
    2732         [ #  # ]:          0 :         if (nb_desc % TXGBE_RXD_ALIGN != 0 ||
    2733         [ #  # ]:          0 :                         nb_desc > TXGBE_RING_DESC_MAX ||
    2734                 :            :                         nb_desc < TXGBE_RING_DESC_MIN) {
    2735                 :            :                 return -EINVAL;
    2736                 :            :         }
    2737                 :            : 
    2738                 :            :         /* Free memory prior to re-allocation if needed... */
    2739         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_idx] != NULL) {
    2740                 :          0 :                 txgbe_rx_queue_release(dev->data->rx_queues[queue_idx]);
    2741                 :          0 :                 dev->data->rx_queues[queue_idx] = NULL;
    2742                 :            :         }
    2743                 :            : 
    2744                 :            :         /* First allocate the rx queue data structure */
    2745                 :          0 :         rxq = rte_zmalloc_socket("ethdev RX queue",
    2746                 :            :                                  sizeof(struct txgbe_rx_queue),
    2747                 :            :                                  RTE_CACHE_LINE_SIZE, socket_id);
    2748         [ #  # ]:          0 :         if (rxq == NULL)
    2749                 :            :                 return -ENOMEM;
    2750                 :          0 :         rxq->mb_pool = mp;
    2751                 :          0 :         rxq->nb_rx_desc = nb_desc;
    2752                 :          0 :         rxq->rx_free_thresh = rx_conf->rx_free_thresh;
    2753                 :          0 :         rxq->queue_id = queue_idx;
    2754         [ #  # ]:          0 :         rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
    2755                 :          0 :                 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
    2756                 :          0 :         rxq->port_id = dev->data->port_id;
    2757         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    2758                 :          0 :                 rxq->crc_len = RTE_ETHER_CRC_LEN;
    2759                 :            :         else
    2760                 :          0 :                 rxq->crc_len = 0;
    2761                 :          0 :         rxq->drop_en = rx_conf->rx_drop_en;
    2762                 :          0 :         rxq->rx_deferred_start = rx_conf->rx_deferred_start;
    2763                 :          0 :         rxq->offloads = offloads;
    2764                 :            : 
    2765                 :            :         /*
    2766                 :            :          * The packet type in RX descriptor is different for different NICs.
    2767                 :            :          * So set different masks for different NICs.
    2768                 :            :          */
    2769                 :          0 :         rxq->pkt_type_mask = TXGBE_PTID_MASK;
    2770                 :            : 
    2771                 :            :         /*
    2772                 :            :          * Allocate RX ring hardware descriptors. A memzone large enough to
    2773                 :            :          * handle the maximum ring size is allocated in order to allow for
    2774                 :            :          * resizing in later calls to the queue setup function.
    2775                 :            :          */
    2776                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
    2777                 :            :                                       RX_RING_SZ, TXGBE_ALIGN, socket_id);
    2778         [ #  # ]:          0 :         if (rz == NULL) {
    2779                 :          0 :                 txgbe_rx_queue_release(rxq);
    2780                 :          0 :                 return -ENOMEM;
    2781                 :            :         }
    2782                 :            : 
    2783                 :          0 :         rxq->mz = rz;
    2784                 :            :         /*
    2785                 :            :          * Zero init all the descriptors in the ring.
    2786                 :            :          */
    2787         [ #  # ]:          0 :         memset(rz->addr, 0, RX_RING_SZ);
    2788                 :            : 
    2789                 :            :         /*
    2790                 :            :          * Modified to setup VFRDT for Virtual Function
    2791                 :            :          */
    2792         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor_vf) {
    2793                 :          0 :                 rxq->rdt_reg_addr =
    2794                 :          0 :                         TXGBE_REG_ADDR(hw, TXGBE_RXWP(queue_idx));
    2795                 :          0 :                 rxq->rdh_reg_addr =
    2796                 :          0 :                         TXGBE_REG_ADDR(hw, TXGBE_RXRP(queue_idx));
    2797                 :            :         } else {
    2798                 :          0 :                 rxq->rdt_reg_addr =
    2799                 :          0 :                         TXGBE_REG_ADDR(hw, TXGBE_RXWP(rxq->reg_idx));
    2800                 :          0 :                 rxq->rdh_reg_addr =
    2801                 :          0 :                         TXGBE_REG_ADDR(hw, TXGBE_RXRP(rxq->reg_idx));
    2802                 :            :         }
    2803                 :            : 
    2804                 :          0 :         rxq->rx_ring_phys_addr = TMZ_PADDR(rz);
    2805                 :          0 :         rxq->rx_ring = (struct txgbe_rx_desc *)TMZ_VADDR(rz);
    2806                 :            : 
    2807                 :            :         /*
    2808                 :            :          * Certain constraints must be met in order to use the bulk buffer
    2809                 :            :          * allocation Rx burst function. If any of Rx queues doesn't meet them
    2810                 :            :          * the feature should be disabled for the whole port.
    2811                 :            :          */
    2812         [ #  # ]:          0 :         if (check_rx_burst_bulk_alloc_preconditions(rxq)) {
    2813                 :          0 :                 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Rx Bulk Alloc "
    2814                 :            :                                     "preconditions - canceling the feature for "
    2815                 :            :                                     "the whole port[%d]",
    2816                 :            :                              rxq->queue_id, rxq->port_id);
    2817                 :          0 :                 adapter->rx_bulk_alloc_allowed = false;
    2818                 :            :         }
    2819                 :            : 
    2820                 :            :         /*
    2821                 :            :          * Allocate software ring. Allow for space at the end of the
    2822                 :            :          * S/W ring to make sure look-ahead logic in bulk alloc Rx burst
    2823                 :            :          * function does not access an invalid memory region.
    2824                 :            :          */
    2825                 :            :         len = nb_desc;
    2826         [ #  # ]:          0 :         if (adapter->rx_bulk_alloc_allowed)
    2827                 :          0 :                 len += RTE_PMD_TXGBE_RX_MAX_BURST;
    2828                 :            : 
    2829                 :          0 :         rxq->sw_ring = rte_zmalloc_socket("rxq->sw_ring",
    2830                 :            :                                           sizeof(struct txgbe_rx_entry) * len,
    2831                 :            :                                           RTE_CACHE_LINE_SIZE, socket_id);
    2832         [ #  # ]:          0 :         if (!rxq->sw_ring) {
    2833                 :          0 :                 txgbe_rx_queue_release(rxq);
    2834                 :          0 :                 return -ENOMEM;
    2835                 :            :         }
    2836                 :            : 
    2837                 :            :         /*
    2838                 :            :          * Always allocate even if it's not going to be needed in order to
    2839                 :            :          * simplify the code.
    2840                 :            :          *
    2841                 :            :          * This ring is used in LRO and Scattered Rx cases and Scattered Rx may
    2842                 :            :          * be requested in txgbe_dev_rx_init(), which is called later from
    2843                 :            :          * dev_start() flow.
    2844                 :            :          */
    2845                 :          0 :         rxq->sw_sc_ring =
    2846                 :          0 :                 rte_zmalloc_socket("rxq->sw_sc_ring",
    2847                 :            :                                   sizeof(struct txgbe_scattered_rx_entry) * len,
    2848                 :            :                                   RTE_CACHE_LINE_SIZE, socket_id);
    2849         [ #  # ]:          0 :         if (!rxq->sw_sc_ring) {
    2850                 :          0 :                 txgbe_rx_queue_release(rxq);
    2851                 :          0 :                 return -ENOMEM;
    2852                 :            :         }
    2853                 :            : 
    2854                 :          0 :         PMD_INIT_LOG(DEBUG, "sw_ring=%p sw_sc_ring=%p hw_ring=%p "
    2855                 :            :                             "dma_addr=0x%" PRIx64,
    2856                 :            :                      rxq->sw_ring, rxq->sw_sc_ring, rxq->rx_ring,
    2857                 :            :                      rxq->rx_ring_phys_addr);
    2858                 :            : 
    2859         [ #  # ]:          0 :         if (!rte_is_power_of_2(nb_desc)) {
    2860                 :          0 :                 PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
    2861                 :            :                                     "preconditions - canceling the feature for "
    2862                 :            :                                     "the whole port[%d]",
    2863                 :            :                              rxq->queue_id, rxq->port_id);
    2864                 :          0 :                 adapter->rx_vec_allowed = false;
    2865                 :            :         } else {
    2866                 :          0 :                 txgbe_rxq_vec_setup(rxq);
    2867                 :            :         }
    2868                 :            : 
    2869                 :          0 :         dev->data->rx_queues[queue_idx] = rxq;
    2870                 :            : 
    2871                 :          0 :         txgbe_reset_rx_queue(adapter, rxq);
    2872                 :            : 
    2873                 :          0 :         return 0;
    2874                 :            : }
    2875                 :            : 
    2876                 :            : uint32_t
    2877                 :          0 : txgbe_dev_rx_queue_count(void *rx_queue)
    2878                 :            : {
    2879                 :            : #define TXGBE_RXQ_SCAN_INTERVAL 4
    2880                 :            :         volatile struct txgbe_rx_desc *rxdp;
    2881                 :            :         struct txgbe_rx_queue *rxq;
    2882                 :            :         uint32_t desc = 0;
    2883                 :            : 
    2884                 :            :         rxq = rx_queue;
    2885                 :          0 :         rxdp = &rxq->rx_ring[rxq->rx_tail];
    2886                 :            : 
    2887         [ #  # ]:          0 :         while ((desc < rxq->nb_rx_desc) &&
    2888         [ #  # ]:          0 :                 (rxdp->qw1.lo.status &
    2889                 :            :                         rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))) {
    2890                 :          0 :                 desc += TXGBE_RXQ_SCAN_INTERVAL;
    2891                 :          0 :                 rxdp += TXGBE_RXQ_SCAN_INTERVAL;
    2892         [ #  # ]:          0 :                 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
    2893                 :          0 :                         rxdp = &(rxq->rx_ring[rxq->rx_tail +
    2894                 :          0 :                                 desc - rxq->nb_rx_desc]);
    2895                 :            :         }
    2896                 :            : 
    2897                 :          0 :         return desc;
    2898                 :            : }
    2899                 :            : 
    2900                 :            : int
    2901                 :          0 : txgbe_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
    2902                 :            : {
    2903                 :            :         struct txgbe_rx_queue *rxq = rx_queue;
    2904                 :            :         volatile uint32_t *status;
    2905                 :            :         uint32_t nb_hold, desc;
    2906                 :            : 
    2907         [ #  # ]:          0 :         if (unlikely(offset >= rxq->nb_rx_desc))
    2908                 :            :                 return -EINVAL;
    2909                 :            : 
    2910                 :            : #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM)
    2911         [ #  # ]:          0 :         if (rxq->rx_using_sse)
    2912                 :          0 :                 nb_hold = rxq->rxrearm_nb;
    2913                 :            :         else
    2914                 :            : #endif
    2915                 :          0 :                 nb_hold = rxq->nb_rx_hold;
    2916         [ #  # ]:          0 :         if (offset >= rxq->nb_rx_desc - nb_hold)
    2917                 :            :                 return RTE_ETH_RX_DESC_UNAVAIL;
    2918                 :            : 
    2919                 :          0 :         desc = rxq->rx_tail + offset;
    2920         [ #  # ]:          0 :         if (desc >= rxq->nb_rx_desc)
    2921                 :          0 :                 desc -= rxq->nb_rx_desc;
    2922                 :            : 
    2923                 :          0 :         status = &rxq->rx_ring[desc].qw1.lo.status;
    2924         [ #  # ]:          0 :         if (*status & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))
    2925                 :          0 :                 return RTE_ETH_RX_DESC_DONE;
    2926                 :            : 
    2927                 :            :         return RTE_ETH_RX_DESC_AVAIL;
    2928                 :            : }
    2929                 :            : 
    2930                 :            : int
    2931                 :          0 : txgbe_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
    2932                 :            : {
    2933                 :            :         struct txgbe_tx_queue *txq = tx_queue;
    2934                 :            :         volatile uint32_t *status;
    2935                 :            :         uint32_t desc;
    2936                 :            : 
    2937         [ #  # ]:          0 :         if (unlikely(offset >= txq->nb_tx_desc))
    2938                 :            :                 return -EINVAL;
    2939                 :            : 
    2940                 :          0 :         desc = txq->tx_tail + offset;
    2941         [ #  # ]:          0 :         if (desc >= txq->nb_tx_desc) {
    2942                 :          0 :                 desc -= txq->nb_tx_desc;
    2943         [ #  # ]:          0 :                 if (desc >= txq->nb_tx_desc)
    2944                 :          0 :                         desc -= txq->nb_tx_desc;
    2945                 :            :         }
    2946                 :            : 
    2947                 :          0 :         status = &txq->tx_ring[desc].dw3;
    2948         [ #  # ]:          0 :         if (*status & rte_cpu_to_le_32(TXGBE_TXD_DD))
    2949                 :          0 :                 return RTE_ETH_TX_DESC_DONE;
    2950                 :            : 
    2951                 :            :         return RTE_ETH_TX_DESC_FULL;
    2952                 :            : }
    2953                 :            : 
    2954                 :            : void __rte_cold
    2955                 :          0 : txgbe_dev_clear_queues(struct rte_eth_dev *dev)
    2956                 :            : {
    2957                 :            :         unsigned int i;
    2958                 :          0 :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
    2959                 :            : 
    2960                 :          0 :         PMD_INIT_FUNC_TRACE();
    2961                 :            : 
    2962         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2963                 :          0 :                 struct txgbe_tx_queue *txq = dev->data->tx_queues[i];
    2964                 :            : 
    2965         [ #  # ]:          0 :                 if (txq != NULL) {
    2966                 :          0 :                         txq->ops->release_mbufs(txq);
    2967                 :          0 :                         txq->ops->reset(txq);
    2968                 :            :                 }
    2969                 :            : 
    2970                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    2971                 :            :         }
    2972                 :            : 
    2973         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2974                 :          0 :                 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
    2975                 :            : 
    2976         [ #  # ]:          0 :                 if (rxq != NULL) {
    2977                 :          0 :                         txgbe_rx_queue_release_mbufs(rxq);
    2978                 :          0 :                         txgbe_reset_rx_queue(adapter, rxq);
    2979                 :            :                 }
    2980                 :            : 
    2981                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    2982                 :            :         }
    2983                 :          0 : }
    2984                 :            : 
    2985                 :            : void
    2986                 :          0 : txgbe_dev_free_queues(struct rte_eth_dev *dev)
    2987                 :            : {
    2988                 :            :         unsigned int i;
    2989                 :            : 
    2990                 :          0 :         PMD_INIT_FUNC_TRACE();
    2991                 :            : 
    2992         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2993                 :          0 :                 txgbe_dev_rx_queue_release(dev, i);
    2994                 :          0 :                 dev->data->rx_queues[i] = NULL;
    2995                 :            :         }
    2996                 :          0 :         dev->data->nb_rx_queues = 0;
    2997                 :            : 
    2998         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2999                 :          0 :                 txgbe_dev_tx_queue_release(dev, i);
    3000                 :          0 :                 dev->data->tx_queues[i] = NULL;
    3001                 :            :         }
    3002                 :          0 :         dev->data->nb_tx_queues = 0;
    3003                 :          0 : }
    3004                 :            : 
    3005                 :            : /**
    3006                 :            :  * Receive Side Scaling (RSS)
    3007                 :            :  *
    3008                 :            :  * Principles:
    3009                 :            :  * The source and destination IP addresses of the IP header and the source
    3010                 :            :  * and destination ports of TCP/UDP headers, if any, of received packets are
    3011                 :            :  * hashed against a configurable random key to compute a 32-bit RSS hash result.
    3012                 :            :  * The seven (7) LSBs of the 32-bit hash result are used as an index into a
    3013                 :            :  * 128-entry redirection table (RETA).  Each entry of the RETA provides a 3-bit
    3014                 :            :  * RSS output index which is used as the RX queue index where to store the
    3015                 :            :  * received packets.
    3016                 :            :  * The following output is supplied in the RX write-back descriptor:
    3017                 :            :  *     - 32-bit result of the Microsoft RSS hash function,
    3018                 :            :  *     - 4-bit RSS type field.
    3019                 :            :  */
    3020                 :            : 
    3021                 :            : /*
    3022                 :            :  * Used as the default key.
    3023                 :            :  */
    3024                 :            : static uint8_t rss_intel_key[40] = {
    3025                 :            :         0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
    3026                 :            :         0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
    3027                 :            :         0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
    3028                 :            :         0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
    3029                 :            :         0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
    3030                 :            : };
    3031                 :            : 
    3032                 :            : static void
    3033                 :          0 : txgbe_rss_disable(struct rte_eth_dev *dev)
    3034                 :            : {
    3035                 :            :         struct txgbe_hw *hw;
    3036                 :            : 
    3037                 :          0 :         hw = TXGBE_DEV_HW(dev);
    3038         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor_vf)
    3039                 :            :                 wr32m(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_RSSENA, 0);
    3040                 :            :         else
    3041                 :            :                 wr32m(hw, TXGBE_RACTL, TXGBE_RACTL_RSSENA, 0);
    3042                 :          0 : }
    3043                 :            : 
    3044                 :            : int
    3045                 :          0 : txgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
    3046                 :            :                           struct rte_eth_rss_conf *rss_conf)
    3047                 :            : {
    3048                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3049                 :            :         uint8_t  *hash_key;
    3050                 :            :         uint32_t mrqc;
    3051                 :            :         uint32_t rss_key;
    3052                 :            :         uint64_t rss_hf;
    3053                 :            :         uint16_t i;
    3054                 :            : 
    3055         [ #  # ]:          0 :         if (!txgbe_rss_update_sp(hw->mac.type)) {
    3056                 :          0 :                 PMD_DRV_LOG(ERR, "RSS hash update is not supported on this "
    3057                 :            :                         "NIC.");
    3058                 :          0 :                 return -ENOTSUP;
    3059                 :            :         }
    3060                 :            : 
    3061                 :          0 :         hash_key = rss_conf->rss_key;
    3062         [ #  # ]:          0 :         if (hash_key) {
    3063                 :            :                 /* Fill in RSS hash key */
    3064         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    3065                 :          0 :                         rss_key  = LS32(hash_key[(i * 4) + 0], 0, 0xFF);
    3066                 :          0 :                         rss_key |= LS32(hash_key[(i * 4) + 1], 8, 0xFF);
    3067                 :          0 :                         rss_key |= LS32(hash_key[(i * 4) + 2], 16, 0xFF);
    3068         [ #  # ]:          0 :                         rss_key |= LS32(hash_key[(i * 4) + 3], 24, 0xFF);
    3069                 :          0 :                         wr32at(hw, TXGBE_REG_RSSKEY, i, rss_key);
    3070                 :            :                 }
    3071                 :            :         }
    3072                 :            : 
    3073                 :            :         /* Set configured hashing protocols */
    3074                 :          0 :         rss_hf = rss_conf->rss_hf & TXGBE_RSS_OFFLOAD_ALL;
    3075         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor_vf) {
    3076                 :            :                 mrqc = rd32(hw, TXGBE_VFPLCFG);
    3077                 :          0 :                 mrqc &= ~TXGBE_VFPLCFG_RSSMASK;
    3078         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_IPV4)
    3079                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV4;
    3080         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
    3081                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV4TCP;
    3082         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_IPV6 ||
    3083                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_EX)
    3084                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV6;
    3085         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP ||
    3086                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
    3087                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV6TCP;
    3088         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
    3089                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV4UDP;
    3090         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP ||
    3091                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
    3092                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSIPV6UDP;
    3093                 :            : 
    3094         [ #  # ]:          0 :                 if (rss_hf)
    3095                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSENA;
    3096                 :            :                 else
    3097                 :          0 :                         mrqc &= ~TXGBE_VFPLCFG_RSSENA;
    3098                 :            : 
    3099         [ #  # ]:          0 :                 if (dev->data->nb_rx_queues > 3)
    3100                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSHASH(2);
    3101         [ #  # ]:          0 :                 else if (dev->data->nb_rx_queues > 1)
    3102                 :          0 :                         mrqc |= TXGBE_VFPLCFG_RSSHASH(1);
    3103                 :            : 
    3104                 :            :                 wr32(hw, TXGBE_VFPLCFG, mrqc);
    3105                 :            :         } else {
    3106                 :            :                 mrqc = rd32(hw, TXGBE_RACTL);
    3107                 :          0 :                 mrqc &= ~TXGBE_RACTL_RSSMASK;
    3108         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_IPV4)
    3109                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV4;
    3110         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
    3111                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV4TCP;
    3112         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_IPV6 ||
    3113                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_EX)
    3114                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV6;
    3115         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP ||
    3116                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
    3117                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV6TCP;
    3118         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
    3119                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV4UDP;
    3120         [ #  # ]:          0 :                 if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP ||
    3121                 :            :                     rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
    3122                 :          0 :                         mrqc |= TXGBE_RACTL_RSSIPV6UDP;
    3123                 :            : 
    3124         [ #  # ]:          0 :                 if (rss_hf)
    3125                 :          0 :                         mrqc |= TXGBE_RACTL_RSSENA;
    3126                 :            :                 else
    3127                 :          0 :                         mrqc &= ~TXGBE_RACTL_RSSENA;
    3128                 :            : 
    3129                 :            :                 wr32(hw, TXGBE_RACTL, mrqc);
    3130                 :            :         }
    3131                 :            : 
    3132                 :            :         return 0;
    3133                 :            : }
    3134                 :            : 
    3135                 :            : int
    3136                 :          0 : txgbe_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
    3137                 :            :                             struct rte_eth_rss_conf *rss_conf)
    3138                 :            : {
    3139                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3140                 :            :         uint8_t *hash_key;
    3141                 :            :         uint32_t mrqc;
    3142                 :            :         uint32_t rss_key;
    3143                 :            :         uint64_t rss_hf;
    3144                 :            :         uint16_t i;
    3145                 :            : 
    3146                 :          0 :         hash_key = rss_conf->rss_key;
    3147         [ #  # ]:          0 :         if (hash_key) {
    3148                 :            :                 /* Return RSS hash key */
    3149         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    3150                 :          0 :                         rss_key = rd32at(hw, TXGBE_REG_RSSKEY, i);
    3151                 :          0 :                         hash_key[(i * 4) + 0] = RS32(rss_key, 0, 0xFF);
    3152                 :          0 :                         hash_key[(i * 4) + 1] = RS32(rss_key, 8, 0xFF);
    3153                 :          0 :                         hash_key[(i * 4) + 2] = RS32(rss_key, 16, 0xFF);
    3154                 :          0 :                         hash_key[(i * 4) + 3] = RS32(rss_key, 24, 0xFF);
    3155                 :            :                 }
    3156                 :            :         }
    3157                 :            : 
    3158                 :            :         rss_hf = 0;
    3159         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor_vf) {
    3160                 :            :                 mrqc = rd32(hw, TXGBE_VFPLCFG);
    3161         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV4)
    3162                 :            :                         rss_hf |= RTE_ETH_RSS_IPV4;
    3163         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV4TCP)
    3164                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
    3165         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV6)
    3166                 :          0 :                         rss_hf |= RTE_ETH_RSS_IPV6 |
    3167                 :            :                                   RTE_ETH_RSS_IPV6_EX;
    3168         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV6TCP)
    3169                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP |
    3170                 :            :                                   RTE_ETH_RSS_IPV6_TCP_EX;
    3171         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV4UDP)
    3172                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
    3173         [ #  # ]:          0 :                 if (mrqc & TXGBE_VFPLCFG_RSSIPV6UDP)
    3174                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP |
    3175                 :            :                                   RTE_ETH_RSS_IPV6_UDP_EX;
    3176         [ #  # ]:          0 :                 if (!(mrqc & TXGBE_VFPLCFG_RSSENA))
    3177                 :            :                         rss_hf = 0;
    3178                 :            :         } else {
    3179                 :            :                 mrqc = rd32(hw, TXGBE_RACTL);
    3180         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV4)
    3181                 :            :                         rss_hf |= RTE_ETH_RSS_IPV4;
    3182         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV4TCP)
    3183                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
    3184         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV6)
    3185                 :          0 :                         rss_hf |= RTE_ETH_RSS_IPV6 |
    3186                 :            :                                   RTE_ETH_RSS_IPV6_EX;
    3187         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV6TCP)
    3188                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP |
    3189                 :            :                                   RTE_ETH_RSS_IPV6_TCP_EX;
    3190         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV4UDP)
    3191                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
    3192         [ #  # ]:          0 :                 if (mrqc & TXGBE_RACTL_RSSIPV6UDP)
    3193                 :          0 :                         rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP |
    3194                 :            :                                   RTE_ETH_RSS_IPV6_UDP_EX;
    3195         [ #  # ]:          0 :                 if (!(mrqc & TXGBE_RACTL_RSSENA))
    3196                 :            :                         rss_hf = 0;
    3197                 :            :         }
    3198                 :            : 
    3199                 :            :         rss_hf &= TXGBE_RSS_OFFLOAD_ALL;
    3200                 :            : 
    3201                 :          0 :         rss_conf->rss_hf = rss_hf;
    3202                 :          0 :         return 0;
    3203                 :            : }
    3204                 :            : 
    3205                 :            : static void
    3206                 :          0 : txgbe_rss_configure(struct rte_eth_dev *dev)
    3207                 :            : {
    3208                 :            :         struct rte_eth_rss_conf rss_conf;
    3209                 :          0 :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
    3210                 :            :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3211                 :            :         uint32_t reta;
    3212                 :            :         uint16_t i;
    3213                 :            :         uint16_t j;
    3214                 :            : 
    3215                 :          0 :         PMD_INIT_FUNC_TRACE();
    3216                 :            : 
    3217                 :            :         /*
    3218                 :            :          * Fill in redirection table
    3219                 :            :          * The byte-swap is needed because NIC registers are in
    3220                 :            :          * little-endian order.
    3221                 :            :          */
    3222         [ #  # ]:          0 :         if (adapter->rss_reta_updated == 0) {
    3223                 :            :                 reta = 0;
    3224         [ #  # ]:          0 :                 for (i = 0, j = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i++, j++) {
    3225         [ #  # ]:          0 :                         if (j == dev->data->nb_rx_queues)
    3226                 :            :                                 j = 0;
    3227                 :          0 :                         reta = (reta >> 8) | LS32(j, 24, 0xFF);
    3228         [ #  # ]:          0 :                         if ((i & 3) == 3)
    3229                 :          0 :                                 wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
    3230                 :            :                 }
    3231                 :            :         }
    3232                 :            :         /*
    3233                 :            :          * Configure the RSS key and the RSS protocols used to compute
    3234                 :            :          * the RSS hash of input packets.
    3235                 :            :          */
    3236                 :          0 :         rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
    3237         [ #  # ]:          0 :         if (rss_conf.rss_key == NULL)
    3238                 :          0 :                 rss_conf.rss_key = rss_intel_key; /* Default hash key */
    3239                 :          0 :         txgbe_dev_rss_hash_update(dev, &rss_conf);
    3240                 :          0 : }
    3241                 :            : 
    3242                 :            : #define NUM_VFTA_REGISTERS 128
    3243                 :            : #define NIC_RX_BUFFER_SIZE 0x200
    3244                 :            : 
    3245                 :            : static void
    3246                 :          0 : txgbe_vmdq_dcb_configure(struct rte_eth_dev *dev)
    3247                 :            : {
    3248                 :            :         struct rte_eth_vmdq_dcb_conf *cfg;
    3249                 :            :         struct txgbe_hw *hw;
    3250                 :            :         enum rte_eth_nb_pools num_pools;
    3251                 :            :         uint32_t mrqc, vt_ctl, queue_mapping, vlanctrl;
    3252                 :            :         uint16_t pbsize;
    3253                 :            :         uint8_t nb_tcs; /* number of traffic classes */
    3254                 :            :         int i;
    3255                 :            : 
    3256                 :          0 :         PMD_INIT_FUNC_TRACE();
    3257                 :          0 :         hw = TXGBE_DEV_HW(dev);
    3258                 :            :         cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
    3259                 :          0 :         num_pools = cfg->nb_queue_pools;
    3260                 :            :         /* Check we have a valid number of pools */
    3261         [ #  # ]:          0 :         if (num_pools != RTE_ETH_16_POOLS && num_pools != RTE_ETH_32_POOLS) {
    3262                 :          0 :                 txgbe_rss_disable(dev);
    3263                 :          0 :                 return;
    3264                 :            :         }
    3265                 :            :         /* 16 pools -> 8 traffic classes, 32 pools -> 4 traffic classes */
    3266                 :          0 :         nb_tcs = (uint8_t)(RTE_ETH_VMDQ_DCB_NUM_QUEUES / (int)num_pools);
    3267                 :            : 
    3268                 :            :         /*
    3269                 :            :          * split rx buffer up into sections, each for 1 traffic class
    3270                 :            :          */
    3271                 :          0 :         pbsize = (uint16_t)(NIC_RX_BUFFER_SIZE / nb_tcs);
    3272         [ #  # ]:          0 :         for (i = 0; i < nb_tcs; i++) {
    3273                 :          0 :                 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
    3274                 :            : 
    3275                 :          0 :                 rxpbsize &= (~(0x3FF << 10));
    3276                 :            :                 /* clear 10 bits. */
    3277                 :          0 :                 rxpbsize |= (pbsize << 10); /* set value */
    3278                 :            :                 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
    3279                 :            :         }
    3280                 :            :         /* zero alloc all unused TCs */
    3281         [ #  # ]:          0 :         for (i = nb_tcs; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3282                 :          0 :                 uint32_t rxpbsize = rd32(hw, TXGBE_PBRXSIZE(i));
    3283                 :            : 
    3284                 :          0 :                 rxpbsize &= (~(0x3FF << 10));
    3285                 :            :                 /* clear 10 bits. */
    3286                 :            :                 wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
    3287                 :            :         }
    3288                 :            : 
    3289         [ #  # ]:          0 :         if (num_pools == RTE_ETH_16_POOLS) {
    3290                 :            :                 mrqc = TXGBE_PORTCTL_NUMTC_8;
    3291                 :            :                 mrqc |= TXGBE_PORTCTL_NUMVT_16;
    3292                 :            :         } else {
    3293                 :            :                 mrqc = TXGBE_PORTCTL_NUMTC_4;
    3294                 :            :                 mrqc |= TXGBE_PORTCTL_NUMVT_32;
    3295                 :            :         }
    3296                 :            :         wr32m(hw, TXGBE_PORTCTL,
    3297                 :            :               TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK, mrqc);
    3298                 :            : 
    3299                 :            :         vt_ctl = TXGBE_POOLCTL_RPLEN;
    3300         [ #  # ]:          0 :         if (cfg->enable_default_pool)
    3301                 :          0 :                 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
    3302                 :            :         else
    3303                 :            :                 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
    3304                 :            : 
    3305                 :            :         wr32(hw, TXGBE_POOLCTL, vt_ctl);
    3306                 :            : 
    3307                 :            :         queue_mapping = 0;
    3308         [ #  # ]:          0 :         for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
    3309                 :            :                 /*
    3310                 :            :                  * mapping is done with 3 bits per priority,
    3311                 :            :                  * so shift by i*3 each time
    3312                 :            :                  */
    3313                 :          0 :                 queue_mapping |= ((cfg->dcb_tc[i] & 0x07) << (i * 3));
    3314                 :            : 
    3315                 :            :         wr32(hw, TXGBE_RPUP2TC, queue_mapping);
    3316                 :            : 
    3317                 :            :         wr32(hw, TXGBE_ARBRXCTL, TXGBE_ARBRXCTL_RRM);
    3318                 :            : 
    3319                 :            :         /* enable vlan filtering and allow all vlan tags through */
    3320                 :            :         vlanctrl = rd32(hw, TXGBE_VLANCTL);
    3321                 :          0 :         vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
    3322                 :            :         wr32(hw, TXGBE_VLANCTL, vlanctrl);
    3323                 :            : 
    3324                 :            :         /* enable all vlan filters */
    3325         [ #  # ]:          0 :         for (i = 0; i < NUM_VFTA_REGISTERS; i++)
    3326                 :          0 :                 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
    3327                 :            : 
    3328         [ #  # ]:          0 :         wr32(hw, TXGBE_POOLRXENA(0),
    3329                 :            :                         num_pools == RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
    3330                 :            : 
    3331                 :            :         wr32(hw, TXGBE_ETHADDRIDX, 0);
    3332                 :            :         wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
    3333                 :            :         wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
    3334                 :            : 
    3335                 :            :         /* set up filters for vlan tags as configured */
    3336         [ #  # ]:          0 :         for (i = 0; i < cfg->nb_pool_maps; i++) {
    3337                 :            :                 /* set vlan id in VF register and set the valid bit */
    3338                 :          0 :                 wr32(hw, TXGBE_PSRVLANIDX, i);
    3339                 :          0 :                 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
    3340                 :          0 :                                 (cfg->pool_map[i].vlan_id & 0xFFF)));
    3341                 :            : 
    3342                 :          0 :                 wr32(hw, TXGBE_PSRVLANPLM(0), cfg->pool_map[i].pools);
    3343                 :            :         }
    3344                 :            : }
    3345                 :            : 
    3346                 :            : /**
    3347                 :            :  * txgbe_dcb_config_tx_hw_config - Configure general DCB TX parameters
    3348                 :            :  * @dev: pointer to eth_dev structure
    3349                 :            :  * @dcb_config: pointer to txgbe_dcb_config structure
    3350                 :            :  */
    3351                 :            : static void
    3352                 :          0 : txgbe_dcb_tx_hw_config(struct rte_eth_dev *dev,
    3353                 :            :                        struct txgbe_dcb_config *dcb_config)
    3354                 :            : {
    3355                 :            :         uint32_t reg;
    3356                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3357                 :            : 
    3358                 :          0 :         PMD_INIT_FUNC_TRACE();
    3359                 :            : 
    3360                 :            :         /* Disable the Tx desc arbiter */
    3361                 :            :         reg = rd32(hw, TXGBE_ARBTXCTL);
    3362                 :          0 :         reg |= TXGBE_ARBTXCTL_DIA;
    3363                 :            :         wr32(hw, TXGBE_ARBTXCTL, reg);
    3364                 :            : 
    3365                 :            :         /* Enable DCB for Tx with 8 TCs */
    3366                 :            :         reg = rd32(hw, TXGBE_PORTCTL);
    3367                 :          0 :         reg &= TXGBE_PORTCTL_NUMTC_MASK;
    3368                 :          0 :         reg |= TXGBE_PORTCTL_DCB;
    3369         [ #  # ]:          0 :         if (dcb_config->num_tcs.pg_tcs == 8)
    3370                 :            :                 reg |= TXGBE_PORTCTL_NUMTC_8;
    3371                 :            :         else
    3372                 :            :                 reg |= TXGBE_PORTCTL_NUMTC_4;
    3373                 :            : 
    3374                 :            :         wr32(hw, TXGBE_PORTCTL, reg);
    3375                 :            : 
    3376                 :            :         /* Enable the Tx desc arbiter */
    3377                 :            :         reg = rd32(hw, TXGBE_ARBTXCTL);
    3378                 :          0 :         reg &= ~TXGBE_ARBTXCTL_DIA;
    3379                 :            :         wr32(hw, TXGBE_ARBTXCTL, reg);
    3380                 :          0 : }
    3381                 :            : 
    3382                 :            : /**
    3383                 :            :  * txgbe_vmdq_dcb_hw_tx_config - Configure general VMDQ+DCB TX parameters
    3384                 :            :  * @dev: pointer to rte_eth_dev structure
    3385                 :            :  * @dcb_config: pointer to txgbe_dcb_config structure
    3386                 :            :  */
    3387                 :            : static void
    3388                 :          0 : txgbe_vmdq_dcb_hw_tx_config(struct rte_eth_dev *dev,
    3389                 :            :                         struct txgbe_dcb_config *dcb_config)
    3390                 :            : {
    3391                 :            :         struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
    3392                 :          0 :                         &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
    3393                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3394                 :            : 
    3395                 :          0 :         PMD_INIT_FUNC_TRACE();
    3396                 :            :         /*PF VF Transmit Enable*/
    3397                 :          0 :         wr32(hw, TXGBE_POOLTXENA(0),
    3398         [ #  # ]:          0 :                 vmdq_tx_conf->nb_queue_pools ==
    3399                 :            :                                 RTE_ETH_16_POOLS ? 0xFFFF : 0xFFFFFFFF);
    3400                 :            : 
    3401                 :            :         /*Configure general DCB TX parameters*/
    3402                 :          0 :         txgbe_dcb_tx_hw_config(dev, dcb_config);
    3403                 :          0 : }
    3404                 :            : 
    3405                 :            : static void
    3406                 :          0 : txgbe_vmdq_dcb_rx_config(struct rte_eth_dev *dev,
    3407                 :            :                         struct txgbe_dcb_config *dcb_config)
    3408                 :            : {
    3409                 :            :         struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
    3410                 :          0 :                         &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
    3411                 :            :         struct txgbe_dcb_tc_config *tc;
    3412                 :            :         uint8_t i, j;
    3413                 :            : 
    3414                 :            :         /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
    3415         [ #  # ]:          0 :         if (vmdq_rx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
    3416                 :          0 :                 dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
    3417                 :          0 :                 dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
    3418                 :            :         } else {
    3419                 :          0 :                 dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
    3420                 :          0 :                 dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
    3421                 :            :         }
    3422                 :            : 
    3423                 :            :         /* Initialize User Priority to Traffic Class mapping */
    3424         [ #  # ]:          0 :         for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
    3425                 :          0 :                 tc = &dcb_config->tc_config[j];
    3426                 :          0 :                 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
    3427                 :            :         }
    3428                 :            : 
    3429                 :            :         /* User Priority to Traffic Class mapping */
    3430         [ #  # ]:          0 :         for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3431                 :          0 :                 j = vmdq_rx_conf->dcb_tc[i];
    3432                 :          0 :                 tc = &dcb_config->tc_config[j];
    3433                 :          0 :                 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
    3434                 :          0 :                                                 (uint8_t)(1 << i);
    3435                 :            :         }
    3436                 :          0 : }
    3437                 :            : 
    3438                 :            : static void
    3439                 :          0 : txgbe_dcb_vt_tx_config(struct rte_eth_dev *dev,
    3440                 :            :                         struct txgbe_dcb_config *dcb_config)
    3441                 :            : {
    3442                 :            :         struct rte_eth_vmdq_dcb_tx_conf *vmdq_tx_conf =
    3443                 :          0 :                         &dev->data->dev_conf.tx_adv_conf.vmdq_dcb_tx_conf;
    3444                 :            :         struct txgbe_dcb_tc_config *tc;
    3445                 :            :         uint8_t i, j;
    3446                 :            : 
    3447                 :            :         /* convert rte_eth_conf.rx_adv_conf to struct txgbe_dcb_config */
    3448         [ #  # ]:          0 :         if (vmdq_tx_conf->nb_queue_pools == RTE_ETH_16_POOLS) {
    3449                 :          0 :                 dcb_config->num_tcs.pg_tcs = RTE_ETH_8_TCS;
    3450                 :          0 :                 dcb_config->num_tcs.pfc_tcs = RTE_ETH_8_TCS;
    3451                 :            :         } else {
    3452                 :          0 :                 dcb_config->num_tcs.pg_tcs = RTE_ETH_4_TCS;
    3453                 :          0 :                 dcb_config->num_tcs.pfc_tcs = RTE_ETH_4_TCS;
    3454                 :            :         }
    3455                 :            : 
    3456                 :            :         /* Initialize User Priority to Traffic Class mapping */
    3457         [ #  # ]:          0 :         for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
    3458                 :          0 :                 tc = &dcb_config->tc_config[j];
    3459                 :          0 :                 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
    3460                 :            :         }
    3461                 :            : 
    3462                 :            :         /* User Priority to Traffic Class mapping */
    3463         [ #  # ]:          0 :         for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3464                 :          0 :                 j = vmdq_tx_conf->dcb_tc[i];
    3465                 :          0 :                 tc = &dcb_config->tc_config[j];
    3466                 :          0 :                 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
    3467                 :          0 :                                                 (uint8_t)(1 << i);
    3468                 :            :         }
    3469                 :          0 : }
    3470                 :            : 
    3471                 :            : static void
    3472                 :            : txgbe_dcb_rx_config(struct rte_eth_dev *dev,
    3473                 :            :                 struct txgbe_dcb_config *dcb_config)
    3474                 :            : {
    3475                 :            :         struct rte_eth_dcb_rx_conf *rx_conf =
    3476                 :            :                         &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
    3477                 :            :         struct txgbe_dcb_tc_config *tc;
    3478                 :            :         uint8_t i, j;
    3479                 :            : 
    3480                 :          0 :         dcb_config->num_tcs.pg_tcs = (uint8_t)rx_conf->nb_tcs;
    3481                 :          0 :         dcb_config->num_tcs.pfc_tcs = (uint8_t)rx_conf->nb_tcs;
    3482                 :            : 
    3483                 :            :         /* Initialize User Priority to Traffic Class mapping */
    3484         [ #  # ]:          0 :         for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
    3485                 :          0 :                 tc = &dcb_config->tc_config[j];
    3486                 :          0 :                 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0;
    3487                 :            :         }
    3488                 :            : 
    3489                 :            :         /* User Priority to Traffic Class mapping */
    3490         [ #  # ]:          0 :         for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3491                 :          0 :                 j = rx_conf->dcb_tc[i];
    3492                 :          0 :                 tc = &dcb_config->tc_config[j];
    3493                 :          0 :                 tc->path[TXGBE_DCB_RX_CONFIG].up_to_tc_bitmap |=
    3494                 :          0 :                                                 (uint8_t)(1 << i);
    3495                 :            :         }
    3496                 :            : }
    3497                 :            : 
    3498                 :            : static void
    3499                 :            : txgbe_dcb_tx_config(struct rte_eth_dev *dev,
    3500                 :            :                 struct txgbe_dcb_config *dcb_config)
    3501                 :            : {
    3502                 :            :         struct rte_eth_dcb_tx_conf *tx_conf =
    3503                 :            :                         &dev->data->dev_conf.tx_adv_conf.dcb_tx_conf;
    3504                 :            :         struct txgbe_dcb_tc_config *tc;
    3505                 :            :         uint8_t i, j;
    3506                 :            : 
    3507                 :          0 :         dcb_config->num_tcs.pg_tcs = (uint8_t)tx_conf->nb_tcs;
    3508                 :          0 :         dcb_config->num_tcs.pfc_tcs = (uint8_t)tx_conf->nb_tcs;
    3509                 :            : 
    3510                 :            :         /* Initialize User Priority to Traffic Class mapping */
    3511         [ #  # ]:          0 :         for (j = 0; j < TXGBE_DCB_TC_MAX; j++) {
    3512                 :          0 :                 tc = &dcb_config->tc_config[j];
    3513                 :          0 :                 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0;
    3514                 :            :         }
    3515                 :            : 
    3516                 :            :         /* User Priority to Traffic Class mapping */
    3517         [ #  # ]:          0 :         for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3518                 :          0 :                 j = tx_conf->dcb_tc[i];
    3519                 :          0 :                 tc = &dcb_config->tc_config[j];
    3520                 :          0 :                 tc->path[TXGBE_DCB_TX_CONFIG].up_to_tc_bitmap |=
    3521                 :          0 :                                                 (uint8_t)(1 << i);
    3522                 :            :         }
    3523                 :            : }
    3524                 :            : 
    3525                 :            : /**
    3526                 :            :  * txgbe_dcb_rx_hw_config - Configure general DCB RX HW parameters
    3527                 :            :  * @dev: pointer to eth_dev structure
    3528                 :            :  * @dcb_config: pointer to txgbe_dcb_config structure
    3529                 :            :  */
    3530                 :            : static void
    3531                 :          0 : txgbe_dcb_rx_hw_config(struct rte_eth_dev *dev,
    3532                 :            :                        struct txgbe_dcb_config *dcb_config)
    3533                 :            : {
    3534                 :            :         uint32_t reg;
    3535                 :            :         uint32_t vlanctrl;
    3536                 :            :         uint8_t i;
    3537                 :            :         uint32_t q;
    3538                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3539                 :            : 
    3540                 :          0 :         PMD_INIT_FUNC_TRACE();
    3541                 :            :         /*
    3542                 :            :          * Disable the arbiter before changing parameters
    3543                 :            :          * (always enable recycle mode; WSP)
    3544                 :            :          */
    3545                 :            :         reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP | TXGBE_ARBRXCTL_DIA;
    3546                 :            :         wr32(hw, TXGBE_ARBRXCTL, reg);
    3547                 :            : 
    3548                 :            :         reg = rd32(hw, TXGBE_PORTCTL);
    3549                 :          0 :         reg &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
    3550         [ #  # ]:          0 :         if (dcb_config->num_tcs.pg_tcs == 4) {
    3551                 :            :                 reg |= TXGBE_PORTCTL_NUMTC_4;
    3552         [ #  # ]:          0 :                 if (dcb_config->vt_mode)
    3553                 :          0 :                         reg |= TXGBE_PORTCTL_NUMVT_32;
    3554                 :            :                 else
    3555                 :            :                         wr32(hw, TXGBE_POOLCTL, 0);
    3556                 :            :         }
    3557                 :            : 
    3558         [ #  # ]:          0 :         if (dcb_config->num_tcs.pg_tcs == 8) {
    3559                 :          0 :                 reg |= TXGBE_PORTCTL_NUMTC_8;
    3560         [ #  # ]:          0 :                 if (dcb_config->vt_mode)
    3561                 :          0 :                         reg |= TXGBE_PORTCTL_NUMVT_16;
    3562                 :            :                 else
    3563                 :            :                         wr32(hw, TXGBE_POOLCTL, 0);
    3564                 :            :         }
    3565                 :            : 
    3566                 :            :         wr32(hw, TXGBE_PORTCTL, reg);
    3567                 :            : 
    3568         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
    3569                 :            :                 /* Disable drop for all queues in VMDQ mode*/
    3570         [ #  # ]:          0 :                 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
    3571                 :          0 :                         u32 val = 1 << (q % 32);
    3572                 :          0 :                         wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
    3573                 :            :                 }
    3574                 :            :         } else {
    3575                 :            :                 /* Enable drop for all queues in SRIOV mode */
    3576         [ #  # ]:          0 :                 for (q = 0; q < TXGBE_MAX_RX_QUEUE_NUM; q++) {
    3577                 :          0 :                         u32 val = 1 << (q % 32);
    3578                 :          0 :                         wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
    3579                 :            :                 }
    3580                 :            :         }
    3581                 :            : 
    3582                 :            :         /* VLNCTL: enable vlan filtering and allow all vlan tags through */
    3583                 :            :         vlanctrl = rd32(hw, TXGBE_VLANCTL);
    3584                 :          0 :         vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
    3585                 :            :         wr32(hw, TXGBE_VLANCTL, vlanctrl);
    3586                 :            : 
    3587                 :            :         /* VLANTBL - enable all vlan filters */
    3588         [ #  # ]:          0 :         for (i = 0; i < NUM_VFTA_REGISTERS; i++)
    3589                 :          0 :                 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
    3590                 :            : 
    3591                 :            :         /*
    3592                 :            :          * Configure Rx packet plane (recycle mode; WSP) and
    3593                 :            :          * enable arbiter
    3594                 :            :          */
    3595                 :            :         reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP;
    3596                 :            :         wr32(hw, TXGBE_ARBRXCTL, reg);
    3597                 :          0 : }
    3598                 :            : 
    3599                 :            : static void
    3600                 :            : txgbe_dcb_hw_arbite_rx_config(struct txgbe_hw *hw, uint16_t *refill,
    3601                 :            :                 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
    3602                 :            : {
    3603                 :          0 :         txgbe_dcb_config_rx_arbiter_raptor(hw, refill, max, bwg_id,
    3604                 :            :                                           tsa, map);
    3605                 :          0 : }
    3606                 :            : 
    3607                 :            : static void
    3608                 :          0 : txgbe_dcb_hw_arbite_tx_config(struct txgbe_hw *hw, uint16_t *refill,
    3609                 :            :                 uint16_t *max, uint8_t *bwg_id, uint8_t *tsa, uint8_t *map)
    3610                 :            : {
    3611         [ #  # ]:          0 :         switch (hw->mac.type) {
    3612                 :          0 :         case txgbe_mac_raptor:
    3613                 :          0 :                 txgbe_dcb_config_tx_desc_arbiter_raptor(hw, refill,
    3614                 :            :                                                         max, bwg_id, tsa);
    3615                 :          0 :                 txgbe_dcb_config_tx_data_arbiter_raptor(hw, refill,
    3616                 :            :                                                         max, bwg_id, tsa, map);
    3617                 :          0 :                 break;
    3618                 :            :         default:
    3619                 :            :                 break;
    3620                 :            :         }
    3621                 :          0 : }
    3622                 :            : 
    3623                 :            : #define DCB_RX_CONFIG  1
    3624                 :            : #define DCB_TX_CONFIG  1
    3625                 :            : #define DCB_TX_PB      1024
    3626                 :            : /**
    3627                 :            :  * txgbe_dcb_hw_configure - Enable DCB and configure
    3628                 :            :  * general DCB in VT mode and non-VT mode parameters
    3629                 :            :  * @dev: pointer to rte_eth_dev structure
    3630                 :            :  * @dcb_config: pointer to txgbe_dcb_config structure
    3631                 :            :  */
    3632                 :            : static int
    3633                 :          0 : txgbe_dcb_hw_configure(struct rte_eth_dev *dev,
    3634                 :            :                         struct txgbe_dcb_config *dcb_config)
    3635                 :            : {
    3636                 :            :         int     ret = 0;
    3637                 :            :         uint8_t i, pfc_en, nb_tcs;
    3638                 :            :         uint16_t pbsize, rx_buffer_size;
    3639                 :            :         uint8_t config_dcb_rx = 0;
    3640                 :            :         uint8_t config_dcb_tx = 0;
    3641                 :          0 :         uint8_t tsa[TXGBE_DCB_TC_MAX] = {0};
    3642                 :          0 :         uint8_t bwgid[TXGBE_DCB_TC_MAX] = {0};
    3643                 :          0 :         uint16_t refill[TXGBE_DCB_TC_MAX] = {0};
    3644                 :          0 :         uint16_t max[TXGBE_DCB_TC_MAX] = {0};
    3645                 :          0 :         uint8_t map[TXGBE_DCB_TC_MAX] = {0};
    3646                 :            :         struct txgbe_dcb_tc_config *tc;
    3647                 :          0 :         uint32_t max_frame = dev->data->mtu +
    3648                 :          0 :                         RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
    3649                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3650                 :            :         struct txgbe_bw_conf *bw_conf = TXGBE_DEV_BW_CONF(dev);
    3651                 :            : 
    3652      [ #  #  # ]:          0 :         switch (dev->data->dev_conf.rxmode.mq_mode) {
    3653                 :          0 :         case RTE_ETH_MQ_RX_VMDQ_DCB:
    3654                 :          0 :                 dcb_config->vt_mode = true;
    3655                 :            :                 config_dcb_rx = DCB_RX_CONFIG;
    3656                 :            :                 /*
    3657                 :            :                  * get dcb and VT rx configuration parameters
    3658                 :            :                  * from rte_eth_conf
    3659                 :            :                  */
    3660                 :          0 :                 txgbe_vmdq_dcb_rx_config(dev, dcb_config);
    3661                 :            :                 /*Configure general VMDQ and DCB RX parameters*/
    3662                 :          0 :                 txgbe_vmdq_dcb_configure(dev);
    3663                 :          0 :                 break;
    3664                 :          0 :         case RTE_ETH_MQ_RX_DCB:
    3665                 :            :         case RTE_ETH_MQ_RX_DCB_RSS:
    3666                 :          0 :                 dcb_config->vt_mode = false;
    3667                 :            :                 config_dcb_rx = DCB_RX_CONFIG;
    3668                 :            :                 /* Get dcb TX configuration parameters from rte_eth_conf */
    3669                 :            :                 txgbe_dcb_rx_config(dev, dcb_config);
    3670                 :            :                 /*Configure general DCB RX parameters*/
    3671                 :          0 :                 txgbe_dcb_rx_hw_config(dev, dcb_config);
    3672                 :          0 :                 break;
    3673                 :          0 :         default:
    3674                 :          0 :                 PMD_INIT_LOG(ERR, "Incorrect DCB RX mode configuration");
    3675                 :          0 :                 break;
    3676                 :            :         }
    3677      [ #  #  # ]:          0 :         switch (dev->data->dev_conf.txmode.mq_mode) {
    3678                 :          0 :         case RTE_ETH_MQ_TX_VMDQ_DCB:
    3679                 :          0 :                 dcb_config->vt_mode = true;
    3680                 :            :                 config_dcb_tx = DCB_TX_CONFIG;
    3681                 :            :                 /* get DCB and VT TX configuration parameters
    3682                 :            :                  * from rte_eth_conf
    3683                 :            :                  */
    3684                 :          0 :                 txgbe_dcb_vt_tx_config(dev, dcb_config);
    3685                 :            :                 /* Configure general VMDQ and DCB TX parameters */
    3686                 :          0 :                 txgbe_vmdq_dcb_hw_tx_config(dev, dcb_config);
    3687                 :          0 :                 break;
    3688                 :            : 
    3689                 :          0 :         case RTE_ETH_MQ_TX_DCB:
    3690                 :          0 :                 dcb_config->vt_mode = false;
    3691                 :            :                 config_dcb_tx = DCB_TX_CONFIG;
    3692                 :            :                 /* get DCB TX configuration parameters from rte_eth_conf */
    3693                 :            :                 txgbe_dcb_tx_config(dev, dcb_config);
    3694                 :            :                 /* Configure general DCB TX parameters */
    3695                 :          0 :                 txgbe_dcb_tx_hw_config(dev, dcb_config);
    3696                 :          0 :                 break;
    3697                 :          0 :         default:
    3698                 :          0 :                 PMD_INIT_LOG(ERR, "Incorrect DCB TX mode configuration");
    3699                 :          0 :                 break;
    3700                 :            :         }
    3701                 :            : 
    3702                 :          0 :         nb_tcs = dcb_config->num_tcs.pfc_tcs;
    3703                 :            :         /* Unpack map */
    3704                 :          0 :         txgbe_dcb_unpack_map_cee(dcb_config, TXGBE_DCB_RX_CONFIG, map);
    3705         [ #  # ]:          0 :         if (nb_tcs == RTE_ETH_4_TCS) {
    3706                 :            :                 /* Avoid un-configured priority mapping to TC0 */
    3707                 :            :                 uint8_t j = 4;
    3708                 :            :                 uint8_t mask = 0xFF;
    3709                 :            : 
    3710         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES - 4; i++)
    3711                 :          0 :                         mask = (uint8_t)(mask & (~(1 << map[i])));
    3712         [ #  # ]:          0 :                 for (i = 0; mask && (i < TXGBE_DCB_TC_MAX); i++) {
    3713   [ #  #  #  # ]:          0 :                         if ((mask & 0x1) && j < RTE_ETH_DCB_NUM_USER_PRIORITIES)
    3714                 :          0 :                                 map[j++] = i;
    3715                 :          0 :                         mask >>= 1;
    3716                 :            :                 }
    3717                 :            :                 /* Re-configure 4 TCs BW */
    3718         [ #  # ]:          0 :                 for (i = 0; i < nb_tcs; i++) {
    3719                 :          0 :                         tc = &dcb_config->tc_config[i];
    3720         [ #  # ]:          0 :                         if (bw_conf->tc_num != nb_tcs)
    3721                 :          0 :                                 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
    3722                 :            :                                         (uint8_t)(100 / nb_tcs);
    3723                 :          0 :                         tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
    3724                 :            :                                                 (uint8_t)(100 / nb_tcs);
    3725                 :            :                 }
    3726         [ #  # ]:          0 :                 for (; i < TXGBE_DCB_TC_MAX; i++) {
    3727                 :          0 :                         tc = &dcb_config->tc_config[i];
    3728                 :          0 :                         tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent = 0;
    3729                 :          0 :                         tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent = 0;
    3730                 :            :                 }
    3731                 :            :         } else {
    3732                 :            :                 /* Re-configure 8 TCs BW */
    3733         [ #  # ]:          0 :                 for (i = 0; i < nb_tcs; i++) {
    3734                 :          0 :                         tc = &dcb_config->tc_config[i];
    3735         [ #  # ]:          0 :                         if (bw_conf->tc_num != nb_tcs)
    3736                 :          0 :                                 tc->path[TXGBE_DCB_TX_CONFIG].bwg_percent =
    3737                 :          0 :                                         (uint8_t)(100 / nb_tcs + (i & 1));
    3738                 :          0 :                         tc->path[TXGBE_DCB_RX_CONFIG].bwg_percent =
    3739                 :          0 :                                 (uint8_t)(100 / nb_tcs + (i & 1));
    3740                 :            :                 }
    3741                 :            :         }
    3742                 :            : 
    3743                 :            :         rx_buffer_size = NIC_RX_BUFFER_SIZE;
    3744                 :            : 
    3745         [ #  # ]:          0 :         if (config_dcb_rx) {
    3746                 :            :                 /* Set RX buffer size */
    3747                 :          0 :                 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
    3748                 :          0 :                 uint32_t rxpbsize = pbsize << 10;
    3749                 :            : 
    3750         [ #  # ]:          0 :                 for (i = 0; i < nb_tcs; i++)
    3751                 :          0 :                         wr32(hw, TXGBE_PBRXSIZE(i), rxpbsize);
    3752                 :            : 
    3753                 :            :                 /* zero alloc all unused TCs */
    3754         [ #  # ]:          0 :                 for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
    3755                 :          0 :                         wr32(hw, TXGBE_PBRXSIZE(i), 0);
    3756                 :            :         }
    3757         [ #  # ]:          0 :         if (config_dcb_tx) {
    3758                 :            :                 /* Only support an equally distributed
    3759                 :            :                  *  Tx packet buffer strategy.
    3760                 :            :                  */
    3761                 :          0 :                 uint32_t txpktsize = TXGBE_PBTXSIZE_MAX / nb_tcs;
    3762                 :          0 :                 uint32_t txpbthresh = (txpktsize / DCB_TX_PB) -
    3763                 :            :                                         TXGBE_TXPKT_SIZE_MAX;
    3764                 :            : 
    3765         [ #  # ]:          0 :                 for (i = 0; i < nb_tcs; i++) {
    3766                 :          0 :                         wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
    3767                 :          0 :                         wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
    3768                 :            :                 }
    3769                 :            :                 /* Clear unused TCs, if any, to zero buffer size*/
    3770         [ #  # ]:          0 :                 for (; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++) {
    3771                 :          0 :                         wr32(hw, TXGBE_PBTXSIZE(i), 0);
    3772                 :          0 :                         wr32(hw, TXGBE_PBTXDMATH(i), 0);
    3773                 :            :                 }
    3774                 :            :         }
    3775                 :            : 
    3776                 :            :         /*Calculates traffic class credits*/
    3777                 :          0 :         txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
    3778                 :            :                                 TXGBE_DCB_TX_CONFIG);
    3779                 :          0 :         txgbe_dcb_calculate_tc_credits_cee(hw, dcb_config, max_frame,
    3780                 :            :                                 TXGBE_DCB_RX_CONFIG);
    3781                 :            : 
    3782         [ #  # ]:          0 :         if (config_dcb_rx) {
    3783                 :            :                 /* Unpack CEE standard containers */
    3784                 :          0 :                 txgbe_dcb_unpack_refill_cee(dcb_config,
    3785                 :            :                                 TXGBE_DCB_RX_CONFIG, refill);
    3786                 :          0 :                 txgbe_dcb_unpack_max_cee(dcb_config, max);
    3787                 :          0 :                 txgbe_dcb_unpack_bwgid_cee(dcb_config,
    3788                 :            :                                 TXGBE_DCB_RX_CONFIG, bwgid);
    3789                 :          0 :                 txgbe_dcb_unpack_tsa_cee(dcb_config,
    3790                 :            :                                 TXGBE_DCB_RX_CONFIG, tsa);
    3791                 :            :                 /* Configure PG(ETS) RX */
    3792                 :            :                 txgbe_dcb_hw_arbite_rx_config(hw, refill, max, bwgid, tsa, map);
    3793                 :            :         }
    3794                 :            : 
    3795         [ #  # ]:          0 :         if (config_dcb_tx) {
    3796                 :            :                 /* Unpack CEE standard containers */
    3797                 :          0 :                 txgbe_dcb_unpack_refill_cee(dcb_config,
    3798                 :            :                                 TXGBE_DCB_TX_CONFIG, refill);
    3799                 :          0 :                 txgbe_dcb_unpack_max_cee(dcb_config, max);
    3800                 :          0 :                 txgbe_dcb_unpack_bwgid_cee(dcb_config,
    3801                 :            :                                 TXGBE_DCB_TX_CONFIG, bwgid);
    3802                 :          0 :                 txgbe_dcb_unpack_tsa_cee(dcb_config,
    3803                 :            :                                 TXGBE_DCB_TX_CONFIG, tsa);
    3804                 :            :                 /* Configure PG(ETS) TX */
    3805                 :          0 :                 txgbe_dcb_hw_arbite_tx_config(hw, refill, max, bwgid, tsa, map);
    3806                 :            :         }
    3807                 :            : 
    3808                 :            :         /* Configure queue statistics registers */
    3809                 :          0 :         txgbe_dcb_config_tc_stats_raptor(hw, dcb_config);
    3810                 :            : 
    3811                 :            :         /* Check if the PFC is supported */
    3812         [ #  # ]:          0 :         if (dev->data->dev_conf.dcb_capability_en & RTE_ETH_DCB_PFC_SUPPORT) {
    3813                 :          0 :                 pbsize = (uint16_t)(rx_buffer_size / nb_tcs);
    3814         [ #  # ]:          0 :                 for (i = 0; i < nb_tcs; i++) {
    3815                 :            :                         /* If the TC count is 8,
    3816                 :            :                          * and the default high_water is 48,
    3817                 :            :                          * the low_water is 16 as default.
    3818                 :            :                          */
    3819                 :          0 :                         hw->fc.high_water[i] = (pbsize * 3) / 4;
    3820                 :          0 :                         hw->fc.low_water[i] = pbsize / 4;
    3821                 :            :                         /* Enable pfc for this TC */
    3822                 :            :                         tc = &dcb_config->tc_config[i];
    3823                 :          0 :                         tc->pfc = txgbe_dcb_pfc_enabled;
    3824                 :            :                 }
    3825                 :          0 :                 txgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
    3826         [ #  # ]:          0 :                 if (dcb_config->num_tcs.pfc_tcs == RTE_ETH_4_TCS)
    3827                 :          0 :                         pfc_en &= 0x0F;
    3828                 :          0 :                 ret = txgbe_dcb_config_pfc(hw, pfc_en, map);
    3829                 :            :         }
    3830                 :            : 
    3831                 :          0 :         return ret;
    3832                 :            : }
    3833                 :            : 
    3834                 :          0 : void txgbe_configure_pb(struct rte_eth_dev *dev)
    3835                 :            : {
    3836                 :          0 :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
    3837                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3838                 :            : 
    3839                 :            :         int hdrm;
    3840                 :          0 :         int tc = dev_conf->rx_adv_conf.dcb_rx_conf.nb_tcs;
    3841                 :            : 
    3842                 :            :         /* Reserve 256KB(/512KB) rx buffer for fdir */
    3843                 :            :         hdrm = 256; /*KB*/
    3844                 :            : 
    3845                 :          0 :         hw->mac.setup_pba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
    3846                 :          0 : }
    3847                 :            : 
    3848                 :          0 : void txgbe_configure_port(struct rte_eth_dev *dev)
    3849                 :            : {
    3850                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    3851                 :            :         int i = 0;
    3852                 :          0 :         uint16_t tpids[8] = {RTE_ETHER_TYPE_VLAN, RTE_ETHER_TYPE_QINQ,
    3853                 :            :                                 0x9100, 0x9200,
    3854                 :            :                                 0x0000, 0x0000,
    3855                 :            :                                 0x0000, 0x0000};
    3856                 :            : 
    3857                 :          0 :         PMD_INIT_FUNC_TRACE();
    3858                 :            : 
    3859                 :            :         /* default outer vlan tpid */
    3860                 :            :         wr32(hw, TXGBE_EXTAG,
    3861                 :            :                 TXGBE_EXTAG_ETAG(RTE_ETHER_TYPE_ETAG) |
    3862                 :            :                 TXGBE_EXTAG_VLAN(RTE_ETHER_TYPE_QINQ));
    3863                 :            : 
    3864                 :            :         /* default inner vlan tpid */
    3865                 :            :         wr32m(hw, TXGBE_VLANCTL,
    3866                 :            :                 TXGBE_VLANCTL_TPID_MASK,
    3867                 :            :                 TXGBE_VLANCTL_TPID(RTE_ETHER_TYPE_VLAN));
    3868                 :            :         wr32m(hw, TXGBE_DMATXCTRL,
    3869                 :            :                 TXGBE_DMATXCTRL_TPID_MASK,
    3870                 :            :                 TXGBE_DMATXCTRL_TPID(RTE_ETHER_TYPE_VLAN));
    3871                 :            : 
    3872                 :            :         /* default vlan tpid filters */
    3873         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
    3874         [ #  # ]:          0 :                 wr32m(hw, TXGBE_TAGTPID(i / 2),
    3875                 :            :                         (i % 2 ? TXGBE_TAGTPID_MSB_MASK
    3876                 :            :                                : TXGBE_TAGTPID_LSB_MASK),
    3877         [ #  # ]:          0 :                         (i % 2 ? TXGBE_TAGTPID_MSB(tpids[i])
    3878                 :          0 :                                : TXGBE_TAGTPID_LSB(tpids[i])));
    3879                 :            :         }
    3880                 :            : 
    3881                 :            :         /* default vxlan port */
    3882                 :            :         wr32(hw, TXGBE_VXLANPORT, 4789);
    3883                 :          0 : }
    3884                 :            : 
    3885                 :            : /**
    3886                 :            :  * txgbe_configure_dcb - Configure DCB  Hardware
    3887                 :            :  * @dev: pointer to rte_eth_dev
    3888                 :            :  */
    3889                 :          0 : void txgbe_configure_dcb(struct rte_eth_dev *dev)
    3890                 :            : {
    3891                 :          0 :         struct txgbe_dcb_config *dcb_cfg = TXGBE_DEV_DCB_CONFIG(dev);
    3892                 :            :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
    3893                 :            : 
    3894                 :          0 :         PMD_INIT_FUNC_TRACE();
    3895                 :            : 
    3896                 :            :         /* check support mq_mode for DCB */
    3897         [ #  # ]:          0 :         if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_DCB &&
    3898         [ #  # ]:          0 :             dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB &&
    3899                 :            :             dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_DCB_RSS)
    3900                 :            :                 return;
    3901                 :            : 
    3902         [ #  # ]:          0 :         if (dev->data->nb_rx_queues > RTE_ETH_DCB_NUM_QUEUES)
    3903                 :            :                 return;
    3904                 :            : 
    3905                 :            :         /** Configure DCB hardware **/
    3906                 :          0 :         txgbe_dcb_hw_configure(dev, dcb_cfg);
    3907                 :            : }
    3908                 :            : 
    3909                 :            : /*
    3910                 :            :  * VMDq only support for 10 GbE NIC.
    3911                 :            :  */
    3912                 :            : static void
    3913                 :          0 : txgbe_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
    3914                 :            : {
    3915                 :            :         struct rte_eth_vmdq_rx_conf *cfg;
    3916                 :            :         struct txgbe_hw *hw;
    3917                 :            :         enum rte_eth_nb_pools num_pools;
    3918                 :            :         uint32_t mrqc, vt_ctl, vlanctrl;
    3919                 :            :         uint32_t vmolr = 0;
    3920                 :            :         int i;
    3921                 :            : 
    3922                 :          0 :         PMD_INIT_FUNC_TRACE();
    3923                 :          0 :         hw = TXGBE_DEV_HW(dev);
    3924                 :            :         cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
    3925                 :          0 :         num_pools = cfg->nb_queue_pools;
    3926                 :            : 
    3927                 :          0 :         txgbe_rss_disable(dev);
    3928                 :            : 
    3929                 :            :         /* enable vmdq */
    3930                 :            :         mrqc = TXGBE_PORTCTL_NUMVT_64;
    3931                 :            :         wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mrqc);
    3932                 :            : 
    3933                 :            :         /* turn on virtualisation and set the default pool */
    3934                 :            :         vt_ctl = TXGBE_POOLCTL_RPLEN;
    3935         [ #  # ]:          0 :         if (cfg->enable_default_pool)
    3936                 :          0 :                 vt_ctl |= TXGBE_POOLCTL_DEFPL(cfg->default_pool);
    3937                 :            :         else
    3938                 :            :                 vt_ctl |= TXGBE_POOLCTL_DEFDSA;
    3939                 :            : 
    3940                 :            :         wr32(hw, TXGBE_POOLCTL, vt_ctl);
    3941                 :            : 
    3942         [ #  # ]:          0 :         for (i = 0; i < (int)num_pools; i++) {
    3943                 :          0 :                 vmolr = txgbe_convert_vm_rx_mask_to_val(cfg->rx_mode, vmolr);
    3944                 :          0 :                 wr32(hw, TXGBE_POOLETHCTL(i), vmolr);
    3945                 :            :         }
    3946                 :            : 
    3947                 :            :         /* enable vlan filtering and allow all vlan tags through */
    3948                 :            :         vlanctrl = rd32(hw, TXGBE_VLANCTL);
    3949                 :          0 :         vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
    3950                 :            :         wr32(hw, TXGBE_VLANCTL, vlanctrl);
    3951                 :            : 
    3952                 :            :         /* enable all vlan filters */
    3953         [ #  # ]:          0 :         for (i = 0; i < NUM_VFTA_REGISTERS; i++)
    3954                 :          0 :                 wr32(hw, TXGBE_VLANTBL(i), UINT32_MAX);
    3955                 :            : 
    3956                 :            :         /* pool enabling for receive - 64 */
    3957                 :            :         wr32(hw, TXGBE_POOLRXENA(0), UINT32_MAX);
    3958         [ #  # ]:          0 :         if (num_pools == RTE_ETH_64_POOLS)
    3959                 :            :                 wr32(hw, TXGBE_POOLRXENA(1), UINT32_MAX);
    3960                 :            : 
    3961                 :            :         /*
    3962                 :            :          * allow pools to read specific mac addresses
    3963                 :            :          * In this case, all pools should be able to read from mac addr 0
    3964                 :            :          */
    3965                 :            :         wr32(hw, TXGBE_ETHADDRIDX, 0);
    3966                 :            :         wr32(hw, TXGBE_ETHADDRASSL, 0xFFFFFFFF);
    3967                 :            :         wr32(hw, TXGBE_ETHADDRASSH, 0xFFFFFFFF);
    3968                 :            : 
    3969                 :            :         /* set up filters for vlan tags as configured */
    3970         [ #  # ]:          0 :         for (i = 0; i < cfg->nb_pool_maps; i++) {
    3971                 :            :                 /* set vlan id in VF register and set the valid bit */
    3972                 :          0 :                 wr32(hw, TXGBE_PSRVLANIDX, i);
    3973                 :          0 :                 wr32(hw, TXGBE_PSRVLAN, (TXGBE_PSRVLAN_EA |
    3974                 :          0 :                                 TXGBE_PSRVLAN_VID(cfg->pool_map[i].vlan_id)));
    3975                 :            :                 /*
    3976                 :            :                  * Put the allowed pools in VFB reg. As we only have 16 or 64
    3977                 :            :                  * pools, we only need to use the first half of the register
    3978                 :            :                  * i.e. bits 0-31
    3979                 :            :                  */
    3980         [ #  # ]:          0 :                 if (((cfg->pool_map[i].pools >> 32) & UINT32_MAX) == 0)
    3981                 :          0 :                         wr32(hw, TXGBE_PSRVLANPLM(0),
    3982                 :            :                                 (cfg->pool_map[i].pools & UINT32_MAX));
    3983                 :            :                 else
    3984                 :          0 :                         wr32(hw, TXGBE_PSRVLANPLM(1),
    3985                 :            :                                 ((cfg->pool_map[i].pools >> 32) & UINT32_MAX));
    3986                 :            :         }
    3987                 :            : 
    3988                 :            :         /* Tx General Switch Control Enables VMDQ loopback */
    3989         [ #  # ]:          0 :         if (cfg->enable_loop_back) {
    3990                 :            :                 wr32(hw, TXGBE_PSRCTL, TXGBE_PSRCTL_LBENA);
    3991         [ #  # ]:          0 :                 for (i = 0; i < 64; i++)
    3992                 :          0 :                         wr32m(hw, TXGBE_POOLETHCTL(i),
    3993                 :            :                                 TXGBE_POOLETHCTL_LLB, TXGBE_POOLETHCTL_LLB);
    3994                 :            :         }
    3995                 :            : 
    3996                 :            :         txgbe_flush(hw);
    3997                 :          0 : }
    3998                 :            : 
    3999                 :            : /*
    4000                 :            :  * txgbe_vmdq_tx_hw_configure - Configure general VMDq TX parameters
    4001                 :            :  * @hw: pointer to hardware structure
    4002                 :            :  */
    4003                 :            : static void
    4004                 :          0 : txgbe_vmdq_tx_hw_configure(struct txgbe_hw *hw)
    4005                 :            : {
    4006                 :            :         uint32_t reg;
    4007                 :            :         uint32_t q;
    4008                 :            : 
    4009                 :          0 :         PMD_INIT_FUNC_TRACE();
    4010                 :            :         /*PF VF Transmit Enable*/
    4011                 :            :         wr32(hw, TXGBE_POOLTXENA(0), UINT32_MAX);
    4012                 :            :         wr32(hw, TXGBE_POOLTXENA(1), UINT32_MAX);
    4013                 :            : 
    4014                 :            :         /* Disable the Tx desc arbiter */
    4015                 :            :         reg = rd32(hw, TXGBE_ARBTXCTL);
    4016                 :          0 :         reg |= TXGBE_ARBTXCTL_DIA;
    4017                 :            :         wr32(hw, TXGBE_ARBTXCTL, reg);
    4018                 :            : 
    4019                 :            :         wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK,
    4020                 :            :                 TXGBE_PORTCTL_NUMVT_64);
    4021                 :            : 
    4022                 :            :         /* Disable drop for all queues */
    4023         [ #  # ]:          0 :         for (q = 0; q < 128; q++) {
    4024                 :          0 :                 u32 val = 1 << (q % 32);
    4025                 :          0 :                 wr32m(hw, TXGBE_QPRXDROP(q / 32), val, val);
    4026                 :            :         }
    4027                 :            : 
    4028                 :            :         /* Enable the Tx desc arbiter */
    4029                 :            :         reg = rd32(hw, TXGBE_ARBTXCTL);
    4030                 :          0 :         reg &= ~TXGBE_ARBTXCTL_DIA;
    4031                 :            :         wr32(hw, TXGBE_ARBTXCTL, reg);
    4032                 :            : 
    4033                 :            :         txgbe_flush(hw);
    4034                 :          0 : }
    4035                 :            : 
    4036                 :            : static int __rte_cold
    4037                 :          0 : txgbe_alloc_rx_queue_mbufs(struct txgbe_rx_queue *rxq)
    4038                 :            : {
    4039                 :          0 :         struct txgbe_rx_entry *rxe = rxq->sw_ring;
    4040                 :            :         uint64_t dma_addr;
    4041                 :            :         unsigned int i;
    4042                 :            : 
    4043                 :            :         /* Initialize software ring entries */
    4044         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
    4045                 :            :                 volatile struct txgbe_rx_desc *rxd;
    4046                 :          0 :                 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
    4047                 :            : 
    4048         [ #  # ]:          0 :                 if (mbuf == NULL) {
    4049                 :          0 :                         PMD_INIT_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
    4050                 :            :                                      (unsigned int)rxq->queue_id);
    4051                 :          0 :                         return -ENOMEM;
    4052                 :            :                 }
    4053                 :            : 
    4054                 :          0 :                 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
    4055                 :          0 :                 mbuf->port = rxq->port_id;
    4056                 :            : 
    4057                 :            :                 dma_addr =
    4058                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
    4059                 :          0 :                 rxd = &rxq->rx_ring[i];
    4060                 :          0 :                 TXGBE_RXD_HDRADDR(rxd, 0);
    4061                 :          0 :                 TXGBE_RXD_PKTADDR(rxd, dma_addr);
    4062                 :          0 :                 rxe[i].mbuf = mbuf;
    4063                 :            :         }
    4064                 :            : 
    4065                 :            :         return 0;
    4066                 :            : }
    4067                 :            : 
    4068                 :            : static int
    4069                 :          0 : txgbe_config_vf_rss(struct rte_eth_dev *dev)
    4070                 :            : {
    4071                 :            :         struct txgbe_hw *hw;
    4072                 :            :         uint32_t mrqc;
    4073                 :            : 
    4074                 :          0 :         txgbe_rss_configure(dev);
    4075                 :            : 
    4076                 :          0 :         hw = TXGBE_DEV_HW(dev);
    4077                 :            : 
    4078                 :            :         /* enable VF RSS */
    4079                 :            :         mrqc = rd32(hw, TXGBE_PORTCTL);
    4080                 :          0 :         mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
    4081      [ #  #  # ]:          0 :         switch (RTE_ETH_DEV_SRIOV(dev).active) {
    4082                 :          0 :         case RTE_ETH_64_POOLS:
    4083                 :          0 :                 mrqc |= TXGBE_PORTCTL_NUMVT_64;
    4084                 :          0 :                 break;
    4085                 :            : 
    4086                 :          0 :         case RTE_ETH_32_POOLS:
    4087                 :          0 :                 mrqc |= TXGBE_PORTCTL_NUMVT_32;
    4088                 :          0 :                 break;
    4089                 :            : 
    4090                 :          0 :         default:
    4091                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid pool number in IOV mode with VMDQ RSS");
    4092                 :          0 :                 return -EINVAL;
    4093                 :            :         }
    4094                 :            : 
    4095                 :            :         wr32(hw, TXGBE_PORTCTL, mrqc);
    4096                 :            : 
    4097                 :          0 :         return 0;
    4098                 :            : }
    4099                 :            : 
    4100                 :            : static int
    4101                 :          0 : txgbe_config_vf_default(struct rte_eth_dev *dev)
    4102                 :            : {
    4103                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4104                 :            :         uint32_t mrqc;
    4105                 :            : 
    4106                 :            :         mrqc = rd32(hw, TXGBE_PORTCTL);
    4107                 :          0 :         mrqc &= ~(TXGBE_PORTCTL_NUMTC_MASK | TXGBE_PORTCTL_NUMVT_MASK);
    4108   [ #  #  #  # ]:          0 :         switch (RTE_ETH_DEV_SRIOV(dev).active) {
    4109                 :          0 :         case RTE_ETH_64_POOLS:
    4110                 :          0 :                 mrqc |= TXGBE_PORTCTL_NUMVT_64;
    4111                 :          0 :                 break;
    4112                 :            : 
    4113                 :          0 :         case RTE_ETH_32_POOLS:
    4114                 :          0 :                 mrqc |= TXGBE_PORTCTL_NUMVT_32;
    4115                 :          0 :                 break;
    4116                 :            : 
    4117                 :          0 :         case RTE_ETH_16_POOLS:
    4118                 :          0 :                 mrqc |= TXGBE_PORTCTL_NUMVT_16;
    4119                 :          0 :                 break;
    4120                 :          0 :         default:
    4121                 :          0 :                 PMD_INIT_LOG(ERR,
    4122                 :            :                         "invalid pool number in IOV mode");
    4123                 :          0 :                 return 0;
    4124                 :            :         }
    4125                 :            : 
    4126                 :            :         wr32(hw, TXGBE_PORTCTL, mrqc);
    4127                 :            : 
    4128                 :          0 :         return 0;
    4129                 :            : }
    4130                 :            : 
    4131                 :            : static int
    4132                 :          0 : txgbe_dev_mq_rx_configure(struct rte_eth_dev *dev)
    4133                 :            : {
    4134         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
    4135                 :            :                 /*
    4136                 :            :                  * SRIOV inactive scheme
    4137                 :            :                  * any DCB/RSS w/o VMDq multi-queue setting
    4138                 :            :                  */
    4139   [ #  #  #  # ]:          0 :                 switch (dev->data->dev_conf.rxmode.mq_mode) {
    4140                 :          0 :                 case RTE_ETH_MQ_RX_RSS:
    4141                 :            :                 case RTE_ETH_MQ_RX_DCB_RSS:
    4142                 :            :                 case RTE_ETH_MQ_RX_VMDQ_RSS:
    4143                 :          0 :                         txgbe_rss_configure(dev);
    4144                 :          0 :                         break;
    4145                 :            : 
    4146                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_DCB:
    4147                 :          0 :                         txgbe_vmdq_dcb_configure(dev);
    4148                 :          0 :                         break;
    4149                 :            : 
    4150                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_ONLY:
    4151                 :          0 :                         txgbe_vmdq_rx_hw_configure(dev);
    4152                 :          0 :                         break;
    4153                 :            : 
    4154                 :          0 :                 case RTE_ETH_MQ_RX_NONE:
    4155                 :            :                 default:
    4156                 :            :                         /* if mq_mode is none, disable rss mode.*/
    4157                 :          0 :                         txgbe_rss_disable(dev);
    4158                 :          0 :                         break;
    4159                 :            :                 }
    4160                 :            :         } else {
    4161                 :            :                 /* SRIOV active scheme
    4162                 :            :                  * Support RSS together with SRIOV.
    4163                 :            :                  */
    4164   [ #  #  #  # ]:          0 :                 switch (dev->data->dev_conf.rxmode.mq_mode) {
    4165                 :          0 :                 case RTE_ETH_MQ_RX_RSS:
    4166                 :            :                 case RTE_ETH_MQ_RX_VMDQ_RSS:
    4167                 :          0 :                         txgbe_config_vf_rss(dev);
    4168                 :          0 :                         break;
    4169                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_DCB:
    4170                 :            :                 case RTE_ETH_MQ_RX_DCB:
    4171                 :            :                 /* In SRIOV, the configuration is the same as VMDq case */
    4172                 :          0 :                         txgbe_vmdq_dcb_configure(dev);
    4173                 :          0 :                         break;
    4174                 :            :                 /* DCB/RSS together with SRIOV is not supported */
    4175                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
    4176                 :            :                 case RTE_ETH_MQ_RX_DCB_RSS:
    4177                 :          0 :                         PMD_INIT_LOG(ERR,
    4178                 :            :                                 "Could not support DCB/RSS with VMDq & SRIOV");
    4179                 :          0 :                         return -1;
    4180                 :          0 :                 default:
    4181                 :          0 :                         txgbe_config_vf_default(dev);
    4182                 :          0 :                         break;
    4183                 :            :                 }
    4184                 :            :         }
    4185                 :            : 
    4186                 :            :         return 0;
    4187                 :            : }
    4188                 :            : 
    4189                 :            : static int
    4190                 :          0 : txgbe_dev_mq_tx_configure(struct rte_eth_dev *dev)
    4191                 :            : {
    4192                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4193                 :            :         uint32_t mtqc;
    4194                 :            :         uint32_t rttdcs;
    4195                 :            : 
    4196                 :            :         /* disable arbiter */
    4197                 :            :         rttdcs = rd32(hw, TXGBE_ARBTXCTL);
    4198                 :          0 :         rttdcs |= TXGBE_ARBTXCTL_DIA;
    4199                 :            :         wr32(hw, TXGBE_ARBTXCTL, rttdcs);
    4200                 :            : 
    4201         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
    4202                 :            :                 /*
    4203                 :            :                  * SRIOV inactive scheme
    4204                 :            :                  * any DCB w/o VMDq multi-queue setting
    4205                 :            :                  */
    4206         [ #  # ]:          0 :                 if (dev->data->dev_conf.txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY)
    4207                 :          0 :                         txgbe_vmdq_tx_hw_configure(hw);
    4208                 :            :                 else
    4209                 :            :                         wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, 0);
    4210                 :            :         } else {
    4211   [ #  #  #  # ]:          0 :                 switch (RTE_ETH_DEV_SRIOV(dev).active) {
    4212                 :            :                 /*
    4213                 :            :                  * SRIOV active scheme
    4214                 :            :                  * FIXME if support DCB together with VMDq & SRIOV
    4215                 :            :                  */
    4216                 :            :                 case RTE_ETH_64_POOLS:
    4217                 :            :                         mtqc = TXGBE_PORTCTL_NUMVT_64;
    4218                 :            :                         break;
    4219                 :          0 :                 case RTE_ETH_32_POOLS:
    4220                 :            :                         mtqc = TXGBE_PORTCTL_NUMVT_32;
    4221                 :          0 :                         break;
    4222                 :          0 :                 case RTE_ETH_16_POOLS:
    4223                 :            :                         mtqc = TXGBE_PORTCTL_NUMVT_16;
    4224                 :          0 :                         break;
    4225                 :          0 :                 default:
    4226                 :            :                         mtqc = 0;
    4227                 :          0 :                         PMD_INIT_LOG(ERR, "invalid pool number in IOV mode");
    4228                 :            :                 }
    4229                 :            :                 wr32m(hw, TXGBE_PORTCTL, TXGBE_PORTCTL_NUMVT_MASK, mtqc);
    4230                 :            :         }
    4231                 :            : 
    4232                 :            :         /* re-enable arbiter */
    4233                 :            :         rttdcs &= ~TXGBE_ARBTXCTL_DIA;
    4234                 :            :         wr32(hw, TXGBE_ARBTXCTL, rttdcs);
    4235                 :            : 
    4236                 :          0 :         return 0;
    4237                 :            : }
    4238                 :            : 
    4239                 :            : /**
    4240                 :            :  * txgbe_get_rscctl_maxdesc
    4241                 :            :  *
    4242                 :            :  * @pool Memory pool of the Rx queue
    4243                 :            :  */
    4244                 :            : static inline uint32_t
    4245                 :            : txgbe_get_rscctl_maxdesc(struct rte_mempool *pool)
    4246                 :            : {
    4247                 :            :         struct rte_pktmbuf_pool_private *mp_priv = rte_mempool_get_priv(pool);
    4248                 :            : 
    4249                 :          0 :         uint16_t maxdesc =
    4250                 :          0 :                 RTE_IPV4_MAX_PKT_LEN /
    4251                 :          0 :                         (mp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM);
    4252                 :            : 
    4253         [ #  # ]:          0 :         if (maxdesc >= 16)
    4254                 :            :                 return TXGBE_RXCFG_RSCMAX_16;
    4255         [ #  # ]:          0 :         else if (maxdesc >= 8)
    4256                 :            :                 return TXGBE_RXCFG_RSCMAX_8;
    4257         [ #  # ]:          0 :         else if (maxdesc >= 4)
    4258                 :            :                 return TXGBE_RXCFG_RSCMAX_4;
    4259                 :            :         else
    4260                 :          0 :                 return TXGBE_RXCFG_RSCMAX_1;
    4261                 :            : }
    4262                 :            : 
    4263                 :            : /**
    4264                 :            :  * txgbe_set_rsc - configure RSC related port HW registers
    4265                 :            :  *
    4266                 :            :  * Configures the port's RSC related registers.
    4267                 :            :  *
    4268                 :            :  * @dev port handle
    4269                 :            :  *
    4270                 :            :  * Returns 0 in case of success or a non-zero error code
    4271                 :            :  */
    4272                 :            : static int
    4273                 :          0 : txgbe_set_rsc(struct rte_eth_dev *dev)
    4274                 :            : {
    4275                 :          0 :         struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
    4276                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4277                 :          0 :         struct rte_eth_dev_info dev_info = { 0 };
    4278                 :            :         bool rsc_capable = false;
    4279                 :            :         uint16_t i;
    4280                 :            :         uint32_t rdrxctl;
    4281                 :            :         uint32_t rfctl;
    4282                 :            : 
    4283                 :            :         /* Sanity check */
    4284                 :          0 :         dev->dev_ops->dev_infos_get(dev, &dev_info);
    4285         [ #  # ]:          0 :         if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TCP_LRO)
    4286                 :            :                 rsc_capable = true;
    4287                 :            : 
    4288         [ #  # ]:          0 :         if (!rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
    4289                 :          0 :                 PMD_INIT_LOG(CRIT, "LRO is requested on HW that doesn't "
    4290                 :            :                                    "support it");
    4291                 :          0 :                 return -EINVAL;
    4292                 :            :         }
    4293                 :            : 
    4294                 :            :         /* RSC global configuration */
    4295                 :            : 
    4296         [ #  # ]:          0 :         if ((rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
    4297                 :            :              (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO)) {
    4298                 :          0 :                 PMD_INIT_LOG(CRIT, "LRO can't be enabled when HW CRC "
    4299                 :            :                                     "is disabled");
    4300                 :          0 :                 return -EINVAL;
    4301                 :            :         }
    4302                 :            : 
    4303                 :            :         rfctl = rd32(hw, TXGBE_PSRCTL);
    4304   [ #  #  #  # ]:          0 :         if (rsc_capable && (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
    4305                 :          0 :                 rfctl &= ~TXGBE_PSRCTL_RSCDIA;
    4306                 :            :         else
    4307                 :          0 :                 rfctl |= TXGBE_PSRCTL_RSCDIA;
    4308                 :            :         wr32(hw, TXGBE_PSRCTL, rfctl);
    4309                 :            : 
    4310                 :            :         /* If LRO hasn't been requested - we are done here. */
    4311         [ #  # ]:          0 :         if (!(rx_conf->offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO))
    4312                 :            :                 return 0;
    4313                 :            : 
    4314                 :            :         /* Set PSRCTL.RSCACK bit */
    4315                 :            :         rdrxctl = rd32(hw, TXGBE_PSRCTL);
    4316                 :          0 :         rdrxctl |= TXGBE_PSRCTL_RSCACK;
    4317                 :            :         wr32(hw, TXGBE_PSRCTL, rdrxctl);
    4318                 :            : 
    4319                 :            :         /* Per-queue RSC configuration */
    4320         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    4321                 :          0 :                 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
    4322                 :            :                 uint32_t srrctl =
    4323                 :          0 :                         rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
    4324                 :            :                 uint32_t psrtype =
    4325                 :          0 :                         rd32(hw, TXGBE_POOLRSS(rxq->reg_idx));
    4326                 :            :                 uint32_t eitr =
    4327                 :          0 :                         rd32(hw, TXGBE_ITR(rxq->reg_idx));
    4328                 :            : 
    4329                 :            :                 /*
    4330                 :            :                  * txgbe PMD doesn't support header-split at the moment.
    4331                 :            :                  */
    4332                 :            :                 srrctl &= ~TXGBE_RXCFG_HDRLEN_MASK;
    4333                 :            :                 srrctl |= TXGBE_RXCFG_HDRLEN(128);
    4334                 :            : 
    4335                 :            :                 /*
    4336                 :            :                  * TODO: Consider setting the Receive Descriptor Minimum
    4337                 :            :                  * Threshold Size for an RSC case. This is not an obviously
    4338                 :            :                  * beneficiary option but the one worth considering...
    4339                 :            :                  */
    4340                 :            : 
    4341                 :            :                 srrctl |= TXGBE_RXCFG_RSCENA;
    4342                 :          0 :                 srrctl &= ~TXGBE_RXCFG_RSCMAX_MASK;
    4343         [ #  # ]:          0 :                 srrctl |= txgbe_get_rscctl_maxdesc(rxq->mb_pool);
    4344                 :          0 :                 psrtype |= TXGBE_POOLRSS_L4HDR;
    4345                 :            : 
    4346                 :            :                 /*
    4347                 :            :                  * RSC: Set ITR interval corresponding to 2K ints/s.
    4348                 :            :                  *
    4349                 :            :                  * Full-sized RSC aggregations for a 10Gb/s link will
    4350                 :            :                  * arrive at about 20K aggregation/s rate.
    4351                 :            :                  *
    4352                 :            :                  * 2K inst/s rate will make only 10% of the
    4353                 :            :                  * aggregations to be closed due to the interrupt timer
    4354                 :            :                  * expiration for a streaming at wire-speed case.
    4355                 :            :                  *
    4356                 :            :                  * For a sparse streaming case this setting will yield
    4357                 :            :                  * at most 500us latency for a single RSC aggregation.
    4358                 :            :                  */
    4359                 :          0 :                 eitr &= ~TXGBE_ITR_IVAL_MASK;
    4360                 :            :                 eitr |= TXGBE_ITR_IVAL_10G(TXGBE_QUEUE_ITR_INTERVAL_DEFAULT);
    4361                 :          0 :                 eitr |= TXGBE_ITR_WRDSA;
    4362                 :            : 
    4363                 :          0 :                 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
    4364                 :          0 :                 wr32(hw, TXGBE_POOLRSS(rxq->reg_idx), psrtype);
    4365                 :          0 :                 wr32(hw, TXGBE_ITR(rxq->reg_idx), eitr);
    4366                 :            : 
    4367                 :            :                 /*
    4368                 :            :                  * RSC requires the mapping of the queue to the
    4369                 :            :                  * interrupt vector.
    4370                 :            :                  */
    4371                 :          0 :                 txgbe_set_ivar_map(hw, 0, rxq->reg_idx, i);
    4372                 :            :         }
    4373                 :            : 
    4374                 :          0 :         dev->data->lro = 1;
    4375                 :            : 
    4376                 :          0 :         PMD_INIT_LOG(DEBUG, "enabling LRO mode");
    4377                 :            : 
    4378                 :          0 :         return 0;
    4379                 :            : }
    4380                 :            : 
    4381                 :            : void __rte_cold
    4382                 :          0 : txgbe_set_rx_function(struct rte_eth_dev *dev)
    4383                 :            : {
    4384                 :            :         uint16_t i, rx_using_sse;
    4385                 :          0 :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
    4386                 :            : 
    4387                 :            :         /*
    4388                 :            :          * In order to allow Vector Rx there are a few configuration
    4389                 :            :          * conditions to be met and Rx Bulk Allocation should be allowed.
    4390                 :            :          */
    4391         [ #  # ]:          0 :         if (txgbe_rx_vec_dev_conf_condition_check(dev) ||
    4392   [ #  #  #  # ]:          0 :             !adapter->rx_bulk_alloc_allowed ||
    4393                 :          0 :                         rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
    4394                 :          0 :                 PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet Vector Rx "
    4395                 :            :                                     "preconditions",
    4396                 :            :                              dev->data->port_id);
    4397                 :            : 
    4398                 :          0 :                 adapter->rx_vec_allowed = false;
    4399                 :            :         }
    4400                 :            : 
    4401                 :            :         /*
    4402                 :            :          * Initialize the appropriate LRO callback.
    4403                 :            :          *
    4404                 :            :          * If all queues satisfy the bulk allocation preconditions
    4405                 :            :          * (adapter->rx_bulk_alloc_allowed is TRUE) then we may use
    4406                 :            :          * bulk allocation. Otherwise use a single allocation version.
    4407                 :            :          */
    4408         [ #  # ]:          0 :         if (dev->data->lro) {
    4409         [ #  # ]:          0 :                 if (adapter->rx_bulk_alloc_allowed) {
    4410                 :          0 :                         PMD_INIT_LOG(DEBUG, "LRO is requested. Using a bulk "
    4411                 :            :                                            "allocation version");
    4412                 :          0 :                         dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
    4413                 :            :                 } else {
    4414                 :          0 :                         PMD_INIT_LOG(DEBUG, "LRO is requested. Using a single "
    4415                 :            :                                            "allocation version");
    4416                 :          0 :                         dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
    4417                 :            :                 }
    4418         [ #  # ]:          0 :         } else if (dev->data->scattered_rx) {
    4419                 :            :                 /*
    4420                 :            :                  * Set the non-LRO scattered callback: there are bulk and
    4421                 :            :                  * single allocation versions.
    4422                 :            :                  */
    4423         [ #  # ]:          0 :                 if (adapter->rx_vec_allowed) {
    4424                 :          0 :                         PMD_INIT_LOG(DEBUG, "Using Vector Scattered Rx "
    4425                 :            :                                             "callback (port=%d).",
    4426                 :            :                                      dev->data->port_id);
    4427                 :          0 :                         dev->rx_pkt_burst = txgbe_recv_scattered_pkts_vec;
    4428         [ #  # ]:          0 :                 } else if (adapter->rx_bulk_alloc_allowed) {
    4429                 :          0 :                         PMD_INIT_LOG(DEBUG, "Using a Scattered with bulk "
    4430                 :            :                                            "allocation callback (port=%d).",
    4431                 :            :                                      dev->data->port_id);
    4432                 :          0 :                         dev->rx_pkt_burst = txgbe_recv_pkts_lro_bulk_alloc;
    4433                 :            :                 } else {
    4434                 :          0 :                         PMD_INIT_LOG(DEBUG, "Using Regular (non-vector, "
    4435                 :            :                                             "single allocation) "
    4436                 :            :                                             "Scattered Rx callback "
    4437                 :            :                                             "(port=%d).",
    4438                 :            :                                      dev->data->port_id);
    4439                 :            : 
    4440                 :          0 :                         dev->rx_pkt_burst = txgbe_recv_pkts_lro_single_alloc;
    4441                 :            :                 }
    4442                 :            :         /*
    4443                 :            :          * Below we set "simple" callbacks according to port/queues parameters.
    4444                 :            :          * If parameters allow we are going to choose between the following
    4445                 :            :          * callbacks:
    4446                 :            :          *    - Vector
    4447                 :            :          *    - Bulk Allocation
    4448                 :            :          *    - Single buffer allocation (the simplest one)
    4449                 :            :          */
    4450         [ #  # ]:          0 :         } else if (adapter->rx_vec_allowed) {
    4451                 :          0 :                 PMD_INIT_LOG(DEBUG, "Vector rx enabled, please make sure RX "
    4452                 :            :                                     "burst size no less than %d (port=%d).",
    4453                 :            :                              RTE_TXGBE_DESCS_PER_LOOP,
    4454                 :            :                              dev->data->port_id);
    4455                 :          0 :                 dev->rx_pkt_burst = txgbe_recv_pkts_vec;
    4456         [ #  # ]:          0 :         } else if (adapter->rx_bulk_alloc_allowed) {
    4457                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
    4458                 :            :                                     "satisfied. Rx Burst Bulk Alloc function "
    4459                 :            :                                     "will be used on port=%d.",
    4460                 :            :                              dev->data->port_id);
    4461                 :            : 
    4462                 :          0 :                 dev->rx_pkt_burst = txgbe_recv_pkts_bulk_alloc;
    4463                 :            :         } else {
    4464                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are not "
    4465                 :            :                                     "satisfied, or Scattered Rx is requested "
    4466                 :            :                                     "(port=%d).",
    4467                 :            :                              dev->data->port_id);
    4468                 :            : 
    4469                 :          0 :                 dev->rx_pkt_burst = txgbe_recv_pkts;
    4470                 :            :         }
    4471                 :            : 
    4472   [ #  #  #  # ]:          0 :         rx_using_sse = (dev->rx_pkt_burst == txgbe_recv_scattered_pkts_vec ||
    4473                 :            :                         dev->rx_pkt_burst == txgbe_recv_pkts_vec);
    4474                 :            : 
    4475         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    4476                 :          0 :                 struct txgbe_rx_queue *rxq = dev->data->rx_queues[i];
    4477                 :            : 
    4478                 :          0 :                 rxq->rx_using_sse = rx_using_sse;
    4479                 :            : #ifdef RTE_LIB_SECURITY
    4480                 :          0 :                 rxq->using_ipsec = !!(dev->data->dev_conf.rxmode.offloads &
    4481                 :            :                                 RTE_ETH_RX_OFFLOAD_SECURITY);
    4482                 :            : #endif
    4483                 :            :         }
    4484                 :          0 : }
    4485                 :            : 
    4486                 :            : /*
    4487                 :            :  * Initializes Receive Unit.
    4488                 :            :  */
    4489                 :            : int __rte_cold
    4490                 :          0 : txgbe_dev_rx_init(struct rte_eth_dev *dev)
    4491                 :            : {
    4492                 :            :         struct txgbe_hw *hw;
    4493                 :            :         struct txgbe_rx_queue *rxq;
    4494                 :            :         uint64_t bus_addr;
    4495                 :            :         uint32_t fctrl;
    4496                 :            :         uint32_t hlreg0;
    4497                 :            :         uint32_t srrctl;
    4498                 :            :         uint32_t rdrxctl;
    4499                 :            :         uint32_t rxcsum;
    4500                 :            :         uint16_t buf_size;
    4501                 :            :         uint16_t i;
    4502                 :          0 :         struct rte_eth_rxmode *rx_conf = &dev->data->dev_conf.rxmode;
    4503                 :            :         int rc;
    4504                 :            : 
    4505                 :          0 :         PMD_INIT_FUNC_TRACE();
    4506                 :          0 :         hw = TXGBE_DEV_HW(dev);
    4507                 :            : 
    4508                 :            :         /*
    4509                 :            :          * Make sure receives are disabled while setting
    4510                 :            :          * up the RX context (registers, descriptor rings, etc.).
    4511                 :            :          */
    4512                 :            :         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
    4513                 :            :         wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
    4514                 :            : 
    4515                 :            :         /* Enable receipt of broadcasted frames */
    4516                 :            :         fctrl = rd32(hw, TXGBE_PSRCTL);
    4517                 :          0 :         fctrl |= TXGBE_PSRCTL_BCA;
    4518                 :            :         wr32(hw, TXGBE_PSRCTL, fctrl);
    4519                 :            : 
    4520                 :            :         /*
    4521                 :            :          * Configure CRC stripping, if any.
    4522                 :            :          */
    4523                 :            :         hlreg0 = rd32(hw, TXGBE_SECRXCTL);
    4524         [ #  # ]:          0 :         if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    4525                 :          0 :                 hlreg0 &= ~TXGBE_SECRXCTL_CRCSTRIP;
    4526                 :            :         else
    4527                 :          0 :                 hlreg0 |= TXGBE_SECRXCTL_CRCSTRIP;
    4528                 :            :         wr32(hw, TXGBE_SECRXCTL, hlreg0);
    4529                 :            : 
    4530                 :            :         /*
    4531                 :            :          * Configure jumbo frame support, if any.
    4532                 :            :          */
    4533                 :          0 :         wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
    4534                 :          0 :                 TXGBE_FRMSZ_MAX(dev->data->mtu + TXGBE_ETH_OVERHEAD));
    4535                 :            : 
    4536                 :            :         /*
    4537                 :            :          * If loopback mode is configured, set LPBK bit.
    4538                 :            :          */
    4539                 :            :         hlreg0 = rd32(hw, TXGBE_PSRCTL);
    4540         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor &&
    4541         [ #  # ]:          0 :             dev->data->dev_conf.lpbk_mode)
    4542                 :          0 :                 hlreg0 |= TXGBE_PSRCTL_LBENA;
    4543                 :            :         else
    4544                 :          0 :                 hlreg0 &= ~TXGBE_PSRCTL_LBENA;
    4545                 :            : 
    4546                 :            :         wr32(hw, TXGBE_PSRCTL, hlreg0);
    4547                 :            : 
    4548                 :            :         /*
    4549                 :            :          * Assume no header split and no VLAN strip support
    4550                 :            :          * on any Rx queue first .
    4551                 :            :          */
    4552                 :          0 :         rx_conf->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    4553                 :            : 
    4554                 :            :         /* Setup RX queues */
    4555         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    4556                 :          0 :                 rxq = dev->data->rx_queues[i];
    4557                 :            : 
    4558                 :            :                 /*
    4559                 :            :                  * Reset crc_len in case it was changed after queue setup by a
    4560                 :            :                  * call to configure.
    4561                 :            :                  */
    4562         [ #  # ]:          0 :                 if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    4563                 :          0 :                         rxq->crc_len = RTE_ETHER_CRC_LEN;
    4564                 :            :                 else
    4565                 :          0 :                         rxq->crc_len = 0;
    4566                 :            : 
    4567                 :            :                 /* Setup the Base and Length of the Rx Descriptor Rings */
    4568                 :          0 :                 bus_addr = rxq->rx_ring_phys_addr;
    4569                 :          0 :                 wr32(hw, TXGBE_RXBAL(rxq->reg_idx),
    4570                 :            :                                 (uint32_t)(bus_addr & BIT_MASK32));
    4571                 :          0 :                 wr32(hw, TXGBE_RXBAH(rxq->reg_idx),
    4572                 :          0 :                                 (uint32_t)(bus_addr >> 32));
    4573                 :          0 :                 wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
    4574                 :          0 :                 wr32(hw, TXGBE_RXWP(rxq->reg_idx), 0);
    4575                 :            : 
    4576         [ #  # ]:          0 :                 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
    4577                 :            : 
    4578                 :            :                 /* Set if packets are dropped when no descriptors available */
    4579         [ #  # ]:          0 :                 if (rxq->drop_en)
    4580                 :          0 :                         srrctl |= TXGBE_RXCFG_DROP;
    4581                 :            : 
    4582                 :            :                 /*
    4583                 :            :                  * Configure the RX buffer size in the PKTLEN field of
    4584                 :            :                  * the RXCFG register of the queue.
    4585                 :            :                  * The value is in 1 KB resolution. Valid values can be from
    4586                 :            :                  * 1 KB to 16 KB.
    4587                 :            :                  */
    4588         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
    4589                 :            :                         RTE_PKTMBUF_HEADROOM);
    4590                 :          0 :                 buf_size = ROUND_DOWN(buf_size, 0x1 << 10);
    4591         [ #  # ]:          0 :                 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
    4592                 :            : 
    4593                 :          0 :                 wr32(hw, TXGBE_RXCFG(rxq->reg_idx), srrctl);
    4594                 :            : 
    4595                 :            :                 /* It adds dual VLAN length for supporting dual VLAN */
    4596                 :          0 :                 if (dev->data->mtu + TXGBE_ETH_OVERHEAD +
    4597         [ #  # ]:          0 :                                 2 * RTE_VLAN_HLEN > buf_size)
    4598                 :          0 :                         dev->data->scattered_rx = 1;
    4599         [ #  # ]:          0 :                 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    4600                 :          0 :                         rx_conf->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    4601                 :            :         }
    4602                 :            : 
    4603         [ #  # ]:          0 :         if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_SCATTER)
    4604                 :          0 :                 dev->data->scattered_rx = 1;
    4605                 :            : 
    4606                 :            :         /*
    4607                 :            :          * Device configured with multiple RX queues.
    4608                 :            :          */
    4609                 :          0 :         txgbe_dev_mq_rx_configure(dev);
    4610                 :            : 
    4611                 :            :         /*
    4612                 :            :          * Setup the Checksum Register.
    4613                 :            :          * Disable Full-Packet Checksum which is mutually exclusive with RSS.
    4614                 :            :          * Enable IP/L4 checksum computation by hardware if requested to do so.
    4615                 :            :          */
    4616                 :            :         rxcsum = rd32(hw, TXGBE_PSRCTL);
    4617                 :            :         rxcsum |= TXGBE_PSRCTL_PCSD;
    4618         [ #  # ]:          0 :         if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
    4619                 :          0 :                 rxcsum |= TXGBE_PSRCTL_L4CSUM;
    4620                 :            :         else
    4621                 :          0 :                 rxcsum &= ~TXGBE_PSRCTL_L4CSUM;
    4622                 :            : 
    4623                 :            :         wr32(hw, TXGBE_PSRCTL, rxcsum);
    4624                 :            : 
    4625         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor) {
    4626                 :            :                 rdrxctl = rd32(hw, TXGBE_SECRXCTL);
    4627         [ #  # ]:          0 :                 if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    4628                 :          0 :                         rdrxctl &= ~TXGBE_SECRXCTL_CRCSTRIP;
    4629                 :            :                 else
    4630                 :          0 :                         rdrxctl |= TXGBE_SECRXCTL_CRCSTRIP;
    4631                 :            :                 wr32(hw, TXGBE_SECRXCTL, rdrxctl);
    4632                 :            :         }
    4633                 :            : 
    4634                 :          0 :         rc = txgbe_set_rsc(dev);
    4635         [ #  # ]:          0 :         if (rc)
    4636                 :            :                 return rc;
    4637                 :            : 
    4638                 :          0 :         txgbe_set_rx_function(dev);
    4639                 :            : 
    4640                 :          0 :         return 0;
    4641                 :            : }
    4642                 :            : 
    4643                 :            : /*
    4644                 :            :  * Initializes Transmit Unit.
    4645                 :            :  */
    4646                 :            : void __rte_cold
    4647                 :          0 : txgbe_dev_tx_init(struct rte_eth_dev *dev)
    4648                 :            : {
    4649                 :            :         struct txgbe_hw     *hw;
    4650                 :            :         struct txgbe_tx_queue *txq;
    4651                 :            :         uint64_t bus_addr;
    4652                 :            :         uint16_t i;
    4653                 :            : 
    4654                 :          0 :         PMD_INIT_FUNC_TRACE();
    4655                 :          0 :         hw = TXGBE_DEV_HW(dev);
    4656                 :            : 
    4657                 :            :         /* Setup the Base and Length of the Tx Descriptor Rings */
    4658         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    4659                 :          0 :                 txq = dev->data->tx_queues[i];
    4660                 :            : 
    4661                 :          0 :                 bus_addr = txq->tx_ring_phys_addr;
    4662                 :          0 :                 wr32(hw, TXGBE_TXBAL(txq->reg_idx),
    4663                 :            :                                 (uint32_t)(bus_addr & BIT_MASK32));
    4664                 :          0 :                 wr32(hw, TXGBE_TXBAH(txq->reg_idx),
    4665                 :          0 :                                 (uint32_t)(bus_addr >> 32));
    4666                 :          0 :                 wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_BUFLEN_MASK,
    4667         [ #  # ]:          0 :                         TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
    4668                 :            :                 /* Setup the HW Tx Head and TX Tail descriptor pointers */
    4669                 :          0 :                 wr32(hw, TXGBE_TXRP(txq->reg_idx), 0);
    4670                 :          0 :                 wr32(hw, TXGBE_TXWP(txq->reg_idx), 0);
    4671                 :            :         }
    4672                 :            : 
    4673                 :            : #ifndef RTE_LIB_SECURITY
    4674                 :            :         for (i = 0; i < 4; i++)
    4675                 :            :                 wr32(hw, TXGBE_TDM_DESC_CHK(i), 0xFFFFFFFF);
    4676                 :            : #endif
    4677                 :            : 
    4678                 :            :         /* Device configured with multiple TX queues. */
    4679                 :          0 :         txgbe_dev_mq_tx_configure(dev);
    4680                 :          0 : }
    4681                 :            : 
    4682                 :            : /*
    4683                 :            :  * Set up link loopback mode Tx->Rx.
    4684                 :            :  */
    4685                 :            : static inline void __rte_cold
    4686                 :          0 : txgbe_setup_loopback_link_raptor(struct txgbe_hw *hw)
    4687                 :            : {
    4688                 :          0 :         PMD_INIT_FUNC_TRACE();
    4689                 :            : 
    4690                 :            :         wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_LB, TXGBE_MACRXCFG_LB);
    4691                 :            : 
    4692                 :            :         msec_delay(50);
    4693                 :          0 : }
    4694                 :            : 
    4695                 :            : /*
    4696                 :            :  * Start Transmit and Receive Units.
    4697                 :            :  */
    4698                 :            : int __rte_cold
    4699                 :          0 : txgbe_dev_rxtx_start(struct rte_eth_dev *dev)
    4700                 :            : {
    4701                 :            :         struct txgbe_hw     *hw;
    4702                 :            :         struct txgbe_tx_queue *txq;
    4703                 :            :         struct txgbe_rx_queue *rxq;
    4704                 :            :         uint32_t dmatxctl;
    4705                 :            :         uint32_t rxctrl;
    4706                 :            :         uint16_t i;
    4707                 :            :         int ret = 0;
    4708                 :            : 
    4709                 :          0 :         PMD_INIT_FUNC_TRACE();
    4710                 :          0 :         hw = TXGBE_DEV_HW(dev);
    4711                 :            : 
    4712         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    4713                 :          0 :                 txq = dev->data->tx_queues[i];
    4714                 :            :                 /* Setup Transmit Threshold Registers */
    4715                 :          0 :                 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
    4716                 :            :                       TXGBE_TXCFG_HTHRESH_MASK |
    4717                 :            :                       TXGBE_TXCFG_WTHRESH_MASK,
    4718                 :          0 :                       TXGBE_TXCFG_HTHRESH(txq->hthresh) |
    4719                 :          0 :                       TXGBE_TXCFG_WTHRESH(txq->wthresh));
    4720                 :            :         }
    4721                 :            : 
    4722                 :            :         dmatxctl = rd32(hw, TXGBE_DMATXCTRL);
    4723                 :          0 :         dmatxctl |= TXGBE_DMATXCTRL_ENA;
    4724                 :            :         wr32(hw, TXGBE_DMATXCTRL, dmatxctl);
    4725                 :            : 
    4726         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    4727                 :          0 :                 txq = dev->data->tx_queues[i];
    4728         [ #  # ]:          0 :                 if (!txq->tx_deferred_start) {
    4729                 :          0 :                         ret = txgbe_dev_tx_queue_start(dev, i);
    4730         [ #  # ]:          0 :                         if (ret < 0)
    4731                 :          0 :                                 return ret;
    4732                 :            :                 }
    4733                 :            :         }
    4734                 :            : 
    4735         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    4736                 :          0 :                 rxq = dev->data->rx_queues[i];
    4737         [ #  # ]:          0 :                 if (!rxq->rx_deferred_start) {
    4738                 :          0 :                         ret = txgbe_dev_rx_queue_start(dev, i);
    4739         [ #  # ]:          0 :                         if (ret < 0)
    4740                 :          0 :                                 return ret;
    4741                 :            :                 }
    4742                 :            :         }
    4743                 :            : 
    4744                 :            :         /* Enable Receive engine */
    4745                 :            :         rxctrl = rd32(hw, TXGBE_PBRXCTL);
    4746                 :          0 :         rxctrl |= TXGBE_PBRXCTL_ENA;
    4747                 :          0 :         hw->mac.enable_rx_dma(hw, rxctrl);
    4748                 :            : 
    4749                 :            :         /* If loopback mode is enabled, set up the link accordingly */
    4750         [ #  # ]:          0 :         if (hw->mac.type == txgbe_mac_raptor &&
    4751         [ #  # ]:          0 :             dev->data->dev_conf.lpbk_mode)
    4752                 :          0 :                 txgbe_setup_loopback_link_raptor(hw);
    4753                 :            : 
    4754                 :            : #ifdef RTE_LIB_SECURITY
    4755         [ #  # ]:          0 :         if ((dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SECURITY) ||
    4756         [ #  # ]:          0 :             (dev->data->dev_conf.txmode.offloads & RTE_ETH_TX_OFFLOAD_SECURITY)) {
    4757                 :          0 :                 ret = txgbe_crypto_enable_ipsec(dev);
    4758         [ #  # ]:          0 :                 if (ret != 0) {
    4759                 :          0 :                         PMD_DRV_LOG(ERR,
    4760                 :            :                                     "txgbe_crypto_enable_ipsec fails with %d.",
    4761                 :            :                                     ret);
    4762                 :          0 :                         return ret;
    4763                 :            :                 }
    4764                 :            :         }
    4765                 :            : #endif
    4766                 :            : 
    4767                 :            :         return 0;
    4768                 :            : }
    4769                 :            : 
    4770                 :            : void
    4771                 :          0 : txgbe_dev_save_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
    4772                 :            : {
    4773                 :          0 :         u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
    4774                 :          0 :         *(reg++) = rd32(hw, TXGBE_RXBAL(rx_queue_id));
    4775                 :          0 :         *(reg++) = rd32(hw, TXGBE_RXBAH(rx_queue_id));
    4776                 :          0 :         *(reg++) = rd32(hw, TXGBE_RXCFG(rx_queue_id));
    4777                 :          0 : }
    4778                 :            : 
    4779                 :            : void
    4780                 :          0 : txgbe_dev_store_rx_queue(struct txgbe_hw *hw, uint16_t rx_queue_id)
    4781                 :            : {
    4782                 :          0 :         u32 *reg = &hw->q_rx_regs[rx_queue_id * 8];
    4783                 :          0 :         wr32(hw, TXGBE_RXBAL(rx_queue_id), *(reg++));
    4784                 :          0 :         wr32(hw, TXGBE_RXBAH(rx_queue_id), *(reg++));
    4785                 :          0 :         wr32(hw, TXGBE_RXCFG(rx_queue_id), *(reg++) & ~TXGBE_RXCFG_ENA);
    4786                 :          0 : }
    4787                 :            : 
    4788                 :            : void
    4789                 :          0 : txgbe_dev_save_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
    4790                 :            : {
    4791                 :          0 :         u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
    4792                 :          0 :         *(reg++) = rd32(hw, TXGBE_TXBAL(tx_queue_id));
    4793                 :          0 :         *(reg++) = rd32(hw, TXGBE_TXBAH(tx_queue_id));
    4794                 :          0 :         *(reg++) = rd32(hw, TXGBE_TXCFG(tx_queue_id));
    4795                 :          0 : }
    4796                 :            : 
    4797                 :            : void
    4798                 :          0 : txgbe_dev_store_tx_queue(struct txgbe_hw *hw, uint16_t tx_queue_id)
    4799                 :            : {
    4800                 :          0 :         u32 *reg = &hw->q_tx_regs[tx_queue_id * 8];
    4801                 :          0 :         wr32(hw, TXGBE_TXBAL(tx_queue_id), *(reg++));
    4802                 :          0 :         wr32(hw, TXGBE_TXBAH(tx_queue_id), *(reg++));
    4803                 :          0 :         wr32(hw, TXGBE_TXCFG(tx_queue_id), *(reg++) & ~TXGBE_TXCFG_ENA);
    4804                 :          0 : }
    4805                 :            : 
    4806                 :            : /*
    4807                 :            :  * Start Receive Units for specified queue.
    4808                 :            :  */
    4809                 :            : int __rte_cold
    4810                 :          0 : txgbe_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    4811                 :            : {
    4812                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4813                 :            :         struct txgbe_rx_queue *rxq;
    4814                 :            :         uint32_t rxdctl;
    4815                 :            :         int poll_ms;
    4816                 :            : 
    4817                 :          0 :         PMD_INIT_FUNC_TRACE();
    4818                 :            : 
    4819                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
    4820                 :            : 
    4821                 :            :         /* Allocate buffers for descriptor rings */
    4822         [ #  # ]:          0 :         if (txgbe_alloc_rx_queue_mbufs(rxq) != 0) {
    4823                 :          0 :                 PMD_INIT_LOG(ERR, "Could not alloc mbuf for queue:%d",
    4824                 :            :                              rx_queue_id);
    4825                 :          0 :                 return -1;
    4826                 :            :         }
    4827                 :          0 :         rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
    4828                 :          0 :         rxdctl |= TXGBE_RXCFG_ENA;
    4829                 :          0 :         wr32(hw, TXGBE_RXCFG(rxq->reg_idx), rxdctl);
    4830                 :            : 
    4831                 :            :         /* Wait until RX Enable ready */
    4832                 :            :         poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
    4833                 :            :         do {
    4834                 :            :                 rte_delay_ms(1);
    4835                 :          0 :                 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
    4836   [ #  #  #  # ]:          0 :         } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
    4837         [ #  # ]:          0 :         if (!poll_ms)
    4838                 :          0 :                 PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", rx_queue_id);
    4839                 :            :         rte_wmb();
    4840                 :          0 :         wr32(hw, TXGBE_RXRP(rxq->reg_idx), 0);
    4841                 :          0 :         wr32(hw, TXGBE_RXWP(rxq->reg_idx), rxq->nb_rx_desc - 1);
    4842                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
    4843                 :            : 
    4844                 :          0 :         return 0;
    4845                 :            : }
    4846                 :            : 
    4847                 :            : /*
    4848                 :            :  * Stop Receive Units for specified queue.
    4849                 :            :  */
    4850                 :            : int __rte_cold
    4851                 :          0 : txgbe_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    4852                 :            : {
    4853                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4854                 :            :         struct txgbe_adapter *adapter = TXGBE_DEV_ADAPTER(dev);
    4855                 :            :         struct txgbe_rx_queue *rxq;
    4856                 :            :         uint32_t rxdctl;
    4857                 :            :         int poll_ms;
    4858                 :            : 
    4859                 :          0 :         PMD_INIT_FUNC_TRACE();
    4860                 :            : 
    4861                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
    4862                 :            : 
    4863                 :          0 :         txgbe_dev_save_rx_queue(hw, rxq->reg_idx);
    4864                 :          0 :         wr32m(hw, TXGBE_RXCFG(rxq->reg_idx), TXGBE_RXCFG_ENA, 0);
    4865                 :            : 
    4866                 :            :         /* Wait until RX Enable bit clear */
    4867                 :            :         poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
    4868                 :            :         do {
    4869                 :            :                 rte_delay_ms(1);
    4870                 :          0 :                 rxdctl = rd32(hw, TXGBE_RXCFG(rxq->reg_idx));
    4871   [ #  #  #  # ]:          0 :         } while (--poll_ms && (rxdctl & TXGBE_RXCFG_ENA));
    4872         [ #  # ]:          0 :         if (!poll_ms)
    4873                 :          0 :                 PMD_INIT_LOG(ERR, "Could not disable Rx Queue %d", rx_queue_id);
    4874                 :            : 
    4875                 :          0 :         rte_delay_us(RTE_TXGBE_WAIT_100_US);
    4876                 :          0 :         txgbe_dev_store_rx_queue(hw, rxq->reg_idx);
    4877                 :            : 
    4878                 :          0 :         txgbe_rx_queue_release_mbufs(rxq);
    4879                 :          0 :         txgbe_reset_rx_queue(adapter, rxq);
    4880                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
    4881                 :            : 
    4882                 :          0 :         return 0;
    4883                 :            : }
    4884                 :            : 
    4885                 :            : /*
    4886                 :            :  * Start Transmit Units for specified queue.
    4887                 :            :  */
    4888                 :            : int __rte_cold
    4889                 :          0 : txgbe_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
    4890                 :            : {
    4891                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4892                 :            :         struct txgbe_tx_queue *txq;
    4893                 :            :         uint32_t txdctl;
    4894                 :            :         int poll_ms;
    4895                 :            : 
    4896                 :          0 :         PMD_INIT_FUNC_TRACE();
    4897                 :            : 
    4898                 :          0 :         txq = dev->data->tx_queues[tx_queue_id];
    4899                 :          0 :         wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
    4900                 :            : 
    4901                 :            :         /* Wait until TX Enable ready */
    4902                 :            :         poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
    4903                 :            :         do {
    4904                 :            :                 rte_delay_ms(1);
    4905                 :          0 :                 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
    4906   [ #  #  #  # ]:          0 :         } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
    4907         [ #  # ]:          0 :         if (!poll_ms)
    4908                 :          0 :                 PMD_INIT_LOG(ERR, "Could not enable "
    4909                 :            :                              "Tx Queue %d", tx_queue_id);
    4910                 :            : 
    4911                 :            :         rte_wmb();
    4912                 :          0 :         wr32(hw, TXGBE_TXWP(txq->reg_idx), txq->tx_tail);
    4913                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
    4914                 :          0 :         txq->resetting = false;
    4915                 :            : 
    4916                 :          0 :         return 0;
    4917                 :            : }
    4918                 :            : 
    4919                 :            : /*
    4920                 :            :  * Stop Transmit Units for specified queue.
    4921                 :            :  */
    4922                 :            : int __rte_cold
    4923                 :          0 : txgbe_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
    4924                 :            : {
    4925                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4926                 :            :         struct txgbe_tx_queue *txq;
    4927                 :            :         uint32_t txdctl;
    4928                 :            :         uint32_t txtdh, txtdt;
    4929                 :            :         int poll_ms;
    4930                 :            : 
    4931                 :          0 :         PMD_INIT_FUNC_TRACE();
    4932                 :            : 
    4933                 :          0 :         txq = dev->data->tx_queues[tx_queue_id];
    4934                 :            : 
    4935                 :            :         /* Wait until TX queue is empty */
    4936                 :            :         poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
    4937                 :            :         do {
    4938                 :          0 :                 rte_delay_us(RTE_TXGBE_WAIT_100_US);
    4939                 :          0 :                 txtdh = rd32(hw, TXGBE_TXRP(txq->reg_idx));
    4940                 :          0 :                 txtdt = rd32(hw, TXGBE_TXWP(txq->reg_idx));
    4941   [ #  #  #  # ]:          0 :         } while (--poll_ms && (txtdh != txtdt));
    4942         [ #  # ]:          0 :         if (!poll_ms)
    4943                 :          0 :                 PMD_INIT_LOG(ERR,
    4944                 :            :                         "Tx Queue %d is not empty when stopping.",
    4945                 :            :                         tx_queue_id);
    4946                 :            : 
    4947                 :          0 :         txgbe_dev_save_tx_queue(hw, txq->reg_idx);
    4948                 :          0 :         wr32m(hw, TXGBE_TXCFG(txq->reg_idx), TXGBE_TXCFG_ENA, 0);
    4949                 :            : 
    4950                 :            :         /* Wait until TX Enable bit clear */
    4951                 :            :         poll_ms = RTE_TXGBE_REGISTER_POLL_WAIT_10_MS;
    4952                 :            :         do {
    4953                 :            :                 rte_delay_ms(1);
    4954                 :          0 :                 txdctl = rd32(hw, TXGBE_TXCFG(txq->reg_idx));
    4955   [ #  #  #  # ]:          0 :         } while (--poll_ms && (txdctl & TXGBE_TXCFG_ENA));
    4956         [ #  # ]:          0 :         if (!poll_ms)
    4957                 :          0 :                 PMD_INIT_LOG(ERR, "Could not disable Tx Queue %d",
    4958                 :            :                         tx_queue_id);
    4959                 :            : 
    4960                 :          0 :         rte_delay_us(RTE_TXGBE_WAIT_100_US);
    4961                 :          0 :         txgbe_dev_store_tx_queue(hw, txq->reg_idx);
    4962                 :            : 
    4963         [ #  # ]:          0 :         if (txq->ops != NULL) {
    4964                 :          0 :                 txq->ops->release_mbufs(txq);
    4965                 :          0 :                 txq->ops->reset(txq);
    4966                 :            :         }
    4967                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
    4968                 :            : 
    4969                 :          0 :         return 0;
    4970                 :            : }
    4971                 :            : 
    4972                 :            : void
    4973                 :          0 : txgbe_tx_queue_clear_error(void *param)
    4974                 :            : {
    4975                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    4976                 :          0 :         struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
    4977                 :            :         struct txgbe_tx_queue *txq;
    4978                 :            :         u32 i;
    4979                 :            : 
    4980         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    4981                 :          0 :                 txq = dev->data->tx_queues[i];
    4982         [ #  # ]:          0 :                 if (!txq->resetting)
    4983                 :          0 :                         continue;
    4984                 :            : 
    4985                 :            :                 /* Increase the count of Tx desc error since
    4986                 :            :                  * it causes the queue reset.
    4987                 :            :                  */
    4988                 :          0 :                 txq->desc_error++;
    4989                 :          0 :                 txgbe_dev_save_tx_queue(hw, i);
    4990                 :            : 
    4991                 :            :                 /* tx ring reset */
    4992                 :          0 :                 wr32(hw, TXGBE_TDM_DESC_NONFATAL(i / 32),
    4993                 :          0 :                         TXGBE_TDM_DESC_MASK(i % 32));
    4994                 :            : 
    4995         [ #  # ]:          0 :                 if (txq->ops != NULL) {
    4996                 :          0 :                         txq->ops->release_mbufs(txq);
    4997                 :          0 :                         txq->ops->reset(txq);
    4998                 :            :                 }
    4999                 :            : 
    5000                 :          0 :                 txgbe_dev_store_tx_queue(hw, i);
    5001                 :          0 :                 txgbe_dev_tx_queue_start(dev, i);
    5002                 :            :         }
    5003                 :          0 : }
    5004                 :            : 
    5005                 :            : void
    5006                 :          0 : txgbe_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    5007                 :            :         struct rte_eth_rxq_info *qinfo)
    5008                 :            : {
    5009                 :            :         struct txgbe_rx_queue *rxq;
    5010                 :            : 
    5011                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    5012                 :            : 
    5013                 :          0 :         qinfo->mp = rxq->mb_pool;
    5014                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    5015                 :          0 :         qinfo->nb_desc = rxq->nb_rx_desc;
    5016                 :            : 
    5017                 :          0 :         qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
    5018                 :          0 :         qinfo->conf.rx_drop_en = rxq->drop_en;
    5019                 :          0 :         qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
    5020                 :          0 :         qinfo->conf.offloads = rxq->offloads;
    5021                 :          0 : }
    5022                 :            : 
    5023                 :            : void
    5024                 :          0 : txgbe_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    5025                 :            :         struct rte_eth_txq_info *qinfo)
    5026                 :            : {
    5027                 :            :         struct txgbe_tx_queue *txq;
    5028                 :            : 
    5029                 :          0 :         txq = dev->data->tx_queues[queue_id];
    5030                 :            : 
    5031                 :          0 :         qinfo->nb_desc = txq->nb_tx_desc;
    5032                 :            : 
    5033                 :          0 :         qinfo->conf.tx_thresh.pthresh = txq->pthresh;
    5034                 :          0 :         qinfo->conf.tx_thresh.hthresh = txq->hthresh;
    5035                 :          0 :         qinfo->conf.tx_thresh.wthresh = txq->wthresh;
    5036                 :            : 
    5037                 :          0 :         qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
    5038                 :          0 :         qinfo->conf.offloads = txq->offloads;
    5039                 :          0 :         qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
    5040                 :          0 : }
    5041                 :            : 
    5042                 :            : /*
    5043                 :            :  * [VF] Initializes Receive Unit.
    5044                 :            :  */
    5045                 :            : int __rte_cold
    5046                 :          0 : txgbevf_dev_rx_init(struct rte_eth_dev *dev)
    5047                 :            : {
    5048                 :            :         struct txgbe_hw     *hw;
    5049                 :            :         struct txgbe_rx_queue *rxq;
    5050                 :          0 :         struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
    5051                 :            :         uint64_t bus_addr;
    5052                 :            :         uint32_t srrctl, psrtype;
    5053                 :            :         uint16_t buf_size;
    5054                 :            :         uint16_t i;
    5055                 :            :         int ret;
    5056                 :            : 
    5057                 :          0 :         PMD_INIT_FUNC_TRACE();
    5058                 :          0 :         hw = TXGBE_DEV_HW(dev);
    5059                 :            : 
    5060         [ #  # ]:          0 :         if (rte_is_power_of_2(dev->data->nb_rx_queues) == 0) {
    5061                 :          0 :                 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
    5062                 :            :                         "it should be power of 2");
    5063                 :          0 :                 return -1;
    5064                 :            :         }
    5065                 :            : 
    5066         [ #  # ]:          0 :         if (dev->data->nb_rx_queues > hw->mac.max_rx_queues) {
    5067                 :          0 :                 PMD_INIT_LOG(ERR, "The number of Rx queue invalid, "
    5068                 :            :                         "it should be equal to or less than %d",
    5069                 :            :                         hw->mac.max_rx_queues);
    5070                 :          0 :                 return -1;
    5071                 :            :         }
    5072                 :            : 
    5073                 :            :         /*
    5074                 :            :          * When the VF driver issues a TXGBE_VF_RESET request, the PF driver
    5075                 :            :          * disables the VF receipt of packets if the PF MTU is > 1500.
    5076                 :            :          * This is done to deal with limitations that imposes
    5077                 :            :          * the PF and all VFs to share the same MTU.
    5078                 :            :          * Then, the PF driver enables again the VF receipt of packet when
    5079                 :            :          * the VF driver issues a TXGBE_VF_SET_LPE request.
    5080                 :            :          * In the meantime, the VF device cannot be used, even if the VF driver
    5081                 :            :          * and the Guest VM network stack are ready to accept packets with a
    5082                 :            :          * size up to the PF MTU.
    5083                 :            :          * As a work-around to this PF behaviour, force the call to
    5084                 :            :          * txgbevf_rlpml_set_vf even if jumbo frames are not used. This way,
    5085                 :            :          * VF packets received can work in all cases.
    5086                 :            :          */
    5087         [ #  # ]:          0 :         if (txgbevf_rlpml_set_vf(hw,
    5088                 :          0 :             (uint16_t)dev->data->mtu + TXGBE_ETH_OVERHEAD)) {
    5089                 :          0 :                 PMD_INIT_LOG(ERR, "Set max packet length to %d failed.",
    5090                 :            :                              dev->data->mtu + TXGBE_ETH_OVERHEAD);
    5091                 :          0 :                 return -EINVAL;
    5092                 :            :         }
    5093                 :            : 
    5094                 :            :         /*
    5095                 :            :          * Assume no header split and no VLAN strip support
    5096                 :            :          * on any Rx queue first .
    5097                 :            :          */
    5098                 :          0 :         rxmode->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    5099                 :            : 
    5100                 :            :         /* Set PSR type for VF RSS according to max Rx queue */
    5101                 :            :         psrtype = TXGBE_VFPLCFG_PSRL4HDR |
    5102                 :            :                   TXGBE_VFPLCFG_PSRL4HDR |
    5103                 :            :                   TXGBE_VFPLCFG_PSRL2HDR |
    5104                 :            :                   TXGBE_VFPLCFG_PSRTUNHDR |
    5105                 :            :                   TXGBE_VFPLCFG_PSRTUNMAC;
    5106                 :            :         wr32(hw, TXGBE_VFPLCFG, TXGBE_VFPLCFG_PSR(psrtype));
    5107                 :            : 
    5108                 :            :         /* Setup RX queues */
    5109         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    5110                 :          0 :                 rxq = dev->data->rx_queues[i];
    5111                 :            : 
    5112                 :            :                 /* Allocate buffers for descriptor rings */
    5113                 :          0 :                 ret = txgbe_alloc_rx_queue_mbufs(rxq);
    5114         [ #  # ]:          0 :                 if (ret)
    5115                 :          0 :                         return ret;
    5116                 :            : 
    5117                 :            :                 /* Setup the Base and Length of the Rx Descriptor Rings */
    5118                 :          0 :                 bus_addr = rxq->rx_ring_phys_addr;
    5119                 :            : 
    5120                 :          0 :                 wr32(hw, TXGBE_RXBAL(i),
    5121                 :            :                                 (uint32_t)(bus_addr & BIT_MASK32));
    5122                 :          0 :                 wr32(hw, TXGBE_RXBAH(i),
    5123                 :          0 :                                 (uint32_t)(bus_addr >> 32));
    5124                 :          0 :                 wr32(hw, TXGBE_RXRP(i), 0);
    5125                 :          0 :                 wr32(hw, TXGBE_RXWP(i), 0);
    5126                 :            : 
    5127                 :            :                 /* Configure the RXCFG register */
    5128         [ #  # ]:          0 :                 srrctl = TXGBE_RXCFG_RNGLEN(rxq->nb_rx_desc);
    5129                 :            : 
    5130                 :            :                 /* Set if packets are dropped when no descriptors available */
    5131         [ #  # ]:          0 :                 if (rxq->drop_en)
    5132                 :          0 :                         srrctl |= TXGBE_RXCFG_DROP;
    5133                 :            : 
    5134                 :            :                 /*
    5135                 :            :                  * Configure the RX buffer size in the PKTLEN field of
    5136                 :            :                  * the RXCFG register of the queue.
    5137                 :            :                  * The value is in 1 KB resolution. Valid values can be from
    5138                 :            :                  * 1 KB to 16 KB.
    5139                 :            :                  */
    5140         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
    5141                 :            :                         RTE_PKTMBUF_HEADROOM);
    5142                 :          0 :                 buf_size = ROUND_UP(buf_size, 1 << 10);
    5143         [ #  # ]:          0 :                 srrctl |= TXGBE_RXCFG_PKTLEN(buf_size);
    5144                 :            : 
    5145                 :            :                 /*
    5146                 :            :                  * VF modification to write virtual function RXCFG register
    5147                 :            :                  */
    5148                 :          0 :                 wr32(hw, TXGBE_RXCFG(i), srrctl);
    5149                 :            : 
    5150         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
    5151                 :            :                     /* It adds dual VLAN length for supporting dual VLAN */
    5152                 :          0 :                     (dev->data->mtu + TXGBE_ETH_OVERHEAD +
    5153         [ #  # ]:          0 :                                 2 * RTE_VLAN_HLEN) > buf_size) {
    5154         [ #  # ]:          0 :                         if (!dev->data->scattered_rx)
    5155                 :          0 :                                 PMD_INIT_LOG(DEBUG, "forcing scatter mode");
    5156                 :          0 :                         dev->data->scattered_rx = 1;
    5157                 :            :                 }
    5158                 :            : 
    5159         [ #  # ]:          0 :                 if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    5160                 :          0 :                         rxmode->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    5161                 :            :         }
    5162                 :            : 
    5163                 :            :         /*
    5164                 :            :          * Device configured with multiple RX queues.
    5165                 :            :          */
    5166                 :          0 :         txgbe_dev_mq_rx_configure(dev);
    5167                 :            : 
    5168                 :          0 :         txgbe_set_rx_function(dev);
    5169                 :            : 
    5170                 :          0 :         return 0;
    5171                 :            : }
    5172                 :            : 
    5173                 :            : /*
    5174                 :            :  * [VF] Initializes Transmit Unit.
    5175                 :            :  */
    5176                 :            : void __rte_cold
    5177                 :          0 : txgbevf_dev_tx_init(struct rte_eth_dev *dev)
    5178                 :            : {
    5179                 :            :         struct txgbe_hw     *hw;
    5180                 :            :         struct txgbe_tx_queue *txq;
    5181                 :            :         uint64_t bus_addr;
    5182                 :            :         uint16_t i;
    5183                 :            : 
    5184                 :          0 :         PMD_INIT_FUNC_TRACE();
    5185                 :          0 :         hw = TXGBE_DEV_HW(dev);
    5186                 :            : 
    5187                 :            :         /* Setup the Base and Length of the Tx Descriptor Rings */
    5188         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    5189                 :          0 :                 txq = dev->data->tx_queues[i];
    5190                 :          0 :                 bus_addr = txq->tx_ring_phys_addr;
    5191                 :          0 :                 wr32(hw, TXGBE_TXBAL(i),
    5192                 :            :                                 (uint32_t)(bus_addr & BIT_MASK32));
    5193                 :          0 :                 wr32(hw, TXGBE_TXBAH(i),
    5194                 :          0 :                                 (uint32_t)(bus_addr >> 32));
    5195                 :          0 :                 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_BUFLEN_MASK,
    5196         [ #  # ]:          0 :                         TXGBE_TXCFG_BUFLEN(txq->nb_tx_desc));
    5197                 :            :                 /* Setup the HW Tx Head and TX Tail descriptor pointers */
    5198                 :          0 :                 wr32(hw, TXGBE_TXRP(i), 0);
    5199                 :          0 :                 wr32(hw, TXGBE_TXWP(i), 0);
    5200                 :            :         }
    5201                 :          0 : }
    5202                 :            : 
    5203                 :            : /*
    5204                 :            :  * [VF] Start Transmit and Receive Units.
    5205                 :            :  */
    5206                 :            : void __rte_cold
    5207                 :          0 : txgbevf_dev_rxtx_start(struct rte_eth_dev *dev)
    5208                 :            : {
    5209                 :            :         struct txgbe_hw     *hw;
    5210                 :            :         struct txgbe_tx_queue *txq;
    5211                 :            :         struct txgbe_rx_queue *rxq;
    5212                 :            :         uint32_t txdctl;
    5213                 :            :         uint32_t rxdctl;
    5214                 :            :         uint16_t i;
    5215                 :            :         int poll_ms;
    5216                 :            : 
    5217                 :          0 :         PMD_INIT_FUNC_TRACE();
    5218                 :          0 :         hw = TXGBE_DEV_HW(dev);
    5219                 :            : 
    5220         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    5221                 :          0 :                 txq = dev->data->tx_queues[i];
    5222                 :            :                 /* Setup Transmit Threshold Registers */
    5223                 :          0 :                 wr32m(hw, TXGBE_TXCFG(txq->reg_idx),
    5224                 :            :                       TXGBE_TXCFG_HTHRESH_MASK |
    5225                 :            :                       TXGBE_TXCFG_WTHRESH_MASK,
    5226                 :          0 :                       TXGBE_TXCFG_HTHRESH(txq->hthresh) |
    5227                 :          0 :                       TXGBE_TXCFG_WTHRESH(txq->wthresh));
    5228                 :            :         }
    5229                 :            : 
    5230         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    5231                 :          0 :                 wr32m(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_ENA, TXGBE_TXCFG_ENA);
    5232                 :            : 
    5233                 :            :                 poll_ms = 10;
    5234                 :            :                 /* Wait until TX Enable ready */
    5235                 :            :                 do {
    5236                 :            :                         rte_delay_ms(1);
    5237                 :            :                         txdctl = rd32(hw, TXGBE_TXCFG(i));
    5238   [ #  #  #  # ]:          0 :                 } while (--poll_ms && !(txdctl & TXGBE_TXCFG_ENA));
    5239         [ #  # ]:          0 :                 if (!poll_ms)
    5240                 :          0 :                         PMD_INIT_LOG(ERR, "Could not enable Tx Queue %d", i);
    5241                 :            :                 else
    5242                 :          0 :                         dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    5243                 :            :         }
    5244         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    5245                 :          0 :                 rxq = dev->data->rx_queues[i];
    5246                 :            : 
    5247                 :          0 :                 wr32m(hw, TXGBE_RXCFG(i), TXGBE_RXCFG_ENA, TXGBE_RXCFG_ENA);
    5248                 :            : 
    5249                 :            :                 /* Wait until RX Enable ready */
    5250                 :            :                 poll_ms = 10;
    5251                 :            :                 do {
    5252                 :            :                         rte_delay_ms(1);
    5253                 :            :                         rxdctl = rd32(hw, TXGBE_RXCFG(i));
    5254   [ #  #  #  # ]:          0 :                 } while (--poll_ms && !(rxdctl & TXGBE_RXCFG_ENA));
    5255         [ #  # ]:          0 :                 if (!poll_ms)
    5256                 :          0 :                         PMD_INIT_LOG(ERR, "Could not enable Rx Queue %d", i);
    5257                 :            :                 else
    5258                 :          0 :                         dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    5259                 :            :                 rte_wmb();
    5260                 :          0 :                 wr32(hw, TXGBE_RXWP(i), rxq->nb_rx_desc - 1);
    5261                 :            :         }
    5262                 :          0 : }
    5263                 :            : 
    5264                 :            : int
    5265                 :          0 : txgbe_rss_conf_init(struct txgbe_rte_flow_rss_conf *out,
    5266                 :            :                     const struct rte_flow_action_rss *in)
    5267                 :            : {
    5268         [ #  # ]:          0 :         if (in->key_len > RTE_DIM(out->key) ||
    5269         [ #  # ]:          0 :             in->queue_num > RTE_DIM(out->queue))
    5270                 :            :                 return -EINVAL;
    5271                 :          0 :         out->conf = (struct rte_flow_action_rss){
    5272                 :          0 :                 .func = in->func,
    5273                 :          0 :                 .level = in->level,
    5274                 :          0 :                 .types = in->types,
    5275                 :            :                 .key_len = in->key_len,
    5276                 :            :                 .queue_num = in->queue_num,
    5277                 :          0 :                 .key = memcpy(out->key, in->key, in->key_len),
    5278                 :          0 :                 .queue = memcpy(out->queue, in->queue,
    5279                 :          0 :                                 sizeof(*in->queue) * in->queue_num),
    5280                 :            :         };
    5281                 :          0 :         return 0;
    5282                 :            : }
    5283                 :            : 
    5284                 :            : int
    5285                 :          0 : txgbe_action_rss_same(const struct rte_flow_action_rss *comp,
    5286                 :            :                       const struct rte_flow_action_rss *with)
    5287                 :            : {
    5288                 :          0 :         return (comp->func == with->func &&
    5289                 :          0 :                 comp->level == with->level &&
    5290         [ #  # ]:          0 :                 comp->types == with->types &&
    5291         [ #  # ]:          0 :                 comp->key_len == with->key_len &&
    5292                 :          0 :                 comp->queue_num == with->queue_num &&
    5293   [ #  #  #  # ]:          0 :                 !memcmp(comp->key, with->key, with->key_len) &&
    5294                 :          0 :                 !memcmp(comp->queue, with->queue,
    5295         [ #  # ]:          0 :                         sizeof(*with->queue) * with->queue_num));
    5296                 :            : }
    5297                 :            : 
    5298                 :            : int
    5299                 :          0 : txgbe_config_rss_filter(struct rte_eth_dev *dev,
    5300                 :            :                 struct txgbe_rte_flow_rss_conf *conf, bool add)
    5301                 :            : {
    5302                 :            :         struct txgbe_hw *hw;
    5303                 :            :         uint32_t reta;
    5304                 :            :         uint16_t i;
    5305                 :            :         uint16_t j;
    5306                 :            :         uint16_t queue;
    5307                 :          0 :         struct rte_eth_rss_conf rss_conf = {
    5308                 :          0 :                 .rss_key = conf->conf.key_len ?
    5309         [ #  # ]:          0 :                         (void *)(uintptr_t)conf->conf.key : NULL,
    5310                 :            :                 .rss_key_len = conf->conf.key_len,
    5311                 :          0 :                 .rss_hf = conf->conf.types,
    5312                 :            :         };
    5313                 :          0 :         struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
    5314                 :            : 
    5315                 :          0 :         PMD_INIT_FUNC_TRACE();
    5316                 :          0 :         hw = TXGBE_DEV_HW(dev);
    5317                 :            : 
    5318         [ #  # ]:          0 :         if (!add) {
    5319         [ #  # ]:          0 :                 if (txgbe_action_rss_same(&filter_info->rss_info.conf,
    5320                 :          0 :                                           &conf->conf)) {
    5321                 :          0 :                         txgbe_rss_disable(dev);
    5322                 :          0 :                         memset(&filter_info->rss_info, 0,
    5323                 :            :                                 sizeof(struct txgbe_rte_flow_rss_conf));
    5324                 :          0 :                         return 0;
    5325                 :            :                 }
    5326                 :            :                 return -EINVAL;
    5327                 :            :         }
    5328                 :            : 
    5329         [ #  # ]:          0 :         if (filter_info->rss_info.conf.queue_num)
    5330                 :            :                 return -EINVAL;
    5331                 :            :         /* Fill in redirection table
    5332                 :            :          * The byte-swap is needed because NIC registers are in
    5333                 :            :          * little-endian order.
    5334                 :            :          */
    5335                 :            :         reta = 0;
    5336         [ #  # ]:          0 :         for (i = 0, j = 0; i < RTE_ETH_RSS_RETA_SIZE_128; i++, j++) {
    5337         [ #  # ]:          0 :                 if (j == conf->conf.queue_num)
    5338                 :            :                         j = 0;
    5339         [ #  # ]:          0 :                 if (RTE_ETH_DEV_SRIOV(dev).active)
    5340                 :          0 :                         queue = RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx +
    5341                 :          0 :                                 conf->conf.queue[j];
    5342                 :            :                 else
    5343                 :          0 :                         queue = conf->conf.queue[j];
    5344                 :          0 :                 reta = (reta >> 8) | LS32(queue, 24, 0xFF);
    5345         [ #  # ]:          0 :                 if ((i & 3) == 3)
    5346                 :          0 :                         wr32at(hw, TXGBE_REG_RSSTBL, i >> 2, reta);
    5347                 :            :         }
    5348                 :            : 
    5349                 :            :         /* Configure the RSS key and the RSS protocols used to compute
    5350                 :            :          * the RSS hash of input packets.
    5351                 :            :          */
    5352         [ #  # ]:          0 :         if ((rss_conf.rss_hf & TXGBE_RSS_OFFLOAD_ALL) == 0) {
    5353                 :          0 :                 txgbe_rss_disable(dev);
    5354                 :          0 :                 return 0;
    5355                 :            :         }
    5356         [ #  # ]:          0 :         if (rss_conf.rss_key == NULL)
    5357                 :          0 :                 rss_conf.rss_key = rss_intel_key; /* Default hash key */
    5358                 :          0 :         txgbe_dev_rss_hash_update(dev, &rss_conf);
    5359                 :            : 
    5360         [ #  # ]:          0 :         if (txgbe_rss_conf_init(&filter_info->rss_info, &conf->conf))
    5361                 :          0 :                 return -EINVAL;
    5362                 :            : 
    5363                 :            :         return 0;
    5364                 :            : }
    5365                 :            : 
    5366                 :            : /* Stubs needed for linkage when RTE_ARCH_PPC_64, RTE_ARCH_RISCV or
    5367                 :            :  * RTE_ARCH_LOONGARCH is set.
    5368                 :            :  */
    5369                 :            : #if defined(RTE_ARCH_PPC_64) || defined(RTE_ARCH_RISCV) || \
    5370                 :            :         defined(RTE_ARCH_LOONGARCH)
    5371                 :            : int
    5372                 :            : txgbe_rx_vec_dev_conf_condition_check(__rte_unused struct rte_eth_dev *dev)
    5373                 :            : {
    5374                 :            :         return -1;
    5375                 :            : }
    5376                 :            : 
    5377                 :            : uint16_t
    5378                 :            : txgbe_recv_pkts_vec(__rte_unused void *rx_queue,
    5379                 :            :                     __rte_unused struct rte_mbuf **rx_pkts,
    5380                 :            :                     __rte_unused uint16_t nb_pkts)
    5381                 :            : {
    5382                 :            :         return 0;
    5383                 :            : }
    5384                 :            : 
    5385                 :            : uint16_t
    5386                 :            : txgbe_recv_scattered_pkts_vec(__rte_unused void *rx_queue,
    5387                 :            :                               __rte_unused struct rte_mbuf **rx_pkts,
    5388                 :            :                               __rte_unused uint16_t nb_pkts)
    5389                 :            : {
    5390                 :            :         return 0;
    5391                 :            : }
    5392                 :            : 
    5393                 :            : int
    5394                 :            : txgbe_rxq_vec_setup(__rte_unused struct txgbe_rx_queue *rxq)
    5395                 :            : {
    5396                 :            :         return -1;
    5397                 :            : }
    5398                 :            : 
    5399                 :            : uint16_t
    5400                 :            : txgbe_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
    5401                 :            :                            __rte_unused struct rte_mbuf **tx_pkts,
    5402                 :            :                            __rte_unused uint16_t nb_pkts)
    5403                 :            : {
    5404                 :            :         return 0;
    5405                 :            : }
    5406                 :            : 
    5407                 :            : int
    5408                 :            : txgbe_txq_vec_setup(__rte_unused struct txgbe_tx_queue *txq)
    5409                 :            : {
    5410                 :            :         return -1;
    5411                 :            : }
    5412                 :            : 
    5413                 :            : void
    5414                 :            : txgbe_rx_queue_release_mbufs_vec(__rte_unused struct txgbe_rx_queue *rxq)
    5415                 :            : {
    5416                 :            : }
    5417                 :            : #endif

Generated by: LCOV version 1.14