LCOV - code coverage report
Current view: top level - drivers/net/e1000 - igb_rxtx.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 959 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 43 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 577 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 <sys/queue.h>
       6                 :            : 
       7                 :            : #include <stdio.h>
       8                 :            : #include <stdlib.h>
       9                 :            : #include <string.h>
      10                 :            : #include <errno.h>
      11                 :            : #include <stdint.h>
      12                 :            : #include <stdarg.h>
      13                 :            : #include <inttypes.h>
      14                 :            : 
      15                 :            : #include <rte_interrupts.h>
      16                 :            : #include <rte_byteorder.h>
      17                 :            : #include <rte_common.h>
      18                 :            : #include <rte_log.h>
      19                 :            : #include <rte_debug.h>
      20                 :            : #include <rte_pci.h>
      21                 :            : #include <rte_memory.h>
      22                 :            : #include <rte_memcpy.h>
      23                 :            : #include <rte_memzone.h>
      24                 :            : #include <rte_launch.h>
      25                 :            : #include <rte_eal.h>
      26                 :            : #include <rte_per_lcore.h>
      27                 :            : #include <rte_lcore.h>
      28                 :            : #include <rte_atomic.h>
      29                 :            : #include <rte_branch_prediction.h>
      30                 :            : #include <rte_mempool.h>
      31                 :            : #include <rte_malloc.h>
      32                 :            : #include <rte_mbuf.h>
      33                 :            : #include <rte_ether.h>
      34                 :            : #include <ethdev_driver.h>
      35                 :            : #include <rte_prefetch.h>
      36                 :            : #include <rte_udp.h>
      37                 :            : #include <rte_tcp.h>
      38                 :            : #include <rte_sctp.h>
      39                 :            : #include <rte_net.h>
      40                 :            : #include <rte_string_fns.h>
      41                 :            : 
      42                 :            : #include "e1000_logs.h"
      43                 :            : #include "base/e1000_api.h"
      44                 :            : #include "e1000_ethdev.h"
      45                 :            : 
      46                 :            : #ifdef RTE_LIBRTE_IEEE1588
      47                 :            : #define IGB_TX_IEEE1588_TMST RTE_MBUF_F_TX_IEEE1588_TMST
      48                 :            : #else
      49                 :            : #define IGB_TX_IEEE1588_TMST 0
      50                 :            : #endif
      51                 :            : /* Bit Mask to indicate what bits required for building TX context */
      52                 :            : #define IGB_TX_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_IPV6 |  \
      53                 :            :                 RTE_MBUF_F_TX_OUTER_IPV4 |       \
      54                 :            :                 RTE_MBUF_F_TX_IPV6 |             \
      55                 :            :                 RTE_MBUF_F_TX_IPV4 |             \
      56                 :            :                 RTE_MBUF_F_TX_VLAN |             \
      57                 :            :                 RTE_MBUF_F_TX_IP_CKSUM |                 \
      58                 :            :                 RTE_MBUF_F_TX_L4_MASK |          \
      59                 :            :                 RTE_MBUF_F_TX_TCP_SEG |          \
      60                 :            :                 IGB_TX_IEEE1588_TMST)
      61                 :            : 
      62                 :            : #define IGB_TX_OFFLOAD_NOTSUP_MASK \
      63                 :            :                 (RTE_MBUF_F_TX_OFFLOAD_MASK ^ IGB_TX_OFFLOAD_MASK)
      64                 :            : 
      65                 :            : /**
      66                 :            :  * Structure associated with each descriptor of the RX ring of a RX queue.
      67                 :            :  */
      68                 :            : struct igb_rx_entry {
      69                 :            :         struct rte_mbuf *mbuf; /**< mbuf associated with RX descriptor. */
      70                 :            : };
      71                 :            : 
      72                 :            : /**
      73                 :            :  * Structure associated with each descriptor of the TX ring of a TX queue.
      74                 :            :  */
      75                 :            : struct igb_tx_entry {
      76                 :            :         struct rte_mbuf *mbuf; /**< mbuf associated with TX desc, if any. */
      77                 :            :         uint16_t next_id; /**< Index of next descriptor in ring. */
      78                 :            :         uint16_t last_id; /**< Index of last scattered descriptor. */
      79                 :            : };
      80                 :            : 
      81                 :            : /**
      82                 :            :  * rx queue flags
      83                 :            :  */
      84                 :            : enum igb_rxq_flags {
      85                 :            :         IGB_RXQ_FLAG_LB_BSWAP_VLAN = 0x01,
      86                 :            : };
      87                 :            : 
      88                 :            : /**
      89                 :            :  * Structure associated with each RX queue.
      90                 :            :  */
      91                 :            : struct igb_rx_queue {
      92                 :            :         struct rte_mempool  *mb_pool;   /**< mbuf pool to populate RX ring. */
      93                 :            :         volatile union e1000_adv_rx_desc *rx_ring; /**< RX ring virtual address. */
      94                 :            :         uint64_t            rx_ring_phys_addr; /**< RX ring DMA address. */
      95                 :            :         volatile uint32_t   *rdt_reg_addr; /**< RDT register address. */
      96                 :            :         volatile uint32_t   *rdh_reg_addr; /**< RDH register address. */
      97                 :            :         struct igb_rx_entry *sw_ring;   /**< address of RX software ring. */
      98                 :            :         struct rte_mbuf *pkt_first_seg; /**< First segment of current packet. */
      99                 :            :         struct rte_mbuf *pkt_last_seg;  /**< Last segment of current packet. */
     100                 :            :         uint16_t            nb_rx_desc; /**< number of RX descriptors. */
     101                 :            :         uint16_t            rx_tail;    /**< current value of RDT register. */
     102                 :            :         uint16_t            nb_rx_hold; /**< number of held free RX desc. */
     103                 :            :         uint16_t            rx_free_thresh; /**< max free RX desc to hold. */
     104                 :            :         uint16_t            queue_id;   /**< RX queue index. */
     105                 :            :         uint16_t            reg_idx;    /**< RX queue register index. */
     106                 :            :         uint16_t            port_id;    /**< Device port identifier. */
     107                 :            :         uint8_t             pthresh;    /**< Prefetch threshold register. */
     108                 :            :         uint8_t             hthresh;    /**< Host threshold register. */
     109                 :            :         uint8_t             wthresh;    /**< Write-back threshold register. */
     110                 :            :         uint8_t             crc_len;    /**< 0 if CRC stripped, 4 otherwise. */
     111                 :            :         uint8_t             drop_en;  /**< If not 0, set SRRCTL.Drop_En. */
     112                 :            :         uint32_t            flags;      /**< RX flags. */
     113                 :            :         uint64_t            offloads;   /**< offloads of RTE_ETH_RX_OFFLOAD_* */
     114                 :            :         const struct rte_memzone *mz;
     115                 :            : };
     116                 :            : 
     117                 :            : /**
     118                 :            :  * Hardware context number
     119                 :            :  */
     120                 :            : enum igb_advctx_num {
     121                 :            :         IGB_CTX_0    = 0, /**< CTX0    */
     122                 :            :         IGB_CTX_1    = 1, /**< CTX1    */
     123                 :            :         IGB_CTX_NUM  = 2, /**< CTX_NUM */
     124                 :            : };
     125                 :            : 
     126                 :            : /** Offload features */
     127                 :            : union igb_tx_offload {
     128                 :            :         uint64_t data;
     129                 :            :         struct {
     130                 :            :                 uint64_t l3_len:9; /**< L3 (IP) Header Length. */
     131                 :            :                 uint64_t l2_len:7; /**< L2 (MAC) Header Length. */
     132                 :            :                 uint64_t vlan_tci:16;  /**< VLAN Tag Control Identifier(CPU order). */
     133                 :            :                 uint64_t l4_len:8; /**< L4 (TCP/UDP) Header Length. */
     134                 :            :                 uint64_t tso_segsz:16; /**< TCP TSO segment size. */
     135                 :            : 
     136                 :            :                 /* uint64_t unused:8; */
     137                 :            :         };
     138                 :            : };
     139                 :            : 
     140                 :            : /*
     141                 :            :  * Compare mask for igb_tx_offload.data,
     142                 :            :  * should be in sync with igb_tx_offload layout.
     143                 :            :  * */
     144                 :            : #define TX_MACIP_LEN_CMP_MASK   0x000000000000FFFFULL /**< L2L3 header mask. */
     145                 :            : #define TX_VLAN_CMP_MASK                0x00000000FFFF0000ULL /**< Vlan mask. */
     146                 :            : #define TX_TCP_LEN_CMP_MASK             0x000000FF00000000ULL /**< TCP header mask. */
     147                 :            : #define TX_TSO_MSS_CMP_MASK             0x00FFFF0000000000ULL /**< TSO segsz mask. */
     148                 :            : /** Mac + IP + TCP + Mss mask. */
     149                 :            : #define TX_TSO_CMP_MASK \
     150                 :            :         (TX_MACIP_LEN_CMP_MASK | TX_TCP_LEN_CMP_MASK | TX_TSO_MSS_CMP_MASK)
     151                 :            : 
     152                 :            : /**
     153                 :            :  * Structure to check if new context need be built
     154                 :            :  */
     155                 :            : struct igb_advctx_info {
     156                 :            :         uint64_t flags;           /**< ol_flags related to context build. */
     157                 :            :         /** tx offload: vlan, tso, l2-l3-l4 lengths. */
     158                 :            :         union igb_tx_offload tx_offload;
     159                 :            :         /** compare mask for tx offload. */
     160                 :            :         union igb_tx_offload tx_offload_mask;
     161                 :            : };
     162                 :            : 
     163                 :            : /**
     164                 :            :  * Structure associated with each TX queue.
     165                 :            :  */
     166                 :            : struct igb_tx_queue {
     167                 :            :         volatile union e1000_adv_tx_desc *tx_ring; /**< TX ring address */
     168                 :            :         uint64_t               tx_ring_phys_addr; /**< TX ring DMA address. */
     169                 :            :         struct igb_tx_entry    *sw_ring; /**< virtual address of SW ring. */
     170                 :            :         volatile uint32_t      *tdt_reg_addr; /**< Address of TDT register. */
     171                 :            :         uint32_t               txd_type;      /**< Device-specific TXD type */
     172                 :            :         uint16_t               nb_tx_desc;    /**< number of TX descriptors. */
     173                 :            :         uint16_t               tx_tail; /**< Current value of TDT register. */
     174                 :            :         uint16_t               tx_head;
     175                 :            :         /**< Index of first used TX descriptor. */
     176                 :            :         uint16_t               queue_id; /**< TX queue index. */
     177                 :            :         uint16_t               reg_idx;  /**< TX queue register index. */
     178                 :            :         uint16_t               port_id;  /**< Device port identifier. */
     179                 :            :         uint8_t                pthresh;  /**< Prefetch threshold register. */
     180                 :            :         uint8_t                hthresh;  /**< Host threshold register. */
     181                 :            :         uint8_t                wthresh;  /**< Write-back threshold register. */
     182                 :            :         uint32_t               ctx_curr;
     183                 :            :         /**< Current used hardware descriptor. */
     184                 :            :         uint32_t               ctx_start;
     185                 :            :         /**< Start context position for transmit queue. */
     186                 :            :         struct igb_advctx_info ctx_cache[IGB_CTX_NUM];
     187                 :            :         /**< Hardware context history.*/
     188                 :            :         uint64_t               offloads; /**< offloads of RTE_ETH_TX_OFFLOAD_* */
     189                 :            :         const struct rte_memzone *mz;
     190                 :            : };
     191                 :            : 
     192                 :            : #if 1
     193                 :            : #define RTE_PMD_USE_PREFETCH
     194                 :            : #endif
     195                 :            : 
     196                 :            : #ifdef RTE_PMD_USE_PREFETCH
     197                 :            : #define rte_igb_prefetch(p)     rte_prefetch0(p)
     198                 :            : #else
     199                 :            : #define rte_igb_prefetch(p)     do {} while(0)
     200                 :            : #endif
     201                 :            : 
     202                 :            : #ifdef RTE_PMD_PACKET_PREFETCH
     203                 :            : #define rte_packet_prefetch(p) rte_prefetch1(p)
     204                 :            : #else
     205                 :            : #define rte_packet_prefetch(p)  do {} while(0)
     206                 :            : #endif
     207                 :            : 
     208                 :            : /*
     209                 :            :  * Macro for VMDq feature for 1 GbE NIC.
     210                 :            :  */
     211                 :            : #define E1000_VMOLR_SIZE                        (8)
     212                 :            : #define IGB_TSO_MAX_HDRLEN                      (512)
     213                 :            : #define IGB_TSO_MAX_MSS                         (9216)
     214                 :            : 
     215                 :            : /*********************************************************************
     216                 :            :  *
     217                 :            :  *  TX function
     218                 :            :  *
     219                 :            :  **********************************************************************/
     220                 :            : 
     221                 :            : /*
     222                 :            :  *There're some limitations in hardware for TCP segmentation offload. We
     223                 :            :  *should check whether the parameters are valid.
     224                 :            :  */
     225                 :            : static inline uint64_t
     226                 :            : check_tso_para(uint64_t ol_req, union igb_tx_offload ol_para)
     227                 :            : {
     228                 :          0 :         if (!(ol_req & RTE_MBUF_F_TX_TCP_SEG))
     229                 :            :                 return ol_req;
     230         [ #  # ]:          0 :         if ((ol_para.tso_segsz > IGB_TSO_MAX_MSS) || (ol_para.l2_len +
     231         [ #  # ]:          0 :                         ol_para.l3_len + ol_para.l4_len > IGB_TSO_MAX_HDRLEN)) {
     232                 :          0 :                 ol_req &= ~RTE_MBUF_F_TX_TCP_SEG;
     233                 :          0 :                 ol_req |= RTE_MBUF_F_TX_TCP_CKSUM;
     234                 :            :         }
     235                 :            :         return ol_req;
     236                 :            : }
     237                 :            : 
     238                 :            : /*
     239                 :            :  * Advanced context descriptor are almost same between igb/ixgbe
     240                 :            :  * This is a separate function, looking for optimization opportunity here
     241                 :            :  * Rework required to go with the pre-defined values.
     242                 :            :  */
     243                 :            : 
     244                 :            : static inline void
     245                 :          0 : igbe_set_xmit_ctx(struct igb_tx_queue* txq,
     246                 :            :                 volatile struct e1000_adv_tx_context_desc *ctx_txd,
     247                 :            :                 uint64_t ol_flags, union igb_tx_offload tx_offload, uint64_t txtime)
     248                 :            : {
     249                 :            :         uint32_t type_tucmd_mlhl;
     250                 :            :         uint32_t mss_l4len_idx;
     251                 :            :         uint32_t ctx_idx, ctx_curr;
     252                 :            :         uint32_t vlan_macip_lens;
     253                 :            :         uint32_t launch_time;
     254                 :            :         union igb_tx_offload tx_offload_mask;
     255                 :            : 
     256                 :          0 :         ctx_curr = txq->ctx_curr;
     257                 :          0 :         ctx_idx = ctx_curr + txq->ctx_start;
     258                 :            : 
     259                 :            :         tx_offload_mask.data = 0;
     260                 :            :         type_tucmd_mlhl = 0;
     261                 :            : 
     262                 :            :         /* Specify which HW CTX to upload. */
     263                 :          0 :         mss_l4len_idx = (ctx_idx << E1000_ADVTXD_IDX_SHIFT);
     264                 :            : 
     265         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_VLAN)
     266                 :            :                 tx_offload_mask.data |= TX_VLAN_CMP_MASK;
     267                 :            : 
     268                 :            :         /* check if TCP segmentation required for this packet */
     269         [ #  # ]:          0 :         if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) {
     270                 :            :                 /* implies IP cksum in IPv4 */
     271         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
     272                 :            :                         type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4 |
     273                 :            :                                 E1000_ADVTXD_TUCMD_L4T_TCP |
     274                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     275                 :            :                 else
     276                 :            :                         type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV6 |
     277                 :            :                                 E1000_ADVTXD_TUCMD_L4T_TCP |
     278                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     279                 :            : 
     280                 :          0 :                 tx_offload_mask.data |= TX_TSO_CMP_MASK;
     281                 :          0 :                 mss_l4len_idx |= tx_offload.tso_segsz << E1000_ADVTXD_MSS_SHIFT;
     282                 :          0 :                 mss_l4len_idx |= tx_offload.l4_len << E1000_ADVTXD_L4LEN_SHIFT;
     283                 :            :         } else { /* no TSO, check if hardware checksum is needed */
     284         [ #  # ]:          0 :                 if (ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK))
     285                 :          0 :                         tx_offload_mask.data |= TX_MACIP_LEN_CMP_MASK;
     286                 :            : 
     287         [ #  # ]:          0 :                 if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
     288                 :            :                         type_tucmd_mlhl = E1000_ADVTXD_TUCMD_IPV4;
     289                 :            : 
     290   [ #  #  #  # ]:          0 :                 switch (ol_flags & RTE_MBUF_F_TX_L4_MASK) {
     291                 :          0 :                 case RTE_MBUF_F_TX_UDP_CKSUM:
     292                 :          0 :                         type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_UDP |
     293                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     294                 :          0 :                         mss_l4len_idx |= sizeof(struct rte_udp_hdr)
     295                 :            :                                 << E1000_ADVTXD_L4LEN_SHIFT;
     296                 :          0 :                         break;
     297                 :          0 :                 case RTE_MBUF_F_TX_TCP_CKSUM:
     298                 :          0 :                         type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_TCP |
     299                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     300                 :          0 :                         mss_l4len_idx |= sizeof(struct rte_tcp_hdr)
     301                 :            :                                 << E1000_ADVTXD_L4LEN_SHIFT;
     302                 :          0 :                         break;
     303                 :          0 :                 case RTE_MBUF_F_TX_SCTP_CKSUM:
     304                 :          0 :                         type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_SCTP |
     305                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     306                 :          0 :                         mss_l4len_idx |= sizeof(struct rte_sctp_hdr)
     307                 :            :                                 << E1000_ADVTXD_L4LEN_SHIFT;
     308                 :          0 :                         break;
     309                 :          0 :                 default:
     310                 :          0 :                         type_tucmd_mlhl |= E1000_ADVTXD_TUCMD_L4T_RSV |
     311                 :            :                                 E1000_ADVTXD_DTYP_CTXT | E1000_ADVTXD_DCMD_DEXT;
     312                 :          0 :                         break;
     313                 :            :                 }
     314                 :            :         }
     315                 :            : 
     316         [ #  # ]:          0 :         if (!txtime) {
     317                 :          0 :                 txq->ctx_cache[ctx_curr].flags = ol_flags;
     318                 :          0 :                 txq->ctx_cache[ctx_curr].tx_offload.data =
     319                 :          0 :                         tx_offload_mask.data & tx_offload.data;
     320                 :          0 :                 txq->ctx_cache[ctx_curr].tx_offload_mask = tx_offload_mask;
     321                 :            :         }
     322                 :            : 
     323                 :          0 :         ctx_txd->type_tucmd_mlhl = rte_cpu_to_le_32(type_tucmd_mlhl);
     324                 :          0 :         vlan_macip_lens = (uint32_t)tx_offload.data;
     325                 :          0 :         ctx_txd->vlan_macip_lens = rte_cpu_to_le_32(vlan_macip_lens);
     326                 :          0 :         ctx_txd->mss_l4len_idx = rte_cpu_to_le_32(mss_l4len_idx);
     327                 :          0 :         ctx_txd->u.seqnum_seed = 0;
     328                 :            : 
     329         [ #  # ]:          0 :         if (txtime) {
     330                 :          0 :                 launch_time = (txtime - IGB_I210_TX_OFFSET_BASE) % NSEC_PER_SEC;
     331                 :          0 :                 ctx_txd->u.launch_time = rte_cpu_to_le_32(launch_time / 32);
     332                 :            :         } else {
     333                 :          0 :                 ctx_txd->u.launch_time = 0;
     334                 :            :         }
     335                 :          0 : }
     336                 :            : 
     337                 :            : /*
     338                 :            :  * Check which hardware context can be used. Use the existing match
     339                 :            :  * or create a new context descriptor.
     340                 :            :  */
     341                 :            : static inline uint32_t
     342                 :          0 : what_advctx_update(struct igb_tx_queue *txq, uint64_t flags,
     343                 :            :                 union igb_tx_offload tx_offload)
     344                 :            : {
     345                 :            :         /* If match with the current context */
     346   [ #  #  #  # ]:          0 :         if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
     347                 :            :                 (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
     348                 :            :                 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
     349                 :            :                         return txq->ctx_curr;
     350                 :            :         }
     351                 :            : 
     352                 :            :         /* If match with the second context */
     353                 :          0 :         txq->ctx_curr ^= 1;
     354   [ #  #  #  # ]:          0 :         if (likely((txq->ctx_cache[txq->ctx_curr].flags == flags) &&
     355                 :            :                 (txq->ctx_cache[txq->ctx_curr].tx_offload.data ==
     356                 :            :                 (txq->ctx_cache[txq->ctx_curr].tx_offload_mask.data & tx_offload.data)))) {
     357                 :          0 :                         return txq->ctx_curr;
     358                 :            :         }
     359                 :            : 
     360                 :            :         /* Mismatch, use the previous context */
     361                 :            :         return IGB_CTX_NUM;
     362                 :            : }
     363                 :            : 
     364                 :            : static inline uint32_t
     365                 :            : tx_desc_cksum_flags_to_olinfo(uint64_t ol_flags)
     366                 :            : {
     367                 :            :         static const uint32_t l4_olinfo[2] = {0, E1000_ADVTXD_POPTS_TXSM};
     368                 :            :         static const uint32_t l3_olinfo[2] = {0, E1000_ADVTXD_POPTS_IXSM};
     369                 :            :         uint32_t tmp;
     370                 :            : 
     371                 :          0 :         tmp  = l4_olinfo[(ol_flags & RTE_MBUF_F_TX_L4_MASK)  != RTE_MBUF_F_TX_L4_NO_CKSUM];
     372                 :          0 :         tmp |= l3_olinfo[(ol_flags & RTE_MBUF_F_TX_IP_CKSUM) != 0];
     373                 :          0 :         tmp |= l4_olinfo[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
     374                 :            :         return tmp;
     375                 :            : }
     376                 :            : 
     377                 :            : static inline uint32_t
     378                 :            : tx_desc_vlan_flags_to_cmdtype(uint64_t ol_flags)
     379                 :            : {
     380                 :            :         uint32_t cmdtype;
     381                 :            :         static uint32_t vlan_cmd[2] = {0, E1000_ADVTXD_DCMD_VLE};
     382                 :            :         static uint32_t tso_cmd[2] = {0, E1000_ADVTXD_DCMD_TSE};
     383                 :          0 :         cmdtype = vlan_cmd[(ol_flags & RTE_MBUF_F_TX_VLAN) != 0];
     384                 :          0 :         cmdtype |= tso_cmd[(ol_flags & RTE_MBUF_F_TX_TCP_SEG) != 0];
     385                 :            :         return cmdtype;
     386                 :            : }
     387                 :            : 
     388                 :            : uint16_t
     389                 :          0 : eth_igb_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
     390                 :            :                uint16_t nb_pkts)
     391                 :            : {
     392                 :            :         struct igb_tx_queue *txq;
     393                 :            :         struct igb_tx_entry *sw_ring;
     394                 :            :         struct igb_tx_entry *txe, *txn;
     395                 :            :         volatile union e1000_adv_tx_desc *txr;
     396                 :            :         volatile union e1000_adv_tx_desc *txd;
     397                 :            :         struct rte_mbuf     *tx_pkt;
     398                 :            :         struct rte_mbuf     *m_seg;
     399                 :            :         uint64_t buf_dma_addr;
     400                 :            :         uint32_t olinfo_status;
     401                 :            :         uint32_t cmd_type_len;
     402                 :            :         uint32_t pkt_len;
     403                 :            :         uint16_t slen;
     404                 :            :         uint64_t ol_flags;
     405                 :            :         uint16_t tx_end;
     406                 :            :         uint16_t tx_id;
     407                 :            :         uint16_t tx_last;
     408                 :            :         uint16_t nb_tx;
     409                 :            :         uint64_t tx_ol_req;
     410                 :            :         uint32_t new_ctx = 0;
     411                 :            :         uint32_t ctx = 0;
     412                 :          0 :         union igb_tx_offload tx_offload = {0};
     413                 :            :         uint64_t ts;
     414                 :            : 
     415                 :            :         txq = tx_queue;
     416                 :          0 :         sw_ring = txq->sw_ring;
     417                 :          0 :         txr     = txq->tx_ring;
     418                 :          0 :         tx_id   = txq->tx_tail;
     419                 :          0 :         txe = &sw_ring[tx_id];
     420                 :            : 
     421         [ #  # ]:          0 :         for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
     422                 :          0 :                 tx_pkt = *tx_pkts++;
     423                 :          0 :                 pkt_len = tx_pkt->pkt_len;
     424                 :            : 
     425         [ #  # ]:          0 :                 RTE_MBUF_PREFETCH_TO_FREE(txe->mbuf);
     426                 :            : 
     427                 :            :                 /*
     428                 :            :                  * The number of descriptors that must be allocated for a
     429                 :            :                  * packet is the number of segments of that packet, plus 1
     430                 :            :                  * Context Descriptor for the VLAN Tag Identifier, if any.
     431                 :            :                  * Determine the last TX descriptor to allocate in the TX ring
     432                 :            :                  * for the packet, starting from the current position (tx_id)
     433                 :            :                  * in the ring.
     434                 :            :                  */
     435                 :          0 :                 tx_last = (uint16_t) (tx_id + tx_pkt->nb_segs - 1);
     436                 :            : 
     437                 :          0 :                 ol_flags = tx_pkt->ol_flags;
     438                 :          0 :                 tx_ol_req = ol_flags & IGB_TX_OFFLOAD_MASK;
     439                 :            : 
     440                 :            :                 /* If a Context Descriptor need be built . */
     441         [ #  # ]:          0 :                 if (tx_ol_req) {
     442                 :          0 :                         tx_offload.l2_len = tx_pkt->l2_len;
     443                 :          0 :                         tx_offload.l3_len = tx_pkt->l3_len;
     444                 :          0 :                         tx_offload.l4_len = tx_pkt->l4_len;
     445                 :          0 :                         tx_offload.vlan_tci = tx_pkt->vlan_tci;
     446         [ #  # ]:          0 :                         tx_offload.tso_segsz = tx_pkt->tso_segsz;
     447                 :            :                         tx_ol_req = check_tso_para(tx_ol_req, tx_offload);
     448                 :            : 
     449                 :          0 :                         ctx = what_advctx_update(txq, tx_ol_req, tx_offload);
     450                 :            :                         /* Only allocate context descriptor if required*/
     451                 :          0 :                         new_ctx = (ctx == IGB_CTX_NUM);
     452                 :          0 :                         ctx = txq->ctx_curr + txq->ctx_start;
     453                 :          0 :                         tx_last = (uint16_t) (tx_last + new_ctx);
     454                 :            :                 }
     455         [ #  # ]:          0 :                 if (tx_last >= txq->nb_tx_desc)
     456                 :          0 :                         tx_last = (uint16_t) (tx_last - txq->nb_tx_desc);
     457                 :            : 
     458                 :            :                 PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u pktlen=%u"
     459                 :            :                            " tx_first=%u tx_last=%u",
     460                 :            :                            (unsigned) txq->port_id,
     461                 :            :                            (unsigned) txq->queue_id,
     462                 :            :                            (unsigned) pkt_len,
     463                 :            :                            (unsigned) tx_id,
     464                 :            :                            (unsigned) tx_last);
     465                 :            : 
     466                 :            :                 /*
     467                 :            :                  * Check if there are enough free descriptors in the TX ring
     468                 :            :                  * to transmit the next packet.
     469                 :            :                  * This operation is based on the two following rules:
     470                 :            :                  *
     471                 :            :                  *   1- Only check that the last needed TX descriptor can be
     472                 :            :                  *      allocated (by construction, if that descriptor is free,
     473                 :            :                  *      all intermediate ones are also free).
     474                 :            :                  *
     475                 :            :                  *      For this purpose, the index of the last TX descriptor
     476                 :            :                  *      used for a packet (the "last descriptor" of a packet)
     477                 :            :                  *      is recorded in the TX entries (the last one included)
     478                 :            :                  *      that are associated with all TX descriptors allocated
     479                 :            :                  *      for that packet.
     480                 :            :                  *
     481                 :            :                  *   2- Avoid to allocate the last free TX descriptor of the
     482                 :            :                  *      ring, in order to never set the TDT register with the
     483                 :            :                  *      same value stored in parallel by the NIC in the TDH
     484                 :            :                  *      register, which makes the TX engine of the NIC enter
     485                 :            :                  *      in a deadlock situation.
     486                 :            :                  *
     487                 :            :                  *      By extension, avoid to allocate a free descriptor that
     488                 :            :                  *      belongs to the last set of free descriptors allocated
     489                 :            :                  *      to the same packet previously transmitted.
     490                 :            :                  */
     491                 :            : 
     492                 :            :                 /*
     493                 :            :                  * The "last descriptor" of the previously sent packet, if any,
     494                 :            :                  * which used the last descriptor to allocate.
     495                 :            :                  */
     496                 :          0 :                 tx_end = sw_ring[tx_last].last_id;
     497                 :            : 
     498                 :            :                 /*
     499                 :            :                  * The next descriptor following that "last descriptor" in the
     500                 :            :                  * ring.
     501                 :            :                  */
     502                 :          0 :                 tx_end = sw_ring[tx_end].next_id;
     503                 :            : 
     504                 :            :                 /*
     505                 :            :                  * The "last descriptor" associated with that next descriptor.
     506                 :            :                  */
     507                 :          0 :                 tx_end = sw_ring[tx_end].last_id;
     508                 :            : 
     509                 :            :                 /*
     510                 :            :                  * Check that this descriptor is free.
     511                 :            :                  */
     512         [ #  # ]:          0 :                 if (! (txr[tx_end].wb.status & E1000_TXD_STAT_DD)) {
     513         [ #  # ]:          0 :                         if (nb_tx == 0)
     514                 :            :                                 return 0;
     515                 :          0 :                         goto end_of_tx;
     516                 :            :                 }
     517                 :            : 
     518                 :            :                 /*
     519                 :            :                  * Set common flags of all TX Data Descriptors.
     520                 :            :                  *
     521                 :            :                  * The following bits must be set in all Data Descriptors:
     522                 :            :                  *   - E1000_ADVTXD_DTYP_DATA
     523                 :            :                  *   - E1000_ADVTXD_DCMD_DEXT
     524                 :            :                  *
     525                 :            :                  * The following bits must be set in the first Data Descriptor
     526                 :            :                  * and are ignored in the other ones:
     527                 :            :                  *   - E1000_ADVTXD_DCMD_IFCS
     528                 :            :                  *   - E1000_ADVTXD_MAC_1588
     529                 :            :                  *   - E1000_ADVTXD_DCMD_VLE
     530                 :            :                  *
     531                 :            :                  * The following bits must only be set in the last Data
     532                 :            :                  * Descriptor:
     533                 :            :                  *   - E1000_TXD_CMD_EOP
     534                 :            :                  *
     535                 :            :                  * The following bits can be set in any Data Descriptor, but
     536                 :            :                  * are only set in the last Data Descriptor:
     537                 :            :                  *   - E1000_TXD_CMD_RS
     538                 :            :                  */
     539                 :          0 :                 cmd_type_len = txq->txd_type |
     540                 :            :                         E1000_ADVTXD_DCMD_IFCS | E1000_ADVTXD_DCMD_DEXT;
     541         [ #  # ]:          0 :                 if (tx_ol_req & RTE_MBUF_F_TX_TCP_SEG)
     542                 :          0 :                         pkt_len -= (tx_pkt->l2_len + tx_pkt->l3_len + tx_pkt->l4_len);
     543                 :          0 :                 olinfo_status = (pkt_len << E1000_ADVTXD_PAYLEN_SHIFT);
     544                 :            : #if defined(RTE_LIBRTE_IEEE1588)
     545                 :            :                 if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
     546                 :            :                         cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
     547                 :            : #endif
     548         [ #  # ]:          0 :                 if (tx_ol_req) {
     549                 :            :                         /* Setup TX Advanced context descriptor if required */
     550         [ #  # ]:          0 :                         if (new_ctx) {
     551                 :            :                                 volatile struct e1000_adv_tx_context_desc *
     552                 :            :                                     ctx_txd;
     553                 :            : 
     554                 :          0 :                                 ctx_txd = (volatile struct
     555                 :            :                                     e1000_adv_tx_context_desc *)
     556                 :          0 :                                     &txr[tx_id];
     557                 :            : 
     558                 :          0 :                                 txn = &sw_ring[txe->next_id];
     559         [ #  # ]:          0 :                                 RTE_MBUF_PREFETCH_TO_FREE(txn->mbuf);
     560                 :            : 
     561         [ #  # ]:          0 :                                 if (txe->mbuf != NULL) {
     562                 :            :                                         rte_pktmbuf_free_seg(txe->mbuf);
     563                 :          0 :                                         txe->mbuf = NULL;
     564                 :            :                                 }
     565                 :            : 
     566         [ #  # ]:          0 :                                 if (igb_tx_timestamp_dynflag > 0) {
     567                 :          0 :                                         ts = *RTE_MBUF_DYNFIELD(tx_pkt,
     568                 :            :                                                 igb_tx_timestamp_dynfield_offset, uint64_t *);
     569                 :          0 :                                         igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, ts);
     570                 :            :                                 } else {
     571                 :          0 :                                         igbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req, tx_offload, 0);
     572                 :            :                                 }
     573                 :            : 
     574                 :          0 :                                 txe->last_id = tx_last;
     575                 :          0 :                                 tx_id = txe->next_id;
     576                 :            :                                 txe = txn;
     577                 :            :                         }
     578                 :            : 
     579                 :            :                         /* Setup the TX Advanced Data Descriptor */
     580                 :          0 :                         cmd_type_len  |= tx_desc_vlan_flags_to_cmdtype(tx_ol_req);
     581                 :          0 :                         olinfo_status |= tx_desc_cksum_flags_to_olinfo(tx_ol_req);
     582                 :          0 :                         olinfo_status |= (ctx << E1000_ADVTXD_IDX_SHIFT);
     583                 :            :                 }
     584                 :            : 
     585                 :            :                 m_seg = tx_pkt;
     586                 :            :                 do {
     587                 :          0 :                         txn = &sw_ring[txe->next_id];
     588                 :          0 :                         txd = &txr[tx_id];
     589                 :            : 
     590         [ #  # ]:          0 :                         if (txe->mbuf != NULL)
     591                 :            :                                 rte_pktmbuf_free_seg(txe->mbuf);
     592                 :          0 :                         txe->mbuf = m_seg;
     593                 :            : 
     594                 :            :                         /*
     595                 :            :                          * Set up transmit descriptor.
     596                 :            :                          */
     597         [ #  # ]:          0 :                         slen = (uint16_t) m_seg->data_len;
     598                 :            :                         buf_dma_addr = rte_mbuf_data_iova(m_seg);
     599                 :          0 :                         txd->read.buffer_addr =
     600                 :            :                                 rte_cpu_to_le_64(buf_dma_addr);
     601                 :          0 :                         txd->read.cmd_type_len =
     602                 :          0 :                                 rte_cpu_to_le_32(cmd_type_len | slen);
     603                 :          0 :                         txd->read.olinfo_status =
     604                 :            :                                 rte_cpu_to_le_32(olinfo_status);
     605                 :          0 :                         txe->last_id = tx_last;
     606                 :          0 :                         tx_id = txe->next_id;
     607                 :            :                         txe = txn;
     608                 :          0 :                         m_seg = m_seg->next;
     609         [ #  # ]:          0 :                 } while (m_seg != NULL);
     610                 :            : 
     611                 :            :                 /*
     612                 :            :                  * The last packet data descriptor needs End Of Packet (EOP)
     613                 :            :                  * and Report Status (RS).
     614                 :            :                  */
     615                 :          0 :                 txd->read.cmd_type_len |=
     616                 :            :                         rte_cpu_to_le_32(E1000_TXD_CMD_EOP | E1000_TXD_CMD_RS);
     617                 :            :         }
     618                 :          0 :  end_of_tx:
     619                 :            :         rte_wmb();
     620                 :            : 
     621                 :            :         /*
     622                 :            :          * Set the Transmit Descriptor Tail (TDT).
     623                 :            :          */
     624                 :          0 :         E1000_PCI_REG_WRITE_RELAXED(txq->tdt_reg_addr, tx_id);
     625                 :            :         PMD_TX_LOG(DEBUG, "port_id=%u queue_id=%u tx_tail=%u nb_tx=%u",
     626                 :            :                    (unsigned) txq->port_id, (unsigned) txq->queue_id,
     627                 :            :                    (unsigned) tx_id, (unsigned) nb_tx);
     628                 :          0 :         txq->tx_tail = tx_id;
     629                 :            : 
     630                 :          0 :         return nb_tx;
     631                 :            : }
     632                 :            : 
     633                 :            : /*********************************************************************
     634                 :            :  *
     635                 :            :  *  TX prep functions
     636                 :            :  *
     637                 :            :  **********************************************************************/
     638                 :            : uint16_t
     639                 :          0 : eth_igb_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
     640                 :            :                 uint16_t nb_pkts)
     641                 :            : {
     642                 :            :         int i, ret;
     643                 :            :         struct rte_mbuf *m;
     644                 :            : 
     645         [ #  # ]:          0 :         for (i = 0; i < nb_pkts; i++) {
     646                 :          0 :                 m = tx_pkts[i];
     647                 :            : 
     648                 :            :                 /* Check some limitations for TSO in hardware */
     649         [ #  # ]:          0 :                 if (m->ol_flags & RTE_MBUF_F_TX_TCP_SEG)
     650         [ #  # ]:          0 :                         if ((m->tso_segsz > IGB_TSO_MAX_MSS) ||
     651         [ #  # ]:          0 :                                         (m->l2_len + m->l3_len + m->l4_len >
     652                 :            :                                         IGB_TSO_MAX_HDRLEN)) {
     653                 :          0 :                                 rte_errno = EINVAL;
     654                 :          0 :                                 return i;
     655                 :            :                         }
     656                 :            : 
     657         [ #  # ]:          0 :                 if (m->ol_flags & IGB_TX_OFFLOAD_NOTSUP_MASK) {
     658                 :          0 :                         rte_errno = ENOTSUP;
     659                 :          0 :                         return i;
     660                 :            :                 }
     661                 :            : 
     662                 :            : #ifdef RTE_ETHDEV_DEBUG_TX
     663                 :            :                 ret = rte_validate_tx_offload(m);
     664                 :            :                 if (ret != 0) {
     665                 :            :                         rte_errno = -ret;
     666                 :            :                         return i;
     667                 :            :                 }
     668                 :            : #endif
     669                 :            :                 ret = rte_net_intel_cksum_prepare(m);
     670         [ #  # ]:          0 :                 if (ret != 0) {
     671                 :          0 :                         rte_errno = -ret;
     672                 :          0 :                         return i;
     673                 :            :                 }
     674                 :            :         }
     675                 :            : 
     676                 :          0 :         return i;
     677                 :            : }
     678                 :            : 
     679                 :            : /*********************************************************************
     680                 :            :  *
     681                 :            :  *  RX functions
     682                 :            :  *
     683                 :            :  **********************************************************************/
     684                 :            : #define IGB_PACKET_TYPE_IPV4              0X01
     685                 :            : #define IGB_PACKET_TYPE_IPV4_TCP          0X11
     686                 :            : #define IGB_PACKET_TYPE_IPV4_UDP          0X21
     687                 :            : #define IGB_PACKET_TYPE_IPV4_SCTP         0X41
     688                 :            : #define IGB_PACKET_TYPE_IPV4_EXT          0X03
     689                 :            : #define IGB_PACKET_TYPE_IPV4_EXT_SCTP     0X43
     690                 :            : #define IGB_PACKET_TYPE_IPV6              0X04
     691                 :            : #define IGB_PACKET_TYPE_IPV6_TCP          0X14
     692                 :            : #define IGB_PACKET_TYPE_IPV6_UDP          0X24
     693                 :            : #define IGB_PACKET_TYPE_IPV6_EXT          0X0C
     694                 :            : #define IGB_PACKET_TYPE_IPV6_EXT_TCP      0X1C
     695                 :            : #define IGB_PACKET_TYPE_IPV6_EXT_UDP      0X2C
     696                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6         0X05
     697                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6_TCP     0X15
     698                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6_UDP     0X25
     699                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT     0X0D
     700                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP 0X1D
     701                 :            : #define IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP 0X2D
     702                 :            : #define IGB_PACKET_TYPE_MAX               0X80
     703                 :            : #define IGB_PACKET_TYPE_MASK              0X7F
     704                 :            : #define IGB_PACKET_TYPE_SHIFT             0X04
     705                 :            : static inline uint32_t
     706                 :            : igb_rxd_pkt_info_to_pkt_type(uint16_t pkt_info)
     707                 :            : {
     708                 :            :         static const alignas(RTE_CACHE_LINE_SIZE) uint32_t
     709                 :            :                 ptype_table[IGB_PACKET_TYPE_MAX] = {
     710                 :            :                 [IGB_PACKET_TYPE_IPV4] = RTE_PTYPE_L2_ETHER |
     711                 :            :                         RTE_PTYPE_L3_IPV4,
     712                 :            :                 [IGB_PACKET_TYPE_IPV4_EXT] = RTE_PTYPE_L2_ETHER |
     713                 :            :                         RTE_PTYPE_L3_IPV4_EXT,
     714                 :            :                 [IGB_PACKET_TYPE_IPV6] = RTE_PTYPE_L2_ETHER |
     715                 :            :                         RTE_PTYPE_L3_IPV6,
     716                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6] = RTE_PTYPE_L2_ETHER |
     717                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     718                 :            :                         RTE_PTYPE_INNER_L3_IPV6,
     719                 :            :                 [IGB_PACKET_TYPE_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
     720                 :            :                         RTE_PTYPE_L3_IPV6_EXT,
     721                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6_EXT] = RTE_PTYPE_L2_ETHER |
     722                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     723                 :            :                         RTE_PTYPE_INNER_L3_IPV6_EXT,
     724                 :            :                 [IGB_PACKET_TYPE_IPV4_TCP] = RTE_PTYPE_L2_ETHER |
     725                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP,
     726                 :            :                 [IGB_PACKET_TYPE_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
     727                 :            :                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_TCP,
     728                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6_TCP] = RTE_PTYPE_L2_ETHER |
     729                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     730                 :            :                         RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_TCP,
     731                 :            :                 [IGB_PACKET_TYPE_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
     732                 :            :                         RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_TCP,
     733                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6_EXT_TCP] = RTE_PTYPE_L2_ETHER |
     734                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     735                 :            :                         RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_TCP,
     736                 :            :                 [IGB_PACKET_TYPE_IPV4_UDP] = RTE_PTYPE_L2_ETHER |
     737                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP,
     738                 :            :                 [IGB_PACKET_TYPE_IPV6_UDP] = RTE_PTYPE_L2_ETHER |
     739                 :            :                         RTE_PTYPE_L3_IPV6 | RTE_PTYPE_L4_UDP,
     740                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6_UDP] =  RTE_PTYPE_L2_ETHER |
     741                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     742                 :            :                         RTE_PTYPE_INNER_L3_IPV6 | RTE_PTYPE_INNER_L4_UDP,
     743                 :            :                 [IGB_PACKET_TYPE_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
     744                 :            :                         RTE_PTYPE_L3_IPV6_EXT | RTE_PTYPE_L4_UDP,
     745                 :            :                 [IGB_PACKET_TYPE_IPV4_IPV6_EXT_UDP] = RTE_PTYPE_L2_ETHER |
     746                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_TUNNEL_IP |
     747                 :            :                         RTE_PTYPE_INNER_L3_IPV6_EXT | RTE_PTYPE_INNER_L4_UDP,
     748                 :            :                 [IGB_PACKET_TYPE_IPV4_SCTP] = RTE_PTYPE_L2_ETHER |
     749                 :            :                         RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_SCTP,
     750                 :            :                 [IGB_PACKET_TYPE_IPV4_EXT_SCTP] = RTE_PTYPE_L2_ETHER |
     751                 :            :                         RTE_PTYPE_L3_IPV4_EXT | RTE_PTYPE_L4_SCTP,
     752                 :            :         };
     753                 :          0 :         if (unlikely(pkt_info & E1000_RXDADV_PKTTYPE_ETQF))
     754                 :            :                 return RTE_PTYPE_UNKNOWN;
     755                 :            : 
     756                 :          0 :         pkt_info = (pkt_info >> IGB_PACKET_TYPE_SHIFT) & IGB_PACKET_TYPE_MASK;
     757                 :            : 
     758                 :          0 :         return ptype_table[pkt_info];
     759                 :            : }
     760                 :            : 
     761                 :            : static inline uint64_t
     762                 :            : rx_desc_hlen_type_rss_to_pkt_flags(struct igb_rx_queue *rxq, uint32_t hl_tp_rs)
     763                 :            : {
     764         [ #  # ]:          0 :         uint64_t pkt_flags = ((hl_tp_rs & 0x0F) == 0) ?  0 : RTE_MBUF_F_RX_RSS_HASH;
     765                 :            : 
     766                 :            : #if defined(RTE_LIBRTE_IEEE1588)
     767                 :            :         static uint32_t ip_pkt_etqf_map[8] = {
     768                 :            :                 0, 0, 0, RTE_MBUF_F_RX_IEEE1588_PTP,
     769                 :            :                 0, 0, 0, 0,
     770                 :            :         };
     771                 :            : 
     772                 :            :         struct rte_eth_dev dev = rte_eth_devices[rxq->port_id];
     773                 :            :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev.data->dev_private);
     774                 :            : 
     775                 :            :         /* EtherType is in bits 8:10 in Packet Type, and not in the default 0:2 */
     776                 :            :         if (hw->mac.type == e1000_i210)
     777                 :            :                 pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 12) & 0x07];
     778                 :            :         else
     779                 :            :                 pkt_flags |= ip_pkt_etqf_map[(hl_tp_rs >> 4) & 0x07];
     780                 :            : #else
     781                 :            :         RTE_SET_USED(rxq);
     782                 :            : #endif
     783                 :            : 
     784                 :            :         return pkt_flags;
     785                 :            : }
     786                 :            : 
     787                 :            : static inline uint64_t
     788                 :            : rx_desc_status_to_pkt_flags(uint32_t rx_status)
     789                 :            : {
     790                 :            :         uint64_t pkt_flags;
     791                 :            : 
     792                 :            :         /* Check if VLAN present */
     793                 :          0 :         pkt_flags = ((rx_status & E1000_RXD_STAT_VP) ?
     794   [ #  #  #  # ]:          0 :                 RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED : 0);
     795                 :            : 
     796                 :            : #if defined(RTE_LIBRTE_IEEE1588)
     797                 :            :         if (rx_status & E1000_RXD_STAT_TMST)
     798                 :            :                 pkt_flags = pkt_flags | RTE_MBUF_F_RX_IEEE1588_TMST;
     799                 :            : #endif
     800                 :            :         return pkt_flags;
     801                 :            : }
     802                 :            : 
     803                 :            : static inline uint64_t
     804                 :            : rx_desc_error_to_pkt_flags(uint32_t rx_status)
     805                 :            : {
     806                 :            :         /*
     807                 :            :          * Bit 30: IPE, IPv4 checksum error
     808                 :            :          * Bit 29: L4I, L4I integrity error
     809                 :            :          */
     810                 :            : 
     811                 :            :         static uint64_t error_to_pkt_flags_map[4] = {
     812                 :            :                 RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
     813                 :            :                 RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_BAD,
     814                 :            :                 RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_GOOD,
     815                 :            :                 RTE_MBUF_F_RX_IP_CKSUM_BAD | RTE_MBUF_F_RX_L4_CKSUM_BAD
     816                 :            :         };
     817                 :          0 :         return error_to_pkt_flags_map[(rx_status >>
     818                 :          0 :                 E1000_RXD_ERR_CKSUM_BIT) & E1000_RXD_ERR_CKSUM_MSK];
     819                 :            : }
     820                 :            : 
     821                 :            : uint16_t
     822                 :          0 : eth_igb_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
     823                 :            :                uint16_t nb_pkts)
     824                 :            : {
     825                 :            :         struct igb_rx_queue *rxq;
     826                 :            :         volatile union e1000_adv_rx_desc *rx_ring;
     827                 :            :         volatile union e1000_adv_rx_desc *rxdp;
     828                 :            :         struct igb_rx_entry *sw_ring;
     829                 :            :         struct igb_rx_entry *rxe;
     830                 :            :         struct rte_mbuf *rxm;
     831                 :            :         struct rte_mbuf *nmb;
     832                 :            :         union e1000_adv_rx_desc rxd;
     833                 :            :         uint64_t dma_addr;
     834                 :            :         uint32_t staterr;
     835                 :            :         uint32_t hlen_type_rss;
     836                 :            :         uint16_t pkt_len;
     837                 :            :         uint16_t rx_id;
     838                 :            :         uint16_t nb_rx;
     839                 :            :         uint16_t nb_hold;
     840                 :            :         uint64_t pkt_flags;
     841                 :            : 
     842                 :            :         nb_rx = 0;
     843                 :            :         nb_hold = 0;
     844                 :            :         rxq = rx_queue;
     845                 :          0 :         rx_id = rxq->rx_tail;
     846                 :          0 :         rx_ring = rxq->rx_ring;
     847                 :          0 :         sw_ring = rxq->sw_ring;
     848         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
     849                 :            :                 /*
     850                 :            :                  * The order of operations here is important as the DD status
     851                 :            :                  * bit must not be read after any other descriptor fields.
     852                 :            :                  * rx_ring and rxdp are pointing to volatile data so the order
     853                 :            :                  * of accesses cannot be reordered by the compiler. If they were
     854                 :            :                  * not volatile, they could be reordered which could lead to
     855                 :            :                  * using invalid descriptor fields when read from rxd.
     856                 :            :                  */
     857                 :          0 :                 rxdp = &rx_ring[rx_id];
     858                 :          0 :                 staterr = rxdp->wb.upper.status_error;
     859         [ #  # ]:          0 :                 if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
     860                 :            :                         break;
     861                 :          0 :                 rxd = *rxdp;
     862                 :            : 
     863                 :            :                 /*
     864                 :            :                  * End of packet.
     865                 :            :                  *
     866                 :            :                  * If the E1000_RXD_STAT_EOP flag is not set, the RX packet is
     867                 :            :                  * likely to be invalid and to be dropped by the various
     868                 :            :                  * validation checks performed by the network stack.
     869                 :            :                  *
     870                 :            :                  * Allocate a new mbuf to replenish the RX ring descriptor.
     871                 :            :                  * If the allocation fails:
     872                 :            :                  *    - arrange for that RX descriptor to be the first one
     873                 :            :                  *      being parsed the next time the receive function is
     874                 :            :                  *      invoked [on the same queue].
     875                 :            :                  *
     876                 :            :                  *    - Stop parsing the RX ring and return immediately.
     877                 :            :                  *
     878                 :            :                  * This policy do not drop the packet received in the RX
     879                 :            :                  * descriptor for which the allocation of a new mbuf failed.
     880                 :            :                  * Thus, it allows that packet to be later retrieved if
     881                 :            :                  * mbuf have been freed in the mean time.
     882                 :            :                  * As a side effect, holding RX descriptors instead of
     883                 :            :                  * systematically giving them back to the NIC may lead to
     884                 :            :                  * RX ring exhaustion situations.
     885                 :            :                  * However, the NIC can gracefully prevent such situations
     886                 :            :                  * to happen by sending specific "back-pressure" flow control
     887                 :            :                  * frames to its peer(s).
     888                 :            :                  */
     889                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
     890                 :            :                            "staterr=0x%x pkt_len=%u",
     891                 :            :                            (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
     892                 :            :                            (unsigned) rx_id, (unsigned) staterr,
     893                 :            :                            (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
     894                 :            : 
     895                 :          0 :                 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
     896         [ #  # ]:          0 :                 if (nmb == NULL) {
     897                 :            :                         PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
     898                 :            :                                    "queue_id=%u", (unsigned) rxq->port_id,
     899                 :            :                                    (unsigned) rxq->queue_id);
     900                 :          0 :                         rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
     901                 :          0 :                         break;
     902                 :            :                 }
     903                 :            : 
     904                 :          0 :                 nb_hold++;
     905                 :          0 :                 rxe = &sw_ring[rx_id];
     906                 :          0 :                 rx_id++;
     907         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc)
     908                 :            :                         rx_id = 0;
     909                 :            : 
     910                 :            :                 /* Prefetch next mbuf while processing current one. */
     911                 :          0 :                 rte_igb_prefetch(sw_ring[rx_id].mbuf);
     912                 :            : 
     913                 :            :                 /*
     914                 :            :                  * When next RX descriptor is on a cache-line boundary,
     915                 :            :                  * prefetch the next 4 RX descriptors and the next 8 pointers
     916                 :            :                  * to mbufs.
     917                 :            :                  */
     918         [ #  # ]:          0 :                 if ((rx_id & 0x3) == 0) {
     919                 :          0 :                         rte_igb_prefetch(&rx_ring[rx_id]);
     920                 :            :                         rte_igb_prefetch(&sw_ring[rx_id]);
     921                 :            :                 }
     922                 :            : 
     923                 :          0 :                 rxm = rxe->mbuf;
     924                 :          0 :                 rxe->mbuf = nmb;
     925                 :            :                 dma_addr =
     926                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
     927                 :          0 :                 rxdp->read.hdr_addr = 0;
     928                 :          0 :                 rxdp->read.pkt_addr = dma_addr;
     929                 :            : 
     930                 :            :                 /*
     931                 :            :                  * Initialize the returned mbuf.
     932                 :            :                  * 1) setup generic mbuf fields:
     933                 :            :                  *    - number of segments,
     934                 :            :                  *    - next segment,
     935                 :            :                  *    - packet length,
     936                 :            :                  *    - RX port identifier.
     937                 :            :                  * 2) integrate hardware offload data, if any:
     938                 :            :                  *    - RSS flag & hash,
     939                 :            :                  *    - IP checksum flag,
     940                 :            :                  *    - VLAN TCI, if any,
     941                 :            :                  *    - error flags.
     942                 :            :                  */
     943                 :          0 :                 pkt_len = (uint16_t) (rte_le_to_cpu_16(rxd.wb.upper.length) -
     944                 :          0 :                                       rxq->crc_len);
     945                 :          0 :                 rxm->data_off = RTE_PKTMBUF_HEADROOM;
     946                 :          0 :                 rte_packet_prefetch((char *)rxm->buf_addr + rxm->data_off);
     947                 :          0 :                 rxm->nb_segs = 1;
     948                 :          0 :                 rxm->next = NULL;
     949                 :          0 :                 rxm->pkt_len = pkt_len;
     950                 :          0 :                 rxm->data_len = pkt_len;
     951                 :          0 :                 rxm->port = rxq->port_id;
     952                 :            : 
     953                 :          0 :                 rxm->hash.rss = rxd.wb.lower.hi_dword.rss;
     954                 :          0 :                 hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
     955                 :            : 
     956                 :            :                 /*
     957                 :            :                  * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
     958                 :            :                  * set in the pkt_flags field and must be in CPU byte order.
     959                 :            :                  */
     960         [ #  # ]:          0 :                 if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
     961         [ #  # ]:          0 :                                 (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
     962         [ #  # ]:          0 :                         rxm->vlan_tci = rte_be_to_cpu_16(rxd.wb.upper.vlan);
     963                 :            :                 } else {
     964                 :          0 :                         rxm->vlan_tci = rte_le_to_cpu_16(rxd.wb.upper.vlan);
     965                 :            :                 }
     966                 :            :                 pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
     967                 :          0 :                 pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
     968                 :          0 :                 pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
     969                 :          0 :                 rxm->ol_flags = pkt_flags;
     970                 :          0 :                 rxm->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.lower.
     971         [ #  # ]:          0 :                                                 lo_dword.hs_rss.pkt_info);
     972                 :            : 
     973                 :            :                 /*
     974                 :            :                  * Store the mbuf address into the next entry of the array
     975                 :            :                  * of returned packets.
     976                 :            :                  */
     977                 :          0 :                 rx_pkts[nb_rx++] = rxm;
     978                 :            :         }
     979                 :          0 :         rxq->rx_tail = rx_id;
     980                 :            : 
     981                 :            :         /*
     982                 :            :          * If the number of free RX descriptors is greater than the RX free
     983                 :            :          * threshold of the queue, advance the Receive Descriptor Tail (RDT)
     984                 :            :          * register.
     985                 :            :          * Update the RDT with the value of the last processed RX descriptor
     986                 :            :          * minus 1, to guarantee that the RDT register is never equal to the
     987                 :            :          * RDH register, which creates a "full" ring situation from the
     988                 :            :          * hardware point of view...
     989                 :            :          */
     990                 :          0 :         nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
     991         [ #  # ]:          0 :         if (nb_hold > rxq->rx_free_thresh) {
     992                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
     993                 :            :                            "nb_hold=%u nb_rx=%u",
     994                 :            :                            (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
     995                 :            :                            (unsigned) rx_id, (unsigned) nb_hold,
     996                 :            :                            (unsigned) nb_rx);
     997         [ #  # ]:          0 :                 rx_id = (uint16_t) ((rx_id == 0) ?
     998                 :          0 :                                      (rxq->nb_rx_desc - 1) : (rx_id - 1));
     999                 :          0 :                 E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
    1000                 :            :                 nb_hold = 0;
    1001                 :            :         }
    1002                 :          0 :         rxq->nb_rx_hold = nb_hold;
    1003                 :          0 :         return nb_rx;
    1004                 :            : }
    1005                 :            : 
    1006                 :            : uint16_t
    1007                 :          0 : eth_igb_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
    1008                 :            :                          uint16_t nb_pkts)
    1009                 :            : {
    1010                 :            :         struct igb_rx_queue *rxq;
    1011                 :            :         volatile union e1000_adv_rx_desc *rx_ring;
    1012                 :            :         volatile union e1000_adv_rx_desc *rxdp;
    1013                 :            :         struct igb_rx_entry *sw_ring;
    1014                 :            :         struct igb_rx_entry *rxe;
    1015                 :            :         struct rte_mbuf *first_seg;
    1016                 :            :         struct rte_mbuf *last_seg;
    1017                 :            :         struct rte_mbuf *rxm;
    1018                 :            :         struct rte_mbuf *nmb;
    1019                 :            :         union e1000_adv_rx_desc rxd;
    1020                 :            :         uint64_t dma; /* Physical address of mbuf data buffer */
    1021                 :            :         uint32_t staterr;
    1022                 :            :         uint32_t hlen_type_rss;
    1023                 :            :         uint16_t rx_id;
    1024                 :            :         uint16_t nb_rx;
    1025                 :            :         uint16_t nb_hold;
    1026                 :            :         uint16_t data_len;
    1027                 :            :         uint64_t pkt_flags;
    1028                 :            : 
    1029                 :            :         nb_rx = 0;
    1030                 :            :         nb_hold = 0;
    1031                 :            :         rxq = rx_queue;
    1032                 :          0 :         rx_id = rxq->rx_tail;
    1033                 :          0 :         rx_ring = rxq->rx_ring;
    1034                 :          0 :         sw_ring = rxq->sw_ring;
    1035                 :            : 
    1036                 :            :         /*
    1037                 :            :          * Retrieve RX context of current packet, if any.
    1038                 :            :          */
    1039                 :          0 :         first_seg = rxq->pkt_first_seg;
    1040                 :          0 :         last_seg = rxq->pkt_last_seg;
    1041                 :            : 
    1042         [ #  # ]:          0 :         while (nb_rx < nb_pkts) {
    1043                 :          0 :         next_desc:
    1044                 :            :                 /*
    1045                 :            :                  * The order of operations here is important as the DD status
    1046                 :            :                  * bit must not be read after any other descriptor fields.
    1047                 :            :                  * rx_ring and rxdp are pointing to volatile data so the order
    1048                 :            :                  * of accesses cannot be reordered by the compiler. If they were
    1049                 :            :                  * not volatile, they could be reordered which could lead to
    1050                 :            :                  * using invalid descriptor fields when read from rxd.
    1051                 :            :                  */
    1052                 :          0 :                 rxdp = &rx_ring[rx_id];
    1053                 :          0 :                 staterr = rxdp->wb.upper.status_error;
    1054         [ #  # ]:          0 :                 if (! (staterr & rte_cpu_to_le_32(E1000_RXD_STAT_DD)))
    1055                 :            :                         break;
    1056                 :          0 :                 rxd = *rxdp;
    1057                 :            : 
    1058                 :            :                 /*
    1059                 :            :                  * Descriptor done.
    1060                 :            :                  *
    1061                 :            :                  * Allocate a new mbuf to replenish the RX ring descriptor.
    1062                 :            :                  * If the allocation fails:
    1063                 :            :                  *    - arrange for that RX descriptor to be the first one
    1064                 :            :                  *      being parsed the next time the receive function is
    1065                 :            :                  *      invoked [on the same queue].
    1066                 :            :                  *
    1067                 :            :                  *    - Stop parsing the RX ring and return immediately.
    1068                 :            :                  *
    1069                 :            :                  * This policy does not drop the packet received in the RX
    1070                 :            :                  * descriptor for which the allocation of a new mbuf failed.
    1071                 :            :                  * Thus, it allows that packet to be later retrieved if
    1072                 :            :                  * mbuf have been freed in the mean time.
    1073                 :            :                  * As a side effect, holding RX descriptors instead of
    1074                 :            :                  * systematically giving them back to the NIC may lead to
    1075                 :            :                  * RX ring exhaustion situations.
    1076                 :            :                  * However, the NIC can gracefully prevent such situations
    1077                 :            :                  * to happen by sending specific "back-pressure" flow control
    1078                 :            :                  * frames to its peer(s).
    1079                 :            :                  */
    1080                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u "
    1081                 :            :                            "staterr=0x%x data_len=%u",
    1082                 :            :                            (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
    1083                 :            :                            (unsigned) rx_id, (unsigned) staterr,
    1084                 :            :                            (unsigned) rte_le_to_cpu_16(rxd.wb.upper.length));
    1085                 :            : 
    1086                 :          0 :                 nmb = rte_mbuf_raw_alloc(rxq->mb_pool);
    1087         [ #  # ]:          0 :                 if (nmb == NULL) {
    1088                 :            :                         PMD_RX_LOG(DEBUG, "RX mbuf alloc failed port_id=%u "
    1089                 :            :                                    "queue_id=%u", (unsigned) rxq->port_id,
    1090                 :            :                                    (unsigned) rxq->queue_id);
    1091                 :          0 :                         rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
    1092                 :          0 :                         break;
    1093                 :            :                 }
    1094                 :            : 
    1095                 :          0 :                 nb_hold++;
    1096                 :          0 :                 rxe = &sw_ring[rx_id];
    1097                 :          0 :                 rx_id++;
    1098         [ #  # ]:          0 :                 if (rx_id == rxq->nb_rx_desc)
    1099                 :            :                         rx_id = 0;
    1100                 :            : 
    1101                 :            :                 /* Prefetch next mbuf while processing current one. */
    1102                 :          0 :                 rte_igb_prefetch(sw_ring[rx_id].mbuf);
    1103                 :            : 
    1104                 :            :                 /*
    1105                 :            :                  * When next RX descriptor is on a cache-line boundary,
    1106                 :            :                  * prefetch the next 4 RX descriptors and the next 8 pointers
    1107                 :            :                  * to mbufs.
    1108                 :            :                  */
    1109         [ #  # ]:          0 :                 if ((rx_id & 0x3) == 0) {
    1110                 :          0 :                         rte_igb_prefetch(&rx_ring[rx_id]);
    1111                 :            :                         rte_igb_prefetch(&sw_ring[rx_id]);
    1112                 :            :                 }
    1113                 :            : 
    1114                 :            :                 /*
    1115                 :            :                  * Update RX descriptor with the physical address of the new
    1116                 :            :                  * data buffer of the new allocated mbuf.
    1117                 :            :                  */
    1118                 :          0 :                 rxm = rxe->mbuf;
    1119         [ #  # ]:          0 :                 rxe->mbuf = nmb;
    1120                 :            :                 dma = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
    1121                 :          0 :                 rxdp->read.pkt_addr = dma;
    1122                 :          0 :                 rxdp->read.hdr_addr = 0;
    1123                 :            : 
    1124                 :            :                 /*
    1125                 :            :                  * Set data length & data buffer address of mbuf.
    1126                 :            :                  */
    1127                 :            :                 data_len = rte_le_to_cpu_16(rxd.wb.upper.length);
    1128                 :          0 :                 rxm->data_len = data_len;
    1129                 :          0 :                 rxm->data_off = RTE_PKTMBUF_HEADROOM;
    1130                 :            : 
    1131                 :            :                 /*
    1132                 :            :                  * If this is the first buffer of the received packet,
    1133                 :            :                  * set the pointer to the first mbuf of the packet and
    1134                 :            :                  * initialize its context.
    1135                 :            :                  * Otherwise, update the total length and the number of segments
    1136                 :            :                  * of the current scattered packet, and update the pointer to
    1137                 :            :                  * the last mbuf of the current packet.
    1138                 :            :                  */
    1139         [ #  # ]:          0 :                 if (first_seg == NULL) {
    1140                 :            :                         first_seg = rxm;
    1141                 :          0 :                         first_seg->pkt_len = data_len;
    1142                 :          0 :                         first_seg->nb_segs = 1;
    1143                 :            :                 } else {
    1144                 :          0 :                         first_seg->pkt_len += data_len;
    1145                 :          0 :                         first_seg->nb_segs++;
    1146                 :          0 :                         last_seg->next = rxm;
    1147                 :            :                 }
    1148                 :            : 
    1149                 :            :                 /*
    1150                 :            :                  * If this is not the last buffer of the received packet,
    1151                 :            :                  * update the pointer to the last mbuf of the current scattered
    1152                 :            :                  * packet and continue to parse the RX ring.
    1153                 :            :                  */
    1154         [ #  # ]:          0 :                 if (! (staterr & E1000_RXD_STAT_EOP)) {
    1155                 :            :                         last_seg = rxm;
    1156                 :          0 :                         goto next_desc;
    1157                 :            :                 }
    1158                 :            : 
    1159                 :            :                 /*
    1160                 :            :                  * This is the last buffer of the received packet.
    1161                 :            :                  * If the CRC is not stripped by the hardware:
    1162                 :            :                  *   - Subtract the CRC length from the total packet length.
    1163                 :            :                  *   - If the last buffer only contains the whole CRC or a part
    1164                 :            :                  *     of it, free the mbuf associated to the last buffer.
    1165                 :            :                  *     If part of the CRC is also contained in the previous
    1166                 :            :                  *     mbuf, subtract the length of that CRC part from the
    1167                 :            :                  *     data length of the previous mbuf.
    1168                 :            :                  */
    1169                 :          0 :                 rxm->next = NULL;
    1170         [ #  # ]:          0 :                 if (unlikely(rxq->crc_len > 0)) {
    1171                 :          0 :                         first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
    1172         [ #  # ]:          0 :                         if (data_len <= RTE_ETHER_CRC_LEN) {
    1173                 :            :                                 rte_pktmbuf_free_seg(rxm);
    1174                 :          0 :                                 first_seg->nb_segs--;
    1175                 :          0 :                                 last_seg->data_len = (uint16_t)
    1176                 :          0 :                                         (last_seg->data_len -
    1177                 :            :                                          (RTE_ETHER_CRC_LEN - data_len));
    1178                 :          0 :                                 last_seg->next = NULL;
    1179                 :            :                         } else
    1180                 :          0 :                                 rxm->data_len = (uint16_t)
    1181                 :            :                                         (data_len - RTE_ETHER_CRC_LEN);
    1182                 :            :                 }
    1183                 :            : 
    1184                 :            :                 /*
    1185                 :            :                  * Initialize the first mbuf of the returned packet:
    1186                 :            :                  *    - RX port identifier,
    1187                 :            :                  *    - hardware offload data, if any:
    1188                 :            :                  *      - RSS flag & hash,
    1189                 :            :                  *      - IP checksum flag,
    1190                 :            :                  *      - VLAN TCI, if any,
    1191                 :            :                  *      - error flags.
    1192                 :            :                  */
    1193                 :          0 :                 first_seg->port = rxq->port_id;
    1194                 :          0 :                 first_seg->hash.rss = rxd.wb.lower.hi_dword.rss;
    1195                 :            : 
    1196                 :            :                 /*
    1197                 :            :                  * The vlan_tci field is only valid when RTE_MBUF_F_RX_VLAN is
    1198                 :            :                  * set in the pkt_flags field and must be in CPU byte order.
    1199                 :            :                  */
    1200         [ #  # ]:          0 :                 if ((staterr & rte_cpu_to_le_32(E1000_RXDEXT_STATERR_LB)) &&
    1201         [ #  # ]:          0 :                                 (rxq->flags & IGB_RXQ_FLAG_LB_BSWAP_VLAN)) {
    1202                 :          0 :                         first_seg->vlan_tci =
    1203         [ #  # ]:          0 :                                 rte_be_to_cpu_16(rxd.wb.upper.vlan);
    1204                 :            :                 } else {
    1205                 :          0 :                         first_seg->vlan_tci =
    1206                 :            :                                 rte_le_to_cpu_16(rxd.wb.upper.vlan);
    1207                 :            :                 }
    1208         [ #  # ]:          0 :                 hlen_type_rss = rte_le_to_cpu_32(rxd.wb.lower.lo_dword.data);
    1209                 :            :                 pkt_flags = rx_desc_hlen_type_rss_to_pkt_flags(rxq, hlen_type_rss);
    1210                 :          0 :                 pkt_flags = pkt_flags | rx_desc_status_to_pkt_flags(staterr);
    1211                 :          0 :                 pkt_flags = pkt_flags | rx_desc_error_to_pkt_flags(staterr);
    1212                 :          0 :                 first_seg->ol_flags = pkt_flags;
    1213                 :          0 :                 first_seg->packet_type = igb_rxd_pkt_info_to_pkt_type(rxd.wb.
    1214         [ #  # ]:          0 :                                         lower.lo_dword.hs_rss.pkt_info);
    1215                 :            : 
    1216                 :            :                 /* Prefetch data of first segment, if configured to do so. */
    1217                 :          0 :                 rte_packet_prefetch((char *)first_seg->buf_addr +
    1218                 :            :                         first_seg->data_off);
    1219                 :            : 
    1220                 :            :                 /*
    1221                 :            :                  * Store the mbuf address into the next entry of the array
    1222                 :            :                  * of returned packets.
    1223                 :            :                  */
    1224                 :          0 :                 rx_pkts[nb_rx++] = first_seg;
    1225                 :            : 
    1226                 :            :                 /*
    1227                 :            :                  * Setup receipt context for a new packet.
    1228                 :            :                  */
    1229                 :            :                 first_seg = NULL;
    1230                 :            :         }
    1231                 :            : 
    1232                 :            :         /*
    1233                 :            :          * Record index of the next RX descriptor to probe.
    1234                 :            :          */
    1235                 :          0 :         rxq->rx_tail = rx_id;
    1236                 :            : 
    1237                 :            :         /*
    1238                 :            :          * Save receive context.
    1239                 :            :          */
    1240                 :          0 :         rxq->pkt_first_seg = first_seg;
    1241                 :          0 :         rxq->pkt_last_seg = last_seg;
    1242                 :            : 
    1243                 :            :         /*
    1244                 :            :          * If the number of free RX descriptors is greater than the RX free
    1245                 :            :          * threshold of the queue, advance the Receive Descriptor Tail (RDT)
    1246                 :            :          * register.
    1247                 :            :          * Update the RDT with the value of the last processed RX descriptor
    1248                 :            :          * minus 1, to guarantee that the RDT register is never equal to the
    1249                 :            :          * RDH register, which creates a "full" ring situation from the
    1250                 :            :          * hardware point of view...
    1251                 :            :          */
    1252                 :          0 :         nb_hold = (uint16_t) (nb_hold + rxq->nb_rx_hold);
    1253         [ #  # ]:          0 :         if (nb_hold > rxq->rx_free_thresh) {
    1254                 :            :                 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
    1255                 :            :                            "nb_hold=%u nb_rx=%u",
    1256                 :            :                            (unsigned) rxq->port_id, (unsigned) rxq->queue_id,
    1257                 :            :                            (unsigned) rx_id, (unsigned) nb_hold,
    1258                 :            :                            (unsigned) nb_rx);
    1259         [ #  # ]:          0 :                 rx_id = (uint16_t) ((rx_id == 0) ?
    1260                 :          0 :                                      (rxq->nb_rx_desc - 1) : (rx_id - 1));
    1261                 :          0 :                 E1000_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
    1262                 :            :                 nb_hold = 0;
    1263                 :            :         }
    1264                 :          0 :         rxq->nb_rx_hold = nb_hold;
    1265                 :          0 :         return nb_rx;
    1266                 :            : }
    1267                 :            : 
    1268                 :            : /*
    1269                 :            :  * Maximum number of Ring Descriptors.
    1270                 :            :  *
    1271                 :            :  * Since RDLEN/TDLEN should be multiple of 128bytes, the number of ring
    1272                 :            :  * descriptors should meet the following condition:
    1273                 :            :  *      (num_ring_desc * sizeof(struct e1000_rx/tx_desc)) % 128 == 0
    1274                 :            :  */
    1275                 :            : 
    1276                 :            : static void
    1277                 :          0 : igb_tx_queue_release_mbufs(struct igb_tx_queue *txq)
    1278                 :            : {
    1279                 :            :         unsigned i;
    1280                 :            : 
    1281         [ #  # ]:          0 :         if (txq->sw_ring != NULL) {
    1282         [ #  # ]:          0 :                 for (i = 0; i < txq->nb_tx_desc; i++) {
    1283         [ #  # ]:          0 :                         if (txq->sw_ring[i].mbuf != NULL) {
    1284                 :            :                                 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
    1285                 :          0 :                                 txq->sw_ring[i].mbuf = NULL;
    1286                 :            :                         }
    1287                 :            :                 }
    1288                 :            :         }
    1289                 :          0 : }
    1290                 :            : 
    1291                 :            : static void
    1292                 :          0 : igb_tx_queue_release(struct igb_tx_queue *txq)
    1293                 :            : {
    1294         [ #  # ]:          0 :         if (txq != NULL) {
    1295                 :          0 :                 igb_tx_queue_release_mbufs(txq);
    1296                 :          0 :                 rte_free(txq->sw_ring);
    1297                 :          0 :                 rte_memzone_free(txq->mz);
    1298                 :          0 :                 rte_free(txq);
    1299                 :            :         }
    1300                 :          0 : }
    1301                 :            : 
    1302                 :            : void
    1303                 :          0 : eth_igb_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    1304                 :            : {
    1305                 :          0 :         igb_tx_queue_release(dev->data->tx_queues[qid]);
    1306                 :          0 : }
    1307                 :            : 
    1308                 :            : static int
    1309                 :          0 : igb_tx_done_cleanup(struct igb_tx_queue *txq, uint32_t free_cnt)
    1310                 :            : {
    1311                 :            :         struct igb_tx_entry *sw_ring;
    1312                 :            :         volatile union e1000_adv_tx_desc *txr;
    1313                 :            :         uint16_t tx_first; /* First segment analyzed. */
    1314                 :            :         uint16_t tx_id;    /* Current segment being processed. */
    1315                 :            :         uint16_t tx_last;  /* Last segment in the current packet. */
    1316                 :            :         uint16_t tx_next;  /* First segment of the next packet. */
    1317                 :            :         int count = 0;
    1318                 :            : 
    1319         [ #  # ]:          0 :         if (!txq)
    1320                 :            :                 return -ENODEV;
    1321                 :            : 
    1322                 :          0 :         sw_ring = txq->sw_ring;
    1323                 :          0 :         txr = txq->tx_ring;
    1324                 :            : 
    1325                 :            :         /* tx_tail is the last sent packet on the sw_ring. Goto the end
    1326                 :            :          * of that packet (the last segment in the packet chain) and
    1327                 :            :          * then the next segment will be the start of the oldest segment
    1328                 :            :          * in the sw_ring. This is the first packet that will be
    1329                 :            :          * attempted to be freed.
    1330                 :            :          */
    1331                 :            : 
    1332                 :            :         /* Get last segment in most recently added packet. */
    1333                 :          0 :         tx_first = sw_ring[txq->tx_tail].last_id;
    1334                 :            : 
    1335                 :            :         /* Get the next segment, which is the oldest segment in ring. */
    1336                 :          0 :         tx_first = sw_ring[tx_first].next_id;
    1337                 :            : 
    1338                 :            :         /* Set the current index to the first. */
    1339                 :            :         tx_id = tx_first;
    1340                 :            : 
    1341                 :            :         /* Loop through each packet. For each packet, verify that an
    1342                 :            :          * mbuf exists and that the last segment is free. If so, free
    1343                 :            :          * it and move on.
    1344                 :            :          */
    1345                 :            :         while (1) {
    1346                 :          0 :                 tx_last = sw_ring[tx_id].last_id;
    1347                 :            : 
    1348         [ #  # ]:          0 :                 if (sw_ring[tx_last].mbuf) {
    1349         [ #  # ]:          0 :                         if (txr[tx_last].wb.status &
    1350                 :            :                             E1000_TXD_STAT_DD) {
    1351                 :            :                                 /* Increment the number of packets
    1352                 :            :                                  * freed.
    1353                 :            :                                  */
    1354                 :          0 :                                 count++;
    1355                 :            : 
    1356                 :            :                                 /* Get the start of the next packet. */
    1357                 :          0 :                                 tx_next = sw_ring[tx_last].next_id;
    1358                 :            : 
    1359                 :            :                                 /* Loop through all segments in a
    1360                 :            :                                  * packet.
    1361                 :            :                                  */
    1362                 :            :                                 do {
    1363         [ #  # ]:          0 :                                         if (sw_ring[tx_id].mbuf) {
    1364                 :            :                                                 rte_pktmbuf_free_seg(
    1365                 :            :                                                         sw_ring[tx_id].mbuf);
    1366                 :          0 :                                                 sw_ring[tx_id].mbuf = NULL;
    1367                 :          0 :                                                 sw_ring[tx_id].last_id = tx_id;
    1368                 :            :                                         }
    1369                 :            : 
    1370                 :            :                                         /* Move to next segment. */
    1371                 :          0 :                                         tx_id = sw_ring[tx_id].next_id;
    1372                 :            : 
    1373         [ #  # ]:          0 :                                 } while (tx_id != tx_next);
    1374                 :            : 
    1375         [ #  # ]:          0 :                                 if (unlikely(count == (int)free_cnt))
    1376                 :            :                                         break;
    1377                 :            :                         } else {
    1378                 :            :                                 /* mbuf still in use, nothing left to
    1379                 :            :                                  * free.
    1380                 :            :                                  */
    1381                 :            :                                 break;
    1382                 :            :                         }
    1383                 :            :                 } else {
    1384                 :            :                         /* There are multiple reasons to be here:
    1385                 :            :                          * 1) All the packets on the ring have been
    1386                 :            :                          *    freed - tx_id is equal to tx_first
    1387                 :            :                          *    and some packets have been freed.
    1388                 :            :                          *    - Done, exit
    1389                 :            :                          * 2) Interfaces has not sent a rings worth of
    1390                 :            :                          *    packets yet, so the segment after tail is
    1391                 :            :                          *    still empty. Or a previous call to this
    1392                 :            :                          *    function freed some of the segments but
    1393                 :            :                          *    not all so there is a hole in the list.
    1394                 :            :                          *    Hopefully this is a rare case.
    1395                 :            :                          *    - Walk the list and find the next mbuf. If
    1396                 :            :                          *      there isn't one, then done.
    1397                 :            :                          */
    1398         [ #  # ]:          0 :                         if (likely(tx_id == tx_first && count != 0))
    1399                 :            :                                 break;
    1400                 :            : 
    1401                 :            :                         /* Walk the list and find the next mbuf, if any. */
    1402                 :            :                         do {
    1403                 :            :                                 /* Move to next segment. */
    1404                 :          0 :                                 tx_id = sw_ring[tx_id].next_id;
    1405                 :            : 
    1406         [ #  # ]:          0 :                                 if (sw_ring[tx_id].mbuf)
    1407                 :            :                                         break;
    1408                 :            : 
    1409         [ #  # ]:          0 :                         } while (tx_id != tx_first);
    1410                 :            : 
    1411                 :            :                         /* Determine why previous loop bailed. If there
    1412                 :            :                          * is not an mbuf, done.
    1413                 :            :                          */
    1414         [ #  # ]:          0 :                         if (!sw_ring[tx_id].mbuf)
    1415                 :            :                                 break;
    1416                 :            :                 }
    1417                 :            :         }
    1418                 :            : 
    1419                 :            :         return count;
    1420                 :            : }
    1421                 :            : 
    1422                 :            : int
    1423                 :          0 : eth_igb_tx_done_cleanup(void *txq, uint32_t free_cnt)
    1424                 :            : {
    1425                 :          0 :         return igb_tx_done_cleanup(txq, free_cnt);
    1426                 :            : }
    1427                 :            : 
    1428                 :            : static void
    1429                 :            : igb_reset_tx_queue_stat(struct igb_tx_queue *txq)
    1430                 :            : {
    1431                 :          0 :         txq->tx_head = 0;
    1432                 :          0 :         txq->tx_tail = 0;
    1433                 :          0 :         txq->ctx_curr = 0;
    1434                 :          0 :         memset((void*)&txq->ctx_cache, 0,
    1435                 :            :                 IGB_CTX_NUM * sizeof(struct igb_advctx_info));
    1436                 :            : }
    1437                 :            : 
    1438                 :            : static void
    1439                 :          0 : igb_reset_tx_queue(struct igb_tx_queue *txq, struct rte_eth_dev *dev)
    1440                 :            : {
    1441                 :            :         static const union e1000_adv_tx_desc zeroed_desc = {{0}};
    1442                 :          0 :         struct igb_tx_entry *txe = txq->sw_ring;
    1443                 :            :         uint16_t i, prev;
    1444                 :            :         struct e1000_hw *hw;
    1445                 :            : 
    1446                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1447                 :            :         /* Zero out HW ring memory */
    1448         [ #  # ]:          0 :         for (i = 0; i < txq->nb_tx_desc; i++) {
    1449                 :          0 :                 txq->tx_ring[i] = zeroed_desc;
    1450                 :            :         }
    1451                 :            : 
    1452                 :            :         /* Initialize ring entries */
    1453                 :          0 :         prev = (uint16_t)(txq->nb_tx_desc - 1);
    1454         [ #  # ]:          0 :         for (i = 0; i < txq->nb_tx_desc; i++) {
    1455                 :          0 :                 volatile union e1000_adv_tx_desc *txd = &(txq->tx_ring[i]);
    1456                 :            : 
    1457                 :          0 :                 txd->wb.status = E1000_TXD_STAT_DD;
    1458                 :          0 :                 txe[i].mbuf = NULL;
    1459                 :          0 :                 txe[i].last_id = i;
    1460                 :          0 :                 txe[prev].next_id = i;
    1461                 :            :                 prev = i;
    1462                 :            :         }
    1463                 :            : 
    1464                 :          0 :         txq->txd_type = E1000_ADVTXD_DTYP_DATA;
    1465                 :            :         /* 82575 specific, each tx queue will use 2 hw contexts */
    1466         [ #  # ]:          0 :         if (hw->mac.type == e1000_82575)
    1467                 :          0 :                 txq->ctx_start = txq->queue_id * IGB_CTX_NUM;
    1468                 :            : 
    1469                 :            :         igb_reset_tx_queue_stat(txq);
    1470                 :          0 : }
    1471                 :            : 
    1472                 :            : uint64_t
    1473                 :          0 : igb_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
    1474                 :            : {
    1475                 :            :         uint64_t tx_offload_capa;
    1476                 :            : 
    1477                 :            :         RTE_SET_USED(dev);
    1478                 :            :         tx_offload_capa = RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
    1479                 :            :                           RTE_ETH_TX_OFFLOAD_IPV4_CKSUM  |
    1480                 :            :                           RTE_ETH_TX_OFFLOAD_UDP_CKSUM   |
    1481                 :            :                           RTE_ETH_TX_OFFLOAD_TCP_CKSUM   |
    1482                 :            :                           RTE_ETH_TX_OFFLOAD_SCTP_CKSUM  |
    1483                 :            :                           RTE_ETH_TX_OFFLOAD_TCP_TSO     |
    1484                 :            :                           RTE_ETH_TX_OFFLOAD_MULTI_SEGS  |
    1485                 :            :                           RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP;
    1486                 :            : 
    1487                 :          0 :         return tx_offload_capa;
    1488                 :            : }
    1489                 :            : 
    1490                 :            : uint64_t
    1491                 :          0 : igb_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
    1492                 :            : {
    1493                 :            :         uint64_t tx_queue_offload_capa;
    1494                 :            : 
    1495                 :          0 :         tx_queue_offload_capa = igb_get_tx_port_offloads_capa(dev);
    1496                 :            : 
    1497                 :          0 :         return tx_queue_offload_capa;
    1498                 :            : }
    1499                 :            : 
    1500                 :            : int
    1501                 :          0 : eth_igb_tx_queue_setup(struct rte_eth_dev *dev,
    1502                 :            :                          uint16_t queue_idx,
    1503                 :            :                          uint16_t nb_desc,
    1504                 :            :                          unsigned int socket_id,
    1505                 :            :                          const struct rte_eth_txconf *tx_conf)
    1506                 :            : {
    1507                 :            :         const struct rte_memzone *tz;
    1508                 :            :         struct igb_tx_queue *txq;
    1509                 :            :         struct e1000_hw     *hw;
    1510                 :            :         uint32_t size;
    1511                 :            :         uint64_t offloads;
    1512                 :            : 
    1513                 :          0 :         offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
    1514                 :            : 
    1515                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1516                 :            : 
    1517                 :            :         /*
    1518                 :            :          * Validate number of transmit descriptors.
    1519                 :            :          * It must not exceed hardware maximum, and must be multiple
    1520                 :            :          * of E1000_ALIGN.
    1521                 :            :          */
    1522         [ #  # ]:          0 :         if (nb_desc % IGB_TXD_ALIGN != 0 ||
    1523         [ #  # ]:          0 :                         (nb_desc > E1000_MAX_RING_DESC) ||
    1524                 :            :                         (nb_desc < E1000_MIN_RING_DESC)) {
    1525                 :            :                 return -EINVAL;
    1526                 :            :         }
    1527                 :            : 
    1528                 :            :         /*
    1529                 :            :          * The tx_free_thresh and tx_rs_thresh values are not used in the 1G
    1530                 :            :          * driver.
    1531                 :            :          */
    1532         [ #  # ]:          0 :         if (tx_conf->tx_free_thresh != 0)
    1533                 :          0 :                 PMD_INIT_LOG(INFO, "The tx_free_thresh parameter is not "
    1534                 :            :                              "used for the 1G driver.");
    1535         [ #  # ]:          0 :         if (tx_conf->tx_rs_thresh != 0)
    1536                 :          0 :                 PMD_INIT_LOG(INFO, "The tx_rs_thresh parameter is not "
    1537                 :            :                              "used for the 1G driver.");
    1538   [ #  #  #  # ]:          0 :         if (tx_conf->tx_thresh.wthresh == 0 && hw->mac.type != e1000_82576)
    1539                 :          0 :                 PMD_INIT_LOG(INFO, "To improve 1G driver performance, "
    1540                 :            :                              "consider setting the TX WTHRESH value to 4, 8, "
    1541                 :            :                              "or 16.");
    1542                 :            : 
    1543                 :            :         /* Free memory prior to re-allocation if needed */
    1544         [ #  # ]:          0 :         if (dev->data->tx_queues[queue_idx] != NULL) {
    1545                 :          0 :                 igb_tx_queue_release(dev->data->tx_queues[queue_idx]);
    1546                 :          0 :                 dev->data->tx_queues[queue_idx] = NULL;
    1547                 :            :         }
    1548                 :            : 
    1549                 :            :         /* First allocate the tx queue data structure */
    1550                 :          0 :         txq = rte_zmalloc("ethdev TX queue", sizeof(struct igb_tx_queue),
    1551                 :            :                                                         RTE_CACHE_LINE_SIZE);
    1552         [ #  # ]:          0 :         if (txq == NULL)
    1553                 :            :                 return -ENOMEM;
    1554                 :            : 
    1555                 :            :         /*
    1556                 :            :          * Allocate TX ring hardware descriptors. A memzone large enough to
    1557                 :            :          * handle the maximum ring size is allocated in order to allow for
    1558                 :            :          * resizing in later calls to the queue setup function.
    1559                 :            :          */
    1560                 :            :         size = sizeof(union e1000_adv_tx_desc) * E1000_MAX_RING_DESC;
    1561                 :          0 :         tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx, size,
    1562                 :            :                                       E1000_ALIGN, socket_id);
    1563         [ #  # ]:          0 :         if (tz == NULL) {
    1564                 :          0 :                 igb_tx_queue_release(txq);
    1565                 :          0 :                 return -ENOMEM;
    1566                 :            :         }
    1567                 :            : 
    1568                 :          0 :         txq->mz = tz;
    1569                 :          0 :         txq->nb_tx_desc = nb_desc;
    1570                 :          0 :         txq->pthresh = tx_conf->tx_thresh.pthresh;
    1571                 :          0 :         txq->hthresh = tx_conf->tx_thresh.hthresh;
    1572                 :          0 :         txq->wthresh = tx_conf->tx_thresh.wthresh;
    1573   [ #  #  #  # ]:          0 :         if (txq->wthresh > 0 && hw->mac.type == e1000_82576)
    1574                 :          0 :                 txq->wthresh = 1;
    1575                 :          0 :         txq->queue_id = queue_idx;
    1576         [ #  # ]:          0 :         txq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
    1577                 :          0 :                 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
    1578                 :          0 :         txq->port_id = dev->data->port_id;
    1579                 :            : 
    1580         [ #  # ]:          0 :         txq->tdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_TDT(txq->reg_idx));
    1581                 :          0 :         txq->tx_ring_phys_addr = tz->iova;
    1582                 :            : 
    1583                 :          0 :         txq->tx_ring = (union e1000_adv_tx_desc *) tz->addr;
    1584                 :            :         /* Allocate software ring */
    1585                 :          0 :         txq->sw_ring = rte_zmalloc("txq->sw_ring",
    1586                 :            :                                    sizeof(struct igb_tx_entry) * nb_desc,
    1587                 :            :                                    RTE_CACHE_LINE_SIZE);
    1588         [ #  # ]:          0 :         if (txq->sw_ring == NULL) {
    1589                 :          0 :                 igb_tx_queue_release(txq);
    1590                 :          0 :                 return -ENOMEM;
    1591                 :            :         }
    1592                 :          0 :         PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
    1593                 :            :                      txq->sw_ring, txq->tx_ring, txq->tx_ring_phys_addr);
    1594                 :            : 
    1595                 :          0 :         igb_reset_tx_queue(txq, dev);
    1596                 :          0 :         dev->tx_pkt_burst = eth_igb_xmit_pkts;
    1597                 :          0 :         dev->tx_pkt_prepare = &eth_igb_prep_pkts;
    1598                 :          0 :         dev->data->tx_queues[queue_idx] = txq;
    1599                 :          0 :         txq->offloads = offloads;
    1600                 :            : 
    1601                 :          0 :         return 0;
    1602                 :            : }
    1603                 :            : 
    1604                 :            : static void
    1605                 :          0 : igb_rx_queue_release_mbufs(struct igb_rx_queue *rxq)
    1606                 :            : {
    1607                 :            :         unsigned i;
    1608                 :            : 
    1609         [ #  # ]:          0 :         if (rxq->sw_ring != NULL) {
    1610         [ #  # ]:          0 :                 for (i = 0; i < rxq->nb_rx_desc; i++) {
    1611         [ #  # ]:          0 :                         if (rxq->sw_ring[i].mbuf != NULL) {
    1612                 :            :                                 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
    1613                 :          0 :                                 rxq->sw_ring[i].mbuf = NULL;
    1614                 :            :                         }
    1615                 :            :                 }
    1616                 :            :         }
    1617                 :          0 : }
    1618                 :            : 
    1619                 :            : static void
    1620                 :          0 : igb_rx_queue_release(struct igb_rx_queue *rxq)
    1621                 :            : {
    1622         [ #  # ]:          0 :         if (rxq != NULL) {
    1623                 :          0 :                 igb_rx_queue_release_mbufs(rxq);
    1624                 :          0 :                 rte_free(rxq->sw_ring);
    1625                 :          0 :                 rte_memzone_free(rxq->mz);
    1626                 :          0 :                 rte_free(rxq);
    1627                 :            :         }
    1628                 :          0 : }
    1629                 :            : 
    1630                 :            : void
    1631                 :          0 : eth_igb_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
    1632                 :            : {
    1633                 :          0 :         igb_rx_queue_release(dev->data->rx_queues[qid]);
    1634                 :          0 : }
    1635                 :            : 
    1636                 :            : static void
    1637                 :            : igb_reset_rx_queue(struct igb_rx_queue *rxq)
    1638                 :            : {
    1639                 :            :         static const union e1000_adv_rx_desc zeroed_desc = {{0}};
    1640                 :            :         unsigned i;
    1641                 :            : 
    1642                 :            :         /* Zero out HW ring memory */
    1643   [ #  #  #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
    1644                 :          0 :                 rxq->rx_ring[i] = zeroed_desc;
    1645                 :            :         }
    1646                 :            : 
    1647                 :          0 :         rxq->rx_tail = 0;
    1648                 :          0 :         rxq->pkt_first_seg = NULL;
    1649                 :          0 :         rxq->pkt_last_seg = NULL;
    1650                 :            : }
    1651                 :            : 
    1652                 :            : uint64_t
    1653                 :          0 : igb_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
    1654                 :            : {
    1655                 :            :         uint64_t rx_offload_capa;
    1656                 :            :         struct e1000_hw *hw;
    1657                 :            : 
    1658                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1659                 :            : 
    1660                 :            :         rx_offload_capa = RTE_ETH_RX_OFFLOAD_VLAN_STRIP  |
    1661                 :            :                           RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
    1662                 :            :                           RTE_ETH_RX_OFFLOAD_IPV4_CKSUM  |
    1663                 :            :                           RTE_ETH_RX_OFFLOAD_UDP_CKSUM   |
    1664                 :            :                           RTE_ETH_RX_OFFLOAD_TCP_CKSUM   |
    1665                 :            :                           RTE_ETH_RX_OFFLOAD_KEEP_CRC    |
    1666                 :            :                           RTE_ETH_RX_OFFLOAD_SCATTER     |
    1667                 :            :                           RTE_ETH_RX_OFFLOAD_RSS_HASH;
    1668                 :            : 
    1669         [ #  # ]:          0 :         if (hw->mac.type == e1000_82576 ||
    1670         [ #  # ]:          0 :             hw->mac.type == e1000_i350 ||
    1671         [ #  # ]:          0 :             hw->mac.type == e1000_i210 ||
    1672                 :            :             hw->mac.type == e1000_i211)
    1673                 :            :                 rx_offload_capa |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
    1674                 :            : 
    1675                 :          0 :         return rx_offload_capa;
    1676                 :            : }
    1677                 :            : 
    1678                 :            : uint64_t
    1679                 :          0 : igb_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
    1680                 :            : {
    1681                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1682                 :            :         uint64_t rx_queue_offload_capa;
    1683                 :            : 
    1684         [ #  # ]:          0 :         switch (hw->mac.type) {
    1685                 :          0 :         case e1000_vfadapt_i350:
    1686                 :            :                 /*
    1687                 :            :                  * As only one Rx queue can be used, let per queue offloading
    1688                 :            :                  * capability be same to per port queue offloading capability
    1689                 :            :                  * for better convenience.
    1690                 :            :                  */
    1691                 :          0 :                 rx_queue_offload_capa = igb_get_rx_port_offloads_capa(dev);
    1692                 :          0 :                 break;
    1693                 :            :         default:
    1694                 :            :                 rx_queue_offload_capa = 0;
    1695                 :            :         }
    1696                 :          0 :         return rx_queue_offload_capa;
    1697                 :            : }
    1698                 :            : 
    1699                 :            : int
    1700                 :          0 : eth_igb_rx_queue_setup(struct rte_eth_dev *dev,
    1701                 :            :                          uint16_t queue_idx,
    1702                 :            :                          uint16_t nb_desc,
    1703                 :            :                          unsigned int socket_id,
    1704                 :            :                          const struct rte_eth_rxconf *rx_conf,
    1705                 :            :                          struct rte_mempool *mp)
    1706                 :            : {
    1707                 :            :         const struct rte_memzone *rz;
    1708                 :            :         struct igb_rx_queue *rxq;
    1709                 :            :         struct e1000_hw     *hw;
    1710                 :            :         unsigned int size;
    1711                 :            :         uint64_t offloads;
    1712                 :            : 
    1713                 :          0 :         offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
    1714                 :            : 
    1715                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1716                 :            : 
    1717                 :            :         /*
    1718                 :            :          * Validate number of receive descriptors.
    1719                 :            :          * It must not exceed hardware maximum, and must be multiple
    1720                 :            :          * of E1000_ALIGN.
    1721                 :            :          */
    1722         [ #  # ]:          0 :         if (nb_desc % IGB_RXD_ALIGN != 0 ||
    1723         [ #  # ]:          0 :                         (nb_desc > E1000_MAX_RING_DESC) ||
    1724                 :            :                         (nb_desc < E1000_MIN_RING_DESC)) {
    1725                 :            :                 return -EINVAL;
    1726                 :            :         }
    1727                 :            : 
    1728                 :            :         /* Free memory prior to re-allocation if needed */
    1729         [ #  # ]:          0 :         if (dev->data->rx_queues[queue_idx] != NULL) {
    1730                 :          0 :                 igb_rx_queue_release(dev->data->rx_queues[queue_idx]);
    1731                 :          0 :                 dev->data->rx_queues[queue_idx] = NULL;
    1732                 :            :         }
    1733                 :            : 
    1734                 :            :         /* First allocate the RX queue data structure. */
    1735                 :          0 :         rxq = rte_zmalloc("ethdev RX queue", sizeof(struct igb_rx_queue),
    1736                 :            :                           RTE_CACHE_LINE_SIZE);
    1737         [ #  # ]:          0 :         if (rxq == NULL)
    1738                 :            :                 return -ENOMEM;
    1739                 :          0 :         rxq->offloads = offloads;
    1740                 :          0 :         rxq->mb_pool = mp;
    1741                 :          0 :         rxq->nb_rx_desc = nb_desc;
    1742                 :          0 :         rxq->pthresh = rx_conf->rx_thresh.pthresh;
    1743                 :          0 :         rxq->hthresh = rx_conf->rx_thresh.hthresh;
    1744                 :          0 :         rxq->wthresh = rx_conf->rx_thresh.wthresh;
    1745         [ #  # ]:          0 :         if (rxq->wthresh > 0 &&
    1746         [ #  # ]:          0 :             (hw->mac.type == e1000_82576 || hw->mac.type == e1000_vfadapt_i350))
    1747                 :          0 :                 rxq->wthresh = 1;
    1748                 :          0 :         rxq->drop_en = rx_conf->rx_drop_en;
    1749                 :          0 :         rxq->rx_free_thresh = rx_conf->rx_free_thresh;
    1750                 :          0 :         rxq->queue_id = queue_idx;
    1751         [ #  # ]:          0 :         rxq->reg_idx = (uint16_t)((RTE_ETH_DEV_SRIOV(dev).active == 0) ?
    1752                 :          0 :                 queue_idx : RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx + queue_idx);
    1753                 :          0 :         rxq->port_id = dev->data->port_id;
    1754         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    1755                 :          0 :                 rxq->crc_len = RTE_ETHER_CRC_LEN;
    1756                 :            :         else
    1757                 :          0 :                 rxq->crc_len = 0;
    1758                 :            : 
    1759                 :            :         /*
    1760                 :            :          *  Allocate RX ring hardware descriptors. A memzone large enough to
    1761                 :            :          *  handle the maximum ring size is allocated in order to allow for
    1762                 :            :          *  resizing in later calls to the queue setup function.
    1763                 :            :          */
    1764                 :            :         size = sizeof(union e1000_adv_rx_desc) * E1000_MAX_RING_DESC;
    1765                 :          0 :         rz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx, size,
    1766                 :            :                                       E1000_ALIGN, socket_id);
    1767         [ #  # ]:          0 :         if (rz == NULL) {
    1768                 :          0 :                 igb_rx_queue_release(rxq);
    1769                 :          0 :                 return -ENOMEM;
    1770                 :            :         }
    1771                 :            : 
    1772                 :          0 :         rxq->mz = rz;
    1773         [ #  # ]:          0 :         rxq->rdt_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDT(rxq->reg_idx));
    1774         [ #  # ]:          0 :         rxq->rdh_reg_addr = E1000_PCI_REG_ADDR(hw, E1000_RDH(rxq->reg_idx));
    1775                 :          0 :         rxq->rx_ring_phys_addr = rz->iova;
    1776                 :          0 :         rxq->rx_ring = (union e1000_adv_rx_desc *) rz->addr;
    1777                 :            : 
    1778                 :            :         /* Allocate software ring. */
    1779                 :          0 :         rxq->sw_ring = rte_zmalloc("rxq->sw_ring",
    1780                 :            :                                    sizeof(struct igb_rx_entry) * nb_desc,
    1781                 :            :                                    RTE_CACHE_LINE_SIZE);
    1782         [ #  # ]:          0 :         if (rxq->sw_ring == NULL) {
    1783                 :          0 :                 igb_rx_queue_release(rxq);
    1784                 :          0 :                 return -ENOMEM;
    1785                 :            :         }
    1786                 :          0 :         PMD_INIT_LOG(DEBUG, "sw_ring=%p hw_ring=%p dma_addr=0x%"PRIx64,
    1787                 :            :                      rxq->sw_ring, rxq->rx_ring, rxq->rx_ring_phys_addr);
    1788                 :            : 
    1789                 :          0 :         dev->data->rx_queues[queue_idx] = rxq;
    1790                 :            :         igb_reset_rx_queue(rxq);
    1791                 :            : 
    1792                 :          0 :         return 0;
    1793                 :            : }
    1794                 :            : 
    1795                 :            : uint32_t
    1796                 :          0 : eth_igb_rx_queue_count(void *rx_queue)
    1797                 :            : {
    1798                 :            : #define IGB_RXQ_SCAN_INTERVAL 4
    1799                 :            :         volatile union e1000_adv_rx_desc *rxdp;
    1800                 :            :         struct igb_rx_queue *rxq;
    1801                 :            :         uint32_t desc = 0;
    1802                 :            : 
    1803                 :            :         rxq = rx_queue;
    1804                 :          0 :         rxdp = &(rxq->rx_ring[rxq->rx_tail]);
    1805                 :            : 
    1806         [ #  # ]:          0 :         while ((desc < rxq->nb_rx_desc) &&
    1807         [ #  # ]:          0 :                 (rxdp->wb.upper.status_error & E1000_RXD_STAT_DD)) {
    1808                 :          0 :                 desc += IGB_RXQ_SCAN_INTERVAL;
    1809                 :          0 :                 rxdp += IGB_RXQ_SCAN_INTERVAL;
    1810         [ #  # ]:          0 :                 if (rxq->rx_tail + desc >= rxq->nb_rx_desc)
    1811                 :          0 :                         rxdp = &(rxq->rx_ring[rxq->rx_tail +
    1812                 :          0 :                                 desc - rxq->nb_rx_desc]);
    1813                 :            :         }
    1814                 :            : 
    1815                 :          0 :         return desc;
    1816                 :            : }
    1817                 :            : 
    1818                 :            : int
    1819                 :          0 : eth_igb_rx_descriptor_status(void *rx_queue, uint16_t offset)
    1820                 :            : {
    1821                 :            :         struct igb_rx_queue *rxq = rx_queue;
    1822                 :            :         volatile uint32_t *status;
    1823                 :            :         uint32_t desc;
    1824                 :            : 
    1825         [ #  # ]:          0 :         if (unlikely(offset >= rxq->nb_rx_desc))
    1826                 :            :                 return -EINVAL;
    1827                 :            : 
    1828         [ #  # ]:          0 :         if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
    1829                 :            :                 return RTE_ETH_RX_DESC_UNAVAIL;
    1830                 :            : 
    1831                 :          0 :         desc = rxq->rx_tail + offset;
    1832         [ #  # ]:          0 :         if (desc >= rxq->nb_rx_desc)
    1833                 :          0 :                 desc -= rxq->nb_rx_desc;
    1834                 :            : 
    1835                 :          0 :         status = &rxq->rx_ring[desc].wb.upper.status_error;
    1836         [ #  # ]:          0 :         if (*status & rte_cpu_to_le_32(E1000_RXD_STAT_DD))
    1837                 :          0 :                 return RTE_ETH_RX_DESC_DONE;
    1838                 :            : 
    1839                 :            :         return RTE_ETH_RX_DESC_AVAIL;
    1840                 :            : }
    1841                 :            : 
    1842                 :            : int
    1843                 :          0 : eth_igb_tx_descriptor_status(void *tx_queue, uint16_t offset)
    1844                 :            : {
    1845                 :            :         struct igb_tx_queue *txq = tx_queue;
    1846                 :            :         volatile uint32_t *status;
    1847                 :            :         uint32_t desc;
    1848                 :            : 
    1849         [ #  # ]:          0 :         if (unlikely(offset >= txq->nb_tx_desc))
    1850                 :            :                 return -EINVAL;
    1851                 :            : 
    1852                 :          0 :         desc = txq->tx_tail + offset;
    1853         [ #  # ]:          0 :         if (desc >= txq->nb_tx_desc)
    1854                 :          0 :                 desc -= txq->nb_tx_desc;
    1855                 :            : 
    1856                 :          0 :         status = &txq->tx_ring[desc].wb.status;
    1857         [ #  # ]:          0 :         if (*status & rte_cpu_to_le_32(E1000_TXD_STAT_DD))
    1858                 :          0 :                 return RTE_ETH_TX_DESC_DONE;
    1859                 :            : 
    1860                 :            :         return RTE_ETH_TX_DESC_FULL;
    1861                 :            : }
    1862                 :            : 
    1863                 :            : void
    1864                 :          0 : igb_dev_clear_queues(struct rte_eth_dev *dev)
    1865                 :            : {
    1866                 :            :         uint16_t i;
    1867                 :            :         struct igb_tx_queue *txq;
    1868                 :            :         struct igb_rx_queue *rxq;
    1869                 :            : 
    1870         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    1871         [ #  # ]:          0 :                 __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
    1872                 :          0 :                 txq = dev->data->tx_queues[i];
    1873         [ #  # ]:          0 :                 if (txq != NULL) {
    1874                 :          0 :                         igb_tx_queue_release_mbufs(txq);
    1875                 :          0 :                         igb_reset_tx_queue(txq, dev);
    1876                 :          0 :                         dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1877                 :            :                 }
    1878                 :            :         }
    1879                 :            : 
    1880         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    1881         [ #  # ]:          0 :                 __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
    1882                 :          0 :                 rxq = dev->data->rx_queues[i];
    1883         [ #  # ]:          0 :                 if (rxq != NULL) {
    1884                 :          0 :                         igb_rx_queue_release_mbufs(rxq);
    1885                 :            :                         igb_reset_rx_queue(rxq);
    1886                 :          0 :                         dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
    1887                 :            :                 }
    1888                 :            :         }
    1889                 :          0 : }
    1890                 :            : 
    1891                 :            : void
    1892                 :          0 : igb_dev_free_queues(struct rte_eth_dev *dev)
    1893                 :            : {
    1894                 :            :         uint16_t i;
    1895                 :            : 
    1896         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    1897                 :          0 :                 eth_igb_rx_queue_release(dev, i);
    1898                 :          0 :                 dev->data->rx_queues[i] = NULL;
    1899                 :            :         }
    1900                 :          0 :         dev->data->nb_rx_queues = 0;
    1901                 :            : 
    1902         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    1903                 :          0 :                 eth_igb_tx_queue_release(dev, i);
    1904                 :          0 :                 dev->data->tx_queues[i] = NULL;
    1905                 :            :         }
    1906                 :          0 :         dev->data->nb_tx_queues = 0;
    1907                 :          0 : }
    1908                 :            : 
    1909                 :            : /**
    1910                 :            :  * Receive Side Scaling (RSS).
    1911                 :            :  * See section 7.1.1.7 in the following document:
    1912                 :            :  *     "Intel 82576 GbE Controller Datasheet" - Revision 2.45 October 2009
    1913                 :            :  *
    1914                 :            :  * Principles:
    1915                 :            :  * The source and destination IP addresses of the IP header and the source and
    1916                 :            :  * destination ports of TCP/UDP headers, if any, of received packets are hashed
    1917                 :            :  * against a configurable random key to compute a 32-bit RSS hash result.
    1918                 :            :  * The seven (7) LSBs of the 32-bit hash result are used as an index into a
    1919                 :            :  * 128-entry redirection table (RETA).  Each entry of the RETA provides a 3-bit
    1920                 :            :  * RSS output index which is used as the RX queue index where to store the
    1921                 :            :  * received packets.
    1922                 :            :  * The following output is supplied in the RX write-back descriptor:
    1923                 :            :  *     - 32-bit result of the Microsoft RSS hash function,
    1924                 :            :  *     - 4-bit RSS type field.
    1925                 :            :  */
    1926                 :            : 
    1927                 :            : /*
    1928                 :            :  * RSS random key supplied in section 7.1.1.7.3 of the Intel 82576 datasheet.
    1929                 :            :  * Used as the default key.
    1930                 :            :  */
    1931                 :            : static uint8_t rss_intel_key[40] = {
    1932                 :            :         0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
    1933                 :            :         0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
    1934                 :            :         0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
    1935                 :            :         0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
    1936                 :            :         0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
    1937                 :            : };
    1938                 :            : 
    1939                 :            : static void
    1940                 :            : igb_rss_disable(struct rte_eth_dev *dev)
    1941                 :            : {
    1942                 :            :         struct e1000_hw *hw;
    1943                 :            :         uint32_t mrqc;
    1944                 :            : 
    1945                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1946                 :          0 :         mrqc = E1000_READ_REG(hw, E1000_MRQC);
    1947                 :          0 :         mrqc &= ~E1000_MRQC_ENABLE_MASK;
    1948                 :          0 :         E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
    1949                 :          0 : }
    1950                 :            : 
    1951                 :            : static void
    1952                 :          0 : igb_hw_rss_hash_set(struct e1000_hw *hw, struct rte_eth_rss_conf *rss_conf)
    1953                 :            : {
    1954                 :            :         uint8_t  *hash_key;
    1955                 :            :         uint32_t rss_key;
    1956                 :            :         uint32_t mrqc;
    1957                 :            :         uint64_t rss_hf;
    1958                 :            :         uint16_t i;
    1959                 :            : 
    1960                 :          0 :         hash_key = rss_conf->rss_key;
    1961         [ #  # ]:          0 :         if (hash_key != NULL) {
    1962                 :            :                 /* Fill in RSS hash key */
    1963         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    1964                 :          0 :                         rss_key  = hash_key[(i * 4)];
    1965                 :          0 :                         rss_key |= hash_key[(i * 4) + 1] << 8;
    1966                 :          0 :                         rss_key |= hash_key[(i * 4) + 2] << 16;
    1967                 :          0 :                         rss_key |= hash_key[(i * 4) + 3] << 24;
    1968                 :          0 :                         E1000_WRITE_REG_ARRAY(hw, E1000_RSSRK(0), i, rss_key);
    1969                 :            :                 }
    1970                 :            :         }
    1971                 :            : 
    1972                 :            :         /* Set configured hashing protocols in MRQC register */
    1973                 :          0 :         rss_hf = rss_conf->rss_hf;
    1974                 :            :         mrqc = E1000_MRQC_ENABLE_RSS_4Q; /* RSS enabled. */
    1975         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_IPV4)
    1976                 :            :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV4;
    1977         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
    1978                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_TCP;
    1979         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_IPV6)
    1980                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6;
    1981         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_IPV6_EX)
    1982                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_EX;
    1983         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
    1984                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP;
    1985         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
    1986                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
    1987         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP)
    1988                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV4_UDP;
    1989         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP)
    1990                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP;
    1991         [ #  # ]:          0 :         if (rss_hf & RTE_ETH_RSS_IPV6_UDP_EX)
    1992                 :          0 :                 mrqc |= E1000_MRQC_RSS_FIELD_IPV6_UDP_EX;
    1993                 :          0 :         E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
    1994                 :          0 : }
    1995                 :            : 
    1996                 :            : int
    1997                 :          0 : eth_igb_rss_hash_update(struct rte_eth_dev *dev,
    1998                 :            :                         struct rte_eth_rss_conf *rss_conf)
    1999                 :            : {
    2000                 :            :         struct e1000_hw *hw;
    2001                 :            :         uint32_t mrqc;
    2002                 :            :         uint64_t rss_hf;
    2003                 :            : 
    2004                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2005                 :            : 
    2006                 :            :         /*
    2007                 :            :          * Before changing anything, first check that the update RSS operation
    2008                 :            :          * does not attempt to disable RSS, if RSS was enabled at
    2009                 :            :          * initialization time, or does not attempt to enable RSS, if RSS was
    2010                 :            :          * disabled at initialization time.
    2011                 :            :          */
    2012                 :          0 :         rss_hf = rss_conf->rss_hf & IGB_RSS_OFFLOAD_ALL;
    2013                 :          0 :         mrqc = E1000_READ_REG(hw, E1000_MRQC);
    2014         [ #  # ]:          0 :         if (!(mrqc & E1000_MRQC_ENABLE_MASK)) { /* RSS disabled */
    2015         [ #  # ]:          0 :                 if (rss_hf != 0) /* Enable RSS */
    2016                 :            :                         return -(EINVAL);
    2017                 :          0 :                 return 0; /* Nothing to do */
    2018                 :            :         }
    2019                 :            :         /* RSS enabled */
    2020         [ #  # ]:          0 :         if (rss_hf == 0) /* Disable RSS */
    2021                 :            :                 return -(EINVAL);
    2022                 :          0 :         igb_hw_rss_hash_set(hw, rss_conf);
    2023                 :          0 :         return 0;
    2024                 :            : }
    2025                 :            : 
    2026                 :          0 : int eth_igb_rss_hash_conf_get(struct rte_eth_dev *dev,
    2027                 :            :                               struct rte_eth_rss_conf *rss_conf)
    2028                 :            : {
    2029                 :            :         struct e1000_hw *hw;
    2030                 :            :         uint8_t *hash_key;
    2031                 :            :         uint32_t rss_key;
    2032                 :            :         uint32_t mrqc;
    2033                 :            :         uint64_t rss_hf;
    2034                 :            :         uint16_t i;
    2035                 :            : 
    2036                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2037                 :          0 :         hash_key = rss_conf->rss_key;
    2038         [ #  # ]:          0 :         if (hash_key != NULL) {
    2039                 :            :                 /* Return RSS hash key */
    2040         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    2041                 :          0 :                         rss_key = E1000_READ_REG_ARRAY(hw, E1000_RSSRK(0), i);
    2042                 :          0 :                         hash_key[(i * 4)] = rss_key & 0x000000FF;
    2043                 :          0 :                         hash_key[(i * 4) + 1] = (rss_key >> 8) & 0x000000FF;
    2044                 :          0 :                         hash_key[(i * 4) + 2] = (rss_key >> 16) & 0x000000FF;
    2045                 :          0 :                         hash_key[(i * 4) + 3] = (rss_key >> 24) & 0x000000FF;
    2046                 :            :                 }
    2047                 :            :         }
    2048                 :            : 
    2049                 :            :         /* Get RSS functions configured in MRQC register */
    2050                 :          0 :         mrqc = E1000_READ_REG(hw, E1000_MRQC);
    2051         [ #  # ]:          0 :         if ((mrqc & E1000_MRQC_ENABLE_RSS_4Q) == 0) { /* RSS is disabled */
    2052                 :          0 :                 rss_conf->rss_hf = 0;
    2053                 :          0 :                 return 0;
    2054                 :            :         }
    2055                 :            :         rss_hf = 0;
    2056         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
    2057                 :            :                 rss_hf |= RTE_ETH_RSS_IPV4;
    2058         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
    2059                 :          0 :                 rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
    2060         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
    2061                 :          0 :                 rss_hf |= RTE_ETH_RSS_IPV6;
    2062         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_EX)
    2063                 :          0 :                 rss_hf |= RTE_ETH_RSS_IPV6_EX;
    2064         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
    2065                 :          0 :                 rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
    2066         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP_EX)
    2067                 :          0 :                 rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
    2068         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_UDP)
    2069                 :          0 :                 rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_UDP;
    2070         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_UDP)
    2071                 :          0 :                 rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_UDP;
    2072         [ #  # ]:          0 :         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_UDP_EX)
    2073                 :          0 :                 rss_hf |= RTE_ETH_RSS_IPV6_UDP_EX;
    2074                 :          0 :         rss_conf->rss_hf = rss_hf;
    2075                 :          0 :         return 0;
    2076                 :            : }
    2077                 :            : 
    2078                 :            : static void
    2079                 :          0 : igb_rss_configure(struct rte_eth_dev *dev)
    2080                 :            : {
    2081                 :            :         struct rte_eth_rss_conf rss_conf;
    2082                 :            :         struct e1000_hw *hw;
    2083                 :            :         uint32_t shift;
    2084                 :            :         uint16_t i;
    2085                 :            : 
    2086                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2087                 :            : 
    2088                 :            :         /* Fill in redirection table. */
    2089         [ #  # ]:          0 :         shift = (hw->mac.type == e1000_82575) ? 6 : 0;
    2090         [ #  # ]:          0 :         for (i = 0; i < 128; i++) {
    2091                 :            :                 union e1000_reta {
    2092                 :            :                         uint32_t dword;
    2093                 :            :                         uint8_t  bytes[4];
    2094                 :            :                 } reta;
    2095                 :            :                 uint8_t q_idx;
    2096                 :            : 
    2097         [ #  # ]:          0 :                 q_idx = (uint8_t) ((dev->data->nb_rx_queues > 1) ?
    2098                 :            :                                    i % dev->data->nb_rx_queues : 0);
    2099                 :          0 :                 reta.bytes[i & 3] = (uint8_t) (q_idx << shift);
    2100         [ #  # ]:          0 :                 if ((i & 3) == 3)
    2101                 :          0 :                         E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
    2102                 :            :         }
    2103                 :            : 
    2104                 :            :         /*
    2105                 :            :          * Configure the RSS key and the RSS protocols used to compute
    2106                 :            :          * the RSS hash of input packets.
    2107                 :            :          */
    2108                 :          0 :         rss_conf = dev->data->dev_conf.rx_adv_conf.rss_conf;
    2109         [ #  # ]:          0 :         if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
    2110                 :            :                 igb_rss_disable(dev);
    2111                 :          0 :                 return;
    2112                 :            :         }
    2113         [ #  # ]:          0 :         if (rss_conf.rss_key == NULL)
    2114                 :          0 :                 rss_conf.rss_key = rss_intel_key; /* Default hash key */
    2115                 :          0 :         igb_hw_rss_hash_set(hw, &rss_conf);
    2116                 :            : }
    2117                 :            : 
    2118                 :            : /*
    2119                 :            :  * Check if the mac type support VMDq or not.
    2120                 :            :  * Return 1 if it supports, otherwise, return 0.
    2121                 :            :  */
    2122                 :            : static int
    2123                 :          0 : igb_is_vmdq_supported(const struct rte_eth_dev *dev)
    2124                 :            : {
    2125                 :          0 :         const struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2126                 :            : 
    2127         [ #  # ]:          0 :         switch (hw->mac.type) {
    2128                 :            :         case e1000_82576:
    2129                 :            :         case e1000_82580:
    2130                 :            :         case e1000_i350:
    2131                 :            :                 return 1;
    2132                 :          0 :         case e1000_82540:
    2133                 :            :         case e1000_82541:
    2134                 :            :         case e1000_82542:
    2135                 :            :         case e1000_82543:
    2136                 :            :         case e1000_82544:
    2137                 :            :         case e1000_82545:
    2138                 :            :         case e1000_82546:
    2139                 :            :         case e1000_82547:
    2140                 :            :         case e1000_82571:
    2141                 :            :         case e1000_82572:
    2142                 :            :         case e1000_82573:
    2143                 :            :         case e1000_82574:
    2144                 :            :         case e1000_82583:
    2145                 :            :         case e1000_i210:
    2146                 :            :         case e1000_i211:
    2147                 :            :         default:
    2148                 :          0 :                 PMD_INIT_LOG(ERR, "Cannot support VMDq feature");
    2149                 :          0 :                 return 0;
    2150                 :            :         }
    2151                 :            : }
    2152                 :            : 
    2153                 :            : static int
    2154                 :          0 : igb_vmdq_rx_hw_configure(struct rte_eth_dev *dev)
    2155                 :            : {
    2156                 :            :         struct rte_eth_vmdq_rx_conf *cfg;
    2157                 :            :         struct e1000_hw *hw;
    2158                 :            :         uint32_t mrqc, vt_ctl, vmolr, rctl;
    2159                 :            :         int i;
    2160                 :            : 
    2161                 :          0 :         PMD_INIT_FUNC_TRACE();
    2162                 :            : 
    2163                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2164                 :            :         cfg = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
    2165                 :            : 
    2166                 :            :         /* Check if mac type can support VMDq, return value of 0 means NOT support */
    2167         [ #  # ]:          0 :         if (igb_is_vmdq_supported(dev) == 0)
    2168                 :            :                 return -1;
    2169                 :            : 
    2170                 :            :         igb_rss_disable(dev);
    2171                 :            : 
    2172                 :            :         /* RCTL: enable VLAN filter */
    2173                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    2174                 :          0 :         rctl |= E1000_RCTL_VFE;
    2175                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    2176                 :            : 
    2177                 :            :         /* MRQC: enable vmdq */
    2178                 :          0 :         mrqc = E1000_READ_REG(hw, E1000_MRQC);
    2179                 :          0 :         mrqc |= E1000_MRQC_ENABLE_VMDQ;
    2180                 :          0 :         E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
    2181                 :            : 
    2182                 :            :         /* VTCTL:  pool selection according to VLAN tag */
    2183                 :          0 :         vt_ctl = E1000_READ_REG(hw, E1000_VT_CTL);
    2184         [ #  # ]:          0 :         if (cfg->enable_default_pool)
    2185                 :          0 :                 vt_ctl |= (cfg->default_pool << E1000_VT_CTL_DEFAULT_POOL_SHIFT);
    2186                 :          0 :         vt_ctl |= E1000_VT_CTL_IGNORE_MAC;
    2187                 :          0 :         E1000_WRITE_REG(hw, E1000_VT_CTL, vt_ctl);
    2188                 :            : 
    2189         [ #  # ]:          0 :         for (i = 0; i < E1000_VMOLR_SIZE; i++) {
    2190                 :          0 :                 vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
    2191                 :          0 :                 vmolr &= ~(E1000_VMOLR_AUPE | E1000_VMOLR_ROMPE |
    2192                 :            :                         E1000_VMOLR_ROPE | E1000_VMOLR_BAM |
    2193                 :            :                         E1000_VMOLR_MPME);
    2194                 :            : 
    2195         [ #  # ]:          0 :                 if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_UNTAG)
    2196                 :          0 :                         vmolr |= E1000_VMOLR_AUPE;
    2197         [ #  # ]:          0 :                 if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_HASH_MC)
    2198                 :          0 :                         vmolr |= E1000_VMOLR_ROMPE;
    2199         [ #  # ]:          0 :                 if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_HASH_UC)
    2200                 :          0 :                         vmolr |= E1000_VMOLR_ROPE;
    2201         [ #  # ]:          0 :                 if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_BROADCAST)
    2202                 :          0 :                         vmolr |= E1000_VMOLR_BAM;
    2203         [ #  # ]:          0 :                 if (cfg->rx_mode & RTE_ETH_VMDQ_ACCEPT_MULTICAST)
    2204                 :          0 :                         vmolr |= E1000_VMOLR_MPME;
    2205                 :            : 
    2206                 :          0 :                 E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
    2207                 :            :         }
    2208                 :            : 
    2209                 :            :         /*
    2210                 :            :          * VMOLR: set STRVLAN as 1 if IGMAC in VTCTL is set as 1
    2211                 :            :          * Both 82576 and 82580 support it
    2212                 :            :          */
    2213         [ #  # ]:          0 :         if (hw->mac.type != e1000_i350) {
    2214         [ #  # ]:          0 :                 for (i = 0; i < E1000_VMOLR_SIZE; i++) {
    2215                 :          0 :                         vmolr = E1000_READ_REG(hw, E1000_VMOLR(i));
    2216                 :          0 :                         vmolr |= E1000_VMOLR_STRVLAN;
    2217                 :          0 :                         E1000_WRITE_REG(hw, E1000_VMOLR(i), vmolr);
    2218                 :            :                 }
    2219                 :            :         }
    2220                 :            : 
    2221                 :            :         /* VFTA - enable all vlan filters */
    2222         [ #  # ]:          0 :         for (i = 0; i < IGB_VFTA_SIZE; i++)
    2223                 :          0 :                 E1000_WRITE_REG(hw, (E1000_VFTA+(i*4)), UINT32_MAX);
    2224                 :            : 
    2225                 :            :         /* VFRE: 8 pools enabling for rx, both 82576 and i350 support it */
    2226         [ #  # ]:          0 :         if (hw->mac.type != e1000_82580)
    2227                 :          0 :                 E1000_WRITE_REG(hw, E1000_VFRE, E1000_MBVFICR_VFREQ_MASK);
    2228                 :            : 
    2229                 :            :         /*
    2230                 :            :          * RAH/RAL - allow pools to read specific mac addresses
    2231                 :            :          * In this case, all pools should be able to read from mac addr 0
    2232                 :            :          */
    2233                 :          0 :         E1000_WRITE_REG(hw, E1000_RAH(0), (E1000_RAH_AV | UINT16_MAX));
    2234                 :          0 :         E1000_WRITE_REG(hw, E1000_RAL(0), UINT32_MAX);
    2235                 :            : 
    2236                 :            :         /* VLVF: set up filters for vlan tags as configured */
    2237         [ #  # ]:          0 :         for (i = 0; i < cfg->nb_pool_maps; i++) {
    2238                 :            :                 /* set vlan id in VF register and set the valid bit */
    2239                 :          0 :                 E1000_WRITE_REG(hw, E1000_VLVF(i), (E1000_VLVF_VLANID_ENABLE |
    2240                 :            :                         (cfg->pool_map[i].vlan_id & RTE_ETH_VLAN_ID_MAX) |
    2241                 :            :                         ((cfg->pool_map[i].pools << E1000_VLVF_POOLSEL_SHIFT) &
    2242                 :            :                         E1000_VLVF_POOLSEL_MASK)));
    2243                 :            :         }
    2244                 :            : 
    2245                 :          0 :         E1000_WRITE_FLUSH(hw);
    2246                 :            : 
    2247                 :          0 :         return 0;
    2248                 :            : }
    2249                 :            : 
    2250                 :            : 
    2251                 :            : /*********************************************************************
    2252                 :            :  *
    2253                 :            :  *  Enable receive unit.
    2254                 :            :  *
    2255                 :            :  **********************************************************************/
    2256                 :            : 
    2257                 :            : static int
    2258                 :          0 : igb_alloc_rx_queue_mbufs(struct igb_rx_queue *rxq)
    2259                 :            : {
    2260                 :          0 :         struct igb_rx_entry *rxe = rxq->sw_ring;
    2261                 :            :         uint64_t dma_addr;
    2262                 :            :         unsigned i;
    2263                 :            : 
    2264                 :            :         /* Initialize software ring entries. */
    2265         [ #  # ]:          0 :         for (i = 0; i < rxq->nb_rx_desc; i++) {
    2266                 :            :                 volatile union e1000_adv_rx_desc *rxd;
    2267                 :          0 :                 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
    2268                 :            : 
    2269         [ #  # ]:          0 :                 if (mbuf == NULL) {
    2270                 :          0 :                         PMD_INIT_LOG(ERR, "RX mbuf alloc failed "
    2271                 :            :                                      "queue_id=%hu", rxq->queue_id);
    2272                 :          0 :                         return -ENOMEM;
    2273                 :            :                 }
    2274                 :            :                 dma_addr =
    2275                 :            :                         rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
    2276                 :          0 :                 rxd = &rxq->rx_ring[i];
    2277                 :          0 :                 rxd->read.hdr_addr = 0;
    2278                 :          0 :                 rxd->read.pkt_addr = dma_addr;
    2279                 :          0 :                 rxe[i].mbuf = mbuf;
    2280                 :            :         }
    2281                 :            : 
    2282                 :            :         return 0;
    2283                 :            : }
    2284                 :            : 
    2285                 :            : #define E1000_MRQC_DEF_Q_SHIFT               (3)
    2286                 :            : static int
    2287                 :          0 : igb_dev_mq_rx_configure(struct rte_eth_dev *dev)
    2288                 :            : {
    2289                 :            :         struct e1000_hw *hw =
    2290                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2291                 :            :         uint32_t mrqc;
    2292                 :            : 
    2293         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active == RTE_ETH_8_POOLS) {
    2294                 :            :                 /*
    2295                 :            :                  * SRIOV active scheme
    2296                 :            :                  * FIXME if support RSS together with VMDq & SRIOV
    2297                 :            :                  */
    2298                 :            :                 mrqc = E1000_MRQC_ENABLE_VMDQ;
    2299                 :            :                 /* 011b Def_Q ignore, according to VT_CTL.DEF_PL */
    2300                 :            :                 mrqc |= 0x3 << E1000_MRQC_DEF_Q_SHIFT;
    2301                 :          0 :                 E1000_WRITE_REG(hw, E1000_MRQC, mrqc);
    2302         [ #  # ]:          0 :         } else if(RTE_ETH_DEV_SRIOV(dev).active == 0) {
    2303                 :            :                 /*
    2304                 :            :                  * SRIOV inactive scheme
    2305                 :            :                  */
    2306      [ #  #  # ]:          0 :                 switch (dev->data->dev_conf.rxmode.mq_mode) {
    2307                 :          0 :                         case RTE_ETH_MQ_RX_RSS:
    2308                 :          0 :                                 igb_rss_configure(dev);
    2309                 :          0 :                                 break;
    2310                 :          0 :                         case RTE_ETH_MQ_RX_VMDQ_ONLY:
    2311                 :            :                                 /*Configure general VMDQ only RX parameters*/
    2312                 :          0 :                                 igb_vmdq_rx_hw_configure(dev);
    2313                 :          0 :                                 break;
    2314                 :            :                         case RTE_ETH_MQ_RX_NONE:
    2315                 :            :                                 /* if mq_mode is none, disable rss mode.*/
    2316                 :            :                         default:
    2317                 :            :                                 igb_rss_disable(dev);
    2318                 :            :                                 break;
    2319                 :            :                 }
    2320                 :            :         }
    2321                 :            : 
    2322                 :          0 :         return 0;
    2323                 :            : }
    2324                 :            : 
    2325                 :            : int
    2326                 :          0 : eth_igb_rx_init(struct rte_eth_dev *dev)
    2327                 :            : {
    2328                 :            :         struct rte_eth_rxmode *rxmode;
    2329                 :            :         struct e1000_hw     *hw;
    2330                 :            :         struct igb_rx_queue *rxq;
    2331                 :            :         uint32_t rctl;
    2332                 :            :         uint32_t rxcsum;
    2333                 :            :         uint32_t srrctl;
    2334                 :            :         uint16_t buf_size;
    2335                 :            :         uint16_t rctl_bsize;
    2336                 :            :         uint32_t max_len;
    2337                 :            :         uint16_t i;
    2338                 :            :         int ret;
    2339                 :            : 
    2340                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2341                 :            :         srrctl = 0;
    2342                 :            : 
    2343                 :            :         /*
    2344                 :            :          * Make sure receives are disabled while setting
    2345                 :            :          * up the descriptor ring.
    2346                 :            :          */
    2347                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    2348                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl & ~E1000_RCTL_EN);
    2349                 :            : 
    2350                 :          0 :         rxmode = &dev->data->dev_conf.rxmode;
    2351                 :            : 
    2352                 :            :         /*
    2353                 :            :          * Configure support of jumbo frames, if any.
    2354                 :            :          */
    2355                 :          0 :         max_len = dev->data->mtu + E1000_ETH_OVERHEAD;
    2356         [ #  # ]:          0 :         if (dev->data->mtu > RTE_ETHER_MTU) {
    2357                 :          0 :                 rctl |= E1000_RCTL_LPE;
    2358                 :            : 
    2359                 :            :                 /*
    2360                 :            :                  * Set maximum packet length by default, and might be updated
    2361                 :            :                  * together with enabling/disabling dual VLAN.
    2362                 :            :                  */
    2363         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
    2364                 :          0 :                         max_len += VLAN_TAG_SIZE;
    2365                 :            : 
    2366                 :          0 :                 E1000_WRITE_REG(hw, E1000_RLPML, max_len);
    2367                 :            :         } else
    2368                 :          0 :                 rctl &= ~E1000_RCTL_LPE;
    2369                 :            : 
    2370                 :            :         /* Configure and enable each RX queue. */
    2371                 :            :         rctl_bsize = 0;
    2372                 :          0 :         dev->rx_pkt_burst = eth_igb_recv_pkts;
    2373         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2374                 :            :                 uint64_t bus_addr;
    2375                 :            :                 uint32_t rxdctl;
    2376                 :            : 
    2377                 :          0 :                 rxq = dev->data->rx_queues[i];
    2378                 :            : 
    2379                 :          0 :                 rxq->flags = 0;
    2380                 :            :                 /*
    2381                 :            :                  * i350 and i354 vlan packets have vlan tags byte swapped.
    2382                 :            :                  */
    2383         [ #  # ]:          0 :                 if (hw->mac.type == e1000_i350 || hw->mac.type == e1000_i354) {
    2384                 :          0 :                         rxq->flags |= IGB_RXQ_FLAG_LB_BSWAP_VLAN;
    2385                 :          0 :                         PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap required");
    2386                 :            :                 } else {
    2387                 :          0 :                         PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap not required");
    2388                 :            :                 }
    2389                 :            : 
    2390                 :            :                 /* Allocate buffers for descriptor rings and set up queue */
    2391                 :          0 :                 ret = igb_alloc_rx_queue_mbufs(rxq);
    2392         [ #  # ]:          0 :                 if (ret)
    2393                 :          0 :                         return ret;
    2394                 :            : 
    2395                 :            :                 /*
    2396                 :            :                  * Reset crc_len in case it was changed after queue setup by a
    2397                 :            :                  *  call to configure
    2398                 :            :                  */
    2399         [ #  # ]:          0 :                 if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
    2400                 :          0 :                         rxq->crc_len = RTE_ETHER_CRC_LEN;
    2401                 :            :                 else
    2402                 :          0 :                         rxq->crc_len = 0;
    2403                 :            : 
    2404                 :          0 :                 bus_addr = rxq->rx_ring_phys_addr;
    2405         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDLEN(rxq->reg_idx),
    2406                 :            :                                 rxq->nb_rx_desc *
    2407                 :            :                                 sizeof(union e1000_adv_rx_desc));
    2408         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDBAH(rxq->reg_idx),
    2409                 :            :                                 (uint32_t)(bus_addr >> 32));
    2410         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDBAL(rxq->reg_idx), (uint32_t)bus_addr);
    2411                 :            : 
    2412                 :            :                 srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
    2413                 :            : 
    2414                 :            :                 /*
    2415                 :            :                  * Configure RX buffer size.
    2416                 :            :                  */
    2417         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
    2418                 :            :                         RTE_PKTMBUF_HEADROOM);
    2419         [ #  # ]:          0 :                 if (buf_size >= 1024) {
    2420                 :            :                         /*
    2421                 :            :                          * Configure the BSIZEPACKET field of the SRRCTL
    2422                 :            :                          * register of the queue.
    2423                 :            :                          * Value is in 1 KB resolution, from 1 KB to 127 KB.
    2424                 :            :                          * If this field is equal to 0b, then RCTL.BSIZE
    2425                 :            :                          * determines the RX packet buffer size.
    2426                 :            :                          */
    2427                 :          0 :                         srrctl |= ((buf_size >> E1000_SRRCTL_BSIZEPKT_SHIFT) &
    2428                 :            :                                    E1000_SRRCTL_BSIZEPKT_MASK);
    2429                 :          0 :                         buf_size = (uint16_t) ((srrctl &
    2430                 :            :                                                 E1000_SRRCTL_BSIZEPKT_MASK) <<
    2431                 :            :                                                E1000_SRRCTL_BSIZEPKT_SHIFT);
    2432                 :            : 
    2433                 :            :                         /* It adds dual VLAN length for supporting dual VLAN */
    2434         [ #  # ]:          0 :                         if ((max_len + 2 * VLAN_TAG_SIZE) > buf_size) {
    2435         [ #  # ]:          0 :                                 if (!dev->data->scattered_rx)
    2436                 :          0 :                                         PMD_INIT_LOG(DEBUG,
    2437                 :            :                                                      "forcing scatter mode");
    2438                 :          0 :                                 dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2439                 :          0 :                                 dev->data->scattered_rx = 1;
    2440                 :            :                         }
    2441                 :            :                 } else {
    2442                 :            :                         /*
    2443                 :            :                          * Use BSIZE field of the device RCTL register.
    2444                 :            :                          */
    2445         [ #  # ]:          0 :                         if ((rctl_bsize == 0) || (rctl_bsize > buf_size))
    2446                 :            :                                 rctl_bsize = buf_size;
    2447         [ #  # ]:          0 :                         if (!dev->data->scattered_rx)
    2448                 :          0 :                                 PMD_INIT_LOG(DEBUG, "forcing scatter mode");
    2449                 :          0 :                         dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2450                 :          0 :                         dev->data->scattered_rx = 1;
    2451                 :            :                 }
    2452                 :            : 
    2453                 :            :                 /* Set if packets are dropped when no descriptors available */
    2454         [ #  # ]:          0 :                 if (rxq->drop_en)
    2455                 :          0 :                         srrctl |= E1000_SRRCTL_DROP_EN;
    2456                 :            : 
    2457         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_SRRCTL(rxq->reg_idx), srrctl);
    2458                 :            : 
    2459                 :            :                 /* Enable this RX queue. */
    2460         [ #  # ]:          0 :                 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(rxq->reg_idx));
    2461                 :            :                 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
    2462                 :          0 :                 rxdctl &= 0xFFF00000;
    2463                 :          0 :                 rxdctl |= (rxq->pthresh & 0x1F);
    2464                 :          0 :                 rxdctl |= ((rxq->hthresh & 0x1F) << 8);
    2465                 :          0 :                 rxdctl |= ((rxq->wthresh & 0x1F) << 16);
    2466         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RXDCTL(rxq->reg_idx), rxdctl);
    2467                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    2468                 :            :         }
    2469                 :            : 
    2470         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
    2471         [ #  # ]:          0 :                 if (!dev->data->scattered_rx)
    2472                 :          0 :                         PMD_INIT_LOG(DEBUG, "forcing scatter mode");
    2473                 :          0 :                 dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2474                 :          0 :                 dev->data->scattered_rx = 1;
    2475                 :            :         }
    2476                 :            : 
    2477                 :            :         /*
    2478                 :            :          * Setup BSIZE field of RCTL register, if needed.
    2479                 :            :          * Buffer sizes >= 1024 are not [supposed to be] setup in the RCTL
    2480                 :            :          * register, since the code above configures the SRRCTL register of
    2481                 :            :          * the RX queue in such a case.
    2482                 :            :          * All configurable sizes are:
    2483                 :            :          * 16384: rctl |= (E1000_RCTL_SZ_16384 | E1000_RCTL_BSEX);
    2484                 :            :          *  8192: rctl |= (E1000_RCTL_SZ_8192  | E1000_RCTL_BSEX);
    2485                 :            :          *  4096: rctl |= (E1000_RCTL_SZ_4096  | E1000_RCTL_BSEX);
    2486                 :            :          *  2048: rctl |= E1000_RCTL_SZ_2048;
    2487                 :            :          *  1024: rctl |= E1000_RCTL_SZ_1024;
    2488                 :            :          *   512: rctl |= E1000_RCTL_SZ_512;
    2489                 :            :          *   256: rctl |= E1000_RCTL_SZ_256;
    2490                 :            :          */
    2491         [ #  # ]:          0 :         if (rctl_bsize > 0) {
    2492         [ #  # ]:          0 :                 if (rctl_bsize >= 512) /* 512 <= buf_size < 1024 - use 512 */
    2493                 :          0 :                         rctl |= E1000_RCTL_SZ_512;
    2494                 :            :                 else /* 256 <= buf_size < 512 - use 256 */
    2495                 :          0 :                         rctl |= E1000_RCTL_SZ_256;
    2496                 :            :         }
    2497                 :            : 
    2498                 :            :         /*
    2499                 :            :          * Configure RSS if device configured with multiple RX queues.
    2500                 :            :          */
    2501                 :          0 :         igb_dev_mq_rx_configure(dev);
    2502                 :            : 
    2503                 :            :         /* Update the rctl since igb_dev_mq_rx_configure may change its value */
    2504                 :          0 :         rctl |= E1000_READ_REG(hw, E1000_RCTL);
    2505                 :            : 
    2506                 :            :         /*
    2507                 :            :          * Setup the Checksum Register.
    2508                 :            :          * Receive Full-Packet Checksum Offload is mutually exclusive with RSS.
    2509                 :            :          */
    2510                 :          0 :         rxcsum = E1000_READ_REG(hw, E1000_RXCSUM);
    2511                 :            :         rxcsum |= E1000_RXCSUM_PCSD;
    2512                 :            : 
    2513                 :            :         /* Enable both L3/L4 rx checksum offload */
    2514         [ #  # ]:          0 :         if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM)
    2515                 :          0 :                 rxcsum |= E1000_RXCSUM_IPOFL;
    2516                 :            :         else
    2517                 :          0 :                 rxcsum &= ~E1000_RXCSUM_IPOFL;
    2518         [ #  # ]:          0 :         if (rxmode->offloads &
    2519                 :            :                 (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM))
    2520                 :          0 :                 rxcsum |= E1000_RXCSUM_TUOFL;
    2521                 :            :         else
    2522                 :          0 :                 rxcsum &= ~E1000_RXCSUM_TUOFL;
    2523         [ #  # ]:          0 :         if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
    2524                 :          0 :                 rxcsum |= E1000_RXCSUM_CRCOFL;
    2525                 :            :         else
    2526                 :          0 :                 rxcsum &= ~E1000_RXCSUM_CRCOFL;
    2527                 :            : 
    2528                 :          0 :         E1000_WRITE_REG(hw, E1000_RXCSUM, rxcsum);
    2529                 :            : 
    2530                 :            :         /* Setup the Receive Control Register. */
    2531         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
    2532                 :          0 :                 rctl &= ~E1000_RCTL_SECRC; /* Do not Strip Ethernet CRC. */
    2533                 :            : 
    2534                 :            :                 /* clear STRCRC bit in all queues */
    2535         [ #  # ]:          0 :                 if (hw->mac.type == e1000_i350 ||
    2536         [ #  # ]:          0 :                     hw->mac.type == e1000_i210 ||
    2537         [ #  # ]:          0 :                     hw->mac.type == e1000_i211 ||
    2538                 :            :                     hw->mac.type == e1000_i354) {
    2539         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2540                 :          0 :                                 rxq = dev->data->rx_queues[i];
    2541                 :          0 :                                 uint32_t dvmolr = E1000_READ_REG(hw,
    2542                 :            :                                         E1000_DVMOLR(rxq->reg_idx));
    2543                 :          0 :                                 dvmolr &= ~E1000_DVMOLR_STRCRC;
    2544                 :          0 :                                 E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
    2545                 :            :                         }
    2546                 :            :                 }
    2547                 :            :         } else {
    2548                 :          0 :                 rctl |= E1000_RCTL_SECRC; /* Strip Ethernet CRC. */
    2549                 :            : 
    2550                 :            :                 /* set STRCRC bit in all queues */
    2551         [ #  # ]:          0 :                 if (hw->mac.type == e1000_i350 ||
    2552         [ #  # ]:          0 :                     hw->mac.type == e1000_i210 ||
    2553         [ #  # ]:          0 :                     hw->mac.type == e1000_i211 ||
    2554                 :            :                     hw->mac.type == e1000_i354) {
    2555         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2556                 :          0 :                                 rxq = dev->data->rx_queues[i];
    2557                 :          0 :                                 uint32_t dvmolr = E1000_READ_REG(hw,
    2558                 :            :                                         E1000_DVMOLR(rxq->reg_idx));
    2559                 :          0 :                                 dvmolr |= E1000_DVMOLR_STRCRC;
    2560                 :          0 :                                 E1000_WRITE_REG(hw, E1000_DVMOLR(rxq->reg_idx), dvmolr);
    2561                 :            :                         }
    2562                 :            :                 }
    2563                 :            :         }
    2564                 :            : 
    2565                 :          0 :         rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
    2566                 :          0 :         rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
    2567                 :            :                 E1000_RCTL_RDMTS_HALF |
    2568                 :          0 :                 (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
    2569                 :            : 
    2570                 :            :         /* Make sure VLAN Filters are off. */
    2571         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_VMDQ_ONLY)
    2572                 :          0 :                 rctl &= ~E1000_RCTL_VFE;
    2573                 :            :         /* Don't store bad packets. */
    2574                 :          0 :         rctl &= ~E1000_RCTL_SBP;
    2575                 :            : 
    2576                 :            :         /* Enable Receives. */
    2577                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    2578                 :            : 
    2579                 :            :         /*
    2580                 :            :          * Setup the HW Rx Head and Tail Descriptor Pointers.
    2581                 :            :          * This needs to be done after enable.
    2582                 :            :          */
    2583         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2584                 :          0 :                 rxq = dev->data->rx_queues[i];
    2585         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDH(rxq->reg_idx), 0);
    2586         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDT(rxq->reg_idx), rxq->nb_rx_desc - 1);
    2587                 :            :         }
    2588                 :            : 
    2589                 :            :         return 0;
    2590                 :            : }
    2591                 :            : 
    2592                 :            : /*********************************************************************
    2593                 :            :  *
    2594                 :            :  *  Enable transmit unit.
    2595                 :            :  *
    2596                 :            :  **********************************************************************/
    2597                 :            : void
    2598                 :          0 : eth_igb_tx_init(struct rte_eth_dev *dev)
    2599                 :            : {
    2600                 :            :         struct e1000_hw     *hw;
    2601                 :            :         struct igb_tx_queue *txq;
    2602                 :          0 :         uint64_t offloads = dev->data->dev_conf.txmode.offloads;
    2603                 :            :         uint32_t tctl;
    2604                 :            :         uint32_t txdctl;
    2605                 :            :         uint16_t i;
    2606                 :            :         int err;
    2607                 :            : 
    2608                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2609                 :            : 
    2610                 :            :         /* Setup the Base and Length of the Tx Descriptor Rings. */
    2611         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2612                 :            :                 uint64_t bus_addr;
    2613                 :          0 :                 txq = dev->data->tx_queues[i];
    2614                 :          0 :                 bus_addr = txq->tx_ring_phys_addr;
    2615                 :            : 
    2616         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDLEN(txq->reg_idx),
    2617                 :            :                                 txq->nb_tx_desc *
    2618                 :            :                                 sizeof(union e1000_adv_tx_desc));
    2619         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDBAH(txq->reg_idx),
    2620                 :            :                                 (uint32_t)(bus_addr >> 32));
    2621         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDBAL(txq->reg_idx), (uint32_t)bus_addr);
    2622                 :            : 
    2623                 :            :                 /* Setup the HW Tx Head and Tail descriptor pointers. */
    2624         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDT(txq->reg_idx), 0);
    2625         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDH(txq->reg_idx), 0);
    2626                 :            : 
    2627                 :            :                 /* Setup Transmit threshold registers. */
    2628         [ #  # ]:          0 :                 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(txq->reg_idx));
    2629                 :          0 :                 txdctl |= txq->pthresh & 0x1F;
    2630                 :          0 :                 txdctl |= ((txq->hthresh & 0x1F) << 8);
    2631                 :          0 :                 txdctl |= ((txq->wthresh & 0x1F) << 16);
    2632                 :          0 :                 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
    2633         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TXDCTL(txq->reg_idx), txdctl);
    2634                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    2635                 :            :         }
    2636                 :            : 
    2637         [ #  # ]:          0 :         if (offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
    2638                 :          0 :                 err = rte_mbuf_dyn_tx_timestamp_register(
    2639                 :            :                         &igb_tx_timestamp_dynfield_offset,
    2640                 :            :                         &igb_tx_timestamp_dynflag);
    2641         [ #  # ]:          0 :                 if (err)
    2642                 :          0 :                         PMD_DRV_LOG(ERR, "Failed to register tx timestamp dynamic field");
    2643                 :            :         }
    2644                 :            : 
    2645                 :            :         /* Program the Transmit Control Register. */
    2646                 :          0 :         tctl = E1000_READ_REG(hw, E1000_TCTL);
    2647                 :          0 :         tctl &= ~E1000_TCTL_CT;
    2648                 :          0 :         tctl |= (E1000_TCTL_PSP | E1000_TCTL_RTLC | E1000_TCTL_EN |
    2649                 :            :                  (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT));
    2650                 :            : 
    2651                 :          0 :         e1000_config_collision_dist(hw);
    2652                 :            : 
    2653                 :            :         /* This write will effectively turn on the transmit unit. */
    2654                 :          0 :         E1000_WRITE_REG(hw, E1000_TCTL, tctl);
    2655                 :          0 : }
    2656                 :            : 
    2657                 :            : /*********************************************************************
    2658                 :            :  *
    2659                 :            :  *  Enable VF receive unit.
    2660                 :            :  *
    2661                 :            :  **********************************************************************/
    2662                 :            : int
    2663                 :          0 : eth_igbvf_rx_init(struct rte_eth_dev *dev)
    2664                 :            : {
    2665                 :            :         struct e1000_hw     *hw;
    2666                 :            :         struct igb_rx_queue *rxq;
    2667                 :            :         uint32_t srrctl;
    2668                 :            :         uint16_t buf_size;
    2669                 :            :         uint16_t rctl_bsize;
    2670                 :            :         uint32_t max_len;
    2671                 :            :         uint16_t i;
    2672                 :            :         int ret;
    2673                 :            : 
    2674                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2675                 :            : 
    2676                 :            :         /* setup MTU */
    2677                 :          0 :         max_len = dev->data->mtu + E1000_ETH_OVERHEAD;
    2678                 :          0 :         e1000_rlpml_set_vf(hw, (uint16_t)(max_len + VLAN_TAG_SIZE));
    2679                 :            : 
    2680                 :            :         /* Configure and enable each RX queue. */
    2681                 :            :         rctl_bsize = 0;
    2682                 :          0 :         dev->rx_pkt_burst = eth_igb_recv_pkts;
    2683         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2684                 :            :                 uint64_t bus_addr;
    2685                 :            :                 uint32_t rxdctl;
    2686                 :            : 
    2687                 :          0 :                 rxq = dev->data->rx_queues[i];
    2688                 :            : 
    2689                 :          0 :                 rxq->flags = 0;
    2690                 :            :                 /*
    2691                 :            :                  * i350VF LB vlan packets have vlan tags byte swapped.
    2692                 :            :                  */
    2693         [ #  # ]:          0 :                 if (hw->mac.type == e1000_vfadapt_i350) {
    2694                 :          0 :                         rxq->flags |= IGB_RXQ_FLAG_LB_BSWAP_VLAN;
    2695                 :          0 :                         PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap required");
    2696                 :            :                 } else {
    2697                 :          0 :                         PMD_INIT_LOG(DEBUG, "IGB rx vlan bswap not required");
    2698                 :            :                 }
    2699                 :            : 
    2700                 :            :                 /* Allocate buffers for descriptor rings and set up queue */
    2701                 :          0 :                 ret = igb_alloc_rx_queue_mbufs(rxq);
    2702         [ #  # ]:          0 :                 if (ret)
    2703                 :          0 :                         return ret;
    2704                 :            : 
    2705                 :          0 :                 bus_addr = rxq->rx_ring_phys_addr;
    2706         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDLEN(i),
    2707                 :            :                                 rxq->nb_rx_desc *
    2708                 :            :                                 sizeof(union e1000_adv_rx_desc));
    2709         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDBAH(i),
    2710                 :            :                                 (uint32_t)(bus_addr >> 32));
    2711         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDBAL(i), (uint32_t)bus_addr);
    2712                 :            : 
    2713                 :            :                 srrctl = E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
    2714                 :            : 
    2715                 :            :                 /*
    2716                 :            :                  * Configure RX buffer size.
    2717                 :            :                  */
    2718         [ #  # ]:          0 :                 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mb_pool) -
    2719                 :            :                         RTE_PKTMBUF_HEADROOM);
    2720         [ #  # ]:          0 :                 if (buf_size >= 1024) {
    2721                 :            :                         /*
    2722                 :            :                          * Configure the BSIZEPACKET field of the SRRCTL
    2723                 :            :                          * register of the queue.
    2724                 :            :                          * Value is in 1 KB resolution, from 1 KB to 127 KB.
    2725                 :            :                          * If this field is equal to 0b, then RCTL.BSIZE
    2726                 :            :                          * determines the RX packet buffer size.
    2727                 :            :                          */
    2728                 :          0 :                         srrctl |= ((buf_size >> E1000_SRRCTL_BSIZEPKT_SHIFT) &
    2729                 :            :                                    E1000_SRRCTL_BSIZEPKT_MASK);
    2730                 :          0 :                         buf_size = (uint16_t) ((srrctl &
    2731                 :            :                                                 E1000_SRRCTL_BSIZEPKT_MASK) <<
    2732                 :            :                                                E1000_SRRCTL_BSIZEPKT_SHIFT);
    2733                 :            : 
    2734                 :            :                         /* It adds dual VLAN length for supporting dual VLAN */
    2735         [ #  # ]:          0 :                         if ((max_len + 2 * VLAN_TAG_SIZE) > buf_size) {
    2736         [ #  # ]:          0 :                                 if (!dev->data->scattered_rx)
    2737                 :          0 :                                         PMD_INIT_LOG(DEBUG,
    2738                 :            :                                                      "forcing scatter mode");
    2739                 :          0 :                                 dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2740                 :          0 :                                 dev->data->scattered_rx = 1;
    2741                 :            :                         }
    2742                 :            :                 } else {
    2743                 :            :                         /*
    2744                 :            :                          * Use BSIZE field of the device RCTL register.
    2745                 :            :                          */
    2746                 :            :                         if ((rctl_bsize == 0) || (rctl_bsize > buf_size))
    2747                 :            :                                 rctl_bsize = buf_size;
    2748         [ #  # ]:          0 :                         if (!dev->data->scattered_rx)
    2749                 :          0 :                                 PMD_INIT_LOG(DEBUG, "forcing scatter mode");
    2750                 :          0 :                         dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2751                 :          0 :                         dev->data->scattered_rx = 1;
    2752                 :            :                 }
    2753                 :            : 
    2754                 :            :                 /* Set if packets are dropped when no descriptors available */
    2755         [ #  # ]:          0 :                 if (rxq->drop_en)
    2756                 :          0 :                         srrctl |= E1000_SRRCTL_DROP_EN;
    2757                 :            : 
    2758         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_SRRCTL(i), srrctl);
    2759                 :            : 
    2760                 :            :                 /* Enable this RX queue. */
    2761         [ #  # ]:          0 :                 rxdctl = E1000_READ_REG(hw, E1000_RXDCTL(i));
    2762                 :            :                 rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
    2763                 :          0 :                 rxdctl &= 0xFFF00000;
    2764                 :          0 :                 rxdctl |= (rxq->pthresh & 0x1F);
    2765                 :          0 :                 rxdctl |= ((rxq->hthresh & 0x1F) << 8);
    2766         [ #  # ]:          0 :                 if (hw->mac.type == e1000_vfadapt) {
    2767                 :            :                         /*
    2768                 :            :                          * Workaround of 82576 VF Erratum
    2769                 :            :                          * force set WTHRESH to 1
    2770                 :            :                          * to avoid Write-Back not triggered sometimes
    2771                 :            :                          */
    2772                 :          0 :                         rxdctl |= 0x10000;
    2773                 :          0 :                         PMD_INIT_LOG(DEBUG, "Force set RX WTHRESH to 1 !");
    2774                 :            :                 }
    2775                 :            :                 else
    2776                 :          0 :                         rxdctl |= ((rxq->wthresh & 0x1F) << 16);
    2777                 :          0 :                 E1000_WRITE_REG(hw, E1000_RXDCTL(i), rxdctl);
    2778                 :            : 
    2779                 :          0 :                 dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    2780                 :            :         }
    2781                 :            : 
    2782         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
    2783         [ #  # ]:          0 :                 if (!dev->data->scattered_rx)
    2784                 :          0 :                         PMD_INIT_LOG(DEBUG, "forcing scatter mode");
    2785                 :          0 :                 dev->rx_pkt_burst = eth_igb_recv_scattered_pkts;
    2786                 :          0 :                 dev->data->scattered_rx = 1;
    2787                 :            :         }
    2788                 :            : 
    2789                 :            :         /*
    2790                 :            :          * Setup the HW Rx Head and Tail Descriptor Pointers.
    2791                 :            :          * This needs to be done after enable.
    2792                 :            :          */
    2793         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2794                 :          0 :                 rxq = dev->data->rx_queues[i];
    2795         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDH(i), 0);
    2796         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_RDT(i), rxq->nb_rx_desc - 1);
    2797                 :            :         }
    2798                 :            : 
    2799                 :            :         return 0;
    2800                 :            : }
    2801                 :            : 
    2802                 :            : /*********************************************************************
    2803                 :            :  *
    2804                 :            :  *  Enable VF transmit unit.
    2805                 :            :  *
    2806                 :            :  **********************************************************************/
    2807                 :            : void
    2808                 :          0 : eth_igbvf_tx_init(struct rte_eth_dev *dev)
    2809                 :            : {
    2810                 :            :         struct e1000_hw     *hw;
    2811                 :            :         struct igb_tx_queue *txq;
    2812                 :            :         uint32_t txdctl;
    2813                 :            :         uint16_t i;
    2814                 :            : 
    2815                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2816                 :            : 
    2817                 :            :         /* Setup the Base and Length of the Tx Descriptor Rings. */
    2818         [ #  # ]:          0 :         for (i = 0; i < dev->data->nb_tx_queues; i++) {
    2819                 :            :                 uint64_t bus_addr;
    2820                 :            : 
    2821                 :          0 :                 txq = dev->data->tx_queues[i];
    2822                 :          0 :                 bus_addr = txq->tx_ring_phys_addr;
    2823         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDLEN(i),
    2824                 :            :                                 txq->nb_tx_desc *
    2825                 :            :                                 sizeof(union e1000_adv_tx_desc));
    2826         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDBAH(i),
    2827                 :            :                                 (uint32_t)(bus_addr >> 32));
    2828         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDBAL(i), (uint32_t)bus_addr);
    2829                 :            : 
    2830                 :            :                 /* Setup the HW Tx Head and Tail descriptor pointers. */
    2831         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDT(i), 0);
    2832         [ #  # ]:          0 :                 E1000_WRITE_REG(hw, E1000_TDH(i), 0);
    2833                 :            : 
    2834                 :            :                 /* Setup Transmit threshold registers. */
    2835         [ #  # ]:          0 :                 txdctl = E1000_READ_REG(hw, E1000_TXDCTL(i));
    2836                 :          0 :                 txdctl |= txq->pthresh & 0x1F;
    2837                 :          0 :                 txdctl |= ((txq->hthresh & 0x1F) << 8);
    2838         [ #  # ]:          0 :                 if (hw->mac.type == e1000_82576) {
    2839                 :            :                         /*
    2840                 :            :                          * Workaround of 82576 VF Erratum
    2841                 :            :                          * force set WTHRESH to 1
    2842                 :            :                          * to avoid Write-Back not triggered sometimes
    2843                 :            :                          */
    2844                 :          0 :                         txdctl |= 0x10000;
    2845                 :          0 :                         PMD_INIT_LOG(DEBUG, "Force set TX WTHRESH to 1 !");
    2846                 :            :                 }
    2847                 :            :                 else
    2848                 :          0 :                         txdctl |= ((txq->wthresh & 0x1F) << 16);
    2849                 :          0 :                 txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
    2850                 :          0 :                 E1000_WRITE_REG(hw, E1000_TXDCTL(i), txdctl);
    2851                 :            : 
    2852                 :          0 :                 dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
    2853                 :            :         }
    2854                 :            : 
    2855                 :          0 : }
    2856                 :            : 
    2857                 :            : void
    2858                 :          0 : igb_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    2859                 :            :         struct rte_eth_rxq_info *qinfo)
    2860                 :            : {
    2861                 :            :         struct igb_rx_queue *rxq;
    2862                 :            : 
    2863                 :          0 :         rxq = dev->data->rx_queues[queue_id];
    2864                 :            : 
    2865                 :          0 :         qinfo->mp = rxq->mb_pool;
    2866                 :          0 :         qinfo->scattered_rx = dev->data->scattered_rx;
    2867                 :          0 :         qinfo->nb_desc = rxq->nb_rx_desc;
    2868                 :            : 
    2869                 :          0 :         qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
    2870                 :          0 :         qinfo->conf.rx_drop_en = rxq->drop_en;
    2871                 :          0 :         qinfo->conf.offloads = rxq->offloads;
    2872                 :          0 : }
    2873                 :            : 
    2874                 :            : void
    2875                 :          0 : igb_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
    2876                 :            :         struct rte_eth_txq_info *qinfo)
    2877                 :            : {
    2878                 :            :         struct igb_tx_queue *txq;
    2879                 :            : 
    2880                 :          0 :         txq = dev->data->tx_queues[queue_id];
    2881                 :            : 
    2882                 :          0 :         qinfo->nb_desc = txq->nb_tx_desc;
    2883                 :            : 
    2884                 :          0 :         qinfo->conf.tx_thresh.pthresh = txq->pthresh;
    2885                 :          0 :         qinfo->conf.tx_thresh.hthresh = txq->hthresh;
    2886                 :          0 :         qinfo->conf.tx_thresh.wthresh = txq->wthresh;
    2887                 :          0 :         qinfo->conf.offloads = txq->offloads;
    2888                 :          0 : }
    2889                 :            : 
    2890                 :            : int
    2891                 :          0 : igb_rss_conf_init(struct rte_eth_dev *dev,
    2892                 :            :                   struct igb_rte_flow_rss_conf *out,
    2893                 :            :                   const struct rte_flow_action_rss *in)
    2894                 :            : {
    2895                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2896                 :            : 
    2897         [ #  # ]:          0 :         if (in->key_len > RTE_DIM(out->key) ||
    2898         [ #  # ]:          0 :             ((hw->mac.type == e1000_82576) &&
    2899   [ #  #  #  # ]:          0 :              (in->queue_num > IGB_MAX_RX_QUEUE_NUM_82576)) ||
    2900                 :          0 :             ((hw->mac.type != e1000_82576) &&
    2901         [ #  # ]:          0 :              (in->queue_num > IGB_MAX_RX_QUEUE_NUM)))
    2902                 :            :                 return -EINVAL;
    2903                 :          0 :         out->conf = (struct rte_flow_action_rss){
    2904                 :          0 :                 .func = in->func,
    2905                 :          0 :                 .level = in->level,
    2906                 :          0 :                 .types = in->types,
    2907                 :            :                 .key_len = in->key_len,
    2908                 :          0 :                 .queue_num = in->queue_num,
    2909                 :          0 :                 .key = memcpy(out->key, in->key, in->key_len),
    2910                 :          0 :                 .queue = memcpy(out->queue, in->queue,
    2911                 :          0 :                                 sizeof(*in->queue) * in->queue_num),
    2912                 :            :         };
    2913                 :          0 :         return 0;
    2914                 :            : }
    2915                 :            : 
    2916                 :            : int
    2917                 :          0 : igb_action_rss_same(const struct rte_flow_action_rss *comp,
    2918                 :            :                     const struct rte_flow_action_rss *with)
    2919                 :            : {
    2920                 :          0 :         return (comp->func == with->func &&
    2921                 :          0 :                 comp->level == with->level &&
    2922         [ #  # ]:          0 :                 comp->types == with->types &&
    2923         [ #  # ]:          0 :                 comp->key_len == with->key_len &&
    2924                 :          0 :                 comp->queue_num == with->queue_num &&
    2925   [ #  #  #  # ]:          0 :                 !memcmp(comp->key, with->key, with->key_len) &&
    2926                 :          0 :                 !memcmp(comp->queue, with->queue,
    2927         [ #  # ]:          0 :                         sizeof(*with->queue) * with->queue_num));
    2928                 :            : }
    2929                 :            : 
    2930                 :            : int
    2931                 :          0 : igb_config_rss_filter(struct rte_eth_dev *dev,
    2932                 :            :                 struct igb_rte_flow_rss_conf *conf, bool add)
    2933                 :            : {
    2934                 :            :         uint32_t shift;
    2935                 :            :         uint16_t i, j;
    2936                 :          0 :         struct rte_eth_rss_conf rss_conf = {
    2937                 :          0 :                 .rss_key = conf->conf.key_len ?
    2938         [ #  # ]:          0 :                         (void *)(uintptr_t)conf->conf.key : NULL,
    2939                 :            :                 .rss_key_len = conf->conf.key_len,
    2940                 :          0 :                 .rss_hf = conf->conf.types,
    2941                 :            :         };
    2942                 :            :         struct e1000_filter_info *filter_info =
    2943                 :          0 :                 E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    2944                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2945                 :            : 
    2946                 :            :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2947                 :            : 
    2948         [ #  # ]:          0 :         if (!add) {
    2949         [ #  # ]:          0 :                 if (igb_action_rss_same(&filter_info->rss_info.conf,
    2950                 :          0 :                                         &conf->conf)) {
    2951                 :            :                         igb_rss_disable(dev);
    2952                 :          0 :                         memset(&filter_info->rss_info, 0,
    2953                 :            :                                 sizeof(struct igb_rte_flow_rss_conf));
    2954                 :          0 :                         return 0;
    2955                 :            :                 }
    2956                 :            :                 return -EINVAL;
    2957                 :            :         }
    2958                 :            : 
    2959         [ #  # ]:          0 :         if (filter_info->rss_info.conf.queue_num)
    2960                 :            :                 return -EINVAL;
    2961                 :            : 
    2962                 :            :         /* Fill in redirection table. */
    2963         [ #  # ]:          0 :         shift = (hw->mac.type == e1000_82575) ? 6 : 0;
    2964         [ #  # ]:          0 :         for (i = 0, j = 0; i < 128; i++, j++) {
    2965                 :            :                 union e1000_reta {
    2966                 :            :                         uint32_t dword;
    2967                 :            :                         uint8_t  bytes[4];
    2968                 :            :                 } reta;
    2969                 :            :                 uint8_t q_idx;
    2970                 :            : 
    2971         [ #  # ]:          0 :                 if (j == conf->conf.queue_num)
    2972                 :            :                         j = 0;
    2973                 :          0 :                 q_idx = conf->conf.queue[j];
    2974                 :          0 :                 reta.bytes[i & 3] = (uint8_t)(q_idx << shift);
    2975         [ #  # ]:          0 :                 if ((i & 3) == 3)
    2976                 :          0 :                         E1000_WRITE_REG(hw, E1000_RETA(i >> 2), reta.dword);
    2977                 :            :         }
    2978                 :            : 
    2979                 :            :         /* Configure the RSS key and the RSS protocols used to compute
    2980                 :            :          * the RSS hash of input packets.
    2981                 :            :          */
    2982         [ #  # ]:          0 :         if ((rss_conf.rss_hf & IGB_RSS_OFFLOAD_ALL) == 0) {
    2983                 :            :                 igb_rss_disable(dev);
    2984                 :          0 :                 return 0;
    2985                 :            :         }
    2986         [ #  # ]:          0 :         if (rss_conf.rss_key == NULL)
    2987                 :          0 :                 rss_conf.rss_key = rss_intel_key; /* Default hash key */
    2988                 :          0 :         igb_hw_rss_hash_set(hw, &rss_conf);
    2989                 :            : 
    2990         [ #  # ]:          0 :         if (igb_rss_conf_init(dev, &filter_info->rss_info, &conf->conf))
    2991                 :          0 :                 return -EINVAL;
    2992                 :            : 
    2993                 :            :         return 0;
    2994                 :            : }

Generated by: LCOV version 1.14