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

Generated by: LCOV version 1.14