LCOV - code coverage report
Current view: top level - drivers/net/i40e - i40e_rxtx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1447 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 65 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 868 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2016 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <stdlib.h>
       7                 :            : #include <string.h>
       8                 :            : #include <errno.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <stdarg.h>
      11                 :            : #include <unistd.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <sys/queue.h>
      14                 :            : 
      15                 :            : #include <rte_string_fns.h>
      16                 :            : #include <rte_memzone.h>
      17                 :            : #include <rte_mbuf.h>
      18                 :            : #include <rte_malloc.h>
      19                 :            : #include <rte_ether.h>
      20                 :            : #include <ethdev_driver.h>
      21                 :            : #include <rte_tcp.h>
      22                 :            : #include <rte_sctp.h>
      23                 :            : #include <rte_udp.h>
      24                 :            : #include <rte_ip.h>
      25                 :            : #include <rte_net.h>
      26                 :            : #include <rte_vect.h>
      27                 :            : 
      28                 :            : #include "i40e_logs.h"
      29                 :            : #include "base/i40e_prototype.h"
      30                 :            : #include "base/i40e_type.h"
      31                 :            : #include "i40e_ethdev.h"
      32                 :            : #include "i40e_rxtx.h"
      33                 :            : 
      34                 :            : #define DEFAULT_TX_RS_THRESH   32
      35                 :            : #define DEFAULT_TX_FREE_THRESH 32
      36                 :            : 
      37                 :            : #define I40E_TX_MAX_BURST  32
      38                 :            : 
      39                 :            : #define I40E_DMA_MEM_ALIGN 4096
      40                 :            : 
      41                 :            : /* Base address of the HW descriptor ring should be 128B aligned. */
      42                 :            : #define I40E_RING_BASE_ALIGN    128
      43                 :            : 
      44                 :            : #define I40E_TXD_CMD (I40E_TX_DESC_CMD_EOP | I40E_TX_DESC_CMD_RS)
      45                 :            : 
      46                 :            : #ifdef RTE_LIBRTE_IEEE1588
      47                 :            : #define I40E_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
      48                 :            : #else
      49                 :            : #define I40E_TX_IEEE1588_TMST 0
      50                 :            : #endif
      51                 :            : 
      52                 :            : #define I40E_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_IP_CKSUM |             \
      53                 :            :                 RTE_MBUF_F_TX_L4_MASK |          \
      54                 :            :                 RTE_MBUF_F_TX_TCP_SEG |          \
      55                 :            :                 RTE_MBUF_F_TX_OUTER_IP_CKSUM)
      56                 :            : 
      57                 :            : #define I40E_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV4 |        \
      58                 :            :                 RTE_MBUF_F_TX_OUTER_IPV6 |      \
      59                 :            :                 RTE_MBUF_F_TX_IPV4 |            \
      60                 :            :                 RTE_MBUF_F_TX_IPV6 |            \
      61                 :            :                 RTE_MBUF_F_TX_IP_CKSUM |       \
      62                 :            :                 RTE_MBUF_F_TX_L4_MASK |        \
      63                 :            :                 RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
      64                 :            :                 RTE_MBUF_F_TX_TCP_SEG |        \
      65                 :            :                 RTE_MBUF_F_TX_QINQ |       \
      66                 :            :                 RTE_MBUF_F_TX_VLAN |    \
      67                 :            :                 RTE_MBUF_F_TX_TUNNEL_MASK |     \
      68                 :            :                 RTE_MBUF_F_TX_OUTER_UDP_CKSUM | \
      69                 :            :                 I40E_TX_IEEE1588_TMST)
      70                 :            : 
      71                 :            : #define I40E_TX_OFFLOAD_NOTSUP_MASK \
      72                 :            :                 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_MASK)
      73                 :            : 
      74                 :            : #define I40E_TX_OFFLOAD_SIMPLE_SUP_MASK (RTE_MBUF_F_TX_IPV4 | \
      75                 :            :                 RTE_MBUF_F_TX_IPV6 | \
      76                 :            :                 RTE_MBUF_F_TX_OUTER_IPV4 | \
      77                 :            :                 RTE_MBUF_F_TX_OUTER_IPV6)
      78                 :            : 
      79                 :            : #define I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK \
      80                 :            :                 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ I40E_TX_OFFLOAD_SIMPLE_SUP_MASK)
      81                 :            : 
      82                 :            : static int
      83                 :          0 : i40e_monitor_callback(const uint64_t value,
      84                 :            :                 const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
      85                 :            : {
      86                 :            :         const uint64_t m = rte_cpu_to_le_64(1 << I40E_RX_DESC_STATUS_DD_SHIFT);
      87                 :            :         /*
      88                 :            :          * we expect the DD bit to be set to 1 if this descriptor was already
      89                 :            :          * written to.
      90                 :            :          */
      91         [ #  # ]:          0 :         return (value & m) == m ? -1 : 0;
      92                 :            : }
      93                 :            : 
      94                 :            : int
      95                 :          0 : i40e_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
      96                 :            : {
      97                 :            :         struct i40e_rx_queue *rxq = rx_queue;
      98                 :            :         volatile union i40e_rx_desc *rxdp;
      99                 :            :         uint16_t desc;
     100                 :            : 
     101                 :          0 :         desc = rxq->rx_tail;
     102                 :          0 :         rxdp = &rxq->rx_ring[desc];
     103                 :            :         /* watch for changes in status bit */
     104                 :          0 :         pmc->addr = &rxdp->wb.qword1.status_error_len;
     105                 :            : 
     106                 :            :         /* comparison callback */
     107                 :          0 :         pmc->fn = i40e_monitor_callback;
     108                 :            : 
     109                 :            :         /* registers are 64-bit */
     110                 :          0 :         pmc->size = sizeof(uint64_t);
     111                 :            : 
     112                 :          0 :         return 0;
     113                 :            : }
     114                 :            : 
     115                 :            : static inline void
     116                 :            : i40e_rxd_to_vlan_tci(struct rte_mbuf *mb, volatile union i40e_rx_desc *rxdp)
     117                 :            : {
     118                 :          0 :         if (rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
     119                 :            :                 (1 << I40E_RX_DESC_STATUS_L2TAG1P_SHIFT)) {
     120                 :          0 :                 mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
     121                 :          0 :                 mb->vlan_tci =
     122                 :          0 :                         rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1);
     123                 :            :                 PMD_RX_LOG(DEBUG, "Descriptor l2tag1: %u",
     124                 :            :                            rte_le_to_cpu_16(rxdp->wb.qword0.lo_dword.l2tag1));
     125                 :            :         } else {
     126                 :          0 :                 mb->vlan_tci = 0;
     127                 :            :         }
     128                 :            : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
     129   [ #  #  #  #  :          0 :         if (rte_le_to_cpu_16(rxdp->wb.qword2.ext_status) &
                   #  # ]
     130                 :            :                 (1 << I40E_RX_DESC_EXT_STATUS_L2TAG2P_SHIFT)) {
     131                 :          0 :                 mb->ol_flags |= RTE_MBUF_F_RX_QINQ_STRIPPED | RTE_MBUF_F_RX_QINQ |
     132                 :            :                         RTE_MBUF_F_RX_VLAN_STRIPPED | RTE_MBUF_F_RX_VLAN;
     133                 :          0 :                 mb->vlan_tci_outer = mb->vlan_tci;
     134                 :          0 :                 mb->vlan_tci = rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2);
     135                 :            :                 PMD_RX_LOG(DEBUG, "Descriptor l2tag2_1: %u, l2tag2_2: %u",
     136                 :            :                            rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_1),
     137                 :            :                            rte_le_to_cpu_16(rxdp->wb.qword2.l2tag2_2));
     138                 :            :         } else {
     139                 :          0 :                 mb->vlan_tci_outer = 0;
     140                 :            :         }
     141                 :            : #endif
     142                 :            :         PMD_RX_LOG(DEBUG, "Mbuf vlan_tci: %u, vlan_tci_outer: %u",
     143                 :            :                    mb->vlan_tci, mb->vlan_tci_outer);
     144                 :            : }
     145                 :            : 
     146                 :            : /* Translate the rx descriptor status to pkt flags */
     147                 :            : static inline uint64_t
     148                 :            : i40e_rxd_status_to_pkt_flags(uint64_t qword)
     149                 :            : {
     150                 :            :         uint64_t flags;
     151                 :            : 
     152                 :            :         /* Check if RSS_HASH */
     153                 :          0 :         flags = (((qword >> I40E_RX_DESC_STATUS_FLTSTAT_SHIFT) &
     154                 :            :                                         I40E_RX_DESC_FLTSTAT_RSS_HASH) ==
     155   [ #  #  #  #  :          0 :                         I40E_RX_DESC_FLTSTAT_RSS_HASH) ? RTE_MBUF_F_RX_RSS_HASH : 0;
                   #  # ]
     156                 :            : 
     157                 :            :         /* Check if FDIR Match */
     158                 :          0 :         flags |= (qword & (1 << I40E_RX_DESC_STATUS_FLM_SHIFT) ?
     159                 :          0 :                                                         RTE_MBUF_F_RX_FDIR : 0);
     160                 :            : 
     161                 :            :         return flags;
     162                 :            : }
     163                 :            : 
     164                 :            : static inline uint64_t
     165                 :            : i40e_rxd_error_to_pkt_flags(uint64_t qword)
     166                 :            : {
     167                 :            :         uint64_t flags = 0;
     168                 :          0 :         uint64_t error_bits = (qword >> I40E_RXD_QW1_ERROR_SHIFT);
     169                 :            : 
     170                 :            : #define I40E_RX_ERR_BITS 0x3f
     171   [ #  #  #  #  :          0 :         if (likely((error_bits & I40E_RX_ERR_BITS) == 0)) {
                   #  # ]
     172                 :            :                 flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
     173                 :            :                 return flags;
     174                 :            :         }
     175                 :            : 
     176   [ #  #  #  #  :          0 :         if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_IPE_SHIFT)))
                   #  # ]
     177                 :            :                 flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
     178                 :            :         else
     179                 :            :                 flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
     180                 :            : 
     181   [ #  #  #  #  :          0 :         if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_L4E_SHIFT)))
                   #  # ]
     182                 :          0 :                 flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
     183                 :            :         else
     184                 :          0 :                 flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
     185                 :            : 
     186   [ #  #  #  #  :          0 :         if (unlikely(error_bits & (1 << I40E_RX_DESC_ERROR_EIPE_SHIFT)))
                   #  # ]
     187                 :          0 :                 flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
     188                 :            : 
     189                 :            :         return flags;
     190                 :            : }
     191                 :            : 
     192                 :            : /* Function to check and set the ieee1588 timesync index and get the
     193                 :            :  * appropriate flags.
     194                 :            :  */
     195                 :            : #ifdef RTE_LIBRTE_IEEE1588
     196                 :            : static inline uint64_t
     197                 :            : i40e_get_iee15888_flags(struct rte_mbuf *mb, uint64_t qword)
     198                 :            : {
     199                 :            :         uint64_t pkt_flags = 0;
     200                 :            :         uint16_t tsyn = (qword & (I40E_RXD_QW1_STATUS_TSYNVALID_MASK
     201                 :            :                                   | I40E_RXD_QW1_STATUS_TSYNINDX_MASK))
     202                 :            :                                     >> I40E_RX_DESC_STATUS_TSYNINDX_SHIFT;
     203                 :            : 
     204                 :            :         if ((mb->packet_type & RTE_PTYPE_L2_MASK)
     205                 :            :                         == RTE_PTYPE_L2_ETHER_TIMESYNC)
     206                 :            :                 pkt_flags = RTE_MBUF_F_RX_IEEE1588_PTP;
     207                 :            :         if (tsyn & 0x04) {
     208                 :            :                 pkt_flags |= RTE_MBUF_F_RX_IEEE1588_TMST;
     209                 :            :                 mb->timesync = tsyn & 0x03;
     210                 :            :         }
     211                 :            : 
     212                 :            :         return pkt_flags;
     213                 :            : }
     214                 :            : #endif
     215                 :            : 
     216                 :            : static inline uint64_t
     217                 :            : i40e_rxd_build_fdir(volatile union i40e_rx_desc *rxdp, struct rte_mbuf *mb)
     218                 :            : {
     219                 :            :         uint64_t flags = 0;
     220                 :            : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
     221                 :            :         uint16_t flexbh, flexbl;
     222                 :            : 
     223                 :          0 :         flexbh = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
     224                 :          0 :                 I40E_RX_DESC_EXT_STATUS_FLEXBH_SHIFT) &
     225                 :            :                 I40E_RX_DESC_EXT_STATUS_FLEXBH_MASK;
     226                 :          0 :         flexbl = (rte_le_to_cpu_32(rxdp->wb.qword2.ext_status) >>
     227                 :          0 :                 I40E_RX_DESC_EXT_STATUS_FLEXBL_SHIFT) &
     228                 :            :                 I40E_RX_DESC_EXT_STATUS_FLEXBL_MASK;
     229                 :            : 
     230                 :            : 
     231   [ #  #  #  #  :          0 :         if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FD_ID) {
                   #  # ]
     232                 :          0 :                 mb->hash.fdir.hi =
     233                 :          0 :                         rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.fd_id);
     234                 :            :                 flags |= RTE_MBUF_F_RX_FDIR_ID;
     235   [ #  #  #  #  :          0 :         } else if (flexbh == I40E_RX_DESC_EXT_STATUS_FLEXBH_FLEX) {
                   #  # ]
     236                 :          0 :                 mb->hash.fdir.hi =
     237                 :          0 :                         rte_le_to_cpu_32(rxdp->wb.qword3.hi_dword.flex_bytes_hi);
     238                 :            :                 flags |= RTE_MBUF_F_RX_FDIR_FLX;
     239                 :            :         }
     240   [ #  #  #  #  :          0 :         if (flexbl == I40E_RX_DESC_EXT_STATUS_FLEXBL_FLEX) {
                   #  # ]
     241                 :          0 :                 mb->hash.fdir.lo =
     242                 :          0 :                         rte_le_to_cpu_32(rxdp->wb.qword3.lo_dword.flex_bytes_lo);
     243                 :          0 :                 flags |= RTE_MBUF_F_RX_FDIR_FLX;
     244                 :            :         }
     245                 :            : #else
     246                 :            :         mb->hash.fdir.hi =
     247                 :            :                 rte_le_to_cpu_32(rxdp->wb.qword0.hi_dword.fd_id);
     248                 :            :         flags |= RTE_MBUF_F_RX_FDIR_ID;
     249                 :            : #endif
     250                 :            :         return flags;
     251                 :            : }
     252                 :            : 
     253                 :            : static inline void
     254                 :          0 : i40e_parse_tunneling_params(uint64_t ol_flags,
     255                 :            :                             union i40e_tx_offload tx_offload,
     256                 :            :                             uint32_t *cd_tunneling)
     257                 :            : {
     258                 :            :         /* EIPT: External (outer) IP header type */
     259         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
     260                 :          0 :                 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4;
     261         [ #  # ]:          0 :         else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4)
     262                 :          0 :                 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV4_NO_CSUM;
     263         [ #  # ]:          0 :         else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6)
     264                 :          0 :                 *cd_tunneling |= I40E_TX_CTX_EXT_IP_IPV6;
     265                 :            : 
     266                 :            :         /* EIPLEN: External (outer) IP header length, in DWords */
     267                 :          0 :         *cd_tunneling |= (tx_offload.outer_l3_len >> 2) <<
     268                 :            :                 I40E_TXD_CTX_QW0_EXT_IPLEN_SHIFT;
     269                 :            : 
     270                 :            :         /* L4TUNT: L4 Tunneling Type */
     271   [ #  #  #  # ]:          0 :         switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
     272                 :            :         case RTE_MBUF_F_TX_TUNNEL_IPIP:
     273                 :            :                 /* for non UDP / GRE tunneling, set to 00b */
     274                 :            :                 break;
     275                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_VXLAN:
     276                 :            :         case RTE_MBUF_F_TX_TUNNEL_GENEVE:
     277                 :          0 :                 *cd_tunneling |= I40E_TXD_CTX_UDP_TUNNELING;
     278                 :          0 :                 break;
     279                 :          0 :         case RTE_MBUF_F_TX_TUNNEL_GRE:
     280                 :          0 :                 *cd_tunneling |= I40E_TXD_CTX_GRE_TUNNELING;
     281                 :          0 :                 break;
     282                 :            :         default:
     283                 :            :                 PMD_TX_LOG(ERR, "Tunnel type not supported");
     284                 :            :                 return;
     285                 :            :         }
     286                 :            : 
     287                 :            :         /* L4TUNLEN: L4 Tunneling Length, in Words
     288                 :            :          *
     289                 :            :          * We depend on app to set rte_mbuf.l2_len correctly.
     290                 :            :          * For IP in GRE it should be set to the length of the GRE
     291                 :            :          * header;
     292                 :            :          * for MAC in GRE or MAC in UDP it should be set to the length
     293                 :            :          * of the GRE or UDP headers plus the inner MAC up to including
     294                 :            :          * its last Ethertype.
     295                 :            :          */
     296                 :          0 :         *cd_tunneling |= (tx_offload.l2_len >> 1) <<
     297                 :            :                 I40E_TXD_CTX_QW0_NATLEN_SHIFT;
     298                 :            : }
     299                 :            : 
     300                 :            : static inline void
     301                 :          0 : i40e_txd_enable_checksum(uint64_t ol_flags,
     302                 :            :                         uint32_t *td_cmd,
     303                 :            :                         uint32_t *td_offset,
     304                 :            :                         union i40e_tx_offload tx_offload)
     305                 :            : {
     306                 :            :         /* Set MACLEN */
     307         [ #  # ]:          0 :         if (!(ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK))
     308                 :          0 :                 *td_offset |= (tx_offload.l2_len >> 1)
     309                 :          0 :                         << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
     310                 :            : 
     311                 :            :         /* Enable L3 checksum offloads */
     312         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM) {
     313                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4_CSUM;
     314                 :          0 :                 *td_offset |= (tx_offload.l3_len >> 2)
     315                 :          0 :                                 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
     316         [ #  # ]:          0 :         } else if (ol_flags & RTE_MBUF_F_TX_IPV4) {
     317                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV4;
     318                 :          0 :                 *td_offset |= (tx_offload.l3_len >> 2)
     319                 :          0 :                                 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
     320         [ #  # ]:          0 :         } else if (ol_flags & RTE_MBUF_F_TX_IPV6) {
     321                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_IIPT_IPV6;
     322                 :          0 :                 *td_offset |= (tx_offload.l3_len >> 2)
     323                 :          0 :                                 << I40E_TX_DESC_LENGTH_IPLEN_SHIFT;
     324                 :            :         }
     325                 :            : 
     326         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
     327                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
     328                 :          0 :                 *td_offset |= (tx_offload.l4_len >> 2)
     329                 :          0 :                         << I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
     330                 :          0 :                 return;
     331                 :            :         }
     332                 :            : 
     333                 :            :         /* Enable L4 checksum offloads */
     334   [ #  #  #  # ]:          0 :         switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
     335                 :          0 :         case RTE_MBUF_F_TX_TCP_CKSUM:
     336                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_TCP;
     337                 :          0 :                 *td_offset |= (sizeof(struct rte_tcp_hdr) >> 2) <<
     338                 :            :                                 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
     339                 :          0 :                 break;
     340                 :          0 :         case RTE_MBUF_F_TX_SCTP_CKSUM:
     341                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_SCTP;
     342                 :          0 :                 *td_offset |= (sizeof(struct rte_sctp_hdr) >> 2) <<
     343                 :            :                                 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
     344                 :          0 :                 break;
     345                 :          0 :         case RTE_MBUF_F_TX_UDP_CKSUM:
     346                 :          0 :                 *td_cmd |= I40E_TX_DESC_CMD_L4T_EOFT_UDP;
     347                 :          0 :                 *td_offset |= (sizeof(struct rte_udp_hdr) >> 2) <<
     348                 :            :                                 I40E_TX_DESC_LENGTH_L4_FC_LEN_SHIFT;
     349                 :          0 :                 break;
     350                 :            :         default:
     351                 :            :                 break;
     352                 :            :         }
     353                 :            : }
     354                 :            : 
     355                 :            : /* Construct the tx flags */
     356                 :            : static inline uint64_t
     357                 :            : i40e_build_ctob(uint32_t td_cmd,
     358                 :            :                 uint32_t td_offset,
     359                 :            :                 unsigned int size,
     360                 :            :                 uint32_t td_tag)
     361                 :            : {
     362                 :          0 :         return rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DATA |
     363                 :            :                         ((uint64_t)td_cmd  << I40E_TXD_QW1_CMD_SHIFT) |
     364                 :            :                         ((uint64_t)td_offset << I40E_TXD_QW1_OFFSET_SHIFT) |
     365                 :            :                         ((uint64_t)size  << I40E_TXD_QW1_TX_BUF_SZ_SHIFT) |
     366                 :            :                         ((uint64_t)td_tag  << I40E_TXD_QW1_L2TAG1_SHIFT));
     367                 :            : }
     368                 :            : 
     369                 :            : static inline int
     370                 :          0 : i40e_xmit_cleanup(struct i40e_tx_queue *txq)
     371                 :            : {
     372                 :          0 :         struct i40e_tx_entry *sw_ring = txq->sw_ring;
     373                 :          0 :         volatile struct i40e_tx_desc *txd = txq->tx_ring;
     374                 :          0 :         uint16_t last_desc_cleaned = txq->last_desc_cleaned;
     375                 :          0 :         uint16_t nb_tx_desc = txq->nb_tx_desc;
     376                 :            :         uint16_t desc_to_clean_to;
     377                 :            :         uint16_t nb_tx_to_clean;
     378                 :            : 
     379                 :          0 :         desc_to_clean_to = (uint16_t)(last_desc_cleaned + txq->tx_rs_thresh);
     380         [ #  # ]:          0 :         if (desc_to_clean_to >= nb_tx_desc)
     381                 :          0 :                 desc_to_clean_to = (uint16_t)(desc_to_clean_to - nb_tx_desc);
     382                 :            : 
     383                 :          0 :         desc_to_clean_to = sw_ring[desc_to_clean_to].last_id;
     384         [ #  # ]:          0 :         if ((txd[desc_to_clean_to].cmd_type_offset_bsz &
     385                 :            :                         rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
     386                 :            :                         rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE)) {
     387                 :            :                 PMD_TX_LOG(DEBUG, "TX descriptor %4u is not done "
     388                 :            :                            "(port=%d queue=%d)", desc_to_clean_to,
     389                 :            :                            txq->port_id, txq->queue_id);
     390                 :            :                 return -1;
     391                 :            :         }
     392                 :            : 
     393         [ #  # ]:          0 :         if (last_desc_cleaned > desc_to_clean_to)
     394                 :          0 :                 nb_tx_to_clean = (uint16_t)((nb_tx_desc - last_desc_cleaned) +
     395                 :            :                                                         desc_to_clean_to);
     396                 :            :         else
     397                 :          0 :                 nb_tx_to_clean = (uint16_t)(desc_to_clean_to -
     398                 :            :                                         last_desc_cleaned);
     399                 :            : 
     400                 :          0 :         txd[desc_to_clean_to].cmd_type_offset_bsz = 0;
     401                 :            : 
     402                 :          0 :         txq->last_desc_cleaned = desc_to_clean_to;
     403                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + nb_tx_to_clean);
     404                 :            : 
     405                 :          0 :         return 0;
     406                 :            : }
     407                 :            : 
     408                 :            : static inline int
     409                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
     410                 :          0 : check_rx_burst_bulk_alloc_preconditions(struct i40e_rx_queue *rxq)
     411                 :            : #else
     412                 :            : check_rx_burst_bulk_alloc_preconditions(__rte_unused struct i40e_rx_queue *rxq)
     413                 :            : #endif
     414                 :            : {
     415                 :            :         int ret = 0;
     416                 :            : 
     417                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
     418         [ #  # ]:          0 :         if (!(rxq->rx_free_thresh >= RTE_PMD_I40E_RX_MAX_BURST)) {
     419                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
     420                 :            :                              "rxq->rx_free_thresh=%d, "
     421                 :            :                              "RTE_PMD_I40E_RX_MAX_BURST=%d",
     422                 :            :                              rxq->rx_free_thresh, RTE_PMD_I40E_RX_MAX_BURST);
     423                 :            :                 ret = -EINVAL;
     424         [ #  # ]:          0 :         } else if (!(rxq->rx_free_thresh < rxq->nb_rx_desc)) {
     425                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
     426                 :            :                              "rxq->rx_free_thresh=%d, "
     427                 :            :                              "rxq->nb_rx_desc=%d",
     428                 :            :                              rxq->rx_free_thresh, rxq->nb_rx_desc);
     429                 :            :                 ret = -EINVAL;
     430         [ #  # ]:          0 :         } else if (rxq->nb_rx_desc % rxq->rx_free_thresh != 0) {
     431                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions: "
     432                 :            :                              "rxq->nb_rx_desc=%d, "
     433                 :            :                              "rxq->rx_free_thresh=%d",
     434                 :            :                              rxq->nb_rx_desc, rxq->rx_free_thresh);
     435                 :            :                 ret = -EINVAL;
     436                 :            :         }
     437                 :            : #else
     438                 :            :         ret = -EINVAL;
     439                 :            : #endif
     440                 :            : 
     441                 :          0 :         return ret;
     442                 :            : }
     443                 :            : 
     444                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
     445                 :            : #define I40E_LOOK_AHEAD 8
     446                 :            : #if (I40E_LOOK_AHEAD != 8)
     447                 :            : #error "PMD I40E: I40E_LOOK_AHEAD must be 8\n"
     448                 :            : #endif
     449                 :            : static inline int
     450                 :          0 : i40e_rx_scan_hw_ring(struct i40e_rx_queue *rxq)
     451                 :            : {
     452                 :            :         volatile union i40e_rx_desc *rxdp;
     453                 :            :         struct i40e_rx_entry *rxep;
     454                 :            :         struct rte_mbuf *mb;
     455                 :            :         uint16_t pkt_len;
     456                 :            :         uint64_t qword1;
     457                 :            :         uint32_t rx_status;
     458                 :            :         int32_t s[I40E_LOOK_AHEAD], var, nb_dd;
     459                 :            :         int32_t i, j, nb_rx = 0;
     460                 :            :         uint64_t pkt_flags;
     461                 :          0 :         uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
     462                 :            : 
     463                 :          0 :         rxdp = &rxq->rx_ring[rxq->rx_tail];
     464                 :          0 :         rxep = &rxq->sw_ring[rxq->rx_tail];
     465                 :            : 
     466                 :          0 :         qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
     467                 :          0 :         rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
     468                 :            :                                 I40E_RXD_QW1_STATUS_SHIFT;
     469                 :            : 
     470                 :            :         /* Make sure there is at least 1 packet to receive */
     471         [ #  # ]:          0 :         if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
     472                 :            :                 return 0;
     473                 :            : 
     474                 :            :         /**
     475                 :            :          * Scan LOOK_AHEAD descriptors at a time to determine which
     476                 :            :          * descriptors reference packets that are ready to be received.
     477                 :            :          */
     478         [ #  # ]:          0 :         for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; i+=I40E_LOOK_AHEAD,
     479                 :          0 :                         rxdp += I40E_LOOK_AHEAD, rxep += I40E_LOOK_AHEAD) {
     480                 :            :                 /* Read desc statuses backwards to avoid race condition */
     481         [ #  # ]:          0 :                 for (j = I40E_LOOK_AHEAD - 1; j >= 0; j--) {
     482                 :          0 :                         qword1 = rte_le_to_cpu_64(\
     483                 :            :                                 rxdp[j].wb.qword1.status_error_len);
     484                 :          0 :                         s[j] = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
     485                 :            :                                         I40E_RXD_QW1_STATUS_SHIFT;
     486                 :            :                 }
     487                 :            : 
     488                 :            :                 /* This barrier is to order loads of different words in the descriptor */
     489                 :            :                 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
     490                 :            : 
     491                 :            :                 /* Compute how many status bits were set */
     492         [ #  # ]:          0 :                 for (j = 0, nb_dd = 0; j < I40E_LOOK_AHEAD; j++) {
     493                 :          0 :                         var = s[j] & (1 << I40E_RX_DESC_STATUS_DD_SHIFT);
     494                 :            : #ifdef RTE_ARCH_ARM
     495                 :            :                         /* For Arm platforms, only compute continuous status bits */
     496                 :            :                         if (var)
     497                 :            :                                 nb_dd += 1;
     498                 :            :                         else
     499                 :            :                                 break;
     500                 :            : #else
     501                 :          0 :                         nb_dd += var;
     502                 :            : #endif
     503                 :            :                 }
     504                 :            : 
     505                 :          0 :                 nb_rx += nb_dd;
     506                 :            : 
     507                 :            :                 /* Translate descriptor info to mbuf parameters */
     508         [ #  # ]:          0 :                 for (j = 0; j < nb_dd; j++) {
     509                 :          0 :                         mb = rxep[j].mbuf;
     510                 :          0 :                         qword1 = rte_le_to_cpu_64(\
     511                 :            :                                 rxdp[j].wb.qword1.status_error_len);
     512                 :          0 :                         pkt_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
     513                 :          0 :                                 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
     514                 :          0 :                         mb->data_len = pkt_len;
     515                 :          0 :                         mb->pkt_len = pkt_len;
     516         [ #  # ]:          0 :                         mb->ol_flags = 0;
     517                 :            :                         i40e_rxd_to_vlan_tci(mb, &rxdp[j]);
     518                 :            :                         pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
     519                 :          0 :                         pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
     520                 :          0 :                         mb->packet_type =
     521                 :          0 :                                 ptype_tbl[(uint8_t)((qword1 &
     522                 :          0 :                                 I40E_RXD_QW1_PTYPE_MASK) >>
     523                 :            :                                 I40E_RXD_QW1_PTYPE_SHIFT)];
     524         [ #  # ]:          0 :                         if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
     525                 :          0 :                                 mb->hash.rss = rte_le_to_cpu_32(\
     526                 :            :                                         rxdp[j].wb.qword0.hi_dword.rss);
     527         [ #  # ]:          0 :                         if (pkt_flags & RTE_MBUF_F_RX_FDIR)
     528                 :          0 :                                 pkt_flags |= i40e_rxd_build_fdir(&rxdp[j], mb);
     529                 :            : 
     530                 :            : #ifdef RTE_LIBRTE_IEEE1588
     531                 :            :                         pkt_flags |= i40e_get_iee15888_flags(mb, qword1);
     532                 :            : #endif
     533                 :          0 :                         mb->ol_flags |= pkt_flags;
     534                 :            : 
     535                 :            :                 }
     536                 :            : 
     537         [ #  # ]:          0 :                 for (j = 0; j < I40E_LOOK_AHEAD; j++)
     538                 :          0 :                         rxq->rx_stage[i + j] = rxep[j].mbuf;
     539                 :            : 
     540         [ #  # ]:          0 :                 if (nb_dd != I40E_LOOK_AHEAD)
     541                 :            :                         break;
     542                 :            :         }
     543                 :            : 
     544                 :            :         /* Clear software ring entries */
     545         [ #  # ]:          0 :         for (i = 0; i < nb_rx; i++)
     546                 :          0 :                 rxq->sw_ring[rxq->rx_tail + i].mbuf = NULL;
     547                 :            : 
     548                 :            :         return nb_rx;
     549                 :            : }
     550                 :            : 
     551                 :            : static inline uint16_t
     552                 :            : i40e_rx_fill_from_stage(struct i40e_rx_queue *rxq,
     553                 :            :                         struct rte_mbuf **rx_pkts,
     554                 :            :                         uint16_t nb_pkts)
     555                 :            : {
     556                 :            :         uint16_t i;
     557                 :          0 :         struct rte_mbuf **stage = &rxq->rx_stage[rxq->rx_next_avail];
     558                 :            : 
     559                 :          0 :         nb_pkts = (uint16_t)RTE_MIN(nb_pkts, rxq->rx_nb_avail);
     560                 :            : 
     561   [ #  #  #  # ]:          0 :         for (i = 0; i < nb_pkts; i++)
     562                 :          0 :                 rx_pkts[i] = stage[i];
     563                 :            : 
     564                 :          0 :         rxq->rx_nb_avail = (uint16_t)(rxq->rx_nb_avail - nb_pkts);
     565                 :          0 :         rxq->rx_next_avail = (uint16_t)(rxq->rx_next_avail + nb_pkts);
     566                 :            : 
     567                 :            :         return nb_pkts;
     568                 :            : }
     569                 :            : 
     570                 :            : static inline int
     571                 :          0 : i40e_rx_alloc_bufs(struct i40e_rx_queue *rxq)
     572                 :            : {
     573                 :            :         volatile union i40e_rx_desc *rxdp;
     574                 :            :         struct i40e_rx_entry *rxep;
     575                 :            :         struct rte_mbuf *mb;
     576                 :            :         uint16_t alloc_idx, i;
     577                 :            :         uint64_t dma_addr;
     578                 :            :         int diag;
     579                 :            : 
     580                 :            :         /* Allocate buffers in bulk */
     581                 :          0 :         alloc_idx = (uint16_t)(rxq->rx_free_trigger -
     582                 :          0 :                                 (rxq->rx_free_thresh - 1));
     583                 :          0 :         rxep = &(rxq->sw_ring[alloc_idx]);
     584         [ #  # ]:          0 :         diag = rte_mempool_get_bulk(rxq->mp, (void *)rxep,
     585                 :            :                                         rxq->rx_free_thresh);
     586         [ #  # ]:          0 :         if (unlikely(diag != 0)) {
     587                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to get mbufs in bulk");
     588                 :          0 :                 return -ENOMEM;
     589                 :            :         }
     590                 :            : 
     591                 :          0 :         rxdp = &rxq->rx_ring[alloc_idx];
     592         [ #  # ]:          0 :         for (i = 0; i < rxq->rx_free_thresh; i++) {
     593         [ #  # ]:          0 :                 if (likely(i < (rxq->rx_free_thresh - 1)))
     594                 :            :                         /* Prefetch next mbuf */
     595                 :          0 :                         rte_prefetch0(rxep[i + 1].mbuf);
     596                 :            : 
     597                 :          0 :                 mb = rxep[i].mbuf;
     598                 :            :                 rte_mbuf_refcnt_set(mb, 1);
     599                 :          0 :                 mb->next = NULL;
     600                 :          0 :                 mb->data_off = RTE_PKTMBUF_HEADROOM;
     601                 :          0 :                 mb->nb_segs = 1;
     602                 :          0 :                 mb->port = rxq->port_id;
     603                 :            :                 dma_addr = rte_cpu_to_le_64(\
     604                 :            :                         rte_mbuf_data_iova_default(mb));
     605                 :          0 :                 rxdp[i].read.hdr_addr = 0;
     606                 :          0 :                 rxdp[i].read.pkt_addr = dma_addr;
     607                 :            :         }
     608                 :            : 
     609                 :            :         /* Update rx tail register */
     610                 :          0 :         I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->rx_free_trigger);
     611                 :            : 
     612                 :          0 :         rxq->rx_free_trigger =
     613                 :          0 :                 (uint16_t)(rxq->rx_free_trigger + rxq->rx_free_thresh);
     614         [ #  # ]:          0 :         if (rxq->rx_free_trigger >= rxq->nb_rx_desc)
     615                 :          0 :                 rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
     616                 :            : 
     617                 :            :         return 0;
     618                 :            : }
     619                 :            : 
     620                 :            : static inline uint16_t
     621                 :          0 : rx_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
     622                 :            : {
     623                 :            :         struct i40e_rx_queue *rxq = (struct i40e_rx_queue *)rx_queue;
     624                 :            :         struct rte_eth_dev *dev;
     625                 :            :         uint16_t nb_rx = 0;
     626                 :            : 
     627         [ #  # ]:          0 :         if (!nb_pkts)
     628                 :            :                 return 0;
     629                 :            : 
     630         [ #  # ]:          0 :         if (rxq->rx_nb_avail)
     631                 :          0 :                 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
     632                 :            : 
     633                 :          0 :         nb_rx = (uint16_t)i40e_rx_scan_hw_ring(rxq);
     634                 :          0 :         rxq->rx_next_avail = 0;
     635                 :          0 :         rxq->rx_nb_avail = nb_rx;
     636                 :          0 :         rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_rx);
     637                 :            : 
     638         [ #  # ]:          0 :         if (rxq->rx_tail > rxq->rx_free_trigger) {
     639         [ #  # ]:          0 :                 if (i40e_rx_alloc_bufs(rxq) != 0) {
     640                 :            :                         uint16_t i, j;
     641                 :            : 
     642                 :          0 :                         dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
     643                 :          0 :                         dev->data->rx_mbuf_alloc_failed +=
     644                 :          0 :                                 rxq->rx_free_thresh;
     645                 :            : 
     646                 :          0 :                         rxq->rx_nb_avail = 0;
     647                 :          0 :                         rxq->rx_tail = (uint16_t)(rxq->rx_tail - nb_rx);
     648         [ #  # ]:          0 :                         for (i = 0, j = rxq->rx_tail; i < nb_rx; i++, j++)
     649                 :          0 :                                 rxq->sw_ring[j].mbuf = rxq->rx_stage[i];
     650                 :            : 
     651                 :            :                         return 0;
     652                 :            :                 }
     653                 :            :         }
     654                 :            : 
     655         [ #  # ]:          0 :         if (rxq->rx_tail >= rxq->nb_rx_desc)
     656                 :          0 :                 rxq->rx_tail = 0;
     657                 :            : 
     658         [ #  # ]:          0 :         if (rxq->rx_nb_avail)
     659                 :          0 :                 return i40e_rx_fill_from_stage(rxq, rx_pkts, nb_pkts);
     660                 :            : 
     661                 :            :         return 0;
     662                 :            : }
     663                 :            : 
     664                 :            : static uint16_t
     665                 :          0 : i40e_recv_pkts_bulk_alloc(void *rx_queue,
     666                 :            :                           struct rte_mbuf **rx_pkts,
     667                 :            :                           uint16_t nb_pkts)
     668                 :            : {
     669                 :            :         uint16_t nb_rx = 0, n, count;
     670                 :            : 
     671         [ #  # ]:          0 :         if (unlikely(nb_pkts == 0))
     672                 :            :                 return 0;
     673                 :            : 
     674         [ #  # ]:          0 :         if (likely(nb_pkts <= RTE_PMD_I40E_RX_MAX_BURST))
     675                 :          0 :                 return rx_recv_pkts(rx_queue, rx_pkts, nb_pkts);
     676                 :            : 
     677         [ #  # ]:          0 :         while (nb_pkts) {
     678                 :          0 :                 n = RTE_MIN(nb_pkts, RTE_PMD_I40E_RX_MAX_BURST);
     679                 :          0 :                 count = rx_recv_pkts(rx_queue, &rx_pkts[nb_rx], n);
     680                 :          0 :                 nb_rx = (uint16_t)(nb_rx + count);
     681                 :          0 :                 nb_pkts = (uint16_t)(nb_pkts - count);
     682         [ #  # ]:          0 :                 if (count < n)
     683                 :            :                         break;
     684                 :            :         }
     685                 :            : 
     686                 :            :         return nb_rx;
     687                 :            : }
     688                 :            : #else
     689                 :            : static uint16_t
     690                 :            : i40e_recv_pkts_bulk_alloc(void __rte_unused *rx_queue,
     691                 :            :                           struct rte_mbuf __rte_unused **rx_pkts,
     692                 :            :                           uint16_t __rte_unused nb_pkts)
     693                 :            : {
     694                 :            :         return 0;
     695                 :            : }
     696                 :            : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
     697                 :            : 
     698                 :            : uint16_t
     699                 :          0 : i40e_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
     700                 :            : {
     701                 :            :         struct i40e_rx_queue *rxq;
     702                 :            :         volatile union i40e_rx_desc *rx_ring;
     703                 :            :         volatile union i40e_rx_desc *rxdp;
     704                 :            :         union i40e_rx_desc rxd;
     705                 :            :         struct i40e_rx_entry *sw_ring;
     706                 :            :         struct i40e_rx_entry *rxe;
     707                 :            :         struct rte_eth_dev *dev;
     708                 :            :         struct rte_mbuf *rxm;
     709                 :            :         struct rte_mbuf *nmb;
     710                 :            :         uint16_t nb_rx;
     711                 :            :         uint32_t rx_status;
     712                 :            :         uint64_t qword1;
     713                 :            :         uint16_t rx_packet_len;
     714                 :            :         uint16_t rx_id, nb_hold;
     715                 :            :         uint64_t dma_addr;
     716                 :            :         uint64_t pkt_flags;
     717                 :            :         uint32_t *ptype_tbl;
     718                 :            : 
     719                 :            :         nb_rx = 0;
     720                 :            :         nb_hold = 0;
     721                 :            :         rxq = rx_queue;
     722                 :          0 :         rx_id = rxq->rx_tail;
     723                 :          0 :         rx_ring = rxq->rx_ring;
     724                 :          0 :         sw_ring = rxq->sw_ring;
     725                 :          0 :         ptype_tbl = rxq->vsi->adapter->ptype_tbl;
     726                 :            : 
     727         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
     728                 :          0 :                 rxdp = &rx_ring[rx_id];
     729                 :          0 :                 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
     730                 :            :                 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK)
     731                 :          0 :                                 >> I40E_RXD_QW1_STATUS_SHIFT;
     732                 :            : 
     733                 :            :                 /* Check the DD bit first */
     734         [ #  # ]:          0 :                 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
     735                 :            :                         break;
     736                 :            : 
     737                 :          0 :                 nmb = rte_mbuf_raw_alloc(rxq->mp);
     738         [ #  # ]:          0 :                 if (unlikely(!nmb)) {
     739                 :          0 :                         dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
     740                 :          0 :                         dev->data->rx_mbuf_alloc_failed++;
     741                 :          0 :                         break;
     742                 :            :                 }
     743                 :            : 
     744                 :            :                 /**
     745                 :            :                  * Use acquire fence to ensure that qword1 which includes DD
     746                 :            :                  * bit is loaded before loading of other descriptor words.
     747                 :            :                  */
     748                 :            :                 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
     749                 :            : 
     750                 :          0 :                 rxd = *rxdp;
     751                 :          0 :                 nb_hold++;
     752                 :          0 :                 rxe = &sw_ring[rx_id];
     753                 :          0 :                 rx_id++;
     754         [ #  # ]:          0 :                 if (unlikely(rx_id == rxq->nb_rx_desc))
     755                 :            :                         rx_id = 0;
     756                 :            : 
     757                 :            :                 /* Prefetch next mbuf */
     758                 :          0 :                 rte_prefetch0(sw_ring[rx_id].mbuf);
     759                 :            : 
     760                 :            :                 /**
     761                 :            :                  * When next RX descriptor is on a cache line boundary,
     762                 :            :                  * prefetch the next 4 RX descriptors and next 8 pointers
     763                 :            :                  * to mbufs.
     764                 :            :                  */
     765         [ #  # ]:          0 :                 if ((rx_id & 0x3) == 0) {
     766                 :          0 :                         rte_prefetch0(&rx_ring[rx_id]);
     767                 :            :                         rte_prefetch0(&sw_ring[rx_id]);
     768                 :            :                 }
     769                 :          0 :                 rxm = rxe->mbuf;
     770                 :          0 :                 rxe->mbuf = nmb;
     771                 :            :                 dma_addr =
     772                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
     773                 :          0 :                 rxdp->read.hdr_addr = 0;
     774                 :          0 :                 rxdp->read.pkt_addr = dma_addr;
     775                 :            : 
     776                 :          0 :                 rx_packet_len = ((qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
     777                 :          0 :                                 I40E_RXD_QW1_LENGTH_PBUF_SHIFT) - rxq->crc_len;
     778                 :            : 
     779                 :          0 :                 rxm->data_off = RTE_PKTMBUF_HEADROOM;
     780                 :          0 :                 rte_prefetch0(RTE_PTR_ADD(rxm->buf_addr, RTE_PKTMBUF_HEADROOM));
     781                 :          0 :                 rxm->nb_segs = 1;
     782                 :          0 :                 rxm->next = NULL;
     783                 :          0 :                 rxm->pkt_len = rx_packet_len;
     784                 :          0 :                 rxm->data_len = rx_packet_len;
     785                 :          0 :                 rxm->port = rxq->port_id;
     786         [ #  # ]:          0 :                 rxm->ol_flags = 0;
     787                 :            :                 i40e_rxd_to_vlan_tci(rxm, &rxd);
     788                 :            :                 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
     789                 :          0 :                 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
     790                 :          0 :                 rxm->packet_type =
     791                 :          0 :                         ptype_tbl[(uint8_t)((qword1 &
     792                 :          0 :                         I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
     793         [ #  # ]:          0 :                 if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
     794                 :          0 :                         rxm->hash.rss =
     795                 :          0 :                                 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
     796         [ #  # ]:          0 :                 if (pkt_flags & RTE_MBUF_F_RX_FDIR)
     797                 :          0 :                         pkt_flags |= i40e_rxd_build_fdir(&rxd, rxm);
     798                 :            : 
     799                 :            : #ifdef RTE_LIBRTE_IEEE1588
     800                 :            :                 pkt_flags |= i40e_get_iee15888_flags(rxm, qword1);
     801                 :            : #endif
     802                 :          0 :                 rxm->ol_flags |= pkt_flags;
     803                 :            : 
     804                 :          0 :                 rx_pkts[nb_rx++] = rxm;
     805                 :            :         }
     806                 :          0 :         rxq->rx_tail = rx_id;
     807                 :            : 
     808                 :            :         /**
     809                 :            :          * If the number of free RX descriptors is greater than the RX free
     810                 :            :          * threshold of the queue, advance the receive tail register of queue.
     811                 :            :          * Update that register with the value of the last processed RX
     812                 :            :          * descriptor minus 1.
     813                 :            :          */
     814                 :          0 :         nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
     815         [ #  # ]:          0 :         if (nb_hold > rxq->rx_free_thresh) {
     816         [ #  # ]:          0 :                 rx_id = (uint16_t) ((rx_id == 0) ?
     817                 :          0 :                         (rxq->nb_rx_desc - 1) : (rx_id - 1));
     818                 :          0 :                 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
     819                 :            :                 nb_hold = 0;
     820                 :            :         }
     821                 :          0 :         rxq->nb_rx_hold = nb_hold;
     822                 :            : 
     823                 :          0 :         return nb_rx;
     824                 :            : }
     825                 :            : 
     826                 :            : uint16_t
     827                 :          0 : i40e_recv_scattered_pkts(void *rx_queue,
     828                 :            :                          struct rte_mbuf **rx_pkts,
     829                 :            :                          uint16_t nb_pkts)
     830                 :            : {
     831                 :            :         struct i40e_rx_queue *rxq = rx_queue;
     832                 :          0 :         volatile union i40e_rx_desc *rx_ring = rxq->rx_ring;
     833                 :            :         volatile union i40e_rx_desc *rxdp;
     834                 :            :         union i40e_rx_desc rxd;
     835                 :          0 :         struct i40e_rx_entry *sw_ring = rxq->sw_ring;
     836                 :            :         struct i40e_rx_entry *rxe;
     837                 :          0 :         struct rte_mbuf *first_seg = rxq->pkt_first_seg;
     838                 :          0 :         struct rte_mbuf *last_seg = rxq->pkt_last_seg;
     839                 :            :         struct rte_mbuf *nmb, *rxm;
     840                 :          0 :         uint16_t rx_id = rxq->rx_tail;
     841                 :            :         uint16_t nb_rx = 0, nb_hold = 0, rx_packet_len;
     842                 :            :         struct rte_eth_dev *dev;
     843                 :            :         uint32_t rx_status;
     844                 :            :         uint64_t qword1;
     845                 :            :         uint64_t dma_addr;
     846                 :            :         uint64_t pkt_flags;
     847                 :          0 :         uint32_t *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
     848                 :            : 
     849         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
     850                 :          0 :                 rxdp = &rx_ring[rx_id];
     851                 :          0 :                 qword1 = rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len);
     852                 :          0 :                 rx_status = (qword1 & I40E_RXD_QW1_STATUS_MASK) >>
     853                 :            :                                         I40E_RXD_QW1_STATUS_SHIFT;
     854                 :            : 
     855                 :            :                 /* Check the DD bit */
     856         [ #  # ]:          0 :                 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_DD_SHIFT)))
     857                 :            :                         break;
     858                 :            : 
     859                 :          0 :                 nmb = rte_mbuf_raw_alloc(rxq->mp);
     860         [ #  # ]:          0 :                 if (unlikely(!nmb)) {
     861                 :          0 :                         dev = I40E_VSI_TO_ETH_DEV(rxq->vsi);
     862                 :          0 :                         dev->data->rx_mbuf_alloc_failed++;
     863                 :          0 :                         break;
     864                 :            :                 }
     865                 :            : 
     866                 :            :                 /**
     867                 :            :                  * Use acquire fence to ensure that qword1 which includes DD
     868                 :            :                  * bit is loaded before loading of other descriptor words.
     869                 :            :                  */
     870                 :            :                 rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
     871                 :            : 
     872                 :          0 :                 rxd = *rxdp;
     873                 :          0 :                 nb_hold++;
     874                 :          0 :                 rxe = &sw_ring[rx_id];
     875                 :          0 :                 rx_id++;
     876         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc)
     877                 :            :                         rx_id = 0;
     878                 :            : 
     879                 :            :                 /* Prefetch next mbuf */
     880                 :          0 :                 rte_prefetch0(sw_ring[rx_id].mbuf);
     881                 :            : 
     882                 :            :                 /**
     883                 :            :                  * When next RX descriptor is on a cache line boundary,
     884                 :            :                  * prefetch the next 4 RX descriptors and next 8 pointers
     885                 :            :                  * to mbufs.
     886                 :            :                  */
     887         [ #  # ]:          0 :                 if ((rx_id & 0x3) == 0) {
     888                 :          0 :                         rte_prefetch0(&rx_ring[rx_id]);
     889                 :            :                         rte_prefetch0(&sw_ring[rx_id]);
     890                 :            :                 }
     891                 :            : 
     892                 :          0 :                 rxm = rxe->mbuf;
     893         [ #  # ]:          0 :                 rxe->mbuf = nmb;
     894                 :            :                 dma_addr =
     895                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
     896                 :            : 
     897                 :            :                 /* Set data buffer address and data length of the mbuf */
     898                 :          0 :                 rxdp->read.hdr_addr = 0;
     899                 :          0 :                 rxdp->read.pkt_addr = dma_addr;
     900                 :          0 :                 rx_packet_len = (qword1 & I40E_RXD_QW1_LENGTH_PBUF_MASK) >>
     901                 :            :                                         I40E_RXD_QW1_LENGTH_PBUF_SHIFT;
     902                 :          0 :                 rxm->data_len = rx_packet_len;
     903                 :          0 :                 rxm->data_off = RTE_PKTMBUF_HEADROOM;
     904                 :            : 
     905                 :            :                 /**
     906                 :            :                  * If this is the first buffer of the received packet, set the
     907                 :            :                  * pointer to the first mbuf of the packet and initialize its
     908                 :            :                  * context. Otherwise, update the total length and the number
     909                 :            :                  * of segments of the current scattered packet, and update the
     910                 :            :                  * pointer to the last mbuf of the current packet.
     911                 :            :                  */
     912         [ #  # ]:          0 :                 if (!first_seg) {
     913                 :            :                         first_seg = rxm;
     914                 :          0 :                         first_seg->nb_segs = 1;
     915                 :          0 :                         first_seg->pkt_len = rx_packet_len;
     916                 :            :                 } else {
     917                 :          0 :                         first_seg->pkt_len =
     918                 :          0 :                                 (uint16_t)(first_seg->pkt_len +
     919                 :            :                                                 rx_packet_len);
     920                 :          0 :                         first_seg->nb_segs++;
     921                 :          0 :                         last_seg->next = rxm;
     922                 :            :                 }
     923                 :            : 
     924                 :            :                 /**
     925                 :            :                  * If this is not the last buffer of the received packet,
     926                 :            :                  * update the pointer to the last mbuf of the current scattered
     927                 :            :                  * packet and continue to parse the RX ring.
     928                 :            :                  */
     929         [ #  # ]:          0 :                 if (!(rx_status & (1 << I40E_RX_DESC_STATUS_EOF_SHIFT))) {
     930                 :            :                         last_seg = rxm;
     931                 :          0 :                         continue;
     932                 :            :                 }
     933                 :            : 
     934                 :            :                 /**
     935                 :            :                  * This is the last buffer of the received packet. If the CRC
     936                 :            :                  * is not stripped by the hardware:
     937                 :            :                  *  - Subtract the CRC length from the total packet length.
     938                 :            :                  *  - If the last buffer only contains the whole CRC or a part
     939                 :            :                  *  of it, free the mbuf associated to the last buffer. If part
     940                 :            :                  *  of the CRC is also contained in the previous mbuf, subtract
     941                 :            :                  *  the length of that CRC part from the data length of the
     942                 :            :                  *  previous mbuf.
     943                 :            :                  */
     944                 :          0 :                 rxm->next = NULL;
     945         [ #  # ]:          0 :                 if (unlikely(rxq->crc_len > 0)) {
     946                 :          0 :                         first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
     947         [ #  # ]:          0 :                         if (rx_packet_len <= RTE_ETHER_CRC_LEN) {
     948                 :            :                                 rte_pktmbuf_free_seg(rxm);
     949                 :          0 :                                 first_seg->nb_segs--;
     950                 :          0 :                                 last_seg->data_len =
     951                 :          0 :                                         (uint16_t)(last_seg->data_len -
     952                 :            :                                         (RTE_ETHER_CRC_LEN - rx_packet_len));
     953                 :          0 :                                 last_seg->next = NULL;
     954                 :            :                         } else
     955                 :          0 :                                 rxm->data_len = (uint16_t)(rx_packet_len -
     956                 :            :                                                         RTE_ETHER_CRC_LEN);
     957                 :            :                 }
     958                 :            : 
     959                 :          0 :                 first_seg->port = rxq->port_id;
     960         [ #  # ]:          0 :                 first_seg->ol_flags = 0;
     961                 :            :                 i40e_rxd_to_vlan_tci(first_seg, &rxd);
     962                 :            :                 pkt_flags = i40e_rxd_status_to_pkt_flags(qword1);
     963                 :          0 :                 pkt_flags |= i40e_rxd_error_to_pkt_flags(qword1);
     964                 :          0 :                 first_seg->packet_type =
     965                 :          0 :                         ptype_tbl[(uint8_t)((qword1 &
     966                 :          0 :                         I40E_RXD_QW1_PTYPE_MASK) >> I40E_RXD_QW1_PTYPE_SHIFT)];
     967         [ #  # ]:          0 :                 if (pkt_flags & RTE_MBUF_F_RX_RSS_HASH)
     968                 :          0 :                         first_seg->hash.rss =
     969                 :          0 :                                 rte_le_to_cpu_32(rxd.wb.qword0.hi_dword.rss);
     970         [ #  # ]:          0 :                 if (pkt_flags & RTE_MBUF_F_RX_FDIR)
     971                 :          0 :                         pkt_flags |= i40e_rxd_build_fdir(&rxd, first_seg);
     972                 :            : 
     973                 :            : #ifdef RTE_LIBRTE_IEEE1588
     974                 :            :                 pkt_flags |= i40e_get_iee15888_flags(first_seg, qword1);
     975                 :            : #endif
     976                 :          0 :                 first_seg->ol_flags |= pkt_flags;
     977                 :            : 
     978                 :            :                 /* Prefetch data of first segment, if configured to do so. */
     979                 :          0 :                 rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr,
     980                 :            :                         first_seg->data_off));
     981                 :          0 :                 rx_pkts[nb_rx++] = first_seg;
     982                 :            :                 first_seg = NULL;
     983                 :            :         }
     984                 :            : 
     985                 :            :         /* Record index of the next RX descriptor to probe. */
     986                 :          0 :         rxq->rx_tail = rx_id;
     987                 :          0 :         rxq->pkt_first_seg = first_seg;
     988                 :          0 :         rxq->pkt_last_seg = last_seg;
     989                 :            : 
     990                 :            :         /**
     991                 :            :          * If the number of free RX descriptors is greater than the RX free
     992                 :            :          * threshold of the queue, advance the Receive Descriptor Tail (RDT)
     993                 :            :          * register. Update the RDT with the value of the last processed RX
     994                 :            :          * descriptor minus 1, to guarantee that the RDT register is never
     995                 :            :          * equal to the RDH register, which creates a "full" ring situation
     996                 :            :          * from the hardware point of view.
     997                 :            :          */
     998                 :          0 :         nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
     999         [ #  # ]:          0 :         if (nb_hold > rxq->rx_free_thresh) {
    1000         [ #  # ]:          0 :                 rx_id = (uint16_t)(rx_id == 0 ?
    1001                 :          0 :                         (rxq->nb_rx_desc - 1) : (rx_id - 1));
    1002                 :          0 :                 I40E_PCI_REG_WC_WRITE(rxq->qrx_tail, rx_id);
    1003                 :            :                 nb_hold = 0;
    1004                 :            :         }
    1005                 :          0 :         rxq->nb_rx_hold = nb_hold;
    1006                 :            : 
    1007                 :          0 :         return nb_rx;
    1008                 :            : }
    1009                 :            : 
    1010                 :            : /* Check if the context descriptor is needed for TX offloading */
    1011                 :            : static inline uint16_t
    1012                 :            : i40e_calc_context_desc(uint64_t flags)
    1013                 :            : {
    1014                 :            :         static uint64_t mask = RTE_MBUF_F_TX_OUTER_IP_CKSUM |
    1015                 :            :                 RTE_MBUF_F_TX_TCP_SEG |
    1016                 :            :                 RTE_MBUF_F_TX_QINQ |
    1017                 :            :                 RTE_MBUF_F_TX_TUNNEL_MASK;
    1018                 :            : 
    1019                 :            : #ifdef RTE_LIBRTE_IEEE1588
    1020                 :            :         mask |= RTE_MBUF_F_TX_IEEE1588_TMST;
    1021                 :            : #endif
    1022                 :            : 
    1023                 :          0 :         return (flags & mask) ? 1 : 0;
    1024                 :            : }
    1025                 :            : 
    1026                 :            : /* set i40e TSO context descriptor */
    1027                 :            : static inline uint64_t
    1028                 :          0 : i40e_set_tso_ctx(struct rte_mbuf *mbuf, union i40e_tx_offload tx_offload)
    1029                 :            : {
    1030                 :            :         uint64_t ctx_desc = 0;
    1031                 :            :         uint32_t cd_cmd, hdr_len, cd_tso_len;
    1032                 :            : 
    1033         [ #  # ]:          0 :         if (!tx_offload.l4_len) {
    1034                 :          0 :                 PMD_DRV_LOG(DEBUG, "L4 length set to 0");
    1035                 :          0 :                 return ctx_desc;
    1036                 :            :         }
    1037                 :            : 
    1038                 :          0 :         hdr_len = tx_offload.l2_len + tx_offload.l3_len + tx_offload.l4_len;
    1039                 :          0 :         hdr_len += (mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
    1040         [ #  # ]:          0 :                    tx_offload.outer_l2_len + tx_offload.outer_l3_len : 0;
    1041                 :            : 
    1042                 :            :         cd_cmd = I40E_TX_CTX_DESC_TSO;
    1043                 :          0 :         cd_tso_len = mbuf->pkt_len - hdr_len;
    1044                 :          0 :         ctx_desc |= ((uint64_t)cd_cmd << I40E_TXD_CTX_QW1_CMD_SHIFT) |
    1045                 :          0 :                 ((uint64_t)cd_tso_len <<
    1046                 :          0 :                  I40E_TXD_CTX_QW1_TSO_LEN_SHIFT) |
    1047                 :          0 :                 ((uint64_t)mbuf->tso_segsz <<
    1048                 :            :                  I40E_TXD_CTX_QW1_MSS_SHIFT);
    1049                 :            : 
    1050                 :          0 :         return ctx_desc;
    1051                 :            : }
    1052                 :            : 
    1053                 :            : /* HW requires that Tx buffer size ranges from 1B up to (16K-1)B. */
    1054                 :            : #define I40E_MAX_DATA_PER_TXD \
    1055                 :            :         (I40E_TXD_QW1_TX_BUF_SZ_MASK >> I40E_TXD_QW1_TX_BUF_SZ_SHIFT)
    1056                 :            : /* Calculate the number of TX descriptors needed for each pkt */
    1057                 :            : static inline uint16_t
    1058                 :            : i40e_calc_pkt_desc(struct rte_mbuf *tx_pkt)
    1059                 :            : {
    1060                 :            :         struct rte_mbuf *txd = tx_pkt;
    1061                 :            :         uint16_t count = 0;
    1062                 :            : 
    1063         [ #  # ]:          0 :         while (txd != NULL) {
    1064                 :          0 :                 count += DIV_ROUND_UP(txd->data_len, I40E_MAX_DATA_PER_TXD);
    1065                 :          0 :                 txd = txd->next;
    1066                 :            :         }
    1067                 :            : 
    1068                 :            :         return count;
    1069                 :            : }
    1070                 :            : 
    1071                 :            : uint16_t
    1072                 :          0 : i40e_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
    1073                 :            : {
    1074                 :            :         struct i40e_tx_queue *txq;
    1075                 :            :         struct i40e_tx_entry *sw_ring;
    1076                 :            :         struct i40e_tx_entry *txe, *txn;
    1077                 :            :         volatile struct i40e_tx_desc *txd;
    1078                 :            :         volatile struct i40e_tx_desc *txr;
    1079                 :            :         struct rte_mbuf *tx_pkt;
    1080                 :            :         struct rte_mbuf *m_seg;
    1081                 :            :         uint32_t cd_tunneling_params;
    1082                 :            :         uint16_t tx_id;
    1083                 :            :         uint16_t nb_tx;
    1084                 :            :         uint32_t td_cmd;
    1085                 :            :         uint32_t td_offset;
    1086                 :            :         uint32_t td_tag;
    1087                 :            :         uint64_t ol_flags;
    1088                 :            :         uint16_t nb_used;
    1089                 :            :         uint16_t nb_ctx;
    1090                 :            :         uint16_t tx_last;
    1091                 :            :         uint16_t slen;
    1092                 :            :         uint64_t buf_dma_addr;
    1093                 :          0 :         union i40e_tx_offload tx_offload = {0};
    1094                 :            : 
    1095                 :            :         txq = tx_queue;
    1096                 :          0 :         sw_ring = txq->sw_ring;
    1097                 :          0 :         txr = txq->tx_ring;
    1098                 :          0 :         tx_id = txq->tx_tail;
    1099                 :          0 :         txe = &sw_ring[tx_id];
    1100                 :            : 
    1101                 :            :         /* Check if the descriptor ring needs to be cleaned. */
    1102         [ #  # ]:          0 :         if (txq->nb_tx_free < txq->tx_free_thresh)
    1103                 :          0 :                 (void)i40e_xmit_cleanup(txq);
    1104                 :            : 
    1105         [ #  # ]:          0 :         for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
    1106                 :          0 :                 td_cmd = 0;
    1107                 :            :                 td_tag = 0;
    1108                 :          0 :                 td_offset = 0;
    1109                 :            : 
    1110                 :          0 :                 tx_pkt = *tx_pkts++;
    1111         [ #  # ]:          0 :                 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
    1112                 :            : 
    1113                 :          0 :                 ol_flags = tx_pkt->ol_flags;
    1114                 :          0 :                 tx_offload.l2_len = tx_pkt->l2_len;
    1115                 :          0 :                 tx_offload.l3_len = tx_pkt->l3_len;
    1116                 :          0 :                 tx_offload.outer_l2_len = tx_pkt->outer_l2_len;
    1117                 :          0 :                 tx_offload.outer_l3_len = tx_pkt->outer_l3_len;
    1118                 :          0 :                 tx_offload.l4_len = tx_pkt->l4_len;
    1119                 :          0 :                 tx_offload.tso_segsz = tx_pkt->tso_segsz;
    1120                 :            : 
    1121                 :            :                 /* Calculate the number of context descriptors needed. */
    1122                 :            :                 nb_ctx = i40e_calc_context_desc(ol_flags);
    1123                 :            : 
    1124                 :            :                 /**
    1125                 :            :                  * The number of descriptors that must be allocated for
    1126                 :            :                  * a packet equals to the number of the segments of that
    1127                 :            :                  * packet plus 1 context descriptor if needed.
    1128                 :            :                  * Recalculate the needed tx descs when TSO enabled in case
    1129                 :            :                  * the mbuf data size exceeds max data size that hw allows
    1130                 :            :                  * per tx desc.
    1131                 :            :                  */
    1132         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
    1133                 :          0 :                         nb_used = (uint16_t)(i40e_calc_pkt_desc(tx_pkt) +
    1134                 :            :                                              nb_ctx);
    1135                 :            :                 else
    1136                 :          0 :                         nb_used = (uint16_t)(tx_pkt->nb_segs + nb_ctx);
    1137                 :          0 :                 tx_last = (uint16_t)(tx_id + nb_used - 1);
    1138                 :            : 
    1139                 :            :                 /* Circular ring */
    1140         [ #  # ]:          0 :                 if (tx_last >= txq->nb_tx_desc)
    1141                 :          0 :                         tx_last = (uint16_t)(tx_last - txq->nb_tx_desc);
    1142                 :            : 
    1143         [ #  # ]:          0 :                 if (nb_used > txq->nb_tx_free) {
    1144         [ #  # ]:          0 :                         if (i40e_xmit_cleanup(txq) != 0) {
    1145         [ #  # ]:          0 :                                 if (nb_tx == 0)
    1146                 :            :                                         return 0;
    1147                 :          0 :                                 goto end_of_tx;
    1148                 :            :                         }
    1149         [ #  # ]:          0 :                         if (unlikely(nb_used > txq->tx_rs_thresh)) {
    1150         [ #  # ]:          0 :                                 while (nb_used > txq->nb_tx_free) {
    1151         [ #  # ]:          0 :                                         if (i40e_xmit_cleanup(txq) != 0) {
    1152         [ #  # ]:          0 :                                                 if (nb_tx == 0)
    1153                 :            :                                                         return 0;
    1154                 :          0 :                                                 goto end_of_tx;
    1155                 :            :                                         }
    1156                 :            :                                 }
    1157                 :            :                         }
    1158                 :            :                 }
    1159                 :            : 
    1160                 :            :                 /* Descriptor based VLAN insertion */
    1161         [ #  # ]:          0 :                 if (ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
    1162                 :          0 :                         td_cmd |= I40E_TX_DESC_CMD_IL2TAG1;
    1163                 :          0 :                         td_tag = tx_pkt->vlan_tci;
    1164                 :            :                 }
    1165                 :            : 
    1166                 :            :                 /* Always enable CRC offload insertion */
    1167                 :          0 :                 td_cmd |= I40E_TX_DESC_CMD_ICRC;
    1168                 :            : 
    1169                 :            :                 /* Fill in tunneling parameters if necessary */
    1170                 :          0 :                 cd_tunneling_params = 0;
    1171         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
    1172                 :          0 :                         td_offset |= (tx_offload.outer_l2_len >> 1)
    1173                 :          0 :                                         << I40E_TX_DESC_LENGTH_MACLEN_SHIFT;
    1174                 :          0 :                         i40e_parse_tunneling_params(ol_flags, tx_offload,
    1175                 :            :                                                     &cd_tunneling_params);
    1176                 :            :                 }
    1177                 :            :                 /* Enable checksum offloading */
    1178         [ #  # ]:          0 :                 if (ol_flags & I40E_TX_CKSUM_OFFLOAD_MASK)
    1179                 :          0 :                         i40e_txd_enable_checksum(ol_flags, &td_cmd,
    1180                 :            :                                                  &td_offset, tx_offload);
    1181                 :            : 
    1182         [ #  # ]:          0 :                 if (nb_ctx) {
    1183                 :            :                         /* Setup TX context descriptor if required */
    1184                 :          0 :                         volatile struct i40e_tx_context_desc *ctx_txd =
    1185                 :            :                                 (volatile struct i40e_tx_context_desc *)\
    1186                 :          0 :                                                         &txr[tx_id];
    1187                 :            :                         uint16_t cd_l2tag2 = 0;
    1188                 :            :                         uint64_t cd_type_cmd_tso_mss =
    1189                 :            :                                 I40E_TX_DESC_DTYPE_CONTEXT;
    1190                 :            : 
    1191                 :          0 :                         txn = &sw_ring[txe->next_id];
    1192         [ #  # ]:          0 :                         RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
    1193         [ #  # ]:          0 :                         if (txe->mbuf != NULL) {
    1194                 :            :                                 rte_pktmbuf_free_seg(txe->mbuf);
    1195                 :          0 :                                 txe->mbuf = NULL;
    1196                 :            :                         }
    1197                 :            : 
    1198                 :            :                         /* TSO enabled means no timestamp */
    1199         [ #  # ]:          0 :                         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG)
    1200                 :          0 :                                 cd_type_cmd_tso_mss |=
    1201                 :          0 :                                         i40e_set_tso_ctx(tx_pkt, tx_offload);
    1202                 :            :                         else {
    1203                 :            : #ifdef RTE_LIBRTE_IEEE1588
    1204                 :            :                                 if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
    1205                 :            :                                         cd_type_cmd_tso_mss |=
    1206                 :            :                                                 ((uint64_t)I40E_TX_CTX_DESC_TSYN <<
    1207                 :            :                                                  I40E_TXD_CTX_QW1_CMD_SHIFT);
    1208                 :            : #endif
    1209                 :            :                         }
    1210                 :            : 
    1211                 :          0 :                         ctx_txd->tunneling_params =
    1212                 :            :                                 rte_cpu_to_le_32(cd_tunneling_params);
    1213         [ #  # ]:          0 :                         if (ol_flags & RTE_MBUF_F_TX_QINQ) {
    1214                 :          0 :                                 cd_l2tag2 = tx_pkt->vlan_tci_outer;
    1215                 :          0 :                                 cd_type_cmd_tso_mss |=
    1216                 :            :                                         ((uint64_t)I40E_TX_CTX_DESC_IL2TAG2 <<
    1217                 :            :                                                 I40E_TXD_CTX_QW1_CMD_SHIFT);
    1218                 :            :                         }
    1219                 :          0 :                         ctx_txd->l2tag2 = rte_cpu_to_le_16(cd_l2tag2);
    1220                 :          0 :                         ctx_txd->type_cmd_tso_mss =
    1221                 :            :                                 rte_cpu_to_le_64(cd_type_cmd_tso_mss);
    1222                 :            : 
    1223                 :            :                         PMD_TX_LOG(DEBUG, "mbuf: %p, TCD[%u]:\n"
    1224                 :            :                                 "tunneling_params: %#x;\n"
    1225                 :            :                                 "l2tag2: %#hx;\n"
    1226                 :            :                                 "rsvd: %#hx;\n"
    1227                 :            :                                 "type_cmd_tso_mss: %#"PRIx64";\n",
    1228                 :            :                                 tx_pkt, tx_id,
    1229                 :            :                                 ctx_txd->tunneling_params,
    1230                 :            :                                 ctx_txd->l2tag2,
    1231                 :            :                                 ctx_txd->rsvd,
    1232                 :            :                                 ctx_txd->type_cmd_tso_mss);
    1233                 :            : 
    1234                 :          0 :                         txe->last_id = tx_last;
    1235                 :          0 :                         tx_id = txe->next_id;
    1236                 :            :                         txe = txn;
    1237                 :            :                 }
    1238                 :            : 
    1239                 :            :                 m_seg = tx_pkt;
    1240                 :            :                 do {
    1241                 :          0 :                         txd = &txr[tx_id];
    1242                 :          0 :                         txn = &sw_ring[txe->next_id];
    1243                 :            : 
    1244         [ #  # ]:          0 :                         if (txe->mbuf)
    1245                 :            :                                 rte_pktmbuf_free_seg(txe->mbuf);
    1246                 :          0 :                         txe->mbuf = m_seg;
    1247                 :            : 
    1248                 :            :                         /* Setup TX Descriptor */
    1249                 :          0 :                         slen = m_seg->data_len;
    1250                 :            :                         buf_dma_addr = rte_mbuf_data_iova(m_seg);
    1251                 :            : 
    1252         [ #  # ]:          0 :                         while ((ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
    1253         [ #  # ]:          0 :                                 unlikely(slen > I40E_MAX_DATA_PER_TXD)) {
    1254                 :          0 :                                 txd->buffer_addr =
    1255                 :            :                                         rte_cpu_to_le_64(buf_dma_addr);
    1256                 :          0 :                                 txd->cmd_type_offset_bsz =
    1257                 :          0 :                                         i40e_build_ctob(td_cmd,
    1258                 :            :                                         td_offset, I40E_MAX_DATA_PER_TXD,
    1259                 :            :                                         td_tag);
    1260                 :            : 
    1261                 :          0 :                                 buf_dma_addr += I40E_MAX_DATA_PER_TXD;
    1262                 :          0 :                                 slen -= I40E_MAX_DATA_PER_TXD;
    1263                 :            : 
    1264                 :          0 :                                 txe->last_id = tx_last;
    1265                 :          0 :                                 tx_id = txe->next_id;
    1266                 :            :                                 txe = txn;
    1267                 :          0 :                                 txd = &txr[tx_id];
    1268                 :          0 :                                 txn = &sw_ring[txe->next_id];
    1269                 :            :                         }
    1270                 :            :                         PMD_TX_LOG(DEBUG, "mbuf: %p, TDD[%u]:\n"
    1271                 :            :                                 "buf_dma_addr: %#"PRIx64";\n"
    1272                 :            :                                 "td_cmd: %#x;\n"
    1273                 :            :                                 "td_offset: %#x;\n"
    1274                 :            :                                 "td_len: %u;\n"
    1275                 :            :                                 "td_tag: %#x;\n",
    1276                 :            :                                 tx_pkt, tx_id, buf_dma_addr,
    1277                 :            :                                 td_cmd, td_offset, slen, td_tag);
    1278                 :            : 
    1279                 :          0 :                         txd->buffer_addr = rte_cpu_to_le_64(buf_dma_addr);
    1280                 :          0 :                         txd->cmd_type_offset_bsz = i40e_build_ctob(td_cmd,
    1281                 :            :                                                 td_offset, slen, td_tag);
    1282                 :          0 :                         txe->last_id = tx_last;
    1283                 :          0 :                         tx_id = txe->next_id;
    1284                 :            :                         txe = txn;
    1285                 :          0 :                         m_seg = m_seg->next;
    1286         [ #  # ]:          0 :                 } while (m_seg != NULL);
    1287                 :            : 
    1288                 :            :                 /* The last packet data descriptor needs End Of Packet (EOP) */
    1289                 :          0 :                 td_cmd |= I40E_TX_DESC_CMD_EOP;
    1290                 :          0 :                 txq->nb_tx_used = (uint16_t)(txq->nb_tx_used + nb_used);
    1291                 :          0 :                 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_used);
    1292                 :            : 
    1293         [ #  # ]:          0 :                 if (txq->nb_tx_used >= txq->tx_rs_thresh) {
    1294                 :            :                         PMD_TX_LOG(DEBUG,
    1295                 :            :                                    "Setting RS bit on TXD id="
    1296                 :            :                                    "%4u (port=%d queue=%d)",
    1297                 :            :                                    tx_last, txq->port_id, txq->queue_id);
    1298                 :            : 
    1299                 :          0 :                         td_cmd |= I40E_TX_DESC_CMD_RS;
    1300                 :            : 
    1301                 :            :                         /* Update txq RS bit counters */
    1302                 :          0 :                         txq->nb_tx_used = 0;
    1303                 :            :                 }
    1304                 :            : 
    1305                 :          0 :                 txd->cmd_type_offset_bsz |=
    1306                 :          0 :                         rte_cpu_to_le_64(((uint64_t)td_cmd) <<
    1307                 :            :                                         I40E_TXD_QW1_CMD_SHIFT);
    1308                 :            :         }
    1309                 :            : 
    1310                 :          0 : end_of_tx:
    1311                 :            :         PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
    1312                 :            :                    (unsigned) txq->port_id, (unsigned) txq->queue_id,
    1313                 :            :                    (unsigned) tx_id, (unsigned) nb_tx);
    1314                 :            : 
    1315                 :          0 :         rte_io_wmb();
    1316         [ #  # ]:          0 :         I40E_PCI_REG_WC_WRITE_RELAXED(txq->qtx_tail, tx_id);
    1317                 :          0 :         txq->tx_tail = tx_id;
    1318                 :            : 
    1319                 :          0 :         return nb_tx;
    1320                 :            : }
    1321                 :            : 
    1322                 :            : static __rte_always_inline int
    1323                 :            : i40e_tx_free_bufs(struct i40e_tx_queue *txq)
    1324                 :            : {
    1325                 :            :         struct i40e_tx_entry *txep;
    1326                 :          0 :         uint16_t tx_rs_thresh = txq->tx_rs_thresh;
    1327                 :            :         uint16_t i = 0, j = 0;
    1328                 :            :         struct rte_mbuf *free[RTE_I40E_TX_MAX_FREE_BUF_SZ];
    1329                 :          0 :         const uint16_t k = RTE_ALIGN_FLOOR(tx_rs_thresh, RTE_I40E_TX_MAX_FREE_BUF_SZ);
    1330                 :          0 :         const uint16_t m = tx_rs_thresh % RTE_I40E_TX_MAX_FREE_BUF_SZ;
    1331                 :            : 
    1332   [ #  #  #  # ]:          0 :         if ((txq->tx_ring[txq->tx_next_dd].cmd_type_offset_bsz &
    1333                 :            :                         rte_cpu_to_le_64(I40E_TXD_QW1_DTYPE_MASK)) !=
    1334                 :            :                         rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE))
    1335                 :            :                 return 0;
    1336                 :            : 
    1337                 :          0 :         txep = &txq->sw_ring[txq->tx_next_dd - (tx_rs_thresh - 1)];
    1338                 :            : 
    1339   [ #  #  #  # ]:          0 :         for (i = 0; i < tx_rs_thresh; i++)
    1340                 :          0 :                 rte_prefetch0((txep + i)->mbuf);
    1341                 :            : 
    1342   [ #  #  #  # ]:          0 :         if (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) {
    1343   [ #  #  #  # ]:          0 :                 if (k) {
    1344   [ #  #  #  # ]:          0 :                         for (j = 0; j != k; j += RTE_I40E_TX_MAX_FREE_BUF_SZ) {
    1345   [ #  #  #  # ]:          0 :                                 for (i = 0; i < RTE_I40E_TX_MAX_FREE_BUF_SZ; ++i, ++txep) {
    1346                 :          0 :                                         free[i] = txep->mbuf;
    1347                 :          0 :                                         txep->mbuf = NULL;
    1348                 :            :                                 }
    1349   [ #  #  #  # ]:          0 :                                 rte_mempool_put_bulk(free[0]->pool, (void **)free,
    1350                 :            :                                                 RTE_I40E_TX_MAX_FREE_BUF_SZ);
    1351                 :            :                         }
    1352                 :            :                 }
    1353                 :            : 
    1354   [ #  #  #  # ]:          0 :                 if (m) {
    1355   [ #  #  #  # ]:          0 :                         for (i = 0; i < m; ++i, ++txep) {
    1356                 :          0 :                                 free[i] = txep->mbuf;
    1357                 :          0 :                                 txep->mbuf = NULL;
    1358                 :            :                         }
    1359   [ #  #  #  # ]:          0 :                         rte_mempool_put_bulk(free[0]->pool, (void **)free, m);
    1360                 :            :                 }
    1361                 :            :         } else {
    1362   [ #  #  #  # ]:          0 :                 for (i = 0; i < txq->tx_rs_thresh; ++i, ++txep) {
    1363                 :          0 :                         rte_pktmbuf_free_seg(txep->mbuf);
    1364                 :          0 :                         txep->mbuf = NULL;
    1365                 :            :                 }
    1366                 :            :         }
    1367                 :            : 
    1368                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free + txq->tx_rs_thresh);
    1369                 :          0 :         txq->tx_next_dd = (uint16_t)(txq->tx_next_dd + txq->tx_rs_thresh);
    1370   [ #  #  #  # ]:          0 :         if (txq->tx_next_dd >= txq->nb_tx_desc)
    1371                 :          0 :                 txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
    1372                 :            : 
    1373                 :          0 :         return txq->tx_rs_thresh;
    1374                 :            : }
    1375                 :            : 
    1376                 :            : /* Populate 4 descriptors with data from 4 mbufs */
    1377                 :            : static inline void
    1378                 :            : tx4(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
    1379                 :            : {
    1380                 :            :         uint64_t dma_addr;
    1381                 :            :         uint32_t i;
    1382                 :            : 
    1383         [ #  # ]:          0 :         for (i = 0; i < 4; i++, txdp++, pkts++) {
    1384                 :          0 :                 dma_addr = rte_mbuf_data_iova(*pkts);
    1385                 :          0 :                 txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
    1386                 :          0 :                 txdp->cmd_type_offset_bsz =
    1387                 :            :                         i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
    1388                 :          0 :                                         (*pkts)->data_len, 0);
    1389                 :            :         }
    1390                 :            : }
    1391                 :            : 
    1392                 :            : /* Populate 1 descriptor with data from 1 mbuf */
    1393                 :            : static inline void
    1394                 :            : tx1(volatile struct i40e_tx_desc *txdp, struct rte_mbuf **pkts)
    1395                 :            : {
    1396                 :            :         uint64_t dma_addr;
    1397                 :            : 
    1398                 :            :         dma_addr = rte_mbuf_data_iova(*pkts);
    1399                 :          0 :         txdp->buffer_addr = rte_cpu_to_le_64(dma_addr);
    1400                 :          0 :         txdp->cmd_type_offset_bsz =
    1401                 :            :                 i40e_build_ctob((uint32_t)I40E_TD_CMD, 0,
    1402                 :          0 :                                 (*pkts)->data_len, 0);
    1403                 :            : }
    1404                 :            : 
    1405                 :            : /* Fill hardware descriptor ring with mbuf data */
    1406                 :            : static inline void
    1407                 :          0 : i40e_tx_fill_hw_ring(struct i40e_tx_queue *txq,
    1408                 :            :                      struct rte_mbuf **pkts,
    1409                 :            :                      uint16_t nb_pkts)
    1410                 :            : {
    1411                 :          0 :         volatile struct i40e_tx_desc *txdp = &(txq->tx_ring[txq->tx_tail]);
    1412                 :          0 :         struct i40e_tx_entry *txep = &(txq->sw_ring[txq->tx_tail]);
    1413                 :            :         const int N_PER_LOOP = 4;
    1414                 :            :         const int N_PER_LOOP_MASK = N_PER_LOOP - 1;
    1415                 :            :         int mainpart, leftover;
    1416                 :            :         int i, j;
    1417                 :            : 
    1418                 :          0 :         mainpart = (nb_pkts & ((uint32_t) ~N_PER_LOOP_MASK));
    1419                 :          0 :         leftover = (nb_pkts & ((uint32_t)  N_PER_LOOP_MASK));
    1420         [ #  # ]:          0 :         for (i = 0; i < mainpart; i += N_PER_LOOP) {
    1421         [ #  # ]:          0 :                 for (j = 0; j < N_PER_LOOP; ++j) {
    1422                 :          0 :                         (txep + i + j)->mbuf = *(pkts + i + j);
    1423                 :            :                 }
    1424                 :          0 :                 tx4(txdp + i, pkts + i);
    1425                 :            :         }
    1426         [ #  # ]:          0 :         if (unlikely(leftover > 0)) {
    1427         [ #  # ]:          0 :                 for (i = 0; i < leftover; ++i) {
    1428                 :          0 :                         (txep + mainpart + i)->mbuf = *(pkts + mainpart + i);
    1429                 :          0 :                         tx1(txdp + mainpart + i, pkts + mainpart + i);
    1430                 :            :                 }
    1431                 :            :         }
    1432                 :          0 : }
    1433                 :            : 
    1434                 :            : static inline uint16_t
    1435                 :          0 : tx_xmit_pkts(struct i40e_tx_queue *txq,
    1436                 :            :              struct rte_mbuf **tx_pkts,
    1437                 :            :              uint16_t nb_pkts)
    1438                 :            : {
    1439                 :          0 :         volatile struct i40e_tx_desc *txr = txq->tx_ring;
    1440                 :            :         uint16_t n = 0;
    1441                 :            : 
    1442                 :            :         /**
    1443                 :            :          * Begin scanning the H/W ring for done descriptors when the number
    1444                 :            :          * of available descriptors drops below tx_free_thresh. For each done
    1445                 :            :          * descriptor, free the associated buffer.
    1446                 :            :          */
    1447         [ #  # ]:          0 :         if (txq->nb_tx_free < txq->tx_free_thresh)
    1448                 :            :                 i40e_tx_free_bufs(txq);
    1449                 :            : 
    1450                 :            :         /* Use available descriptor only */
    1451                 :          0 :         nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
    1452         [ #  # ]:          0 :         if (unlikely(!nb_pkts))
    1453                 :            :                 return 0;
    1454                 :            : 
    1455                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
    1456         [ #  # ]:          0 :         if ((txq->tx_tail + nb_pkts) > txq->nb_tx_desc) {
    1457                 :          0 :                 n = (uint16_t)(txq->nb_tx_desc - txq->tx_tail);
    1458                 :          0 :                 i40e_tx_fill_hw_ring(txq, tx_pkts, n);
    1459                 :          0 :                 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
    1460                 :            :                         rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
    1461                 :            :                                                 I40E_TXD_QW1_CMD_SHIFT);
    1462                 :          0 :                 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
    1463                 :          0 :                 txq->tx_tail = 0;
    1464                 :            :         }
    1465                 :            : 
    1466                 :            :         /* Fill hardware descriptor ring with mbuf data */
    1467                 :          0 :         i40e_tx_fill_hw_ring(txq, tx_pkts + n, (uint16_t)(nb_pkts - n));
    1468                 :          0 :         txq->tx_tail = (uint16_t)(txq->tx_tail + (nb_pkts - n));
    1469                 :            : 
    1470                 :            :         /* Determine if RS bit needs to be set */
    1471         [ #  # ]:          0 :         if (txq->tx_tail > txq->tx_next_rs) {
    1472                 :          0 :                 txr[txq->tx_next_rs].cmd_type_offset_bsz |=
    1473                 :            :                         rte_cpu_to_le_64(((uint64_t)I40E_TX_DESC_CMD_RS) <<
    1474                 :            :                                                 I40E_TXD_QW1_CMD_SHIFT);
    1475                 :          0 :                 txq->tx_next_rs =
    1476                 :          0 :                         (uint16_t)(txq->tx_next_rs + txq->tx_rs_thresh);
    1477         [ #  # ]:          0 :                 if (txq->tx_next_rs >= txq->nb_tx_desc)
    1478                 :          0 :                         txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
    1479                 :            :         }
    1480                 :            : 
    1481         [ #  # ]:          0 :         if (txq->tx_tail >= txq->nb_tx_desc)
    1482                 :          0 :                 txq->tx_tail = 0;
    1483                 :            : 
    1484                 :            :         /* Update the tx tail register */
    1485                 :          0 :         I40E_PCI_REG_WC_WRITE(txq->qtx_tail, txq->tx_tail);
    1486                 :            : 
    1487                 :            :         return nb_pkts;
    1488                 :            : }
    1489                 :            : 
    1490                 :            : static uint16_t
    1491                 :          0 : i40e_xmit_pkts_simple(void *tx_queue,
    1492                 :            :                       struct rte_mbuf **tx_pkts,
    1493                 :            :                       uint16_t nb_pkts)
    1494                 :            : {
    1495                 :            :         uint16_t nb_tx = 0;
    1496                 :            : 
    1497         [ #  # ]:          0 :         if (likely(nb_pkts <= I40E_TX_MAX_BURST))
    1498                 :          0 :                 return tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
    1499                 :            :                                                 tx_pkts, nb_pkts);
    1500                 :            : 
    1501         [ #  # ]:          0 :         while (nb_pkts) {
    1502                 :          0 :                 uint16_t ret, num = (uint16_t)RTE_MIN(nb_pkts,
    1503                 :            :                                                 I40E_TX_MAX_BURST);
    1504                 :            : 
    1505                 :          0 :                 ret = tx_xmit_pkts((struct i40e_tx_queue *)tx_queue,
    1506                 :          0 :                                                 &tx_pkts[nb_tx], num);
    1507                 :          0 :                 nb_tx = (uint16_t)(nb_tx + ret);
    1508                 :          0 :                 nb_pkts = (uint16_t)(nb_pkts - ret);
    1509         [ #  # ]:          0 :                 if (ret < num)
    1510                 :            :                         break;
    1511                 :            :         }
    1512                 :            : 
    1513                 :            :         return nb_tx;
    1514                 :            : }
    1515                 :            : 
    1516                 :            : static uint16_t
    1517                 :          0 : i40e_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
    1518                 :            :                    uint16_t nb_pkts)
    1519                 :            : {
    1520                 :            :         uint16_t nb_tx = 0;
    1521                 :            :         struct i40e_tx_queue *txq = (struct i40e_tx_queue *)tx_queue;
    1522                 :            : 
    1523         [ #  # ]:          0 :         while (nb_pkts) {
    1524                 :            :                 uint16_t ret, num;
    1525                 :            : 
    1526                 :            :                 /* cross rs_thresh boundary is not allowed */
    1527                 :          0 :                 num = (uint16_t)RTE_MIN(nb_pkts, txq->tx_rs_thresh);
    1528                 :          0 :                 ret = i40e_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
    1529                 :            :                                                 num);
    1530                 :          0 :                 nb_tx += ret;
    1531                 :          0 :                 nb_pkts -= ret;
    1532         [ #  # ]:          0 :                 if (ret < num)
    1533                 :            :                         break;
    1534                 :            :         }
    1535                 :            : 
    1536                 :          0 :         return nb_tx;
    1537                 :            : }
    1538                 :            : 
    1539                 :            : /*********************************************************************
    1540                 :            :  *
    1541                 :            :  *  TX simple prep functions
    1542                 :            :  *
    1543                 :            :  **********************************************************************/
    1544                 :            : uint16_t
    1545                 :          0 : i40e_simple_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
    1546                 :            :                       uint16_t nb_pkts)
    1547                 :            : {
    1548                 :            :         int i;
    1549                 :            :         uint64_t ol_flags;
    1550                 :            :         struct rte_mbuf *m;
    1551                 :            : 
    1552         [ #  # ]:          0 :         for (i = 0; i < nb_pkts; i++) {
    1553                 :          0 :                 m = tx_pkts[i];
    1554                 :          0 :                 ol_flags = m->ol_flags;
    1555                 :            : 
    1556         [ #  # ]:          0 :                 if (m->nb_segs != 1) {
    1557                 :          0 :                         rte_errno = EINVAL;
    1558                 :          0 :                         return i;
    1559                 :            :                 }
    1560                 :            : 
    1561         [ #  # ]:          0 :                 if (ol_flags & I40E_TX_OFFLOAD_SIMPLE_NOTSUP_MASK) {
    1562                 :          0 :                         rte_errno = ENOTSUP;
    1563                 :          0 :                         return i;
    1564                 :            :                 }
    1565                 :            : 
    1566                 :            :                 /* check the size of packet */
    1567         [ #  # ]:          0 :                 if (m->pkt_len < I40E_TX_MIN_PKT_LEN ||
    1568                 :            :                     m->pkt_len > I40E_FRAME_SIZE_MAX) {
    1569                 :          0 :                         rte_errno = EINVAL;
    1570                 :          0 :                         return i;
    1571                 :            :                 }
    1572                 :            :         }
    1573                 :          0 :         return i;
    1574                 :            : }
    1575                 :            : 
    1576                 :            : /*********************************************************************
    1577                 :            :  *
    1578                 :            :  *  TX prep functions
    1579                 :            :  *
    1580                 :            :  **********************************************************************/
    1581                 :            : uint16_t
    1582                 :          0 : i40e_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
    1583                 :            :                 uint16_t nb_pkts)
    1584                 :            : {
    1585                 :            :         int i, ret;
    1586                 :            :         uint64_t ol_flags;
    1587                 :            :         struct rte_mbuf *m;
    1588                 :            : 
    1589         [ #  # ]:          0 :         for (i = 0; i < nb_pkts; i++) {
    1590                 :          0 :                 m = tx_pkts[i];
    1591                 :          0 :                 ol_flags = m->ol_flags;
    1592                 :            : 
    1593                 :            :                 /* Check for m->nb_segs to not exceed the limits. */
    1594         [ #  # ]:          0 :                 if (!(ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
    1595         [ #  # ]:          0 :                         if (m->nb_segs > I40E_TX_MAX_MTU_SEG ||
    1596         [ #  # ]:          0 :                             m->pkt_len > I40E_FRAME_SIZE_MAX) {
    1597                 :          0 :                                 rte_errno = EINVAL;
    1598                 :          0 :                                 return i;
    1599                 :            :                         }
    1600         [ #  # ]:          0 :                 } else if (m->nb_segs > I40E_TX_MAX_SEG ||
    1601   [ #  #  #  # ]:          0 :                            m->tso_segsz < I40E_MIN_TSO_MSS ||
    1602                 :          0 :                            m->tso_segsz > I40E_MAX_TSO_MSS ||
    1603         [ #  # ]:          0 :                            m->pkt_len > I40E_TSO_FRAME_SIZE_MAX) {
    1604                 :            :                         /* MSS outside the range (256B - 9674B) are considered
    1605                 :            :                          * malicious
    1606                 :            :                          */
    1607                 :          0 :                         rte_errno = EINVAL;
    1608                 :          0 :                         return i;
    1609                 :            :                 }
    1610                 :            : 
    1611         [ #  # ]:          0 :                 if (ol_flags & I40E_TX_OFFLOAD_NOTSUP_MASK) {
    1612                 :          0 :                         rte_errno = ENOTSUP;
    1613                 :          0 :                         return i;
    1614                 :            :                 }
    1615                 :            : 
    1616                 :            :                 /* check the size of packet */
    1617         [ #  # ]:          0 :                 if (m->pkt_len < I40E_TX_MIN_PKT_LEN) {
    1618                 :          0 :                         rte_errno = EINVAL;
    1619                 :          0 :                         return i;
    1620                 :            :                 }
    1621                 :            : 
    1622                 :            : #ifdef RTE_ETHDEV_DEBUG_TX
    1623                 :            :                 ret = rte_validate_tx_offload(m);
    1624                 :            :                 if (ret != 0) {
    1625                 :            :                         rte_errno = -ret;
    1626                 :            :                         return i;
    1627                 :            :                 }
    1628                 :            : #endif
    1629                 :            :                 ret = rte_net_intel_cksum_prepare(m);
    1630         [ #  # ]:          0 :                 if (ret != 0) {
    1631                 :          0 :                         rte_errno = -ret;
    1632                 :          0 :                         return i;
    1633                 :            :                 }
    1634                 :            :         }
    1635                 :          0 :         return i;
    1636                 :            : }
    1637                 :            : 
    1638                 :            : /*
    1639                 :            :  * Find the VSI the queue belongs to. 'queue_idx' is the queue index
    1640                 :            :  * application used, which assume having sequential ones. But from driver's
    1641                 :            :  * perspective, it's different. For example, q0 belongs to FDIR VSI, q1-q64
    1642                 :            :  * to MAIN VSI, , q65-96 to SRIOV VSIs, q97-128 to VMDQ VSIs. For application
    1643                 :            :  * running on host, q1-64 and q97-128 can be used, total 96 queues. They can
    1644                 :            :  * use queue_idx from 0 to 95 to access queues, while real queue would be
    1645                 :            :  * different. This function will do a queue mapping to find VSI the queue
    1646                 :            :  * belongs to.
    1647                 :            :  */
    1648                 :            : static struct i40e_vsi*
    1649                 :          0 : i40e_pf_get_vsi_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
    1650                 :            : {
    1651                 :            :         /* the queue in MAIN VSI range */
    1652         [ #  # ]:          0 :         if (queue_idx < pf->main_vsi->nb_qps)
    1653                 :            :                 return pf->main_vsi;
    1654                 :            : 
    1655                 :          0 :         queue_idx -= pf->main_vsi->nb_qps;
    1656                 :            : 
    1657                 :            :         /* queue_idx is greater than VMDQ VSIs range */
    1658         [ #  # ]:          0 :         if (queue_idx > pf->nb_cfg_vmdq_vsi * pf->vmdq_nb_qps - 1) {
    1659                 :          0 :                 PMD_INIT_LOG(ERR, "queue_idx out of range. VMDQ configured?");
    1660                 :          0 :                 return NULL;
    1661                 :            :         }
    1662                 :            : 
    1663                 :          0 :         return pf->vmdq[queue_idx / pf->vmdq_nb_qps].vsi;
    1664                 :            : }
    1665                 :            : 
    1666                 :            : static uint16_t
    1667                 :          0 : i40e_get_queue_offset_by_qindex(struct i40e_pf *pf, uint16_t queue_idx)
    1668                 :            : {
    1669                 :            :         /* the queue in MAIN VSI range */
    1670         [ #  # ]:          0 :         if (queue_idx < pf->main_vsi->nb_qps)
    1671                 :            :                 return queue_idx;
    1672                 :            : 
    1673                 :            :         /* It's VMDQ queues */
    1674                 :          0 :         queue_idx -= pf->main_vsi->nb_qps;
    1675                 :            : 
    1676         [ #  # ]:          0 :         if (pf->nb_cfg_vmdq_vsi)
    1677                 :          0 :                 return queue_idx % pf->vmdq_nb_qps;
    1678                 :            :         else {
    1679                 :          0 :                 PMD_INIT_LOG(ERR, "Fail to get queue offset");
    1680                 :          0 :                 return (uint16_t)(-1);
    1681                 :            :         }
    1682                 :            : }
    1683                 :            : 
    1684                 :            : int
    1685                 :          0 : i40e_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    1686                 :            : {
    1687                 :            :         struct i40e_rx_queue *rxq;
    1688                 :            :         int err;
    1689                 :          0 :         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1690                 :            : 
    1691                 :          0 :         PMD_INIT_FUNC_TRACE();
    1692                 :            : 
    1693                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
    1694   [ #  #  #  # ]:          0 :         if (!rxq || !rxq->q_set) {
    1695                 :          0 :                 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
    1696                 :            :                             rx_queue_id);
    1697                 :          0 :                 return -EINVAL;
    1698                 :            :         }
    1699                 :            : 
    1700         [ #  # ]:          0 :         if (rxq->rx_deferred_start)
    1701                 :          0 :                 PMD_DRV_LOG(WARNING, "RX queue %u is deferred start",
    1702                 :            :                             rx_queue_id);
    1703                 :            : 
    1704                 :          0 :         err = i40e_alloc_rx_queue_mbufs(rxq);
    1705         [ #  # ]:          0 :         if (err) {
    1706                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
    1707                 :          0 :                 return err;
    1708                 :            :         }
    1709                 :            : 
    1710                 :            :         /* Init the RX tail register. */
    1711                 :          0 :         I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
    1712                 :            : 
    1713                 :          0 :         err = i40e_switch_rx_queue(hw, rxq->reg_idx, TRUE);
    1714         [ #  # ]:          0 :         if (err) {
    1715                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
    1716                 :            :                             rx_queue_id);
    1717                 :            : 
    1718                 :          0 :                 i40e_rx_queue_release_mbufs(rxq);
    1719                 :          0 :                 i40e_reset_rx_queue(rxq);
    1720                 :          0 :                 return err;
    1721                 :            :         }
    1722                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
    1723                 :            : 
    1724                 :          0 :         return 0;
    1725                 :            : }
    1726                 :            : 
    1727                 :            : int
    1728                 :          0 : i40e_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
    1729                 :            : {
    1730                 :            :         struct i40e_rx_queue *rxq;
    1731                 :            :         int err;
    1732                 :          0 :         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1733                 :            : 
    1734                 :          0 :         rxq = dev->data->rx_queues[rx_queue_id];
    1735   [ #  #  #  # ]:          0 :         if (!rxq || !rxq->q_set) {
    1736                 :          0 :                 PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
    1737                 :            :                                 rx_queue_id);
    1738                 :          0 :                 return -EINVAL;
    1739                 :            :         }
    1740                 :            : 
    1741                 :            :         /*
    1742                 :            :          * rx_queue_id is queue id application refers to, while
    1743                 :            :          * rxq->reg_idx is the real queue index.
    1744                 :            :          */
    1745                 :          0 :         err = i40e_switch_rx_queue(hw, rxq->reg_idx, FALSE);
    1746         [ #  # ]:          0 :         if (err) {
    1747                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
    1748                 :            :                             rx_queue_id);
    1749                 :          0 :                 return err;
    1750                 :            :         }
    1751                 :          0 :         i40e_rx_queue_release_mbufs(rxq);
    1752                 :          0 :         i40e_reset_rx_queue(rxq);
    1753                 :          0 :         dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
    1754                 :            : 
    1755                 :          0 :         return 0;
    1756                 :            : }
    1757                 :            : 
    1758                 :            : int
    1759                 :          0 : i40e_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
    1760                 :            : {
    1761                 :            :         int err;
    1762                 :            :         struct i40e_tx_queue *txq;
    1763                 :          0 :         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1764                 :            : 
    1765                 :          0 :         PMD_INIT_FUNC_TRACE();
    1766                 :            : 
    1767                 :          0 :         txq = dev->data->tx_queues[tx_queue_id];
    1768   [ #  #  #  # ]:          0 :         if (!txq || !txq->q_set) {
    1769                 :          0 :                 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
    1770                 :            :                             tx_queue_id);
    1771                 :          0 :                 return -EINVAL;
    1772                 :            :         }
    1773                 :            : 
    1774         [ #  # ]:          0 :         if (txq->tx_deferred_start)
    1775                 :          0 :                 PMD_DRV_LOG(WARNING, "TX queue %u is deferred start",
    1776                 :            :                             tx_queue_id);
    1777                 :            : 
    1778                 :            :         /*
    1779                 :            :          * tx_queue_id is queue id application refers to, while
    1780                 :            :          * rxq->reg_idx is the real queue index.
    1781                 :            :          */
    1782                 :          0 :         err = i40e_switch_tx_queue(hw, txq->reg_idx, TRUE);
    1783         [ #  # ]:          0 :         if (err) {
    1784                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
    1785                 :            :                             tx_queue_id);
    1786                 :          0 :                 return err;
    1787                 :            :         }
    1788                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
    1789                 :            : 
    1790                 :          0 :         return 0;
    1791                 :            : }
    1792                 :            : 
    1793                 :            : int
    1794                 :          0 : i40e_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
    1795                 :            : {
    1796                 :            :         struct i40e_tx_queue *txq;
    1797                 :            :         int err;
    1798                 :          0 :         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1799                 :            : 
    1800                 :          0 :         txq = dev->data->tx_queues[tx_queue_id];
    1801   [ #  #  #  # ]:          0 :         if (!txq || !txq->q_set) {
    1802                 :          0 :                 PMD_DRV_LOG(ERR, "TX queue %u is not available or setup",
    1803                 :            :                         tx_queue_id);
    1804                 :          0 :                 return -EINVAL;
    1805                 :            :         }
    1806                 :            : 
    1807                 :            :         /*
    1808                 :            :          * tx_queue_id is queue id application refers to, while
    1809                 :            :          * txq->reg_idx is the real queue index.
    1810                 :            :          */
    1811                 :          0 :         err = i40e_switch_tx_queue(hw, txq->reg_idx, FALSE);
    1812         [ #  # ]:          0 :         if (err) {
    1813                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to switch TX queue %u of",
    1814                 :            :                             tx_queue_id);
    1815                 :          0 :                 return err;
    1816                 :            :         }
    1817                 :            : 
    1818                 :          0 :         i40e_tx_queue_release_mbufs(txq);
    1819                 :          0 :         i40e_reset_tx_queue(txq);
    1820                 :          0 :         dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
    1821                 :            : 
    1822                 :          0 :         return 0;
    1823                 :            : }
    1824                 :            : 
    1825                 :            : const uint32_t *
    1826                 :          0 : i40e_dev_supported_ptypes_get(struct rte_eth_dev *dev)
    1827                 :            : {
    1828                 :            :         static const uint32_t ptypes[] = {
    1829                 :            :                 /* refers to i40e_rxd_pkt_type_mapping() */
    1830                 :            :                 RTE_PTYPE_L2_ETHER,
    1831                 :            :                 RTE_PTYPE_L2_ETHER_TIMESYNC,
    1832                 :            :                 RTE_PTYPE_L2_ETHER_LLDP,
    1833                 :            :                 RTE_PTYPE_L2_ETHER_ARP,
    1834                 :            :                 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
    1835                 :            :                 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
    1836                 :            :                 RTE_PTYPE_L4_FRAG,
    1837                 :            :                 RTE_PTYPE_L4_ICMP,
    1838                 :            :                 RTE_PTYPE_L4_NONFRAG,
    1839                 :            :                 RTE_PTYPE_L4_SCTP,
    1840                 :            :                 RTE_PTYPE_L4_TCP,
    1841                 :            :                 RTE_PTYPE_L4_UDP,
    1842                 :            :                 RTE_PTYPE_TUNNEL_GRENAT,
    1843                 :            :                 RTE_PTYPE_TUNNEL_IP,
    1844                 :            :                 RTE_PTYPE_INNER_L2_ETHER,
    1845                 :            :                 RTE_PTYPE_INNER_L2_ETHER_VLAN,
    1846                 :            :                 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
    1847                 :            :                 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
    1848                 :            :                 RTE_PTYPE_INNER_L4_FRAG,
    1849                 :            :                 RTE_PTYPE_INNER_L4_ICMP,
    1850                 :            :                 RTE_PTYPE_INNER_L4_NONFRAG,
    1851                 :            :                 RTE_PTYPE_INNER_L4_SCTP,
    1852                 :            :                 RTE_PTYPE_INNER_L4_TCP,
    1853                 :            :                 RTE_PTYPE_INNER_L4_UDP,
    1854                 :            :                 RTE_PTYPE_UNKNOWN
    1855                 :            :         };
    1856                 :            : 
    1857   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == i40e_recv_pkts ||
    1858                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
    1859         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_pkts_bulk_alloc ||
    1860                 :            : #endif
    1861         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_scattered_pkts ||
    1862         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
    1863         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_pkts_vec ||
    1864                 :            : #ifdef CC_AVX512_SUPPORT
    1865         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
    1866         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
    1867                 :            : #endif
    1868         [ #  # ]:          0 :             dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
    1869                 :            :             dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2)
    1870                 :          0 :                 return ptypes;
    1871                 :            :         return NULL;
    1872                 :            : }
    1873                 :            : 
    1874                 :            : static int
    1875                 :            : i40e_dev_first_queue(uint16_t idx, void **queues, int num)
    1876                 :            : {
    1877                 :            :         uint16_t i;
    1878                 :            : 
    1879   [ #  #  #  # ]:          0 :         for (i = 0; i < num; i++) {
    1880   [ #  #  #  #  :          0 :                 if (i != idx && queues[i])
             #  #  #  # ]
    1881                 :            :                         return 0;
    1882                 :            :         }
    1883                 :            : 
    1884                 :            :         return 1;
    1885                 :            : }
    1886                 :            : 
    1887                 :            : static int
    1888                 :          0 : i40e_dev_rx_queue_setup_runtime(struct rte_eth_dev *dev,
    1889                 :            :                                 struct i40e_rx_queue *rxq)
    1890                 :            : {
    1891                 :          0 :         struct i40e_adapter *ad =
    1892                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    1893                 :            :         int use_def_burst_func =
    1894                 :          0 :                 check_rx_burst_bulk_alloc_preconditions(rxq);
    1895                 :          0 :         uint16_t buf_size =
    1896         [ #  # ]:          0 :                 (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
    1897                 :            :                            RTE_PKTMBUF_HEADROOM);
    1898                 :            :         int use_scattered_rx =
    1899                 :          0 :                 (rxq->max_pkt_len > buf_size);
    1900                 :            : 
    1901         [ #  # ]:          0 :         if (i40e_rx_queue_init(rxq) != I40E_SUCCESS) {
    1902                 :          0 :                 PMD_DRV_LOG(ERR,
    1903                 :            :                             "Failed to do RX queue initialization");
    1904                 :          0 :                 return -EINVAL;
    1905                 :            :         }
    1906                 :            : 
    1907         [ #  # ]:          0 :         if (i40e_dev_first_queue(rxq->queue_id,
    1908                 :            :                                  dev->data->rx_queues,
    1909                 :          0 :                                  dev->data->nb_rx_queues)) {
    1910                 :            :                 /**
    1911                 :            :                  * If it is the first queue to setup,
    1912                 :            :                  * set all flags to default and call
    1913                 :            :                  * i40e_set_rx_function.
    1914                 :            :                  */
    1915                 :          0 :                 ad->rx_bulk_alloc_allowed = true;
    1916                 :          0 :                 ad->rx_vec_allowed = true;
    1917                 :          0 :                 dev->data->scattered_rx = use_scattered_rx;
    1918         [ #  # ]:          0 :                 if (use_def_burst_func)
    1919                 :          0 :                         ad->rx_bulk_alloc_allowed = false;
    1920                 :          0 :                 i40e_set_rx_function(dev);
    1921                 :            : 
    1922   [ #  #  #  # ]:          0 :                 if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
    1923                 :          0 :                         PMD_DRV_LOG(ERR, "Failed vector rx setup.");
    1924                 :          0 :                         return -EINVAL;
    1925                 :            :                 }
    1926                 :            : 
    1927                 :          0 :                 return 0;
    1928   [ #  #  #  # ]:          0 :         } else if (ad->rx_vec_allowed && !rte_is_power_of_2(rxq->nb_rx_desc)) {
    1929                 :          0 :                 PMD_DRV_LOG(ERR, "Vector mode is allowed, but descriptor"
    1930                 :            :                             " number %d of queue %d isn't power of 2",
    1931                 :            :                             rxq->nb_rx_desc, rxq->queue_id);
    1932                 :          0 :                 return -EINVAL;
    1933                 :            :         }
    1934                 :            : 
    1935                 :            :         /* check bulk alloc conflict */
    1936   [ #  #  #  # ]:          0 :         if (ad->rx_bulk_alloc_allowed && use_def_burst_func) {
    1937                 :          0 :                 PMD_DRV_LOG(ERR, "Can't use default burst.");
    1938                 :          0 :                 return -EINVAL;
    1939                 :            :         }
    1940                 :            :         /* check scattered conflict */
    1941   [ #  #  #  # ]:          0 :         if (!dev->data->scattered_rx && use_scattered_rx) {
    1942                 :          0 :                 PMD_DRV_LOG(ERR, "Scattered rx is required.");
    1943                 :          0 :                 return -EINVAL;
    1944                 :            :         }
    1945                 :            :         /* check vector conflict */
    1946   [ #  #  #  # ]:          0 :         if (ad->rx_vec_allowed && i40e_rxq_vec_setup(rxq)) {
    1947                 :          0 :                 PMD_DRV_LOG(ERR, "Failed vector rx setup.");
    1948                 :          0 :                 return -EINVAL;
    1949                 :            :         }
    1950                 :            : 
    1951                 :            :         return 0;
    1952                 :            : }
    1953                 :            : 
    1954                 :            : int
    1955                 :          0 : i40e_dev_rx_queue_setup(struct rte_eth_dev *dev,
    1956                 :            :                         uint16_t queue_idx,
    1957                 :            :                         uint16_t nb_desc,
    1958                 :            :                         unsigned int socket_id,
    1959                 :            :                         const struct rte_eth_rxconf *rx_conf,
    1960                 :            :                         struct rte_mempool *mp)
    1961                 :            : {
    1962                 :          0 :         struct i40e_adapter *ad =
    1963                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    1964                 :            :         struct i40e_vsi *vsi;
    1965                 :            :         struct i40e_pf *pf = NULL;
    1966                 :            :         struct i40e_rx_queue *rxq;
    1967                 :            :         const struct rte_memzone *rz;
    1968                 :            :         uint32_t ring_size;
    1969                 :            :         uint16_t len, i;
    1970                 :            :         uint16_t reg_idx, base, bsf, tc_mapping;
    1971                 :            :         int q_offset, use_def_burst_func = 1;
    1972                 :            :         uint64_t offloads;
    1973                 :            : 
    1974                 :          0 :         offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
    1975                 :            : 
    1976                 :          0 :         pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
    1977                 :          0 :         vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
    1978         [ #  # ]:          0 :         if (!vsi)
    1979                 :            :                 return -EINVAL;
    1980                 :          0 :         q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
    1981                 :            :         if (q_offset < 0)
    1982                 :            :                 return -EINVAL;
    1983                 :          0 :         reg_idx = vsi->base_queue + q_offset;
    1984                 :            : 
    1985         [ #  # ]:          0 :         if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
    1986         [ #  # ]:          0 :             (nb_desc > I40E_MAX_RING_DESC) ||
    1987                 :            :             (nb_desc < I40E_MIN_RING_DESC)) {
    1988                 :          0 :                 PMD_DRV_LOG(ERR, "Number (%u) of receive descriptors is "
    1989                 :            :                             "invalid", nb_desc);
    1990                 :          0 :                 return -EINVAL;
    1991                 :            :         }
    1992                 :            : 
    1993                 :            :         /* Free memory if needed */
    1994         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_idx]) {
    1995                 :          0 :                 i40e_rx_queue_release(dev->data->rx_queues[queue_idx]);
    1996                 :          0 :                 dev->data->rx_queues[queue_idx] = NULL;
    1997                 :            :         }
    1998                 :            : 
    1999                 :            :         /* Allocate the rx queue data structure */
    2000                 :          0 :         rxq = rte_zmalloc_socket("i40e rx queue",
    2001                 :            :                                  sizeof(struct i40e_rx_queue),
    2002                 :            :                                  RTE_CACHE_LINE_SIZE,
    2003                 :            :                                  socket_id);
    2004         [ #  # ]:          0 :         if (!rxq) {
    2005                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
    2006                 :            :                             "rx queue data structure");
    2007                 :          0 :                 return -ENOMEM;
    2008                 :            :         }
    2009                 :          0 :         rxq->mp = mp;
    2010                 :          0 :         rxq->nb_rx_desc = nb_desc;
    2011                 :          0 :         rxq->rx_free_thresh = rx_conf->rx_free_thresh;
    2012                 :          0 :         rxq->queue_id = queue_idx;
    2013                 :          0 :         rxq->reg_idx = reg_idx;
    2014                 :          0 :         rxq->port_id = dev->data->port_id;
    2015         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    2016                 :          0 :                 rxq->crc_len = RTE_ETHER_CRC_LEN;
    2017                 :            :         else
    2018                 :          0 :                 rxq->crc_len = 0;
    2019                 :          0 :         rxq->drop_en = rx_conf->rx_drop_en;
    2020                 :          0 :         rxq->vsi = vsi;
    2021                 :          0 :         rxq->rx_deferred_start = rx_conf->rx_deferred_start;
    2022                 :          0 :         rxq->offloads = offloads;
    2023                 :            : 
    2024                 :            :         /* Allocate the maximum number of RX ring hardware descriptor. */
    2025                 :            :         len = I40E_MAX_RING_DESC;
    2026                 :            : 
    2027                 :            :         /**
    2028                 :            :          * Allocating a little more memory because vectorized/bulk_alloc Rx
    2029                 :            :          * functions doesn't check boundaries each time.
    2030                 :            :          */
    2031                 :            :         len += RTE_PMD_I40E_RX_MAX_BURST;
    2032                 :            : 
    2033                 :            :         ring_size = RTE_ALIGN(len * sizeof(union i40e_rx_desc),
    2034                 :            :                               I40E_DMA_MEM_ALIGN);
    2035                 :            : 
    2036                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
    2037                 :            :                               ring_size, I40E_RING_BASE_ALIGN, socket_id);
    2038         [ #  # ]:          0 :         if (!rz) {
    2039                 :          0 :                 i40e_rx_queue_release(rxq);
    2040                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX");
    2041                 :          0 :                 return -ENOMEM;
    2042                 :            :         }
    2043                 :            : 
    2044                 :          0 :         rxq->mz = rz;
    2045                 :            :         /* Zero all the descriptors in the ring. */
    2046                 :          0 :         memset(rz->addr, 0, ring_size);
    2047                 :            : 
    2048                 :          0 :         rxq->rx_ring_phys_addr = rz->iova;
    2049                 :          0 :         rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
    2050                 :            : 
    2051                 :          0 :         len = (uint16_t)(nb_desc + RTE_PMD_I40E_RX_MAX_BURST);
    2052                 :            : 
    2053                 :            :         /* Allocate the software ring. */
    2054                 :          0 :         rxq->sw_ring =
    2055                 :          0 :                 rte_zmalloc_socket("i40e rx sw ring",
    2056                 :            :                                    sizeof(struct i40e_rx_entry) * len,
    2057                 :            :                                    RTE_CACHE_LINE_SIZE,
    2058                 :            :                                    socket_id);
    2059         [ #  # ]:          0 :         if (!rxq->sw_ring) {
    2060                 :          0 :                 i40e_rx_queue_release(rxq);
    2061                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW ring");
    2062                 :          0 :                 return -ENOMEM;
    2063                 :            :         }
    2064                 :            : 
    2065                 :          0 :         i40e_reset_rx_queue(rxq);
    2066                 :          0 :         rxq->q_set = TRUE;
    2067                 :            : 
    2068         [ #  # ]:          0 :         for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
    2069         [ #  # ]:          0 :                 if (!(vsi->enabled_tc & (1 << i)))
    2070                 :          0 :                         continue;
    2071                 :          0 :                 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
    2072                 :          0 :                 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
    2073                 :            :                         I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
    2074                 :          0 :                 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
    2075                 :            :                         I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
    2076                 :            : 
    2077   [ #  #  #  # ]:          0 :                 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
    2078                 :          0 :                         rxq->dcb_tc = i;
    2079                 :            :         }
    2080                 :            : 
    2081         [ #  # ]:          0 :         if (dev->data->dev_started) {
    2082         [ #  # ]:          0 :                 if (i40e_dev_rx_queue_setup_runtime(dev, rxq)) {
    2083                 :          0 :                         i40e_rx_queue_release(rxq);
    2084                 :          0 :                         return -EINVAL;
    2085                 :            :                 }
    2086                 :            :         } else {
    2087                 :            :                 use_def_burst_func =
    2088                 :          0 :                         check_rx_burst_bulk_alloc_preconditions(rxq);
    2089         [ #  # ]:          0 :                 if (!use_def_burst_func) {
    2090                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
    2091                 :          0 :                         PMD_INIT_LOG(DEBUG,
    2092                 :            :                           "Rx Burst Bulk Alloc Preconditions are "
    2093                 :            :                           "satisfied. Rx Burst Bulk Alloc function will be "
    2094                 :            :                           "used on port=%d, queue=%d.",
    2095                 :            :                           rxq->port_id, rxq->queue_id);
    2096                 :            : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
    2097                 :            :                 } else {
    2098                 :          0 :                         PMD_INIT_LOG(DEBUG,
    2099                 :            :                           "Rx Burst Bulk Alloc Preconditions are "
    2100                 :            :                           "not satisfied, Scattered Rx is requested, "
    2101                 :            :                           "or RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC is "
    2102                 :            :                           "not enabled on port=%d, queue=%d.",
    2103                 :            :                           rxq->port_id, rxq->queue_id);
    2104                 :          0 :                         ad->rx_bulk_alloc_allowed = false;
    2105                 :            :                 }
    2106                 :            :         }
    2107                 :            : 
    2108                 :          0 :         dev->data->rx_queues[queue_idx] = rxq;
    2109                 :          0 :         return 0;
    2110                 :            : }
    2111                 :            : 
    2112                 :            : void
    2113                 :          0 : i40e_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    2114                 :            : {
    2115                 :          0 :         i40e_rx_queue_release(dev->data->rx_queues[qid]);
    2116                 :          0 : }
    2117                 :            : 
    2118                 :            : void
    2119                 :          0 : i40e_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    2120                 :            : {
    2121                 :          0 :         i40e_tx_queue_release(dev->data->tx_queues[qid]);
    2122                 :          0 : }
    2123                 :            : 
    2124                 :            : void
    2125                 :          0 : i40e_rx_queue_release(void *rxq)
    2126                 :            : {
    2127                 :            :         struct i40e_rx_queue *q = (struct i40e_rx_queue *)rxq;
    2128                 :            : 
    2129         [ #  # ]:          0 :         if (!q) {
    2130                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
    2131                 :          0 :                 return;
    2132                 :            :         }
    2133                 :            : 
    2134                 :          0 :         i40e_rx_queue_release_mbufs(q);
    2135                 :          0 :         rte_free(q->sw_ring);
    2136                 :          0 :         rte_memzone_free(q->mz);
    2137                 :          0 :         rte_free(q);
    2138                 :            : }
    2139                 :            : 
    2140                 :            : uint32_t
    2141                 :          0 : i40e_dev_rx_queue_count(void *rx_queue)
    2142                 :            : {
    2143                 :            : #define I40E_RXQ_SCAN_INTERVAL 4
    2144                 :            :         volatile union i40e_rx_desc *rxdp;
    2145                 :            :         struct i40e_rx_queue *rxq;
    2146                 :            :         uint16_t desc = 0;
    2147                 :            : 
    2148                 :            :         rxq = rx_queue;
    2149                 :          0 :         rxdp = &(rxq->rx_ring[rxq->rx_tail]);
    2150         [ #  # ]:          0 :         while ((desc < rxq->nb_rx_desc) &&
    2151                 :          0 :                 ((rte_le_to_cpu_64(rxdp->wb.qword1.status_error_len) &
    2152         [ #  # ]:          0 :                 I40E_RXD_QW1_STATUS_MASK) >> I40E_RXD_QW1_STATUS_SHIFT) &
    2153                 :            :                                 (1 << I40E_RX_DESC_STATUS_DD_SHIFT)) {
    2154                 :            :                 /**
    2155                 :            :                  * Check the DD bit of a rx descriptor of each 4 in a group,
    2156                 :            :                  * to avoid checking too frequently and downgrading performance
    2157                 :            :                  * too much.
    2158                 :            :                  */
    2159                 :          0 :                 desc += I40E_RXQ_SCAN_INTERVAL;
    2160                 :          0 :                 rxdp += I40E_RXQ_SCAN_INTERVAL;
    2161         [ #  # ]:          0 :                 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
    2162                 :          0 :                         rxdp = &(rxq->rx_ring[rxq->rx_tail +
    2163                 :          0 :                                         desc - rxq->nb_rx_desc]);
    2164                 :            :         }
    2165                 :            : 
    2166                 :          0 :         return desc;
    2167                 :            : }
    2168                 :            : 
    2169                 :            : int
    2170                 :          0 : i40e_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
    2171                 :            : {
    2172                 :            :         struct i40e_rx_queue *rxq = rx_queue;
    2173                 :            :         volatile uint64_t *status;
    2174                 :            :         uint64_t mask;
    2175                 :            :         uint32_t desc;
    2176                 :            : 
    2177         [ #  # ]:          0 :         if (unlikely(offset >= rxq->nb_rx_desc))
    2178                 :            :                 return -EINVAL;
    2179                 :            : 
    2180         [ #  # ]:          0 :         if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
    2181                 :            :                 return RTE_ETH_RX_DESC_UNAVAIL;
    2182                 :            : 
    2183                 :          0 :         desc = rxq->rx_tail + offset;
    2184         [ #  # ]:          0 :         if (desc >= rxq->nb_rx_desc)
    2185                 :          0 :                 desc -= rxq->nb_rx_desc;
    2186                 :            : 
    2187                 :          0 :         status = &rxq->rx_ring[desc].wb.qword1.status_error_len;
    2188                 :            :         mask = rte_le_to_cpu_64((1ULL << I40E_RX_DESC_STATUS_DD_SHIFT)
    2189                 :            :                 << I40E_RXD_QW1_STATUS_SHIFT);
    2190         [ #  # ]:          0 :         if (*status & mask)
    2191                 :          0 :                 return RTE_ETH_RX_DESC_DONE;
    2192                 :            : 
    2193                 :            :         return RTE_ETH_RX_DESC_AVAIL;
    2194                 :            : }
    2195                 :            : 
    2196                 :            : int
    2197                 :          0 : i40e_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
    2198                 :            : {
    2199                 :            :         struct i40e_tx_queue *txq = tx_queue;
    2200                 :            :         volatile uint64_t *status;
    2201                 :            :         uint64_t mask, expect;
    2202                 :            :         uint32_t desc;
    2203                 :            : 
    2204         [ #  # ]:          0 :         if (unlikely(offset >= txq->nb_tx_desc))
    2205                 :            :                 return -EINVAL;
    2206                 :            : 
    2207                 :          0 :         desc = txq->tx_tail + offset;
    2208                 :            :         /* go to next desc that has the RS bit */
    2209                 :          0 :         desc = ((desc + txq->tx_rs_thresh - 1) / txq->tx_rs_thresh) *
    2210                 :            :                 txq->tx_rs_thresh;
    2211         [ #  # ]:          0 :         if (desc >= txq->nb_tx_desc) {
    2212                 :          0 :                 desc -= txq->nb_tx_desc;
    2213         [ #  # ]:          0 :                 if (desc >= txq->nb_tx_desc)
    2214                 :          0 :                         desc -= txq->nb_tx_desc;
    2215                 :            :         }
    2216                 :            : 
    2217                 :          0 :         status = &txq->tx_ring[desc].cmd_type_offset_bsz;
    2218                 :            :         mask = rte_le_to_cpu_64(I40E_TXD_QW1_DTYPE_MASK);
    2219                 :            :         expect = rte_cpu_to_le_64(
    2220                 :            :                 I40E_TX_DESC_DTYPE_DESC_DONE << I40E_TXD_QW1_DTYPE_SHIFT);
    2221         [ #  # ]:          0 :         if ((*status & mask) == expect)
    2222                 :          0 :                 return RTE_ETH_TX_DESC_DONE;
    2223                 :            : 
    2224                 :            :         return RTE_ETH_TX_DESC_FULL;
    2225                 :            : }
    2226                 :            : 
    2227                 :            : static int
    2228                 :          0 : i40e_dev_tx_queue_setup_runtime(struct rte_eth_dev *dev,
    2229                 :            :                                 struct i40e_tx_queue *txq)
    2230                 :            : {
    2231                 :          0 :         struct i40e_adapter *ad =
    2232                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    2233                 :            : 
    2234         [ #  # ]:          0 :         if (i40e_tx_queue_init(txq) != I40E_SUCCESS) {
    2235                 :          0 :                 PMD_DRV_LOG(ERR,
    2236                 :            :                             "Failed to do TX queue initialization");
    2237                 :          0 :                 return -EINVAL;
    2238                 :            :         }
    2239                 :            : 
    2240         [ #  # ]:          0 :         if (i40e_dev_first_queue(txq->queue_id,
    2241                 :            :                                  dev->data->tx_queues,
    2242                 :          0 :                                  dev->data->nb_tx_queues)) {
    2243                 :            :                 /**
    2244                 :            :                  * If it is the first queue to setup,
    2245                 :            :                  * set all flags and call
    2246                 :            :                  * i40e_set_tx_function.
    2247                 :            :                  */
    2248                 :          0 :                 i40e_set_tx_function_flag(dev, txq);
    2249                 :          0 :                 i40e_set_tx_function(dev);
    2250                 :          0 :                 return 0;
    2251                 :            :         }
    2252                 :            : 
    2253                 :            :         /* check vector conflict */
    2254         [ #  # ]:          0 :         if (ad->tx_vec_allowed) {
    2255   [ #  #  #  # ]:          0 :                 if (txq->tx_rs_thresh > RTE_I40E_TX_MAX_FREE_BUF_SZ ||
    2256                 :          0 :                     i40e_txq_vec_setup(txq)) {
    2257                 :          0 :                         PMD_DRV_LOG(ERR, "Failed vector tx setup.");
    2258                 :          0 :                         return -EINVAL;
    2259                 :            :                 }
    2260                 :            :         }
    2261                 :            :         /* check simple tx conflict */
    2262         [ #  # ]:          0 :         if (ad->tx_simple_allowed) {
    2263         [ #  # ]:          0 :                 if ((txq->offloads & ~RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) != 0 ||
    2264         [ #  # ]:          0 :                                 txq->tx_rs_thresh < RTE_PMD_I40E_TX_MAX_BURST) {
    2265                 :          0 :                         PMD_DRV_LOG(ERR, "No-simple tx is required.");
    2266                 :          0 :                         return -EINVAL;
    2267                 :            :                 }
    2268                 :            :         }
    2269                 :            : 
    2270                 :            :         return 0;
    2271                 :            : }
    2272                 :            : 
    2273                 :            : int
    2274                 :          0 : i40e_dev_tx_queue_setup(struct rte_eth_dev *dev,
    2275                 :            :                         uint16_t queue_idx,
    2276                 :            :                         uint16_t nb_desc,
    2277                 :            :                         unsigned int socket_id,
    2278                 :            :                         const struct rte_eth_txconf *tx_conf)
    2279                 :            : {
    2280                 :            :         struct i40e_vsi *vsi;
    2281                 :            :         struct i40e_pf *pf = NULL;
    2282                 :            :         struct i40e_tx_queue *txq;
    2283                 :            :         const struct rte_memzone *tz;
    2284                 :            :         uint32_t ring_size;
    2285                 :            :         uint16_t tx_rs_thresh, tx_free_thresh;
    2286                 :            :         uint16_t reg_idx, i, base, bsf, tc_mapping;
    2287                 :            :         int q_offset;
    2288                 :            :         uint64_t offloads;
    2289                 :            : 
    2290                 :          0 :         offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
    2291                 :            : 
    2292                 :          0 :         pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
    2293                 :          0 :         vsi = i40e_pf_get_vsi_by_qindex(pf, queue_idx);
    2294         [ #  # ]:          0 :         if (!vsi)
    2295                 :            :                 return -EINVAL;
    2296                 :          0 :         q_offset = i40e_get_queue_offset_by_qindex(pf, queue_idx);
    2297                 :            :         if (q_offset < 0)
    2298                 :            :                 return -EINVAL;
    2299                 :          0 :         reg_idx = vsi->base_queue + q_offset;
    2300                 :            : 
    2301         [ #  # ]:          0 :         if (nb_desc % I40E_ALIGN_RING_DESC != 0 ||
    2302         [ #  # ]:          0 :             (nb_desc > I40E_MAX_RING_DESC) ||
    2303                 :            :             (nb_desc < I40E_MIN_RING_DESC)) {
    2304                 :          0 :                 PMD_DRV_LOG(ERR, "Number (%u) of transmit descriptors is "
    2305                 :            :                             "invalid", nb_desc);
    2306                 :          0 :                 return -EINVAL;
    2307                 :            :         }
    2308                 :            : 
    2309                 :            :         /**
    2310                 :            :          * The following two parameters control the setting of the RS bit on
    2311                 :            :          * transmit descriptors. TX descriptors will have their RS bit set
    2312                 :            :          * after txq->tx_rs_thresh descriptors have been used. The TX
    2313                 :            :          * descriptor ring will be cleaned after txq->tx_free_thresh
    2314                 :            :          * descriptors are used or if the number of descriptors required to
    2315                 :            :          * transmit a packet is greater than the number of free TX descriptors.
    2316                 :            :          *
    2317                 :            :          * The following constraints must be satisfied:
    2318                 :            :          *  - tx_rs_thresh must be greater than 0.
    2319                 :            :          *  - tx_rs_thresh must be less than the size of the ring minus 2.
    2320                 :            :          *  - tx_rs_thresh must be less than or equal to tx_free_thresh.
    2321                 :            :          *  - tx_rs_thresh must be a divisor of the ring size.
    2322                 :            :          *  - tx_free_thresh must be greater than 0.
    2323                 :            :          *  - tx_free_thresh must be less than the size of the ring minus 3.
    2324                 :            :          *  - tx_free_thresh + tx_rs_thresh must not exceed nb_desc.
    2325                 :            :          *
    2326                 :            :          * One descriptor in the TX ring is used as a sentinel to avoid a H/W
    2327                 :            :          * race condition, hence the maximum threshold constraints. When set
    2328                 :            :          * to zero use default values.
    2329                 :            :          */
    2330         [ #  # ]:          0 :         tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
    2331                 :            :                 tx_conf->tx_free_thresh : DEFAULT_TX_FREE_THRESH);
    2332                 :            :         /* force tx_rs_thresh to adapt an aggressive tx_free_thresh */
    2333         [ #  # ]:          0 :         tx_rs_thresh = (DEFAULT_TX_RS_THRESH + tx_free_thresh > nb_desc) ?
    2334                 :            :                 nb_desc - tx_free_thresh : DEFAULT_TX_RS_THRESH;
    2335         [ #  # ]:          0 :         if (tx_conf->tx_rs_thresh > 0)
    2336                 :            :                 tx_rs_thresh = tx_conf->tx_rs_thresh;
    2337         [ #  # ]:          0 :         if (tx_rs_thresh + tx_free_thresh > nb_desc) {
    2338                 :          0 :                 PMD_INIT_LOG(ERR, "tx_rs_thresh + tx_free_thresh must not "
    2339                 :            :                                 "exceed nb_desc. (tx_rs_thresh=%u "
    2340                 :            :                                 "tx_free_thresh=%u nb_desc=%u port=%d queue=%d)",
    2341                 :            :                                 (unsigned int)tx_rs_thresh,
    2342                 :            :                                 (unsigned int)tx_free_thresh,
    2343                 :            :                                 (unsigned int)nb_desc,
    2344                 :            :                                 (int)dev->data->port_id,
    2345                 :            :                                 (int)queue_idx);
    2346                 :          0 :                 return I40E_ERR_PARAM;
    2347                 :            :         }
    2348         [ #  # ]:          0 :         if (tx_rs_thresh >= (nb_desc - 2)) {
    2349                 :          0 :                 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than the "
    2350                 :            :                              "number of TX descriptors minus 2. "
    2351                 :            :                              "(tx_rs_thresh=%u port=%d queue=%d)",
    2352                 :            :                              (unsigned int)tx_rs_thresh,
    2353                 :            :                              (int)dev->data->port_id,
    2354                 :            :                              (int)queue_idx);
    2355                 :          0 :                 return I40E_ERR_PARAM;
    2356                 :            :         }
    2357         [ #  # ]:          0 :         if (tx_free_thresh >= (nb_desc - 3)) {
    2358                 :          0 :                 PMD_INIT_LOG(ERR, "tx_free_thresh must be less than the "
    2359                 :            :                              "number of TX descriptors minus 3. "
    2360                 :            :                              "(tx_free_thresh=%u port=%d queue=%d)",
    2361                 :            :                              (unsigned int)tx_free_thresh,
    2362                 :            :                              (int)dev->data->port_id,
    2363                 :            :                              (int)queue_idx);
    2364                 :          0 :                 return I40E_ERR_PARAM;
    2365                 :            :         }
    2366         [ #  # ]:          0 :         if (tx_rs_thresh > tx_free_thresh) {
    2367                 :          0 :                 PMD_INIT_LOG(ERR, "tx_rs_thresh must be less than or "
    2368                 :            :                              "equal to tx_free_thresh. (tx_free_thresh=%u"
    2369                 :            :                              " tx_rs_thresh=%u port=%d queue=%d)",
    2370                 :            :                              (unsigned int)tx_free_thresh,
    2371                 :            :                              (unsigned int)tx_rs_thresh,
    2372                 :            :                              (int)dev->data->port_id,
    2373                 :            :                              (int)queue_idx);
    2374                 :          0 :                 return I40E_ERR_PARAM;
    2375                 :            :         }
    2376         [ #  # ]:          0 :         if ((nb_desc % tx_rs_thresh) != 0) {
    2377                 :          0 :                 PMD_INIT_LOG(ERR, "tx_rs_thresh must be a divisor of the "
    2378                 :            :                              "number of TX descriptors. (tx_rs_thresh=%u"
    2379                 :            :                              " port=%d queue=%d)",
    2380                 :            :                              (unsigned int)tx_rs_thresh,
    2381                 :            :                              (int)dev->data->port_id,
    2382                 :            :                              (int)queue_idx);
    2383                 :          0 :                 return I40E_ERR_PARAM;
    2384                 :            :         }
    2385   [ #  #  #  # ]:          0 :         if ((tx_rs_thresh > 1) && (tx_conf->tx_thresh.wthresh != 0)) {
    2386                 :          0 :                 PMD_INIT_LOG(ERR, "TX WTHRESH must be set to 0 if "
    2387                 :            :                              "tx_rs_thresh is greater than 1. "
    2388                 :            :                              "(tx_rs_thresh=%u port=%d queue=%d)",
    2389                 :            :                              (unsigned int)tx_rs_thresh,
    2390                 :            :                              (int)dev->data->port_id,
    2391                 :            :                              (int)queue_idx);
    2392                 :          0 :                 return I40E_ERR_PARAM;
    2393                 :            :         }
    2394                 :            : 
    2395                 :            :         /* Free memory if needed. */
    2396         [ #  # ]:          0 :         if (dev->data->tx_queues[queue_idx]) {
    2397                 :          0 :                 i40e_tx_queue_release(dev->data->tx_queues[queue_idx]);
    2398                 :          0 :                 dev->data->tx_queues[queue_idx] = NULL;
    2399                 :            :         }
    2400                 :            : 
    2401                 :            :         /* Allocate the TX queue data structure. */
    2402                 :          0 :         txq = rte_zmalloc_socket("i40e tx queue",
    2403                 :            :                                   sizeof(struct i40e_tx_queue),
    2404                 :            :                                   RTE_CACHE_LINE_SIZE,
    2405                 :            :                                   socket_id);
    2406         [ #  # ]:          0 :         if (!txq) {
    2407                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
    2408                 :            :                             "tx queue structure");
    2409                 :          0 :                 return -ENOMEM;
    2410                 :            :         }
    2411                 :            : 
    2412                 :            :         /* Allocate TX hardware ring descriptors. */
    2413                 :            :         ring_size = sizeof(struct i40e_tx_desc) * I40E_MAX_RING_DESC;
    2414                 :            :         ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
    2415                 :          0 :         tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
    2416                 :            :                               ring_size, I40E_RING_BASE_ALIGN, socket_id);
    2417         [ #  # ]:          0 :         if (!tz) {
    2418                 :          0 :                 i40e_tx_queue_release(txq);
    2419                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX");
    2420                 :          0 :                 return -ENOMEM;
    2421                 :            :         }
    2422                 :            : 
    2423                 :          0 :         txq->mz = tz;
    2424                 :          0 :         txq->nb_tx_desc = nb_desc;
    2425                 :          0 :         txq->tx_rs_thresh = tx_rs_thresh;
    2426                 :          0 :         txq->tx_free_thresh = tx_free_thresh;
    2427                 :          0 :         txq->pthresh = tx_conf->tx_thresh.pthresh;
    2428                 :          0 :         txq->hthresh = tx_conf->tx_thresh.hthresh;
    2429                 :          0 :         txq->wthresh = tx_conf->tx_thresh.wthresh;
    2430                 :          0 :         txq->queue_id = queue_idx;
    2431                 :          0 :         txq->reg_idx = reg_idx;
    2432                 :          0 :         txq->port_id = dev->data->port_id;
    2433                 :          0 :         txq->offloads = offloads;
    2434                 :          0 :         txq->vsi = vsi;
    2435                 :          0 :         txq->tx_deferred_start = tx_conf->tx_deferred_start;
    2436                 :            : 
    2437                 :          0 :         txq->tx_ring_phys_addr = tz->iova;
    2438                 :          0 :         txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
    2439                 :            : 
    2440                 :            :         /* Allocate software ring */
    2441                 :          0 :         txq->sw_ring =
    2442                 :          0 :                 rte_zmalloc_socket("i40e tx sw ring",
    2443                 :            :                                    sizeof(struct i40e_tx_entry) * nb_desc,
    2444                 :            :                                    RTE_CACHE_LINE_SIZE,
    2445                 :            :                                    socket_id);
    2446         [ #  # ]:          0 :         if (!txq->sw_ring) {
    2447                 :          0 :                 i40e_tx_queue_release(txq);
    2448                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for SW TX ring");
    2449                 :          0 :                 return -ENOMEM;
    2450                 :            :         }
    2451                 :            : 
    2452                 :          0 :         i40e_reset_tx_queue(txq);
    2453                 :          0 :         txq->q_set = TRUE;
    2454                 :            : 
    2455         [ #  # ]:          0 :         for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
    2456         [ #  # ]:          0 :                 if (!(vsi->enabled_tc & (1 << i)))
    2457                 :          0 :                         continue;
    2458                 :          0 :                 tc_mapping = rte_le_to_cpu_16(vsi->info.tc_mapping[i]);
    2459                 :          0 :                 base = (tc_mapping & I40E_AQ_VSI_TC_QUE_OFFSET_MASK) >>
    2460                 :            :                         I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT;
    2461                 :          0 :                 bsf = (tc_mapping & I40E_AQ_VSI_TC_QUE_NUMBER_MASK) >>
    2462                 :            :                         I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT;
    2463                 :            : 
    2464   [ #  #  #  # ]:          0 :                 if (queue_idx >= base && queue_idx < (base + BIT(bsf)))
    2465                 :          0 :                         txq->dcb_tc = i;
    2466                 :            :         }
    2467                 :            : 
    2468         [ #  # ]:          0 :         if (dev->data->dev_started) {
    2469         [ #  # ]:          0 :                 if (i40e_dev_tx_queue_setup_runtime(dev, txq)) {
    2470                 :          0 :                         i40e_tx_queue_release(txq);
    2471                 :          0 :                         return -EINVAL;
    2472                 :            :                 }
    2473                 :            :         } else {
    2474                 :            :                 /**
    2475                 :            :                  * Use a simple TX queue without offloads or
    2476                 :            :                  * multi segs if possible
    2477                 :            :                  */
    2478                 :          0 :                 i40e_set_tx_function_flag(dev, txq);
    2479                 :            :         }
    2480                 :          0 :         dev->data->tx_queues[queue_idx] = txq;
    2481                 :            : 
    2482                 :          0 :         return 0;
    2483                 :            : }
    2484                 :            : 
    2485                 :            : void
    2486                 :          0 : i40e_tx_queue_release(void *txq)
    2487                 :            : {
    2488                 :            :         struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
    2489                 :            : 
    2490         [ #  # ]:          0 :         if (!q) {
    2491                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to TX queue is NULL");
    2492                 :          0 :                 return;
    2493                 :            :         }
    2494                 :            : 
    2495                 :          0 :         i40e_tx_queue_release_mbufs(q);
    2496                 :          0 :         rte_free(q->sw_ring);
    2497                 :          0 :         rte_memzone_free(q->mz);
    2498                 :          0 :         rte_free(q);
    2499                 :            : }
    2500                 :            : 
    2501                 :            : const struct rte_memzone *
    2502                 :          0 : i40e_memzone_reserve(const char *name, uint32_t len, int socket_id)
    2503                 :            : {
    2504                 :            :         const struct rte_memzone *mz;
    2505                 :            : 
    2506                 :          0 :         mz = rte_memzone_lookup(name);
    2507         [ #  # ]:          0 :         if (mz)
    2508                 :            :                 return mz;
    2509                 :            : 
    2510                 :          0 :         mz = rte_memzone_reserve_aligned(name, len, socket_id,
    2511                 :            :                         RTE_MEMZONE_IOVA_CONTIG, I40E_RING_BASE_ALIGN);
    2512                 :          0 :         return mz;
    2513                 :            : }
    2514                 :            : 
    2515                 :            : void
    2516                 :          0 : i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
    2517                 :            : {
    2518                 :            :         uint16_t i;
    2519                 :            : 
    2520                 :            :         /* SSE Vector driver has a different way of releasing mbufs. */
    2521         [ #  # ]:          0 :         if (rxq->rx_using_sse) {
    2522                 :          0 :                 i40e_rx_queue_release_mbufs_vec(rxq);
    2523                 :          0 :                 return;
    2524                 :            :         }
    2525                 :            : 
    2526         [ #  # ]:          0 :         if (!rxq->sw_ring) {
    2527                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to sw_ring is NULL");
    2528                 :          0 :                 return;
    2529                 :            :         }
    2530                 :            : 
    2531         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
    2532         [ #  # ]:          0 :                 if (rxq->sw_ring[i].mbuf) {
    2533                 :            :                         rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
    2534                 :          0 :                         rxq->sw_ring[i].mbuf = NULL;
    2535                 :            :                 }
    2536                 :            :         }
    2537                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
    2538         [ #  # ]:          0 :         if (rxq->rx_nb_avail == 0)
    2539                 :            :                 return;
    2540         [ #  # ]:          0 :         for (i = 0; i < rxq->rx_nb_avail; i++) {
    2541                 :            :                 struct rte_mbuf *mbuf;
    2542                 :            : 
    2543         [ #  # ]:          0 :                 mbuf = rxq->rx_stage[rxq->rx_next_avail + i];
    2544                 :            :                 rte_pktmbuf_free_seg(mbuf);
    2545                 :            :         }
    2546                 :          0 :         rxq->rx_nb_avail = 0;
    2547                 :            : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
    2548                 :            : }
    2549                 :            : 
    2550                 :            : void
    2551                 :          0 : i40e_reset_rx_queue(struct i40e_rx_queue *rxq)
    2552                 :            : {
    2553                 :            :         unsigned i;
    2554                 :            :         uint16_t len;
    2555                 :            : 
    2556         [ #  # ]:          0 :         if (!rxq) {
    2557                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to rxq is NULL");
    2558                 :          0 :                 return;
    2559                 :            :         }
    2560                 :            : 
    2561                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
    2562         [ #  # ]:          0 :         if (check_rx_burst_bulk_alloc_preconditions(rxq) == 0)
    2563                 :          0 :                 len = (uint16_t)(rxq->nb_rx_desc + RTE_PMD_I40E_RX_MAX_BURST);
    2564                 :            :         else
    2565                 :            : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
    2566                 :          0 :                 len = rxq->nb_rx_desc;
    2567                 :            : 
    2568         [ #  # ]:          0 :         for (i = 0; i < len * sizeof(union i40e_rx_desc); i++)
    2569                 :          0 :                 ((volatile char *)rxq->rx_ring)[i] = 0;
    2570                 :            : 
    2571                 :          0 :         memset(&rxq->fake_mbuf, 0x0, sizeof(rxq->fake_mbuf));
    2572         [ #  # ]:          0 :         for (i = 0; i < RTE_PMD_I40E_RX_MAX_BURST; ++i)
    2573                 :          0 :                 rxq->sw_ring[rxq->nb_rx_desc + i].mbuf = &rxq->fake_mbuf;
    2574                 :            : 
    2575                 :            : #ifdef RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC
    2576                 :          0 :         rxq->rx_nb_avail = 0;
    2577                 :          0 :         rxq->rx_next_avail = 0;
    2578                 :          0 :         rxq->rx_free_trigger = (uint16_t)(rxq->rx_free_thresh - 1);
    2579                 :            : #endif /* RTE_LIBRTE_I40E_RX_ALLOW_BULK_ALLOC */
    2580                 :          0 :         rxq->rx_tail = 0;
    2581                 :          0 :         rxq->nb_rx_hold = 0;
    2582                 :            : 
    2583                 :          0 :         rte_pktmbuf_free(rxq->pkt_first_seg);
    2584                 :            : 
    2585                 :          0 :         rxq->pkt_first_seg = NULL;
    2586                 :          0 :         rxq->pkt_last_seg = NULL;
    2587                 :            : 
    2588                 :          0 :         rxq->rxrearm_start = 0;
    2589                 :          0 :         rxq->rxrearm_nb = 0;
    2590                 :            : }
    2591                 :            : 
    2592                 :            : void
    2593                 :          0 : i40e_tx_queue_release_mbufs(struct i40e_tx_queue *txq)
    2594                 :            : {
    2595                 :            :         struct rte_eth_dev *dev;
    2596                 :            :         uint16_t i;
    2597                 :            : 
    2598   [ #  #  #  # ]:          0 :         if (!txq || !txq->sw_ring) {
    2599                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to txq or sw_ring is NULL");
    2600                 :          0 :                 return;
    2601                 :            :         }
    2602                 :            : 
    2603                 :          0 :         dev = &rte_eth_devices[txq->port_id];
    2604                 :            : 
    2605                 :            :         /**
    2606                 :            :          *  vPMD tx will not set sw_ring's mbuf to NULL after free,
    2607                 :            :          *  so need to free remains more carefully.
    2608                 :            :          */
    2609                 :            : #ifdef CC_AVX512_SUPPORT
    2610         [ #  # ]:          0 :         if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx512) {
    2611                 :            :                 struct i40e_vec_tx_entry *swr = (void *)txq->sw_ring;
    2612                 :            : 
    2613                 :          0 :                 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
    2614         [ #  # ]:          0 :                 if (txq->tx_tail < i) {
    2615         [ #  # ]:          0 :                         for (; i < txq->nb_tx_desc; i++) {
    2616         [ #  # ]:          0 :                                 rte_pktmbuf_free_seg(swr[i].mbuf);
    2617                 :          0 :                                 swr[i].mbuf = NULL;
    2618                 :            :                         }
    2619                 :            :                         i = 0;
    2620                 :            :                 }
    2621         [ #  # ]:          0 :                 for (; i < txq->tx_tail; i++) {
    2622         [ #  # ]:          0 :                         rte_pktmbuf_free_seg(swr[i].mbuf);
    2623                 :          0 :                         swr[i].mbuf = NULL;
    2624                 :            :                 }
    2625                 :            :                 return;
    2626                 :            :         }
    2627                 :            : #endif
    2628   [ #  #  #  # ]:          0 :         if (dev->tx_pkt_burst == i40e_xmit_pkts_vec_avx2 ||
    2629                 :            :                         dev->tx_pkt_burst == i40e_xmit_pkts_vec) {
    2630                 :          0 :                 i = txq->tx_next_dd - txq->tx_rs_thresh + 1;
    2631         [ #  # ]:          0 :                 if (txq->tx_tail < i) {
    2632         [ #  # ]:          0 :                         for (; i < txq->nb_tx_desc; i++) {
    2633         [ #  # ]:          0 :                                 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
    2634                 :          0 :                                 txq->sw_ring[i].mbuf = NULL;
    2635                 :            :                         }
    2636                 :            :                         i = 0;
    2637                 :            :                 }
    2638         [ #  # ]:          0 :                 for (; i < txq->tx_tail; i++) {
    2639         [ #  # ]:          0 :                         rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
    2640                 :          0 :                         txq->sw_ring[i].mbuf = NULL;
    2641                 :            :                 }
    2642                 :            :         } else {
    2643         [ #  # ]:          0 :                 for (i = 0; i < txq->nb_tx_desc; i++) {
    2644         [ #  # ]:          0 :                         if (txq->sw_ring[i].mbuf) {
    2645                 :            :                                 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
    2646                 :          0 :                                 txq->sw_ring[i].mbuf = NULL;
    2647                 :            :                         }
    2648                 :            :                 }
    2649                 :            :         }
    2650                 :            : }
    2651                 :            : 
    2652                 :            : static int
    2653                 :          0 : i40e_tx_done_cleanup_full(struct i40e_tx_queue *txq,
    2654                 :            :                         uint32_t free_cnt)
    2655                 :            : {
    2656                 :          0 :         struct i40e_tx_entry *swr_ring = txq->sw_ring;
    2657                 :            :         uint16_t i, tx_last, tx_id;
    2658                 :            :         uint16_t nb_tx_free_last;
    2659                 :            :         uint16_t nb_tx_to_clean;
    2660                 :            :         uint32_t pkt_cnt;
    2661                 :            : 
    2662                 :            :         /* Start free mbuf from the next of tx_tail */
    2663                 :          0 :         tx_last = txq->tx_tail;
    2664                 :          0 :         tx_id  = swr_ring[tx_last].next_id;
    2665                 :            : 
    2666   [ #  #  #  # ]:          0 :         if (txq->nb_tx_free == 0 && i40e_xmit_cleanup(txq))
    2667                 :            :                 return 0;
    2668                 :            : 
    2669                 :          0 :         nb_tx_to_clean = txq->nb_tx_free;
    2670                 :            :         nb_tx_free_last = txq->nb_tx_free;
    2671         [ #  # ]:          0 :         if (!free_cnt)
    2672                 :          0 :                 free_cnt = txq->nb_tx_desc;
    2673                 :            : 
    2674                 :            :         /* Loop through swr_ring to count the amount of
    2675                 :            :          * freeable mubfs and packets.
    2676                 :            :          */
    2677         [ #  # ]:          0 :         for (pkt_cnt = 0; pkt_cnt < free_cnt; ) {
    2678                 :          0 :                 for (i = 0; i < nb_tx_to_clean &&
    2679   [ #  #  #  # ]:          0 :                         pkt_cnt < free_cnt &&
    2680                 :          0 :                         tx_id != tx_last; i++) {
    2681         [ #  # ]:          0 :                         if (swr_ring[tx_id].mbuf != NULL) {
    2682                 :            :                                 rte_pktmbuf_free_seg(swr_ring[tx_id].mbuf);
    2683                 :          0 :                                 swr_ring[tx_id].mbuf = NULL;
    2684                 :            : 
    2685                 :            :                                 /*
    2686                 :            :                                  * last segment in the packet,
    2687                 :            :                                  * increment packet count
    2688                 :            :                                  */
    2689                 :          0 :                                 pkt_cnt += (swr_ring[tx_id].last_id == tx_id);
    2690                 :            :                         }
    2691                 :            : 
    2692                 :          0 :                         tx_id = swr_ring[tx_id].next_id;
    2693                 :            :                 }
    2694                 :            : 
    2695                 :          0 :                 if (txq->tx_rs_thresh > txq->nb_tx_desc -
    2696   [ #  #  #  # ]:          0 :                         txq->nb_tx_free || tx_id == tx_last)
    2697                 :            :                         break;
    2698                 :            : 
    2699         [ #  # ]:          0 :                 if (pkt_cnt < free_cnt) {
    2700         [ #  # ]:          0 :                         if (i40e_xmit_cleanup(txq))
    2701                 :            :                                 break;
    2702                 :            : 
    2703                 :          0 :                         nb_tx_to_clean = txq->nb_tx_free - nb_tx_free_last;
    2704                 :            :                         nb_tx_free_last = txq->nb_tx_free;
    2705                 :            :                 }
    2706                 :            :         }
    2707                 :            : 
    2708                 :          0 :         return (int)pkt_cnt;
    2709                 :            : }
    2710                 :            : 
    2711                 :            : static int
    2712                 :          0 : i40e_tx_done_cleanup_simple(struct i40e_tx_queue *txq,
    2713                 :            :                         uint32_t free_cnt)
    2714                 :            : {
    2715                 :            :         int i, n, cnt;
    2716                 :            : 
    2717   [ #  #  #  # ]:          0 :         if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
    2718                 :          0 :                 free_cnt = txq->nb_tx_desc;
    2719                 :            : 
    2720                 :          0 :         cnt = free_cnt - free_cnt % txq->tx_rs_thresh;
    2721                 :            : 
    2722         [ #  # ]:          0 :         for (i = 0; i < cnt; i += n) {
    2723         [ #  # ]:          0 :                 if (txq->nb_tx_desc - txq->nb_tx_free < txq->tx_rs_thresh)
    2724                 :            :                         break;
    2725                 :            : 
    2726                 :            :                 n = i40e_tx_free_bufs(txq);
    2727                 :            : 
    2728         [ #  # ]:          0 :                 if (n == 0)
    2729                 :            :                         break;
    2730                 :            :         }
    2731                 :            : 
    2732                 :          0 :         return i;
    2733                 :            : }
    2734                 :            : 
    2735                 :            : static int
    2736                 :            : i40e_tx_done_cleanup_vec(struct i40e_tx_queue *txq __rte_unused,
    2737                 :            :                         uint32_t free_cnt __rte_unused)
    2738                 :            : {
    2739                 :            :         return -ENOTSUP;
    2740                 :            : }
    2741                 :            : int
    2742                 :          0 : i40e_tx_done_cleanup(void *txq, uint32_t free_cnt)
    2743                 :            : {
    2744                 :            :         struct i40e_tx_queue *q = (struct i40e_tx_queue *)txq;
    2745                 :          0 :         struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
    2746                 :          0 :         struct i40e_adapter *ad =
    2747                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    2748                 :            : 
    2749         [ #  # ]:          0 :         if (ad->tx_simple_allowed) {
    2750         [ #  # ]:          0 :                 if (ad->tx_vec_allowed)
    2751                 :            :                         return i40e_tx_done_cleanup_vec(q, free_cnt);
    2752                 :            :                 else
    2753                 :          0 :                         return i40e_tx_done_cleanup_simple(q, free_cnt);
    2754                 :            :         } else {
    2755                 :          0 :                 return i40e_tx_done_cleanup_full(q, free_cnt);
    2756                 :            :         }
    2757                 :            : }
    2758                 :            : 
    2759                 :            : void
    2760                 :          0 : i40e_reset_tx_queue(struct i40e_tx_queue *txq)
    2761                 :            : {
    2762                 :            :         struct i40e_tx_entry *txe;
    2763                 :            :         uint16_t i, prev, size;
    2764                 :            : 
    2765         [ #  # ]:          0 :         if (!txq) {
    2766                 :          0 :                 PMD_DRV_LOG(DEBUG, "Pointer to txq is NULL");
    2767                 :          0 :                 return;
    2768                 :            :         }
    2769                 :            : 
    2770                 :          0 :         txe = txq->sw_ring;
    2771                 :          0 :         size = sizeof(struct i40e_tx_desc) * txq->nb_tx_desc;
    2772         [ #  # ]:          0 :         for (i = 0; i < size; i++)
    2773                 :          0 :                 ((volatile char *)txq->tx_ring)[i] = 0;
    2774                 :            : 
    2775                 :          0 :         prev = (uint16_t)(txq->nb_tx_desc - 1);
    2776         [ #  # ]:          0 :         for (i = 0; i < txq->nb_tx_desc; i++) {
    2777                 :          0 :                 volatile struct i40e_tx_desc *txd = &txq->tx_ring[i];
    2778                 :            : 
    2779                 :          0 :                 txd->cmd_type_offset_bsz =
    2780                 :            :                         rte_cpu_to_le_64(I40E_TX_DESC_DTYPE_DESC_DONE);
    2781                 :          0 :                 txe[i].mbuf =  NULL;
    2782                 :          0 :                 txe[i].last_id = i;
    2783                 :          0 :                 txe[prev].next_id = i;
    2784                 :            :                 prev = i;
    2785                 :            :         }
    2786                 :            : 
    2787                 :          0 :         txq->tx_next_dd = (uint16_t)(txq->tx_rs_thresh - 1);
    2788                 :          0 :         txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
    2789                 :            : 
    2790                 :          0 :         txq->tx_tail = 0;
    2791                 :          0 :         txq->nb_tx_used = 0;
    2792                 :            : 
    2793                 :          0 :         txq->last_desc_cleaned = (uint16_t)(txq->nb_tx_desc - 1);
    2794                 :          0 :         txq->nb_tx_free = (uint16_t)(txq->nb_tx_desc - 1);
    2795                 :            : }
    2796                 :            : 
    2797                 :            : /* Init the TX queue in hardware */
    2798                 :            : int
    2799                 :          0 : i40e_tx_queue_init(struct i40e_tx_queue *txq)
    2800                 :            : {
    2801                 :            :         enum i40e_status_code err = I40E_SUCCESS;
    2802                 :          0 :         struct i40e_vsi *vsi = txq->vsi;
    2803                 :          0 :         struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
    2804         [ #  # ]:          0 :         uint16_t pf_q = txq->reg_idx;
    2805                 :            :         struct i40e_hmc_obj_txq tx_ctx;
    2806                 :            :         uint32_t qtx_ctl;
    2807                 :            : 
    2808                 :            :         /* clear the context structure first */
    2809                 :            :         memset(&tx_ctx, 0, sizeof(tx_ctx));
    2810                 :          0 :         tx_ctx.new_context = 1;
    2811                 :          0 :         tx_ctx.base = txq->tx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
    2812                 :          0 :         tx_ctx.qlen = txq->nb_tx_desc;
    2813                 :            : 
    2814                 :            : #ifdef RTE_LIBRTE_IEEE1588
    2815                 :            :         tx_ctx.timesync_ena = 1;
    2816                 :            : #endif
    2817                 :          0 :         tx_ctx.rdylist = rte_le_to_cpu_16(vsi->info.qs_handle[txq->dcb_tc]);
    2818         [ #  # ]:          0 :         if (vsi->type == I40E_VSI_FDIR)
    2819                 :          0 :                 tx_ctx.fd_ena = TRUE;
    2820                 :            : 
    2821                 :          0 :         err = i40e_clear_lan_tx_queue_context(hw, pf_q);
    2822         [ #  # ]:          0 :         if (err != I40E_SUCCESS) {
    2823                 :          0 :                 PMD_DRV_LOG(ERR, "Failure of clean lan tx queue context");
    2824                 :          0 :                 return err;
    2825                 :            :         }
    2826                 :            : 
    2827                 :          0 :         err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
    2828         [ #  # ]:          0 :         if (err != I40E_SUCCESS) {
    2829                 :          0 :                 PMD_DRV_LOG(ERR, "Failure of set lan tx queue context");
    2830                 :          0 :                 return err;
    2831                 :            :         }
    2832                 :            : 
    2833                 :            :         /* Now associate this queue with this PCI function */
    2834                 :            :         qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
    2835                 :          0 :         qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
    2836                 :            :                                         I40E_QTX_CTL_PF_INDX_MASK);
    2837                 :          0 :         I40E_WRITE_REG(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
    2838                 :          0 :         I40E_WRITE_FLUSH(hw);
    2839                 :            : 
    2840                 :          0 :         txq->qtx_tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
    2841                 :            : 
    2842                 :          0 :         return err;
    2843                 :            : }
    2844                 :            : 
    2845                 :            : int
    2846                 :          0 : i40e_alloc_rx_queue_mbufs(struct i40e_rx_queue *rxq)
    2847                 :            : {
    2848                 :          0 :         struct i40e_rx_entry *rxe = rxq->sw_ring;
    2849                 :            :         uint64_t dma_addr;
    2850                 :            :         uint16_t i;
    2851                 :            : 
    2852         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
    2853                 :            :                 volatile union i40e_rx_desc *rxd;
    2854                 :          0 :                 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mp);
    2855                 :            : 
    2856         [ #  # ]:          0 :                 if (unlikely(!mbuf)) {
    2857                 :          0 :                         PMD_DRV_LOG(ERR, "Failed to allocate mbuf for RX");
    2858                 :          0 :                         return -ENOMEM;
    2859                 :            :                 }
    2860                 :            : 
    2861                 :            :                 rte_mbuf_refcnt_set(mbuf, 1);
    2862                 :          0 :                 mbuf->next = NULL;
    2863                 :          0 :                 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
    2864                 :          0 :                 mbuf->nb_segs = 1;
    2865                 :          0 :                 mbuf->port = rxq->port_id;
    2866                 :            : 
    2867                 :            :                 dma_addr =
    2868                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
    2869                 :            : 
    2870                 :          0 :                 rxd = &rxq->rx_ring[i];
    2871                 :          0 :                 rxd->read.pkt_addr = dma_addr;
    2872                 :          0 :                 rxd->read.hdr_addr = 0;
    2873                 :            : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
    2874                 :          0 :                 rxd->read.rsvd1 = 0;
    2875                 :          0 :                 rxd->read.rsvd2 = 0;
    2876                 :            : #endif /* RTE_LIBRTE_I40E_16BYTE_RX_DESC */
    2877                 :            : 
    2878                 :          0 :                 rxe[i].mbuf = mbuf;
    2879                 :            :         }
    2880                 :            : 
    2881                 :            :         return 0;
    2882                 :            : }
    2883                 :            : 
    2884                 :            : /*
    2885                 :            :  * Calculate the buffer length, and check the jumbo frame
    2886                 :            :  * and maximum packet length.
    2887                 :            :  */
    2888                 :            : static int
    2889                 :          0 : i40e_rx_queue_config(struct i40e_rx_queue *rxq)
    2890                 :            : {
    2891                 :          0 :         struct i40e_pf *pf = I40E_VSI_TO_PF(rxq->vsi);
    2892                 :            :         struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
    2893                 :          0 :         struct rte_eth_dev_data *data = pf->dev_data;
    2894                 :            :         uint16_t buf_size;
    2895                 :            : 
    2896         [ #  # ]:          0 :         buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
    2897                 :            :                 RTE_PKTMBUF_HEADROOM);
    2898                 :            : 
    2899         [ #  # ]:          0 :         switch (pf->flags & (I40E_FLAG_HEADER_SPLIT_DISABLED |
    2900                 :            :                         I40E_FLAG_HEADER_SPLIT_ENABLED)) {
    2901                 :          0 :         case I40E_FLAG_HEADER_SPLIT_ENABLED: /* Not supported */
    2902                 :          0 :                 rxq->rx_hdr_len = RTE_ALIGN(I40E_RXBUF_SZ_1024,
    2903                 :            :                                 (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
    2904                 :          0 :                 rxq->rx_buf_len = RTE_ALIGN(I40E_RXBUF_SZ_2048,
    2905                 :            :                                 (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
    2906                 :          0 :                 rxq->hs_mode = i40e_header_split_enabled;
    2907                 :          0 :                 break;
    2908                 :          0 :         case I40E_FLAG_HEADER_SPLIT_DISABLED:
    2909                 :            :         default:
    2910                 :          0 :                 rxq->rx_hdr_len = 0;
    2911                 :          0 :                 rxq->rx_buf_len = RTE_ALIGN_FLOOR(buf_size,
    2912                 :            :                         (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
    2913                 :          0 :                 rxq->rx_buf_len = RTE_MIN(rxq->rx_buf_len,
    2914                 :            :                                           I40E_RX_MAX_DATA_BUF_SIZE);
    2915                 :          0 :                 rxq->hs_mode = i40e_header_split_none;
    2916                 :          0 :                 break;
    2917                 :            :         }
    2918                 :            : 
    2919                 :          0 :         rxq->max_pkt_len =
    2920                 :          0 :                 RTE_MIN(hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len,
    2921                 :            :                                 data->mtu + I40E_ETH_OVERHEAD);
    2922         [ #  # ]:          0 :         if (rxq->max_pkt_len < RTE_ETHER_MIN_LEN ||
    2923                 :            :                 rxq->max_pkt_len > I40E_FRAME_SIZE_MAX) {
    2924                 :          0 :                 PMD_DRV_LOG(ERR, "maximum packet length must be "
    2925                 :            :                             "larger than %u and smaller than %u",
    2926                 :            :                             (uint32_t)RTE_ETHER_MIN_LEN,
    2927                 :            :                             (uint32_t)I40E_FRAME_SIZE_MAX);
    2928                 :          0 :                 return I40E_ERR_CONFIG;
    2929                 :            :         }
    2930                 :            : 
    2931                 :            :         return 0;
    2932                 :            : }
    2933                 :            : 
    2934                 :            : /* Init the RX queue in hardware */
    2935                 :            : int
    2936                 :          0 : i40e_rx_queue_init(struct i40e_rx_queue *rxq)
    2937                 :            : {
    2938                 :            :         int err = I40E_SUCCESS;
    2939                 :          0 :         struct i40e_hw *hw = I40E_VSI_TO_HW(rxq->vsi);
    2940                 :          0 :         struct rte_eth_dev_data *dev_data = I40E_VSI_TO_DEV_DATA(rxq->vsi);
    2941                 :          0 :         uint16_t pf_q = rxq->reg_idx;
    2942                 :            :         uint16_t buf_size;
    2943                 :            :         struct i40e_hmc_obj_rxq rx_ctx;
    2944                 :            : 
    2945                 :          0 :         err = i40e_rx_queue_config(rxq);
    2946         [ #  # ]:          0 :         if (err < 0) {
    2947                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to config RX queue");
    2948                 :          0 :                 return err;
    2949                 :            :         }
    2950                 :            : 
    2951                 :            :         /* Clear the context structure first */
    2952                 :            :         memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
    2953                 :          0 :         rx_ctx.dbuff = rxq->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
    2954                 :          0 :         rx_ctx.hbuff = rxq->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
    2955                 :            : 
    2956                 :          0 :         rx_ctx.base = rxq->rx_ring_phys_addr / I40E_QUEUE_BASE_ADDR_UNIT;
    2957                 :          0 :         rx_ctx.qlen = rxq->nb_rx_desc;
    2958                 :            : #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC
    2959                 :          0 :         rx_ctx.dsize = 1;
    2960                 :            : #endif
    2961                 :          0 :         rx_ctx.dtype = rxq->hs_mode;
    2962         [ #  # ]:          0 :         if (rxq->hs_mode)
    2963                 :          0 :                 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_ALL;
    2964                 :            :         else
    2965                 :            :                 rx_ctx.hsplit_0 = I40E_HEADER_SPLIT_NONE;
    2966                 :          0 :         rx_ctx.rxmax = rxq->max_pkt_len;
    2967                 :          0 :         rx_ctx.tphrdesc_ena = 1;
    2968                 :          0 :         rx_ctx.tphwdesc_ena = 1;
    2969                 :          0 :         rx_ctx.tphdata_ena = 1;
    2970                 :          0 :         rx_ctx.tphhead_ena = 1;
    2971                 :          0 :         rx_ctx.lrxqthresh = 2;
    2972                 :          0 :         rx_ctx.crcstrip = (rxq->crc_len == 0) ? 1 : 0;
    2973                 :          0 :         rx_ctx.l2tsel = 1;
    2974                 :            :         /* showiv indicates if inner VLAN is stripped inside of tunnel
    2975                 :            :          * packet. When set it to 1, vlan information is stripped from
    2976                 :            :          * the inner header, but the hardware does not put it in the
    2977                 :            :          * descriptor. So set it zero by default.
    2978                 :            :          */
    2979                 :            :         rx_ctx.showiv = 0;
    2980                 :          0 :         rx_ctx.prefena = 1;
    2981                 :            : 
    2982                 :          0 :         err = i40e_clear_lan_rx_queue_context(hw, pf_q);
    2983         [ #  # ]:          0 :         if (err != I40E_SUCCESS) {
    2984                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to clear LAN RX queue context");
    2985                 :          0 :                 return err;
    2986                 :            :         }
    2987                 :          0 :         err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
    2988         [ #  # ]:          0 :         if (err != I40E_SUCCESS) {
    2989                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to set LAN RX queue context");
    2990                 :          0 :                 return err;
    2991                 :            :         }
    2992                 :            : 
    2993                 :          0 :         rxq->qrx_tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
    2994                 :            : 
    2995         [ #  # ]:          0 :         buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
    2996                 :            :                 RTE_PKTMBUF_HEADROOM);
    2997                 :            : 
    2998                 :            :         /* Check if scattered RX needs to be used. */
    2999         [ #  # ]:          0 :         if (rxq->max_pkt_len > buf_size)
    3000                 :          0 :                 dev_data->scattered_rx = 1;
    3001                 :            : 
    3002                 :            :         /* Init the RX tail register. */
    3003                 :          0 :         I40E_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
    3004                 :            : 
    3005                 :          0 :         return 0;
    3006                 :            : }
    3007                 :            : 
    3008                 :            : void
    3009                 :          0 : i40e_dev_clear_queues(struct rte_eth_dev *dev)
    3010                 :            : {
    3011                 :            :         uint16_t i;
    3012                 :            : 
    3013                 :          0 :         PMD_INIT_FUNC_TRACE();
    3014                 :            : 
    3015         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    3016         [ #  # ]:          0 :                 if (!dev->data->tx_queues[i])
    3017                 :          0 :                         continue;
    3018                 :          0 :                 i40e_tx_queue_release_mbufs(dev->data->tx_queues[i]);
    3019                 :          0 :                 i40e_reset_tx_queue(dev->data->tx_queues[i]);
    3020                 :            :         }
    3021                 :            : 
    3022         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    3023         [ #  # ]:          0 :                 if (!dev->data->rx_queues[i])
    3024                 :          0 :                         continue;
    3025                 :          0 :                 i40e_rx_queue_release_mbufs(dev->data->rx_queues[i]);
    3026                 :          0 :                 i40e_reset_rx_queue(dev->data->rx_queues[i]);
    3027                 :            :         }
    3028                 :          0 : }
    3029                 :            : 
    3030                 :            : void
    3031                 :          0 : i40e_dev_free_queues(struct rte_eth_dev *dev)
    3032                 :            : {
    3033                 :            :         uint16_t i;
    3034                 :            : 
    3035                 :          0 :         PMD_INIT_FUNC_TRACE();
    3036                 :            : 
    3037         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    3038         [ #  # ]:          0 :                 if (!dev->data->rx_queues[i])
    3039                 :          0 :                         continue;
    3040                 :          0 :                 i40e_rx_queue_release(dev->data->rx_queues[i]);
    3041                 :          0 :                 dev->data->rx_queues[i] = NULL;
    3042                 :            :         }
    3043                 :            : 
    3044         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    3045         [ #  # ]:          0 :                 if (!dev->data->tx_queues[i])
    3046                 :          0 :                         continue;
    3047                 :          0 :                 i40e_tx_queue_release(dev->data->tx_queues[i]);
    3048                 :          0 :                 dev->data->tx_queues[i] = NULL;
    3049                 :            :         }
    3050                 :          0 : }
    3051                 :            : 
    3052                 :            : enum i40e_status_code
    3053                 :          0 : i40e_fdir_setup_tx_resources(struct i40e_pf *pf)
    3054                 :            : {
    3055                 :            :         struct i40e_tx_queue *txq;
    3056                 :            :         const struct rte_memzone *tz = NULL;
    3057                 :            :         struct rte_eth_dev *dev;
    3058                 :            :         uint32_t ring_size;
    3059                 :            : 
    3060         [ #  # ]:          0 :         if (!pf) {
    3061                 :          0 :                 PMD_DRV_LOG(ERR, "PF is not available");
    3062                 :          0 :                 return I40E_ERR_BAD_PTR;
    3063                 :            :         }
    3064                 :            : 
    3065                 :          0 :         dev = &rte_eth_devices[pf->dev_data->port_id];
    3066                 :            : 
    3067                 :            :         /* Allocate the TX queue data structure. */
    3068                 :          0 :         txq = rte_zmalloc_socket("i40e fdir tx queue",
    3069                 :            :                                   sizeof(struct i40e_tx_queue),
    3070                 :            :                                   RTE_CACHE_LINE_SIZE,
    3071                 :            :                                   SOCKET_ID_ANY);
    3072         [ #  # ]:          0 :         if (!txq) {
    3073                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
    3074                 :            :                                         "tx queue structure.");
    3075                 :          0 :                 return I40E_ERR_NO_MEMORY;
    3076                 :            :         }
    3077                 :            : 
    3078                 :            :         /* Allocate TX hardware ring descriptors. */
    3079                 :            :         ring_size = sizeof(struct i40e_tx_desc) * I40E_FDIR_NUM_TX_DESC;
    3080                 :            :         ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
    3081                 :            : 
    3082                 :          0 :         tz = rte_eth_dma_zone_reserve(dev, "fdir_tx_ring",
    3083                 :            :                                       I40E_FDIR_QUEUE_ID, ring_size,
    3084                 :            :                                       I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
    3085         [ #  # ]:          0 :         if (!tz) {
    3086                 :          0 :                 i40e_tx_queue_release(txq);
    3087                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for TX.");
    3088                 :          0 :                 return I40E_ERR_NO_MEMORY;
    3089                 :            :         }
    3090                 :            : 
    3091                 :          0 :         txq->mz = tz;
    3092                 :          0 :         txq->nb_tx_desc = I40E_FDIR_NUM_TX_DESC;
    3093                 :          0 :         txq->queue_id = I40E_FDIR_QUEUE_ID;
    3094                 :          0 :         txq->reg_idx = pf->fdir.fdir_vsi->base_queue;
    3095                 :          0 :         txq->vsi = pf->fdir.fdir_vsi;
    3096                 :            : 
    3097                 :          0 :         txq->tx_ring_phys_addr = tz->iova;
    3098                 :          0 :         txq->tx_ring = (struct i40e_tx_desc *)tz->addr;
    3099                 :            : 
    3100                 :            :         /*
    3101                 :            :          * don't need to allocate software ring and reset for the fdir
    3102                 :            :          * program queue just set the queue has been configured.
    3103                 :            :          */
    3104                 :          0 :         txq->q_set = TRUE;
    3105                 :          0 :         pf->fdir.txq = txq;
    3106                 :          0 :         pf->fdir.txq_available_buf_count = I40E_FDIR_PRG_PKT_CNT;
    3107                 :            : 
    3108                 :          0 :         return I40E_SUCCESS;
    3109                 :            : }
    3110                 :            : 
    3111                 :            : enum i40e_status_code
    3112                 :          0 : i40e_fdir_setup_rx_resources(struct i40e_pf *pf)
    3113                 :            : {
    3114                 :            :         struct i40e_rx_queue *rxq;
    3115                 :            :         const struct rte_memzone *rz = NULL;
    3116                 :            :         uint32_t ring_size;
    3117                 :            :         struct rte_eth_dev *dev;
    3118                 :            : 
    3119         [ #  # ]:          0 :         if (!pf) {
    3120                 :          0 :                 PMD_DRV_LOG(ERR, "PF is not available");
    3121                 :          0 :                 return I40E_ERR_BAD_PTR;
    3122                 :            :         }
    3123                 :            : 
    3124                 :          0 :         dev = &rte_eth_devices[pf->dev_data->port_id];
    3125                 :            : 
    3126                 :            :         /* Allocate the RX queue data structure. */
    3127                 :          0 :         rxq = rte_zmalloc_socket("i40e fdir rx queue",
    3128                 :            :                                   sizeof(struct i40e_rx_queue),
    3129                 :            :                                   RTE_CACHE_LINE_SIZE,
    3130                 :            :                                   SOCKET_ID_ANY);
    3131         [ #  # ]:          0 :         if (!rxq) {
    3132                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to allocate memory for "
    3133                 :            :                                         "rx queue structure.");
    3134                 :          0 :                 return I40E_ERR_NO_MEMORY;
    3135                 :            :         }
    3136                 :            : 
    3137                 :            :         /* Allocate RX hardware ring descriptors. */
    3138                 :            :         ring_size = sizeof(union i40e_rx_desc) * I40E_FDIR_NUM_RX_DESC;
    3139                 :            :         ring_size = RTE_ALIGN(ring_size, I40E_DMA_MEM_ALIGN);
    3140                 :            : 
    3141                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "fdir_rx_ring",
    3142                 :            :                                       I40E_FDIR_QUEUE_ID, ring_size,
    3143                 :            :                                       I40E_RING_BASE_ALIGN, SOCKET_ID_ANY);
    3144         [ #  # ]:          0 :         if (!rz) {
    3145                 :          0 :                 i40e_rx_queue_release(rxq);
    3146                 :          0 :                 PMD_DRV_LOG(ERR, "Failed to reserve DMA memory for RX.");
    3147                 :          0 :                 return I40E_ERR_NO_MEMORY;
    3148                 :            :         }
    3149                 :            : 
    3150                 :          0 :         rxq->mz = rz;
    3151                 :          0 :         rxq->nb_rx_desc = I40E_FDIR_NUM_RX_DESC;
    3152                 :          0 :         rxq->queue_id = I40E_FDIR_QUEUE_ID;
    3153                 :          0 :         rxq->reg_idx = pf->fdir.fdir_vsi->base_queue;
    3154                 :          0 :         rxq->vsi = pf->fdir.fdir_vsi;
    3155                 :            : 
    3156                 :          0 :         rxq->rx_ring_phys_addr = rz->iova;
    3157                 :          0 :         memset(rz->addr, 0, I40E_FDIR_NUM_RX_DESC * sizeof(union i40e_rx_desc));
    3158                 :          0 :         rxq->rx_ring = (union i40e_rx_desc *)rz->addr;
    3159                 :            : 
    3160                 :            :         /*
    3161                 :            :          * Don't need to allocate software ring and reset for the fdir
    3162                 :            :          * rx queue, just set the queue has been configured.
    3163                 :            :          */
    3164                 :          0 :         rxq->q_set = TRUE;
    3165                 :          0 :         pf->fdir.rxq = rxq;
    3166                 :            : 
    3167                 :          0 :         return I40E_SUCCESS;
    3168                 :            : }
    3169                 :            : 
    3170                 :            : void
    3171                 :          0 : i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    3172                 :            :         struct rte_eth_rxq_info *qinfo)
    3173                 :            : {
    3174                 :            :         struct i40e_rx_queue *rxq;
    3175                 :            : 
    3176                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    3177                 :            : 
    3178                 :          0 :         qinfo->mp = rxq->mp;
    3179                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    3180                 :          0 :         qinfo->nb_desc = rxq->nb_rx_desc;
    3181                 :            : 
    3182                 :          0 :         qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
    3183                 :          0 :         qinfo->conf.rx_drop_en = rxq->drop_en;
    3184                 :          0 :         qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
    3185                 :          0 :         qinfo->conf.offloads = rxq->offloads;
    3186                 :          0 : }
    3187                 :            : 
    3188                 :            : void
    3189                 :          0 : i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    3190                 :            :         struct rte_eth_txq_info *qinfo)
    3191                 :            : {
    3192                 :            :         struct i40e_tx_queue *txq;
    3193                 :            : 
    3194                 :          0 :         txq = dev->data->tx_queues[queue_id];
    3195                 :            : 
    3196                 :          0 :         qinfo->nb_desc = txq->nb_tx_desc;
    3197                 :            : 
    3198                 :          0 :         qinfo->conf.tx_thresh.pthresh = txq->pthresh;
    3199                 :          0 :         qinfo->conf.tx_thresh.hthresh = txq->hthresh;
    3200                 :          0 :         qinfo->conf.tx_thresh.wthresh = txq->wthresh;
    3201                 :            : 
    3202                 :          0 :         qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
    3203                 :          0 :         qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
    3204                 :          0 :         qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
    3205                 :          0 :         qinfo->conf.offloads = txq->offloads;
    3206                 :          0 : }
    3207                 :            : 
    3208                 :            : void
    3209                 :          0 : i40e_recycle_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    3210                 :            :         struct rte_eth_recycle_rxq_info *recycle_rxq_info)
    3211                 :            : {
    3212                 :            :         struct i40e_rx_queue *rxq;
    3213                 :          0 :         struct i40e_adapter *ad =
    3214                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3215                 :            : 
    3216                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    3217                 :            : 
    3218                 :          0 :         recycle_rxq_info->mbuf_ring = (void *)rxq->sw_ring;
    3219                 :          0 :         recycle_rxq_info->mp = rxq->mp;
    3220                 :          0 :         recycle_rxq_info->mbuf_ring_size = rxq->nb_rx_desc;
    3221                 :          0 :         recycle_rxq_info->receive_tail = &rxq->rx_tail;
    3222                 :            : 
    3223         [ #  # ]:          0 :         if (ad->rx_vec_allowed) {
    3224                 :          0 :                 recycle_rxq_info->refill_requirement = RTE_I40E_RXQ_REARM_THRESH;
    3225                 :          0 :                 recycle_rxq_info->refill_head = &rxq->rxrearm_start;
    3226                 :            :         } else {
    3227                 :          0 :                 recycle_rxq_info->refill_requirement = rxq->rx_free_thresh;
    3228                 :          0 :                 recycle_rxq_info->refill_head = &rxq->rx_free_trigger;
    3229                 :            :         }
    3230                 :          0 : }
    3231                 :            : 
    3232                 :            : #ifdef RTE_ARCH_X86
    3233                 :            : static inline bool
    3234                 :          0 : get_avx_supported(bool request_avx512)
    3235                 :            : {
    3236         [ #  # ]:          0 :         if (request_avx512) {
    3237   [ #  #  #  # ]:          0 :                 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512 &&
    3238         [ #  # ]:          0 :                 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1 &&
    3239                 :          0 :                 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512BW) == 1)
    3240                 :            : #ifdef CC_AVX512_SUPPORT
    3241                 :          0 :                         return true;
    3242                 :            : #else
    3243                 :            :                 PMD_DRV_LOG(NOTICE,
    3244                 :            :                         "AVX512 is not supported in build env");
    3245                 :            :                 return false;
    3246                 :            : #endif
    3247                 :            :         } else {
    3248   [ #  #  #  # ]:          0 :                 if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256 &&
    3249         [ #  # ]:          0 :                                 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) == 1 &&
    3250                 :          0 :                                 rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) == 1)
    3251                 :          0 :                         return true;
    3252                 :            :         }
    3253                 :            : 
    3254                 :            :         return false;
    3255                 :            : }
    3256                 :            : #endif /* RTE_ARCH_X86 */
    3257                 :            : 
    3258                 :            : 
    3259                 :            : void __rte_cold
    3260                 :          0 : i40e_set_rx_function(struct rte_eth_dev *dev)
    3261                 :            : {
    3262                 :          0 :         struct i40e_adapter *ad =
    3263                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3264                 :            :         uint16_t rx_using_sse, i;
    3265                 :            :         /* In order to allow Vector Rx there are a few configuration
    3266                 :            :          * conditions to be met and Rx Bulk Allocation should be allowed.
    3267                 :            :          */
    3268         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    3269                 :            : #ifdef RTE_ARCH_X86
    3270                 :          0 :                 ad->rx_use_avx512 = false;
    3271                 :          0 :                 ad->rx_use_avx2 = false;
    3272                 :            : #endif
    3273         [ #  # ]:          0 :                 if (i40e_rx_vec_dev_conf_condition_check(dev) ||
    3274         [ #  # ]:          0 :                     !ad->rx_bulk_alloc_allowed) {
    3275                 :          0 :                         PMD_INIT_LOG(DEBUG, "Port[%d] doesn't meet"
    3276                 :            :                                      " Vector Rx preconditions",
    3277                 :            :                                      dev->data->port_id);
    3278                 :            : 
    3279                 :          0 :                         ad->rx_vec_allowed = false;
    3280                 :            :                 }
    3281         [ #  # ]:          0 :                 if (ad->rx_vec_allowed) {
    3282         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    3283                 :          0 :                                 struct i40e_rx_queue *rxq =
    3284                 :          0 :                                         dev->data->rx_queues[i];
    3285                 :            : 
    3286   [ #  #  #  # ]:          0 :                                 if (rxq && i40e_rxq_vec_setup(rxq)) {
    3287                 :          0 :                                         ad->rx_vec_allowed = false;
    3288                 :          0 :                                         break;
    3289                 :            :                                 }
    3290                 :            :                         }
    3291                 :            : #ifdef RTE_ARCH_X86
    3292                 :          0 :                         ad->rx_use_avx512 = get_avx_supported(1);
    3293                 :            : 
    3294         [ #  # ]:          0 :                         if (!ad->rx_use_avx512)
    3295                 :          0 :                                 ad->rx_use_avx2 = get_avx_supported(0);
    3296                 :            : #endif
    3297                 :            :                 }
    3298                 :            :         }
    3299                 :            : 
    3300   [ #  #  #  # ]:          0 :         if (ad->rx_vec_allowed  &&
    3301                 :          0 :             rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
    3302                 :            : #ifdef RTE_ARCH_X86
    3303         [ #  # ]:          0 :                 if (dev->data->scattered_rx) {
    3304         [ #  # ]:          0 :                         if (ad->rx_use_avx512) {
    3305                 :            : #ifdef CC_AVX512_SUPPORT
    3306                 :          0 :                                 PMD_DRV_LOG(NOTICE,
    3307                 :            :                                         "Using AVX512 Vector Scattered Rx (port %d).",
    3308                 :            :                                         dev->data->port_id);
    3309                 :          0 :                                 dev->rx_pkt_burst =
    3310                 :            :                                         i40e_recv_scattered_pkts_vec_avx512;
    3311                 :            : #endif
    3312                 :            :                         } else {
    3313         [ #  # ]:          0 :                                 PMD_INIT_LOG(DEBUG,
    3314                 :            :                                         "Using %sVector Scattered Rx (port %d).",
    3315                 :            :                                         ad->rx_use_avx2 ? "avx2 " : "",
    3316                 :            :                                         dev->data->port_id);
    3317                 :          0 :                                 dev->rx_pkt_burst = ad->rx_use_avx2 ?
    3318         [ #  # ]:          0 :                                         i40e_recv_scattered_pkts_vec_avx2 :
    3319                 :            :                                         i40e_recv_scattered_pkts_vec;
    3320                 :          0 :                                 dev->recycle_rx_descriptors_refill =
    3321                 :            :                                         i40e_recycle_rx_descriptors_refill_vec;
    3322                 :            :                         }
    3323                 :            :                 } else {
    3324         [ #  # ]:          0 :                         if (ad->rx_use_avx512) {
    3325                 :            : #ifdef CC_AVX512_SUPPORT
    3326                 :          0 :                                 PMD_DRV_LOG(NOTICE,
    3327                 :            :                                         "Using AVX512 Vector Rx (port %d).",
    3328                 :            :                                         dev->data->port_id);
    3329                 :          0 :                                 dev->rx_pkt_burst =
    3330                 :            :                                         i40e_recv_pkts_vec_avx512;
    3331                 :            : #endif
    3332                 :            :                         } else {
    3333         [ #  # ]:          0 :                                 PMD_INIT_LOG(DEBUG,
    3334                 :            :                                         "Using %sVector Rx (port %d).",
    3335                 :            :                                         ad->rx_use_avx2 ? "avx2 " : "",
    3336                 :            :                                         dev->data->port_id);
    3337                 :          0 :                                 dev->rx_pkt_burst = ad->rx_use_avx2 ?
    3338         [ #  # ]:          0 :                                         i40e_recv_pkts_vec_avx2 :
    3339                 :            :                                         i40e_recv_pkts_vec;
    3340                 :          0 :                                 dev->recycle_rx_descriptors_refill =
    3341                 :            :                                         i40e_recycle_rx_descriptors_refill_vec;
    3342                 :            :                         }
    3343                 :            :                 }
    3344                 :            : #else /* RTE_ARCH_X86 */
    3345                 :            :                 dev->recycle_rx_descriptors_refill = i40e_recycle_rx_descriptors_refill_vec;
    3346                 :            :                 if (dev->data->scattered_rx) {
    3347                 :            :                         PMD_INIT_LOG(DEBUG,
    3348                 :            :                                      "Using Vector Scattered Rx (port %d).",
    3349                 :            :                                      dev->data->port_id);
    3350                 :            :                         dev->rx_pkt_burst = i40e_recv_scattered_pkts_vec;
    3351                 :            :                 } else {
    3352                 :            :                         PMD_INIT_LOG(DEBUG, "Using Vector Rx (port %d).",
    3353                 :            :                                      dev->data->port_id);
    3354                 :            :                         dev->rx_pkt_burst = i40e_recv_pkts_vec;
    3355                 :            :                 }
    3356                 :            : #endif /* RTE_ARCH_X86 */
    3357   [ #  #  #  # ]:          0 :         } else if (!dev->data->scattered_rx && ad->rx_bulk_alloc_allowed) {
    3358                 :          0 :                 PMD_INIT_LOG(DEBUG, "Rx Burst Bulk Alloc Preconditions are "
    3359                 :            :                                     "satisfied. Rx Burst Bulk Alloc function "
    3360                 :            :                                     "will be used on port=%d.",
    3361                 :            :                              dev->data->port_id);
    3362                 :            : 
    3363                 :          0 :                 dev->rx_pkt_burst = i40e_recv_pkts_bulk_alloc;
    3364                 :            :         } else {
    3365                 :            :                 /* Simple Rx Path. */
    3366                 :          0 :                 PMD_INIT_LOG(DEBUG, "Simple Rx path will be used on port=%d.",
    3367                 :            :                              dev->data->port_id);
    3368                 :          0 :                 dev->rx_pkt_burst = dev->data->scattered_rx ?
    3369         [ #  # ]:          0 :                                         i40e_recv_scattered_pkts :
    3370                 :            :                                         i40e_recv_pkts;
    3371                 :            :         }
    3372                 :            : 
    3373                 :            :         /* Propagate information about RX function choice through all queues. */
    3374         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    3375                 :          0 :                 rx_using_sse =
    3376         [ #  # ]:          0 :                         (dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec ||
    3377         [ #  # ]:          0 :                          dev->rx_pkt_burst == i40e_recv_pkts_vec ||
    3378                 :            : #ifdef CC_AVX512_SUPPORT
    3379         [ #  # ]:          0 :                          dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx512 ||
    3380         [ #  # ]:          0 :                          dev->rx_pkt_burst == i40e_recv_pkts_vec_avx512 ||
    3381                 :            : #endif
    3382   [ #  #  #  # ]:          0 :                          dev->rx_pkt_burst == i40e_recv_scattered_pkts_vec_avx2 ||
    3383                 :            :                          dev->rx_pkt_burst == i40e_recv_pkts_vec_avx2);
    3384                 :            : 
    3385         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
    3386                 :          0 :                         struct i40e_rx_queue *rxq = dev->data->rx_queues[i];
    3387                 :            : 
    3388         [ #  # ]:          0 :                         if (rxq)
    3389                 :          0 :                                 rxq->rx_using_sse = rx_using_sse;
    3390                 :            :                 }
    3391                 :            :         }
    3392                 :          0 : }
    3393                 :            : 
    3394                 :            : static const struct {
    3395                 :            :         eth_rx_burst_t pkt_burst;
    3396                 :            :         const char *info;
    3397                 :            : } i40e_rx_burst_infos[] = {
    3398                 :            :         { i40e_recv_scattered_pkts,          "Scalar Scattered" },
    3399                 :            :         { i40e_recv_pkts_bulk_alloc,         "Scalar Bulk Alloc" },
    3400                 :            :         { i40e_recv_pkts,                    "Scalar" },
    3401                 :            : #ifdef RTE_ARCH_X86
    3402                 :            : #ifdef CC_AVX512_SUPPORT
    3403                 :            :         { i40e_recv_scattered_pkts_vec_avx512, "Vector AVX512 Scattered" },
    3404                 :            :         { i40e_recv_pkts_vec_avx512,           "Vector AVX512" },
    3405                 :            : #endif
    3406                 :            :         { i40e_recv_scattered_pkts_vec_avx2, "Vector AVX2 Scattered" },
    3407                 :            :         { i40e_recv_pkts_vec_avx2,           "Vector AVX2" },
    3408                 :            :         { i40e_recv_scattered_pkts_vec,      "Vector SSE Scattered" },
    3409                 :            :         { i40e_recv_pkts_vec,                "Vector SSE" },
    3410                 :            : #elif defined(RTE_ARCH_ARM64)
    3411                 :            :         { i40e_recv_scattered_pkts_vec,      "Vector Neon Scattered" },
    3412                 :            :         { i40e_recv_pkts_vec,                "Vector Neon" },
    3413                 :            : #elif defined(RTE_ARCH_PPC_64)
    3414                 :            :         { i40e_recv_scattered_pkts_vec,      "Vector AltiVec Scattered" },
    3415                 :            :         { i40e_recv_pkts_vec,                "Vector AltiVec" },
    3416                 :            : #endif
    3417                 :            : };
    3418                 :            : 
    3419                 :            : int
    3420                 :          0 : i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
    3421                 :            :                        struct rte_eth_burst_mode *mode)
    3422                 :            : {
    3423                 :          0 :         eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
    3424                 :            :         int ret = -EINVAL;
    3425                 :            :         unsigned int i;
    3426                 :            : 
    3427         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(i40e_rx_burst_infos); ++i) {
    3428         [ #  # ]:          0 :                 if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) {
    3429                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
    3430                 :          0 :                                  i40e_rx_burst_infos[i].info);
    3431                 :            :                         ret = 0;
    3432                 :          0 :                         break;
    3433                 :            :                 }
    3434                 :            :         }
    3435                 :            : 
    3436                 :          0 :         return ret;
    3437                 :            : }
    3438                 :            : 
    3439                 :            : void __rte_cold
    3440                 :          0 : i40e_set_tx_function_flag(struct rte_eth_dev *dev, struct i40e_tx_queue *txq)
    3441                 :            : {
    3442                 :          0 :         struct i40e_adapter *ad =
    3443                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3444                 :            : 
    3445                 :            :         /* Use a simple Tx queue if possible (only fast free is allowed) */
    3446                 :          0 :         ad->tx_simple_allowed =
    3447                 :          0 :                 (txq->offloads ==
    3448         [ #  # ]:          0 :                  (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) &&
    3449         [ #  # ]:          0 :                  txq->tx_rs_thresh >= RTE_PMD_I40E_TX_MAX_BURST);
    3450         [ #  # ]:          0 :         ad->tx_vec_allowed = (ad->tx_simple_allowed &&
    3451         [ #  # ]:          0 :                         txq->tx_rs_thresh <= RTE_I40E_TX_MAX_FREE_BUF_SZ);
    3452                 :            : 
    3453         [ #  # ]:          0 :         if (ad->tx_vec_allowed)
    3454                 :          0 :                 PMD_INIT_LOG(DEBUG, "Vector Tx can be enabled on Tx queue %u.",
    3455                 :            :                                 txq->queue_id);
    3456         [ #  # ]:          0 :         else if (ad->tx_simple_allowed)
    3457                 :          0 :                 PMD_INIT_LOG(DEBUG, "Simple Tx can be enabled on Tx queue %u.",
    3458                 :            :                                 txq->queue_id);
    3459                 :            :         else
    3460                 :          0 :                 PMD_INIT_LOG(DEBUG,
    3461                 :            :                                 "Neither simple nor vector Tx enabled on Tx queue %u\n",
    3462                 :            :                                 txq->queue_id);
    3463                 :          0 : }
    3464                 :            : 
    3465                 :            : void __rte_cold
    3466                 :          0 : i40e_set_tx_function(struct rte_eth_dev *dev)
    3467                 :            : {
    3468                 :          0 :         struct i40e_adapter *ad =
    3469                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3470                 :            :         int i;
    3471                 :            : 
    3472         [ #  # ]:          0 :         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
    3473                 :            : #ifdef RTE_ARCH_X86
    3474                 :          0 :                 ad->tx_use_avx2 = false;
    3475                 :          0 :                 ad->tx_use_avx512 = false;
    3476                 :            : #endif
    3477         [ #  # ]:          0 :                 if (ad->tx_vec_allowed) {
    3478         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    3479                 :          0 :                                 struct i40e_tx_queue *txq =
    3480                 :          0 :                                         dev->data->tx_queues[i];
    3481                 :            : 
    3482   [ #  #  #  # ]:          0 :                                 if (txq && i40e_txq_vec_setup(txq)) {
    3483                 :          0 :                                         ad->tx_vec_allowed = false;
    3484                 :          0 :                                         break;
    3485                 :            :                                 }
    3486                 :            :                         }
    3487                 :            : #ifdef RTE_ARCH_X86
    3488                 :          0 :                         ad->tx_use_avx512 = get_avx_supported(1);
    3489                 :            : 
    3490         [ #  # ]:          0 :                         if (!ad->tx_use_avx512)
    3491                 :          0 :                                 ad->tx_use_avx2 = get_avx_supported(0);
    3492                 :            : #endif
    3493                 :            :                 }
    3494                 :            :         }
    3495                 :            : 
    3496         [ #  # ]:          0 :         if (ad->tx_simple_allowed) {
    3497   [ #  #  #  # ]:          0 :                 if (ad->tx_vec_allowed &&
    3498                 :          0 :                     rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
    3499                 :            : #ifdef RTE_ARCH_X86
    3500         [ #  # ]:          0 :                         if (ad->tx_use_avx512) {
    3501                 :            : #ifdef CC_AVX512_SUPPORT
    3502                 :          0 :                                 PMD_DRV_LOG(NOTICE, "Using AVX512 Vector Tx (port %d).",
    3503                 :            :                                             dev->data->port_id);
    3504                 :          0 :                                 dev->tx_pkt_burst = i40e_xmit_pkts_vec_avx512;
    3505                 :            : #endif
    3506                 :            :                         } else {
    3507         [ #  # ]:          0 :                                 PMD_INIT_LOG(DEBUG, "Using %sVector Tx (port %d).",
    3508                 :            :                                              ad->tx_use_avx2 ? "avx2 " : "",
    3509                 :            :                                              dev->data->port_id);
    3510                 :          0 :                                 dev->tx_pkt_burst = ad->tx_use_avx2 ?
    3511         [ #  # ]:          0 :                                                     i40e_xmit_pkts_vec_avx2 :
    3512                 :            :                                                     i40e_xmit_pkts_vec;
    3513                 :          0 :                                 dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
    3514                 :            :                         }
    3515                 :            : #else /* RTE_ARCH_X86 */
    3516                 :            :                         PMD_INIT_LOG(DEBUG, "Using Vector Tx (port %d).",
    3517                 :            :                                      dev->data->port_id);
    3518                 :            :                         dev->tx_pkt_burst = i40e_xmit_pkts_vec;
    3519                 :            :                         dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
    3520                 :            : #endif /* RTE_ARCH_X86 */
    3521                 :            :                 } else {
    3522                 :          0 :                         PMD_INIT_LOG(DEBUG, "Simple tx finally be used.");
    3523                 :          0 :                         dev->tx_pkt_burst = i40e_xmit_pkts_simple;
    3524                 :          0 :                         dev->recycle_tx_mbufs_reuse = i40e_recycle_tx_mbufs_reuse_vec;
    3525                 :            :                 }
    3526                 :          0 :                 dev->tx_pkt_prepare = i40e_simple_prep_pkts;
    3527                 :            :         } else {
    3528                 :          0 :                 PMD_INIT_LOG(DEBUG, "Xmit tx finally be used.");
    3529                 :          0 :                 dev->tx_pkt_burst = i40e_xmit_pkts;
    3530                 :          0 :                 dev->tx_pkt_prepare = i40e_prep_pkts;
    3531                 :            :         }
    3532                 :          0 : }
    3533                 :            : 
    3534                 :            : static const struct {
    3535                 :            :         eth_tx_burst_t pkt_burst;
    3536                 :            :         const char *info;
    3537                 :            : } i40e_tx_burst_infos[] = {
    3538                 :            :         { i40e_xmit_pkts_simple,   "Scalar Simple" },
    3539                 :            :         { i40e_xmit_pkts,          "Scalar" },
    3540                 :            : #ifdef RTE_ARCH_X86
    3541                 :            : #ifdef CC_AVX512_SUPPORT
    3542                 :            :         { i40e_xmit_pkts_vec_avx512, "Vector AVX512" },
    3543                 :            : #endif
    3544                 :            :         { i40e_xmit_pkts_vec_avx2, "Vector AVX2" },
    3545                 :            :         { i40e_xmit_pkts_vec,      "Vector SSE" },
    3546                 :            : #elif defined(RTE_ARCH_ARM64)
    3547                 :            :         { i40e_xmit_pkts_vec,      "Vector Neon" },
    3548                 :            : #elif defined(RTE_ARCH_PPC_64)
    3549                 :            :         { i40e_xmit_pkts_vec,      "Vector AltiVec" },
    3550                 :            : #endif
    3551                 :            : };
    3552                 :            : 
    3553                 :            : int
    3554                 :          0 : i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
    3555                 :            :                        struct rte_eth_burst_mode *mode)
    3556                 :            : {
    3557                 :          0 :         eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
    3558                 :            :         int ret = -EINVAL;
    3559                 :            :         unsigned int i;
    3560                 :            : 
    3561         [ #  # ]:          0 :         for (i = 0; i < RTE_DIM(i40e_tx_burst_infos); ++i) {
    3562         [ #  # ]:          0 :                 if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) {
    3563                 :          0 :                         snprintf(mode->info, sizeof(mode->info), "%s",
    3564                 :          0 :                                  i40e_tx_burst_infos[i].info);
    3565                 :            :                         ret = 0;
    3566                 :          0 :                         break;
    3567                 :            :                 }
    3568                 :            :         }
    3569                 :            : 
    3570                 :          0 :         return ret;
    3571                 :            : }
    3572                 :            : 
    3573                 :            : void __rte_cold
    3574                 :          0 : i40e_set_default_ptype_table(struct rte_eth_dev *dev)
    3575                 :            : {
    3576                 :          0 :         struct i40e_adapter *ad =
    3577                 :          0 :                 I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3578                 :            :         int i;
    3579                 :            : 
    3580         [ #  # ]:          0 :         for (i = 0; i < I40E_MAX_PKT_TYPE; i++)
    3581                 :          0 :                 ad->ptype_tbl[i] = i40e_get_default_pkt_type(i);
    3582                 :          0 : }
    3583                 :            : 
    3584                 :            : void __rte_cold
    3585                 :          0 : i40e_set_default_pctype_table(struct rte_eth_dev *dev)
    3586                 :            : {
    3587                 :          0 :         struct i40e_adapter *ad =
    3588                 :          0 :                         I40E_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
    3589                 :            :         struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3590                 :            :         int i;
    3591                 :            : 
    3592         [ #  # ]:          0 :         for (i = 0; i < I40E_FLOW_TYPE_MAX; i++)
    3593                 :          0 :                 ad->pctypes_tbl[i] = 0ULL;
    3594                 :          0 :         ad->flow_types_mask = 0ULL;
    3595                 :          0 :         ad->pctypes_mask = 0ULL;
    3596                 :            : 
    3597                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV4] =
    3598                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4);
    3599                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] =
    3600                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP);
    3601                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] =
    3602                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
    3603                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_SCTP] =
    3604                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP);
    3605                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_OTHER] =
    3606                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
    3607                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_FRAG_IPV6] =
    3608                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6);
    3609                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] =
    3610                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP);
    3611                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] =
    3612                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
    3613                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_SCTP] =
    3614                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP);
    3615                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_OTHER] =
    3616                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
    3617                 :          0 :         ad->pctypes_tbl[RTE_ETH_FLOW_L2_PAYLOAD] =
    3618                 :            :                                 (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD);
    3619                 :            : 
    3620         [ #  # ]:          0 :         if (hw->mac.type == I40E_MAC_X722 ||
    3621                 :            :                 hw->mac.type == I40E_MAC_X722_VF) {
    3622                 :            :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
    3623                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP);
    3624                 :          0 :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_UDP] |=
    3625                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
    3626                 :          0 :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV4_TCP] |=
    3627                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
    3628                 :            :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
    3629                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP);
    3630                 :          0 :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_UDP] |=
    3631                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
    3632                 :          0 :                 ad->pctypes_tbl[RTE_ETH_FLOW_NONFRAG_IPV6_TCP] |=
    3633                 :            :                         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
    3634                 :            :         }
    3635                 :            : 
    3636         [ #  # ]:          0 :         for (i = 0; i < I40E_FLOW_TYPE_MAX; i++) {
    3637         [ #  # ]:          0 :                 if (ad->pctypes_tbl[i])
    3638                 :          0 :                         ad->flow_types_mask |= (1ULL << i);
    3639                 :          0 :                 ad->pctypes_mask |= ad->pctypes_tbl[i];
    3640                 :            :         }
    3641                 :          0 : }
    3642                 :            : 
    3643                 :            : #ifndef RTE_ARCH_X86
    3644                 :            : uint16_t
    3645                 :            : i40e_recv_pkts_vec_avx2(void __rte_unused *rx_queue,
    3646                 :            :                         struct rte_mbuf __rte_unused **rx_pkts,
    3647                 :            :                         uint16_t __rte_unused nb_pkts)
    3648                 :            : {
    3649                 :            :         return 0;
    3650                 :            : }
    3651                 :            : 
    3652                 :            : uint16_t
    3653                 :            : i40e_recv_scattered_pkts_vec_avx2(void __rte_unused *rx_queue,
    3654                 :            :                         struct rte_mbuf __rte_unused **rx_pkts,
    3655                 :            :                         uint16_t __rte_unused nb_pkts)
    3656                 :            : {
    3657                 :            :         return 0;
    3658                 :            : }
    3659                 :            : 
    3660                 :            : uint16_t
    3661                 :            : i40e_xmit_pkts_vec_avx2(void __rte_unused * tx_queue,
    3662                 :            :                           struct rte_mbuf __rte_unused **tx_pkts,
    3663                 :            :                           uint16_t __rte_unused nb_pkts)
    3664                 :            : {
    3665                 :            :         return 0;
    3666                 :            : }
    3667                 :            : #endif /* ifndef RTE_ARCH_X86 */

Generated by: LCOV version 1.14