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

Generated by: LCOV version 1.14