LCOV - code coverage report
Current view: top level - drivers/net/intel/ixgbe - ixgbe_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 4 3198 0.1 %
Date: 2025-03-01 20:23:48 Functions: 4 196 2.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 1353 0.1 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <sys/queue.h>
       6                 :            : #include <stdio.h>
       7                 :            : #include <errno.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <string.h>
      10                 :            : #include <unistd.h>
      11                 :            : #include <stdarg.h>
      12                 :            : #include <inttypes.h>
      13                 :            : #include <rte_string_fns.h>
      14                 :            : #include <rte_byteorder.h>
      15                 :            : #include <rte_common.h>
      16                 :            : #include <rte_cycles.h>
      17                 :            : 
      18                 :            : #include <rte_interrupts.h>
      19                 :            : #include <rte_log.h>
      20                 :            : #include <rte_debug.h>
      21                 :            : #include <rte_pci.h>
      22                 :            : #include <bus_pci_driver.h>
      23                 :            : #include <rte_branch_prediction.h>
      24                 :            : #include <rte_memory.h>
      25                 :            : #include <rte_kvargs.h>
      26                 :            : #include <rte_eal.h>
      27                 :            : #include <rte_alarm.h>
      28                 :            : #include <rte_ether.h>
      29                 :            : #include <ethdev_driver.h>
      30                 :            : #include <ethdev_pci.h>
      31                 :            : #include <rte_malloc.h>
      32                 :            : #include <rte_random.h>
      33                 :            : #include <dev_driver.h>
      34                 :            : #include <rte_hash_crc.h>
      35                 :            : #ifdef RTE_LIB_SECURITY
      36                 :            : #include <rte_security_driver.h>
      37                 :            : #endif
      38                 :            : #include <rte_os_shim.h>
      39                 :            : 
      40                 :            : #include "ixgbe_logs.h"
      41                 :            : #include "base/ixgbe_api.h"
      42                 :            : #include "base/ixgbe_vf.h"
      43                 :            : #include "base/ixgbe_common.h"
      44                 :            : #include "ixgbe_ethdev.h"
      45                 :            : #include "ixgbe_bypass.h"
      46                 :            : #include "ixgbe_rxtx.h"
      47                 :            : #include "base/ixgbe_type.h"
      48                 :            : #include "base/ixgbe_phy.h"
      49                 :            : #include "base/ixgbe_osdep.h"
      50                 :            : #include "ixgbe_regs.h"
      51                 :            : 
      52                 :            : /*
      53                 :            :  * High threshold controlling when to start sending XOFF frames. Must be at
      54                 :            :  * least 8 bytes less than receive packet buffer size. This value is in units
      55                 :            :  * of 1024 bytes.
      56                 :            :  */
      57                 :            : #define IXGBE_FC_HI    0x80
      58                 :            : 
      59                 :            : /*
      60                 :            :  * Low threshold controlling when to start sending XON frames. This value is
      61                 :            :  * in units of 1024 bytes.
      62                 :            :  */
      63                 :            : #define IXGBE_FC_LO    0x40
      64                 :            : 
      65                 :            : /* Timer value included in XOFF frames. */
      66                 :            : #define IXGBE_FC_PAUSE 0x680
      67                 :            : 
      68                 :            : /*Default value of Max Rx Queue*/
      69                 :            : #define IXGBE_MAX_RX_QUEUE_NUM 128
      70                 :            : 
      71                 :            : #define IXGBE_LINK_DOWN_CHECK_TIMEOUT 4000 /* ms */
      72                 :            : #define IXGBE_LINK_UP_CHECK_TIMEOUT   1000 /* ms */
      73                 :            : #define IXGBE_VMDQ_NUM_UC_MAC         4096 /* Maximum nb. of UC MAC addr. */
      74                 :            : 
      75                 :            : #define IXGBE_MMW_SIZE_DEFAULT        0x4
      76                 :            : #define IXGBE_MMW_SIZE_JUMBO_FRAME    0x14
      77                 :            : #define IXGBE_MAX_RING_DESC           8192 /* replicate define from rxtx */
      78                 :            : 
      79                 :            : /*
      80                 :            :  *  Default values for RX/TX configuration
      81                 :            :  */
      82                 :            : #define IXGBE_DEFAULT_RX_FREE_THRESH  32
      83                 :            : #define IXGBE_DEFAULT_RX_PTHRESH      8
      84                 :            : #define IXGBE_DEFAULT_RX_HTHRESH      8
      85                 :            : #define IXGBE_DEFAULT_RX_WTHRESH      0
      86                 :            : 
      87                 :            : #define IXGBE_DEFAULT_TX_FREE_THRESH  32
      88                 :            : #define IXGBE_DEFAULT_TX_PTHRESH      32
      89                 :            : #define IXGBE_DEFAULT_TX_HTHRESH      0
      90                 :            : #define IXGBE_DEFAULT_TX_WTHRESH      0
      91                 :            : #define IXGBE_DEFAULT_TX_RSBIT_THRESH 32
      92                 :            : 
      93                 :            : /* Bit shift and mask */
      94                 :            : #define IXGBE_4_BIT_WIDTH  (CHAR_BIT / 2)
      95                 :            : #define IXGBE_4_BIT_MASK   RTE_LEN2MASK(IXGBE_4_BIT_WIDTH, uint8_t)
      96                 :            : #define IXGBE_8_BIT_WIDTH  CHAR_BIT
      97                 :            : #define IXGBE_8_BIT_MASK   UINT8_MAX
      98                 :            : 
      99                 :            : #define IXGBEVF_PMD_NAME "rte_ixgbevf_pmd" /* PMD name */
     100                 :            : 
     101                 :            : #define IXGBE_QUEUE_STAT_COUNTERS (sizeof(hw_stats->qprc) / sizeof(hw_stats->qprc[0]))
     102                 :            : 
     103                 :            : /* Additional timesync values. */
     104                 :            : #define NSEC_PER_SEC             1000000000L
     105                 :            : #define IXGBE_INCVAL_10GB        0x66666666
     106                 :            : #define IXGBE_INCVAL_1GB         0x40000000
     107                 :            : #define IXGBE_INCVAL_100         0x50000000
     108                 :            : #define IXGBE_INCVAL_SHIFT_10GB  28
     109                 :            : #define IXGBE_INCVAL_SHIFT_1GB   24
     110                 :            : #define IXGBE_INCVAL_SHIFT_100   21
     111                 :            : #define IXGBE_INCVAL_SHIFT_82599 7
     112                 :            : #define IXGBE_INCPER_SHIFT_82599 24
     113                 :            : 
     114                 :            : #define IXGBE_CYCLECOUNTER_MASK   0xffffffffffffffffULL
     115                 :            : 
     116                 :            : #define IXGBE_VT_CTL_POOLING_MODE_MASK         0x00030000
     117                 :            : #define IXGBE_VT_CTL_POOLING_MODE_ETAG         0x00010000
     118                 :            : #define IXGBE_ETAG_ETYPE                       0x00005084
     119                 :            : #define IXGBE_ETAG_ETYPE_MASK                  0x0000ffff
     120                 :            : #define IXGBE_ETAG_ETYPE_VALID                 0x80000000
     121                 :            : #define IXGBE_RAH_ADTYPE                       0x40000000
     122                 :            : #define IXGBE_RAL_ETAG_FILTER_MASK             0x00003fff
     123                 :            : #define IXGBE_VMVIR_TAGA_MASK                  0x18000000
     124                 :            : #define IXGBE_VMVIR_TAGA_ETAG_INSERT           0x08000000
     125                 :            : #define IXGBE_VMTIR(_i) (0x00017000 + ((_i) * 4)) /* 64 of these (0-63) */
     126                 :            : #define IXGBE_QDE_STRIP_TAG                    0x00000004
     127                 :            : #define IXGBE_VTEICR_MASK                      0x07
     128                 :            : 
     129                 :            : #define IXGBE_EXVET_VET_EXT_SHIFT              16
     130                 :            : #define IXGBE_DMATXCTL_VT_MASK                 0xFFFF0000
     131                 :            : 
     132                 :            : #define IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE  "fiber_sdp3_no_tx_disable"
     133                 :            : 
     134                 :            : static const char * const ixgbe_valid_arguments[] = {
     135                 :            :         IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE,
     136                 :            :         NULL
     137                 :            : };
     138                 :            : 
     139                 :            : #define IXGBEVF_DEVARG_PFLINK_FULLCHK           "pflink_fullchk"
     140                 :            : 
     141                 :            : static const char * const ixgbevf_valid_arguments[] = {
     142                 :            :         IXGBEVF_DEVARG_PFLINK_FULLCHK,
     143                 :            :         NULL
     144                 :            : };
     145                 :            : 
     146                 :            : static int eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params);
     147                 :            : static int eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev);
     148                 :            : static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev);
     149                 :            : static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev);
     150                 :            : static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev);
     151                 :            : static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev);
     152                 :            : static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev);
     153                 :            : static int ixgbe_dev_configure(struct rte_eth_dev *dev);
     154                 :            : static int ixgbe_dev_start(struct rte_eth_dev *dev);
     155                 :            : static int ixgbe_dev_stop(struct rte_eth_dev *dev);
     156                 :            : static int ixgbe_dev_set_link_up(struct rte_eth_dev *dev);
     157                 :            : static int ixgbe_dev_set_link_down(struct rte_eth_dev *dev);
     158                 :            : static int ixgbe_dev_close(struct rte_eth_dev *dev);
     159                 :            : static int ixgbe_dev_reset(struct rte_eth_dev *dev);
     160                 :            : static int ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev);
     161                 :            : static int ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev);
     162                 :            : static int ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev);
     163                 :            : static int ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev);
     164                 :            : static int ixgbe_dev_link_update(struct rte_eth_dev *dev,
     165                 :            :                                 int wait_to_complete);
     166                 :            : static int ixgbe_dev_stats_get(struct rte_eth_dev *dev,
     167                 :            :                                 struct rte_eth_stats *stats);
     168                 :            : static int ixgbe_dev_xstats_get(struct rte_eth_dev *dev,
     169                 :            :                                 struct rte_eth_xstat *xstats, unsigned n);
     170                 :            : static int ixgbevf_dev_xstats_get(struct rte_eth_dev *dev,
     171                 :            :                                   struct rte_eth_xstat *xstats, unsigned n);
     172                 :            : static int
     173                 :            : ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
     174                 :            :                 uint64_t *values, unsigned int n);
     175                 :            : static int ixgbe_dev_stats_reset(struct rte_eth_dev *dev);
     176                 :            : static int ixgbe_dev_xstats_reset(struct rte_eth_dev *dev);
     177                 :            : static int ixgbe_dev_xstats_get_names(struct rte_eth_dev *dev,
     178                 :            :         struct rte_eth_xstat_name *xstats_names,
     179                 :            :         unsigned int size);
     180                 :            : static int ixgbevf_dev_xstats_get_names(struct rte_eth_dev *dev,
     181                 :            :         struct rte_eth_xstat_name *xstats_names, unsigned limit);
     182                 :            : static int ixgbe_dev_xstats_get_names_by_id(
     183                 :            :         struct rte_eth_dev *dev,
     184                 :            :         const uint64_t *ids,
     185                 :            :         struct rte_eth_xstat_name *xstats_names,
     186                 :            :         unsigned int limit);
     187                 :            : static int ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
     188                 :            :                                              uint16_t queue_id,
     189                 :            :                                              uint8_t stat_idx,
     190                 :            :                                              uint8_t is_rx);
     191                 :            : static int ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
     192                 :            :                                  size_t fw_size);
     193                 :            : static int ixgbe_dev_info_get(struct rte_eth_dev *dev,
     194                 :            :                               struct rte_eth_dev_info *dev_info);
     195                 :            : static const uint32_t *ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev,
     196                 :            :                                                       size_t *no_of_elements);
     197                 :            : static int ixgbevf_dev_info_get(struct rte_eth_dev *dev,
     198                 :            :                                 struct rte_eth_dev_info *dev_info);
     199                 :            : static int ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
     200                 :            : 
     201                 :            : static int ixgbe_vlan_filter_set(struct rte_eth_dev *dev,
     202                 :            :                 uint16_t vlan_id, int on);
     203                 :            : static int ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
     204                 :            :                                enum rte_vlan_type vlan_type,
     205                 :            :                                uint16_t tpid_id);
     206                 :            : static void ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev,
     207                 :            :                 uint16_t queue, bool on);
     208                 :            : static void ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue,
     209                 :            :                 int on);
     210                 :            : static void ixgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev,
     211                 :            :                                                   int mask);
     212                 :            : static int ixgbe_vlan_offload_config(struct rte_eth_dev *dev, int mask);
     213                 :            : static int ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask);
     214                 :            : static void ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue);
     215                 :            : static void ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue);
     216                 :            : static void ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev);
     217                 :            : static void ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev);
     218                 :            : 
     219                 :            : static int ixgbe_dev_led_on(struct rte_eth_dev *dev);
     220                 :            : static int ixgbe_dev_led_off(struct rte_eth_dev *dev);
     221                 :            : static int ixgbe_flow_ctrl_get(struct rte_eth_dev *dev,
     222                 :            :                                struct rte_eth_fc_conf *fc_conf);
     223                 :            : static int ixgbe_flow_ctrl_set(struct rte_eth_dev *dev,
     224                 :            :                                struct rte_eth_fc_conf *fc_conf);
     225                 :            : static int ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev,
     226                 :            :                 struct rte_eth_pfc_conf *pfc_conf);
     227                 :            : static int ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
     228                 :            :                         struct rte_eth_rss_reta_entry64 *reta_conf,
     229                 :            :                         uint16_t reta_size);
     230                 :            : static int ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
     231                 :            :                         struct rte_eth_rss_reta_entry64 *reta_conf,
     232                 :            :                         uint16_t reta_size);
     233                 :            : static void ixgbe_dev_link_status_print(struct rte_eth_dev *dev);
     234                 :            : static int ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on);
     235                 :            : static int ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev);
     236                 :            : static int ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
     237                 :            : static int ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev);
     238                 :            : static int ixgbe_dev_interrupt_action(struct rte_eth_dev *dev);
     239                 :            : static void ixgbe_dev_interrupt_handler(void *param);
     240                 :            : static void ixgbe_dev_interrupt_delayed_handler(void *param);
     241                 :            : static uint32_t ixgbe_dev_setup_link_thread_handler(void *param);
     242                 :            : static int ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev,
     243                 :            :                                               uint32_t timeout_ms);
     244                 :            : 
     245                 :            : static int ixgbe_add_rar(struct rte_eth_dev *dev,
     246                 :            :                         struct rte_ether_addr *mac_addr,
     247                 :            :                         uint32_t index, uint32_t pool);
     248                 :            : static void ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index);
     249                 :            : static int ixgbe_set_default_mac_addr(struct rte_eth_dev *dev,
     250                 :            :                                            struct rte_ether_addr *mac_addr);
     251                 :            : static void ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config);
     252                 :            : static bool is_device_supported(struct rte_eth_dev *dev,
     253                 :            :                                 struct rte_pci_driver *drv);
     254                 :            : 
     255                 :            : /* For Virtual Function support */
     256                 :            : static int eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev);
     257                 :            : static int eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev);
     258                 :            : static int  ixgbevf_dev_configure(struct rte_eth_dev *dev);
     259                 :            : static int  ixgbevf_dev_start(struct rte_eth_dev *dev);
     260                 :            : static int ixgbevf_dev_link_update(struct rte_eth_dev *dev,
     261                 :            :                                    int wait_to_complete);
     262                 :            : static int ixgbevf_dev_stop(struct rte_eth_dev *dev);
     263                 :            : static int ixgbevf_dev_close(struct rte_eth_dev *dev);
     264                 :            : static int  ixgbevf_dev_reset(struct rte_eth_dev *dev);
     265                 :            : static void ixgbevf_intr_disable(struct rte_eth_dev *dev);
     266                 :            : static void ixgbevf_intr_enable(struct rte_eth_dev *dev);
     267                 :            : static int ixgbevf_dev_stats_get(struct rte_eth_dev *dev,
     268                 :            :                 struct rte_eth_stats *stats);
     269                 :            : static int ixgbevf_dev_stats_reset(struct rte_eth_dev *dev);
     270                 :            : static int ixgbevf_vlan_filter_set(struct rte_eth_dev *dev,
     271                 :            :                 uint16_t vlan_id, int on);
     272                 :            : static void ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev,
     273                 :            :                 uint16_t queue, int on);
     274                 :            : static int ixgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask);
     275                 :            : static int ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask);
     276                 :            : static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on);
     277                 :            : static int ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
     278                 :            :                                             uint16_t queue_id);
     279                 :            : static int ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
     280                 :            :                                              uint16_t queue_id);
     281                 :            : static void ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
     282                 :            :                                  uint8_t queue, uint8_t msix_vector);
     283                 :            : static void ixgbevf_configure_msix(struct rte_eth_dev *dev);
     284                 :            : static int ixgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev);
     285                 :            : static int ixgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev);
     286                 :            : static int ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev);
     287                 :            : static int ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev);
     288                 :            : 
     289                 :            : /* For Eth VMDQ APIs support */
     290                 :            : static int ixgbe_uc_hash_table_set(struct rte_eth_dev *dev, struct
     291                 :            :                 rte_ether_addr * mac_addr, uint8_t on);
     292                 :            : static int ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on);
     293                 :            : static int ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev,
     294                 :            :                                           uint16_t queue_id);
     295                 :            : static int ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
     296                 :            :                                            uint16_t queue_id);
     297                 :            : static void ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
     298                 :            :                                uint8_t queue, uint8_t msix_vector);
     299                 :            : static void ixgbe_configure_msix(struct rte_eth_dev *dev);
     300                 :            : 
     301                 :            : static int ixgbevf_add_mac_addr(struct rte_eth_dev *dev,
     302                 :            :                                 struct rte_ether_addr *mac_addr,
     303                 :            :                                 uint32_t index, uint32_t pool);
     304                 :            : static void ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index);
     305                 :            : static int ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
     306                 :            :                                              struct rte_ether_addr *mac_addr);
     307                 :            : static int ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
     308                 :            :                         struct ixgbe_5tuple_filter *filter);
     309                 :            : static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
     310                 :            :                         struct ixgbe_5tuple_filter *filter);
     311                 :            : static int ixgbe_dev_flow_ops_get(struct rte_eth_dev *dev,
     312                 :            :                                   const struct rte_flow_ops **ops);
     313                 :            : static int ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu);
     314                 :            : 
     315                 :            : static int ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
     316                 :            :                                       struct rte_ether_addr *mc_addr_set,
     317                 :            :                                       uint32_t nb_mc_addr);
     318                 :            : static int ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
     319                 :            :                                    struct rte_eth_dcb_info *dcb_info);
     320                 :            : 
     321                 :            : static int ixgbe_get_reg_length(struct rte_eth_dev *dev);
     322                 :            : static int ixgbe_get_regs(struct rte_eth_dev *dev,
     323                 :            :                             struct rte_dev_reg_info *regs);
     324                 :            : static int ixgbe_get_eeprom_length(struct rte_eth_dev *dev);
     325                 :            : static int ixgbe_get_eeprom(struct rte_eth_dev *dev,
     326                 :            :                                 struct rte_dev_eeprom_info *eeprom);
     327                 :            : static int ixgbe_set_eeprom(struct rte_eth_dev *dev,
     328                 :            :                                 struct rte_dev_eeprom_info *eeprom);
     329                 :            : 
     330                 :            : static int ixgbe_get_module_info(struct rte_eth_dev *dev,
     331                 :            :                                  struct rte_eth_dev_module_info *modinfo);
     332                 :            : static int ixgbe_get_module_eeprom(struct rte_eth_dev *dev,
     333                 :            :                                    struct rte_dev_eeprom_info *info);
     334                 :            : 
     335                 :            : static int ixgbevf_get_reg_length(struct rte_eth_dev *dev);
     336                 :            : static int ixgbevf_get_regs(struct rte_eth_dev *dev,
     337                 :            :                                 struct rte_dev_reg_info *regs);
     338                 :            : 
     339                 :            : static int ixgbe_timesync_enable(struct rte_eth_dev *dev);
     340                 :            : static int ixgbe_timesync_disable(struct rte_eth_dev *dev);
     341                 :            : static int ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
     342                 :            :                                             struct timespec *timestamp,
     343                 :            :                                             uint32_t flags);
     344                 :            : static int ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
     345                 :            :                                             struct timespec *timestamp);
     346                 :            : static int ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta);
     347                 :            : static int ixgbe_timesync_read_time(struct rte_eth_dev *dev,
     348                 :            :                                    struct timespec *timestamp);
     349                 :            : static int ixgbe_timesync_write_time(struct rte_eth_dev *dev,
     350                 :            :                                    const struct timespec *timestamp);
     351                 :            : static void ixgbevf_dev_interrupt_handler(void *param);
     352                 :            : 
     353                 :            : static int ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
     354                 :            :                                          struct rte_eth_udp_tunnel *udp_tunnel);
     355                 :            : static int ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
     356                 :            :                                          struct rte_eth_udp_tunnel *udp_tunnel);
     357                 :            : static int ixgbe_filter_restore(struct rte_eth_dev *dev);
     358                 :            : static void ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev);
     359                 :            : static int ixgbe_wait_for_link_up(struct ixgbe_hw *hw);
     360                 :            : static int devarg_handle_int(__rte_unused const char *key, const char *value,
     361                 :            :                              void *extra_args);
     362                 :            : 
     363                 :            : /*
     364                 :            :  * Define VF Stats MACRO for Non "cleared on read" register
     365                 :            :  */
     366                 :            : #define UPDATE_VF_STAT(reg, last, cur)                          \
     367                 :            : {                                                               \
     368                 :            :         uint32_t latest = IXGBE_READ_REG(hw, reg);              \
     369                 :            :         cur += (latest - last) & UINT_MAX;                      \
     370                 :            :         last = latest;                                          \
     371                 :            : }
     372                 :            : 
     373                 :            : #define UPDATE_VF_STAT_36BIT(lsb, msb, last, cur)                \
     374                 :            : {                                                                \
     375                 :            :         u64 new_lsb = IXGBE_READ_REG(hw, lsb);                   \
     376                 :            :         u64 new_msb = IXGBE_READ_REG(hw, msb);                   \
     377                 :            :         u64 latest = ((new_msb << 32) | new_lsb);                \
     378                 :            :         cur += (0x1000000000LL + latest - last) & 0xFFFFFFFFFLL; \
     379                 :            :         last = latest;                                           \
     380                 :            : }
     381                 :            : 
     382                 :            : #define IXGBE_SET_HWSTRIP(h, q) do {\
     383                 :            :                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
     384                 :            :                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
     385                 :            :                 (h)->bitmap[idx] |= 1 << bit;\
     386                 :            :         } while (0)
     387                 :            : 
     388                 :            : #define IXGBE_CLEAR_HWSTRIP(h, q) do {\
     389                 :            :                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
     390                 :            :                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
     391                 :            :                 (h)->bitmap[idx] &= ~(1 << bit);\
     392                 :            :         } while (0)
     393                 :            : 
     394                 :            : #define IXGBE_GET_HWSTRIP(h, q, r) do {\
     395                 :            :                 uint32_t idx = (q) / (sizeof((h)->bitmap[0]) * NBBY); \
     396                 :            :                 uint32_t bit = (q) % (sizeof((h)->bitmap[0]) * NBBY); \
     397                 :            :                 (r) = (h)->bitmap[idx] >> bit & 1;\
     398                 :            :         } while (0)
     399                 :            : 
     400                 :            : /*
     401                 :            :  * The set of PCI devices this driver supports
     402                 :            :  */
     403                 :            : static const struct rte_pci_id pci_id_ixgbe_map[] = {
     404                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598) },
     405                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_BX) },
     406                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_DUAL_PORT) },
     407                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AF_SINGLE_PORT) },
     408                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT) },
     409                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598AT2) },
     410                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_SFP_LOM) },
     411                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_CX4) },
     412                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_CX4_DUAL_PORT) },
     413                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_DA_DUAL_PORT) },
     414                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM) },
     415                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82598EB_XF_LR) },
     416                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4) },
     417                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KX4_MEZZ) },
     418                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_KR) },
     419                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_COMBO_BACKPLANE) },
     420                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_CX4) },
     421                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP) },
     422                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BACKPLANE_FCOE) },
     423                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_FCOE) },
     424                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_EM) },
     425                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF2) },
     426                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_SFP_SF_QP) },
     427                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_QSFP_SF_QP) },
     428                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599EN_SFP) },
     429                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_XAUI_LOM) },
     430                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_T3_LOM) },
     431                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_LS) },
     432                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T) },
     433                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540T1) },
     434                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_SFP) },
     435                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_10G_T) },
     436                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_1G_T) },
     437                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T) },
     438                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550T1) },
     439                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR) },
     440                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_KR_L) },
     441                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP_N) },
     442                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII) },
     443                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SGMII_L) },
     444                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_10G_T) },
     445                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP) },
     446                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_QSFP_N) },
     447                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_SFP) },
     448                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T) },
     449                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_1G_T_L) },
     450                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KX4) },
     451                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_KR) },
     452                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_XFI) },
     453                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_10G_T) },
     454                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_2_5G_T) },
     455                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_BACKPLANE) },
     456                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_SFP) },
     457                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_SGMII) },
     458                 :            : #ifdef RTE_LIBRTE_IXGBE_BYPASS
     459                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_BYPASS) },
     460                 :            : #endif
     461                 :            :         { .vendor_id = 0, /* sentinel */ },
     462                 :            : };
     463                 :            : 
     464                 :            : /*
     465                 :            :  * The set of PCI devices this driver supports (for 82599 VF)
     466                 :            :  */
     467                 :            : static const struct rte_pci_id pci_id_ixgbevf_map[] = {
     468                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF) },
     469                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_82599_VF_HV) },
     470                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF) },
     471                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X540_VF_HV) },
     472                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF_HV) },
     473                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550_VF) },
     474                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF) },
     475                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_A_VF_HV) },
     476                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF) },
     477                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_X550EM_X_VF_HV) },
     478                 :            :         { RTE_PCI_DEVICE(IXGBE_INTEL_VENDOR_ID, IXGBE_DEV_ID_E610_VF) },
     479                 :            :         { .vendor_id = 0, /* sentinel */ },
     480                 :            : };
     481                 :            : 
     482                 :            : static const struct rte_eth_desc_lim rx_desc_lim = {
     483                 :            :         .nb_max = IXGBE_MAX_RING_DESC,
     484                 :            :         .nb_min = IXGBE_MIN_RING_DESC,
     485                 :            :         .nb_align = IXGBE_RXD_ALIGN,
     486                 :            : };
     487                 :            : 
     488                 :            : static const struct rte_eth_desc_lim tx_desc_lim = {
     489                 :            :         .nb_max = IXGBE_MAX_RING_DESC,
     490                 :            :         .nb_min = IXGBE_MIN_RING_DESC,
     491                 :            :         .nb_align = IXGBE_TXD_ALIGN,
     492                 :            :         .nb_seg_max = IXGBE_TX_MAX_SEG,
     493                 :            :         .nb_mtu_seg_max = IXGBE_TX_MAX_SEG,
     494                 :            : };
     495                 :            : 
     496                 :            : static const struct eth_dev_ops ixgbe_eth_dev_ops = {
     497                 :            :         .dev_configure        = ixgbe_dev_configure,
     498                 :            :         .dev_start            = ixgbe_dev_start,
     499                 :            :         .dev_stop             = ixgbe_dev_stop,
     500                 :            :         .dev_set_link_up    = ixgbe_dev_set_link_up,
     501                 :            :         .dev_set_link_down  = ixgbe_dev_set_link_down,
     502                 :            :         .dev_close            = ixgbe_dev_close,
     503                 :            :         .dev_reset            = ixgbe_dev_reset,
     504                 :            :         .promiscuous_enable   = ixgbe_dev_promiscuous_enable,
     505                 :            :         .promiscuous_disable  = ixgbe_dev_promiscuous_disable,
     506                 :            :         .allmulticast_enable  = ixgbe_dev_allmulticast_enable,
     507                 :            :         .allmulticast_disable = ixgbe_dev_allmulticast_disable,
     508                 :            :         .link_update          = ixgbe_dev_link_update,
     509                 :            :         .stats_get            = ixgbe_dev_stats_get,
     510                 :            :         .xstats_get           = ixgbe_dev_xstats_get,
     511                 :            :         .xstats_get_by_id     = ixgbe_dev_xstats_get_by_id,
     512                 :            :         .stats_reset          = ixgbe_dev_stats_reset,
     513                 :            :         .xstats_reset         = ixgbe_dev_xstats_reset,
     514                 :            :         .xstats_get_names     = ixgbe_dev_xstats_get_names,
     515                 :            :         .xstats_get_names_by_id = ixgbe_dev_xstats_get_names_by_id,
     516                 :            :         .queue_stats_mapping_set = ixgbe_dev_queue_stats_mapping_set,
     517                 :            :         .fw_version_get       = ixgbe_fw_version_get,
     518                 :            :         .dev_infos_get        = ixgbe_dev_info_get,
     519                 :            :         .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
     520                 :            :         .mtu_set              = ixgbe_dev_mtu_set,
     521                 :            :         .vlan_filter_set      = ixgbe_vlan_filter_set,
     522                 :            :         .vlan_tpid_set        = ixgbe_vlan_tpid_set,
     523                 :            :         .vlan_offload_set     = ixgbe_vlan_offload_set,
     524                 :            :         .vlan_strip_queue_set = ixgbe_vlan_strip_queue_set,
     525                 :            :         .rx_queue_start       = ixgbe_dev_rx_queue_start,
     526                 :            :         .rx_queue_stop        = ixgbe_dev_rx_queue_stop,
     527                 :            :         .tx_queue_start       = ixgbe_dev_tx_queue_start,
     528                 :            :         .tx_queue_stop        = ixgbe_dev_tx_queue_stop,
     529                 :            :         .rx_queue_setup       = ixgbe_dev_rx_queue_setup,
     530                 :            :         .rx_queue_intr_enable = ixgbe_dev_rx_queue_intr_enable,
     531                 :            :         .rx_queue_intr_disable = ixgbe_dev_rx_queue_intr_disable,
     532                 :            :         .rx_queue_release     = ixgbe_dev_rx_queue_release,
     533                 :            :         .tx_queue_setup       = ixgbe_dev_tx_queue_setup,
     534                 :            :         .tx_queue_release     = ixgbe_dev_tx_queue_release,
     535                 :            :         .dev_led_on           = ixgbe_dev_led_on,
     536                 :            :         .dev_led_off          = ixgbe_dev_led_off,
     537                 :            :         .flow_ctrl_get        = ixgbe_flow_ctrl_get,
     538                 :            :         .flow_ctrl_set        = ixgbe_flow_ctrl_set,
     539                 :            :         .priority_flow_ctrl_set = ixgbe_priority_flow_ctrl_set,
     540                 :            :         .mac_addr_add         = ixgbe_add_rar,
     541                 :            :         .mac_addr_remove      = ixgbe_remove_rar,
     542                 :            :         .mac_addr_set         = ixgbe_set_default_mac_addr,
     543                 :            :         .uc_hash_table_set    = ixgbe_uc_hash_table_set,
     544                 :            :         .uc_all_hash_table_set  = ixgbe_uc_all_hash_table_set,
     545                 :            :         .set_queue_rate_limit = ixgbe_set_queue_rate_limit,
     546                 :            :         .reta_update          = ixgbe_dev_rss_reta_update,
     547                 :            :         .reta_query           = ixgbe_dev_rss_reta_query,
     548                 :            :         .rss_hash_update      = ixgbe_dev_rss_hash_update,
     549                 :            :         .rss_hash_conf_get    = ixgbe_dev_rss_hash_conf_get,
     550                 :            :         .flow_ops_get         = ixgbe_dev_flow_ops_get,
     551                 :            :         .set_mc_addr_list     = ixgbe_dev_set_mc_addr_list,
     552                 :            :         .rxq_info_get         = ixgbe_rxq_info_get,
     553                 :            :         .txq_info_get         = ixgbe_txq_info_get,
     554                 :            :         .recycle_rxq_info_get = ixgbe_recycle_rxq_info_get,
     555                 :            :         .timesync_enable      = ixgbe_timesync_enable,
     556                 :            :         .timesync_disable     = ixgbe_timesync_disable,
     557                 :            :         .timesync_read_rx_timestamp = ixgbe_timesync_read_rx_timestamp,
     558                 :            :         .timesync_read_tx_timestamp = ixgbe_timesync_read_tx_timestamp,
     559                 :            :         .get_reg              = ixgbe_get_regs,
     560                 :            :         .get_eeprom_length    = ixgbe_get_eeprom_length,
     561                 :            :         .get_eeprom           = ixgbe_get_eeprom,
     562                 :            :         .set_eeprom           = ixgbe_set_eeprom,
     563                 :            :         .get_module_info      = ixgbe_get_module_info,
     564                 :            :         .get_module_eeprom    = ixgbe_get_module_eeprom,
     565                 :            :         .get_dcb_info         = ixgbe_dev_get_dcb_info,
     566                 :            :         .timesync_adjust_time = ixgbe_timesync_adjust_time,
     567                 :            :         .timesync_read_time   = ixgbe_timesync_read_time,
     568                 :            :         .timesync_write_time  = ixgbe_timesync_write_time,
     569                 :            :         .udp_tunnel_port_add  = ixgbe_dev_udp_tunnel_port_add,
     570                 :            :         .udp_tunnel_port_del  = ixgbe_dev_udp_tunnel_port_del,
     571                 :            :         .tm_ops_get           = ixgbe_tm_ops_get,
     572                 :            :         .tx_done_cleanup      = ixgbe_dev_tx_done_cleanup,
     573                 :            :         .get_monitor_addr     = ixgbe_get_monitor_addr,
     574                 :            : };
     575                 :            : 
     576                 :            : /*
     577                 :            :  * dev_ops for virtual function, bare necessities for basic vf
     578                 :            :  * operation have been implemented
     579                 :            :  */
     580                 :            : static const struct eth_dev_ops ixgbevf_eth_dev_ops = {
     581                 :            :         .dev_configure        = ixgbevf_dev_configure,
     582                 :            :         .dev_start            = ixgbevf_dev_start,
     583                 :            :         .dev_stop             = ixgbevf_dev_stop,
     584                 :            :         .link_update          = ixgbevf_dev_link_update,
     585                 :            :         .stats_get            = ixgbevf_dev_stats_get,
     586                 :            :         .xstats_get           = ixgbevf_dev_xstats_get,
     587                 :            :         .stats_reset          = ixgbevf_dev_stats_reset,
     588                 :            :         .xstats_reset         = ixgbevf_dev_stats_reset,
     589                 :            :         .xstats_get_names     = ixgbevf_dev_xstats_get_names,
     590                 :            :         .dev_close            = ixgbevf_dev_close,
     591                 :            :         .dev_reset            = ixgbevf_dev_reset,
     592                 :            :         .promiscuous_enable   = ixgbevf_dev_promiscuous_enable,
     593                 :            :         .promiscuous_disable  = ixgbevf_dev_promiscuous_disable,
     594                 :            :         .allmulticast_enable  = ixgbevf_dev_allmulticast_enable,
     595                 :            :         .allmulticast_disable = ixgbevf_dev_allmulticast_disable,
     596                 :            :         .dev_infos_get        = ixgbevf_dev_info_get,
     597                 :            :         .dev_supported_ptypes_get = ixgbe_dev_supported_ptypes_get,
     598                 :            :         .mtu_set              = ixgbevf_dev_set_mtu,
     599                 :            :         .vlan_filter_set      = ixgbevf_vlan_filter_set,
     600                 :            :         .vlan_strip_queue_set = ixgbevf_vlan_strip_queue_set,
     601                 :            :         .vlan_offload_set     = ixgbevf_vlan_offload_set,
     602                 :            :         .rx_queue_setup       = ixgbe_dev_rx_queue_setup,
     603                 :            :         .rx_queue_release     = ixgbe_dev_rx_queue_release,
     604                 :            :         .tx_queue_setup       = ixgbe_dev_tx_queue_setup,
     605                 :            :         .tx_queue_release     = ixgbe_dev_tx_queue_release,
     606                 :            :         .rx_queue_intr_enable = ixgbevf_dev_rx_queue_intr_enable,
     607                 :            :         .rx_queue_intr_disable = ixgbevf_dev_rx_queue_intr_disable,
     608                 :            :         .mac_addr_add         = ixgbevf_add_mac_addr,
     609                 :            :         .mac_addr_remove      = ixgbevf_remove_mac_addr,
     610                 :            :         .set_mc_addr_list     = ixgbe_dev_set_mc_addr_list,
     611                 :            :         .rxq_info_get         = ixgbe_rxq_info_get,
     612                 :            :         .txq_info_get         = ixgbe_txq_info_get,
     613                 :            :         .mac_addr_set         = ixgbevf_set_default_mac_addr,
     614                 :            :         .get_reg              = ixgbevf_get_regs,
     615                 :            :         .reta_update          = ixgbe_dev_rss_reta_update,
     616                 :            :         .reta_query           = ixgbe_dev_rss_reta_query,
     617                 :            :         .rss_hash_update      = ixgbe_dev_rss_hash_update,
     618                 :            :         .rss_hash_conf_get    = ixgbe_dev_rss_hash_conf_get,
     619                 :            :         .tx_done_cleanup      = ixgbe_dev_tx_done_cleanup,
     620                 :            :         .get_monitor_addr     = ixgbe_get_monitor_addr,
     621                 :            : };
     622                 :            : 
     623                 :            : /* store statistics names and its offset in stats structure */
     624                 :            : struct rte_ixgbe_xstats_name_off {
     625                 :            :         char name[RTE_ETH_XSTATS_NAME_SIZE];
     626                 :            :         unsigned offset;
     627                 :            : };
     628                 :            : 
     629                 :            : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_stats_strings[] = {
     630                 :            :         {"rx_crc_errors", offsetof(struct ixgbe_hw_stats, crcerrs)},
     631                 :            :         {"rx_illegal_byte_errors", offsetof(struct ixgbe_hw_stats, illerrc)},
     632                 :            :         {"rx_error_bytes", offsetof(struct ixgbe_hw_stats, errbc)},
     633                 :            :         {"mac_local_errors", offsetof(struct ixgbe_hw_stats, mlfc)},
     634                 :            :         {"mac_remote_errors", offsetof(struct ixgbe_hw_stats, mrfc)},
     635                 :            :         {"rx_length_errors", offsetof(struct ixgbe_hw_stats, rlec)},
     636                 :            :         {"tx_xon_packets", offsetof(struct ixgbe_hw_stats, lxontxc)},
     637                 :            :         {"rx_xon_packets", offsetof(struct ixgbe_hw_stats, lxonrxc)},
     638                 :            :         {"tx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxofftxc)},
     639                 :            :         {"rx_xoff_packets", offsetof(struct ixgbe_hw_stats, lxoffrxc)},
     640                 :            :         {"rx_size_64_packets", offsetof(struct ixgbe_hw_stats, prc64)},
     641                 :            :         {"rx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, prc127)},
     642                 :            :         {"rx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, prc255)},
     643                 :            :         {"rx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, prc511)},
     644                 :            :         {"rx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
     645                 :            :                 prc1023)},
     646                 :            :         {"rx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
     647                 :            :                 prc1522)},
     648                 :            :         {"rx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bprc)},
     649                 :            :         {"rx_multicast_packets", offsetof(struct ixgbe_hw_stats, mprc)},
     650                 :            :         {"rx_fragment_errors", offsetof(struct ixgbe_hw_stats, rfc)},
     651                 :            :         {"rx_undersize_errors", offsetof(struct ixgbe_hw_stats, ruc)},
     652                 :            :         {"rx_oversize_errors", offsetof(struct ixgbe_hw_stats, roc)},
     653                 :            :         {"rx_jabber_errors", offsetof(struct ixgbe_hw_stats, rjc)},
     654                 :            :         {"rx_management_packets", offsetof(struct ixgbe_hw_stats, mngprc)},
     655                 :            :         {"rx_management_dropped", offsetof(struct ixgbe_hw_stats, mngpdc)},
     656                 :            :         {"tx_management_packets", offsetof(struct ixgbe_hw_stats, mngptc)},
     657                 :            :         {"rx_total_packets", offsetof(struct ixgbe_hw_stats, tpr)},
     658                 :            :         {"rx_total_bytes", offsetof(struct ixgbe_hw_stats, tor)},
     659                 :            :         {"tx_total_packets", offsetof(struct ixgbe_hw_stats, tpt)},
     660                 :            :         {"tx_size_64_packets", offsetof(struct ixgbe_hw_stats, ptc64)},
     661                 :            :         {"tx_size_65_to_127_packets", offsetof(struct ixgbe_hw_stats, ptc127)},
     662                 :            :         {"tx_size_128_to_255_packets", offsetof(struct ixgbe_hw_stats, ptc255)},
     663                 :            :         {"tx_size_256_to_511_packets", offsetof(struct ixgbe_hw_stats, ptc511)},
     664                 :            :         {"tx_size_512_to_1023_packets", offsetof(struct ixgbe_hw_stats,
     665                 :            :                 ptc1023)},
     666                 :            :         {"tx_size_1024_to_max_packets", offsetof(struct ixgbe_hw_stats,
     667                 :            :                 ptc1522)},
     668                 :            :         {"tx_multicast_packets", offsetof(struct ixgbe_hw_stats, mptc)},
     669                 :            :         {"tx_broadcast_packets", offsetof(struct ixgbe_hw_stats, bptc)},
     670                 :            :         {"rx_mac_short_packet_dropped", offsetof(struct ixgbe_hw_stats, mspdc)},
     671                 :            :         {"rx_l3_l4_xsum_error", offsetof(struct ixgbe_hw_stats, xec)},
     672                 :            : 
     673                 :            :         {"flow_director_added_filters", offsetof(struct ixgbe_hw_stats,
     674                 :            :                 fdirustat_add)},
     675                 :            :         {"flow_director_removed_filters", offsetof(struct ixgbe_hw_stats,
     676                 :            :                 fdirustat_remove)},
     677                 :            :         {"flow_director_filter_add_errors", offsetof(struct ixgbe_hw_stats,
     678                 :            :                 fdirfstat_fadd)},
     679                 :            :         {"flow_director_filter_remove_errors", offsetof(struct ixgbe_hw_stats,
     680                 :            :                 fdirfstat_fremove)},
     681                 :            :         {"flow_director_matched_filters", offsetof(struct ixgbe_hw_stats,
     682                 :            :                 fdirmatch)},
     683                 :            :         {"flow_director_missed_filters", offsetof(struct ixgbe_hw_stats,
     684                 :            :                 fdirmiss)},
     685                 :            : 
     686                 :            :         {"rx_fcoe_crc_errors", offsetof(struct ixgbe_hw_stats, fccrc)},
     687                 :            :         {"rx_fcoe_dropped", offsetof(struct ixgbe_hw_stats, fcoerpdc)},
     688                 :            :         {"rx_fcoe_mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats,
     689                 :            :                 fclast)},
     690                 :            :         {"rx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeprc)},
     691                 :            :         {"tx_fcoe_packets", offsetof(struct ixgbe_hw_stats, fcoeptc)},
     692                 :            :         {"rx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwrc)},
     693                 :            :         {"tx_fcoe_bytes", offsetof(struct ixgbe_hw_stats, fcoedwtc)},
     694                 :            :         {"rx_fcoe_no_direct_data_placement", offsetof(struct ixgbe_hw_stats,
     695                 :            :                 fcoe_noddp)},
     696                 :            :         {"rx_fcoe_no_direct_data_placement_ext_buff",
     697                 :            :                 offsetof(struct ixgbe_hw_stats, fcoe_noddp_ext_buff)},
     698                 :            : 
     699                 :            :         {"tx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
     700                 :            :                 lxontxc)},
     701                 :            :         {"rx_flow_control_xon_packets", offsetof(struct ixgbe_hw_stats,
     702                 :            :                 lxonrxc)},
     703                 :            :         {"tx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
     704                 :            :                 lxofftxc)},
     705                 :            :         {"rx_flow_control_xoff_packets", offsetof(struct ixgbe_hw_stats,
     706                 :            :                 lxoffrxc)},
     707                 :            :         {"rx_total_missed_packets", offsetof(struct ixgbe_hw_stats, mpctotal)},
     708                 :            : };
     709                 :            : 
     710                 :            : #define IXGBE_NB_HW_STATS (sizeof(rte_ixgbe_stats_strings) / \
     711                 :            :                            sizeof(rte_ixgbe_stats_strings[0]))
     712                 :            : 
     713                 :            : /* MACsec statistics */
     714                 :            : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_macsec_strings[] = {
     715                 :            :         {"out_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
     716                 :            :                 out_pkts_untagged)},
     717                 :            :         {"out_pkts_encrypted", offsetof(struct ixgbe_macsec_stats,
     718                 :            :                 out_pkts_encrypted)},
     719                 :            :         {"out_pkts_protected", offsetof(struct ixgbe_macsec_stats,
     720                 :            :                 out_pkts_protected)},
     721                 :            :         {"out_octets_encrypted", offsetof(struct ixgbe_macsec_stats,
     722                 :            :                 out_octets_encrypted)},
     723                 :            :         {"out_octets_protected", offsetof(struct ixgbe_macsec_stats,
     724                 :            :                 out_octets_protected)},
     725                 :            :         {"in_pkts_untagged", offsetof(struct ixgbe_macsec_stats,
     726                 :            :                 in_pkts_untagged)},
     727                 :            :         {"in_pkts_badtag", offsetof(struct ixgbe_macsec_stats,
     728                 :            :                 in_pkts_badtag)},
     729                 :            :         {"in_pkts_nosci", offsetof(struct ixgbe_macsec_stats,
     730                 :            :                 in_pkts_nosci)},
     731                 :            :         {"in_pkts_unknownsci", offsetof(struct ixgbe_macsec_stats,
     732                 :            :                 in_pkts_unknownsci)},
     733                 :            :         {"in_octets_decrypted", offsetof(struct ixgbe_macsec_stats,
     734                 :            :                 in_octets_decrypted)},
     735                 :            :         {"in_octets_validated", offsetof(struct ixgbe_macsec_stats,
     736                 :            :                 in_octets_validated)},
     737                 :            :         {"in_pkts_unchecked", offsetof(struct ixgbe_macsec_stats,
     738                 :            :                 in_pkts_unchecked)},
     739                 :            :         {"in_pkts_delayed", offsetof(struct ixgbe_macsec_stats,
     740                 :            :                 in_pkts_delayed)},
     741                 :            :         {"in_pkts_late", offsetof(struct ixgbe_macsec_stats,
     742                 :            :                 in_pkts_late)},
     743                 :            :         {"in_pkts_ok", offsetof(struct ixgbe_macsec_stats,
     744                 :            :                 in_pkts_ok)},
     745                 :            :         {"in_pkts_invalid", offsetof(struct ixgbe_macsec_stats,
     746                 :            :                 in_pkts_invalid)},
     747                 :            :         {"in_pkts_notvalid", offsetof(struct ixgbe_macsec_stats,
     748                 :            :                 in_pkts_notvalid)},
     749                 :            :         {"in_pkts_unusedsa", offsetof(struct ixgbe_macsec_stats,
     750                 :            :                 in_pkts_unusedsa)},
     751                 :            :         {"in_pkts_notusingsa", offsetof(struct ixgbe_macsec_stats,
     752                 :            :                 in_pkts_notusingsa)},
     753                 :            : };
     754                 :            : 
     755                 :            : #define IXGBE_NB_MACSEC_STATS (sizeof(rte_ixgbe_macsec_strings) / \
     756                 :            :                            sizeof(rte_ixgbe_macsec_strings[0]))
     757                 :            : 
     758                 :            : /* Per-queue statistics */
     759                 :            : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_rxq_strings[] = {
     760                 :            :         {"mbuf_allocation_errors", offsetof(struct ixgbe_hw_stats, rnbc)},
     761                 :            :         {"dropped", offsetof(struct ixgbe_hw_stats, mpc)},
     762                 :            :         {"xon_packets", offsetof(struct ixgbe_hw_stats, pxonrxc)},
     763                 :            :         {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxoffrxc)},
     764                 :            : };
     765                 :            : 
     766                 :            : #define IXGBE_NB_RXQ_PRIO_STATS (sizeof(rte_ixgbe_rxq_strings) / \
     767                 :            :                            sizeof(rte_ixgbe_rxq_strings[0]))
     768                 :            : #define IXGBE_NB_RXQ_PRIO_VALUES 8
     769                 :            : 
     770                 :            : static const struct rte_ixgbe_xstats_name_off rte_ixgbe_txq_strings[] = {
     771                 :            :         {"xon_packets", offsetof(struct ixgbe_hw_stats, pxontxc)},
     772                 :            :         {"xoff_packets", offsetof(struct ixgbe_hw_stats, pxofftxc)},
     773                 :            :         {"xon_to_xoff_packets", offsetof(struct ixgbe_hw_stats,
     774                 :            :                 pxon2offc)},
     775                 :            : };
     776                 :            : 
     777                 :            : #define IXGBE_NB_TXQ_PRIO_STATS (sizeof(rte_ixgbe_txq_strings) / \
     778                 :            :                            sizeof(rte_ixgbe_txq_strings[0]))
     779                 :            : #define IXGBE_NB_TXQ_PRIO_VALUES 8
     780                 :            : 
     781                 :            : static const struct rte_ixgbe_xstats_name_off rte_ixgbevf_stats_strings[] = {
     782                 :            :         {"rx_multicast_packets", offsetof(struct ixgbevf_hw_stats, vfmprc)},
     783                 :            : };
     784                 :            : 
     785                 :            : #define IXGBEVF_NB_XSTATS (sizeof(rte_ixgbevf_stats_strings) /  \
     786                 :            :                 sizeof(rte_ixgbevf_stats_strings[0]))
     787                 :            : 
     788                 :            : /*
     789                 :            :  * This function is the same as ixgbe_is_sfp() in base/ixgbe.h.
     790                 :            :  */
     791                 :            : static inline int
     792                 :          0 : ixgbe_is_sfp(struct ixgbe_hw *hw)
     793                 :            : {
     794         [ #  # ]:          0 :         switch (hw->phy.type) {
     795                 :            :         case ixgbe_phy_sfp_avago:
     796                 :            :         case ixgbe_phy_sfp_ftl:
     797                 :            :         case ixgbe_phy_sfp_intel:
     798                 :            :         case ixgbe_phy_sfp_unknown:
     799                 :            :         case ixgbe_phy_sfp_passive_tyco:
     800                 :            :         case ixgbe_phy_sfp_passive_unknown:
     801                 :            :                 return 1;
     802                 :          0 :         default:
     803                 :            :                 /* x550em devices may be SFP, check media type */
     804         [ #  # ]:          0 :                 switch (hw->mac.type) {
     805                 :          0 :                 case ixgbe_mac_X550EM_x:
     806                 :            :                 case ixgbe_mac_X550EM_a:
     807                 :          0 :                         switch (ixgbe_get_media_type(hw)) {
     808                 :            :                         case ixgbe_media_type_fiber:
     809                 :            :                         case ixgbe_media_type_fiber_qsfp:
     810                 :            :                                 return 1;
     811                 :            :                         default:
     812                 :            :                                 break;
     813                 :            :                         }
     814                 :            :                 default:
     815                 :            :                         break;
     816                 :            :                 }
     817                 :            :                 return 0;
     818                 :            :         }
     819                 :            : }
     820                 :            : 
     821                 :            : static inline int32_t
     822                 :          0 : ixgbe_pf_reset_hw(struct ixgbe_hw *hw)
     823                 :            : {
     824                 :            :         uint32_t ctrl_ext;
     825                 :            :         int32_t status;
     826                 :            : 
     827                 :          0 :         status = ixgbe_reset_hw(hw);
     828                 :            : 
     829                 :          0 :         ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
     830                 :            :         /* Set PF Reset Done bit so PF/VF Mail Ops can work */
     831                 :          0 :         ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
     832                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
     833                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     834                 :            : 
     835         [ #  # ]:          0 :         if (status == IXGBE_ERR_SFP_NOT_PRESENT)
     836                 :            :                 status = IXGBE_SUCCESS;
     837                 :          0 :         return status;
     838                 :            : }
     839                 :            : 
     840                 :            : static inline void
     841                 :            : ixgbe_enable_intr(struct rte_eth_dev *dev)
     842                 :            : {
     843                 :            :         struct ixgbe_interrupt *intr =
     844                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
     845                 :            :         struct ixgbe_hw *hw =
     846                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     847                 :            : 
     848                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EIMS, intr->mask);
     849                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     850                 :          0 : }
     851                 :            : 
     852                 :            : /*
     853                 :            :  * This function is based on ixgbe_disable_intr() in base/ixgbe.h.
     854                 :            :  */
     855                 :            : static void
     856                 :          0 : ixgbe_disable_intr(struct ixgbe_hw *hw)
     857                 :            : {
     858                 :          0 :         PMD_INIT_FUNC_TRACE();
     859                 :            : 
     860         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
     861                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMC, ~0);
     862                 :            :         } else {
     863                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMC, 0xFFFF0000);
     864                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), ~0);
     865                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), ~0);
     866                 :            :         }
     867                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     868                 :          0 : }
     869                 :            : 
     870                 :            : /*
     871                 :            :  * This function resets queue statistics mapping registers.
     872                 :            :  * From Niantic datasheet, Initialization of Statistics section:
     873                 :            :  * "...if software requires the queue counters, the RQSMR and TQSM registers
     874                 :            :  * must be re-programmed following a device reset.
     875                 :            :  */
     876                 :            : static void
     877                 :            : ixgbe_reset_qstat_mappings(struct ixgbe_hw *hw)
     878                 :            : {
     879                 :            :         uint32_t i;
     880                 :            : 
     881         [ #  # ]:          0 :         for (i = 0; i != IXGBE_NB_STAT_MAPPING_REGS; i++) {
     882                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0);
     883                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0);
     884                 :            :         }
     885                 :            : }
     886                 :            : 
     887                 :            : 
     888                 :            : static int
     889                 :          0 : ixgbe_dev_queue_stats_mapping_set(struct rte_eth_dev *eth_dev,
     890                 :            :                                   uint16_t queue_id,
     891                 :            :                                   uint8_t stat_idx,
     892                 :            :                                   uint8_t is_rx)
     893                 :            : {
     894                 :            : #define QSM_REG_NB_BITS_PER_QMAP_FIELD 8
     895                 :            : #define NB_QMAP_FIELDS_PER_QSM_REG 4
     896                 :            : #define QMAP_FIELD_RESERVED_BITS_MASK 0x0f
     897                 :            : 
     898                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     899                 :            :         struct ixgbe_stat_mapping_registers *stat_mappings =
     900                 :            :                 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(eth_dev->data->dev_private);
     901                 :            :         uint32_t qsmr_mask = 0;
     902                 :            :         uint32_t clearing_mask = QMAP_FIELD_RESERVED_BITS_MASK;
     903                 :            :         uint32_t q_map;
     904                 :            :         uint8_t n, offset;
     905                 :            : 
     906         [ #  # ]:          0 :         if ((hw->mac.type != ixgbe_mac_82599EB) &&
     907         [ #  # ]:          0 :                 (hw->mac.type != ixgbe_mac_X540) &&
     908         [ #  # ]:          0 :                 (hw->mac.type != ixgbe_mac_X550) &&
     909         [ #  # ]:          0 :                 (hw->mac.type != ixgbe_mac_X550EM_x) &&
     910                 :            :                 (hw->mac.type != ixgbe_mac_X550EM_a))
     911                 :            :                 return -ENOSYS;
     912                 :            : 
     913         [ #  # ]:          0 :         PMD_INIT_LOG(DEBUG, "Setting port %d, %s queue_id %d to stat index %d",
     914                 :            :                      (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
     915                 :            :                      queue_id, stat_idx);
     916                 :            : 
     917                 :          0 :         n = (uint8_t)(queue_id / NB_QMAP_FIELDS_PER_QSM_REG);
     918         [ #  # ]:          0 :         if (n >= IXGBE_NB_STAT_MAPPING_REGS) {
     919                 :          0 :                 PMD_INIT_LOG(ERR, "Nb of stat mapping registers exceeded");
     920                 :          0 :                 return -EIO;
     921                 :            :         }
     922                 :          0 :         offset = (uint8_t)(queue_id % NB_QMAP_FIELDS_PER_QSM_REG);
     923                 :            : 
     924                 :            :         /* Now clear any previous stat_idx set */
     925                 :          0 :         clearing_mask <<= (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
     926         [ #  # ]:          0 :         if (!is_rx)
     927                 :          0 :                 stat_mappings->tqsm[n] &= ~clearing_mask;
     928                 :            :         else
     929                 :          0 :                 stat_mappings->rqsmr[n] &= ~clearing_mask;
     930                 :            : 
     931                 :            :         q_map = (uint32_t)stat_idx;
     932                 :          0 :         q_map &= QMAP_FIELD_RESERVED_BITS_MASK;
     933                 :          0 :         qsmr_mask = q_map << (QSM_REG_NB_BITS_PER_QMAP_FIELD * offset);
     934         [ #  # ]:          0 :         if (!is_rx)
     935                 :          0 :                 stat_mappings->tqsm[n] |= qsmr_mask;
     936                 :            :         else
     937                 :          0 :                 stat_mappings->rqsmr[n] |= qsmr_mask;
     938                 :            : 
     939                 :          0 :         PMD_INIT_LOG(DEBUG, "Set port %d, %s queue_id %d to stat index %d",
     940                 :            :                      (int)(eth_dev->data->port_id), is_rx ? "RX" : "TX",
     941                 :            :                      queue_id, stat_idx);
     942   [ #  #  #  # ]:          0 :         PMD_INIT_LOG(DEBUG, "%s[%d] = 0x%08x", is_rx ? "RQSMR" : "TQSM", n,
     943                 :            :                      is_rx ? stat_mappings->rqsmr[n] : stat_mappings->tqsm[n]);
     944                 :            : 
     945                 :            :         /* Now write the mapping in the appropriate register */
     946         [ #  # ]:          0 :         if (is_rx) {
     947                 :          0 :                 PMD_INIT_LOG(DEBUG, "Write 0x%x to RX IXGBE stat mapping reg:%d",
     948                 :            :                              stat_mappings->rqsmr[n], n);
     949                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(n), stat_mappings->rqsmr[n]);
     950                 :            :         } else {
     951                 :          0 :                 PMD_INIT_LOG(DEBUG, "Write 0x%x to TX IXGBE stat mapping reg:%d",
     952                 :            :                              stat_mappings->tqsm[n], n);
     953                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(n), stat_mappings->tqsm[n]);
     954                 :            :         }
     955                 :            :         return 0;
     956                 :            : }
     957                 :            : 
     958                 :            : static void
     959                 :          0 : ixgbe_restore_statistics_mapping(struct rte_eth_dev *dev)
     960                 :            : {
     961                 :            :         struct ixgbe_stat_mapping_registers *stat_mappings =
     962                 :          0 :                 IXGBE_DEV_PRIVATE_TO_STAT_MAPPINGS(dev->data->dev_private);
     963                 :            :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     964                 :            :         int i;
     965                 :            : 
     966                 :            :         /* write whatever was in stat mapping table to the NIC */
     967         [ #  # ]:          0 :         for (i = 0; i < IXGBE_NB_STAT_MAPPING_REGS; i++) {
     968                 :            :                 /* rx */
     969                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), stat_mappings->rqsmr[i]);
     970                 :            : 
     971                 :            :                 /* tx */
     972                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), stat_mappings->tqsm[i]);
     973                 :            :         }
     974                 :          0 : }
     975                 :            : 
     976                 :            : static void
     977                 :          0 : ixgbe_dcb_init(struct ixgbe_hw *hw, struct ixgbe_dcb_config *dcb_config)
     978                 :            : {
     979                 :            :         uint8_t i;
     980                 :            :         struct ixgbe_dcb_tc_config *tc;
     981                 :            :         uint8_t dcb_max_tc = IXGBE_DCB_MAX_TRAFFIC_CLASS;
     982                 :            : 
     983                 :          0 :         dcb_config->num_tcs.pg_tcs = dcb_max_tc;
     984                 :          0 :         dcb_config->num_tcs.pfc_tcs = dcb_max_tc;
     985         [ #  # ]:          0 :         for (i = 0; i < dcb_max_tc; i++) {
     986                 :          0 :                 tc = &dcb_config->tc_config[i];
     987                 :          0 :                 tc->path[IXGBE_DCB_TX_CONFIG].bwg_id = i;
     988                 :          0 :                 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent =
     989                 :          0 :                                  (uint8_t)(100/dcb_max_tc + (i & 1));
     990                 :          0 :                 tc->path[IXGBE_DCB_RX_CONFIG].bwg_id = i;
     991                 :          0 :                 tc->path[IXGBE_DCB_RX_CONFIG].bwg_percent =
     992                 :            :                                  (uint8_t)(100/dcb_max_tc + (i & 1));
     993                 :          0 :                 tc->pfc = ixgbe_dcb_pfc_disabled;
     994                 :            :         }
     995                 :            : 
     996                 :            :         /* Initialize default user to priority mapping, UPx->TC0 */
     997                 :            :         tc = &dcb_config->tc_config[0];
     998                 :          0 :         tc->path[IXGBE_DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
     999                 :          0 :         tc->path[IXGBE_DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
    1000         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_BW_GROUP; i++) {
    1001                 :          0 :                 dcb_config->bw_percentage[IXGBE_DCB_TX_CONFIG][i] = 100;
    1002                 :          0 :                 dcb_config->bw_percentage[IXGBE_DCB_RX_CONFIG][i] = 100;
    1003                 :            :         }
    1004                 :          0 :         dcb_config->rx_pba_cfg = ixgbe_dcb_pba_equal;
    1005                 :          0 :         dcb_config->pfc_mode_enable = false;
    1006                 :          0 :         dcb_config->vt_mode = true;
    1007                 :          0 :         dcb_config->round_robin_enable = false;
    1008                 :            :         /* support all DCB capabilities in 82599 */
    1009                 :          0 :         dcb_config->support.capabilities = 0xFF;
    1010                 :            : 
    1011                 :            :         /*we only support 4 Tcs for X540, X550 */
    1012         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_X540 ||
    1013         [ #  # ]:          0 :                 hw->mac.type == ixgbe_mac_X550 ||
    1014         [ #  # ]:          0 :                 hw->mac.type == ixgbe_mac_X550EM_x ||
    1015                 :            :                 hw->mac.type == ixgbe_mac_X550EM_a) {
    1016                 :          0 :                 dcb_config->num_tcs.pg_tcs = 4;
    1017                 :          0 :                 dcb_config->num_tcs.pfc_tcs = 4;
    1018                 :            :         }
    1019                 :          0 : }
    1020                 :            : 
    1021                 :            : /*
    1022                 :            :  * Ensure that all locks are released before first NVM or PHY access
    1023                 :            :  */
    1024                 :            : static void
    1025                 :          0 : ixgbe_swfw_lock_reset(struct ixgbe_hw *hw)
    1026                 :            : {
    1027                 :            :         uint16_t mask;
    1028                 :            : 
    1029                 :            :         /*
    1030                 :            :          * Phy lock should not fail in this early stage. If this is the case,
    1031                 :            :          * it is due to an improper exit of the application.
    1032                 :            :          * So force the release of the faulty lock. Release of common lock
    1033                 :            :          * is done automatically by swfw_sync function.
    1034                 :            :          */
    1035                 :          0 :         mask = IXGBE_GSSR_PHY0_SM << hw->bus.func;
    1036         [ #  # ]:          0 :         if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
    1037                 :          0 :                 PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
    1038                 :            :         }
    1039                 :          0 :         ixgbe_release_swfw_semaphore(hw, mask);
    1040                 :            : 
    1041                 :            :         /*
    1042                 :            :          * These ones are more tricky since they are common to all ports; but
    1043                 :            :          * swfw_sync retries last long enough (1s) to be almost sure that if
    1044                 :            :          * lock can not be taken it is due to an improper lock of the
    1045                 :            :          * semaphore.
    1046                 :            :          */
    1047                 :            :         mask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_MAC_CSR_SM | IXGBE_GSSR_SW_MNG_SM;
    1048         [ #  # ]:          0 :         if (ixgbe_acquire_swfw_semaphore(hw, mask) < 0) {
    1049                 :          0 :                 PMD_DRV_LOG(DEBUG, "SWFW common locks released");
    1050                 :            :         }
    1051                 :          0 :         ixgbe_release_swfw_semaphore(hw, mask);
    1052                 :          0 : }
    1053                 :            : 
    1054                 :            : static void
    1055                 :          0 : ixgbe_parse_devargs(struct ixgbe_adapter *adapter,
    1056                 :            :                       struct rte_devargs *devargs)
    1057                 :            : {
    1058                 :            :         struct rte_kvargs *kvlist;
    1059                 :            :         uint16_t sdp3_no_tx_disable;
    1060                 :            : 
    1061         [ #  # ]:          0 :         if (devargs == NULL)
    1062                 :          0 :                 return;
    1063                 :            : 
    1064                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, ixgbe_valid_arguments);
    1065         [ #  # ]:          0 :         if (kvlist == NULL)
    1066                 :            :                 return;
    1067                 :            : 
    1068   [ #  #  #  # ]:          0 :         if (rte_kvargs_count(kvlist, IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE) == 1 &&
    1069                 :          0 :             rte_kvargs_process(kvlist, IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE,
    1070                 :          0 :                                devarg_handle_int, &sdp3_no_tx_disable) == 0 &&
    1071         [ #  # ]:          0 :             sdp3_no_tx_disable == 1)
    1072                 :          0 :                 adapter->sdp3_no_tx_disable = 1;
    1073                 :            : 
    1074                 :          0 :         rte_kvargs_free(kvlist);
    1075                 :            : }
    1076                 :            : 
    1077                 :            : /*
    1078                 :            :  * This function is based on code in ixgbe_attach() in base/ixgbe.c.
    1079                 :            :  * It returns 0 on success.
    1080                 :            :  */
    1081                 :            : static int
    1082                 :          0 : eth_ixgbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
    1083                 :            : {
    1084                 :          0 :         struct ixgbe_adapter *ad = eth_dev->data->dev_private;
    1085                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    1086                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1087                 :          0 :         struct ixgbe_hw *hw =
    1088                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
    1089                 :          0 :         struct ixgbe_vfta *shadow_vfta =
    1090                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
    1091                 :          0 :         struct ixgbe_hwstrip *hwstrip =
    1092                 :            :                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
    1093                 :          0 :         struct ixgbe_dcb_config *dcb_config =
    1094                 :            :                 IXGBE_DEV_PRIVATE_TO_DCB_CFG(eth_dev->data->dev_private);
    1095                 :          0 :         struct ixgbe_filter_info *filter_info =
    1096                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
    1097                 :          0 :         struct ixgbe_bw_conf *bw_conf =
    1098                 :            :                 IXGBE_DEV_PRIVATE_TO_BW_CONF(eth_dev->data->dev_private);
    1099                 :            :         uint32_t ctrl_ext;
    1100                 :            :         uint16_t csum;
    1101                 :            :         int diag, i, ret;
    1102                 :            : 
    1103                 :          0 :         PMD_INIT_FUNC_TRACE();
    1104                 :            : 
    1105                 :          0 :         ixgbe_dev_macsec_setting_reset(eth_dev);
    1106                 :            : 
    1107                 :          0 :         eth_dev->dev_ops = &ixgbe_eth_dev_ops;
    1108                 :          0 :         eth_dev->rx_queue_count       = ixgbe_dev_rx_queue_count;
    1109                 :          0 :         eth_dev->rx_descriptor_status = ixgbe_dev_rx_descriptor_status;
    1110                 :          0 :         eth_dev->tx_descriptor_status = ixgbe_dev_tx_descriptor_status;
    1111                 :          0 :         eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
    1112                 :          0 :         eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
    1113                 :          0 :         eth_dev->tx_pkt_prepare = &ixgbe_prep_pkts;
    1114                 :            : 
    1115                 :            :         /*
    1116                 :            :          * For secondary processes, we don't initialise any further as primary
    1117                 :            :          * has already done this work. Only check we don't need a different
    1118                 :            :          * RX and TX function.
    1119                 :            :          */
    1120         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    1121                 :            :                 struct ci_tx_queue *txq;
    1122                 :            :                 /* TX queue function in primary, set by last queue initialized
    1123                 :            :                  * Tx queue may not initialized by primary process
    1124                 :            :                  */
    1125         [ #  # ]:          0 :                 if (eth_dev->data->tx_queues) {
    1126                 :          0 :                         txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues-1];
    1127                 :          0 :                         ixgbe_set_tx_function(eth_dev, txq);
    1128                 :            :                 } else {
    1129                 :            :                         /* Use default TX function if we get here */
    1130                 :          0 :                         PMD_INIT_LOG(NOTICE, "No TX queues configured yet. "
    1131                 :            :                                      "Using default TX function.");
    1132                 :            :                 }
    1133                 :            : 
    1134                 :          0 :                 ixgbe_set_rx_function(eth_dev);
    1135                 :            : 
    1136                 :          0 :                 return 0;
    1137                 :            :         }
    1138                 :            : 
    1139                 :            :         /* NOTE: review for potential ordering optimization */
    1140                 :          0 :         rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
    1141                 :          0 :         ixgbe_parse_devargs(eth_dev->data->dev_private,
    1142                 :            :                             pci_dev->device.devargs);
    1143                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
    1144                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    1145                 :            : 
    1146                 :            :         /* Vendor and Device ID need to be set before init of shared code */
    1147                 :          0 :         hw->device_id = pci_dev->id.device_id;
    1148                 :          0 :         hw->vendor_id = pci_dev->id.vendor_id;
    1149                 :          0 :         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
    1150                 :          0 :         hw->allow_unsupported_sfp = 1;
    1151                 :            : 
    1152                 :            :         /* Initialize the shared code (base driver) */
    1153                 :            : #ifdef RTE_LIBRTE_IXGBE_BYPASS
    1154                 :          0 :         diag = ixgbe_bypass_init_shared_code(hw);
    1155                 :            : #else
    1156                 :            :         diag = ixgbe_init_shared_code(hw);
    1157                 :            : #endif /* RTE_LIBRTE_IXGBE_BYPASS */
    1158                 :            : 
    1159         [ #  # ]:          0 :         if (diag != IXGBE_SUCCESS) {
    1160                 :          0 :                 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
    1161                 :          0 :                 return -EIO;
    1162                 :            :         }
    1163                 :            : 
    1164   [ #  #  #  # ]:          0 :         if (hw->mac.ops.fw_recovery_mode && hw->mac.ops.fw_recovery_mode(hw)) {
    1165                 :          0 :                 PMD_INIT_LOG(ERR, "ERROR: Firmware recovery mode detected. Limiting functionality.");
    1166                 :          0 :                 return -EIO;
    1167                 :            :         }
    1168                 :            : 
    1169                 :            :         /* pick up the PCI bus settings for reporting later */
    1170                 :          0 :         ixgbe_get_bus_info(hw);
    1171                 :            : 
    1172                 :            :         /* Unlock any pending hardware semaphore */
    1173                 :          0 :         ixgbe_swfw_lock_reset(hw);
    1174                 :            : 
    1175                 :            : #ifdef RTE_LIB_SECURITY
    1176                 :            :         /* Initialize security_ctx only for primary process*/
    1177         [ #  # ]:          0 :         if (ixgbe_ipsec_ctx_create(eth_dev))
    1178                 :            :                 return -ENOMEM;
    1179                 :            : #endif
    1180                 :            : 
    1181                 :            :         /* Initialize DCB configuration*/
    1182                 :            :         memset(dcb_config, 0, sizeof(struct ixgbe_dcb_config));
    1183                 :          0 :         ixgbe_dcb_init(hw, dcb_config);
    1184                 :            :         /* Get Hardware Flow Control setting */
    1185                 :          0 :         hw->fc.requested_mode = ixgbe_fc_none;
    1186                 :          0 :         hw->fc.current_mode = ixgbe_fc_none;
    1187                 :          0 :         hw->fc.pause_time = IXGBE_FC_PAUSE;
    1188         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
    1189                 :          0 :                 hw->fc.low_water[i] = IXGBE_FC_LO;
    1190                 :          0 :                 hw->fc.high_water[i] = IXGBE_FC_HI;
    1191                 :            :         }
    1192                 :          0 :         hw->fc.send_xon = 1;
    1193                 :            : 
    1194                 :            :         /* Make sure we have a good EEPROM before we read from it */
    1195                 :          0 :         diag = ixgbe_validate_eeprom_checksum(hw, &csum);
    1196         [ #  # ]:          0 :         if (diag != IXGBE_SUCCESS) {
    1197                 :          0 :                 PMD_INIT_LOG(ERR, "The EEPROM checksum is not valid: %d", diag);
    1198                 :            :                 ret = -EIO;
    1199                 :          0 :                 goto err_exit;
    1200                 :            :         }
    1201                 :            : 
    1202                 :            : #ifdef RTE_LIBRTE_IXGBE_BYPASS
    1203                 :          0 :         diag = ixgbe_bypass_init_hw(hw);
    1204                 :            : #else
    1205                 :            :         diag = ixgbe_init_hw(hw);
    1206                 :            : #endif /* RTE_LIBRTE_IXGBE_BYPASS */
    1207                 :            : 
    1208                 :            :         /*
    1209                 :            :          * Devices with copper phys will fail to initialise if ixgbe_init_hw()
    1210                 :            :          * is called too soon after the kernel driver unbinding/binding occurs.
    1211                 :            :          * The failure occurs in ixgbe_identify_phy_generic() for all devices,
    1212                 :            :          * but for non-copper devies, ixgbe_identify_sfp_module_generic() is
    1213                 :            :          * also called. See ixgbe_identify_phy_82599(). The reason for the
    1214                 :            :          * failure is not known, and only occuts when virtualisation features
    1215                 :            :          * are disabled in the bios. A delay of 100ms  was found to be enough by
    1216                 :            :          * trial-and-error, and is doubled to be safe.
    1217                 :            :          */
    1218   [ #  #  #  # ]:          0 :         if (diag && (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)) {
    1219                 :            :                 rte_delay_ms(200);
    1220                 :          0 :                 diag = ixgbe_init_hw(hw);
    1221                 :            :         }
    1222                 :            : 
    1223         [ #  # ]:          0 :         if (diag == IXGBE_ERR_SFP_NOT_PRESENT)
    1224                 :            :                 diag = IXGBE_SUCCESS;
    1225                 :            : 
    1226         [ #  # ]:          0 :         if (diag == IXGBE_ERR_EEPROM_VERSION) {
    1227                 :          0 :                 PMD_INIT_LOG(ERR, "This device is a pre-production adapter/"
    1228                 :            :                              "LOM.  Please be aware there may be issues associated "
    1229                 :            :                              "with your hardware.");
    1230                 :          0 :                 PMD_INIT_LOG(ERR, "If you are experiencing problems "
    1231                 :            :                              "please contact your Intel or hardware representative "
    1232                 :            :                              "who provided you with this hardware.");
    1233         [ #  # ]:          0 :         } else if (diag == IXGBE_ERR_SFP_NOT_SUPPORTED)
    1234                 :          0 :                 PMD_INIT_LOG(ERR, "Unsupported SFP+ Module");
    1235         [ #  # ]:          0 :         if (diag) {
    1236                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware Initialization Failure: %d", diag);
    1237                 :            :                 ret = -EIO;
    1238                 :          0 :                 goto err_exit;
    1239                 :            :         }
    1240                 :            : 
    1241                 :            :         /* Reset the hw statistics */
    1242                 :          0 :         ixgbe_dev_stats_reset(eth_dev);
    1243                 :            : 
    1244                 :            :         /* disable interrupt */
    1245                 :          0 :         ixgbe_disable_intr(hw);
    1246                 :            : 
    1247                 :            :         /* reset mappings for queue statistics hw counters*/
    1248                 :            :         ixgbe_reset_qstat_mappings(hw);
    1249                 :            : 
    1250                 :            :         /* Allocate memory for storing MAC addresses */
    1251                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("ixgbe", RTE_ETHER_ADDR_LEN *
    1252                 :          0 :                                                hw->mac.num_rar_entries, 0);
    1253         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    1254                 :          0 :                 PMD_INIT_LOG(ERR,
    1255                 :            :                              "Failed to allocate %u bytes needed to store "
    1256                 :            :                              "MAC addresses",
    1257                 :            :                              RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
    1258                 :            :                 ret = -ENOMEM;
    1259                 :          0 :                 goto err_exit;
    1260                 :            :         }
    1261                 :            :         /* Copy the permanent MAC address */
    1262                 :            :         rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.perm_addr,
    1263                 :            :                         &eth_dev->data->mac_addrs[0]);
    1264                 :            : 
    1265                 :            :         /* Allocate memory for storing hash filter MAC addresses */
    1266                 :          0 :         eth_dev->data->hash_mac_addrs = rte_zmalloc(
    1267                 :            :                 "ixgbe", RTE_ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC, 0);
    1268         [ #  # ]:          0 :         if (eth_dev->data->hash_mac_addrs == NULL) {
    1269                 :          0 :                 PMD_INIT_LOG(ERR,
    1270                 :            :                              "Failed to allocate %d bytes needed to store MAC addresses",
    1271                 :            :                              RTE_ETHER_ADDR_LEN * IXGBE_VMDQ_NUM_UC_MAC);
    1272                 :          0 :                 rte_free(eth_dev->data->mac_addrs);
    1273                 :          0 :                 eth_dev->data->mac_addrs = NULL;
    1274                 :            :                 ret = -ENOMEM;
    1275                 :          0 :                 goto err_exit;
    1276                 :            :         }
    1277                 :            : 
    1278                 :            :         /* initialize the vfta */
    1279                 :            :         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
    1280                 :            : 
    1281                 :            :         /* initialize the hw strip bitmap*/
    1282                 :            :         memset(hwstrip, 0, sizeof(*hwstrip));
    1283                 :            : 
    1284                 :            :         /* initialize PF if max_vfs not zero */
    1285                 :          0 :         ret = ixgbe_pf_host_init(eth_dev);
    1286         [ #  # ]:          0 :         if (ret)
    1287                 :          0 :                 goto err_pf_host_init;
    1288                 :            : 
    1289                 :          0 :         ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
    1290                 :            :         /* let hardware know driver is loaded */
    1291                 :            :         ctrl_ext |= IXGBE_CTRL_EXT_DRV_LOAD;
    1292                 :            :         /* Set PF Reset Done bit so PF/VF Mail Ops can work */
    1293                 :          0 :         ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
    1294                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
    1295                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1296                 :            : 
    1297   [ #  #  #  # ]:          0 :         if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
    1298                 :          0 :                 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d, SFP+: %d",
    1299                 :            :                              (int) hw->mac.type, (int) hw->phy.type,
    1300                 :            :                              (int) hw->phy.sfp_type);
    1301                 :            :         else
    1302                 :          0 :                 PMD_INIT_LOG(DEBUG, "MAC: %d, PHY: %d",
    1303                 :            :                              (int) hw->mac.type, (int) hw->phy.type);
    1304                 :            : 
    1305                 :          0 :         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
    1306                 :            :                      eth_dev->data->port_id, pci_dev->id.vendor_id,
    1307                 :            :                      pci_dev->id.device_id);
    1308                 :            : 
    1309                 :          0 :         rte_intr_callback_register(intr_handle,
    1310                 :            :                                    ixgbe_dev_interrupt_handler, eth_dev);
    1311                 :            : 
    1312                 :            :         /* enable uio/vfio intr/eventfd mapping */
    1313                 :          0 :         rte_intr_enable(intr_handle);
    1314                 :            : 
    1315                 :            :         /* enable support intr */
    1316                 :            :         ixgbe_enable_intr(eth_dev);
    1317                 :            : 
    1318                 :            :         /* initialize filter info */
    1319                 :            :         memset(filter_info, 0,
    1320                 :            :                sizeof(struct ixgbe_filter_info));
    1321                 :            : 
    1322                 :            :         /* initialize 5tuple filter list */
    1323                 :          0 :         TAILQ_INIT(&filter_info->fivetuple_list);
    1324                 :            : 
    1325                 :            :         /* initialize flow director filter list & hash */
    1326                 :          0 :         ret = ixgbe_fdir_filter_init(eth_dev);
    1327         [ #  # ]:          0 :         if (ret)
    1328                 :          0 :                 goto err_fdir_filter_init;
    1329                 :            : 
    1330                 :            :         /* initialize l2 tunnel filter list & hash */
    1331                 :          0 :         ret = ixgbe_l2_tn_filter_init(eth_dev);
    1332         [ #  # ]:          0 :         if (ret)
    1333                 :          0 :                 goto err_l2_tn_filter_init;
    1334                 :            : 
    1335                 :            :         /* initialize flow filter lists */
    1336                 :          0 :         ixgbe_filterlist_init();
    1337                 :            : 
    1338                 :            :         /* initialize bandwidth configuration info */
    1339                 :            :         memset(bw_conf, 0, sizeof(struct ixgbe_bw_conf));
    1340                 :            : 
    1341                 :            :         /* initialize Traffic Manager configuration */
    1342                 :          0 :         ixgbe_tm_conf_init(eth_dev);
    1343                 :            : 
    1344                 :          0 :         return 0;
    1345                 :            : 
    1346                 :            : err_l2_tn_filter_init:
    1347                 :          0 :         ixgbe_fdir_filter_uninit(eth_dev);
    1348                 :          0 : err_fdir_filter_init:
    1349                 :          0 :         ixgbe_disable_intr(hw);
    1350                 :          0 :         rte_intr_disable(intr_handle);
    1351                 :          0 :         rte_intr_callback_unregister(intr_handle,
    1352                 :            :                 ixgbe_dev_interrupt_handler, eth_dev);
    1353                 :          0 :         ixgbe_pf_host_uninit(eth_dev);
    1354                 :          0 : err_pf_host_init:
    1355                 :          0 :         rte_free(eth_dev->data->mac_addrs);
    1356                 :          0 :         eth_dev->data->mac_addrs = NULL;
    1357                 :          0 :         rte_free(eth_dev->data->hash_mac_addrs);
    1358                 :          0 :         eth_dev->data->hash_mac_addrs = NULL;
    1359                 :          0 : err_exit:
    1360                 :            : #ifdef RTE_LIB_SECURITY
    1361                 :          0 :         rte_free(eth_dev->security_ctx);
    1362                 :          0 :         eth_dev->security_ctx = NULL;
    1363                 :            : #endif
    1364                 :          0 :         return ret;
    1365                 :            : }
    1366                 :            : 
    1367                 :            : static int
    1368                 :          0 : eth_ixgbe_dev_uninit(struct rte_eth_dev *eth_dev)
    1369                 :            : {
    1370                 :          0 :         PMD_INIT_FUNC_TRACE();
    1371                 :            : 
    1372         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1373                 :            :                 return 0;
    1374                 :            : 
    1375                 :          0 :         ixgbe_dev_close(eth_dev);
    1376                 :            : 
    1377                 :          0 :         return 0;
    1378                 :            : }
    1379                 :            : 
    1380                 :          0 : static int ixgbe_ntuple_filter_uninit(struct rte_eth_dev *eth_dev)
    1381                 :            : {
    1382                 :            :         struct ixgbe_filter_info *filter_info =
    1383                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
    1384                 :            :         struct ixgbe_5tuple_filter *p_5tuple;
    1385                 :            : 
    1386         [ #  # ]:          0 :         while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list))) {
    1387         [ #  # ]:          0 :                 TAILQ_REMOVE(&filter_info->fivetuple_list,
    1388                 :            :                              p_5tuple,
    1389                 :            :                              entries);
    1390                 :          0 :                 rte_free(p_5tuple);
    1391                 :            :         }
    1392                 :          0 :         memset(filter_info->fivetuple_mask, 0,
    1393                 :            :                sizeof(uint32_t) * IXGBE_5TUPLE_ARRAY_SIZE);
    1394                 :            : 
    1395                 :          0 :         return 0;
    1396                 :            : }
    1397                 :            : 
    1398                 :          0 : static int ixgbe_fdir_filter_uninit(struct rte_eth_dev *eth_dev)
    1399                 :            : {
    1400                 :            :         struct ixgbe_hw_fdir_info *fdir_info =
    1401                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
    1402                 :            :         struct ixgbe_fdir_filter *fdir_filter;
    1403                 :            : 
    1404                 :          0 :         rte_free(fdir_info->hash_map);
    1405                 :          0 :         rte_hash_free(fdir_info->hash_handle);
    1406                 :            : 
    1407         [ #  # ]:          0 :         while ((fdir_filter = TAILQ_FIRST(&fdir_info->fdir_list))) {
    1408         [ #  # ]:          0 :                 TAILQ_REMOVE(&fdir_info->fdir_list,
    1409                 :            :                              fdir_filter,
    1410                 :            :                              entries);
    1411                 :          0 :                 rte_free(fdir_filter);
    1412                 :            :         }
    1413                 :            : 
    1414                 :          0 :         return 0;
    1415                 :            : }
    1416                 :            : 
    1417                 :          0 : static int ixgbe_l2_tn_filter_uninit(struct rte_eth_dev *eth_dev)
    1418                 :            : {
    1419                 :            :         struct ixgbe_l2_tn_info *l2_tn_info =
    1420                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
    1421                 :            :         struct ixgbe_l2_tn_filter *l2_tn_filter;
    1422                 :            : 
    1423                 :          0 :         rte_free(l2_tn_info->hash_map);
    1424                 :          0 :         rte_hash_free(l2_tn_info->hash_handle);
    1425                 :            : 
    1426         [ #  # ]:          0 :         while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
    1427         [ #  # ]:          0 :                 TAILQ_REMOVE(&l2_tn_info->l2_tn_list,
    1428                 :            :                              l2_tn_filter,
    1429                 :            :                              entries);
    1430                 :          0 :                 rte_free(l2_tn_filter);
    1431                 :            :         }
    1432                 :            : 
    1433                 :          0 :         return 0;
    1434                 :            : }
    1435                 :            : 
    1436                 :          0 : static int ixgbe_fdir_filter_init(struct rte_eth_dev *eth_dev)
    1437                 :            : {
    1438                 :            :         struct ixgbe_hw_fdir_info *fdir_info =
    1439                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FDIR_INFO(eth_dev->data->dev_private);
    1440                 :            :         char fdir_hash_name[RTE_HASH_NAMESIZE];
    1441                 :          0 :         struct rte_hash_parameters fdir_hash_params = {
    1442                 :            :                 .name = fdir_hash_name,
    1443                 :            :                 .entries = IXGBE_MAX_FDIR_FILTER_NUM,
    1444                 :            :                 .key_len = sizeof(union ixgbe_atr_input),
    1445                 :            :                 .hash_func = rte_hash_crc,
    1446                 :            :                 .hash_func_init_val = 0,
    1447                 :          0 :                 .socket_id = rte_socket_id(),
    1448                 :            :         };
    1449                 :            : 
    1450                 :          0 :         TAILQ_INIT(&fdir_info->fdir_list);
    1451                 :          0 :         snprintf(fdir_hash_name, RTE_HASH_NAMESIZE,
    1452                 :          0 :                  "fdir_%s", eth_dev->device->name);
    1453                 :          0 :         fdir_info->hash_handle = rte_hash_create(&fdir_hash_params);
    1454         [ #  # ]:          0 :         if (!fdir_info->hash_handle) {
    1455                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to create fdir hash table!");
    1456                 :          0 :                 return -EINVAL;
    1457                 :            :         }
    1458                 :          0 :         fdir_info->hash_map = rte_zmalloc("ixgbe",
    1459                 :            :                                           sizeof(struct ixgbe_fdir_filter *) *
    1460                 :            :                                           IXGBE_MAX_FDIR_FILTER_NUM,
    1461                 :            :                                           0);
    1462         [ #  # ]:          0 :         if (!fdir_info->hash_map) {
    1463                 :          0 :                 PMD_INIT_LOG(ERR,
    1464                 :            :                              "Failed to allocate memory for fdir hash map!");
    1465                 :          0 :                 rte_hash_free(fdir_info->hash_handle);
    1466                 :          0 :                 return -ENOMEM;
    1467                 :            :         }
    1468                 :          0 :         fdir_info->mask_added = FALSE;
    1469                 :            : 
    1470                 :          0 :         return 0;
    1471                 :            : }
    1472                 :            : 
    1473                 :          0 : static int ixgbe_l2_tn_filter_init(struct rte_eth_dev *eth_dev)
    1474                 :            : {
    1475                 :            :         struct ixgbe_l2_tn_info *l2_tn_info =
    1476                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(eth_dev->data->dev_private);
    1477                 :            :         char l2_tn_hash_name[RTE_HASH_NAMESIZE];
    1478                 :          0 :         struct rte_hash_parameters l2_tn_hash_params = {
    1479                 :            :                 .name = l2_tn_hash_name,
    1480                 :            :                 .entries = IXGBE_MAX_L2_TN_FILTER_NUM,
    1481                 :            :                 .key_len = sizeof(struct ixgbe_l2_tn_key),
    1482                 :            :                 .hash_func = rte_hash_crc,
    1483                 :            :                 .hash_func_init_val = 0,
    1484                 :          0 :                 .socket_id = rte_socket_id(),
    1485                 :            :         };
    1486                 :            : 
    1487                 :          0 :         TAILQ_INIT(&l2_tn_info->l2_tn_list);
    1488                 :          0 :         snprintf(l2_tn_hash_name, RTE_HASH_NAMESIZE,
    1489                 :          0 :                  "l2_tn_%s", eth_dev->device->name);
    1490                 :          0 :         l2_tn_info->hash_handle = rte_hash_create(&l2_tn_hash_params);
    1491         [ #  # ]:          0 :         if (!l2_tn_info->hash_handle) {
    1492                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to create L2 TN hash table!");
    1493                 :          0 :                 return -EINVAL;
    1494                 :            :         }
    1495                 :          0 :         l2_tn_info->hash_map = rte_zmalloc("ixgbe",
    1496                 :            :                                    sizeof(struct ixgbe_l2_tn_filter *) *
    1497                 :            :                                    IXGBE_MAX_L2_TN_FILTER_NUM,
    1498                 :            :                                    0);
    1499         [ #  # ]:          0 :         if (!l2_tn_info->hash_map) {
    1500                 :          0 :                 PMD_INIT_LOG(ERR,
    1501                 :            :                         "Failed to allocate memory for L2 TN hash map!");
    1502                 :          0 :                 rte_hash_free(l2_tn_info->hash_handle);
    1503                 :          0 :                 return -ENOMEM;
    1504                 :            :         }
    1505                 :          0 :         l2_tn_info->e_tag_en = FALSE;
    1506                 :          0 :         l2_tn_info->e_tag_fwd_en = FALSE;
    1507                 :          0 :         l2_tn_info->e_tag_ether_type = RTE_ETHER_TYPE_ETAG;
    1508                 :            : 
    1509                 :          0 :         return 0;
    1510                 :            : }
    1511                 :            : /*
    1512                 :            :  * Negotiate mailbox API version with the PF.
    1513                 :            :  * After reset API version is always set to the basic one (ixgbe_mbox_api_10).
    1514                 :            :  * Then we try to negotiate starting with the most recent one.
    1515                 :            :  * If all negotiation attempts fail, then we will proceed with
    1516                 :            :  * the default one (ixgbe_mbox_api_10).
    1517                 :            :  */
    1518                 :            : static void
    1519                 :          0 : ixgbevf_negotiate_api(struct ixgbe_hw *hw)
    1520                 :            : {
    1521                 :            :         int32_t i;
    1522                 :            : 
    1523                 :            :         /* start with highest supported, proceed down */
    1524                 :            :         static const enum ixgbe_pfvf_api_rev sup_ver[] = {
    1525                 :            :                 ixgbe_mbox_api_13,
    1526                 :            :                 ixgbe_mbox_api_12,
    1527                 :            :                 ixgbe_mbox_api_11,
    1528                 :            :                 ixgbe_mbox_api_10,
    1529                 :            :         };
    1530                 :            : 
    1531                 :          0 :         for (i = 0;
    1532   [ #  #  #  # ]:          0 :                         i != RTE_DIM(sup_ver) &&
    1533                 :          0 :                         ixgbevf_negotiate_api_version(hw, sup_ver[i]) != 0;
    1534                 :          0 :                         i++)
    1535                 :            :                 ;
    1536                 :          0 : }
    1537                 :            : 
    1538                 :            : static void
    1539                 :          0 : generate_random_mac_addr(struct rte_ether_addr *mac_addr)
    1540                 :            : {
    1541                 :            :         uint64_t random;
    1542                 :            : 
    1543                 :            :         /* Set Organizationally Unique Identifier (OUI) prefix. */
    1544                 :            :         mac_addr->addr_bytes[0] = 0x00;
    1545                 :          0 :         mac_addr->addr_bytes[1] = 0x09;
    1546                 :          0 :         mac_addr->addr_bytes[2] = 0xC0;
    1547                 :            :         /* Force indication of locally assigned MAC address. */
    1548                 :          0 :         mac_addr->addr_bytes[0] |= RTE_ETHER_LOCAL_ADMIN_ADDR;
    1549                 :            :         /* Generate the last 3 bytes of the MAC address with a random number. */
    1550                 :          0 :         random = rte_rand();
    1551                 :          0 :         memcpy(&mac_addr->addr_bytes[3], &random, 3);
    1552                 :          0 : }
    1553                 :            : 
    1554                 :            : static int
    1555                 :          0 : devarg_handle_int(__rte_unused const char *key, const char *value,
    1556                 :            :                   void *extra_args)
    1557                 :            : {
    1558                 :            :         uint16_t *n = extra_args;
    1559                 :            : 
    1560         [ #  # ]:          0 :         if (value == NULL || extra_args == NULL)
    1561                 :            :                 return -EINVAL;
    1562                 :            : 
    1563                 :          0 :         *n = (uint16_t)strtoul(value, NULL, 0);
    1564   [ #  #  #  # ]:          0 :         if (*n == USHRT_MAX && errno == ERANGE)
    1565                 :          0 :                 return -1;
    1566                 :            : 
    1567                 :            :         return 0;
    1568                 :            : }
    1569                 :            : 
    1570                 :            : static void
    1571                 :          0 : ixgbevf_parse_devargs(struct ixgbe_adapter *adapter,
    1572                 :            :                       struct rte_devargs *devargs)
    1573                 :            : {
    1574                 :            :         struct rte_kvargs *kvlist;
    1575                 :            :         uint16_t pflink_fullchk;
    1576                 :            : 
    1577         [ #  # ]:          0 :         if (devargs == NULL)
    1578                 :          0 :                 return;
    1579                 :            : 
    1580                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, ixgbevf_valid_arguments);
    1581         [ #  # ]:          0 :         if (kvlist == NULL)
    1582                 :            :                 return;
    1583                 :            : 
    1584   [ #  #  #  # ]:          0 :         if (rte_kvargs_count(kvlist, IXGBEVF_DEVARG_PFLINK_FULLCHK) == 1 &&
    1585                 :          0 :             rte_kvargs_process(kvlist, IXGBEVF_DEVARG_PFLINK_FULLCHK,
    1586                 :          0 :                                devarg_handle_int, &pflink_fullchk) == 0 &&
    1587         [ #  # ]:          0 :             pflink_fullchk == 1)
    1588                 :          0 :                 adapter->pflink_fullchk = 1;
    1589                 :            : 
    1590                 :          0 :         rte_kvargs_free(kvlist);
    1591                 :            : }
    1592                 :            : 
    1593                 :            : /*
    1594                 :            :  * Virtual Function device init
    1595                 :            :  */
    1596                 :            : static int
    1597                 :          0 : eth_ixgbevf_dev_init(struct rte_eth_dev *eth_dev)
    1598                 :            : {
    1599                 :            :         int diag;
    1600                 :            :         uint32_t tc, tcs;
    1601                 :          0 :         struct ixgbe_adapter *ad = eth_dev->data->dev_private;
    1602                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    1603                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1604                 :          0 :         struct ixgbe_hw *hw =
    1605                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
    1606                 :          0 :         struct ixgbe_vfta *shadow_vfta =
    1607                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
    1608                 :          0 :         struct ixgbe_hwstrip *hwstrip =
    1609                 :            :                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(eth_dev->data->dev_private);
    1610                 :          0 :         struct rte_ether_addr *perm_addr =
    1611                 :            :                 (struct rte_ether_addr *)hw->mac.perm_addr;
    1612                 :            : 
    1613                 :          0 :         PMD_INIT_FUNC_TRACE();
    1614                 :            : 
    1615                 :          0 :         eth_dev->dev_ops = &ixgbevf_eth_dev_ops;
    1616                 :          0 :         eth_dev->rx_descriptor_status = ixgbe_dev_rx_descriptor_status;
    1617                 :          0 :         eth_dev->tx_descriptor_status = ixgbe_dev_tx_descriptor_status;
    1618                 :          0 :         eth_dev->rx_pkt_burst = &ixgbe_recv_pkts;
    1619                 :          0 :         eth_dev->tx_pkt_burst = &ixgbe_xmit_pkts;
    1620                 :            : 
    1621                 :            :         /* for secondary processes, we don't initialise any further as primary
    1622                 :            :          * has already done this work. Only check we don't need a different
    1623                 :            :          * RX function
    1624                 :            :          */
    1625         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
    1626                 :            :                 struct ci_tx_queue *txq;
    1627                 :            :                 /* TX queue function in primary, set by last queue initialized
    1628                 :            :                  * Tx queue may not initialized by primary process
    1629                 :            :                  */
    1630         [ #  # ]:          0 :                 if (eth_dev->data->tx_queues) {
    1631                 :          0 :                         txq = eth_dev->data->tx_queues[eth_dev->data->nb_tx_queues - 1];
    1632                 :          0 :                         ixgbe_set_tx_function(eth_dev, txq);
    1633                 :            :                 } else {
    1634                 :            :                         /* Use default TX function if we get here */
    1635                 :          0 :                         PMD_INIT_LOG(NOTICE,
    1636                 :            :                                      "No TX queues configured yet. Using default TX function.");
    1637                 :            :                 }
    1638                 :            : 
    1639                 :          0 :                 ixgbe_set_rx_function(eth_dev);
    1640                 :            : 
    1641                 :          0 :                 return 0;
    1642                 :            :         }
    1643                 :            : 
    1644                 :            :         /* NOTE: review for potential ordering optimization */
    1645                 :          0 :         rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
    1646                 :          0 :         ixgbevf_parse_devargs(eth_dev->data->dev_private,
    1647                 :            :                               pci_dev->device.devargs);
    1648                 :            : 
    1649                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
    1650                 :          0 :         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
    1651                 :            : 
    1652                 :          0 :         hw->device_id = pci_dev->id.device_id;
    1653                 :          0 :         hw->vendor_id = pci_dev->id.vendor_id;
    1654                 :          0 :         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
    1655                 :            : 
    1656                 :            :         /* initialize the vfta */
    1657                 :            :         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
    1658                 :            : 
    1659                 :            :         /* initialize the hw strip bitmap*/
    1660                 :            :         memset(hwstrip, 0, sizeof(*hwstrip));
    1661                 :            : 
    1662                 :            :         /* Initialize the shared code (base driver) */
    1663                 :          0 :         diag = ixgbe_init_shared_code(hw);
    1664         [ #  # ]:          0 :         if (diag != IXGBE_SUCCESS) {
    1665                 :          0 :                 PMD_INIT_LOG(ERR, "Shared code init failed for ixgbevf: %d", diag);
    1666                 :          0 :                 return -EIO;
    1667                 :            :         }
    1668                 :            : 
    1669                 :            :         /* init_mailbox_params */
    1670                 :          0 :         hw->mbx.ops[0].init_params(hw);
    1671                 :            : 
    1672                 :            :         /* Reset the hw statistics */
    1673                 :            :         ixgbevf_dev_stats_reset(eth_dev);
    1674                 :            : 
    1675                 :            :         /* Disable the interrupts for VF */
    1676                 :          0 :         ixgbevf_intr_disable(eth_dev);
    1677                 :            : 
    1678                 :          0 :         hw->mac.num_rar_entries = 128; /* The MAX of the underlying PF */
    1679                 :          0 :         diag = hw->mac.ops.reset_hw(hw);
    1680                 :            : 
    1681                 :            :         /*
    1682                 :            :          * The VF reset operation returns the IXGBE_ERR_INVALID_MAC_ADDR when
    1683                 :            :          * the underlying PF driver has not assigned a MAC address to the VF.
    1684                 :            :          * In this case, assign a random MAC address.
    1685                 :            :          */
    1686         [ #  # ]:          0 :         if ((diag != IXGBE_SUCCESS) && (diag != IXGBE_ERR_INVALID_MAC_ADDR)) {
    1687                 :          0 :                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
    1688                 :            :                 /*
    1689                 :            :                  * This error code will be propagated to the app by
    1690                 :            :                  * rte_eth_dev_reset, so use a public error code rather than
    1691                 :            :                  * the internal-only IXGBE_ERR_RESET_FAILED
    1692                 :            :                  */
    1693                 :          0 :                 return -EAGAIN;
    1694                 :            :         }
    1695                 :            : 
    1696                 :            :         /* negotiate mailbox API version to use with the PF. */
    1697                 :          0 :         ixgbevf_negotiate_api(hw);
    1698                 :            : 
    1699                 :            :         /* Get Rx/Tx queue count via mailbox, which is ready after reset_hw */
    1700                 :          0 :         ixgbevf_get_queues(hw, &tcs, &tc);
    1701                 :            : 
    1702                 :            :         /* Allocate memory for storing MAC addresses */
    1703                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("ixgbevf", RTE_ETHER_ADDR_LEN *
    1704                 :          0 :                                                hw->mac.num_rar_entries, 0);
    1705         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    1706                 :          0 :                 PMD_INIT_LOG(ERR,
    1707                 :            :                              "Failed to allocate %u bytes needed to store "
    1708                 :            :                              "MAC addresses",
    1709                 :            :                              RTE_ETHER_ADDR_LEN * hw->mac.num_rar_entries);
    1710                 :          0 :                 return -ENOMEM;
    1711                 :            :         }
    1712                 :            : 
    1713                 :            :         /* Generate a random MAC address, if none was assigned by PF. */
    1714         [ #  # ]:          0 :         if (rte_is_zero_ether_addr(perm_addr)) {
    1715                 :          0 :                 generate_random_mac_addr(perm_addr);
    1716                 :          0 :                 diag = ixgbe_set_rar_vf(hw, 1, perm_addr->addr_bytes, 0, 1);
    1717         [ #  # ]:          0 :                 if (diag) {
    1718                 :          0 :                         rte_free(eth_dev->data->mac_addrs);
    1719                 :          0 :                         eth_dev->data->mac_addrs = NULL;
    1720                 :          0 :                         return diag;
    1721                 :            :                 }
    1722                 :          0 :                 PMD_INIT_LOG(INFO, "\tVF MAC address not assigned by Host PF");
    1723                 :          0 :                 PMD_INIT_LOG(INFO, "\tAssign randomly generated MAC address "
    1724                 :            :                              RTE_ETHER_ADDR_PRT_FMT,
    1725                 :            :                                  RTE_ETHER_ADDR_BYTES(perm_addr));
    1726                 :            :         }
    1727                 :            : 
    1728                 :            :         /* Copy the permanent MAC address */
    1729                 :          0 :         rte_ether_addr_copy(perm_addr, &eth_dev->data->mac_addrs[0]);
    1730                 :            : 
    1731                 :            :         /* reset the hardware with the new settings */
    1732                 :          0 :         diag = hw->mac.ops.start_hw(hw);
    1733         [ #  # ]:          0 :         switch (diag) {
    1734                 :            :         case  0:
    1735                 :            :                 break;
    1736                 :            : 
    1737                 :          0 :         default:
    1738                 :          0 :                 PMD_INIT_LOG(ERR, "VF Initialization Failure: %d", diag);
    1739                 :          0 :                 rte_free(eth_dev->data->mac_addrs);
    1740                 :          0 :                 eth_dev->data->mac_addrs = NULL;
    1741                 :          0 :                 return -EIO;
    1742                 :            :         }
    1743                 :            : 
    1744                 :          0 :         rte_intr_callback_register(intr_handle,
    1745                 :            :                                    ixgbevf_dev_interrupt_handler, eth_dev);
    1746                 :          0 :         rte_intr_enable(intr_handle);
    1747                 :          0 :         ixgbevf_intr_enable(eth_dev);
    1748                 :            : 
    1749                 :          0 :         PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x mac.type=%s",
    1750                 :            :                      eth_dev->data->port_id, pci_dev->id.vendor_id,
    1751                 :            :                      pci_dev->id.device_id, "ixgbe_mac_82599_vf");
    1752                 :            : 
    1753                 :          0 :         return 0;
    1754                 :            : }
    1755                 :            : 
    1756                 :            : /* Virtual Function device uninit */
    1757                 :            : 
    1758                 :            : static int
    1759                 :          0 : eth_ixgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
    1760                 :            : {
    1761                 :          0 :         PMD_INIT_FUNC_TRACE();
    1762                 :            : 
    1763         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1764                 :            :                 return 0;
    1765                 :            : 
    1766                 :          0 :         ixgbevf_dev_close(eth_dev);
    1767                 :            : 
    1768                 :          0 :         return 0;
    1769                 :            : }
    1770                 :            : 
    1771                 :            : static int
    1772                 :          0 : eth_ixgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
    1773                 :            :                 struct rte_pci_device *pci_dev)
    1774                 :            : {
    1775                 :            :         char name[RTE_ETH_NAME_MAX_LEN];
    1776                 :            :         struct rte_eth_dev *pf_ethdev;
    1777                 :            :         struct rte_eth_devargs eth_da;
    1778                 :            :         int i, retval;
    1779                 :            : 
    1780         [ #  # ]:          0 :         if (pci_dev->device.devargs) {
    1781                 :          0 :                 retval = rte_eth_devargs_parse(pci_dev->device.devargs->args,
    1782                 :            :                                 &eth_da, 1);
    1783         [ #  # ]:          0 :                 if (retval < 0)
    1784                 :            :                         return retval;
    1785                 :            :         } else
    1786                 :            :                 memset(&eth_da, 0, sizeof(eth_da));
    1787                 :            : 
    1788         [ #  # ]:          0 :         if (eth_da.nb_representor_ports > 0 &&
    1789         [ #  # ]:          0 :             eth_da.type != RTE_ETH_REPRESENTOR_VF) {
    1790                 :          0 :                 PMD_DRV_LOG(ERR, "unsupported representor type: %s",
    1791                 :            :                             pci_dev->device.devargs->args);
    1792                 :          0 :                 return -ENOTSUP;
    1793                 :            :         }
    1794                 :            : 
    1795                 :          0 :         retval = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
    1796                 :            :                 sizeof(struct ixgbe_adapter),
    1797                 :            :                 eth_dev_pci_specific_init, pci_dev,
    1798                 :            :                 eth_ixgbe_dev_init, NULL);
    1799                 :            : 
    1800   [ #  #  #  # ]:          0 :         if (retval || eth_da.nb_representor_ports < 1)
    1801                 :            :                 return retval;
    1802                 :            : 
    1803                 :          0 :         pf_ethdev = rte_eth_dev_allocated(pci_dev->device.name);
    1804         [ #  # ]:          0 :         if (pf_ethdev == NULL)
    1805                 :            :                 return -ENODEV;
    1806                 :            : 
    1807                 :            :         /* probe VF representor ports */
    1808         [ #  # ]:          0 :         for (i = 0; i < eth_da.nb_representor_ports; i++) {
    1809                 :            :                 struct ixgbe_vf_info *vfinfo;
    1810                 :            :                 struct ixgbe_vf_representor representor;
    1811                 :            : 
    1812                 :          0 :                 vfinfo = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(
    1813                 :            :                         pf_ethdev->data->dev_private);
    1814         [ #  # ]:          0 :                 if (vfinfo == NULL) {
    1815                 :          0 :                         PMD_DRV_LOG(ERR,
    1816                 :            :                                 "no virtual functions supported by PF");
    1817                 :          0 :                         break;
    1818                 :            :                 }
    1819                 :            : 
    1820                 :          0 :                 representor.vf_id = eth_da.representor_ports[i];
    1821                 :          0 :                 representor.switch_domain_id = vfinfo->switch_domain_id;
    1822                 :          0 :                 representor.pf_ethdev = pf_ethdev;
    1823                 :            : 
    1824                 :            :                 /* representor port net_bdf_port */
    1825                 :          0 :                 snprintf(name, sizeof(name), "net_%s_representor_%d",
    1826                 :            :                         pci_dev->device.name,
    1827                 :            :                         eth_da.representor_ports[i]);
    1828                 :            : 
    1829                 :          0 :                 retval = rte_eth_dev_create(&pci_dev->device, name,
    1830                 :            :                         sizeof(struct ixgbe_vf_representor), NULL, NULL,
    1831                 :            :                         ixgbe_vf_representor_init, &representor);
    1832                 :            : 
    1833         [ #  # ]:          0 :                 if (retval)
    1834                 :          0 :                         PMD_DRV_LOG(ERR, "failed to create ixgbe vf "
    1835                 :            :                                 "representor %s.", name);
    1836                 :            :         }
    1837                 :            : 
    1838                 :            :         return 0;
    1839                 :            : }
    1840                 :            : 
    1841                 :          0 : static int eth_ixgbe_pci_remove(struct rte_pci_device *pci_dev)
    1842                 :            : {
    1843                 :            :         struct rte_eth_dev *ethdev;
    1844                 :            : 
    1845                 :          0 :         ethdev = rte_eth_dev_allocated(pci_dev->device.name);
    1846         [ #  # ]:          0 :         if (!ethdev)
    1847                 :            :                 return 0;
    1848                 :            : 
    1849         [ #  # ]:          0 :         if (rte_eth_dev_is_repr(ethdev))
    1850                 :          0 :                 return rte_eth_dev_pci_generic_remove(pci_dev,
    1851                 :            :                                         ixgbe_vf_representor_uninit);
    1852                 :            :         else
    1853                 :          0 :                 return rte_eth_dev_pci_generic_remove(pci_dev,
    1854                 :            :                                                 eth_ixgbe_dev_uninit);
    1855                 :            : }
    1856                 :            : 
    1857                 :            : static struct rte_pci_driver rte_ixgbe_pmd = {
    1858                 :            :         .id_table = pci_id_ixgbe_map,
    1859                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
    1860                 :            :         .probe = eth_ixgbe_pci_probe,
    1861                 :            :         .remove = eth_ixgbe_pci_remove,
    1862                 :            : };
    1863                 :            : 
    1864                 :          0 : static int eth_ixgbevf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
    1865                 :            :         struct rte_pci_device *pci_dev)
    1866                 :            : {
    1867                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev,
    1868                 :            :                 sizeof(struct ixgbe_adapter), eth_ixgbevf_dev_init);
    1869                 :            : }
    1870                 :            : 
    1871                 :          0 : static int eth_ixgbevf_pci_remove(struct rte_pci_device *pci_dev)
    1872                 :            : {
    1873                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, eth_ixgbevf_dev_uninit);
    1874                 :            : }
    1875                 :            : 
    1876                 :            : /*
    1877                 :            :  * virtual function driver struct
    1878                 :            :  */
    1879                 :            : static struct rte_pci_driver rte_ixgbevf_pmd = {
    1880                 :            :         .id_table = pci_id_ixgbevf_map,
    1881                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
    1882                 :            :         .probe = eth_ixgbevf_pci_probe,
    1883                 :            :         .remove = eth_ixgbevf_pci_remove,
    1884                 :            : };
    1885                 :            : 
    1886                 :            : static int
    1887                 :          0 : ixgbe_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
    1888                 :            : {
    1889                 :            :         struct ixgbe_hw *hw =
    1890                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1891                 :            :         struct ixgbe_vfta *shadow_vfta =
    1892                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    1893                 :            :         uint32_t vfta;
    1894                 :            :         uint32_t vid_idx;
    1895                 :            :         uint32_t vid_bit;
    1896                 :            : 
    1897                 :          0 :         vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
    1898                 :          0 :         vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
    1899                 :          0 :         vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(vid_idx));
    1900         [ #  # ]:          0 :         if (on)
    1901                 :          0 :                 vfta |= vid_bit;
    1902                 :            :         else
    1903                 :          0 :                 vfta &= ~vid_bit;
    1904                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VFTA(vid_idx), vfta);
    1905                 :            : 
    1906                 :            :         /* update local VFTA copy */
    1907                 :          0 :         shadow_vfta->vfta[vid_idx] = vfta;
    1908                 :            : 
    1909                 :          0 :         return 0;
    1910                 :            : }
    1911                 :            : 
    1912                 :            : static void
    1913                 :          0 : ixgbe_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
    1914                 :            : {
    1915         [ #  # ]:          0 :         if (on)
    1916                 :          0 :                 ixgbe_vlan_hw_strip_enable(dev, queue);
    1917                 :            :         else
    1918                 :          0 :                 ixgbe_vlan_hw_strip_disable(dev, queue);
    1919                 :          0 : }
    1920                 :            : 
    1921                 :            : static int
    1922                 :          0 : ixgbe_vlan_tpid_set(struct rte_eth_dev *dev,
    1923                 :            :                     enum rte_vlan_type vlan_type,
    1924                 :            :                     uint16_t tpid)
    1925                 :            : {
    1926                 :            :         struct ixgbe_hw *hw =
    1927                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1928                 :            :         int ret = 0;
    1929                 :            :         uint32_t reg;
    1930                 :            :         uint32_t qinq;
    1931                 :            : 
    1932                 :          0 :         qinq = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
    1933                 :          0 :         qinq &= IXGBE_DMATXCTL_GDV;
    1934                 :            : 
    1935      [ #  #  # ]:          0 :         switch (vlan_type) {
    1936                 :          0 :         case RTE_ETH_VLAN_TYPE_INNER:
    1937         [ #  # ]:          0 :                 if (qinq) {
    1938                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    1939                 :          0 :                         reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
    1940                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
    1941                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
    1942                 :          0 :                         reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
    1943                 :          0 :                                 | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
    1944                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
    1945                 :            :                 } else {
    1946                 :            :                         ret = -ENOTSUP;
    1947                 :          0 :                         PMD_DRV_LOG(ERR, "Inner type is not supported"
    1948                 :            :                                     " by single VLAN");
    1949                 :            :                 }
    1950                 :            :                 break;
    1951                 :          0 :         case RTE_ETH_VLAN_TYPE_OUTER:
    1952         [ #  # ]:          0 :                 if (qinq) {
    1953                 :            :                         /* Only the high 16-bits is valid */
    1954                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_EXVET, (uint32_t)tpid <<
    1955                 :            :                                         IXGBE_EXVET_VET_EXT_SHIFT);
    1956                 :            :                 } else {
    1957                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    1958                 :          0 :                         reg = (reg & (~IXGBE_VLNCTRL_VET)) | (uint32_t)tpid;
    1959                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, reg);
    1960                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
    1961                 :          0 :                         reg = (reg & (~IXGBE_DMATXCTL_VT_MASK))
    1962                 :          0 :                                 | ((uint32_t)tpid << IXGBE_DMATXCTL_VT_SHIFT);
    1963                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
    1964                 :            :                 }
    1965                 :            : 
    1966                 :            :                 break;
    1967                 :          0 :         default:
    1968                 :            :                 ret = -EINVAL;
    1969                 :          0 :                 PMD_DRV_LOG(ERR, "Unsupported VLAN type %d", vlan_type);
    1970                 :          0 :                 break;
    1971                 :            :         }
    1972                 :            : 
    1973                 :          0 :         return ret;
    1974                 :            : }
    1975                 :            : 
    1976                 :            : void
    1977                 :          0 : ixgbe_vlan_hw_filter_disable(struct rte_eth_dev *dev)
    1978                 :            : {
    1979                 :            :         struct ixgbe_hw *hw =
    1980                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1981                 :            :         uint32_t vlnctrl;
    1982                 :            : 
    1983                 :          0 :         PMD_INIT_FUNC_TRACE();
    1984                 :            : 
    1985                 :            :         /* Filter Table Disable */
    1986                 :          0 :         vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    1987                 :          0 :         vlnctrl &= ~IXGBE_VLNCTRL_VFE;
    1988                 :            : 
    1989                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
    1990                 :          0 : }
    1991                 :            : 
    1992                 :            : void
    1993                 :          0 : ixgbe_vlan_hw_filter_enable(struct rte_eth_dev *dev)
    1994                 :            : {
    1995                 :            :         struct ixgbe_hw *hw =
    1996                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1997                 :            :         struct ixgbe_vfta *shadow_vfta =
    1998                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    1999                 :            :         uint32_t vlnctrl;
    2000                 :            :         uint16_t i;
    2001                 :            : 
    2002                 :          0 :         PMD_INIT_FUNC_TRACE();
    2003                 :            : 
    2004                 :            :         /* Filter Table Enable */
    2005                 :          0 :         vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    2006                 :          0 :         vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
    2007                 :          0 :         vlnctrl |= IXGBE_VLNCTRL_VFE;
    2008                 :            : 
    2009                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
    2010                 :            : 
    2011                 :            :         /* write whatever is in local vfta copy */
    2012         [ #  # ]:          0 :         for (i = 0; i < IXGBE_VFTA_SIZE; i++)
    2013                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), shadow_vfta->vfta[i]);
    2014                 :          0 : }
    2015                 :            : 
    2016                 :            : static void
    2017                 :          0 : ixgbe_vlan_hw_strip_bitmap_set(struct rte_eth_dev *dev, uint16_t queue, bool on)
    2018                 :            : {
    2019                 :            :         struct ixgbe_hwstrip *hwstrip =
    2020                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HWSTRIP_BITMAP(dev->data->dev_private);
    2021                 :            :         struct ixgbe_rx_queue *rxq;
    2022                 :            : 
    2023         [ #  # ]:          0 :         if (queue >= IXGBE_MAX_RX_QUEUE_NUM)
    2024                 :            :                 return;
    2025                 :            : 
    2026         [ #  # ]:          0 :         if (on)
    2027                 :          0 :                 IXGBE_SET_HWSTRIP(hwstrip, queue);
    2028                 :            :         else
    2029                 :          0 :                 IXGBE_CLEAR_HWSTRIP(hwstrip, queue);
    2030                 :            : 
    2031         [ #  # ]:          0 :         if (queue >= dev->data->nb_rx_queues)
    2032                 :            :                 return;
    2033                 :            : 
    2034                 :          0 :         rxq = dev->data->rx_queues[queue];
    2035                 :            : 
    2036         [ #  # ]:          0 :         if (on) {
    2037                 :          0 :                 rxq->vlan_flags = RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
    2038                 :          0 :                 rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    2039                 :            :         } else {
    2040                 :          0 :                 rxq->vlan_flags = RTE_MBUF_F_RX_VLAN;
    2041                 :          0 :                 rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    2042                 :            :         }
    2043                 :            : }
    2044                 :            : 
    2045                 :            : static void
    2046                 :          0 : ixgbe_vlan_hw_strip_disable(struct rte_eth_dev *dev, uint16_t queue)
    2047                 :            : {
    2048                 :            :         struct ixgbe_hw *hw =
    2049                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2050                 :            :         uint32_t ctrl;
    2051                 :            : 
    2052                 :          0 :         PMD_INIT_FUNC_TRACE();
    2053                 :            : 
    2054         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
    2055                 :            :                 /* No queue level support */
    2056                 :          0 :                 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
    2057                 :          0 :                 return;
    2058                 :            :         }
    2059                 :            : 
    2060                 :            :         /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
    2061         [ #  # ]:          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
    2062                 :          0 :         ctrl &= ~IXGBE_RXDCTL_VME;
    2063                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
    2064                 :            : 
    2065                 :            :         /* record those setting for HW strip per queue */
    2066                 :          0 :         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 0);
    2067                 :            : }
    2068                 :            : 
    2069                 :            : static void
    2070                 :          0 : ixgbe_vlan_hw_strip_enable(struct rte_eth_dev *dev, uint16_t queue)
    2071                 :            : {
    2072                 :            :         struct ixgbe_hw *hw =
    2073                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2074                 :            :         uint32_t ctrl;
    2075                 :            : 
    2076                 :          0 :         PMD_INIT_FUNC_TRACE();
    2077                 :            : 
    2078         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
    2079                 :            :                 /* No queue level supported */
    2080                 :          0 :                 PMD_INIT_LOG(NOTICE, "82598EB not support queue level hw strip");
    2081                 :          0 :                 return;
    2082                 :            :         }
    2083                 :            : 
    2084                 :            :         /* Other 10G NIC, the VLAN strip can be setup per queue in RXDCTL */
    2085         [ #  # ]:          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
    2086                 :          0 :         ctrl |= IXGBE_RXDCTL_VME;
    2087                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
    2088                 :            : 
    2089                 :            :         /* record those setting for HW strip per queue */
    2090                 :          0 :         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, 1);
    2091                 :            : }
    2092                 :            : 
    2093                 :            : static void
    2094                 :          0 : ixgbe_vlan_hw_extend_disable(struct rte_eth_dev *dev)
    2095                 :            : {
    2096                 :            :         struct ixgbe_hw *hw =
    2097                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2098                 :            :         uint32_t ctrl;
    2099                 :            : 
    2100                 :          0 :         PMD_INIT_FUNC_TRACE();
    2101                 :            : 
    2102                 :            :         /* DMATXCTRL: Geric Double VLAN Disable */
    2103                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
    2104                 :          0 :         ctrl &= ~IXGBE_DMATXCTL_GDV;
    2105                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
    2106                 :            : 
    2107                 :            :         /* CTRL_EXT: Global Double VLAN Disable */
    2108                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
    2109                 :          0 :         ctrl &= ~IXGBE_EXTENDED_VLAN;
    2110                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
    2111                 :            : 
    2112                 :          0 : }
    2113                 :            : 
    2114                 :            : static void
    2115                 :          0 : ixgbe_vlan_hw_extend_enable(struct rte_eth_dev *dev)
    2116                 :            : {
    2117                 :            :         struct ixgbe_hw *hw =
    2118                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2119                 :            :         uint32_t ctrl;
    2120                 :            : 
    2121                 :          0 :         PMD_INIT_FUNC_TRACE();
    2122                 :            : 
    2123                 :            :         /* DMATXCTRL: Geric Double VLAN Enable */
    2124                 :          0 :         ctrl  = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
    2125                 :          0 :         ctrl |= IXGBE_DMATXCTL_GDV;
    2126                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, ctrl);
    2127                 :            : 
    2128                 :            :         /* CTRL_EXT: Global Double VLAN Enable */
    2129                 :          0 :         ctrl  = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
    2130                 :          0 :         ctrl |= IXGBE_EXTENDED_VLAN;
    2131                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl);
    2132                 :            : 
    2133                 :            :         /* Clear pooling mode of PFVTCTL. It's required by X550. */
    2134                 :          0 :         if (hw->mac.type == ixgbe_mac_X550 ||
    2135         [ #  # ]:          0 :             hw->mac.type == ixgbe_mac_X550EM_x ||
    2136                 :            :             hw->mac.type == ixgbe_mac_X550EM_a) {
    2137                 :          0 :                 ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
    2138                 :          0 :                 ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
    2139                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
    2140                 :            :         }
    2141                 :            : 
    2142                 :            :         /*
    2143                 :            :          * VET EXT field in the EXVET register = 0x8100 by default
    2144                 :            :          * So no need to change. Same to VT field of DMATXCTL register
    2145                 :            :          */
    2146                 :          0 : }
    2147                 :            : 
    2148                 :            : void
    2149                 :          0 : ixgbe_vlan_hw_strip_config(struct rte_eth_dev *dev)
    2150                 :            : {
    2151                 :            :         struct ixgbe_hw *hw =
    2152                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2153                 :            :         struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
    2154                 :            :         uint32_t ctrl;
    2155                 :            :         uint16_t i;
    2156                 :            :         struct ixgbe_rx_queue *rxq;
    2157                 :            :         bool on;
    2158                 :            : 
    2159                 :          0 :         PMD_INIT_FUNC_TRACE();
    2160                 :            : 
    2161         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
    2162         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
    2163                 :          0 :                         ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    2164                 :          0 :                         ctrl |= IXGBE_VLNCTRL_VME;
    2165                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
    2166                 :            :                 } else {
    2167                 :          0 :                         ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    2168                 :          0 :                         ctrl &= ~IXGBE_VLNCTRL_VME;
    2169                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
    2170                 :            :                 }
    2171                 :            :         } else {
    2172                 :            :                 /*
    2173                 :            :                  * Other 10G NIC, the VLAN strip can be setup
    2174                 :            :                  * per queue in RXDCTL
    2175                 :            :                  */
    2176         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2177                 :          0 :                         rxq = dev->data->rx_queues[i];
    2178         [ #  # ]:          0 :                         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxq->reg_idx));
    2179         [ #  # ]:          0 :                         if (rxq->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
    2180                 :          0 :                                 ctrl |= IXGBE_RXDCTL_VME;
    2181                 :            :                                 on = TRUE;
    2182                 :            :                         } else {
    2183                 :          0 :                                 ctrl &= ~IXGBE_RXDCTL_VME;
    2184                 :            :                                 on = FALSE;
    2185                 :            :                         }
    2186         [ #  # ]:          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxq->reg_idx), ctrl);
    2187                 :            : 
    2188                 :            :                         /* record those setting for HW strip per queue */
    2189                 :          0 :                         ixgbe_vlan_hw_strip_bitmap_set(dev, i, on);
    2190                 :            :                 }
    2191                 :            :         }
    2192                 :          0 : }
    2193                 :            : 
    2194                 :            : static void
    2195                 :          0 : ixgbe_config_vlan_strip_on_all_queues(struct rte_eth_dev *dev, int mask)
    2196                 :            : {
    2197                 :            :         uint16_t i;
    2198                 :            :         struct rte_eth_rxmode *rxmode;
    2199                 :            :         struct ixgbe_rx_queue *rxq;
    2200                 :            : 
    2201         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
    2202                 :          0 :                 rxmode = &dev->data->dev_conf.rxmode;
    2203         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    2204         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2205                 :          0 :                                 rxq = dev->data->rx_queues[i];
    2206                 :          0 :                                 rxq->offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    2207                 :            :                         }
    2208                 :            :                 else
    2209         [ #  # ]:          0 :                         for (i = 0; i < dev->data->nb_rx_queues; i++) {
    2210                 :          0 :                                 rxq = dev->data->rx_queues[i];
    2211                 :          0 :                                 rxq->offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
    2212                 :            :                         }
    2213                 :            :         }
    2214                 :          0 : }
    2215                 :            : 
    2216                 :            : static int
    2217                 :          0 : ixgbe_vlan_offload_config(struct rte_eth_dev *dev, int mask)
    2218                 :            : {
    2219                 :            :         struct rte_eth_rxmode *rxmode;
    2220                 :          0 :         rxmode = &dev->data->dev_conf.rxmode;
    2221                 :            : 
    2222         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK)
    2223                 :          0 :                 ixgbe_vlan_hw_strip_config(dev);
    2224                 :            : 
    2225         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_FILTER_MASK) {
    2226         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
    2227                 :          0 :                         ixgbe_vlan_hw_filter_enable(dev);
    2228                 :            :                 else
    2229                 :          0 :                         ixgbe_vlan_hw_filter_disable(dev);
    2230                 :            :         }
    2231                 :            : 
    2232         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_EXTEND_MASK) {
    2233         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
    2234                 :          0 :                         ixgbe_vlan_hw_extend_enable(dev);
    2235                 :            :                 else
    2236                 :          0 :                         ixgbe_vlan_hw_extend_disable(dev);
    2237                 :            :         }
    2238                 :            : 
    2239                 :          0 :         return 0;
    2240                 :            : }
    2241                 :            : 
    2242                 :            : static int
    2243                 :          0 : ixgbe_vlan_offload_set(struct rte_eth_dev *dev, int mask)
    2244                 :            : {
    2245                 :          0 :         ixgbe_config_vlan_strip_on_all_queues(dev, mask);
    2246                 :            : 
    2247                 :          0 :         ixgbe_vlan_offload_config(dev, mask);
    2248                 :            : 
    2249                 :          0 :         return 0;
    2250                 :            : }
    2251                 :            : 
    2252                 :            : static void
    2253                 :            : ixgbe_vmdq_vlan_hw_filter_enable(struct rte_eth_dev *dev)
    2254                 :            : {
    2255                 :            :         struct ixgbe_hw *hw =
    2256                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2257                 :            :         /* VLNCTRL: enable vlan filtering and allow all vlan tags through */
    2258                 :          0 :         uint32_t vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
    2259                 :            : 
    2260                 :          0 :         vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
    2261                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
    2262                 :          0 : }
    2263                 :            : 
    2264                 :            : static int
    2265                 :            : ixgbe_check_vf_rss_rxq_num(struct rte_eth_dev *dev, uint16_t nb_rx_q)
    2266                 :            : {
    2267                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    2268                 :            : 
    2269      [ #  #  # ]:          0 :         switch (nb_rx_q) {
    2270                 :          0 :         case 1:
    2271                 :            :         case 2:
    2272                 :          0 :                 RTE_ETH_DEV_SRIOV(dev).active = RTE_ETH_64_POOLS;
    2273                 :          0 :                 break;
    2274                 :          0 :         case 4:
    2275                 :          0 :                 RTE_ETH_DEV_SRIOV(dev).active = RTE_ETH_32_POOLS;
    2276                 :          0 :                 break;
    2277                 :            :         default:
    2278                 :            :                 return -EINVAL;
    2279                 :            :         }
    2280                 :            : 
    2281                 :          0 :         RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool =
    2282                 :          0 :                 IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
    2283                 :          0 :         RTE_ETH_DEV_SRIOV(dev).def_pool_q_idx =
    2284                 :          0 :                 pci_dev->max_vfs * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
    2285                 :            :         return 0;
    2286                 :            : }
    2287                 :            : 
    2288                 :            : static int
    2289                 :          0 : ixgbe_check_mq_mode(struct rte_eth_dev *dev)
    2290                 :            : {
    2291                 :          0 :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
    2292                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2293                 :          0 :         uint16_t nb_rx_q = dev->data->nb_rx_queues;
    2294                 :          0 :         uint16_t nb_tx_q = dev->data->nb_tx_queues;
    2295                 :            : 
    2296         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active != 0) {
    2297                 :            :                 /* check multi-queue mode */
    2298   [ #  #  #  #  :          0 :                 switch (dev_conf->rxmode.mq_mode) {
                      # ]
    2299                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_DCB:
    2300                 :          0 :                         PMD_INIT_LOG(INFO, "RTE_ETH_MQ_RX_VMDQ_DCB mode supported in SRIOV");
    2301                 :          0 :                         break;
    2302                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_DCB_RSS:
    2303                 :            :                         /* DCB/RSS VMDQ in SRIOV mode, not implement yet */
    2304                 :          0 :                         PMD_INIT_LOG(ERR, "SRIOV active,"
    2305                 :            :                                         " unsupported mq_mode rx %d.",
    2306                 :            :                                         dev_conf->rxmode.mq_mode);
    2307                 :          0 :                         return -EINVAL;
    2308                 :          0 :                 case RTE_ETH_MQ_RX_RSS:
    2309                 :            :                 case RTE_ETH_MQ_RX_VMDQ_RSS:
    2310                 :          0 :                         dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_RSS;
    2311         [ #  # ]:          0 :                         if (nb_rx_q <= RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)
    2312                 :            :                                 if (ixgbe_check_vf_rss_rxq_num(dev, nb_rx_q)) {
    2313                 :          0 :                                         PMD_INIT_LOG(ERR, "SRIOV is active,"
    2314                 :            :                                                 " invalid queue number"
    2315                 :            :                                                 " for VMDQ RSS, allowed"
    2316                 :            :                                                 " value are 1, 2 or 4.");
    2317                 :          0 :                                         return -EINVAL;
    2318                 :            :                                 }
    2319                 :            :                         break;
    2320                 :          0 :                 case RTE_ETH_MQ_RX_VMDQ_ONLY:
    2321                 :            :                 case RTE_ETH_MQ_RX_NONE:
    2322                 :            :                         /* if nothing mq mode configure, use default scheme */
    2323                 :          0 :                         dev->data->dev_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_VMDQ_ONLY;
    2324                 :          0 :                         break;
    2325                 :          0 :                 default: /* RTE_ETH_MQ_RX_DCB, RTE_ETH_MQ_RX_DCB_RSS or RTE_ETH_MQ_TX_DCB*/
    2326                 :            :                         /* SRIOV only works in VMDq enable mode */
    2327                 :          0 :                         PMD_INIT_LOG(ERR, "SRIOV is active,"
    2328                 :            :                                         " wrong mq_mode rx %d.",
    2329                 :            :                                         dev_conf->rxmode.mq_mode);
    2330                 :          0 :                         return -EINVAL;
    2331                 :            :                 }
    2332                 :            : 
    2333         [ #  # ]:          0 :                 switch (dev_conf->txmode.mq_mode) {
    2334                 :          0 :                 case RTE_ETH_MQ_TX_VMDQ_DCB:
    2335                 :          0 :                         PMD_INIT_LOG(INFO, "RTE_ETH_MQ_TX_VMDQ_DCB mode supported in SRIOV");
    2336                 :          0 :                         dev->data->dev_conf.txmode.mq_mode = RTE_ETH_MQ_TX_VMDQ_DCB;
    2337                 :          0 :                         break;
    2338                 :          0 :                 default: /* RTE_ETH_MQ_TX_VMDQ_ONLY or RTE_ETH_MQ_TX_NONE */
    2339                 :          0 :                         dev->data->dev_conf.txmode.mq_mode = RTE_ETH_MQ_TX_VMDQ_ONLY;
    2340                 :          0 :                         break;
    2341                 :            :                 }
    2342                 :            : 
    2343                 :            :                 /* check valid queue number */
    2344   [ #  #  #  # ]:          0 :                 if ((nb_rx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool) ||
    2345                 :            :                     (nb_tx_q > RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool)) {
    2346                 :          0 :                         PMD_INIT_LOG(ERR, "SRIOV is active,"
    2347                 :            :                                         " nb_rx_q=%d nb_tx_q=%d queue number"
    2348                 :            :                                         " must be less than or equal to %d.",
    2349                 :            :                                         nb_rx_q, nb_tx_q,
    2350                 :            :                                         RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool);
    2351                 :          0 :                         return -EINVAL;
    2352                 :            :                 }
    2353                 :            :         } else {
    2354         [ #  # ]:          0 :                 if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_DCB_RSS) {
    2355                 :          0 :                         PMD_INIT_LOG(ERR, "VMDQ+DCB+RSS mq_mode is"
    2356                 :            :                                           " not supported.");
    2357                 :          0 :                         return -EINVAL;
    2358                 :            :                 }
    2359                 :            :                 /* check configuration for vmdb+dcb mode */
    2360         [ #  # ]:          0 :                 if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_DCB) {
    2361                 :            :                         const struct rte_eth_vmdq_dcb_conf *conf;
    2362                 :            : 
    2363         [ #  # ]:          0 :                         if (nb_rx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
    2364                 :          0 :                                 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_rx_q != %d.",
    2365                 :            :                                                 IXGBE_VMDQ_DCB_NB_QUEUES);
    2366                 :          0 :                                 return -EINVAL;
    2367                 :            :                         }
    2368                 :            :                         conf = &dev_conf->rx_adv_conf.vmdq_dcb_conf;
    2369         [ #  # ]:          0 :                         if (!(conf->nb_queue_pools == RTE_ETH_16_POOLS ||
    2370                 :            :                                conf->nb_queue_pools == RTE_ETH_32_POOLS)) {
    2371                 :          0 :                                 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
    2372                 :            :                                                 " nb_queue_pools must be %d or %d.",
    2373                 :            :                                                 RTE_ETH_16_POOLS, RTE_ETH_32_POOLS);
    2374                 :          0 :                                 return -EINVAL;
    2375                 :            :                         }
    2376                 :            :                 }
    2377         [ #  # ]:          0 :                 if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB) {
    2378                 :            :                         const struct rte_eth_vmdq_dcb_tx_conf *conf;
    2379                 :            : 
    2380         [ #  # ]:          0 :                         if (nb_tx_q != IXGBE_VMDQ_DCB_NB_QUEUES) {
    2381                 :          0 :                                 PMD_INIT_LOG(ERR, "VMDQ+DCB, nb_tx_q != %d",
    2382                 :            :                                                  IXGBE_VMDQ_DCB_NB_QUEUES);
    2383                 :          0 :                                 return -EINVAL;
    2384                 :            :                         }
    2385                 :            :                         conf = &dev_conf->tx_adv_conf.vmdq_dcb_tx_conf;
    2386         [ #  # ]:          0 :                         if (!(conf->nb_queue_pools == RTE_ETH_16_POOLS ||
    2387                 :            :                                conf->nb_queue_pools == RTE_ETH_32_POOLS)) {
    2388                 :          0 :                                 PMD_INIT_LOG(ERR, "VMDQ+DCB selected,"
    2389                 :            :                                                 " nb_queue_pools != %d and"
    2390                 :            :                                                 " nb_queue_pools != %d.",
    2391                 :            :                                                 RTE_ETH_16_POOLS, RTE_ETH_32_POOLS);
    2392                 :          0 :                                 return -EINVAL;
    2393                 :            :                         }
    2394                 :            :                 }
    2395                 :            : 
    2396                 :            :                 /* For DCB mode check our configuration before we go further */
    2397         [ #  # ]:          0 :                 if (dev_conf->rxmode.mq_mode == RTE_ETH_MQ_RX_DCB) {
    2398                 :            :                         const struct rte_eth_dcb_rx_conf *conf;
    2399                 :            : 
    2400                 :            :                         conf = &dev_conf->rx_adv_conf.dcb_rx_conf;
    2401         [ #  # ]:          0 :                         if (!(conf->nb_tcs == RTE_ETH_4_TCS ||
    2402                 :            :                                conf->nb_tcs == RTE_ETH_8_TCS)) {
    2403                 :          0 :                                 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
    2404                 :            :                                                 " and nb_tcs != %d.",
    2405                 :            :                                                 RTE_ETH_4_TCS, RTE_ETH_8_TCS);
    2406                 :          0 :                                 return -EINVAL;
    2407                 :            :                         }
    2408                 :            :                 }
    2409                 :            : 
    2410         [ #  # ]:          0 :                 if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_DCB) {
    2411                 :            :                         const struct rte_eth_dcb_tx_conf *conf;
    2412                 :            : 
    2413                 :            :                         conf = &dev_conf->tx_adv_conf.dcb_tx_conf;
    2414         [ #  # ]:          0 :                         if (!(conf->nb_tcs == RTE_ETH_4_TCS ||
    2415                 :            :                                conf->nb_tcs == RTE_ETH_8_TCS)) {
    2416                 :          0 :                                 PMD_INIT_LOG(ERR, "DCB selected, nb_tcs != %d"
    2417                 :            :                                                 " and nb_tcs != %d.",
    2418                 :            :                                                 RTE_ETH_4_TCS, RTE_ETH_8_TCS);
    2419                 :          0 :                                 return -EINVAL;
    2420                 :            :                         }
    2421                 :            :                 }
    2422                 :            : 
    2423                 :            :                 /*
    2424                 :            :                  * When DCB/VT is off, maximum number of queues changes,
    2425                 :            :                  * except for 82598EB, which remains constant.
    2426                 :            :                  */
    2427         [ #  # ]:          0 :                 if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_NONE &&
    2428         [ #  # ]:          0 :                                 hw->mac.type != ixgbe_mac_82598EB) {
    2429         [ #  # ]:          0 :                         if (nb_tx_q > IXGBE_NONE_MODE_TX_NB_QUEUES) {
    2430                 :          0 :                                 PMD_INIT_LOG(ERR,
    2431                 :            :                                              "Neither VT nor DCB are enabled, "
    2432                 :            :                                              "nb_tx_q > %d.",
    2433                 :            :                                              IXGBE_NONE_MODE_TX_NB_QUEUES);
    2434                 :          0 :                                 return -EINVAL;
    2435                 :            :                         }
    2436                 :            :                 }
    2437                 :            :         }
    2438                 :            :         return 0;
    2439                 :            : }
    2440                 :            : 
    2441                 :            : static int
    2442                 :          0 : ixgbe_dev_configure(struct rte_eth_dev *dev)
    2443                 :            : {
    2444                 :            :         struct ixgbe_interrupt *intr =
    2445                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    2446                 :            :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    2447                 :            :         int ret;
    2448                 :            : 
    2449                 :          0 :         PMD_INIT_FUNC_TRACE();
    2450                 :            : 
    2451         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
    2452                 :          0 :                 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
    2453                 :            : 
    2454                 :            :         /* multiple queue mode checking */
    2455                 :          0 :         ret  = ixgbe_check_mq_mode(dev);
    2456         [ #  # ]:          0 :         if (ret != 0) {
    2457                 :          0 :                 PMD_DRV_LOG(ERR, "ixgbe_check_mq_mode fails with %d.",
    2458                 :            :                             ret);
    2459                 :          0 :                 return ret;
    2460                 :            :         }
    2461                 :            : 
    2462                 :            :         /* set flag to update link status after init */
    2463                 :          0 :         intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
    2464                 :            : 
    2465                 :            :         /*
    2466                 :            :          * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
    2467                 :            :          * allocation or vector Rx preconditions we will reset it.
    2468                 :            :          */
    2469                 :          0 :         adapter->rx_bulk_alloc_allowed = true;
    2470                 :          0 :         adapter->rx_vec_allowed = true;
    2471                 :            : 
    2472                 :          0 :         return 0;
    2473                 :            : }
    2474                 :            : 
    2475                 :            : static void
    2476                 :          0 : ixgbe_dev_phy_intr_setup(struct rte_eth_dev *dev)
    2477                 :            : {
    2478                 :            :         struct ixgbe_hw *hw =
    2479                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2480                 :            :         struct ixgbe_interrupt *intr =
    2481                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    2482                 :            :         uint32_t gpie;
    2483                 :            : 
    2484                 :            :         /* only set up it on X550EM_X */
    2485         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_X550EM_x) {
    2486                 :          0 :                 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
    2487                 :          0 :                 gpie |= IXGBE_SDP0_GPIEN_X550EM_x;
    2488                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
    2489         [ #  # ]:          0 :                 if (hw->phy.type == ixgbe_phy_x550em_ext_t)
    2490                 :          0 :                         intr->mask |= IXGBE_EICR_GPI_SDP0_X550EM_x;
    2491                 :            :         }
    2492                 :          0 : }
    2493                 :            : 
    2494                 :            : int
    2495                 :          0 : ixgbe_set_vf_rate_limit(struct rte_eth_dev *dev, uint16_t vf,
    2496                 :            :                         uint32_t tx_rate, uint64_t q_msk)
    2497                 :            : {
    2498                 :            :         struct ixgbe_hw *hw;
    2499                 :            :         struct ixgbe_vf_info *vfinfo;
    2500                 :            :         struct rte_eth_link link;
    2501                 :            :         uint8_t  nb_q_per_pool;
    2502                 :            :         uint32_t queue_stride;
    2503                 :            :         uint32_t queue_idx, idx = 0, vf_idx;
    2504                 :            :         uint32_t queue_end;
    2505                 :            :         uint16_t total_rate = 0;
    2506                 :            :         struct rte_pci_device *pci_dev;
    2507                 :            :         int ret;
    2508                 :            : 
    2509                 :          0 :         pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    2510                 :          0 :         ret = rte_eth_link_get_nowait(dev->data->port_id, &link);
    2511         [ #  # ]:          0 :         if (ret < 0)
    2512                 :            :                 return ret;
    2513                 :            : 
    2514         [ #  # ]:          0 :         if (vf >= pci_dev->max_vfs)
    2515                 :            :                 return -EINVAL;
    2516                 :            : 
    2517         [ #  # ]:          0 :         if (tx_rate > link.link_speed)
    2518                 :            :                 return -EINVAL;
    2519                 :            : 
    2520         [ #  # ]:          0 :         if (q_msk == 0)
    2521                 :            :                 return 0;
    2522                 :            : 
    2523                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2524                 :          0 :         vfinfo = *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
    2525                 :          0 :         nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
    2526                 :          0 :         queue_stride = IXGBE_MAX_RX_QUEUE_NUM / RTE_ETH_DEV_SRIOV(dev).active;
    2527                 :          0 :         queue_idx = vf * queue_stride;
    2528                 :          0 :         queue_end = queue_idx + nb_q_per_pool - 1;
    2529         [ #  # ]:          0 :         if (queue_end >= hw->mac.max_tx_queues)
    2530                 :            :                 return -EINVAL;
    2531                 :            : 
    2532         [ #  # ]:          0 :         if (vfinfo) {
    2533         [ #  # ]:          0 :                 for (vf_idx = 0; vf_idx < pci_dev->max_vfs; vf_idx++) {
    2534         [ #  # ]:          0 :                         if (vf_idx == vf)
    2535                 :          0 :                                 continue;
    2536         [ #  # ]:          0 :                         for (idx = 0; idx < RTE_DIM(vfinfo[vf_idx].tx_rate);
    2537                 :          0 :                                 idx++)
    2538                 :          0 :                                 total_rate += vfinfo[vf_idx].tx_rate[idx];
    2539                 :            :                 }
    2540                 :            :         } else {
    2541                 :            :                 return -EINVAL;
    2542                 :            :         }
    2543                 :            : 
    2544                 :            :         /* Store tx_rate for this vf. */
    2545         [ #  # ]:          0 :         for (idx = 0; idx < nb_q_per_pool; idx++) {
    2546         [ #  # ]:          0 :                 if (((uint64_t)0x1 << idx) & q_msk) {
    2547         [ #  # ]:          0 :                         if (vfinfo[vf].tx_rate[idx] != tx_rate)
    2548                 :          0 :                                 vfinfo[vf].tx_rate[idx] = tx_rate;
    2549                 :          0 :                         total_rate += tx_rate;
    2550                 :            :                 }
    2551                 :            :         }
    2552                 :            : 
    2553         [ #  # ]:          0 :         if (total_rate > dev->data->dev_link.link_speed) {
    2554                 :            :                 /* Reset stored TX rate of the VF if it causes exceed
    2555                 :            :                  * link speed.
    2556                 :            :                  */
    2557                 :          0 :                 memset(vfinfo[vf].tx_rate, 0, sizeof(vfinfo[vf].tx_rate));
    2558                 :          0 :                 return -EINVAL;
    2559                 :            :         }
    2560                 :            : 
    2561                 :            :         /* Set RTTBCNRC of each queue/pool for vf X  */
    2562         [ #  # ]:          0 :         for (; queue_idx <= queue_end; queue_idx++) {
    2563         [ #  # ]:          0 :                 if (0x1 & q_msk)
    2564                 :          0 :                         ixgbe_set_queue_rate_limit(dev, queue_idx, tx_rate);
    2565                 :          0 :                 q_msk = q_msk >> 1;
    2566                 :            :         }
    2567                 :            : 
    2568                 :            :         return 0;
    2569                 :            : }
    2570                 :            : 
    2571                 :            : static int
    2572                 :          0 : ixgbe_flow_ctrl_enable(struct rte_eth_dev *dev, struct ixgbe_hw *hw)
    2573                 :            : {
    2574                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    2575                 :            :         int err;
    2576                 :            :         uint32_t mflcn;
    2577                 :            : 
    2578                 :          0 :         ixgbe_setup_fc(hw);
    2579                 :            : 
    2580                 :          0 :         err = ixgbe_fc_enable(hw);
    2581                 :            : 
    2582                 :            :         /* Not negotiated is not an error case */
    2583         [ #  # ]:          0 :         if (err == IXGBE_SUCCESS || err == IXGBE_ERR_FC_NOT_NEGOTIATED) {
    2584                 :            :                 /*
    2585                 :            :                  *check if we want to forward MAC frames - driver doesn't
    2586                 :            :                  *have native capability to do that,
    2587                 :            :                  *so we'll write the registers ourselves
    2588                 :            :                  */
    2589                 :            : 
    2590                 :          0 :                 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
    2591                 :            : 
    2592                 :            :                 /* set or clear MFLCN.PMCF bit depending on configuration */
    2593         [ #  # ]:          0 :                 if (adapter->mac_ctrl_frame_fwd != 0)
    2594                 :          0 :                         mflcn |= IXGBE_MFLCN_PMCF;
    2595                 :            :                 else
    2596                 :          0 :                         mflcn &= ~IXGBE_MFLCN_PMCF;
    2597                 :            : 
    2598                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn);
    2599                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2600                 :            : 
    2601                 :          0 :                 return 0;
    2602                 :            :         }
    2603                 :            :         return err;
    2604                 :            : }
    2605                 :            : 
    2606                 :            : /*
    2607                 :            :  * Configure device link speed and setup link.
    2608                 :            :  * It returns 0 on success.
    2609                 :            :  */
    2610                 :            : static int
    2611                 :          0 : ixgbe_dev_start(struct rte_eth_dev *dev)
    2612                 :            : {
    2613                 :          0 :         struct ixgbe_hw *hw =
    2614                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2615                 :          0 :         struct ixgbe_vf_info *vfinfo =
    2616                 :            :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
    2617                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    2618                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    2619                 :            :         uint32_t intr_vector = 0;
    2620                 :            :         int err;
    2621                 :          0 :         bool link_up = false, negotiate = 0;
    2622                 :          0 :         uint32_t speed = 0;
    2623                 :            :         uint32_t allowed_speeds = 0;
    2624                 :            :         int mask = 0;
    2625                 :            :         int status;
    2626                 :            :         uint16_t vf, idx;
    2627                 :            :         uint32_t *link_speeds;
    2628                 :            :         struct ixgbe_tm_conf *tm_conf =
    2629                 :            :                 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
    2630                 :          0 :         struct ixgbe_macsec_setting *macsec_setting =
    2631                 :            :                 IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
    2632                 :            : 
    2633                 :          0 :         PMD_INIT_FUNC_TRACE();
    2634                 :            : 
    2635                 :            :         /* Stop the link setup handler before resetting the HW. */
    2636                 :          0 :         ixgbe_dev_wait_setup_link_complete(dev, 0);
    2637                 :            : 
    2638                 :            :         /* disable uio/vfio intr/eventfd mapping */
    2639                 :          0 :         rte_intr_disable(intr_handle);
    2640                 :            : 
    2641                 :            :         /* stop adapter */
    2642                 :          0 :         hw->adapter_stopped = 0;
    2643                 :          0 :         ixgbe_stop_adapter(hw);
    2644                 :            : 
    2645                 :            :         /* reinitialize adapter
    2646                 :            :          * this calls reset and start
    2647                 :            :          */
    2648                 :          0 :         status = ixgbe_pf_reset_hw(hw);
    2649         [ #  # ]:          0 :         if (status != 0)
    2650                 :            :                 return -1;
    2651                 :          0 :         hw->mac.ops.start_hw(hw);
    2652                 :          0 :         hw->mac.get_link_status = true;
    2653                 :            : 
    2654                 :            :         /* configure PF module if SRIOV enabled */
    2655                 :          0 :         ixgbe_pf_host_configure(dev);
    2656                 :            : 
    2657                 :          0 :         ixgbe_dev_phy_intr_setup(dev);
    2658                 :            : 
    2659                 :            :         /* check and configure queue intr-vector mapping */
    2660         [ #  # ]:          0 :         if ((rte_intr_cap_multiple(intr_handle) ||
    2661         [ #  # ]:          0 :              !RTE_ETH_DEV_SRIOV(dev).active) &&
    2662         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.rxq != 0) {
    2663                 :          0 :                 intr_vector = dev->data->nb_rx_queues;
    2664         [ #  # ]:          0 :                 if (intr_vector > IXGBE_MAX_INTR_QUEUE_NUM) {
    2665                 :          0 :                         PMD_INIT_LOG(ERR, "At most %d intr queues supported",
    2666                 :            :                                         IXGBE_MAX_INTR_QUEUE_NUM);
    2667                 :          0 :                         return -ENOTSUP;
    2668                 :            :                 }
    2669         [ #  # ]:          0 :                 if (rte_intr_efd_enable(intr_handle, intr_vector))
    2670                 :            :                         return -1;
    2671                 :            :         }
    2672                 :            : 
    2673         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
    2674         [ #  # ]:          0 :                 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
    2675                 :          0 :                                                    dev->data->nb_rx_queues)) {
    2676                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
    2677                 :            :                                      " intr_vec", dev->data->nb_rx_queues);
    2678                 :          0 :                         return -ENOMEM;
    2679                 :            :                 }
    2680                 :            :         }
    2681                 :            : 
    2682                 :            :         /* configure MSI-X for sleep until Rx interrupt */
    2683                 :          0 :         ixgbe_configure_msix(dev);
    2684                 :            : 
    2685                 :            :         /* initialize transmission unit */
    2686                 :          0 :         ixgbe_dev_tx_init(dev);
    2687                 :            : 
    2688                 :            :         /* This can fail when allocating mbufs for descriptor rings */
    2689                 :          0 :         err = ixgbe_dev_rx_init(dev);
    2690         [ #  # ]:          0 :         if (err) {
    2691                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
    2692                 :          0 :                 goto error;
    2693                 :            :         }
    2694                 :            : 
    2695                 :            :         mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
    2696                 :            :                 RTE_ETH_VLAN_EXTEND_MASK;
    2697                 :          0 :         err = ixgbe_vlan_offload_config(dev, mask);
    2698         [ #  # ]:          0 :         if (err) {
    2699                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to set VLAN offload");
    2700                 :          0 :                 goto error;
    2701                 :            :         }
    2702                 :            : 
    2703         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode == RTE_ETH_MQ_RX_VMDQ_ONLY) {
    2704                 :            :                 /* Enable vlan filtering for VMDq */
    2705                 :            :                 ixgbe_vmdq_vlan_hw_filter_enable(dev);
    2706                 :            :         }
    2707                 :            : 
    2708                 :            :         /* Configure DCB hw */
    2709                 :          0 :         ixgbe_configure_dcb(dev);
    2710                 :            : 
    2711         [ #  # ]:          0 :         if (IXGBE_DEV_FDIR_CONF(dev)->mode != RTE_FDIR_MODE_NONE) {
    2712                 :          0 :                 err = ixgbe_fdir_configure(dev);
    2713         [ #  # ]:          0 :                 if (err)
    2714                 :          0 :                         goto error;
    2715                 :            :         }
    2716                 :            : 
    2717                 :            :         /* Restore vf rate limit */
    2718         [ #  # ]:          0 :         if (vfinfo != NULL) {
    2719         [ #  # ]:          0 :                 for (vf = 0; vf < pci_dev->max_vfs; vf++)
    2720         [ #  # ]:          0 :                         for (idx = 0; idx < IXGBE_MAX_QUEUE_NUM_PER_VF; idx++)
    2721         [ #  # ]:          0 :                                 if (vfinfo[vf].tx_rate[idx] != 0)
    2722                 :          0 :                                         ixgbe_set_vf_rate_limit(
    2723                 :            :                                                 dev, vf,
    2724                 :            :                                                 vfinfo[vf].tx_rate[idx],
    2725                 :            :                                                 RTE_BIT64(idx));
    2726                 :            :         }
    2727                 :            : 
    2728                 :          0 :         ixgbe_restore_statistics_mapping(dev);
    2729                 :            : 
    2730                 :          0 :         err = ixgbe_flow_ctrl_enable(dev, hw);
    2731         [ #  # ]:          0 :         if (err < 0) {
    2732                 :          0 :                 PMD_INIT_LOG(ERR, "enable flow ctrl err");
    2733                 :          0 :                 goto error;
    2734                 :            :         }
    2735                 :            : 
    2736                 :          0 :         err = ixgbe_dev_rxtx_start(dev);
    2737         [ #  # ]:          0 :         if (err < 0) {
    2738                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to start rxtx queues");
    2739                 :          0 :                 goto error;
    2740                 :            :         }
    2741                 :            : 
    2742                 :            :         /* Skip link setup if loopback mode is enabled. */
    2743         [ #  # ]:          0 :         if (dev->data->dev_conf.lpbk_mode != 0) {
    2744                 :          0 :                 err = ixgbe_check_supported_loopback_mode(dev);
    2745         [ #  # ]:          0 :                 if (err < 0) {
    2746                 :          0 :                         PMD_INIT_LOG(ERR, "Unsupported loopback mode");
    2747                 :          0 :                         goto error;
    2748                 :            :                 } else {
    2749                 :          0 :                         goto skip_link_setup;
    2750                 :            :                 }
    2751                 :            :         }
    2752                 :            : 
    2753   [ #  #  #  # ]:          0 :         if (ixgbe_is_sfp(hw) && hw->phy.multispeed_fiber) {
    2754                 :          0 :                 err = hw->mac.ops.setup_sfp(hw);
    2755         [ #  # ]:          0 :                 if (err)
    2756                 :          0 :                         goto error;
    2757                 :            :         }
    2758                 :            : 
    2759         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
    2760                 :            :                 /* Turn on the copper */
    2761                 :          0 :                 ixgbe_set_phy_power(hw, true);
    2762                 :            :         } else {
    2763                 :            :                 /* Turn on the laser */
    2764                 :          0 :                 ixgbe_enable_tx_laser(hw);
    2765                 :            :         }
    2766                 :            : 
    2767                 :          0 :         err = ixgbe_check_link(hw, &speed, &link_up, 0);
    2768         [ #  # ]:          0 :         if (err)
    2769                 :          0 :                 goto error;
    2770                 :          0 :         dev->data->dev_link.link_status = link_up;
    2771                 :            : 
    2772                 :          0 :         err = ixgbe_get_link_capabilities(hw, &speed, &negotiate);
    2773         [ #  # ]:          0 :         if (err)
    2774                 :          0 :                 goto error;
    2775                 :            : 
    2776         [ #  # ]:          0 :         switch (hw->mac.type) {
    2777                 :          0 :         case ixgbe_mac_X550:
    2778                 :            :         case ixgbe_mac_X550EM_x:
    2779                 :            :         case ixgbe_mac_X550EM_a:
    2780                 :            :                 allowed_speeds = RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G |
    2781                 :            :                         RTE_ETH_LINK_SPEED_2_5G |  RTE_ETH_LINK_SPEED_5G |
    2782                 :            :                         RTE_ETH_LINK_SPEED_10G;
    2783         [ #  # ]:          0 :                 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
    2784                 :            :                                 hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
    2785                 :            :                         allowed_speeds = RTE_ETH_LINK_SPEED_10M |
    2786                 :            :                                 RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G;
    2787                 :            :                 break;
    2788                 :            :         default:
    2789                 :            :                 allowed_speeds = RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G |
    2790                 :            :                         RTE_ETH_LINK_SPEED_10G;
    2791                 :            :         }
    2792                 :            : 
    2793                 :          0 :         link_speeds = &dev->data->dev_conf.link_speeds;
    2794                 :            : 
    2795                 :            :         /* Ignore autoneg flag bit and check the validity of 
    2796                 :            :          * link_speed 
    2797                 :            :          */
    2798         [ #  # ]:          0 :         if (((*link_speeds) >> 1) & ~(allowed_speeds >> 1)) {
    2799                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid link setting");
    2800                 :          0 :                 goto error;
    2801                 :            :         }
    2802                 :            : 
    2803                 :          0 :         speed = 0x0;
    2804         [ #  # ]:          0 :         if (*link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
    2805   [ #  #  #  # ]:          0 :                 switch (hw->mac.type) {
    2806                 :          0 :                 case ixgbe_mac_82598EB:
    2807                 :          0 :                         speed = IXGBE_LINK_SPEED_82598_AUTONEG;
    2808                 :          0 :                         break;
    2809                 :          0 :                 case ixgbe_mac_82599EB:
    2810                 :            :                 case ixgbe_mac_X540:
    2811                 :          0 :                         speed = IXGBE_LINK_SPEED_82599_AUTONEG;
    2812                 :          0 :                         break;
    2813                 :          0 :                 case ixgbe_mac_X550:
    2814                 :            :                 case ixgbe_mac_X550EM_x:
    2815                 :            :                 case ixgbe_mac_X550EM_a:
    2816                 :          0 :                         speed = IXGBE_LINK_SPEED_X550_AUTONEG;
    2817                 :          0 :                         break;
    2818                 :          0 :                 default:
    2819                 :          0 :                         speed = IXGBE_LINK_SPEED_82599_AUTONEG;
    2820                 :            :                 }
    2821                 :            :         } else {
    2822         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_10G)
    2823                 :          0 :                         speed |= IXGBE_LINK_SPEED_10GB_FULL;
    2824         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_5G)
    2825                 :          0 :                         speed |= IXGBE_LINK_SPEED_5GB_FULL;
    2826         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_2_5G)
    2827                 :          0 :                         speed |= IXGBE_LINK_SPEED_2_5GB_FULL;
    2828         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_1G)
    2829                 :          0 :                         speed |= IXGBE_LINK_SPEED_1GB_FULL;
    2830         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_100M)
    2831                 :          0 :                         speed |= IXGBE_LINK_SPEED_100_FULL;
    2832         [ #  # ]:          0 :                 if (*link_speeds & RTE_ETH_LINK_SPEED_10M)
    2833                 :          0 :                         speed |= IXGBE_LINK_SPEED_10_FULL;
    2834                 :            :         }
    2835                 :            : 
    2836                 :          0 :         err = ixgbe_setup_link(hw, speed, link_up);
    2837         [ #  # ]:          0 :         if (err)
    2838                 :          0 :                 goto error;
    2839                 :            : 
    2840                 :          0 : skip_link_setup:
    2841                 :            : 
    2842         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle)) {
    2843                 :            :                 /* check if lsc interrupt is enabled */
    2844         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc != 0)
    2845                 :            :                         ixgbe_dev_lsc_interrupt_setup(dev, TRUE);
    2846                 :            :                 else
    2847                 :            :                         ixgbe_dev_lsc_interrupt_setup(dev, FALSE);
    2848                 :            :                 ixgbe_dev_macsec_interrupt_setup(dev);
    2849                 :            :         } else {
    2850                 :          0 :                 rte_intr_callback_unregister(intr_handle,
    2851                 :            :                                              ixgbe_dev_interrupt_handler, dev);
    2852         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc != 0)
    2853                 :          0 :                         PMD_INIT_LOG(INFO, "lsc won't enable because of"
    2854                 :            :                                      " no intr multiplex");
    2855                 :            :         }
    2856                 :            : 
    2857                 :            :         /* check if rxq interrupt is enabled */
    2858   [ #  #  #  # ]:          0 :         if (dev->data->dev_conf.intr_conf.rxq != 0 &&
    2859                 :          0 :             rte_intr_dp_is_en(intr_handle))
    2860                 :            :                 ixgbe_dev_rxq_interrupt_setup(dev);
    2861                 :            : 
    2862                 :            :         /* enable uio/vfio intr/eventfd mapping */
    2863                 :          0 :         rte_intr_enable(intr_handle);
    2864                 :            : 
    2865                 :            :         /* resume enabled intr since hw reset */
    2866                 :            :         ixgbe_enable_intr(dev);
    2867                 :          0 :         ixgbe_l2_tunnel_conf(dev);
    2868                 :          0 :         ixgbe_filter_restore(dev);
    2869                 :            : 
    2870   [ #  #  #  # ]:          0 :         if (tm_conf->root && !tm_conf->committed)
    2871                 :          0 :                 PMD_DRV_LOG(WARNING,
    2872                 :            :                             "please call hierarchy_commit() "
    2873                 :            :                             "before starting the port");
    2874                 :            : 
    2875                 :            :         /* wait for the controller to acquire link */
    2876                 :            :         err = ixgbe_wait_for_link_up(hw);
    2877                 :            :         if (err)
    2878                 :            :                 goto error;
    2879                 :            : 
    2880                 :            :         /*
    2881                 :            :          * Update link status right before return, because it may
    2882                 :            :          * start link configuration process in a separate thread.
    2883                 :            :          */
    2884                 :            :         ixgbe_dev_link_update(dev, 0);
    2885                 :            : 
    2886                 :            :         /* setup the macsec setting register */
    2887         [ #  # ]:          0 :         if (macsec_setting->offload_en)
    2888                 :          0 :                 ixgbe_dev_macsec_register_enable(dev, macsec_setting);
    2889                 :            : 
    2890                 :            :         return 0;
    2891                 :            : 
    2892                 :          0 : error:
    2893                 :          0 :         PMD_INIT_LOG(ERR, "failure in ixgbe_dev_start(): %d", err);
    2894                 :          0 :         ixgbe_dev_clear_queues(dev);
    2895                 :          0 :         return -EIO;
    2896                 :            : }
    2897                 :            : 
    2898                 :            : /*
    2899                 :            :  * Stop device: disable rx and tx functions to allow for reconfiguring.
    2900                 :            :  */
    2901                 :            : static int
    2902                 :          0 : ixgbe_dev_stop(struct rte_eth_dev *dev)
    2903                 :            : {
    2904                 :            :         struct rte_eth_link link;
    2905                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    2906                 :          0 :         struct ixgbe_hw *hw =
    2907                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2908                 :          0 :         struct ixgbe_vf_info *vfinfo =
    2909                 :            :                 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
    2910                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    2911                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    2912                 :            :         int vf;
    2913                 :            :         struct ixgbe_tm_conf *tm_conf =
    2914                 :            :                 IXGBE_DEV_PRIVATE_TO_TM_CONF(dev->data->dev_private);
    2915                 :            : 
    2916         [ #  # ]:          0 :         if (hw->adapter_stopped)
    2917                 :            :                 return 0;
    2918                 :            : 
    2919                 :          0 :         PMD_INIT_FUNC_TRACE();
    2920                 :            : 
    2921                 :          0 :         ixgbe_dev_wait_setup_link_complete(dev, 0);
    2922                 :            : 
    2923                 :            :         /* disable interrupts */
    2924                 :          0 :         ixgbe_disable_intr(hw);
    2925                 :            : 
    2926                 :            :         /* reset the NIC */
    2927                 :          0 :         ixgbe_pf_reset_hw(hw);
    2928                 :          0 :         hw->adapter_stopped = 0;
    2929                 :            : 
    2930                 :            :         /* stop adapter */
    2931                 :          0 :         ixgbe_stop_adapter(hw);
    2932                 :            : 
    2933   [ #  #  #  # ]:          0 :         for (vf = 0; vfinfo != NULL && vf < pci_dev->max_vfs; vf++)
    2934                 :          0 :                 vfinfo[vf].clear_to_send = false;
    2935                 :            : 
    2936         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
    2937                 :            :                 /* Turn off the copper */
    2938                 :          0 :                 ixgbe_set_phy_power(hw, false);
    2939                 :            :         } else {
    2940                 :            :                 /* Turn off the laser */
    2941                 :          0 :                 ixgbe_disable_tx_laser(hw);
    2942                 :            :         }
    2943                 :            : 
    2944                 :          0 :         ixgbe_dev_clear_queues(dev);
    2945                 :            : 
    2946                 :            :         /* Clear stored conf */
    2947                 :          0 :         dev->data->scattered_rx = 0;
    2948                 :          0 :         dev->data->lro = 0;
    2949                 :            : 
    2950                 :            :         /* Clear recorded link status */
    2951                 :            :         memset(&link, 0, sizeof(link));
    2952                 :          0 :         rte_eth_linkstatus_set(dev, &link);
    2953                 :            : 
    2954         [ #  # ]:          0 :         if (!rte_intr_allow_others(intr_handle))
    2955                 :            :                 /* resume to the default handler */
    2956                 :          0 :                 rte_intr_callback_register(intr_handle,
    2957                 :            :                                            ixgbe_dev_interrupt_handler,
    2958                 :            :                                            (void *)dev);
    2959                 :            : 
    2960                 :            :         /* Clean datapath event and queue/vec mapping */
    2961                 :          0 :         rte_intr_efd_disable(intr_handle);
    2962                 :          0 :         rte_intr_vec_list_free(intr_handle);
    2963                 :            : 
    2964                 :            :         /* reset hierarchy commit */
    2965                 :          0 :         tm_conf->committed = false;
    2966                 :            : 
    2967                 :          0 :         adapter->rss_reta_updated = 0;
    2968                 :            : 
    2969                 :          0 :         hw->adapter_stopped = true;
    2970                 :          0 :         dev->data->dev_started = 0;
    2971                 :            : 
    2972                 :          0 :         return 0;
    2973                 :            : }
    2974                 :            : 
    2975                 :            : /*
    2976                 :            :  * Set device link up: enable tx.
    2977                 :            :  */
    2978                 :            : static int
    2979                 :          0 : ixgbe_dev_set_link_up(struct rte_eth_dev *dev)
    2980                 :            : {
    2981                 :          0 :         struct ixgbe_hw *hw =
    2982                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    2983         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82599EB) {
    2984                 :            : #ifdef RTE_LIBRTE_IXGBE_BYPASS
    2985         [ #  # ]:          0 :                 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
    2986                 :            :                         /* Not supported in bypass mode */
    2987                 :          0 :                         PMD_INIT_LOG(ERR, "Set link up is not supported "
    2988                 :            :                                      "by device id 0x%x", hw->device_id);
    2989                 :          0 :                         return -ENOTSUP;
    2990                 :            :                 }
    2991                 :            : #endif
    2992                 :            :         }
    2993                 :            : 
    2994         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
    2995                 :            :                 /* Turn on the copper */
    2996                 :          0 :                 ixgbe_set_phy_power(hw, true);
    2997                 :            :         } else {
    2998                 :            :                 /* Turn on the laser */
    2999                 :          0 :                 ixgbe_enable_tx_laser(hw);
    3000                 :            :                 ixgbe_dev_link_update(dev, 0);
    3001                 :            :         }
    3002                 :            : 
    3003                 :            :         return 0;
    3004                 :            : }
    3005                 :            : 
    3006                 :            : /*
    3007                 :            :  * Set device link down: disable tx.
    3008                 :            :  */
    3009                 :            : static int
    3010                 :          0 : ixgbe_dev_set_link_down(struct rte_eth_dev *dev)
    3011                 :            : {
    3012                 :          0 :         struct ixgbe_hw *hw =
    3013                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3014         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82599EB) {
    3015                 :            : #ifdef RTE_LIBRTE_IXGBE_BYPASS
    3016         [ #  # ]:          0 :                 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
    3017                 :            :                         /* Not supported in bypass mode */
    3018                 :          0 :                         PMD_INIT_LOG(ERR, "Set link down is not supported "
    3019                 :            :                                      "by device id 0x%x", hw->device_id);
    3020                 :          0 :                         return -ENOTSUP;
    3021                 :            :                 }
    3022                 :            : #endif
    3023                 :            :         }
    3024                 :            : 
    3025         [ #  # ]:          0 :         if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper) {
    3026                 :            :                 /* Turn off the copper */
    3027                 :          0 :                 ixgbe_set_phy_power(hw, false);
    3028                 :            :         } else {
    3029                 :            :                 /* Turn off the laser */
    3030                 :          0 :                 ixgbe_disable_tx_laser(hw);
    3031                 :            :                 ixgbe_dev_link_update(dev, 0);
    3032                 :            :         }
    3033                 :            : 
    3034                 :            :         return 0;
    3035                 :            : }
    3036                 :            : 
    3037                 :            : /*
    3038                 :            :  * Reset and stop device.
    3039                 :            :  */
    3040                 :            : static int
    3041                 :          0 : ixgbe_dev_close(struct rte_eth_dev *dev)
    3042                 :            : {
    3043                 :          0 :         struct ixgbe_hw *hw =
    3044                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3045                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    3046                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    3047                 :            :         int retries = 0;
    3048                 :            :         int ret;
    3049                 :            : 
    3050                 :          0 :         PMD_INIT_FUNC_TRACE();
    3051         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    3052                 :            :                 return 0;
    3053                 :            : 
    3054                 :          0 :         ixgbe_pf_reset_hw(hw);
    3055                 :            : 
    3056                 :          0 :         ret = ixgbe_dev_stop(dev);
    3057                 :            : 
    3058                 :          0 :         ixgbe_dev_free_queues(dev);
    3059                 :            : 
    3060                 :          0 :         ixgbe_disable_pcie_primary(hw);
    3061                 :            : 
    3062                 :            :         /* reprogram the RAR[0] in case user changed it. */
    3063                 :          0 :         ixgbe_set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
    3064                 :            : 
    3065                 :            :         /* Unlock any pending hardware semaphore */
    3066                 :          0 :         ixgbe_swfw_lock_reset(hw);
    3067                 :            : 
    3068                 :            :         /* disable uio intr before callback unregister */
    3069                 :          0 :         rte_intr_disable(intr_handle);
    3070                 :            : 
    3071                 :            :         do {
    3072                 :          0 :                 ret = rte_intr_callback_unregister(intr_handle,
    3073                 :            :                                 ixgbe_dev_interrupt_handler, dev);
    3074         [ #  # ]:          0 :                 if (ret >= 0 || ret == -ENOENT) {
    3075                 :            :                         break;
    3076         [ #  # ]:          0 :                 } else if (ret != -EAGAIN) {
    3077                 :          0 :                         PMD_INIT_LOG(ERR,
    3078                 :            :                                 "intr callback unregister failed: %d",
    3079                 :            :                                 ret);
    3080                 :            :                 }
    3081                 :            :                 rte_delay_ms(100);
    3082         [ #  # ]:          0 :         } while (retries++ < (10 + IXGBE_LINK_UP_TIME));
    3083                 :            : 
    3084                 :            :         /* cancel the delay handler before remove dev */
    3085                 :          0 :         rte_eal_alarm_cancel(ixgbe_dev_interrupt_delayed_handler, dev);
    3086                 :            : 
    3087                 :            :         /* uninitialize PF if max_vfs not zero */
    3088                 :          0 :         ixgbe_pf_host_uninit(dev);
    3089                 :            : 
    3090                 :            :         /* remove all the fdir filters & hash */
    3091                 :          0 :         ixgbe_fdir_filter_uninit(dev);
    3092                 :            : 
    3093                 :            :         /* remove all the L2 tunnel filters & hash */
    3094                 :          0 :         ixgbe_l2_tn_filter_uninit(dev);
    3095                 :            : 
    3096                 :            :         /* Remove all ntuple filters of the device */
    3097                 :          0 :         ixgbe_ntuple_filter_uninit(dev);
    3098                 :            : 
    3099                 :            :         /* clear all the filters list */
    3100                 :          0 :         ixgbe_filterlist_flush();
    3101                 :            : 
    3102                 :            :         /* Remove all Traffic Manager configuration */
    3103                 :          0 :         ixgbe_tm_conf_uninit(dev);
    3104                 :            : 
    3105                 :            : #ifdef RTE_LIB_SECURITY
    3106                 :          0 :         rte_free(dev->security_ctx);
    3107                 :          0 :         dev->security_ctx = NULL;
    3108                 :            : #endif
    3109                 :            : 
    3110                 :          0 :         return ret;
    3111                 :            : }
    3112                 :            : 
    3113                 :            : /*
    3114                 :            :  * Reset PF device.
    3115                 :            :  */
    3116                 :            : static int
    3117                 :          0 : ixgbe_dev_reset(struct rte_eth_dev *dev)
    3118                 :            : {
    3119                 :            :         int ret;
    3120                 :            : 
    3121                 :            :         /* When a DPDK PMD PF begin to reset PF port, it should notify all
    3122                 :            :          * its VF to make them align with it. The detailed notification
    3123                 :            :          * mechanism is PMD specific. As to ixgbe PF, it is rather complex.
    3124                 :            :          * To avoid unexpected behavior in VF, currently reset of PF with
    3125                 :            :          * SR-IOV activation is not supported. It might be supported later.
    3126                 :            :          */
    3127         [ #  # ]:          0 :         if (dev->data->sriov.active)
    3128                 :            :                 return -ENOTSUP;
    3129                 :            : 
    3130                 :          0 :         ret = eth_ixgbe_dev_uninit(dev);
    3131         [ #  # ]:          0 :         if (ret)
    3132                 :            :                 return ret;
    3133                 :            : 
    3134                 :          0 :         ret = eth_ixgbe_dev_init(dev, NULL);
    3135                 :            : 
    3136                 :          0 :         return ret;
    3137                 :            : }
    3138                 :            : 
    3139                 :            : static void
    3140                 :          0 : ixgbe_read_stats_registers(struct ixgbe_hw *hw,
    3141                 :            :                            struct ixgbe_hw_stats *hw_stats,
    3142                 :            :                            struct ixgbe_macsec_stats *macsec_stats,
    3143                 :            :                            uint64_t *total_missed_rx, uint64_t *total_qbrc,
    3144                 :            :                            uint64_t *total_qprc, uint64_t *total_qprdc)
    3145                 :            : {
    3146                 :            :         uint32_t bprc, lxon, lxoff, total;
    3147                 :            :         uint32_t delta_gprc = 0;
    3148                 :            :         unsigned i;
    3149                 :            :         /* Workaround for RX byte count not including CRC bytes when CRC
    3150                 :            :          * strip is enabled. CRC bytes are removed from counters when crc_strip
    3151                 :            :          * is disabled.
    3152                 :            :          */
    3153                 :          0 :         int crc_strip = (IXGBE_READ_REG(hw, IXGBE_HLREG0) &
    3154                 :            :                         IXGBE_HLREG0_RXCRCSTRP);
    3155                 :            : 
    3156                 :          0 :         hw_stats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
    3157                 :          0 :         hw_stats->illerrc += IXGBE_READ_REG(hw, IXGBE_ILLERRC);
    3158                 :          0 :         hw_stats->errbc += IXGBE_READ_REG(hw, IXGBE_ERRBC);
    3159                 :          0 :         hw_stats->mspdc += IXGBE_READ_REG(hw, IXGBE_MSPDC);
    3160                 :            : 
    3161         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
    3162                 :          0 :                 uint32_t mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
    3163                 :            : 
    3164                 :            :                 /* global total per queue */
    3165                 :          0 :                 hw_stats->mpc[i] += mp;
    3166                 :            :                 /* Running comprehensive total for stats display */
    3167                 :          0 :                 *total_missed_rx += hw_stats->mpc[i];
    3168         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_82598EB) {
    3169                 :          0 :                         hw_stats->rnbc[i] +=
    3170                 :          0 :                             IXGBE_READ_REG(hw, IXGBE_RNBC(i));
    3171                 :          0 :                         hw_stats->pxonrxc[i] +=
    3172                 :          0 :                                 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
    3173                 :          0 :                         hw_stats->pxoffrxc[i] +=
    3174                 :          0 :                                 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
    3175                 :            :                 } else {
    3176                 :          0 :                         hw_stats->pxonrxc[i] +=
    3177                 :          0 :                                 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
    3178                 :          0 :                         hw_stats->pxoffrxc[i] +=
    3179                 :          0 :                                 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
    3180                 :          0 :                         hw_stats->pxon2offc[i] +=
    3181                 :          0 :                                 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
    3182                 :            :                 }
    3183                 :          0 :                 hw_stats->pxontxc[i] +=
    3184                 :          0 :                     IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
    3185                 :          0 :                 hw_stats->pxofftxc[i] +=
    3186                 :          0 :                     IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
    3187                 :            :         }
    3188         [ #  # ]:          0 :         for (i = 0; i < IXGBE_QUEUE_STAT_COUNTERS; i++) {
    3189                 :          0 :                 uint32_t delta_qprc = IXGBE_READ_REG(hw, IXGBE_QPRC(i));
    3190                 :          0 :                 uint32_t delta_qptc = IXGBE_READ_REG(hw, IXGBE_QPTC(i));
    3191                 :          0 :                 uint32_t delta_qprdc = IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
    3192                 :            : 
    3193                 :          0 :                 delta_gprc += delta_qprc;
    3194                 :            : 
    3195                 :          0 :                 hw_stats->qprc[i] += delta_qprc;
    3196                 :          0 :                 hw_stats->qptc[i] += delta_qptc;
    3197                 :            : 
    3198                 :          0 :                 hw_stats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
    3199                 :          0 :                 hw_stats->qbrc[i] +=
    3200                 :          0 :                     ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)) << 32);
    3201         [ #  # ]:          0 :                 if (crc_strip == 0)
    3202                 :          0 :                         hw_stats->qbrc[i] -= delta_qprc * RTE_ETHER_CRC_LEN;
    3203                 :            : 
    3204                 :          0 :                 hw_stats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
    3205                 :          0 :                 hw_stats->qbtc[i] +=
    3206                 :          0 :                     ((uint64_t)IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)) << 32);
    3207                 :            : 
    3208                 :          0 :                 hw_stats->qprdc[i] += delta_qprdc;
    3209                 :          0 :                 *total_qprdc += hw_stats->qprdc[i];
    3210                 :            : 
    3211                 :          0 :                 *total_qprc += hw_stats->qprc[i];
    3212                 :          0 :                 *total_qbrc += hw_stats->qbrc[i];
    3213                 :            :         }
    3214                 :          0 :         hw_stats->mlfc += IXGBE_READ_REG(hw, IXGBE_MLFC);
    3215                 :          0 :         hw_stats->mrfc += IXGBE_READ_REG(hw, IXGBE_MRFC);
    3216                 :          0 :         hw_stats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
    3217                 :            : 
    3218                 :            :         /*
    3219                 :            :          * An errata states that gprc actually counts good + missed packets:
    3220                 :            :          * Workaround to set gprc to summated queue packet receives
    3221                 :            :          */
    3222                 :          0 :         hw_stats->gprc = *total_qprc;
    3223                 :            : 
    3224         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
    3225                 :          0 :                 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
    3226                 :          0 :                 hw_stats->gorc += ((u64)IXGBE_READ_REG(hw, IXGBE_GORCH) << 32);
    3227                 :          0 :                 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
    3228                 :          0 :                 hw_stats->gotc += ((u64)IXGBE_READ_REG(hw, IXGBE_GOTCH) << 32);
    3229                 :          0 :                 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
    3230                 :          0 :                 hw_stats->tor += ((u64)IXGBE_READ_REG(hw, IXGBE_TORH) << 32);
    3231                 :          0 :                 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
    3232                 :          0 :                 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
    3233                 :            :         } else {
    3234                 :          0 :                 hw_stats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
    3235                 :          0 :                 hw_stats->lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
    3236                 :            :                 /* 82598 only has a counter in the high register */
    3237                 :          0 :                 hw_stats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
    3238                 :          0 :                 hw_stats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
    3239                 :          0 :                 hw_stats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
    3240                 :            :         }
    3241                 :          0 :         uint64_t old_tpr = hw_stats->tpr;
    3242                 :            : 
    3243                 :          0 :         hw_stats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
    3244                 :          0 :         hw_stats->tpt += IXGBE_READ_REG(hw, IXGBE_TPT);
    3245                 :            : 
    3246         [ #  # ]:          0 :         if (crc_strip == 0)
    3247                 :          0 :                 hw_stats->gorc -= delta_gprc * RTE_ETHER_CRC_LEN;
    3248                 :            : 
    3249                 :          0 :         uint64_t delta_gptc = IXGBE_READ_REG(hw, IXGBE_GPTC);
    3250                 :          0 :         hw_stats->gptc += delta_gptc;
    3251                 :          0 :         hw_stats->gotc -= delta_gptc * RTE_ETHER_CRC_LEN;
    3252                 :          0 :         hw_stats->tor -= (hw_stats->tpr - old_tpr) * RTE_ETHER_CRC_LEN;
    3253                 :            : 
    3254                 :            :         /*
    3255                 :            :          * Workaround: mprc hardware is incorrectly counting
    3256                 :            :          * broadcasts, so for now we subtract those.
    3257                 :            :          */
    3258                 :          0 :         bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
    3259                 :          0 :         hw_stats->bprc += bprc;
    3260                 :          0 :         hw_stats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
    3261         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
    3262                 :          0 :                 hw_stats->mprc -= bprc;
    3263                 :            : 
    3264                 :          0 :         hw_stats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
    3265                 :          0 :         hw_stats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
    3266                 :          0 :         hw_stats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
    3267                 :          0 :         hw_stats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
    3268                 :          0 :         hw_stats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
    3269                 :          0 :         hw_stats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
    3270                 :            : 
    3271                 :          0 :         lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
    3272                 :          0 :         hw_stats->lxontxc += lxon;
    3273                 :          0 :         lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
    3274                 :          0 :         hw_stats->lxofftxc += lxoff;
    3275                 :          0 :         total = lxon + lxoff;
    3276                 :            : 
    3277                 :          0 :         hw_stats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
    3278                 :          0 :         hw_stats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
    3279                 :          0 :         hw_stats->gptc -= total;
    3280                 :          0 :         hw_stats->mptc -= total;
    3281                 :          0 :         hw_stats->ptc64 -= total;
    3282                 :          0 :         hw_stats->gotc -= total * RTE_ETHER_MIN_LEN;
    3283                 :            : 
    3284                 :          0 :         hw_stats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
    3285                 :          0 :         hw_stats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
    3286                 :          0 :         hw_stats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
    3287                 :          0 :         hw_stats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
    3288                 :          0 :         hw_stats->mngprc += IXGBE_READ_REG(hw, IXGBE_MNGPRC);
    3289                 :          0 :         hw_stats->mngpdc += IXGBE_READ_REG(hw, IXGBE_MNGPDC);
    3290                 :          0 :         hw_stats->mngptc += IXGBE_READ_REG(hw, IXGBE_MNGPTC);
    3291                 :          0 :         hw_stats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
    3292                 :          0 :         hw_stats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
    3293                 :          0 :         hw_stats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
    3294                 :          0 :         hw_stats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
    3295                 :          0 :         hw_stats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
    3296                 :          0 :         hw_stats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
    3297                 :          0 :         hw_stats->xec += IXGBE_READ_REG(hw, IXGBE_XEC);
    3298                 :          0 :         hw_stats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
    3299                 :          0 :         hw_stats->fclast += IXGBE_READ_REG(hw, IXGBE_FCLAST);
    3300                 :            :         /* Only read FCOE on 82599 */
    3301         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
    3302                 :          0 :                 hw_stats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
    3303                 :          0 :                 hw_stats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
    3304                 :          0 :                 hw_stats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
    3305                 :          0 :                 hw_stats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
    3306                 :          0 :                 hw_stats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
    3307                 :            :         }
    3308                 :            : 
    3309                 :            :         /* Flow Director Stats registers */
    3310         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
    3311                 :          0 :                 hw_stats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
    3312                 :          0 :                 hw_stats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
    3313                 :          0 :                 hw_stats->fdirustat_add += IXGBE_READ_REG(hw,
    3314                 :          0 :                                         IXGBE_FDIRUSTAT) & 0xFFFF;
    3315                 :          0 :                 hw_stats->fdirustat_remove += (IXGBE_READ_REG(hw,
    3316                 :          0 :                                         IXGBE_FDIRUSTAT) >> 16) & 0xFFFF;
    3317                 :          0 :                 hw_stats->fdirfstat_fadd += IXGBE_READ_REG(hw,
    3318                 :          0 :                                         IXGBE_FDIRFSTAT) & 0xFFFF;
    3319                 :          0 :                 hw_stats->fdirfstat_fremove += (IXGBE_READ_REG(hw,
    3320                 :          0 :                                         IXGBE_FDIRFSTAT) >> 16) & 0xFFFF;
    3321                 :            :         }
    3322                 :            :         /* MACsec Stats registers */
    3323                 :          0 :         macsec_stats->out_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECTXUT);
    3324                 :          0 :         macsec_stats->out_pkts_encrypted +=
    3325                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECTXPKTE);
    3326                 :          0 :         macsec_stats->out_pkts_protected +=
    3327                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECTXPKTP);
    3328                 :          0 :         macsec_stats->out_octets_encrypted +=
    3329                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECTXOCTE);
    3330                 :          0 :         macsec_stats->out_octets_protected +=
    3331                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECTXOCTP);
    3332                 :          0 :         macsec_stats->in_pkts_untagged += IXGBE_READ_REG(hw, IXGBE_LSECRXUT);
    3333                 :          0 :         macsec_stats->in_pkts_badtag += IXGBE_READ_REG(hw, IXGBE_LSECRXBAD);
    3334                 :          0 :         macsec_stats->in_pkts_nosci += IXGBE_READ_REG(hw, IXGBE_LSECRXNOSCI);
    3335                 :          0 :         macsec_stats->in_pkts_unknownsci +=
    3336                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECRXUNSCI);
    3337                 :          0 :         macsec_stats->in_octets_decrypted +=
    3338                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECRXOCTD);
    3339                 :          0 :         macsec_stats->in_octets_validated +=
    3340                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECRXOCTV);
    3341                 :          0 :         macsec_stats->in_pkts_unchecked += IXGBE_READ_REG(hw, IXGBE_LSECRXUNCH);
    3342                 :          0 :         macsec_stats->in_pkts_delayed += IXGBE_READ_REG(hw, IXGBE_LSECRXDELAY);
    3343                 :          0 :         macsec_stats->in_pkts_late += IXGBE_READ_REG(hw, IXGBE_LSECRXLATE);
    3344         [ #  # ]:          0 :         for (i = 0; i < 2; i++) {
    3345                 :          0 :                 macsec_stats->in_pkts_ok +=
    3346                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_LSECRXOK(i));
    3347                 :          0 :                 macsec_stats->in_pkts_invalid +=
    3348                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_LSECRXINV(i));
    3349                 :          0 :                 macsec_stats->in_pkts_notvalid +=
    3350                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_LSECRXNV(i));
    3351                 :            :         }
    3352                 :          0 :         macsec_stats->in_pkts_unusedsa += IXGBE_READ_REG(hw, IXGBE_LSECRXUNSA);
    3353                 :          0 :         macsec_stats->in_pkts_notusingsa +=
    3354                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LSECRXNUSA);
    3355                 :          0 : }
    3356                 :            : 
    3357                 :            : /*
    3358                 :            :  * This function is based on ixgbe_update_stats_counters() in ixgbe/ixgbe.c
    3359                 :            :  */
    3360                 :            : static int
    3361                 :          0 : ixgbe_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
    3362                 :            : {
    3363                 :          0 :         struct ixgbe_hw *hw =
    3364                 :          0 :                         IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3365                 :          0 :         struct ixgbe_hw_stats *hw_stats =
    3366                 :            :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3367                 :          0 :         struct ixgbe_macsec_stats *macsec_stats =
    3368                 :            :                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
    3369                 :            :                                 dev->data->dev_private);
    3370                 :            :         uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
    3371                 :            :         unsigned i;
    3372                 :            : 
    3373                 :          0 :         total_missed_rx = 0;
    3374                 :          0 :         total_qbrc = 0;
    3375                 :          0 :         total_qprc = 0;
    3376                 :          0 :         total_qprdc = 0;
    3377                 :            : 
    3378                 :          0 :         ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
    3379                 :            :                         &total_qbrc, &total_qprc, &total_qprdc);
    3380                 :            : 
    3381         [ #  # ]:          0 :         if (stats == NULL)
    3382                 :            :                 return -EINVAL;
    3383                 :            : 
    3384                 :            :         /* Fill out the rte_eth_stats statistics structure */
    3385                 :          0 :         stats->ipackets = total_qprc;
    3386                 :          0 :         stats->ibytes = total_qbrc;
    3387                 :          0 :         stats->opackets = hw_stats->gptc;
    3388                 :          0 :         stats->obytes = hw_stats->gotc;
    3389                 :            : 
    3390         [ #  # ]:          0 :         for (i = 0; i < RTE_MIN_T(IXGBE_QUEUE_STAT_COUNTERS,
    3391                 :          0 :                         RTE_ETHDEV_QUEUE_STAT_CNTRS, typeof(i)); i++) {
    3392                 :          0 :                 stats->q_ipackets[i] = hw_stats->qprc[i];
    3393                 :          0 :                 stats->q_opackets[i] = hw_stats->qptc[i];
    3394                 :          0 :                 stats->q_ibytes[i] = hw_stats->qbrc[i];
    3395                 :          0 :                 stats->q_obytes[i] = hw_stats->qbtc[i];
    3396                 :          0 :                 stats->q_errors[i] = hw_stats->qprdc[i];
    3397                 :            :         }
    3398                 :            : 
    3399                 :            :         /* Rx Errors */
    3400                 :          0 :         stats->imissed  = total_missed_rx;
    3401                 :          0 :         stats->ierrors  = hw_stats->crcerrs +
    3402                 :          0 :                           hw_stats->mspdc +
    3403                 :          0 :                           hw_stats->rlec +
    3404                 :          0 :                           hw_stats->ruc +
    3405                 :          0 :                           hw_stats->roc +
    3406                 :          0 :                           hw_stats->illerrc +
    3407                 :          0 :                           hw_stats->errbc +
    3408                 :          0 :                           hw_stats->rfc +
    3409                 :          0 :                           hw_stats->fccrc +
    3410                 :          0 :                           hw_stats->fclast;
    3411                 :            : 
    3412                 :            :         /*
    3413                 :            :          * 82599 errata, UDP frames with a 0 checksum can be marked as checksum
    3414                 :            :          * errors.
    3415                 :            :          */
    3416         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82599EB)
    3417                 :          0 :                 stats->ierrors += hw_stats->xec;
    3418                 :            : 
    3419                 :            :         /* Tx Errors */
    3420                 :          0 :         stats->oerrors  = 0;
    3421                 :          0 :         return 0;
    3422                 :            : }
    3423                 :            : 
    3424                 :            : static int
    3425                 :          0 : ixgbe_dev_stats_reset(struct rte_eth_dev *dev)
    3426                 :            : {
    3427                 :          0 :         struct ixgbe_hw_stats *stats =
    3428                 :          0 :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3429                 :            : 
    3430                 :            :         /* HW registers are cleared on read */
    3431                 :          0 :         ixgbe_dev_stats_get(dev, NULL);
    3432                 :            : 
    3433                 :            :         /* Reset software totals */
    3434                 :            :         memset(stats, 0, sizeof(*stats));
    3435                 :            : 
    3436                 :          0 :         return 0;
    3437                 :            : }
    3438                 :            : 
    3439                 :            : /* This function calculates the number of xstats based on the current config */
    3440                 :            : 
    3441                 :            : #define IXGBE_XSTATS_CALC_NUM   \
    3442                 :            :         (IXGBE_NB_HW_STATS + IXGBE_NB_MACSEC_STATS + \
    3443                 :            :         (IXGBE_NB_RXQ_PRIO_STATS * IXGBE_NB_RXQ_PRIO_VALUES) + \
    3444                 :            :         (IXGBE_NB_TXQ_PRIO_STATS * IXGBE_NB_TXQ_PRIO_VALUES))
    3445                 :            : 
    3446                 :            : static unsigned
    3447                 :            : ixgbe_xstats_calc_num(void)
    3448                 :            : {
    3449                 :            :         return IXGBE_XSTATS_CALC_NUM;
    3450                 :            : }
    3451                 :            : 
    3452                 :          0 : static int ixgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
    3453                 :            :         struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned int size)
    3454                 :            : {
    3455                 :            :         const unsigned cnt_stats = ixgbe_xstats_calc_num();
    3456                 :            :         unsigned stat, i, count;
    3457                 :            : 
    3458         [ #  # ]:          0 :         if (xstats_names != NULL) {
    3459                 :            :                 count = 0;
    3460                 :            : 
    3461                 :            :                 /* Note: limit >= cnt_stats checked upstream
    3462                 :            :                  * in rte_eth_xstats_names()
    3463                 :            :                  */
    3464                 :            : 
    3465                 :            :                 /* Extended stats from ixgbe_hw_stats */
    3466         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
    3467                 :          0 :                         strlcpy(xstats_names[count].name,
    3468                 :            :                                 rte_ixgbe_stats_strings[i].name,
    3469                 :            :                                 sizeof(xstats_names[count].name));
    3470                 :          0 :                         count++;
    3471                 :            :                 }
    3472                 :            : 
    3473                 :            :                 /* MACsec Stats */
    3474         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
    3475                 :          0 :                         strlcpy(xstats_names[count].name,
    3476                 :            :                                 rte_ixgbe_macsec_strings[i].name,
    3477                 :            :                                 sizeof(xstats_names[count].name));
    3478                 :          0 :                         count++;
    3479                 :            :                 }
    3480                 :            : 
    3481                 :            :                 /* RX Priority Stats */
    3482         [ #  # ]:          0 :                 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
    3483         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
    3484                 :          0 :                                 snprintf(xstats_names[count].name,
    3485                 :            :                                         sizeof(xstats_names[count].name),
    3486                 :            :                                         "rx_priority%u_%s", i,
    3487                 :          0 :                                         rte_ixgbe_rxq_strings[stat].name);
    3488                 :          0 :                                 count++;
    3489                 :            :                         }
    3490                 :            :                 }
    3491                 :            : 
    3492                 :            :                 /* TX Priority Stats */
    3493         [ #  # ]:          0 :                 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
    3494         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
    3495                 :          0 :                                 snprintf(xstats_names[count].name,
    3496                 :            :                                         sizeof(xstats_names[count].name),
    3497                 :            :                                         "tx_priority%u_%s", i,
    3498                 :          0 :                                         rte_ixgbe_txq_strings[stat].name);
    3499                 :          0 :                                 count++;
    3500                 :            :                         }
    3501                 :            :                 }
    3502                 :            :         }
    3503                 :          0 :         return cnt_stats;
    3504                 :            : }
    3505                 :            : 
    3506                 :          0 : static int ixgbe_dev_xstats_get_names_by_id(
    3507                 :            :         struct rte_eth_dev *dev,
    3508                 :            :         const uint64_t *ids,
    3509                 :            :         struct rte_eth_xstat_name *xstats_names,
    3510                 :            :         unsigned int limit)
    3511                 :            : {
    3512         [ #  # ]:          0 :         if (!ids) {
    3513                 :            :                 const unsigned int cnt_stats = ixgbe_xstats_calc_num();
    3514                 :            :                 unsigned int stat, i, count;
    3515                 :            : 
    3516         [ #  # ]:          0 :                 if (xstats_names != NULL) {
    3517                 :            :                         count = 0;
    3518                 :            : 
    3519                 :            :                         /* Note: limit >= cnt_stats checked upstream
    3520                 :            :                          * in rte_eth_xstats_names()
    3521                 :            :                          */
    3522                 :            : 
    3523                 :            :                         /* Extended stats from ixgbe_hw_stats */
    3524         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
    3525                 :          0 :                                 strlcpy(xstats_names[count].name,
    3526                 :            :                                         rte_ixgbe_stats_strings[i].name,
    3527                 :            :                                         sizeof(xstats_names[count].name));
    3528                 :          0 :                                 count++;
    3529                 :            :                         }
    3530                 :            : 
    3531                 :            :                         /* MACsec Stats */
    3532         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
    3533                 :          0 :                                 strlcpy(xstats_names[count].name,
    3534                 :            :                                         rte_ixgbe_macsec_strings[i].name,
    3535                 :            :                                         sizeof(xstats_names[count].name));
    3536                 :          0 :                                 count++;
    3537                 :            :                         }
    3538                 :            : 
    3539                 :            :                         /* RX Priority Stats */
    3540         [ #  # ]:          0 :                         for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
    3541         [ #  # ]:          0 :                                 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
    3542                 :          0 :                                         snprintf(xstats_names[count].name,
    3543                 :            :                                             sizeof(xstats_names[count].name),
    3544                 :            :                                             "rx_priority%u_%s", i,
    3545                 :          0 :                                             rte_ixgbe_rxq_strings[stat].name);
    3546                 :          0 :                                         count++;
    3547                 :            :                                 }
    3548                 :            :                         }
    3549                 :            : 
    3550                 :            :                         /* TX Priority Stats */
    3551         [ #  # ]:          0 :                         for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
    3552         [ #  # ]:          0 :                                 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
    3553                 :          0 :                                         snprintf(xstats_names[count].name,
    3554                 :            :                                             sizeof(xstats_names[count].name),
    3555                 :            :                                             "tx_priority%u_%s", i,
    3556                 :          0 :                                             rte_ixgbe_txq_strings[stat].name);
    3557                 :          0 :                                         count++;
    3558                 :            :                                 }
    3559                 :            :                         }
    3560                 :            :                 }
    3561                 :          0 :                 return cnt_stats;
    3562                 :            :         }
    3563                 :            : 
    3564                 :            :         uint16_t i;
    3565                 :            :         struct rte_eth_xstat_name xstats_names_copy[IXGBE_XSTATS_CALC_NUM];
    3566                 :            :         const uint16_t size = RTE_DIM(xstats_names_copy);
    3567                 :            : 
    3568                 :          0 :         ixgbe_dev_xstats_get_names_by_id(dev, NULL, xstats_names_copy,
    3569                 :            :                         size);
    3570                 :            : 
    3571         [ #  # ]:          0 :         for (i = 0; i < limit; i++) {
    3572         [ #  # ]:          0 :                 if (ids[i] >= size) {
    3573                 :          0 :                         PMD_INIT_LOG(ERR, "id value isn't valid");
    3574                 :          0 :                         return -1;
    3575                 :            :                 }
    3576                 :          0 :                 strcpy(xstats_names[i].name,
    3577                 :          0 :                                 xstats_names_copy[ids[i]].name);
    3578                 :            :         }
    3579                 :          0 :         return limit;
    3580                 :            : }
    3581                 :            : 
    3582                 :          0 : static int ixgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
    3583                 :            :         struct rte_eth_xstat_name *xstats_names, unsigned limit)
    3584                 :            : {
    3585                 :            :         unsigned i;
    3586                 :            : 
    3587         [ #  # ]:          0 :         if (limit < IXGBEVF_NB_XSTATS && xstats_names != NULL)
    3588                 :            :                 return -ENOMEM;
    3589                 :            : 
    3590         [ #  # ]:          0 :         if (xstats_names != NULL)
    3591         [ #  # ]:          0 :                 for (i = 0; i < IXGBEVF_NB_XSTATS; i++)
    3592                 :          0 :                         strlcpy(xstats_names[i].name,
    3593                 :            :                                 rte_ixgbevf_stats_strings[i].name,
    3594                 :            :                                 sizeof(xstats_names[i].name));
    3595                 :            :         return IXGBEVF_NB_XSTATS;
    3596                 :            : }
    3597                 :            : 
    3598                 :            : static int
    3599                 :          0 : ixgbe_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
    3600                 :            :                                          unsigned n)
    3601                 :            : {
    3602                 :          0 :         struct ixgbe_hw *hw =
    3603                 :          0 :                         IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3604                 :          0 :         struct ixgbe_hw_stats *hw_stats =
    3605                 :            :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3606                 :          0 :         struct ixgbe_macsec_stats *macsec_stats =
    3607                 :            :                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
    3608                 :            :                                 dev->data->dev_private);
    3609                 :            :         uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
    3610                 :            :         unsigned i, stat, count = 0;
    3611                 :            : 
    3612                 :            :         count = ixgbe_xstats_calc_num();
    3613                 :            : 
    3614         [ #  # ]:          0 :         if (n < count)
    3615                 :            :                 return count;
    3616                 :            : 
    3617                 :          0 :         total_missed_rx = 0;
    3618                 :          0 :         total_qbrc = 0;
    3619                 :          0 :         total_qprc = 0;
    3620                 :          0 :         total_qprdc = 0;
    3621                 :            : 
    3622                 :          0 :         ixgbe_read_stats_registers(hw, hw_stats, macsec_stats, &total_missed_rx,
    3623                 :            :                         &total_qbrc, &total_qprc, &total_qprdc);
    3624                 :            : 
    3625                 :            :         /* If this is a reset xstats is NULL, and we have cleared the
    3626                 :            :          * registers by reading them.
    3627                 :            :          */
    3628         [ #  # ]:          0 :         if (!xstats)
    3629                 :            :                 return 0;
    3630                 :            : 
    3631                 :            :         /* Extended stats from ixgbe_hw_stats */
    3632                 :            :         count = 0;
    3633         [ #  # ]:          0 :         for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
    3634                 :          0 :                 xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
    3635                 :          0 :                                 rte_ixgbe_stats_strings[i].offset);
    3636                 :          0 :                 xstats[count].id = count;
    3637                 :          0 :                 count++;
    3638                 :            :         }
    3639                 :            : 
    3640                 :            :         /* MACsec Stats */
    3641         [ #  # ]:          0 :         for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
    3642                 :          0 :                 xstats[count].value = *(uint64_t *)(((char *)macsec_stats) +
    3643                 :          0 :                                 rte_ixgbe_macsec_strings[i].offset);
    3644                 :          0 :                 xstats[count].id = count;
    3645                 :          0 :                 count++;
    3646                 :            :         }
    3647                 :            : 
    3648                 :            :         /* RX Priority Stats */
    3649         [ #  # ]:          0 :         for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
    3650         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
    3651                 :          0 :                         xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
    3652                 :          0 :                                         rte_ixgbe_rxq_strings[stat].offset +
    3653                 :          0 :                                         (sizeof(uint64_t) * i));
    3654                 :          0 :                         xstats[count].id = count;
    3655                 :          0 :                         count++;
    3656                 :            :                 }
    3657                 :            :         }
    3658                 :            : 
    3659                 :            :         /* TX Priority Stats */
    3660         [ #  # ]:          0 :         for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
    3661         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
    3662                 :          0 :                         xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
    3663                 :          0 :                                         rte_ixgbe_txq_strings[stat].offset +
    3664                 :          0 :                                         (sizeof(uint64_t) * i));
    3665                 :          0 :                         xstats[count].id = count;
    3666                 :          0 :                         count++;
    3667                 :            :                 }
    3668                 :            :         }
    3669                 :          0 :         return count;
    3670                 :            : }
    3671                 :            : 
    3672                 :            : static int
    3673                 :          0 : ixgbe_dev_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
    3674                 :            :                 uint64_t *values, unsigned int n)
    3675                 :            : {
    3676         [ #  # ]:          0 :         if (!ids) {
    3677                 :          0 :                 struct ixgbe_hw *hw =
    3678                 :          0 :                                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3679                 :          0 :                 struct ixgbe_hw_stats *hw_stats =
    3680                 :            :                                 IXGBE_DEV_PRIVATE_TO_STATS(
    3681                 :            :                                                 dev->data->dev_private);
    3682                 :          0 :                 struct ixgbe_macsec_stats *macsec_stats =
    3683                 :            :                                 IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
    3684                 :            :                                         dev->data->dev_private);
    3685                 :            :                 uint64_t total_missed_rx, total_qbrc, total_qprc, total_qprdc;
    3686                 :            :                 unsigned int i, stat, count = 0;
    3687                 :            : 
    3688                 :            :                 count = ixgbe_xstats_calc_num();
    3689                 :            : 
    3690         [ #  # ]:          0 :                 if (!ids && n < count)
    3691                 :            :                         return count;
    3692                 :            : 
    3693                 :          0 :                 total_missed_rx = 0;
    3694                 :          0 :                 total_qbrc = 0;
    3695                 :          0 :                 total_qprc = 0;
    3696                 :          0 :                 total_qprdc = 0;
    3697                 :            : 
    3698                 :          0 :                 ixgbe_read_stats_registers(hw, hw_stats, macsec_stats,
    3699                 :            :                                 &total_missed_rx, &total_qbrc, &total_qprc,
    3700                 :            :                                 &total_qprdc);
    3701                 :            : 
    3702                 :            :                 /* If this is a reset xstats is NULL, and we have cleared the
    3703                 :            :                  * registers by reading them.
    3704                 :            :                  */
    3705         [ #  # ]:          0 :                 if (!ids && !values)
    3706                 :            :                         return 0;
    3707                 :            : 
    3708                 :            :                 /* Extended stats from ixgbe_hw_stats */
    3709                 :            :                 count = 0;
    3710         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_HW_STATS; i++) {
    3711                 :          0 :                         values[count] = *(uint64_t *)(((char *)hw_stats) +
    3712                 :          0 :                                         rte_ixgbe_stats_strings[i].offset);
    3713                 :          0 :                         count++;
    3714                 :            :                 }
    3715                 :            : 
    3716                 :            :                 /* MACsec Stats */
    3717         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_NB_MACSEC_STATS; i++) {
    3718                 :          0 :                         values[count] = *(uint64_t *)(((char *)macsec_stats) +
    3719                 :          0 :                                         rte_ixgbe_macsec_strings[i].offset);
    3720                 :          0 :                         count++;
    3721                 :            :                 }
    3722                 :            : 
    3723                 :            :                 /* RX Priority Stats */
    3724         [ #  # ]:          0 :                 for (stat = 0; stat < IXGBE_NB_RXQ_PRIO_STATS; stat++) {
    3725         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_RXQ_PRIO_VALUES; i++) {
    3726                 :          0 :                                 values[count] =
    3727                 :          0 :                                         *(uint64_t *)(((char *)hw_stats) +
    3728                 :          0 :                                         rte_ixgbe_rxq_strings[stat].offset +
    3729                 :          0 :                                         (sizeof(uint64_t) * i));
    3730                 :          0 :                                 count++;
    3731                 :            :                         }
    3732                 :            :                 }
    3733                 :            : 
    3734                 :            :                 /* TX Priority Stats */
    3735         [ #  # ]:          0 :                 for (stat = 0; stat < IXGBE_NB_TXQ_PRIO_STATS; stat++) {
    3736         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_NB_TXQ_PRIO_VALUES; i++) {
    3737                 :          0 :                                 values[count] =
    3738                 :          0 :                                         *(uint64_t *)(((char *)hw_stats) +
    3739                 :          0 :                                         rte_ixgbe_txq_strings[stat].offset +
    3740                 :          0 :                                         (sizeof(uint64_t) * i));
    3741                 :          0 :                                 count++;
    3742                 :            :                         }
    3743                 :            :                 }
    3744                 :          0 :                 return count;
    3745                 :            :         }
    3746                 :            : 
    3747                 :            :         uint16_t i;
    3748                 :            :         uint64_t values_copy[IXGBE_XSTATS_CALC_NUM];
    3749                 :            :         const uint16_t size = RTE_DIM(values_copy);
    3750                 :            : 
    3751                 :          0 :         ixgbe_dev_xstats_get_by_id(dev, NULL, values_copy, size);
    3752                 :            : 
    3753         [ #  # ]:          0 :         for (i = 0; i < n; i++) {
    3754         [ #  # ]:          0 :                 if (ids[i] >= size) {
    3755                 :          0 :                         PMD_INIT_LOG(ERR, "id value isn't valid");
    3756                 :          0 :                         return -1;
    3757                 :            :                 }
    3758                 :          0 :                 values[i] = values_copy[ids[i]];
    3759                 :            :         }
    3760                 :          0 :         return n;
    3761                 :            : }
    3762                 :            : 
    3763                 :            : static int
    3764                 :          0 : ixgbe_dev_xstats_reset(struct rte_eth_dev *dev)
    3765                 :            : {
    3766                 :          0 :         struct ixgbe_hw_stats *stats =
    3767                 :          0 :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3768                 :          0 :         struct ixgbe_macsec_stats *macsec_stats =
    3769                 :            :                         IXGBE_DEV_PRIVATE_TO_MACSEC_STATS(
    3770                 :            :                                 dev->data->dev_private);
    3771                 :            : 
    3772                 :            :         unsigned count = ixgbe_xstats_calc_num();
    3773                 :            : 
    3774                 :            :         /* HW registers are cleared on read */
    3775                 :          0 :         ixgbe_dev_xstats_get(dev, NULL, count);
    3776                 :            : 
    3777                 :            :         /* Reset software totals */
    3778                 :            :         memset(stats, 0, sizeof(*stats));
    3779                 :            :         memset(macsec_stats, 0, sizeof(*macsec_stats));
    3780                 :            : 
    3781                 :          0 :         return 0;
    3782                 :            : }
    3783                 :            : 
    3784                 :            : static void
    3785                 :          0 : ixgbevf_update_stats(struct rte_eth_dev *dev)
    3786                 :            : {
    3787                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3788                 :            :         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
    3789                 :            :                           IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3790                 :            : 
    3791                 :            :         /* Good Rx packet, include VF loopback */
    3792                 :          0 :         UPDATE_VF_STAT(IXGBE_VFGPRC,
    3793                 :            :             hw_stats->last_vfgprc, hw_stats->vfgprc);
    3794                 :            : 
    3795                 :            :         /* Good Rx octets, include VF loopback */
    3796                 :          0 :         UPDATE_VF_STAT_36BIT(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB,
    3797                 :            :             hw_stats->last_vfgorc, hw_stats->vfgorc);
    3798                 :            : 
    3799                 :            :         /* Good Tx packet, include VF loopback */
    3800                 :          0 :         UPDATE_VF_STAT(IXGBE_VFGPTC,
    3801                 :            :             hw_stats->last_vfgptc, hw_stats->vfgptc);
    3802                 :            : 
    3803                 :            :         /* Good Tx octets, include VF loopback */
    3804                 :          0 :         UPDATE_VF_STAT_36BIT(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB,
    3805                 :            :             hw_stats->last_vfgotc, hw_stats->vfgotc);
    3806                 :            : 
    3807                 :            :         /* Rx Multicst Packet */
    3808                 :          0 :         UPDATE_VF_STAT(IXGBE_VFMPRC,
    3809                 :            :             hw_stats->last_vfmprc, hw_stats->vfmprc);
    3810                 :          0 : }
    3811                 :            : 
    3812                 :            : static int
    3813                 :          0 : ixgbevf_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
    3814                 :            :                        unsigned n)
    3815                 :            : {
    3816                 :            :         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
    3817                 :          0 :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3818                 :            :         unsigned i;
    3819                 :            : 
    3820         [ #  # ]:          0 :         if (n < IXGBEVF_NB_XSTATS)
    3821                 :            :                 return IXGBEVF_NB_XSTATS;
    3822                 :            : 
    3823                 :          0 :         ixgbevf_update_stats(dev);
    3824                 :            : 
    3825         [ #  # ]:          0 :         if (!xstats)
    3826                 :            :                 return 0;
    3827                 :            : 
    3828                 :            :         /* Extended stats */
    3829         [ #  # ]:          0 :         for (i = 0; i < IXGBEVF_NB_XSTATS; i++) {
    3830                 :          0 :                 xstats[i].id = i;
    3831                 :          0 :                 xstats[i].value = *(uint64_t *)(((char *)hw_stats) +
    3832                 :            :                         rte_ixgbevf_stats_strings[i].offset);
    3833                 :            :         }
    3834                 :            : 
    3835                 :            :         return IXGBEVF_NB_XSTATS;
    3836                 :            : }
    3837                 :            : 
    3838                 :            : static int
    3839                 :          0 : ixgbevf_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
    3840                 :            : {
    3841                 :            :         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
    3842                 :          0 :                           IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3843                 :            : 
    3844                 :          0 :         ixgbevf_update_stats(dev);
    3845                 :            : 
    3846         [ #  # ]:          0 :         if (stats == NULL)
    3847                 :            :                 return -EINVAL;
    3848                 :            : 
    3849                 :          0 :         stats->ipackets = hw_stats->vfgprc;
    3850                 :          0 :         stats->ibytes = hw_stats->vfgorc;
    3851                 :          0 :         stats->opackets = hw_stats->vfgptc;
    3852                 :          0 :         stats->obytes = hw_stats->vfgotc;
    3853                 :          0 :         return 0;
    3854                 :            : }
    3855                 :            : 
    3856                 :            : static int
    3857                 :          0 : ixgbevf_dev_stats_reset(struct rte_eth_dev *dev)
    3858                 :            : {
    3859                 :            :         struct ixgbevf_hw_stats *hw_stats = (struct ixgbevf_hw_stats *)
    3860                 :          0 :                         IXGBE_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    3861                 :            : 
    3862                 :            :         /* Sync HW register to the last stats */
    3863                 :            :         ixgbevf_dev_stats_get(dev, NULL);
    3864                 :            : 
    3865                 :            :         /* reset HW current stats*/
    3866                 :          0 :         hw_stats->vfgprc = 0;
    3867                 :          0 :         hw_stats->vfgorc = 0;
    3868                 :          0 :         hw_stats->vfgptc = 0;
    3869                 :          0 :         hw_stats->vfgotc = 0;
    3870                 :          0 :         hw_stats->vfmprc = 0;
    3871                 :            : 
    3872                 :          0 :         return 0;
    3873                 :            : }
    3874                 :            : 
    3875                 :            : static int
    3876                 :          0 : ixgbe_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
    3877                 :            : {
    3878                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3879                 :            :         struct ixgbe_nvm_version nvm_ver;
    3880                 :            :         int ret;
    3881                 :            : 
    3882                 :          0 :         ixgbe_get_oem_prod_version(hw, &nvm_ver);
    3883         [ #  # ]:          0 :         if (nvm_ver.oem_valid) {
    3884                 :          0 :                 snprintf(fw_version, fw_size, "%x.%x.%x",
    3885                 :          0 :                          nvm_ver.oem_major, nvm_ver.oem_minor,
    3886                 :          0 :                          nvm_ver.oem_release);
    3887                 :          0 :                 return 0;
    3888                 :            :         }
    3889                 :            : 
    3890                 :          0 :         ixgbe_get_etk_id(hw, &nvm_ver);
    3891                 :          0 :         ixgbe_get_orom_version(hw, &nvm_ver);
    3892                 :            : 
    3893         [ #  # ]:          0 :         if (nvm_ver.or_valid) {
    3894                 :          0 :                 snprintf(fw_version, fw_size, "0x%08x, %d.%d.%d",
    3895                 :          0 :                          nvm_ver.etk_id, nvm_ver.or_major,
    3896                 :          0 :                          nvm_ver.or_build, nvm_ver.or_patch);
    3897                 :          0 :                 return 0;
    3898                 :            :         }
    3899                 :            : 
    3900         [ #  # ]:          0 :         ret = snprintf(fw_version, fw_size, "0x%08x", nvm_ver.etk_id);
    3901         [ #  # ]:          0 :         if (ret < 0)
    3902                 :            :                 return -EINVAL;
    3903                 :            : 
    3904         [ #  # ]:          0 :         return (fw_size < (size_t)ret++) ? ret : 0;
    3905                 :            : }
    3906                 :            : 
    3907                 :            : static int
    3908                 :          0 : ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
    3909                 :            : {
    3910                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    3911                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    3912                 :            :         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
    3913                 :            : 
    3914                 :          0 :         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
    3915                 :          0 :         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
    3916         [ #  # ]:          0 :         if (RTE_ETH_DEV_SRIOV(dev).active == 0) {
    3917                 :            :                 /*
    3918                 :            :                  * When DCB/VT is off, maximum number of queues changes,
    3919                 :            :                  * except for 82598EB, which remains constant.
    3920                 :            :                  */
    3921         [ #  # ]:          0 :                 if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_NONE &&
    3922         [ #  # ]:          0 :                                 hw->mac.type != ixgbe_mac_82598EB)
    3923                 :          0 :                         dev_info->max_tx_queues = IXGBE_NONE_MODE_TX_NB_QUEUES;
    3924                 :            :         }
    3925                 :          0 :         dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL register */
    3926                 :          0 :         dev_info->max_rx_pktlen = 15872; /* includes CRC, cf MAXFRS register */
    3927                 :          0 :         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
    3928                 :          0 :         dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
    3929                 :          0 :         dev_info->max_vfs = pci_dev->max_vfs;
    3930         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
    3931                 :          0 :                 dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
    3932                 :            :         else
    3933                 :          0 :                 dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
    3934                 :          0 :         dev_info->max_mtu =  dev_info->max_rx_pktlen - IXGBE_ETH_OVERHEAD;
    3935                 :          0 :         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
    3936                 :          0 :         dev_info->vmdq_queue_num = dev_info->max_rx_queues;
    3937                 :          0 :         dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
    3938                 :          0 :         dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
    3939                 :          0 :                                      dev_info->rx_queue_offload_capa);
    3940                 :          0 :         dev_info->tx_queue_offload_capa = ixgbe_get_tx_queue_offloads(dev);
    3941                 :          0 :         dev_info->tx_offload_capa = ixgbe_get_tx_port_offloads(dev);
    3942                 :            : 
    3943                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
    3944                 :            :                 .rx_thresh = {
    3945                 :            :                         .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
    3946                 :            :                         .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
    3947                 :            :                         .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
    3948                 :            :                 },
    3949                 :            :                 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
    3950                 :            :                 .rx_drop_en = 0,
    3951                 :            :                 .offloads = 0,
    3952                 :            :         };
    3953                 :            : 
    3954                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
    3955                 :            :                 .tx_thresh = {
    3956                 :            :                         .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
    3957                 :            :                         .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
    3958                 :            :                         .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
    3959                 :            :                 },
    3960                 :            :                 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
    3961                 :            :                 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
    3962                 :            :                 .offloads = 0,
    3963                 :            :         };
    3964                 :            : 
    3965                 :          0 :         dev_info->rx_desc_lim = rx_desc_lim;
    3966                 :          0 :         dev_info->tx_desc_lim = tx_desc_lim;
    3967                 :            : 
    3968                 :          0 :         dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
    3969                 :          0 :         dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
    3970                 :          0 :         dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
    3971                 :            : 
    3972                 :          0 :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G;
    3973         [ #  # ]:          0 :         if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
    3974                 :            :                         hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
    3975                 :          0 :                 dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M |
    3976                 :            :                         RTE_ETH_LINK_SPEED_100M | RTE_ETH_LINK_SPEED_1G;
    3977                 :            : 
    3978                 :          0 :         if (hw->mac.type == ixgbe_mac_X540 ||
    3979                 :            :             hw->mac.type == ixgbe_mac_X540_vf ||
    3980         [ #  # ]:          0 :             hw->mac.type == ixgbe_mac_X550 ||
    3981                 :            :             hw->mac.type == ixgbe_mac_X550_vf) {
    3982                 :          0 :                 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100M;
    3983                 :            :         }
    3984         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_X550) {
    3985                 :          0 :                 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_2_5G;
    3986                 :          0 :                 dev_info->speed_capa |= RTE_ETH_LINK_SPEED_5G;
    3987                 :            :         }
    3988                 :            : 
    3989                 :            :         /* Driver-preferred Rx/Tx parameters */
    3990                 :          0 :         dev_info->default_rxportconf.burst_size = 32;
    3991                 :          0 :         dev_info->default_txportconf.burst_size = 32;
    3992                 :          0 :         dev_info->default_rxportconf.nb_queues = 1;
    3993                 :          0 :         dev_info->default_txportconf.nb_queues = 1;
    3994                 :          0 :         dev_info->default_rxportconf.ring_size = 256;
    3995                 :          0 :         dev_info->default_txportconf.ring_size = 256;
    3996                 :            : 
    3997                 :          0 :         return 0;
    3998                 :            : }
    3999                 :            : 
    4000                 :            : static const uint32_t *
    4001                 :          0 : ixgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
    4002                 :            : {
    4003                 :            :         static const uint32_t ptypes[] = {
    4004                 :            :                 /* For non-vec functions,
    4005                 :            :                  * refers to ixgbe_rxd_pkt_info_to_pkt_type();
    4006                 :            :                  * for vec functions,
    4007                 :            :                  * refers to _recv_raw_pkts_vec().
    4008                 :            :                  */
    4009                 :            :                 RTE_PTYPE_L2_ETHER,
    4010                 :            :                 RTE_PTYPE_L3_IPV4,
    4011                 :            :                 RTE_PTYPE_L3_IPV4_EXT,
    4012                 :            :                 RTE_PTYPE_L3_IPV6,
    4013                 :            :                 RTE_PTYPE_L3_IPV6_EXT,
    4014                 :            :                 RTE_PTYPE_L4_SCTP,
    4015                 :            :                 RTE_PTYPE_L4_TCP,
    4016                 :            :                 RTE_PTYPE_L4_UDP,
    4017                 :            :                 RTE_PTYPE_TUNNEL_IP,
    4018                 :            :                 RTE_PTYPE_INNER_L3_IPV6,
    4019                 :            :                 RTE_PTYPE_INNER_L3_IPV6_EXT,
    4020                 :            :                 RTE_PTYPE_INNER_L4_TCP,
    4021                 :            :                 RTE_PTYPE_INNER_L4_UDP,
    4022                 :            :         };
    4023                 :            : 
    4024   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == ixgbe_recv_pkts ||
    4025         [ #  # ]:          0 :             dev->rx_pkt_burst == ixgbe_recv_pkts_lro_single_alloc ||
    4026         [ #  # ]:          0 :             dev->rx_pkt_burst == ixgbe_recv_pkts_lro_bulk_alloc ||
    4027                 :            :             dev->rx_pkt_burst == ixgbe_recv_pkts_bulk_alloc) {
    4028                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
    4029                 :          0 :                 return ptypes;
    4030                 :            :         }
    4031                 :            : 
    4032                 :            : #if defined(RTE_ARCH_X86) || defined(__ARM_NEON)
    4033   [ #  #  #  # ]:          0 :         if (dev->rx_pkt_burst == ixgbe_recv_pkts_vec ||
    4034                 :            :             dev->rx_pkt_burst == ixgbe_recv_scattered_pkts_vec) {
    4035                 :          0 :                 *no_of_elements = RTE_DIM(ptypes);
    4036                 :          0 :                 return ptypes;
    4037                 :            :         }
    4038                 :            : #endif
    4039                 :            :         return NULL;
    4040                 :            : }
    4041                 :            : 
    4042                 :            : static int
    4043                 :          0 : ixgbevf_dev_info_get(struct rte_eth_dev *dev,
    4044                 :            :                      struct rte_eth_dev_info *dev_info)
    4045                 :            : {
    4046                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    4047                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4048                 :            : 
    4049                 :          0 :         dev_info->max_rx_queues = (uint16_t)hw->mac.max_rx_queues;
    4050                 :          0 :         dev_info->max_tx_queues = (uint16_t)hw->mac.max_tx_queues;
    4051                 :          0 :         dev_info->min_rx_bufsize = 1024; /* cf BSIZEPACKET in SRRCTL reg */
    4052                 :          0 :         dev_info->max_rx_pktlen = 9728; /* includes CRC, cf MAXFRS reg */
    4053                 :          0 :         dev_info->max_mtu = dev_info->max_rx_pktlen - IXGBE_ETH_OVERHEAD;
    4054                 :          0 :         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
    4055                 :          0 :         dev_info->max_hash_mac_addrs = IXGBE_VMDQ_NUM_UC_MAC;
    4056                 :          0 :         dev_info->max_vfs = pci_dev->max_vfs;
    4057         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
    4058                 :          0 :                 dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
    4059                 :            :         else
    4060                 :          0 :                 dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
    4061                 :          0 :         dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
    4062                 :          0 :         dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
    4063                 :          0 :                                      dev_info->rx_queue_offload_capa);
    4064                 :          0 :         dev_info->tx_queue_offload_capa = ixgbe_get_tx_queue_offloads(dev);
    4065                 :          0 :         dev_info->tx_offload_capa = ixgbe_get_tx_port_offloads(dev);
    4066                 :          0 :         dev_info->hash_key_size = IXGBE_HKEY_MAX_INDEX * sizeof(uint32_t);
    4067                 :          0 :         dev_info->reta_size = ixgbe_reta_size_get(hw->mac.type);
    4068                 :          0 :         dev_info->flow_type_rss_offloads = IXGBE_RSS_OFFLOAD_ALL;
    4069                 :            : 
    4070                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
    4071                 :            :                 .rx_thresh = {
    4072                 :            :                         .pthresh = IXGBE_DEFAULT_RX_PTHRESH,
    4073                 :            :                         .hthresh = IXGBE_DEFAULT_RX_HTHRESH,
    4074                 :            :                         .wthresh = IXGBE_DEFAULT_RX_WTHRESH,
    4075                 :            :                 },
    4076                 :            :                 .rx_free_thresh = IXGBE_DEFAULT_RX_FREE_THRESH,
    4077                 :            :                 .rx_drop_en = 0,
    4078                 :            :                 .offloads = 0,
    4079                 :            :         };
    4080                 :            : 
    4081                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
    4082                 :            :                 .tx_thresh = {
    4083                 :            :                         .pthresh = IXGBE_DEFAULT_TX_PTHRESH,
    4084                 :            :                         .hthresh = IXGBE_DEFAULT_TX_HTHRESH,
    4085                 :            :                         .wthresh = IXGBE_DEFAULT_TX_WTHRESH,
    4086                 :            :                 },
    4087                 :            :                 .tx_free_thresh = IXGBE_DEFAULT_TX_FREE_THRESH,
    4088                 :            :                 .tx_rs_thresh = IXGBE_DEFAULT_TX_RSBIT_THRESH,
    4089                 :            :                 .offloads = 0,
    4090                 :            :         };
    4091                 :            : 
    4092                 :          0 :         dev_info->rx_desc_lim = rx_desc_lim;
    4093                 :          0 :         dev_info->tx_desc_lim = tx_desc_lim;
    4094                 :            : 
    4095                 :          0 :         dev_info->err_handle_mode = RTE_ETH_ERROR_HANDLE_MODE_PASSIVE;
    4096                 :            : 
    4097                 :          0 :         return 0;
    4098                 :            : }
    4099                 :            : 
    4100                 :            : static int
    4101                 :          0 : ixgbevf_check_link(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
    4102                 :            :                    bool *link_up, int wait_to_complete)
    4103                 :            : {
    4104                 :            :         struct ixgbe_adapter *adapter = container_of(hw,
    4105                 :            :                                                      struct ixgbe_adapter, hw);
    4106                 :            :         struct ixgbe_mbx_info *mbx = &hw->mbx;
    4107                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
    4108                 :            :         uint32_t links_reg, in_msg;
    4109                 :            :         int ret_val = 0;
    4110                 :            : 
    4111                 :            :         /* If we were hit with a reset drop the link */
    4112   [ #  #  #  # ]:          0 :         if (!mbx->ops[0].check_for_rst(hw, 0) || !mbx->timeout)
    4113                 :          0 :                 mac->get_link_status = true;
    4114                 :            : 
    4115         [ #  # ]:          0 :         if (!mac->get_link_status)
    4116                 :          0 :                 goto out;
    4117                 :            : 
    4118                 :            :         /* if link status is down no point in checking to see if pf is up */
    4119                 :          0 :         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
    4120         [ #  # ]:          0 :         if (!(links_reg & IXGBE_LINKS_UP))
    4121                 :          0 :                 goto out;
    4122                 :            : 
    4123                 :            :         /* for SFP+ modules and DA cables on 82599 it can take up to 500usecs
    4124                 :            :          * before the link status is correct
    4125                 :            :          */
    4126   [ #  #  #  # ]:          0 :         if (mac->type == ixgbe_mac_82599_vf && wait_to_complete) {
    4127                 :            :                 int i;
    4128                 :            : 
    4129         [ #  # ]:          0 :                 for (i = 0; i < 5; i++) {
    4130                 :          0 :                         rte_delay_us(100);
    4131                 :          0 :                         links_reg = IXGBE_READ_REG(hw, IXGBE_VFLINKS);
    4132                 :            : 
    4133         [ #  # ]:          0 :                         if (!(links_reg & IXGBE_LINKS_UP))
    4134                 :          0 :                                 goto out;
    4135                 :            :                 }
    4136                 :            :         }
    4137                 :            : 
    4138   [ #  #  #  #  :          0 :         switch (links_reg & IXGBE_LINKS_SPEED_82599) {
                      # ]
    4139                 :          0 :         case IXGBE_LINKS_SPEED_10G_82599:
    4140                 :          0 :                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
    4141         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_X550) {
    4142         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
    4143                 :          0 :                                 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
    4144                 :            :                 }
    4145                 :            :                 break;
    4146                 :          0 :         case IXGBE_LINKS_SPEED_1G_82599:
    4147                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
    4148                 :          0 :                 break;
    4149                 :          0 :         case IXGBE_LINKS_SPEED_100_82599:
    4150                 :          0 :                 *speed = IXGBE_LINK_SPEED_100_FULL;
    4151         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_X550) {
    4152         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
    4153                 :          0 :                                 *speed = IXGBE_LINK_SPEED_5GB_FULL;
    4154                 :            :                 }
    4155                 :            :                 break;
    4156                 :          0 :         case IXGBE_LINKS_SPEED_10_X550EM_A:
    4157                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4158                 :            :                 /* Since Reserved in older MAC's */
    4159         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_X550)
    4160                 :          0 :                         *speed = IXGBE_LINK_SPEED_10_FULL;
    4161                 :            :                 break;
    4162                 :          0 :         default:
    4163                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4164                 :            :         }
    4165                 :            : 
    4166   [ #  #  #  # ]:          0 :         if (wait_to_complete == 0 && adapter->pflink_fullchk == 0) {
    4167         [ #  # ]:          0 :                 if (*speed == IXGBE_LINK_SPEED_UNKNOWN)
    4168                 :          0 :                         mac->get_link_status = true;
    4169                 :            :                 else
    4170                 :          0 :                         mac->get_link_status = false;
    4171                 :            : 
    4172                 :          0 :                 goto out;
    4173                 :            :         }
    4174                 :            : 
    4175                 :            :         /* if the read failed it could just be a mailbox collision, best wait
    4176                 :            :          * until we are called again and don't report an error
    4177                 :            :          */
    4178                 :            : 
    4179                 :            :         /*
    4180                 :            :          * on MinGW, the read op call is interpreted as call into read() macro,
    4181                 :            :          * so avoid calling it directly.
    4182                 :            :          */
    4183         [ #  # ]:          0 :         if ((mbx->ops[0].read)(hw, &in_msg, 1, 0))
    4184                 :          0 :                 goto out;
    4185                 :            : 
    4186         [ #  # ]:          0 :         if (!(in_msg & IXGBE_VT_MSGTYPE_CTS)) {
    4187                 :            :                 /* msg is not CTS and is FAILURE we must have lost CTS status */
    4188         [ #  # ]:          0 :                 if (in_msg & IXGBE_VT_MSGTYPE_FAILURE)
    4189                 :          0 :                         mac->get_link_status = false;
    4190                 :          0 :                 goto out;
    4191                 :            :         }
    4192                 :            : 
    4193                 :            :         /* the pf is talking, if we timed out in the past we reinit */
    4194         [ #  # ]:          0 :         if (!mbx->timeout) {
    4195                 :            :                 ret_val = -1;
    4196                 :          0 :                 goto out;
    4197                 :            :         }
    4198                 :            : 
    4199                 :            :         /* if we passed all the tests above then the link is up and we no
    4200                 :            :          * longer need to check for link
    4201                 :            :          */
    4202                 :          0 :         mac->get_link_status = false;
    4203                 :            : 
    4204                 :          0 : out:
    4205                 :          0 :         *link_up = !mac->get_link_status;
    4206                 :          0 :         return ret_val;
    4207                 :            : }
    4208                 :            : 
    4209                 :            : /*
    4210                 :            :  * If @timeout_ms was 0, it means that it will not return until link complete.
    4211                 :            :  * It returns 1 on complete, return 0 on timeout.
    4212                 :            :  */
    4213                 :            : static int
    4214                 :          0 : ixgbe_dev_wait_setup_link_complete(struct rte_eth_dev *dev, uint32_t timeout_ms)
    4215                 :            : {
    4216                 :            : #define WARNING_TIMEOUT    9000 /* 9s  in total */
    4217                 :          0 :         struct ixgbe_adapter *ad = dev->data->dev_private;
    4218         [ #  # ]:          0 :         uint32_t timeout = timeout_ms ? timeout_ms : WARNING_TIMEOUT;
    4219                 :            : 
    4220                 :            :         /* NOTE: review for potential ordering optimization */
    4221         [ #  # ]:          0 :         while (rte_atomic_load_explicit(&ad->link_thread_running, rte_memory_order_seq_cst)) {
    4222                 :          0 :                 msec_delay(1);
    4223                 :          0 :                 timeout--;
    4224                 :            : 
    4225         [ #  # ]:          0 :                 if (timeout_ms) {
    4226         [ #  # ]:          0 :                         if (!timeout)
    4227                 :            :                                 return 0;
    4228         [ #  # ]:          0 :                 } else if (!timeout) {
    4229                 :            :                         /* It will not return until link complete */
    4230                 :            :                         timeout = WARNING_TIMEOUT;
    4231                 :          0 :                         PMD_DRV_LOG(ERR, "IXGBE link thread not complete too long time!");
    4232                 :            :                 }
    4233                 :            :         }
    4234                 :            : 
    4235                 :            :         return 1;
    4236                 :            : }
    4237                 :            : 
    4238                 :            : static uint32_t
    4239                 :          0 : ixgbe_dev_setup_link_thread_handler(void *param)
    4240                 :            : {
    4241                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    4242                 :          0 :         struct ixgbe_adapter *ad = dev->data->dev_private;
    4243                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4244                 :            :         struct ixgbe_interrupt *intr =
    4245                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4246                 :            :         u32 speed;
    4247                 :          0 :         bool autoneg = false;
    4248                 :            : 
    4249                 :          0 :         rte_thread_detach(rte_thread_self());
    4250                 :          0 :         speed = hw->phy.autoneg_advertised;
    4251         [ #  # ]:          0 :         if (!speed)
    4252                 :          0 :                 ixgbe_get_link_capabilities(hw, &speed, &autoneg);
    4253                 :            : 
    4254                 :          0 :         ixgbe_setup_link(hw, speed, true);
    4255                 :            : 
    4256                 :          0 :         intr->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
    4257                 :            :         /* NOTE: review for potential ordering optimization */
    4258                 :          0 :         rte_atomic_store_explicit(&ad->link_thread_running, 0, rte_memory_order_seq_cst);
    4259                 :          0 :         return 0;
    4260                 :            : }
    4261                 :            : 
    4262                 :            : /*
    4263                 :            :  * In freebsd environment, nic_uio drivers do not support interrupts,
    4264                 :            :  * rte_intr_callback_register() will fail to register interrupts.
    4265                 :            :  * We can not make link status to change from down to up by interrupt
    4266                 :            :  * callback. So we need to wait for the controller to acquire link
    4267                 :            :  * when ports start.
    4268                 :            :  * It returns 0 on link up.
    4269                 :            :  */
    4270                 :            : static int
    4271                 :            : ixgbe_wait_for_link_up(struct ixgbe_hw *hw)
    4272                 :            : {
    4273                 :            : #ifdef RTE_EXEC_ENV_FREEBSD
    4274                 :            :         int err, i;
    4275                 :            :         bool link_up = false;
    4276                 :            :         uint32_t speed = 0;
    4277                 :            :         const int nb_iter = 25;
    4278                 :            : 
    4279                 :            :         for (i = 0; i < nb_iter; i++) {
    4280                 :            :                 err = ixgbe_check_link(hw, &speed, &link_up, 0);
    4281                 :            :                 if (err)
    4282                 :            :                         return err;
    4283                 :            :                 if (link_up)
    4284                 :            :                         return 0;
    4285                 :            :                 msec_delay(200);
    4286                 :            :         }
    4287                 :            : 
    4288                 :            :         return 0;
    4289                 :            : #else
    4290                 :            :         RTE_SET_USED(hw);
    4291                 :            :         return 0;
    4292                 :            : #endif
    4293                 :            : }
    4294                 :            : 
    4295                 :            : /* return 0 means link status changed, -1 means not changed */
    4296                 :            : int
    4297                 :          0 : ixgbe_dev_link_update_share(struct rte_eth_dev *dev,
    4298                 :            :                             int wait_to_complete, int vf)
    4299                 :            : {
    4300                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4301                 :            :         struct ixgbe_adapter *ad = dev->data->dev_private;
    4302                 :            :         struct rte_eth_link link;
    4303                 :          0 :         ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
    4304                 :            :         struct ixgbe_interrupt *intr =
    4305                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4306                 :            :         bool link_up;
    4307                 :            :         int diag;
    4308                 :            :         int wait = 1;
    4309                 :            :         u32 esdp_reg;
    4310                 :            : 
    4311         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    4312                 :            :                 return -1;
    4313                 :            : 
    4314                 :            :         memset(&link, 0, sizeof(link));
    4315                 :            :         link.link_status = RTE_ETH_LINK_DOWN;
    4316                 :            :         link.link_speed = RTE_ETH_SPEED_NUM_NONE;
    4317                 :            :         link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
    4318                 :          0 :         link.link_autoneg = !(dev->data->dev_conf.link_speeds &
    4319                 :            :                         RTE_ETH_LINK_SPEED_FIXED);
    4320                 :            : 
    4321                 :          0 :         hw->mac.get_link_status = true;
    4322                 :            : 
    4323         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_NEED_LINK_CONFIG)
    4324                 :          0 :                 return rte_eth_linkstatus_set(dev, &link);
    4325                 :            : 
    4326                 :            :         /* check if it needs to wait to complete, if lsc interrupt is enabled */
    4327   [ #  #  #  # ]:          0 :         if (wait_to_complete == 0 || dev->data->dev_conf.intr_conf.lsc != 0)
    4328                 :            :                 wait = 0;
    4329                 :            : 
    4330         [ #  # ]:          0 :         if (vf)
    4331                 :          0 :                 diag = ixgbevf_check_link(hw, &link_speed, &link_up, wait);
    4332                 :            :         else
    4333                 :          0 :                 diag = ixgbe_check_link(hw, &link_speed, &link_up, wait);
    4334                 :            : 
    4335         [ #  # ]:          0 :         if (diag != 0) {
    4336                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_100M;
    4337         [ #  # ]:          0 :                 link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    4338                 :          0 :                 return rte_eth_linkstatus_set(dev, &link);
    4339                 :            :         }
    4340                 :            : 
    4341         [ #  # ]:          0 :         if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber &&
    4342         [ #  # ]:          0 :             !ad->sdp3_no_tx_disable) {
    4343                 :          0 :                 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
    4344         [ #  # ]:          0 :                 if ((esdp_reg & IXGBE_ESDP_SDP3))
    4345                 :          0 :                         link_up = 0;
    4346                 :            :         }
    4347                 :            : 
    4348         [ #  # ]:          0 :         if (link_up == 0) {
    4349         [ #  # ]:          0 :                 if (ixgbe_get_media_type(hw) == ixgbe_media_type_fiber) {
    4350                 :          0 :                         ixgbe_dev_wait_setup_link_complete(dev, 0);
    4351                 :            :                         /* NOTE: review for potential ordering optimization */
    4352         [ #  # ]:          0 :                         if (!rte_atomic_exchange_explicit(&ad->link_thread_running, 1,
    4353                 :            :                                         rte_memory_order_seq_cst)) {
    4354                 :            :                                 /* To avoid race condition between threads, set
    4355                 :            :                                  * the IXGBE_FLAG_NEED_LINK_CONFIG flag only
    4356                 :            :                                  * when there is no link thread running.
    4357                 :            :                                  */
    4358                 :          0 :                                 intr->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
    4359         [ #  # ]:          0 :                                 if (rte_thread_create_internal_control(&ad->link_thread_tid,
    4360                 :            :                                                 "ixgbe-link",
    4361                 :            :                                                 ixgbe_dev_setup_link_thread_handler, dev) < 0) {
    4362                 :          0 :                                         PMD_DRV_LOG(ERR,
    4363                 :            :                                                 "Create link thread failed!");
    4364                 :            :                                         /* NOTE: review for potential ordering optimization */
    4365                 :          0 :                                         rte_atomic_store_explicit(&ad->link_thread_running, 0,
    4366                 :            :                                                         rte_memory_order_seq_cst);
    4367                 :            :                                 }
    4368                 :            :                         } else {
    4369                 :          0 :                                 PMD_DRV_LOG(ERR,
    4370                 :            :                                         "Other link thread is running now!");
    4371                 :            :                         }
    4372                 :            :                 }
    4373                 :          0 :                 return rte_eth_linkstatus_set(dev, &link);
    4374                 :            :         }
    4375                 :            : 
    4376                 :          0 :         link.link_status = RTE_ETH_LINK_UP;
    4377                 :          0 :         link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
    4378                 :            : 
    4379   [ #  #  #  #  :          0 :         switch (link_speed) {
                #  #  # ]
    4380                 :          0 :         default:
    4381                 :            :         case IXGBE_LINK_SPEED_UNKNOWN:
    4382                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
    4383                 :          0 :                 break;
    4384                 :            : 
    4385                 :          0 :         case IXGBE_LINK_SPEED_10_FULL:
    4386                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_10M;
    4387                 :          0 :                 break;
    4388                 :            : 
    4389                 :          0 :         case IXGBE_LINK_SPEED_100_FULL:
    4390                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_100M;
    4391                 :          0 :                 break;
    4392                 :            : 
    4393                 :          0 :         case IXGBE_LINK_SPEED_1GB_FULL:
    4394                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_1G;
    4395                 :          0 :                 break;
    4396                 :            : 
    4397                 :          0 :         case IXGBE_LINK_SPEED_2_5GB_FULL:
    4398                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_2_5G;
    4399                 :          0 :                 break;
    4400                 :            : 
    4401                 :          0 :         case IXGBE_LINK_SPEED_5GB_FULL:
    4402                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_5G;
    4403                 :          0 :                 break;
    4404                 :            : 
    4405                 :          0 :         case IXGBE_LINK_SPEED_10GB_FULL:
    4406                 :          0 :                 link.link_speed = RTE_ETH_SPEED_NUM_10G;
    4407                 :          0 :                 break;
    4408                 :            :         }
    4409                 :            : 
    4410                 :            :         return rte_eth_linkstatus_set(dev, &link);
    4411                 :            : }
    4412                 :            : 
    4413                 :            : static int
    4414                 :          0 : ixgbe_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
    4415                 :            : {
    4416                 :          0 :         return ixgbe_dev_link_update_share(dev, wait_to_complete, 0);
    4417                 :            : }
    4418                 :            : 
    4419                 :            : static int
    4420                 :          0 : ixgbevf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
    4421                 :            : {
    4422                 :          0 :         return ixgbe_dev_link_update_share(dev, wait_to_complete, 1);
    4423                 :            : }
    4424                 :            : 
    4425                 :            : static int
    4426                 :          0 : ixgbe_dev_promiscuous_enable(struct rte_eth_dev *dev)
    4427                 :            : {
    4428                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4429                 :            :         uint32_t fctrl;
    4430                 :            : 
    4431                 :          0 :         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    4432                 :          0 :         fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
    4433                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    4434                 :            : 
    4435                 :          0 :         return 0;
    4436                 :            : }
    4437                 :            : 
    4438                 :            : static int
    4439                 :          0 : ixgbe_dev_promiscuous_disable(struct rte_eth_dev *dev)
    4440                 :            : {
    4441                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4442                 :            :         uint32_t fctrl;
    4443                 :            : 
    4444                 :          0 :         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    4445                 :          0 :         fctrl &= (~IXGBE_FCTRL_UPE);
    4446         [ #  # ]:          0 :         if (dev->data->all_multicast == 1)
    4447                 :          0 :                 fctrl |= IXGBE_FCTRL_MPE;
    4448                 :            :         else
    4449                 :          0 :                 fctrl &= (~IXGBE_FCTRL_MPE);
    4450                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    4451                 :            : 
    4452                 :          0 :         return 0;
    4453                 :            : }
    4454                 :            : 
    4455                 :            : static int
    4456                 :          0 : ixgbe_dev_allmulticast_enable(struct rte_eth_dev *dev)
    4457                 :            : {
    4458                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4459                 :            :         uint32_t fctrl;
    4460                 :            : 
    4461                 :          0 :         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    4462                 :          0 :         fctrl |= IXGBE_FCTRL_MPE;
    4463                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    4464                 :            : 
    4465                 :          0 :         return 0;
    4466                 :            : }
    4467                 :            : 
    4468                 :            : static int
    4469                 :          0 : ixgbe_dev_allmulticast_disable(struct rte_eth_dev *dev)
    4470                 :            : {
    4471                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4472                 :            :         uint32_t fctrl;
    4473                 :            : 
    4474         [ #  # ]:          0 :         if (dev->data->promiscuous == 1)
    4475                 :            :                 return 0; /* must remain in all_multicast mode */
    4476                 :            : 
    4477                 :          0 :         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    4478                 :          0 :         fctrl &= (~IXGBE_FCTRL_MPE);
    4479                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    4480                 :            : 
    4481                 :          0 :         return 0;
    4482                 :            : }
    4483                 :            : 
    4484                 :            : /**
    4485                 :            :  * It clears the interrupt causes and enables the interrupt.
    4486                 :            :  * It will be called once only during nic initialized.
    4487                 :            :  *
    4488                 :            :  * @param dev
    4489                 :            :  *  Pointer to struct rte_eth_dev.
    4490                 :            :  * @param on
    4491                 :            :  *  Enable or Disable.
    4492                 :            :  *
    4493                 :            :  * @return
    4494                 :            :  *  - On success, zero.
    4495                 :            :  *  - On failure, a negative value.
    4496                 :            :  */
    4497                 :            : static int
    4498                 :            : ixgbe_dev_lsc_interrupt_setup(struct rte_eth_dev *dev, uint8_t on)
    4499                 :            : {
    4500                 :            :         struct ixgbe_interrupt *intr =
    4501                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4502                 :            : 
    4503                 :          0 :         ixgbe_dev_link_status_print(dev);
    4504                 :            :         if (on)
    4505                 :          0 :                 intr->mask |= IXGBE_EICR_LSC;
    4506                 :            :         else
    4507                 :          0 :                 intr->mask &= ~IXGBE_EICR_LSC;
    4508                 :            : 
    4509                 :            :         return 0;
    4510                 :            : }
    4511                 :            : 
    4512                 :            : /**
    4513                 :            :  * It clears the interrupt causes and enables the interrupt.
    4514                 :            :  * It will be called once only during nic initialized.
    4515                 :            :  *
    4516                 :            :  * @param dev
    4517                 :            :  *  Pointer to struct rte_eth_dev.
    4518                 :            :  *
    4519                 :            :  * @return
    4520                 :            :  *  - On success, zero.
    4521                 :            :  *  - On failure, a negative value.
    4522                 :            :  */
    4523                 :            : static int
    4524                 :            : ixgbe_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
    4525                 :            : {
    4526                 :            :         struct ixgbe_interrupt *intr =
    4527                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4528                 :            : 
    4529                 :          0 :         intr->mask |= IXGBE_EICR_RTX_QUEUE;
    4530                 :            : 
    4531                 :          0 :         return 0;
    4532                 :            : }
    4533                 :            : 
    4534                 :            : /**
    4535                 :            :  * It clears the interrupt causes and enables the interrupt.
    4536                 :            :  * It will be called once only during nic initialized.
    4537                 :            :  *
    4538                 :            :  * @param dev
    4539                 :            :  *  Pointer to struct rte_eth_dev.
    4540                 :            :  *
    4541                 :            :  * @return
    4542                 :            :  *  - On success, zero.
    4543                 :            :  *  - On failure, a negative value.
    4544                 :            :  */
    4545                 :            : static int
    4546                 :            : ixgbe_dev_macsec_interrupt_setup(struct rte_eth_dev *dev)
    4547                 :            : {
    4548                 :            :         struct ixgbe_interrupt *intr =
    4549                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4550                 :            : 
    4551                 :          0 :         intr->mask |= IXGBE_EICR_LINKSEC;
    4552                 :            : 
    4553                 :          0 :         return 0;
    4554                 :            : }
    4555                 :            : 
    4556                 :            : /*
    4557                 :            :  * It reads ICR and sets flag (IXGBE_EICR_LSC) for the link_update.
    4558                 :            :  *
    4559                 :            :  * @param dev
    4560                 :            :  *  Pointer to struct rte_eth_dev.
    4561                 :            :  *
    4562                 :            :  * @return
    4563                 :            :  *  - On success, zero.
    4564                 :            :  *  - On failure, a negative value.
    4565                 :            :  */
    4566                 :            : static int
    4567                 :          0 : ixgbe_dev_interrupt_get_status(struct rte_eth_dev *dev)
    4568                 :            : {
    4569                 :            :         uint32_t eicr;
    4570                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4571                 :            :         struct ixgbe_interrupt *intr =
    4572                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4573                 :            : 
    4574                 :            :         /* clear all cause mask */
    4575                 :          0 :         ixgbe_disable_intr(hw);
    4576                 :            : 
    4577                 :            :         /* read-on-clear nic registers here */
    4578                 :          0 :         eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
    4579                 :          0 :         PMD_DRV_LOG(DEBUG, "eicr %x", eicr);
    4580                 :            : 
    4581                 :          0 :         intr->flags = 0;
    4582                 :            : 
    4583                 :            :         /* set flag for async link update */
    4584         [ #  # ]:          0 :         if (eicr & IXGBE_EICR_LSC)
    4585                 :          0 :                 intr->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
    4586                 :            : 
    4587         [ #  # ]:          0 :         if (eicr & IXGBE_EICR_MAILBOX)
    4588                 :          0 :                 intr->flags |= IXGBE_FLAG_MAILBOX;
    4589                 :            : 
    4590         [ #  # ]:          0 :         if (eicr & IXGBE_EICR_LINKSEC)
    4591                 :          0 :                 intr->flags |= IXGBE_FLAG_MACSEC;
    4592                 :            : 
    4593         [ #  # ]:          0 :         if (hw->mac.type ==  ixgbe_mac_X550EM_x &&
    4594         [ #  # ]:          0 :             hw->phy.type == ixgbe_phy_x550em_ext_t &&
    4595         [ #  # ]:          0 :             (eicr & IXGBE_EICR_GPI_SDP0_X550EM_x))
    4596                 :          0 :                 intr->flags |= IXGBE_FLAG_PHY_INTERRUPT;
    4597                 :            : 
    4598                 :          0 :         return 0;
    4599                 :            : }
    4600                 :            : 
    4601                 :            : /**
    4602                 :            :  * It gets and then prints the link status.
    4603                 :            :  *
    4604                 :            :  * @param dev
    4605                 :            :  *  Pointer to struct rte_eth_dev.
    4606                 :            :  *
    4607                 :            :  * @return
    4608                 :            :  *  - On success, zero.
    4609                 :            :  *  - On failure, a negative value.
    4610                 :            :  */
    4611                 :            : static void
    4612                 :          0 : ixgbe_dev_link_status_print(struct rte_eth_dev *dev)
    4613                 :            : {
    4614                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    4615                 :            :         struct rte_eth_link link;
    4616                 :            : 
    4617                 :          0 :         rte_eth_linkstatus_get(dev, &link);
    4618                 :            : 
    4619         [ #  # ]:          0 :         if (link.link_status) {
    4620         [ #  # ]:          0 :                 PMD_INIT_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
    4621                 :            :                                         (int)(dev->data->port_id),
    4622                 :            :                                         (unsigned)link.link_speed,
    4623                 :            :                         link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
    4624                 :            :                                         "full-duplex" : "half-duplex");
    4625                 :            :         } else {
    4626                 :          0 :                 PMD_INIT_LOG(INFO, " Port %d: Link Down",
    4627                 :            :                                 (int)(dev->data->port_id));
    4628                 :            :         }
    4629                 :          0 :         PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
    4630                 :            :                                 pci_dev->addr.domain,
    4631                 :            :                                 pci_dev->addr.bus,
    4632                 :            :                                 pci_dev->addr.devid,
    4633                 :            :                                 pci_dev->addr.function);
    4634                 :          0 : }
    4635                 :            : 
    4636                 :            : /*
    4637                 :            :  * It executes link_update after knowing an interrupt occurred.
    4638                 :            :  *
    4639                 :            :  * @param dev
    4640                 :            :  *  Pointer to struct rte_eth_dev.
    4641                 :            :  *
    4642                 :            :  * @return
    4643                 :            :  *  - On success, zero.
    4644                 :            :  *  - On failure, a negative value.
    4645                 :            :  */
    4646                 :            : static int
    4647                 :          0 : ixgbe_dev_interrupt_action(struct rte_eth_dev *dev)
    4648                 :            : {
    4649                 :            :         struct ixgbe_interrupt *intr =
    4650                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4651                 :            :         int64_t timeout;
    4652                 :          0 :         struct ixgbe_hw *hw =
    4653                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4654                 :            : 
    4655                 :          0 :         PMD_DRV_LOG(DEBUG, "intr action type %d", intr->flags);
    4656                 :            : 
    4657         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_MAILBOX) {
    4658                 :          0 :                 ixgbe_pf_mbx_process(dev);
    4659                 :          0 :                 intr->flags &= ~IXGBE_FLAG_MAILBOX;
    4660                 :            :         }
    4661                 :            : 
    4662         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
    4663                 :          0 :                 ixgbe_handle_lasi(hw);
    4664                 :          0 :                 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
    4665                 :            :         }
    4666                 :            : 
    4667         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
    4668                 :            :                 struct rte_eth_link link;
    4669                 :            : 
    4670                 :            :                 /* get the link status before link update, for predicting later */
    4671                 :          0 :                 rte_eth_linkstatus_get(dev, &link);
    4672                 :            : 
    4673                 :            :                 ixgbe_dev_link_update(dev, 0);
    4674                 :            : 
    4675                 :            :                 /* likely to up */
    4676         [ #  # ]:          0 :                 if (!link.link_status)
    4677                 :            :                         /* handle it 1 sec later, wait it being stable */
    4678                 :            :                         timeout = IXGBE_LINK_UP_CHECK_TIMEOUT;
    4679                 :            :                 /* likely to down */
    4680                 :            :                 else
    4681                 :            :                         /* handle it 4 sec later, wait it being stable */
    4682                 :            :                         timeout = IXGBE_LINK_DOWN_CHECK_TIMEOUT;
    4683                 :            : 
    4684                 :          0 :                 ixgbe_dev_link_status_print(dev);
    4685                 :            : 
    4686                 :            :                 /* Don't program delayed handler if LSC interrupt is disabled.
    4687                 :            :                  * It means one is already programmed.
    4688                 :            :                  */
    4689         [ #  # ]:          0 :                 if (intr->mask & IXGBE_EIMS_LSC) {
    4690         [ #  # ]:          0 :                         if (rte_eal_alarm_set(timeout * 1000,
    4691                 :            :                                               ixgbe_dev_interrupt_delayed_handler, (void *)dev) < 0)
    4692                 :          0 :                                 PMD_DRV_LOG(ERR, "Error setting alarm");
    4693                 :            :                         else {
    4694                 :            :                                 /* remember original mask */
    4695                 :          0 :                                 intr->mask_original = intr->mask;
    4696                 :            :                                 /* only disable lsc interrupt */
    4697                 :          0 :                                 intr->mask &= ~IXGBE_EIMS_LSC;
    4698                 :            :                         }
    4699                 :            :                 }
    4700                 :            :         }
    4701                 :            : 
    4702                 :          0 :         PMD_DRV_LOG(DEBUG, "enable intr immediately");
    4703                 :            :         ixgbe_enable_intr(dev);
    4704                 :            : 
    4705                 :          0 :         return 0;
    4706                 :            : }
    4707                 :            : 
    4708                 :            : /**
    4709                 :            :  * Interrupt handler which shall be registered for alarm callback for delayed
    4710                 :            :  * handling specific interrupt to wait for the stable nic state. As the
    4711                 :            :  * NIC interrupt state is not stable for ixgbe after link is just down,
    4712                 :            :  * it needs to wait 4 seconds to get the stable status.
    4713                 :            :  *
    4714                 :            :  * @param handle
    4715                 :            :  *  Pointer to interrupt handle.
    4716                 :            :  * @param param
    4717                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    4718                 :            :  *
    4719                 :            :  * @return
    4720                 :            :  *  void
    4721                 :            :  */
    4722                 :            : static void
    4723                 :          0 : ixgbe_dev_interrupt_delayed_handler(void *param)
    4724                 :            : {
    4725                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    4726                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    4727                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    4728                 :            :         struct ixgbe_interrupt *intr =
    4729                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    4730                 :          0 :         struct ixgbe_hw *hw =
    4731                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4732                 :            :         uint32_t eicr;
    4733                 :            : 
    4734                 :          0 :         ixgbe_disable_intr(hw);
    4735                 :            : 
    4736                 :          0 :         eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
    4737         [ #  # ]:          0 :         if (eicr & IXGBE_EICR_MAILBOX)
    4738                 :          0 :                 ixgbe_pf_mbx_process(dev);
    4739                 :            : 
    4740         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_PHY_INTERRUPT) {
    4741                 :          0 :                 ixgbe_handle_lasi(hw);
    4742                 :          0 :                 intr->flags &= ~IXGBE_FLAG_PHY_INTERRUPT;
    4743                 :            :         }
    4744                 :            : 
    4745         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
    4746                 :            :                 ixgbe_dev_link_update(dev, 0);
    4747                 :          0 :                 intr->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
    4748                 :          0 :                 ixgbe_dev_link_status_print(dev);
    4749                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    4750                 :            :         }
    4751                 :            : 
    4752         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_MACSEC) {
    4753                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_MACSEC, NULL);
    4754                 :          0 :                 intr->flags &= ~IXGBE_FLAG_MACSEC;
    4755                 :            :         }
    4756                 :            : 
    4757                 :            :         /* restore original mask */
    4758                 :          0 :         intr->mask = intr->mask_original;
    4759                 :          0 :         intr->mask_original = 0;
    4760                 :            : 
    4761                 :          0 :         PMD_DRV_LOG(DEBUG, "enable intr in delayed handler S[%08x]", eicr);
    4762                 :            :         ixgbe_enable_intr(dev);
    4763                 :          0 :         rte_intr_ack(intr_handle);
    4764                 :          0 : }
    4765                 :            : 
    4766                 :            : /**
    4767                 :            :  * Interrupt handler triggered by NIC  for handling
    4768                 :            :  * specific interrupt.
    4769                 :            :  *
    4770                 :            :  * @param handle
    4771                 :            :  *  Pointer to interrupt handle.
    4772                 :            :  * @param param
    4773                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    4774                 :            :  *
    4775                 :            :  * @return
    4776                 :            :  *  void
    4777                 :            :  */
    4778                 :            : static void
    4779                 :          0 : ixgbe_dev_interrupt_handler(void *param)
    4780                 :            : {
    4781                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    4782                 :            : 
    4783                 :          0 :         ixgbe_dev_interrupt_get_status(dev);
    4784                 :          0 :         ixgbe_dev_interrupt_action(dev);
    4785                 :          0 : }
    4786                 :            : 
    4787                 :            : static int
    4788                 :          0 : ixgbe_dev_led_on(struct rte_eth_dev *dev)
    4789                 :            : {
    4790                 :            :         struct ixgbe_hw *hw;
    4791                 :            : 
    4792                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4793         [ #  # ]:          0 :         return ixgbe_led_on(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
    4794                 :            : }
    4795                 :            : 
    4796                 :            : static int
    4797                 :          0 : ixgbe_dev_led_off(struct rte_eth_dev *dev)
    4798                 :            : {
    4799                 :            :         struct ixgbe_hw *hw;
    4800                 :            : 
    4801                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4802         [ #  # ]:          0 :         return ixgbe_led_off(hw, 0) == IXGBE_SUCCESS ? 0 : -ENOTSUP;
    4803                 :            : }
    4804                 :            : 
    4805                 :            : static int
    4806                 :          0 : ixgbe_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    4807                 :            : {
    4808                 :            :         struct ixgbe_hw *hw;
    4809                 :            :         uint32_t mflcn_reg;
    4810                 :            :         uint32_t fccfg_reg;
    4811                 :            :         int rx_pause;
    4812                 :            :         int tx_pause;
    4813                 :            : 
    4814                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4815                 :            : 
    4816                 :          0 :         fc_conf->pause_time = hw->fc.pause_time;
    4817                 :          0 :         fc_conf->high_water = hw->fc.high_water[0];
    4818                 :          0 :         fc_conf->low_water = hw->fc.low_water[0];
    4819                 :          0 :         fc_conf->send_xon = hw->fc.send_xon;
    4820                 :          0 :         fc_conf->autoneg = !hw->fc.disable_fc_autoneg;
    4821                 :            : 
    4822                 :            :         /*
    4823                 :            :          * Return rx_pause status according to actual setting of
    4824                 :            :          * MFLCN register.
    4825                 :            :          */
    4826                 :          0 :         mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
    4827         [ #  # ]:          0 :         if (mflcn_reg & IXGBE_MFLCN_PMCF)
    4828                 :          0 :                 fc_conf->mac_ctrl_frame_fwd = 1;
    4829                 :            :         else
    4830                 :          0 :                 fc_conf->mac_ctrl_frame_fwd = 0;
    4831                 :            : 
    4832         [ #  # ]:          0 :         if (mflcn_reg & (IXGBE_MFLCN_RPFCE | IXGBE_MFLCN_RFCE))
    4833                 :            :                 rx_pause = 1;
    4834                 :            :         else
    4835                 :            :                 rx_pause = 0;
    4836                 :            : 
    4837                 :            :         /*
    4838                 :            :          * Return tx_pause status according to actual setting of
    4839                 :            :          * FCCFG register.
    4840                 :            :          */
    4841                 :          0 :         fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
    4842         [ #  # ]:          0 :         if (fccfg_reg & (IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY))
    4843                 :            :                 tx_pause = 1;
    4844                 :            :         else
    4845                 :            :                 tx_pause = 0;
    4846                 :            : 
    4847         [ #  # ]:          0 :         if (rx_pause && tx_pause)
    4848                 :          0 :                 fc_conf->mode = RTE_ETH_FC_FULL;
    4849         [ #  # ]:          0 :         else if (rx_pause)
    4850                 :          0 :                 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
    4851         [ #  # ]:          0 :         else if (tx_pause)
    4852                 :          0 :                 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    4853                 :            :         else
    4854                 :          0 :                 fc_conf->mode = RTE_ETH_FC_NONE;
    4855                 :            : 
    4856                 :          0 :         return 0;
    4857                 :            : }
    4858                 :            : 
    4859                 :            : static int
    4860                 :          0 : ixgbe_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    4861                 :            : {
    4862                 :            :         struct ixgbe_hw *hw;
    4863                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    4864                 :            :         int err;
    4865                 :            :         uint32_t rx_buf_size;
    4866                 :            :         uint32_t max_high_water;
    4867                 :          0 :         enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
    4868                 :            :                 ixgbe_fc_none,
    4869                 :            :                 ixgbe_fc_rx_pause,
    4870                 :            :                 ixgbe_fc_tx_pause,
    4871                 :            :                 ixgbe_fc_full
    4872                 :            :         };
    4873                 :            : 
    4874                 :          0 :         PMD_INIT_FUNC_TRACE();
    4875                 :            : 
    4876                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    4877                 :          0 :         rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(0));
    4878                 :          0 :         PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
    4879                 :            : 
    4880                 :            :         /*
    4881                 :            :          * At least reserve one Ethernet frame for watermark
    4882                 :            :          * high_water/low_water in kilo bytes for ixgbe
    4883                 :            :          */
    4884                 :          0 :         max_high_water = (rx_buf_size -
    4885                 :            :                         RTE_ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
    4886         [ #  # ]:          0 :         if ((fc_conf->high_water > max_high_water) ||
    4887         [ #  # ]:          0 :                 (fc_conf->high_water < fc_conf->low_water)) {
    4888                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
    4889                 :          0 :                 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
    4890                 :          0 :                 return -EINVAL;
    4891                 :            :         }
    4892                 :            : 
    4893                 :          0 :         hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[fc_conf->mode];
    4894                 :          0 :         hw->fc.pause_time     = fc_conf->pause_time;
    4895                 :          0 :         hw->fc.high_water[0]  = fc_conf->high_water;
    4896                 :          0 :         hw->fc.low_water[0]   = fc_conf->low_water;
    4897                 :          0 :         hw->fc.send_xon       = fc_conf->send_xon;
    4898                 :          0 :         hw->fc.disable_fc_autoneg = !fc_conf->autoneg;
    4899                 :          0 :         adapter->mac_ctrl_frame_fwd = fc_conf->mac_ctrl_frame_fwd;
    4900                 :            : 
    4901                 :          0 :         err = ixgbe_flow_ctrl_enable(dev, hw);
    4902         [ #  # ]:          0 :         if (err < 0) {
    4903                 :          0 :                 PMD_INIT_LOG(ERR, "ixgbe_flow_ctrl_enable = 0x%x", err);
    4904                 :          0 :                 return -EIO;
    4905                 :            :         }
    4906                 :            :         return err;
    4907                 :            : }
    4908                 :            : 
    4909                 :            : /**
    4910                 :            :  *  ixgbe_pfc_enable_generic - Enable flow control
    4911                 :            :  *  @hw: pointer to hardware structure
    4912                 :            :  *  @tc_num: traffic class number
    4913                 :            :  *  Enable flow control according to the current settings.
    4914                 :            :  */
    4915                 :            : static int
    4916                 :          0 : ixgbe_dcb_pfc_enable_generic(struct ixgbe_hw *hw, uint8_t tc_num)
    4917                 :            : {
    4918                 :            :         int ret_val = 0;
    4919                 :            :         uint32_t mflcn_reg, fccfg_reg;
    4920                 :            :         uint32_t reg;
    4921                 :            :         uint32_t fcrtl, fcrth;
    4922                 :            :         uint8_t i;
    4923                 :            :         uint8_t nb_rx_en;
    4924                 :            : 
    4925                 :            :         /* Validate the water mark configuration */
    4926         [ #  # ]:          0 :         if (!hw->fc.pause_time) {
    4927                 :            :                 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
    4928                 :          0 :                 goto out;
    4929                 :            :         }
    4930                 :            : 
    4931                 :            :         /* Low water mark of zero causes XOFF floods */
    4932         [ #  # ]:          0 :         if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
    4933                 :            :                  /* High/Low water can not be 0 */
    4934   [ #  #  #  # ]:          0 :                 if ((!hw->fc.high_water[tc_num]) || (!hw->fc.low_water[tc_num])) {
    4935                 :          0 :                         PMD_INIT_LOG(ERR, "Invalid water mark configuration");
    4936                 :            :                         ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
    4937                 :          0 :                         goto out;
    4938                 :            :                 }
    4939                 :            : 
    4940         [ #  # ]:          0 :                 if (hw->fc.low_water[tc_num] >= hw->fc.high_water[tc_num]) {
    4941                 :          0 :                         PMD_INIT_LOG(ERR, "Invalid water mark configuration");
    4942                 :            :                         ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
    4943                 :          0 :                         goto out;
    4944                 :            :                 }
    4945                 :            :         }
    4946                 :            :         /* Negotiate the fc mode to use */
    4947                 :          0 :         ixgbe_fc_autoneg(hw);
    4948                 :            : 
    4949                 :            :         /* Disable any previous flow control settings */
    4950                 :          0 :         mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
    4951                 :          0 :         mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_SHIFT | IXGBE_MFLCN_RFCE|IXGBE_MFLCN_RPFCE);
    4952                 :            : 
    4953                 :          0 :         fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
    4954                 :          0 :         fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
    4955                 :            : 
    4956   [ #  #  #  #  :          0 :         switch (hw->fc.current_mode) {
                      # ]
    4957                 :            :         case ixgbe_fc_none:
    4958                 :            :                 /*
    4959                 :            :                  * If the count of enabled RX Priority Flow control >1,
    4960                 :            :                  * and the TX pause can not be disabled
    4961                 :            :                  */
    4962                 :            :                 nb_rx_en = 0;
    4963         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
    4964                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
    4965         [ #  # ]:          0 :                         if (reg & IXGBE_FCRTH_FCEN)
    4966                 :          0 :                                 nb_rx_en++;
    4967                 :            :                 }
    4968         [ #  # ]:          0 :                 if (nb_rx_en > 1)
    4969                 :          0 :                         fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
    4970                 :            :                 break;
    4971                 :          0 :         case ixgbe_fc_rx_pause:
    4972                 :            :                 /*
    4973                 :            :                  * Rx Flow control is enabled and Tx Flow control is
    4974                 :            :                  * disabled by software override. Since there really
    4975                 :            :                  * isn't a way to advertise that we are capable of RX
    4976                 :            :                  * Pause ONLY, we will advertise that we support both
    4977                 :            :                  * symmetric and asymmetric Rx PAUSE.  Later, we will
    4978                 :            :                  * disable the adapter's ability to send PAUSE frames.
    4979                 :            :                  */
    4980                 :          0 :                 mflcn_reg |= IXGBE_MFLCN_RPFCE;
    4981                 :            :                 /*
    4982                 :            :                  * If the count of enabled RX Priority Flow control >1,
    4983                 :            :                  * and the TX pause can not be disabled
    4984                 :            :                  */
    4985                 :            :                 nb_rx_en = 0;
    4986         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
    4987                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_FCRTH_82599(i));
    4988         [ #  # ]:          0 :                         if (reg & IXGBE_FCRTH_FCEN)
    4989                 :          0 :                                 nb_rx_en++;
    4990                 :            :                 }
    4991         [ #  # ]:          0 :                 if (nb_rx_en > 1)
    4992                 :          0 :                         fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
    4993                 :            :                 break;
    4994                 :          0 :         case ixgbe_fc_tx_pause:
    4995                 :            :                 /*
    4996                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
    4997                 :            :                  * disabled by software override.
    4998                 :            :                  */
    4999                 :          0 :                 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
    5000                 :          0 :                 break;
    5001                 :          0 :         case ixgbe_fc_full:
    5002                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
    5003                 :          0 :                 mflcn_reg |= IXGBE_MFLCN_RPFCE;
    5004                 :          0 :                 fccfg_reg |= IXGBE_FCCFG_TFCE_PRIORITY;
    5005                 :          0 :                 break;
    5006                 :          0 :         default:
    5007                 :          0 :                 PMD_DRV_LOG(DEBUG, "Flow control param set incorrectly");
    5008                 :            :                 ret_val = IXGBE_ERR_CONFIG;
    5009                 :          0 :                 goto out;
    5010                 :            :         }
    5011                 :            : 
    5012                 :            :         /* Set 802.3x based flow control settings. */
    5013                 :          0 :         mflcn_reg |= IXGBE_MFLCN_DPF;
    5014                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
    5015                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
    5016                 :            : 
    5017                 :            :         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
    5018         [ #  # ]:          0 :         if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
    5019         [ #  # ]:          0 :                 hw->fc.high_water[tc_num]) {
    5020                 :          0 :                 fcrtl = (hw->fc.low_water[tc_num] << 10) | IXGBE_FCRTL_XONE;
    5021                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), fcrtl);
    5022                 :          0 :                 fcrth = (hw->fc.high_water[tc_num] << 10) | IXGBE_FCRTH_FCEN;
    5023                 :            :         } else {
    5024                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(tc_num), 0);
    5025                 :            :                 /*
    5026                 :            :                  * In order to prevent Tx hangs when the internal Tx
    5027                 :            :                  * switch is enabled we must set the high water mark
    5028                 :            :                  * to the maximum FCRTH value.  This allows the Tx
    5029                 :            :                  * switch to function even under heavy Rx workloads.
    5030                 :            :                  */
    5031                 :          0 :                 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num)) - 32;
    5032                 :            :         }
    5033                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(tc_num), fcrth);
    5034                 :            : 
    5035                 :            :         /* Configure pause time (2 TCs per register) */
    5036                 :          0 :         reg = hw->fc.pause_time * 0x00010001;
    5037         [ #  # ]:          0 :         for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
    5038                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
    5039                 :            : 
    5040                 :            :         /* Configure flow control refresh threshold value */
    5041                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
    5042                 :            : 
    5043                 :          0 : out:
    5044                 :          0 :         return ret_val;
    5045                 :            : }
    5046                 :            : 
    5047                 :            : static int
    5048                 :            : ixgbe_dcb_pfc_enable(struct rte_eth_dev *dev, uint8_t tc_num)
    5049                 :            : {
    5050                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5051                 :            :         int32_t ret_val = IXGBE_NOT_IMPLEMENTED;
    5052                 :            : 
    5053                 :          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
    5054                 :          0 :                 ret_val = ixgbe_dcb_pfc_enable_generic(hw, tc_num);
    5055                 :            :         }
    5056                 :            :         return ret_val;
    5057                 :            : }
    5058                 :            : 
    5059                 :            : static int
    5060                 :          0 : ixgbe_priority_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_pfc_conf *pfc_conf)
    5061                 :            : {
    5062                 :            :         int err;
    5063                 :            :         uint32_t rx_buf_size;
    5064                 :            :         uint32_t max_high_water;
    5065                 :            :         uint8_t tc_num;
    5066                 :          0 :         uint8_t  map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
    5067                 :            :         struct ixgbe_hw *hw =
    5068                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5069                 :          0 :         struct ixgbe_dcb_config *dcb_config =
    5070                 :            :                 IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
    5071                 :            : 
    5072                 :          0 :         enum ixgbe_fc_mode rte_fcmode_2_ixgbe_fcmode[] = {
    5073                 :            :                 ixgbe_fc_none,
    5074                 :            :                 ixgbe_fc_rx_pause,
    5075                 :            :                 ixgbe_fc_tx_pause,
    5076                 :            :                 ixgbe_fc_full
    5077                 :            :         };
    5078                 :            : 
    5079                 :          0 :         PMD_INIT_FUNC_TRACE();
    5080                 :            : 
    5081                 :          0 :         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_RX_CONFIG, map);
    5082                 :          0 :         tc_num = map[pfc_conf->priority];
    5083                 :          0 :         rx_buf_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc_num));
    5084                 :          0 :         PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
    5085                 :            :         /*
    5086                 :            :          * At least reserve one Ethernet frame for watermark
    5087                 :            :          * high_water/low_water in kilo bytes for ixgbe
    5088                 :            :          */
    5089                 :          0 :         max_high_water = (rx_buf_size -
    5090                 :            :                         RTE_ETHER_MAX_LEN) >> IXGBE_RXPBSIZE_SHIFT;
    5091         [ #  # ]:          0 :         if ((pfc_conf->fc.high_water > max_high_water) ||
    5092         [ #  # ]:          0 :             (pfc_conf->fc.high_water <= pfc_conf->fc.low_water)) {
    5093                 :          0 :                 PMD_INIT_LOG(ERR, "Invalid high/low water setup value in KB");
    5094                 :          0 :                 PMD_INIT_LOG(ERR, "High_water must <= 0x%x", max_high_water);
    5095                 :          0 :                 return -EINVAL;
    5096                 :            :         }
    5097                 :            : 
    5098                 :          0 :         hw->fc.requested_mode = rte_fcmode_2_ixgbe_fcmode[pfc_conf->fc.mode];
    5099                 :          0 :         hw->fc.pause_time = pfc_conf->fc.pause_time;
    5100                 :          0 :         hw->fc.send_xon = pfc_conf->fc.send_xon;
    5101                 :          0 :         hw->fc.low_water[tc_num] =  pfc_conf->fc.low_water;
    5102         [ #  # ]:          0 :         hw->fc.high_water[tc_num] = pfc_conf->fc.high_water;
    5103                 :            : 
    5104                 :            :         err = ixgbe_dcb_pfc_enable(dev, tc_num);
    5105                 :            : 
    5106                 :            :         /* Not negotiated is not an error case */
    5107         [ #  # ]:          0 :         if ((err == IXGBE_SUCCESS) || (err == IXGBE_ERR_FC_NOT_NEGOTIATED))
    5108                 :            :                 return 0;
    5109                 :            : 
    5110                 :          0 :         PMD_INIT_LOG(ERR, "ixgbe_dcb_pfc_enable = 0x%x", err);
    5111                 :          0 :         return -EIO;
    5112                 :            : }
    5113                 :            : 
    5114                 :            : static int
    5115                 :          0 : ixgbe_dev_rss_reta_update(struct rte_eth_dev *dev,
    5116                 :            :                           struct rte_eth_rss_reta_entry64 *reta_conf,
    5117                 :            :                           uint16_t reta_size)
    5118                 :            : {
    5119                 :            :         uint16_t i, sp_reta_size;
    5120                 :            :         uint8_t j, mask;
    5121                 :            :         uint32_t reta, r;
    5122                 :            :         uint16_t idx, shift;
    5123                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    5124                 :            :         struct rte_eth_dev_data *dev_data = dev->data;
    5125                 :            :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5126                 :            :         uint32_t reta_reg;
    5127                 :            : 
    5128                 :          0 :         PMD_INIT_FUNC_TRACE();
    5129                 :            : 
    5130         [ #  # ]:          0 :         if (!dev_data->dev_started) {
    5131                 :          0 :                 PMD_DRV_LOG(ERR,
    5132                 :            :                         "port %d must be started before rss reta update",
    5133                 :            :                          dev_data->port_id);
    5134                 :          0 :                 return -EIO;
    5135                 :            :         }
    5136                 :            : 
    5137         [ #  # ]:          0 :         if (!ixgbe_rss_update_sp(hw->mac.type)) {
    5138                 :          0 :                 PMD_DRV_LOG(ERR, "RSS reta update is not supported on this "
    5139                 :            :                         "NIC.");
    5140                 :          0 :                 return -ENOTSUP;
    5141                 :            :         }
    5142                 :            : 
    5143                 :          0 :         sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
    5144         [ #  # ]:          0 :         if (reta_size != sp_reta_size) {
    5145                 :          0 :                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
    5146                 :            :                         "(%d) doesn't match the number hardware can supported "
    5147                 :            :                         "(%d)", reta_size, sp_reta_size);
    5148                 :          0 :                 return -EINVAL;
    5149                 :            :         }
    5150                 :            : 
    5151         [ #  # ]:          0 :         for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
    5152                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    5153                 :          0 :                 shift = i % RTE_ETH_RETA_GROUP_SIZE;
    5154                 :          0 :                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
    5155                 :            :                                                 IXGBE_4_BIT_MASK);
    5156         [ #  # ]:          0 :                 if (!mask)
    5157                 :          0 :                         continue;
    5158                 :          0 :                 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
    5159         [ #  # ]:          0 :                 if (mask == IXGBE_4_BIT_MASK)
    5160                 :            :                         r = 0;
    5161                 :            :                 else
    5162                 :          0 :                         r = IXGBE_READ_REG(hw, reta_reg);
    5163         [ #  # ]:          0 :                 for (j = 0, reta = 0; j < IXGBE_4_BIT_WIDTH; j++) {
    5164         [ #  # ]:          0 :                         if (mask & (0x1 << j))
    5165                 :          0 :                                 reta |= reta_conf[idx].reta[shift + j] <<
    5166                 :          0 :                                                         (CHAR_BIT * j);
    5167                 :            :                         else
    5168                 :          0 :                                 reta |= r & (IXGBE_8_BIT_MASK <<
    5169                 :          0 :                                                 (CHAR_BIT * j));
    5170                 :            :                 }
    5171                 :          0 :                 IXGBE_WRITE_REG(hw, reta_reg, reta);
    5172                 :            :         }
    5173                 :          0 :         adapter->rss_reta_updated = 1;
    5174                 :            : 
    5175                 :          0 :         return 0;
    5176                 :            : }
    5177                 :            : 
    5178                 :            : static int
    5179                 :          0 : ixgbe_dev_rss_reta_query(struct rte_eth_dev *dev,
    5180                 :            :                          struct rte_eth_rss_reta_entry64 *reta_conf,
    5181                 :            :                          uint16_t reta_size)
    5182                 :            : {
    5183                 :            :         uint16_t i, sp_reta_size;
    5184                 :            :         uint8_t j, mask;
    5185                 :            :         uint32_t reta;
    5186                 :            :         uint16_t idx, shift;
    5187                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5188                 :            :         uint32_t reta_reg;
    5189                 :            : 
    5190                 :          0 :         PMD_INIT_FUNC_TRACE();
    5191                 :          0 :         sp_reta_size = ixgbe_reta_size_get(hw->mac.type);
    5192         [ #  # ]:          0 :         if (reta_size != sp_reta_size) {
    5193                 :          0 :                 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
    5194                 :            :                         "(%d) doesn't match the number hardware can supported "
    5195                 :            :                         "(%d)", reta_size, sp_reta_size);
    5196                 :          0 :                 return -EINVAL;
    5197                 :            :         }
    5198                 :            : 
    5199         [ #  # ]:          0 :         for (i = 0; i < reta_size; i += IXGBE_4_BIT_WIDTH) {
    5200                 :          0 :                 idx = i / RTE_ETH_RETA_GROUP_SIZE;
    5201                 :          0 :                 shift = i % RTE_ETH_RETA_GROUP_SIZE;
    5202                 :          0 :                 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
    5203                 :            :                                                 IXGBE_4_BIT_MASK);
    5204         [ #  # ]:          0 :                 if (!mask)
    5205                 :          0 :                         continue;
    5206                 :            : 
    5207                 :          0 :                 reta_reg = ixgbe_reta_reg_get(hw->mac.type, i);
    5208                 :          0 :                 reta = IXGBE_READ_REG(hw, reta_reg);
    5209         [ #  # ]:          0 :                 for (j = 0; j < IXGBE_4_BIT_WIDTH; j++) {
    5210         [ #  # ]:          0 :                         if (mask & (0x1 << j))
    5211                 :          0 :                                 reta_conf[idx].reta[shift + j] =
    5212                 :          0 :                                         ((reta >> (CHAR_BIT * j)) &
    5213                 :            :                                                 IXGBE_8_BIT_MASK);
    5214                 :            :                 }
    5215                 :            :         }
    5216                 :            : 
    5217                 :            :         return 0;
    5218                 :            : }
    5219                 :            : 
    5220                 :            : static int
    5221                 :          0 : ixgbe_add_rar(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
    5222                 :            :                                 uint32_t index, uint32_t pool)
    5223                 :            : {
    5224                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5225                 :            :         uint32_t enable_addr = 1;
    5226                 :            : 
    5227                 :          0 :         return ixgbe_set_rar(hw, index, mac_addr->addr_bytes,
    5228                 :            :                              pool, enable_addr);
    5229                 :            : }
    5230                 :            : 
    5231                 :            : static void
    5232                 :          0 : ixgbe_remove_rar(struct rte_eth_dev *dev, uint32_t index)
    5233                 :            : {
    5234                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5235                 :            : 
    5236                 :          0 :         ixgbe_clear_rar(hw, index);
    5237                 :          0 : }
    5238                 :            : 
    5239                 :            : static int
    5240                 :          0 : ixgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
    5241                 :            : {
    5242                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5243                 :            : 
    5244                 :            :         ixgbe_remove_rar(dev, 0);
    5245                 :          0 :         ixgbe_add_rar(dev, addr, 0, pci_dev->max_vfs);
    5246                 :            : 
    5247                 :          0 :         return 0;
    5248                 :            : }
    5249                 :            : 
    5250                 :            : static bool
    5251                 :            : is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
    5252                 :            : {
    5253                 :          0 :         if (strcmp(dev->device->driver->name, drv->driver.name))
    5254                 :          0 :                 return false;
    5255                 :            : 
    5256                 :            :         return true;
    5257                 :            : }
    5258                 :            : 
    5259                 :            : bool
    5260         [ #  # ]:          0 : is_ixgbe_supported(struct rte_eth_dev *dev)
    5261                 :            : {
    5262                 :          0 :         return is_device_supported(dev, &rte_ixgbe_pmd);
    5263                 :            : }
    5264                 :            : 
    5265                 :            : static int
    5266                 :          0 : ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
    5267                 :            : {
    5268                 :            :         uint32_t hlreg0;
    5269                 :            :         uint32_t maxfrs;
    5270                 :            :         struct ixgbe_hw *hw;
    5271                 :            :         struct rte_eth_dev_info dev_info;
    5272                 :          0 :         uint32_t frame_size = mtu + IXGBE_ETH_OVERHEAD;
    5273                 :            :         int ret;
    5274                 :            : 
    5275                 :          0 :         ret = ixgbe_dev_info_get(dev, &dev_info);
    5276         [ #  # ]:          0 :         if (ret != 0)
    5277                 :            :                 return ret;
    5278                 :            : 
    5279                 :            :         /* check that mtu is within the allowed range */
    5280   [ #  #  #  # ]:          0 :         if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
    5281                 :            :                 return -EINVAL;
    5282                 :            : 
    5283                 :            :         /* If device is started, refuse mtu that requires the support of
    5284                 :            :          * scattered packets when this feature has not been enabled before.
    5285                 :            :          */
    5286         [ #  # ]:          0 :         if (dev->data->dev_started && !dev->data->scattered_rx &&
    5287                 :          0 :             frame_size + 2 * RTE_VLAN_HLEN >
    5288         [ #  # ]:          0 :                         dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
    5289                 :          0 :                 PMD_INIT_LOG(ERR, "Stop port first.");
    5290                 :          0 :                 return -EINVAL;
    5291                 :            :         }
    5292                 :            : 
    5293                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5294                 :          0 :         hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
    5295                 :            : 
    5296                 :            :         /* switch to jumbo mode if needed */
    5297         [ #  # ]:          0 :         if (mtu > RTE_ETHER_MTU)
    5298                 :          0 :                 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
    5299                 :            :         else
    5300                 :          0 :                 hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
    5301                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
    5302                 :            : 
    5303                 :          0 :         maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
    5304                 :          0 :         maxfrs &= 0x0000FFFF;
    5305                 :          0 :         maxfrs |= (frame_size << 16);
    5306                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, maxfrs);
    5307                 :            : 
    5308                 :          0 :         return 0;
    5309                 :            : }
    5310                 :            : 
    5311                 :            : /*
    5312                 :            :  * Virtual Function operations
    5313                 :            :  */
    5314                 :            : static void
    5315                 :          0 : ixgbevf_intr_disable(struct rte_eth_dev *dev)
    5316                 :            : {
    5317                 :            :         struct ixgbe_interrupt *intr =
    5318                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5319                 :            :         struct ixgbe_hw *hw =
    5320                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5321                 :            : 
    5322                 :          0 :         PMD_INIT_FUNC_TRACE();
    5323                 :            : 
    5324                 :            :         /* Clear interrupt mask to stop from interrupts being generated */
    5325                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, IXGBE_VF_IRQ_CLEAR_MASK);
    5326                 :            : 
    5327                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    5328                 :            : 
    5329                 :            :         /* Clear mask value. */
    5330                 :          0 :         intr->mask = 0;
    5331                 :          0 : }
    5332                 :            : 
    5333                 :            : static void
    5334                 :          0 : ixgbevf_intr_enable(struct rte_eth_dev *dev)
    5335                 :            : {
    5336                 :            :         struct ixgbe_interrupt *intr =
    5337                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5338                 :            :         struct ixgbe_hw *hw =
    5339                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5340                 :            : 
    5341                 :          0 :         PMD_INIT_FUNC_TRACE();
    5342                 :            : 
    5343                 :            :         /* VF enable interrupt autoclean */
    5344                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, IXGBE_VF_IRQ_ENABLE_MASK);
    5345                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, IXGBE_VF_IRQ_ENABLE_MASK);
    5346                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, IXGBE_VF_IRQ_ENABLE_MASK);
    5347                 :            : 
    5348                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    5349                 :            : 
    5350                 :            :         /* Save IXGBE_VTEIMS value to mask. */
    5351                 :          0 :         intr->mask = IXGBE_VF_IRQ_ENABLE_MASK;
    5352                 :          0 : }
    5353                 :            : 
    5354                 :            : static int
    5355                 :          0 : ixgbevf_dev_configure(struct rte_eth_dev *dev)
    5356                 :            : {
    5357                 :          0 :         struct rte_eth_conf *conf = &dev->data->dev_conf;
    5358                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    5359                 :            : 
    5360                 :          0 :         PMD_INIT_LOG(DEBUG, "Configured Virtual Function port id: %d",
    5361                 :            :                      dev->data->port_id);
    5362                 :            : 
    5363         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
    5364                 :          0 :                 dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
    5365                 :            : 
    5366                 :            :         /*
    5367                 :            :          * VF has no ability to enable/disable HW CRC
    5368                 :            :          * Keep the persistent behavior the same as Host PF
    5369                 :            :          */
    5370                 :            : #ifndef RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC
    5371         [ #  # ]:          0 :         if (conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
    5372                 :          0 :                 PMD_INIT_LOG(NOTICE, "VF can't disable HW CRC Strip");
    5373                 :          0 :                 conf->rxmode.offloads &= ~RTE_ETH_RX_OFFLOAD_KEEP_CRC;
    5374                 :            :         }
    5375                 :            : #else
    5376                 :            :         if (!(conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)) {
    5377                 :            :                 PMD_INIT_LOG(NOTICE, "VF can't enable HW CRC Strip");
    5378                 :            :                 conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_KEEP_CRC;
    5379                 :            :         }
    5380                 :            : #endif
    5381                 :            : 
    5382                 :            :         /*
    5383                 :            :          * Initialize to TRUE. If any of Rx queues doesn't meet the bulk
    5384                 :            :          * allocation or vector Rx preconditions we will reset it.
    5385                 :            :          */
    5386                 :          0 :         adapter->rx_bulk_alloc_allowed = true;
    5387                 :          0 :         adapter->rx_vec_allowed = true;
    5388                 :            : 
    5389                 :          0 :         return 0;
    5390                 :            : }
    5391                 :            : 
    5392                 :            : static int
    5393                 :          0 : ixgbevf_dev_start(struct rte_eth_dev *dev)
    5394                 :            : {
    5395                 :          0 :         struct ixgbe_hw *hw =
    5396                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5397                 :            :         uint32_t intr_vector = 0;
    5398                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5399                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5400                 :            : 
    5401                 :            :         int err, mask = 0;
    5402                 :            : 
    5403                 :          0 :         PMD_INIT_FUNC_TRACE();
    5404                 :            : 
    5405                 :            :         /* Stop the link setup handler before resetting the HW. */
    5406                 :          0 :         ixgbe_dev_wait_setup_link_complete(dev, 0);
    5407                 :            : 
    5408                 :          0 :         err = hw->mac.ops.reset_hw(hw);
    5409                 :            : 
    5410                 :            :         /**
    5411                 :            :          * In this case, reuses the MAC address assigned by VF
    5412                 :            :          * initialization.
    5413                 :            :          */
    5414         [ #  # ]:          0 :         if (err != IXGBE_SUCCESS && err != IXGBE_ERR_INVALID_MAC_ADDR) {
    5415                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to reset vf hardware (%d)", err);
    5416                 :          0 :                 return err;
    5417                 :            :         }
    5418                 :            : 
    5419                 :          0 :         hw->mac.get_link_status = true;
    5420                 :            : 
    5421                 :            :         /* negotiate mailbox API version to use with the PF. */
    5422                 :          0 :         ixgbevf_negotiate_api(hw);
    5423                 :            : 
    5424                 :          0 :         ixgbevf_dev_tx_init(dev);
    5425                 :            : 
    5426                 :            :         /* This can fail when allocating mbufs for descriptor rings */
    5427                 :          0 :         err = ixgbevf_dev_rx_init(dev);
    5428         [ #  # ]:          0 :         if (err) {
    5429                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware (%d)", err);
    5430                 :          0 :                 ixgbe_dev_clear_queues(dev);
    5431                 :          0 :                 return err;
    5432                 :            :         }
    5433                 :            : 
    5434                 :            :         /* Set vfta */
    5435                 :          0 :         ixgbevf_set_vfta_all(dev, 1);
    5436                 :            : 
    5437                 :            :         /* Set HW strip */
    5438                 :            :         mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
    5439                 :            :                 RTE_ETH_VLAN_EXTEND_MASK;
    5440                 :          0 :         err = ixgbevf_vlan_offload_config(dev, mask);
    5441         [ #  # ]:          0 :         if (err) {
    5442                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to set VLAN offload (%d)", err);
    5443                 :          0 :                 ixgbe_dev_clear_queues(dev);
    5444                 :          0 :                 return err;
    5445                 :            :         }
    5446                 :            : 
    5447                 :          0 :         ixgbevf_dev_rxtx_start(dev);
    5448                 :            : 
    5449                 :            :         /* check and configure queue intr-vector mapping */
    5450         [ #  # ]:          0 :         if (rte_intr_cap_multiple(intr_handle) &&
    5451         [ #  # ]:          0 :             dev->data->dev_conf.intr_conf.rxq) {
    5452                 :            :                 /* According to datasheet, only vector 0/1/2 can be used,
    5453                 :            :                  * now only one vector is used for Rx queue
    5454                 :            :                  */
    5455                 :            :                 intr_vector = 1;
    5456         [ #  # ]:          0 :                 if (rte_intr_efd_enable(intr_handle, intr_vector)) {
    5457                 :          0 :                         ixgbe_dev_clear_queues(dev);
    5458                 :          0 :                         return -1;
    5459                 :            :                 }
    5460                 :            :         }
    5461                 :            : 
    5462         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
    5463         [ #  # ]:          0 :                 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
    5464                 :          0 :                                                    dev->data->nb_rx_queues)) {
    5465                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
    5466                 :            :                                      " intr_vec", dev->data->nb_rx_queues);
    5467                 :          0 :                         ixgbe_dev_clear_queues(dev);
    5468                 :          0 :                         return -ENOMEM;
    5469                 :            :                 }
    5470                 :            :         }
    5471                 :          0 :         ixgbevf_configure_msix(dev);
    5472                 :            : 
    5473                 :            :         /* When a VF port is bound to VFIO-PCI, only miscellaneous interrupt
    5474                 :            :          * is mapped to VFIO vector 0 in eth_ixgbevf_dev_init( ).
    5475                 :            :          * If previous VFIO interrupt mapping setting in eth_ixgbevf_dev_init( )
    5476                 :            :          * is not cleared, it will fail when following rte_intr_enable( ) tries
    5477                 :            :          * to map Rx queue interrupt to other VFIO vectors.
    5478                 :            :          * So clear uio/vfio intr/evevnfd first to avoid failure.
    5479                 :            :          */
    5480                 :          0 :         rte_intr_disable(intr_handle);
    5481                 :            : 
    5482                 :          0 :         rte_intr_enable(intr_handle);
    5483                 :            : 
    5484                 :            :         /* Re-enable interrupt for VF */
    5485                 :          0 :         ixgbevf_intr_enable(dev);
    5486                 :            : 
    5487                 :            :         /*
    5488                 :            :          * Update link status right before return, because it may
    5489                 :            :          * start link configuration process in a separate thread.
    5490                 :            :          */
    5491                 :            :         ixgbevf_dev_link_update(dev, 0);
    5492                 :            : 
    5493                 :          0 :         hw->adapter_stopped = false;
    5494                 :            : 
    5495                 :          0 :         return 0;
    5496                 :            : }
    5497                 :            : 
    5498                 :            : static int
    5499                 :          0 : ixgbevf_dev_stop(struct rte_eth_dev *dev)
    5500                 :            : {
    5501                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5502                 :            :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    5503                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5504                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5505                 :            : 
    5506         [ #  # ]:          0 :         if (hw->adapter_stopped)
    5507                 :            :                 return 0;
    5508                 :            : 
    5509                 :          0 :         PMD_INIT_FUNC_TRACE();
    5510                 :            : 
    5511                 :          0 :         ixgbe_dev_wait_setup_link_complete(dev, 0);
    5512                 :            : 
    5513                 :          0 :         ixgbevf_intr_disable(dev);
    5514                 :            : 
    5515                 :          0 :         dev->data->dev_started = 0;
    5516                 :          0 :         hw->adapter_stopped = 1;
    5517                 :          0 :         ixgbe_stop_adapter(hw);
    5518                 :            : 
    5519                 :            :         /*
    5520                 :            :           * Clear what we set, but we still keep shadow_vfta to
    5521                 :            :           * restore after device starts
    5522                 :            :           */
    5523                 :          0 :         ixgbevf_set_vfta_all(dev, 0);
    5524                 :            : 
    5525                 :            :         /* Clear stored conf */
    5526                 :          0 :         dev->data->scattered_rx = 0;
    5527                 :            : 
    5528                 :          0 :         ixgbe_dev_clear_queues(dev);
    5529                 :            : 
    5530                 :            :         /* Clean datapath event and queue/vec mapping */
    5531                 :          0 :         rte_intr_efd_disable(intr_handle);
    5532                 :          0 :         rte_intr_vec_list_free(intr_handle);
    5533                 :            : 
    5534                 :          0 :         adapter->rss_reta_updated = 0;
    5535                 :            : 
    5536                 :          0 :         return 0;
    5537                 :            : }
    5538                 :            : 
    5539                 :            : static int
    5540                 :          0 : ixgbevf_dev_close(struct rte_eth_dev *dev)
    5541                 :            : {
    5542                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5543                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5544                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5545                 :            :         int ret;
    5546                 :            : 
    5547                 :          0 :         PMD_INIT_FUNC_TRACE();
    5548         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    5549                 :            :                 return 0;
    5550                 :            : 
    5551                 :          0 :         ixgbe_reset_hw(hw);
    5552                 :            : 
    5553                 :          0 :         ret = ixgbevf_dev_stop(dev);
    5554                 :            : 
    5555                 :          0 :         ixgbe_dev_free_queues(dev);
    5556                 :            : 
    5557                 :            :         /**
    5558                 :            :          * Remove the VF MAC address ro ensure
    5559                 :            :          * that the VF traffic goes to the PF
    5560                 :            :          * after stop, close and detach of the VF
    5561                 :            :          **/
    5562                 :          0 :         ixgbevf_remove_mac_addr(dev, 0);
    5563                 :            : 
    5564                 :          0 :         rte_intr_disable(intr_handle);
    5565                 :          0 :         rte_intr_callback_unregister(intr_handle,
    5566                 :            :                                      ixgbevf_dev_interrupt_handler, dev);
    5567                 :            : 
    5568                 :          0 :         return ret;
    5569                 :            : }
    5570                 :            : 
    5571                 :            : /*
    5572                 :            :  * Reset VF device
    5573                 :            :  */
    5574                 :            : static int
    5575                 :          0 : ixgbevf_dev_reset(struct rte_eth_dev *dev)
    5576                 :            : {
    5577                 :            :         int ret;
    5578                 :            : 
    5579                 :          0 :         ret = eth_ixgbevf_dev_uninit(dev);
    5580         [ #  # ]:          0 :         if (ret)
    5581                 :            :                 return ret;
    5582                 :            : 
    5583                 :          0 :         ret = eth_ixgbevf_dev_init(dev);
    5584                 :            : 
    5585                 :          0 :         return ret;
    5586                 :            : }
    5587                 :            : 
    5588                 :          0 : static void ixgbevf_set_vfta_all(struct rte_eth_dev *dev, bool on)
    5589                 :            : {
    5590                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5591                 :            :         struct ixgbe_vfta *shadow_vfta =
    5592                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    5593                 :            :         int i = 0, j = 0, vfta = 0, mask = 1;
    5594                 :            : 
    5595         [ #  # ]:          0 :         for (i = 0; i < IXGBE_VFTA_SIZE; i++) {
    5596                 :          0 :                 vfta = shadow_vfta->vfta[i];
    5597         [ #  # ]:          0 :                 if (vfta) {
    5598                 :            :                         mask = 1;
    5599         [ #  # ]:          0 :                         for (j = 0; j < 32; j++) {
    5600         [ #  # ]:          0 :                                 if (vfta & mask)
    5601                 :          0 :                                         ixgbe_set_vfta(hw, (i<<5)+j, 0,
    5602                 :            :                                                        on, false);
    5603                 :          0 :                                 mask <<= 1;
    5604                 :            :                         }
    5605                 :            :                 }
    5606                 :            :         }
    5607                 :            : 
    5608                 :          0 : }
    5609                 :            : 
    5610                 :            : static int
    5611                 :          0 : ixgbevf_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
    5612                 :            : {
    5613                 :          0 :         struct ixgbe_hw *hw =
    5614                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5615                 :            :         struct ixgbe_vfta *shadow_vfta =
    5616                 :            :                 IXGBE_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    5617                 :            :         uint32_t vid_idx = 0;
    5618                 :            :         uint32_t vid_bit = 0;
    5619                 :            :         int ret = 0;
    5620                 :            : 
    5621                 :          0 :         PMD_INIT_FUNC_TRACE();
    5622                 :            : 
    5623                 :            :         /* vind is not used in VF driver, set to 0, check ixgbe_set_vfta_vf */
    5624                 :          0 :         ret = ixgbe_set_vfta(hw, vlan_id, 0, !!on, false);
    5625         [ #  # ]:          0 :         if (ret) {
    5626                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to set VF vlan");
    5627                 :          0 :                 return ret;
    5628                 :            :         }
    5629                 :          0 :         vid_idx = (uint32_t) ((vlan_id >> 5) & 0x7F);
    5630                 :          0 :         vid_bit = (uint32_t) (1 << (vlan_id & 0x1F));
    5631                 :            : 
    5632                 :            :         /* Save what we set and retore it after device reset */
    5633         [ #  # ]:          0 :         if (on)
    5634                 :          0 :                 shadow_vfta->vfta[vid_idx] |= vid_bit;
    5635                 :            :         else
    5636                 :          0 :                 shadow_vfta->vfta[vid_idx] &= ~vid_bit;
    5637                 :            : 
    5638                 :            :         return 0;
    5639                 :            : }
    5640                 :            : 
    5641                 :            : static void
    5642                 :          0 : ixgbevf_vlan_strip_queue_set(struct rte_eth_dev *dev, uint16_t queue, int on)
    5643                 :            : {
    5644                 :            :         struct ixgbe_hw *hw =
    5645                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5646                 :            :         uint32_t ctrl;
    5647                 :            : 
    5648                 :          0 :         PMD_INIT_FUNC_TRACE();
    5649                 :            : 
    5650         [ #  # ]:          0 :         if (queue >= hw->mac.max_rx_queues)
    5651                 :            :                 return;
    5652                 :            : 
    5653         [ #  # ]:          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(queue));
    5654         [ #  # ]:          0 :         if (on)
    5655                 :          0 :                 ctrl |= IXGBE_RXDCTL_VME;
    5656                 :            :         else
    5657                 :          0 :                 ctrl &= ~IXGBE_RXDCTL_VME;
    5658                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(queue), ctrl);
    5659                 :            : 
    5660                 :          0 :         ixgbe_vlan_hw_strip_bitmap_set(dev, queue, on);
    5661                 :            : }
    5662                 :            : 
    5663                 :            : static int
    5664                 :          0 : ixgbevf_vlan_offload_config(struct rte_eth_dev *dev, int mask)
    5665                 :            : {
    5666                 :            :         struct ixgbe_rx_queue *rxq;
    5667                 :            :         uint16_t i;
    5668                 :            :         int on = 0;
    5669                 :            : 
    5670                 :            :         /* VF function only support hw strip feature, others are not support */
    5671         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
    5672         [ #  # ]:          0 :                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
    5673                 :          0 :                         rxq = dev->data->rx_queues[i];
    5674                 :          0 :                         on = !!(rxq->offloads &  RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
    5675                 :          0 :                         ixgbevf_vlan_strip_queue_set(dev, i, on);
    5676                 :            :                 }
    5677                 :            :         }
    5678                 :            : 
    5679                 :          0 :         return 0;
    5680                 :            : }
    5681                 :            : 
    5682                 :            : static int
    5683                 :          0 : ixgbevf_vlan_offload_set(struct rte_eth_dev *dev, int mask)
    5684                 :            : {
    5685                 :          0 :         ixgbe_config_vlan_strip_on_all_queues(dev, mask);
    5686                 :            : 
    5687                 :          0 :         ixgbevf_vlan_offload_config(dev, mask);
    5688                 :            : 
    5689                 :          0 :         return 0;
    5690                 :            : }
    5691                 :            : 
    5692                 :            : int
    5693                 :          0 : ixgbe_vt_check(struct ixgbe_hw *hw)
    5694                 :            : {
    5695                 :            :         uint32_t reg_val;
    5696                 :            : 
    5697                 :            :         /* if Virtualization Technology is enabled */
    5698                 :          0 :         reg_val = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
    5699         [ #  # ]:          0 :         if (!(reg_val & IXGBE_VT_CTL_VT_ENABLE)) {
    5700                 :          0 :                 PMD_INIT_LOG(ERR, "VT must be enabled for this setting");
    5701                 :          0 :                 return -1;
    5702                 :            :         }
    5703                 :            : 
    5704                 :            :         return 0;
    5705                 :            : }
    5706                 :            : 
    5707                 :            : static uint32_t
    5708                 :          0 : ixgbe_uta_vector(struct ixgbe_hw *hw, struct rte_ether_addr *uc_addr)
    5709                 :            : {
    5710                 :            :         uint32_t vector = 0;
    5711                 :            : 
    5712   [ #  #  #  #  :          0 :         switch (hw->mac.mc_filter_type) {
                      # ]
    5713                 :          0 :         case 0:   /* use bits [47:36] of the address */
    5714                 :          0 :                 vector = ((uc_addr->addr_bytes[4] >> 4) |
    5715                 :          0 :                         (((uint16_t)uc_addr->addr_bytes[5]) << 4));
    5716                 :          0 :                 break;
    5717                 :          0 :         case 1:   /* use bits [46:35] of the address */
    5718                 :          0 :                 vector = ((uc_addr->addr_bytes[4] >> 3) |
    5719                 :          0 :                         (((uint16_t)uc_addr->addr_bytes[5]) << 5));
    5720                 :          0 :                 break;
    5721                 :          0 :         case 2:   /* use bits [45:34] of the address */
    5722                 :          0 :                 vector = ((uc_addr->addr_bytes[4] >> 2) |
    5723                 :          0 :                         (((uint16_t)uc_addr->addr_bytes[5]) << 6));
    5724                 :          0 :                 break;
    5725                 :          0 :         case 3:   /* use bits [43:32] of the address */
    5726                 :          0 :                 vector = ((uc_addr->addr_bytes[4]) |
    5727                 :          0 :                         (((uint16_t)uc_addr->addr_bytes[5]) << 8));
    5728                 :          0 :                 break;
    5729                 :            :         default:  /* Invalid mc_filter_type */
    5730                 :            :                 break;
    5731                 :            :         }
    5732                 :            : 
    5733                 :            :         /* vector can only be 12-bits or boundary will be exceeded */
    5734                 :          0 :         vector &= 0xFFF;
    5735                 :          0 :         return vector;
    5736                 :            : }
    5737                 :            : 
    5738                 :            : static int
    5739                 :          0 : ixgbe_uc_hash_table_set(struct rte_eth_dev *dev,
    5740                 :            :                         struct rte_ether_addr *mac_addr, uint8_t on)
    5741                 :            : {
    5742                 :            :         uint32_t vector;
    5743                 :            :         uint32_t uta_idx;
    5744                 :            :         uint32_t reg_val;
    5745                 :            :         uint32_t uta_shift;
    5746                 :            :         uint32_t rc;
    5747                 :            :         const uint32_t ixgbe_uta_idx_mask = 0x7F;
    5748                 :            :         const uint32_t ixgbe_uta_bit_shift = 5;
    5749                 :            :         const uint32_t ixgbe_uta_bit_mask = (0x1 << ixgbe_uta_bit_shift) - 1;
    5750                 :            :         const uint32_t bit1 = 0x1;
    5751                 :            : 
    5752                 :          0 :         struct ixgbe_hw *hw =
    5753                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5754                 :            :         struct ixgbe_uta_info *uta_info =
    5755                 :            :                 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
    5756                 :            : 
    5757                 :            :         /* The UTA table only exists on 82599 hardware and newer */
    5758         [ #  # ]:          0 :         if (hw->mac.type < ixgbe_mac_82599EB)
    5759                 :            :                 return -ENOTSUP;
    5760                 :            : 
    5761                 :          0 :         vector = ixgbe_uta_vector(hw, mac_addr);
    5762                 :          0 :         uta_idx = (vector >> ixgbe_uta_bit_shift) & ixgbe_uta_idx_mask;
    5763                 :          0 :         uta_shift = vector & ixgbe_uta_bit_mask;
    5764                 :            : 
    5765                 :          0 :         rc = ((uta_info->uta_shadow[uta_idx] >> uta_shift & bit1) != 0);
    5766         [ #  # ]:          0 :         if (rc == on)
    5767                 :            :                 return 0;
    5768                 :            : 
    5769                 :          0 :         reg_val = IXGBE_READ_REG(hw, IXGBE_UTA(uta_idx));
    5770         [ #  # ]:          0 :         if (on) {
    5771                 :          0 :                 uta_info->uta_in_use++;
    5772                 :          0 :                 reg_val |= (bit1 << uta_shift);
    5773                 :          0 :                 uta_info->uta_shadow[uta_idx] |= (bit1 << uta_shift);
    5774                 :            :         } else {
    5775                 :          0 :                 uta_info->uta_in_use--;
    5776                 :          0 :                 reg_val &= ~(bit1 << uta_shift);
    5777                 :          0 :                 uta_info->uta_shadow[uta_idx] &= ~(bit1 << uta_shift);
    5778                 :            :         }
    5779                 :            : 
    5780                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_UTA(uta_idx), reg_val);
    5781                 :            : 
    5782         [ #  # ]:          0 :         if (uta_info->uta_in_use > 0)
    5783                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
    5784                 :            :                                 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
    5785                 :            :         else
    5786                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
    5787                 :            : 
    5788                 :            :         return 0;
    5789                 :            : }
    5790                 :            : 
    5791                 :            : static int
    5792                 :          0 : ixgbe_uc_all_hash_table_set(struct rte_eth_dev *dev, uint8_t on)
    5793                 :            : {
    5794                 :            :         int i;
    5795                 :            :         struct ixgbe_hw *hw =
    5796                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5797                 :            :         struct ixgbe_uta_info *uta_info =
    5798                 :            :                 IXGBE_DEV_PRIVATE_TO_UTA(dev->data->dev_private);
    5799                 :            : 
    5800                 :            :         /* The UTA table only exists on 82599 hardware and newer */
    5801         [ #  # ]:          0 :         if (hw->mac.type < ixgbe_mac_82599EB)
    5802                 :            :                 return -ENOTSUP;
    5803                 :            : 
    5804         [ #  # ]:          0 :         if (on) {
    5805         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
    5806                 :          0 :                         uta_info->uta_shadow[i] = ~0;
    5807                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
    5808                 :            :                 }
    5809                 :            :         } else {
    5810         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY; i++) {
    5811                 :          0 :                         uta_info->uta_shadow[i] = 0;
    5812                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
    5813                 :            :                 }
    5814                 :            :         }
    5815                 :            :         return 0;
    5816                 :            : 
    5817                 :            : }
    5818                 :            : 
    5819                 :            : uint32_t
    5820                 :          0 : ixgbe_convert_vm_rx_mask_to_val(uint16_t rx_mask, uint32_t orig_val)
    5821                 :            : {
    5822                 :            :         uint32_t new_val = orig_val;
    5823                 :            : 
    5824         [ #  # ]:          0 :         if (rx_mask & RTE_ETH_VMDQ_ACCEPT_UNTAG)
    5825                 :          0 :                 new_val |= IXGBE_VMOLR_AUPE;
    5826         [ #  # ]:          0 :         if (rx_mask & RTE_ETH_VMDQ_ACCEPT_HASH_MC)
    5827                 :          0 :                 new_val |= IXGBE_VMOLR_ROMPE;
    5828         [ #  # ]:          0 :         if (rx_mask & RTE_ETH_VMDQ_ACCEPT_HASH_UC)
    5829                 :          0 :                 new_val |= IXGBE_VMOLR_ROPE;
    5830         [ #  # ]:          0 :         if (rx_mask & RTE_ETH_VMDQ_ACCEPT_BROADCAST)
    5831                 :          0 :                 new_val |= IXGBE_VMOLR_BAM;
    5832         [ #  # ]:          0 :         if (rx_mask & RTE_ETH_VMDQ_ACCEPT_MULTICAST)
    5833                 :          0 :                 new_val |= IXGBE_VMOLR_MPE;
    5834                 :            : 
    5835                 :          0 :         return new_val;
    5836                 :            : }
    5837                 :            : 
    5838                 :            : static int
    5839                 :          0 : ixgbevf_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
    5840                 :            : {
    5841                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5842                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5843                 :            :         struct ixgbe_interrupt *intr =
    5844                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5845                 :            :         struct ixgbe_hw *hw =
    5846                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5847                 :            :         uint32_t vec = IXGBE_MISC_VEC_ID;
    5848                 :            : 
    5849         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle))
    5850                 :            :                 vec = IXGBE_RX_VEC_START;
    5851                 :          0 :         intr->mask |= (1 << vec);
    5852                 :            :         RTE_SET_USED(queue_id);
    5853                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, intr->mask);
    5854                 :            : 
    5855                 :          0 :         rte_intr_ack(intr_handle);
    5856                 :            : 
    5857                 :          0 :         return 0;
    5858                 :            : }
    5859                 :            : 
    5860                 :            : static int
    5861                 :          0 : ixgbevf_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
    5862                 :            : {
    5863                 :            :         struct ixgbe_interrupt *intr =
    5864                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5865                 :            :         struct ixgbe_hw *hw =
    5866                 :            :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5867                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5868                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5869                 :            :         uint32_t vec = IXGBE_MISC_VEC_ID;
    5870                 :            : 
    5871         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle))
    5872                 :            :                 vec = IXGBE_RX_VEC_START;
    5873                 :          0 :         intr->mask &= ~(1 << vec);
    5874                 :            :         RTE_SET_USED(queue_id);
    5875                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, intr->mask);
    5876                 :            : 
    5877                 :          0 :         return 0;
    5878                 :            : }
    5879                 :            : 
    5880                 :            : static int
    5881                 :          0 : ixgbe_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
    5882                 :            : {
    5883                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    5884                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    5885                 :            :         uint32_t mask;
    5886                 :          0 :         struct ixgbe_hw *hw =
    5887                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5888                 :            :         struct ixgbe_interrupt *intr =
    5889                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5890                 :            : 
    5891         [ #  # ]:          0 :         if (queue_id < 16) {
    5892                 :          0 :                 ixgbe_disable_intr(hw);
    5893                 :          0 :                 intr->mask |= (1 << queue_id);
    5894                 :            :                 ixgbe_enable_intr(dev);
    5895         [ #  # ]:          0 :         } else if (queue_id < 32) {
    5896                 :          0 :                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
    5897                 :          0 :                 mask &= (1 << queue_id);
    5898                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
    5899         [ #  # ]:          0 :         } else if (queue_id < 64) {
    5900                 :          0 :                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
    5901                 :          0 :                 mask &= (1 << (queue_id - 32));
    5902                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
    5903                 :            :         }
    5904                 :          0 :         rte_intr_ack(intr_handle);
    5905                 :            : 
    5906                 :          0 :         return 0;
    5907                 :            : }
    5908                 :            : 
    5909                 :            : static int
    5910                 :          0 : ixgbe_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
    5911                 :            : {
    5912                 :            :         uint32_t mask;
    5913                 :          0 :         struct ixgbe_hw *hw =
    5914                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    5915                 :            :         struct ixgbe_interrupt *intr =
    5916                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    5917                 :            : 
    5918         [ #  # ]:          0 :         if (queue_id < 16) {
    5919                 :          0 :                 ixgbe_disable_intr(hw);
    5920                 :          0 :                 intr->mask &= ~(1 << queue_id);
    5921                 :            :                 ixgbe_enable_intr(dev);
    5922         [ #  # ]:          0 :         } else if (queue_id < 32) {
    5923                 :          0 :                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(0));
    5924                 :          0 :                 mask &= ~(1 << queue_id);
    5925                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
    5926         [ #  # ]:          0 :         } else if (queue_id < 64) {
    5927                 :          0 :                 mask = IXGBE_READ_REG(hw, IXGBE_EIMS_EX(1));
    5928                 :          0 :                 mask &= ~(1 << (queue_id - 32));
    5929                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
    5930                 :            :         }
    5931                 :            : 
    5932                 :          0 :         return 0;
    5933                 :            : }
    5934                 :            : 
    5935                 :            : static void
    5936                 :          0 : ixgbevf_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
    5937                 :            :                      uint8_t queue, uint8_t msix_vector)
    5938                 :            : {
    5939                 :            :         uint32_t tmp, idx;
    5940                 :            : 
    5941         [ #  # ]:          0 :         if (direction == -1) {
    5942                 :            :                 /* other causes */
    5943                 :          0 :                 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
    5944                 :          0 :                 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC);
    5945                 :          0 :                 tmp &= ~0xFF;
    5946                 :          0 :                 tmp |= msix_vector;
    5947                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, tmp);
    5948                 :            :         } else {
    5949                 :            :                 /* rx or tx cause */
    5950                 :          0 :                 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
    5951                 :          0 :                 idx = ((16 * (queue & 1)) + (8 * direction));
    5952                 :          0 :                 tmp = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1));
    5953                 :          0 :                 tmp &= ~(0xFF << idx);
    5954                 :          0 :                 tmp |= (msix_vector << idx);
    5955                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), tmp);
    5956                 :            :         }
    5957                 :          0 : }
    5958                 :            : 
    5959                 :            : /**
    5960                 :            :  * set the IVAR registers, mapping interrupt causes to vectors
    5961                 :            :  * @param hw
    5962                 :            :  *  pointer to ixgbe_hw struct
    5963                 :            :  * @direction
    5964                 :            :  *  0 for Rx, 1 for Tx, -1 for other causes
    5965                 :            :  * @queue
    5966                 :            :  *  queue to map the corresponding interrupt to
    5967                 :            :  * @msix_vector
    5968                 :            :  *  the vector to map to the corresponding queue
    5969                 :            :  */
    5970                 :            : static void
    5971                 :          0 : ixgbe_set_ivar_map(struct ixgbe_hw *hw, int8_t direction,
    5972                 :            :                    uint8_t queue, uint8_t msix_vector)
    5973                 :            : {
    5974                 :            :         uint32_t tmp, idx;
    5975                 :            : 
    5976                 :          0 :         msix_vector |= IXGBE_IVAR_ALLOC_VAL;
    5977         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
    5978         [ #  # ]:          0 :                 if (direction == -1)
    5979                 :            :                         direction = 0;
    5980                 :          0 :                 idx = (((direction * 64) + queue) >> 2) & 0x1F;
    5981                 :          0 :                 tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(idx));
    5982                 :          0 :                 tmp &= ~(0xFF << (8 * (queue & 0x3)));
    5983                 :          0 :                 tmp |= (msix_vector << (8 * (queue & 0x3)));
    5984                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_IVAR(idx), tmp);
    5985         [ #  # ]:          0 :         } else if ((hw->mac.type == ixgbe_mac_82599EB) ||
    5986                 :            :                         (hw->mac.type == ixgbe_mac_X540) ||
    5987                 :            :                         (hw->mac.type == ixgbe_mac_X550) ||
    5988                 :            :                         (hw->mac.type == ixgbe_mac_X550EM_a) ||
    5989                 :            :                         (hw->mac.type == ixgbe_mac_X550EM_x) ||
    5990                 :            :                         (hw->mac.type == ixgbe_mac_E610)) {
    5991         [ #  # ]:          0 :                 if (direction == -1) {
    5992                 :            :                         /* other causes */
    5993                 :          0 :                         idx = ((queue & 1) * 8);
    5994                 :          0 :                         tmp = IXGBE_READ_REG(hw, IXGBE_IVAR_MISC);
    5995                 :          0 :                         tmp &= ~(0xFF << idx);
    5996                 :          0 :                         tmp |= (msix_vector << idx);
    5997                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_IVAR_MISC, tmp);
    5998                 :            :                 } else {
    5999                 :            :                         /* rx or tx causes */
    6000                 :          0 :                         idx = ((16 * (queue & 1)) + (8 * direction));
    6001                 :          0 :                         tmp = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
    6002                 :          0 :                         tmp &= ~(0xFF << idx);
    6003                 :          0 :                         tmp |= (msix_vector << idx);
    6004                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), tmp);
    6005                 :            :                 }
    6006                 :            :         }
    6007                 :          0 : }
    6008                 :            : 
    6009                 :            : static void
    6010                 :          0 : ixgbevf_configure_msix(struct rte_eth_dev *dev)
    6011                 :            : {
    6012                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    6013                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    6014                 :          0 :         struct ixgbe_hw *hw =
    6015                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6016                 :            :         uint32_t q_idx;
    6017                 :            :         uint32_t vector_idx = IXGBE_MISC_VEC_ID;
    6018                 :            :         uint32_t base = IXGBE_MISC_VEC_ID;
    6019                 :            : 
    6020                 :            :         /* Configure VF other cause ivar */
    6021                 :            :         ixgbevf_set_ivar_map(hw, -1, 1, vector_idx);
    6022                 :            : 
    6023                 :            :         /* won't configure msix register if no mapping is done
    6024                 :            :          * between intr vector and event fd.
    6025                 :            :          */
    6026         [ #  # ]:          0 :         if (!rte_intr_dp_is_en(intr_handle))
    6027                 :            :                 return;
    6028                 :            : 
    6029         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle)) {
    6030                 :            :                 base = IXGBE_RX_VEC_START;
    6031                 :            :                 vector_idx = IXGBE_RX_VEC_START;
    6032                 :            :         }
    6033                 :            : 
    6034                 :            :         /* Configure all RX queues of VF */
    6035         [ #  # ]:          0 :         for (q_idx = 0; q_idx < dev->data->nb_rx_queues; q_idx++) {
    6036                 :            :                 /* Force all queue use vector 0,
    6037                 :            :                  * as IXGBE_VF_MAXMSIVECTOR = 1
    6038                 :            :                  */
    6039                 :          0 :                 ixgbevf_set_ivar_map(hw, 0, q_idx, vector_idx);
    6040                 :          0 :                 rte_intr_vec_list_index_set(intr_handle, q_idx,
    6041                 :            :                                                    vector_idx);
    6042                 :          0 :                 if (vector_idx < base + rte_intr_nb_efd_get(intr_handle)
    6043         [ #  # ]:          0 :                     - 1)
    6044                 :          0 :                         vector_idx++;
    6045                 :            :         }
    6046                 :            : 
    6047                 :            :         /* As RX queue setting above show, all queues use the vector 0.
    6048                 :            :          * Set only the ITR value of IXGBE_MISC_VEC_ID.
    6049                 :            :          */
    6050                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VTEITR(IXGBE_MISC_VEC_ID),
    6051                 :            :                         IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
    6052                 :            :                         | IXGBE_EITR_CNT_WDIS);
    6053                 :            : }
    6054                 :            : 
    6055                 :            : /**
    6056                 :            :  * Sets up the hardware to properly generate MSI-X interrupts
    6057                 :            :  * @hw
    6058                 :            :  *  board private structure
    6059                 :            :  */
    6060                 :            : static void
    6061                 :          0 : ixgbe_configure_msix(struct rte_eth_dev *dev)
    6062                 :            : {
    6063                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    6064                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    6065                 :          0 :         struct ixgbe_hw *hw =
    6066                 :          0 :                 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6067                 :            :         uint32_t queue_id, base = IXGBE_MISC_VEC_ID;
    6068                 :            :         uint32_t vec = IXGBE_MISC_VEC_ID;
    6069                 :            :         uint32_t mask;
    6070                 :            :         uint32_t gpie;
    6071                 :            : 
    6072                 :            :         /* won't configure msix register if no mapping is done
    6073                 :            :          * between intr vector and event fd
    6074                 :            :          * but if misx has been enabled already, need to configure
    6075                 :            :          * auto clean, auto mask and throttling.
    6076                 :            :          */
    6077                 :          0 :         gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
    6078         [ #  # ]:          0 :         if (!rte_intr_dp_is_en(intr_handle) &&
    6079         [ #  # ]:          0 :             !(gpie & (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT)))
    6080                 :            :                 return;
    6081                 :            : 
    6082         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle))
    6083                 :            :                 vec = base = IXGBE_RX_VEC_START;
    6084                 :            : 
    6085                 :            :         /* setup GPIE for MSI-x mode */
    6086                 :          0 :         gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
    6087                 :          0 :         gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
    6088                 :            :                 IXGBE_GPIE_OCD | IXGBE_GPIE_EIAME;
    6089                 :            :         /* auto clearing and auto setting corresponding bits in EIMS
    6090                 :            :          * when MSI-X interrupt is triggered
    6091                 :            :          */
    6092         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB) {
    6093                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
    6094                 :            :         } else {
    6095                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
    6096                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
    6097                 :            :         }
    6098                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
    6099                 :            : 
    6100                 :            :         /* Populate the IVAR table and set the ITR values to the
    6101                 :            :          * corresponding register.
    6102                 :            :          */
    6103         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
    6104         [ #  # ]:          0 :                 for (queue_id = 0; queue_id < dev->data->nb_rx_queues;
    6105                 :          0 :                         queue_id++) {
    6106                 :            :                         /* by default, 1:1 mapping */
    6107                 :          0 :                         ixgbe_set_ivar_map(hw, 0, queue_id, vec);
    6108                 :          0 :                         rte_intr_vec_list_index_set(intr_handle,
    6109                 :            :                                                            queue_id, vec);
    6110                 :          0 :                         if (vec < base + rte_intr_nb_efd_get(intr_handle)
    6111         [ #  # ]:          0 :                             - 1)
    6112                 :          0 :                                 vec++;
    6113                 :            :                 }
    6114                 :            : 
    6115      [ #  #  # ]:          0 :                 switch (hw->mac.type) {
    6116                 :          0 :                 case ixgbe_mac_82598EB:
    6117                 :          0 :                         ixgbe_set_ivar_map(hw, -1,
    6118                 :            :                                            IXGBE_IVAR_OTHER_CAUSES_INDEX,
    6119                 :            :                                            IXGBE_MISC_VEC_ID);
    6120                 :          0 :                         break;
    6121                 :          0 :                 case ixgbe_mac_82599EB:
    6122                 :            :                 case ixgbe_mac_X540:
    6123                 :            :                 case ixgbe_mac_X550:
    6124                 :            :                 case ixgbe_mac_X550EM_x:
    6125                 :            :                 case ixgbe_mac_E610:
    6126                 :          0 :                         ixgbe_set_ivar_map(hw, -1, 1, IXGBE_MISC_VEC_ID);
    6127                 :          0 :                         break;
    6128                 :            :                 default:
    6129                 :            :                         break;
    6130                 :            :                 }
    6131                 :            :         }
    6132                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EITR(IXGBE_MISC_VEC_ID),
    6133                 :            :                         IXGBE_EITR_INTERVAL_US(IXGBE_QUEUE_ITR_INTERVAL_DEFAULT)
    6134                 :            :                         | IXGBE_EITR_CNT_WDIS);
    6135                 :            : 
    6136                 :            :         /* set up to autoclear timer, and the vectors */
    6137                 :            :         mask = IXGBE_EIMS_ENABLE_MASK;
    6138                 :            :         mask &= ~(IXGBE_EIMS_OTHER |
    6139                 :            :                   IXGBE_EIMS_MAILBOX |
    6140                 :            :                   IXGBE_EIMS_LSC);
    6141                 :            : 
    6142                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EIAC, mask);
    6143                 :            : }
    6144                 :            : 
    6145                 :            : int
    6146                 :          0 : ixgbe_set_queue_rate_limit(struct rte_eth_dev *dev,
    6147                 :            :                            uint16_t queue_idx, uint32_t tx_rate)
    6148                 :            : {
    6149                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6150                 :            :         uint32_t rf_dec, rf_int;
    6151                 :            :         uint32_t bcnrc_val;
    6152                 :          0 :         uint16_t link_speed = dev->data->dev_link.link_speed;
    6153                 :            : 
    6154         [ #  # ]:          0 :         if (queue_idx >= hw->mac.max_tx_queues)
    6155                 :            :                 return -EINVAL;
    6156                 :            : 
    6157         [ #  # ]:          0 :         if (tx_rate != 0) {
    6158                 :            :                 /* Calculate the rate factor values to set */
    6159                 :          0 :                 rf_int = (uint32_t)link_speed / (uint32_t)tx_rate;
    6160                 :          0 :                 rf_dec = (uint32_t)link_speed % (uint32_t)tx_rate;
    6161                 :          0 :                 rf_dec = (rf_dec << IXGBE_RTTBCNRC_RF_INT_SHIFT) / tx_rate;
    6162                 :            : 
    6163                 :            :                 bcnrc_val = IXGBE_RTTBCNRC_RS_ENA;
    6164                 :          0 :                 bcnrc_val |= ((rf_int << IXGBE_RTTBCNRC_RF_INT_SHIFT) &
    6165                 :            :                                 IXGBE_RTTBCNRC_RF_INT_MASK_M);
    6166                 :          0 :                 bcnrc_val |= (rf_dec & IXGBE_RTTBCNRC_RF_DEC_MASK);
    6167                 :            :         } else {
    6168                 :            :                 bcnrc_val = 0;
    6169                 :            :         }
    6170                 :            : 
    6171                 :            :         /*
    6172                 :            :          * Set global transmit compensation time to the MMW_SIZE in RTTBCNRM
    6173                 :            :          * register. MMW_SIZE=0x014 if 9728-byte jumbo is supported, otherwise
    6174                 :            :          * set as 0x4.
    6175                 :            :          */
    6176         [ #  # ]:          0 :         if (dev->data->mtu + IXGBE_ETH_OVERHEAD >= IXGBE_MAX_JUMBO_FRAME_SIZE)
    6177                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, IXGBE_MMW_SIZE_JUMBO_FRAME);
    6178                 :            :         else
    6179                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRM, IXGBE_MMW_SIZE_DEFAULT);
    6180                 :            : 
    6181                 :            :         /* Set RTTBCNRC of queue X */
    6182                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_idx);
    6183                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
    6184                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    6185                 :            : 
    6186                 :          0 :         return 0;
    6187                 :            : }
    6188                 :            : 
    6189                 :            : static int
    6190                 :          0 : ixgbevf_add_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
    6191                 :            :                      __rte_unused uint32_t index,
    6192                 :            :                      __rte_unused uint32_t pool)
    6193                 :            : {
    6194                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6195                 :            :         int diag;
    6196                 :            : 
    6197                 :            :         /*
    6198                 :            :          * On a 82599 VF, adding again the same MAC addr is not an idempotent
    6199                 :            :          * operation. Trap this case to avoid exhausting the [very limited]
    6200                 :            :          * set of PF resources used to store VF MAC addresses.
    6201                 :            :          */
    6202         [ #  # ]:          0 :         if (memcmp(hw->mac.perm_addr, mac_addr,
    6203                 :            :                         sizeof(struct rte_ether_addr)) == 0)
    6204                 :            :                 return -1;
    6205                 :          0 :         diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
    6206         [ #  # ]:          0 :         if (diag != 0)
    6207                 :          0 :                 PMD_DRV_LOG(ERR, "Unable to add MAC address "
    6208                 :            :                             RTE_ETHER_ADDR_PRT_FMT " - diag=%d",
    6209                 :            :                             RTE_ETHER_ADDR_BYTES(mac_addr), diag);
    6210                 :            :         return diag;
    6211                 :            : }
    6212                 :            : 
    6213                 :            : static void
    6214                 :          0 : ixgbevf_remove_mac_addr(struct rte_eth_dev *dev, uint32_t index)
    6215                 :            : {
    6216                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6217                 :          0 :         struct rte_ether_addr *perm_addr =
    6218                 :            :                 (struct rte_ether_addr *)hw->mac.perm_addr;
    6219                 :            :         struct rte_ether_addr *mac_addr;
    6220                 :            :         uint32_t i;
    6221                 :            :         int diag;
    6222                 :            : 
    6223                 :            :         /*
    6224                 :            :          * The IXGBE_VF_SET_MACVLAN command of the ixgbe-pf driver does
    6225                 :            :          * not support the deletion of a given MAC address.
    6226                 :            :          * Instead, it imposes to delete all MAC addresses, then to add again
    6227                 :            :          * all MAC addresses with the exception of the one to be deleted.
    6228                 :            :          */
    6229                 :          0 :         (void) ixgbevf_set_uc_addr_vf(hw, 0, NULL);
    6230                 :            : 
    6231                 :            :         /*
    6232                 :            :          * Add again all MAC addresses, with the exception of the deleted one
    6233                 :            :          * and of the permanent MAC address.
    6234                 :            :          */
    6235                 :          0 :         for (i = 0, mac_addr = dev->data->mac_addrs;
    6236         [ #  # ]:          0 :              i < hw->mac.num_rar_entries; i++, mac_addr++) {
    6237                 :            :                 /* Skip the deleted MAC address */
    6238         [ #  # ]:          0 :                 if (i == index)
    6239                 :          0 :                         continue;
    6240                 :            :                 /* Skip NULL MAC addresses */
    6241         [ #  # ]:          0 :                 if (rte_is_zero_ether_addr(mac_addr))
    6242                 :          0 :                         continue;
    6243                 :            :                 /* Skip the permanent MAC address */
    6244         [ #  # ]:          0 :                 if (memcmp(perm_addr, mac_addr,
    6245                 :            :                                 sizeof(struct rte_ether_addr)) == 0)
    6246                 :          0 :                         continue;
    6247                 :          0 :                 diag = ixgbevf_set_uc_addr_vf(hw, 2, mac_addr->addr_bytes);
    6248         [ #  # ]:          0 :                 if (diag != 0)
    6249                 :          0 :                         PMD_DRV_LOG(ERR,
    6250                 :            :                                     "Adding again MAC address "
    6251                 :            :                                      RTE_ETHER_ADDR_PRT_FMT " failed "
    6252                 :            :                                     "diag=%d", RTE_ETHER_ADDR_BYTES(mac_addr),
    6253                 :            :                                     diag);
    6254                 :            :         }
    6255                 :          0 : }
    6256                 :            : 
    6257                 :            : static int
    6258                 :          0 : ixgbevf_set_default_mac_addr(struct rte_eth_dev *dev,
    6259                 :            :                         struct rte_ether_addr *addr)
    6260                 :            : {
    6261                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6262                 :            : 
    6263                 :          0 :         hw->mac.ops.set_rar(hw, 0, (void *)addr, 0, 0);
    6264                 :            : 
    6265                 :          0 :         return 0;
    6266                 :            : }
    6267                 :            : 
    6268                 :            : int
    6269                 :          0 : ixgbe_syn_filter_set(struct rte_eth_dev *dev,
    6270                 :            :                         struct rte_eth_syn_filter *filter,
    6271                 :            :                         bool add)
    6272                 :            : {
    6273                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6274                 :            :         struct ixgbe_filter_info *filter_info =
    6275                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    6276                 :            :         uint32_t syn_info;
    6277                 :            :         uint32_t synqf;
    6278                 :            : 
    6279         [ #  # ]:          0 :         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
    6280                 :            :                 return -EINVAL;
    6281                 :            : 
    6282                 :          0 :         syn_info = filter_info->syn_info;
    6283                 :            : 
    6284         [ #  # ]:          0 :         if (add) {
    6285         [ #  # ]:          0 :                 if (syn_info & IXGBE_SYN_FILTER_ENABLE)
    6286                 :            :                         return -EINVAL;
    6287                 :          0 :                 synqf = (uint32_t)(((filter->queue << IXGBE_SYN_FILTER_QUEUE_SHIFT) &
    6288                 :          0 :                         IXGBE_SYN_FILTER_QUEUE) | IXGBE_SYN_FILTER_ENABLE);
    6289                 :            : 
    6290         [ #  # ]:          0 :                 if (filter->hig_pri)
    6291                 :          0 :                         synqf |= IXGBE_SYN_FILTER_SYNQFP;
    6292                 :            :                 else
    6293                 :            :                         synqf &= ~IXGBE_SYN_FILTER_SYNQFP;
    6294                 :            :         } else {
    6295                 :          0 :                 synqf = IXGBE_READ_REG(hw, IXGBE_SYNQF);
    6296         [ #  # ]:          0 :                 if (!(syn_info & IXGBE_SYN_FILTER_ENABLE))
    6297                 :            :                         return -ENOENT;
    6298                 :          0 :                 synqf &= ~(IXGBE_SYN_FILTER_QUEUE | IXGBE_SYN_FILTER_ENABLE);
    6299                 :            :         }
    6300                 :            : 
    6301                 :          0 :         filter_info->syn_info = synqf;
    6302                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
    6303                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    6304                 :          0 :         return 0;
    6305                 :            : }
    6306                 :            : 
    6307                 :            : 
    6308                 :            : static inline enum ixgbe_5tuple_protocol
    6309                 :            : convert_protocol_type(uint8_t protocol_value)
    6310                 :            : {
    6311                 :          0 :         if (protocol_value == IPPROTO_TCP)
    6312                 :            :                 return IXGBE_FILTER_PROTOCOL_TCP;
    6313         [ #  # ]:          0 :         else if (protocol_value == IPPROTO_UDP)
    6314                 :            :                 return IXGBE_FILTER_PROTOCOL_UDP;
    6315         [ #  # ]:          0 :         else if (protocol_value == IPPROTO_SCTP)
    6316                 :            :                 return IXGBE_FILTER_PROTOCOL_SCTP;
    6317                 :            :         else
    6318                 :          0 :                 return IXGBE_FILTER_PROTOCOL_NONE;
    6319                 :            : }
    6320                 :            : 
    6321                 :            : /* inject a 5-tuple filter to HW */
    6322                 :            : static inline void
    6323                 :          0 : ixgbe_inject_5tuple_filter(struct rte_eth_dev *dev,
    6324                 :            :                            struct ixgbe_5tuple_filter *filter)
    6325                 :            : {
    6326                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6327                 :            :         int i;
    6328                 :            :         uint32_t ftqf, sdpqf;
    6329                 :            :         uint32_t l34timir = 0;
    6330                 :            :         uint8_t mask = 0xff;
    6331                 :            : 
    6332                 :          0 :         i = filter->index;
    6333                 :            : 
    6334                 :          0 :         sdpqf = (uint32_t)(filter->filter_info.dst_port <<
    6335                 :            :                                 IXGBE_SDPQF_DSTPORT_SHIFT);
    6336                 :          0 :         sdpqf = sdpqf | (filter->filter_info.src_port & IXGBE_SDPQF_SRCPORT);
    6337                 :            : 
    6338                 :          0 :         ftqf = (uint32_t)(filter->filter_info.proto &
    6339                 :            :                 IXGBE_FTQF_PROTOCOL_MASK);
    6340                 :          0 :         ftqf |= (uint32_t)((filter->filter_info.priority &
    6341                 :          0 :                 IXGBE_FTQF_PRIORITY_MASK) << IXGBE_FTQF_PRIORITY_SHIFT);
    6342         [ #  # ]:          0 :         if (filter->filter_info.src_ip_mask == 0) /* 0 means compare. */
    6343                 :            :                 mask &= IXGBE_FTQF_SOURCE_ADDR_MASK;
    6344         [ #  # ]:          0 :         if (filter->filter_info.dst_ip_mask == 0)
    6345                 :          0 :                 mask &= IXGBE_FTQF_DEST_ADDR_MASK;
    6346         [ #  # ]:          0 :         if (filter->filter_info.src_port_mask == 0)
    6347                 :          0 :                 mask &= IXGBE_FTQF_SOURCE_PORT_MASK;
    6348         [ #  # ]:          0 :         if (filter->filter_info.dst_port_mask == 0)
    6349                 :          0 :                 mask &= IXGBE_FTQF_DEST_PORT_MASK;
    6350         [ #  # ]:          0 :         if (filter->filter_info.proto_mask == 0)
    6351                 :          0 :                 mask &= IXGBE_FTQF_PROTOCOL_COMP_MASK;
    6352                 :          0 :         ftqf |= mask << IXGBE_FTQF_5TUPLE_MASK_SHIFT;
    6353                 :            :         ftqf |= IXGBE_FTQF_POOL_MASK_EN;
    6354                 :          0 :         ftqf |= IXGBE_FTQF_QUEUE_ENABLE;
    6355                 :            : 
    6356                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_DAQF(i), filter->filter_info.dst_ip);
    6357                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SAQF(i), filter->filter_info.src_ip);
    6358                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SDPQF(i), sdpqf);
    6359                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FTQF(i), ftqf);
    6360                 :            : 
    6361                 :            :         l34timir |= IXGBE_L34T_IMIR_RESERVE;
    6362                 :          0 :         l34timir |= (uint32_t)(filter->queue <<
    6363                 :            :                                 IXGBE_L34T_IMIR_QUEUE_SHIFT);
    6364                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(i), l34timir);
    6365                 :          0 : }
    6366                 :            : 
    6367                 :            : /*
    6368                 :            :  * add a 5tuple filter
    6369                 :            :  *
    6370                 :            :  * @param
    6371                 :            :  * dev: Pointer to struct rte_eth_dev.
    6372                 :            :  * index: the index the filter allocates.
    6373                 :            :  * filter: pointer to the filter that will be added.
    6374                 :            :  * rx_queue: the queue id the filter assigned to.
    6375                 :            :  *
    6376                 :            :  * @return
    6377                 :            :  *    - On success, zero.
    6378                 :            :  *    - On failure, a negative value.
    6379                 :            :  */
    6380                 :            : static int
    6381                 :          0 : ixgbe_add_5tuple_filter(struct rte_eth_dev *dev,
    6382                 :            :                         struct ixgbe_5tuple_filter *filter)
    6383                 :            : {
    6384                 :            :         struct ixgbe_filter_info *filter_info =
    6385                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    6386                 :            :         int i, idx, shift;
    6387                 :            : 
    6388                 :            :         /*
    6389                 :            :          * look for an unused 5tuple filter index,
    6390                 :            :          * and insert the filter to list.
    6391                 :            :          */
    6392         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_FTQF_FILTERS; i++) {
    6393                 :          0 :                 idx = i / (sizeof(uint32_t) * NBBY);
    6394                 :          0 :                 shift = i % (sizeof(uint32_t) * NBBY);
    6395         [ #  # ]:          0 :                 if (!(filter_info->fivetuple_mask[idx] & (1 << shift))) {
    6396                 :          0 :                         filter_info->fivetuple_mask[idx] |= 1 << shift;
    6397                 :          0 :                         filter->index = i;
    6398                 :          0 :                         TAILQ_INSERT_TAIL(&filter_info->fivetuple_list,
    6399                 :            :                                           filter,
    6400                 :            :                                           entries);
    6401                 :          0 :                         break;
    6402                 :            :                 }
    6403                 :            :         }
    6404         [ #  # ]:          0 :         if (i >= IXGBE_MAX_FTQF_FILTERS) {
    6405                 :          0 :                 PMD_DRV_LOG(ERR, "5tuple filters are full.");
    6406                 :          0 :                 return -ENOSYS;
    6407                 :            :         }
    6408                 :            : 
    6409                 :          0 :         ixgbe_inject_5tuple_filter(dev, filter);
    6410                 :            : 
    6411                 :          0 :         return 0;
    6412                 :            : }
    6413                 :            : 
    6414                 :            : /*
    6415                 :            :  * remove a 5tuple filter
    6416                 :            :  *
    6417                 :            :  * @param
    6418                 :            :  * dev: Pointer to struct rte_eth_dev.
    6419                 :            :  * filter: the pointer of the filter will be removed.
    6420                 :            :  */
    6421                 :            : static void
    6422                 :          0 : ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
    6423                 :            :                         struct ixgbe_5tuple_filter *filter)
    6424                 :            : {
    6425                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6426                 :            :         struct ixgbe_filter_info *filter_info =
    6427                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    6428                 :          0 :         uint16_t index = filter->index;
    6429                 :            : 
    6430                 :          0 :         filter_info->fivetuple_mask[index / (sizeof(uint32_t) * NBBY)] &=
    6431                 :          0 :                                 ~(1 << (index % (sizeof(uint32_t) * NBBY)));
    6432         [ #  # ]:          0 :         TAILQ_REMOVE(&filter_info->fivetuple_list, filter, entries);
    6433                 :          0 :         rte_free(filter);
    6434                 :            : 
    6435                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_DAQF(index), 0);
    6436                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SAQF(index), 0);
    6437                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SDPQF(index), 0);
    6438                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FTQF(index), 0);
    6439                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_L34T_IMIR(index), 0);
    6440                 :          0 : }
    6441                 :            : 
    6442                 :            : static int
    6443                 :          0 : ixgbevf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
    6444                 :            : {
    6445                 :            :         struct ixgbe_hw *hw;
    6446                 :          0 :         uint32_t max_frame = mtu + IXGBE_ETH_OVERHEAD;
    6447                 :          0 :         struct rte_eth_dev_data *dev_data = dev->data;
    6448                 :            : 
    6449                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6450                 :            : 
    6451         [ #  # ]:          0 :         if (mtu < RTE_ETHER_MIN_MTU || max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
    6452                 :            :                 return -EINVAL;
    6453                 :            : 
    6454                 :            :         /* If device is started, refuse mtu that requires the support of
    6455                 :            :          * scattered packets when this feature has not been enabled before.
    6456                 :            :          */
    6457         [ #  # ]:          0 :         if (dev_data->dev_started && !dev_data->scattered_rx &&
    6458                 :          0 :             (max_frame + 2 * RTE_VLAN_HLEN >
    6459         [ #  # ]:          0 :                         dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
    6460                 :          0 :                 PMD_INIT_LOG(ERR, "Stop port first.");
    6461                 :          0 :                 return -EINVAL;
    6462                 :            :         }
    6463                 :            : 
    6464                 :            :         /*
    6465                 :            :          * When supported by the underlying PF driver, use the IXGBE_VF_SET_MTU
    6466                 :            :          * request of the version 2.0 of the mailbox API.
    6467                 :            :          * For now, use the IXGBE_VF_SET_LPE request of the version 1.0
    6468                 :            :          * of the mailbox API.
    6469                 :            :          * This call to IXGBE_SET_LPE action won't work with ixgbe pf drivers
    6470                 :            :          * prior to 3.11.33 which contains the following change:
    6471                 :            :          * "ixgbe: Enable jumbo frames support w/ SR-IOV"
    6472                 :            :          */
    6473         [ #  # ]:          0 :         if (ixgbevf_rlpml_set_vf(hw, max_frame))
    6474                 :          0 :                 return -EINVAL;
    6475                 :            : 
    6476                 :            :         return 0;
    6477                 :            : }
    6478                 :            : 
    6479                 :            : static inline struct ixgbe_5tuple_filter *
    6480                 :            : ixgbe_5tuple_filter_lookup(struct ixgbe_5tuple_filter_list *filter_list,
    6481                 :            :                         struct ixgbe_5tuple_filter_info *key)
    6482                 :            : {
    6483                 :            :         struct ixgbe_5tuple_filter *it;
    6484                 :            : 
    6485         [ #  # ]:          0 :         TAILQ_FOREACH(it, filter_list, entries) {
    6486         [ #  # ]:          0 :                 if (memcmp(key, &it->filter_info,
    6487                 :            :                         sizeof(struct ixgbe_5tuple_filter_info)) == 0) {
    6488                 :            :                         return it;
    6489                 :            :                 }
    6490                 :            :         }
    6491                 :            :         return NULL;
    6492                 :            : }
    6493                 :            : 
    6494                 :            : /* translate elements in struct rte_eth_ntuple_filter to struct ixgbe_5tuple_filter_info*/
    6495                 :            : static inline int
    6496                 :          0 : ntuple_filter_to_5tuple(struct rte_eth_ntuple_filter *filter,
    6497                 :            :                         struct ixgbe_5tuple_filter_info *filter_info)
    6498                 :            : {
    6499         [ #  # ]:          0 :         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM ||
    6500   [ #  #  #  # ]:          0 :                 filter->priority > IXGBE_5TUPLE_MAX_PRI ||
    6501                 :            :                 filter->priority < IXGBE_5TUPLE_MIN_PRI)
    6502                 :            :                 return -EINVAL;
    6503                 :            : 
    6504      [ #  #  # ]:          0 :         switch (filter->dst_ip_mask) {
    6505                 :          0 :         case UINT32_MAX:
    6506                 :          0 :                 filter_info->dst_ip_mask = 0;
    6507                 :          0 :                 filter_info->dst_ip = filter->dst_ip;
    6508                 :          0 :                 break;
    6509                 :          0 :         case 0:
    6510                 :          0 :                 filter_info->dst_ip_mask = 1;
    6511                 :          0 :                 break;
    6512                 :          0 :         default:
    6513                 :          0 :                 PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
    6514                 :          0 :                 return -EINVAL;
    6515                 :            :         }
    6516                 :            : 
    6517      [ #  #  # ]:          0 :         switch (filter->src_ip_mask) {
    6518                 :          0 :         case UINT32_MAX:
    6519                 :          0 :                 filter_info->src_ip_mask = 0;
    6520                 :          0 :                 filter_info->src_ip = filter->src_ip;
    6521                 :          0 :                 break;
    6522                 :          0 :         case 0:
    6523                 :          0 :                 filter_info->src_ip_mask = 1;
    6524                 :          0 :                 break;
    6525                 :          0 :         default:
    6526                 :          0 :                 PMD_DRV_LOG(ERR, "invalid src_ip mask.");
    6527                 :          0 :                 return -EINVAL;
    6528                 :            :         }
    6529                 :            : 
    6530      [ #  #  # ]:          0 :         switch (filter->dst_port_mask) {
    6531                 :          0 :         case UINT16_MAX:
    6532                 :          0 :                 filter_info->dst_port_mask = 0;
    6533                 :          0 :                 filter_info->dst_port = filter->dst_port;
    6534                 :          0 :                 break;
    6535                 :          0 :         case 0:
    6536                 :          0 :                 filter_info->dst_port_mask = 1;
    6537                 :          0 :                 break;
    6538                 :          0 :         default:
    6539                 :          0 :                 PMD_DRV_LOG(ERR, "invalid dst_port mask.");
    6540                 :          0 :                 return -EINVAL;
    6541                 :            :         }
    6542                 :            : 
    6543      [ #  #  # ]:          0 :         switch (filter->src_port_mask) {
    6544                 :          0 :         case UINT16_MAX:
    6545                 :          0 :                 filter_info->src_port_mask = 0;
    6546                 :          0 :                 filter_info->src_port = filter->src_port;
    6547                 :          0 :                 break;
    6548                 :          0 :         case 0:
    6549                 :          0 :                 filter_info->src_port_mask = 1;
    6550                 :          0 :                 break;
    6551                 :          0 :         default:
    6552                 :          0 :                 PMD_DRV_LOG(ERR, "invalid src_port mask.");
    6553                 :          0 :                 return -EINVAL;
    6554                 :            :         }
    6555                 :            : 
    6556      [ #  #  # ]:          0 :         switch (filter->proto_mask) {
    6557                 :          0 :         case UINT8_MAX:
    6558                 :          0 :                 filter_info->proto_mask = 0;
    6559                 :          0 :                 filter_info->proto =
    6560         [ #  # ]:          0 :                         convert_protocol_type(filter->proto);
    6561                 :          0 :                 break;
    6562                 :          0 :         case 0:
    6563                 :          0 :                 filter_info->proto_mask = 1;
    6564                 :          0 :                 break;
    6565                 :          0 :         default:
    6566                 :          0 :                 PMD_DRV_LOG(ERR, "invalid protocol mask.");
    6567                 :          0 :                 return -EINVAL;
    6568                 :            :         }
    6569                 :            : 
    6570                 :          0 :         filter_info->priority = (uint8_t)filter->priority;
    6571                 :          0 :         return 0;
    6572                 :            : }
    6573                 :            : 
    6574                 :            : /*
    6575                 :            :  * add or delete a ntuple filter
    6576                 :            :  *
    6577                 :            :  * @param
    6578                 :            :  * dev: Pointer to struct rte_eth_dev.
    6579                 :            :  * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
    6580                 :            :  * add: if true, add filter, if false, remove filter
    6581                 :            :  *
    6582                 :            :  * @return
    6583                 :            :  *    - On success, zero.
    6584                 :            :  *    - On failure, a negative value.
    6585                 :            :  */
    6586                 :            : int
    6587                 :          0 : ixgbe_add_del_ntuple_filter(struct rte_eth_dev *dev,
    6588                 :            :                         struct rte_eth_ntuple_filter *ntuple_filter,
    6589                 :            :                         bool add)
    6590                 :            : {
    6591                 :            :         struct ixgbe_filter_info *filter_info =
    6592                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    6593                 :            :         struct ixgbe_5tuple_filter_info filter_5tuple;
    6594                 :            :         struct ixgbe_5tuple_filter *filter;
    6595                 :            :         int ret;
    6596                 :            : 
    6597         [ #  # ]:          0 :         if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
    6598                 :          0 :                 PMD_DRV_LOG(ERR, "only 5tuple is supported.");
    6599                 :          0 :                 return -EINVAL;
    6600                 :            :         }
    6601                 :            : 
    6602                 :            :         memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
    6603                 :          0 :         ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
    6604         [ #  # ]:          0 :         if (ret < 0)
    6605                 :            :                 return ret;
    6606                 :            : 
    6607                 :            :         filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
    6608                 :            :                                          &filter_5tuple);
    6609         [ #  # ]:          0 :         if (filter != NULL && add) {
    6610                 :          0 :                 PMD_DRV_LOG(ERR, "filter exists.");
    6611                 :          0 :                 return -EEXIST;
    6612                 :            :         }
    6613         [ #  # ]:          0 :         if (filter == NULL && !add) {
    6614                 :          0 :                 PMD_DRV_LOG(ERR, "filter doesn't exist.");
    6615                 :          0 :                 return -ENOENT;
    6616                 :            :         }
    6617                 :            : 
    6618         [ #  # ]:          0 :         if (add) {
    6619                 :          0 :                 filter = rte_zmalloc("ixgbe_5tuple_filter",
    6620                 :            :                                 sizeof(struct ixgbe_5tuple_filter), 0);
    6621         [ #  # ]:          0 :                 if (filter == NULL)
    6622                 :            :                         return -ENOMEM;
    6623         [ #  # ]:          0 :                 rte_memcpy(&filter->filter_info,
    6624                 :            :                                  &filter_5tuple,
    6625                 :            :                                  sizeof(struct ixgbe_5tuple_filter_info));
    6626                 :          0 :                 filter->queue = ntuple_filter->queue;
    6627                 :          0 :                 ret = ixgbe_add_5tuple_filter(dev, filter);
    6628         [ #  # ]:          0 :                 if (ret < 0) {
    6629                 :          0 :                         rte_free(filter);
    6630                 :          0 :                         return ret;
    6631                 :            :                 }
    6632                 :            :         } else
    6633                 :          0 :                 ixgbe_remove_5tuple_filter(dev, filter);
    6634                 :            : 
    6635                 :            :         return 0;
    6636                 :            : }
    6637                 :            : 
    6638                 :            : int
    6639                 :          0 : ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
    6640                 :            :                         struct rte_eth_ethertype_filter *filter,
    6641                 :            :                         bool add)
    6642                 :            : {
    6643                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6644                 :            :         struct ixgbe_filter_info *filter_info =
    6645                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    6646                 :            :         uint32_t etqf = 0;
    6647                 :            :         uint32_t etqs = 0;
    6648                 :            :         int ret;
    6649                 :            :         struct ixgbe_ethertype_filter ethertype_filter;
    6650                 :            : 
    6651         [ #  # ]:          0 :         if (filter->queue >= IXGBE_MAX_RX_QUEUE_NUM)
    6652                 :            :                 return -EINVAL;
    6653                 :            : 
    6654         [ #  # ]:          0 :         if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
    6655                 :            :                 filter->ether_type == RTE_ETHER_TYPE_IPV6) {
    6656                 :          0 :                 PMD_DRV_LOG(ERR, "unsupported ether_type(0x%04x) in"
    6657                 :            :                         " ethertype filter.", filter->ether_type);
    6658                 :          0 :                 return -EINVAL;
    6659                 :            :         }
    6660                 :            : 
    6661         [ #  # ]:          0 :         if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
    6662                 :          0 :                 PMD_DRV_LOG(ERR, "mac compare is unsupported.");
    6663                 :          0 :                 return -EINVAL;
    6664                 :            :         }
    6665         [ #  # ]:          0 :         if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
    6666                 :          0 :                 PMD_DRV_LOG(ERR, "drop option is unsupported.");
    6667                 :          0 :                 return -EINVAL;
    6668                 :            :         }
    6669                 :            : 
    6670                 :          0 :         ret = ixgbe_ethertype_filter_lookup(filter_info, filter->ether_type);
    6671         [ #  # ]:          0 :         if (ret >= 0 && add) {
    6672                 :          0 :                 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter exists.",
    6673                 :            :                             filter->ether_type);
    6674                 :          0 :                 return -EEXIST;
    6675                 :            :         }
    6676         [ #  # ]:          0 :         if (ret < 0 && !add) {
    6677                 :          0 :                 PMD_DRV_LOG(ERR, "ethertype (0x%04x) filter doesn't exist.",
    6678                 :            :                             filter->ether_type);
    6679                 :          0 :                 return -ENOENT;
    6680                 :            :         }
    6681                 :            : 
    6682         [ #  # ]:          0 :         if (add) {
    6683                 :            :                 etqf = IXGBE_ETQF_FILTER_EN;
    6684                 :          0 :                 etqf |= (uint32_t)filter->ether_type;
    6685                 :          0 :                 etqs |= (uint32_t)((filter->queue <<
    6686                 :            :                                     IXGBE_ETQS_RX_QUEUE_SHIFT) &
    6687                 :            :                                     IXGBE_ETQS_RX_QUEUE);
    6688                 :          0 :                 etqs |= IXGBE_ETQS_QUEUE_EN;
    6689                 :            : 
    6690                 :            :                 ethertype_filter.ethertype = filter->ether_type;
    6691                 :            :                 ethertype_filter.etqf = etqf;
    6692                 :            :                 ethertype_filter.etqs = etqs;
    6693                 :            :                 ethertype_filter.conf = FALSE;
    6694                 :            :                 ret = ixgbe_ethertype_filter_insert(filter_info,
    6695                 :            :                                                     &ethertype_filter);
    6696         [ #  # ]:          0 :                 if (ret < 0) {
    6697                 :          0 :                         PMD_DRV_LOG(ERR, "ethertype filters are full.");
    6698                 :          0 :                         return -ENOSPC;
    6699                 :            :                 }
    6700                 :            :         } else {
    6701         [ #  # ]:          0 :                 ret = ixgbe_ethertype_filter_remove(filter_info, (uint8_t)ret);
    6702                 :            :                 if (ret < 0)
    6703                 :            :                         return -ENOSYS;
    6704                 :            :         }
    6705                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETQF(ret), etqf);
    6706                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETQS(ret), etqs);
    6707                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    6708                 :            : 
    6709                 :          0 :         return 0;
    6710                 :            : }
    6711                 :            : 
    6712                 :            : static int
    6713                 :          0 : ixgbe_dev_flow_ops_get(__rte_unused struct rte_eth_dev *dev,
    6714                 :            :                        const struct rte_flow_ops **ops)
    6715                 :            : {
    6716                 :          0 :         *ops = &ixgbe_flow_ops;
    6717                 :          0 :         return 0;
    6718                 :            : }
    6719                 :            : 
    6720                 :            : static u8 *
    6721                 :          0 : ixgbe_dev_addr_list_itr(__rte_unused struct ixgbe_hw *hw,
    6722                 :            :                         u8 **mc_addr_ptr, u32 *vmdq)
    6723                 :            : {
    6724                 :            :         u8 *mc_addr;
    6725                 :            : 
    6726                 :          0 :         *vmdq = 0;
    6727                 :          0 :         mc_addr = *mc_addr_ptr;
    6728                 :          0 :         *mc_addr_ptr = (mc_addr + sizeof(struct rte_ether_addr));
    6729                 :          0 :         return mc_addr;
    6730                 :            : }
    6731                 :            : 
    6732                 :            : static int
    6733                 :          0 : ixgbe_dev_set_mc_addr_list(struct rte_eth_dev *dev,
    6734                 :            :                           struct rte_ether_addr *mc_addr_set,
    6735                 :            :                           uint32_t nb_mc_addr)
    6736                 :            : {
    6737                 :            :         struct ixgbe_hw *hw;
    6738                 :            :         u8 *mc_addr_list;
    6739                 :            : 
    6740                 :          0 :         hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6741                 :            :         mc_addr_list = (u8 *)mc_addr_set;
    6742                 :          0 :         return ixgbe_update_mc_addr_list(hw, mc_addr_list, nb_mc_addr,
    6743                 :            :                                          ixgbe_dev_addr_list_itr, TRUE);
    6744                 :            : }
    6745                 :            : 
    6746                 :            : static uint64_t
    6747                 :          0 : ixgbe_read_systime_cyclecounter(struct rte_eth_dev *dev)
    6748                 :            : {
    6749                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6750                 :            :         uint64_t systime_cycles;
    6751                 :            : 
    6752         [ #  # ]:          0 :         switch (hw->mac.type) {
    6753                 :          0 :         case ixgbe_mac_X550:
    6754                 :            :         case ixgbe_mac_X550EM_x:
    6755                 :            :         case ixgbe_mac_X550EM_a:
    6756                 :            :         case ixgbe_mac_E610:
    6757                 :            :                 /* SYSTIMEL stores ns and SYSTIMEH stores seconds. */
    6758                 :          0 :                 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
    6759                 :          0 :                 systime_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
    6760                 :          0 :                                 * NSEC_PER_SEC;
    6761                 :          0 :                 break;
    6762                 :          0 :         default:
    6763                 :          0 :                 systime_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIML);
    6764                 :          0 :                 systime_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_SYSTIMH)
    6765                 :          0 :                                 << 32;
    6766                 :            :         }
    6767                 :            : 
    6768                 :          0 :         return systime_cycles;
    6769                 :            : }
    6770                 :            : 
    6771                 :            : static uint64_t
    6772                 :          0 : ixgbe_read_rx_tstamp_cyclecounter(struct rte_eth_dev *dev)
    6773                 :            : {
    6774                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6775                 :            :         uint64_t rx_tstamp_cycles;
    6776                 :            : 
    6777         [ #  # ]:          0 :         switch (hw->mac.type) {
    6778                 :          0 :         case ixgbe_mac_X550:
    6779                 :            :         case ixgbe_mac_X550EM_x:
    6780                 :            :         case ixgbe_mac_X550EM_a:
    6781                 :            :         case ixgbe_mac_E610:
    6782                 :            :                 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
    6783                 :          0 :                 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
    6784                 :          0 :                 rx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
    6785                 :          0 :                                 * NSEC_PER_SEC;
    6786                 :          0 :                 break;
    6787                 :          0 :         default:
    6788                 :            :                 /* RXSTMPL stores ns and RXSTMPH stores seconds. */
    6789                 :          0 :                 rx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
    6790                 :          0 :                 rx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_RXSTMPH)
    6791                 :          0 :                                 << 32;
    6792                 :            :         }
    6793                 :            : 
    6794                 :          0 :         return rx_tstamp_cycles;
    6795                 :            : }
    6796                 :            : 
    6797                 :            : static uint64_t
    6798                 :          0 : ixgbe_read_tx_tstamp_cyclecounter(struct rte_eth_dev *dev)
    6799                 :            : {
    6800                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6801                 :            :         uint64_t tx_tstamp_cycles;
    6802                 :            : 
    6803         [ #  # ]:          0 :         switch (hw->mac.type) {
    6804                 :          0 :         case ixgbe_mac_X550:
    6805                 :            :         case ixgbe_mac_X550EM_x:
    6806                 :            :         case ixgbe_mac_X550EM_a:
    6807                 :            :         case ixgbe_mac_E610:
    6808                 :            :                 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
    6809                 :          0 :                 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
    6810                 :          0 :                 tx_tstamp_cycles += (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
    6811                 :          0 :                                 * NSEC_PER_SEC;
    6812                 :          0 :                 break;
    6813                 :          0 :         default:
    6814                 :            :                 /* TXSTMPL stores ns and TXSTMPH stores seconds. */
    6815                 :          0 :                 tx_tstamp_cycles = (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPL);
    6816                 :          0 :                 tx_tstamp_cycles |= (uint64_t)IXGBE_READ_REG(hw, IXGBE_TXSTMPH)
    6817                 :          0 :                                 << 32;
    6818                 :            :         }
    6819                 :            : 
    6820                 :          0 :         return tx_tstamp_cycles;
    6821                 :            : }
    6822                 :            : 
    6823                 :            : static void
    6824                 :          0 : ixgbe_start_timecounters(struct rte_eth_dev *dev)
    6825                 :            : {
    6826                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6827                 :            :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    6828                 :            :         struct rte_eth_link link;
    6829                 :            :         uint32_t incval = 0;
    6830                 :            :         uint32_t shift = 0;
    6831                 :            : 
    6832                 :            :         /* Get current link speed. */
    6833                 :            :         ixgbe_dev_link_update(dev, 1);
    6834                 :          0 :         rte_eth_linkstatus_get(dev, &link);
    6835                 :            : 
    6836      [ #  #  # ]:          0 :         switch (link.link_speed) {
    6837                 :            :         case RTE_ETH_SPEED_NUM_100M:
    6838                 :            :                 incval = IXGBE_INCVAL_100;
    6839                 :            :                 shift = IXGBE_INCVAL_SHIFT_100;
    6840                 :            :                 break;
    6841                 :          0 :         case RTE_ETH_SPEED_NUM_1G:
    6842                 :            :                 incval = IXGBE_INCVAL_1GB;
    6843                 :            :                 shift = IXGBE_INCVAL_SHIFT_1GB;
    6844                 :          0 :                 break;
    6845                 :          0 :         case RTE_ETH_SPEED_NUM_10G:
    6846                 :            :         default:
    6847                 :            :                 incval = IXGBE_INCVAL_10GB;
    6848                 :            :                 shift = IXGBE_INCVAL_SHIFT_10GB;
    6849                 :          0 :                 break;
    6850                 :            :         }
    6851                 :            : 
    6852   [ #  #  #  # ]:          0 :         switch (hw->mac.type) {
    6853                 :          0 :         case ixgbe_mac_X550:
    6854                 :            :         case ixgbe_mac_X550EM_x:
    6855                 :            :         case ixgbe_mac_X550EM_a:
    6856                 :            :         case ixgbe_mac_E610:
    6857                 :            :                 /* Independent of link speed. */
    6858                 :            :                 incval = 1;
    6859                 :            :                 /* Cycles read will be interpreted as ns. */
    6860                 :            :                 shift = 0;
    6861                 :            :                 /* Fall-through */
    6862                 :          0 :         case ixgbe_mac_X540:
    6863                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, incval);
    6864                 :            :                 break;
    6865                 :          0 :         case ixgbe_mac_82599EB:
    6866                 :          0 :                 incval >>= IXGBE_INCVAL_SHIFT_82599;
    6867                 :          0 :                 shift -= IXGBE_INCVAL_SHIFT_82599;
    6868                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TIMINCA,
    6869                 :            :                                 (1 << IXGBE_INCPER_SHIFT_82599) | incval);
    6870                 :            :                 break;
    6871                 :            :         default:
    6872                 :            :                 /* Not supported. */
    6873                 :          0 :                 return;
    6874                 :            :         }
    6875                 :            : 
    6876                 :          0 :         memset(&adapter->systime_tc, 0, sizeof(struct rte_timecounter));
    6877                 :          0 :         memset(&adapter->rx_tstamp_tc, 0, sizeof(struct rte_timecounter));
    6878                 :          0 :         memset(&adapter->tx_tstamp_tc, 0, sizeof(struct rte_timecounter));
    6879                 :            : 
    6880                 :          0 :         adapter->systime_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
    6881                 :          0 :         adapter->systime_tc.cc_shift = shift;
    6882                 :          0 :         adapter->systime_tc.nsec_mask = (1ULL << shift) - 1;
    6883                 :            : 
    6884                 :          0 :         adapter->rx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
    6885                 :          0 :         adapter->rx_tstamp_tc.cc_shift = shift;
    6886                 :          0 :         adapter->rx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
    6887                 :            : 
    6888                 :          0 :         adapter->tx_tstamp_tc.cc_mask = IXGBE_CYCLECOUNTER_MASK;
    6889                 :          0 :         adapter->tx_tstamp_tc.cc_shift = shift;
    6890                 :          0 :         adapter->tx_tstamp_tc.nsec_mask = (1ULL << shift) - 1;
    6891                 :            : }
    6892                 :            : 
    6893                 :            : static int
    6894                 :          0 : ixgbe_timesync_adjust_time(struct rte_eth_dev *dev, int64_t delta)
    6895                 :            : {
    6896                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    6897                 :            : 
    6898                 :          0 :         adapter->systime_tc.nsec += delta;
    6899                 :          0 :         adapter->rx_tstamp_tc.nsec += delta;
    6900                 :          0 :         adapter->tx_tstamp_tc.nsec += delta;
    6901                 :            : 
    6902                 :          0 :         return 0;
    6903                 :            : }
    6904                 :            : 
    6905                 :            : static int
    6906                 :          0 : ixgbe_timesync_write_time(struct rte_eth_dev *dev, const struct timespec *ts)
    6907                 :            : {
    6908                 :            :         uint64_t ns;
    6909                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    6910                 :            : 
    6911                 :            :         ns = rte_timespec_to_ns(ts);
    6912                 :            :         /* Set the timecounters to a new value. */
    6913                 :          0 :         adapter->systime_tc.nsec = ns;
    6914                 :          0 :         adapter->rx_tstamp_tc.nsec = ns;
    6915                 :          0 :         adapter->tx_tstamp_tc.nsec = ns;
    6916                 :            : 
    6917                 :          0 :         return 0;
    6918                 :            : }
    6919                 :            : 
    6920                 :            : static int
    6921                 :          0 : ixgbe_timesync_read_time(struct rte_eth_dev *dev, struct timespec *ts)
    6922                 :            : {
    6923                 :            :         uint64_t ns, systime_cycles;
    6924                 :          0 :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    6925                 :            : 
    6926                 :          0 :         systime_cycles = ixgbe_read_systime_cyclecounter(dev);
    6927                 :            :         ns = rte_timecounter_update(&adapter->systime_tc, systime_cycles);
    6928                 :          0 :         *ts = rte_ns_to_timespec(ns);
    6929                 :            : 
    6930                 :          0 :         return 0;
    6931                 :            : }
    6932                 :            : 
    6933                 :            : static int
    6934                 :          0 : ixgbe_timesync_enable(struct rte_eth_dev *dev)
    6935                 :            : {
    6936                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6937                 :            :         uint32_t tsync_ctl;
    6938                 :            :         uint32_t tsauxc;
    6939                 :            :         struct timespec ts;
    6940                 :            : 
    6941                 :            :         memset(&ts, 0, sizeof(struct timespec));
    6942                 :            : 
    6943                 :            :         /* get current system time */
    6944                 :          0 :         clock_gettime(CLOCK_REALTIME, &ts);
    6945                 :            : 
    6946                 :            :         /* Stop the timesync system time. */
    6947                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0x0);
    6948                 :            :         /* Reset the timesync system time value. */
    6949                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SYSTIML, 0x0);
    6950                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SYSTIMH, 0x0);
    6951                 :            : 
    6952                 :            :         /* Enable system time for platforms where it isn't on by default. */
    6953                 :          0 :         tsauxc = IXGBE_READ_REG(hw, IXGBE_TSAUXC);
    6954                 :          0 :         tsauxc &= ~IXGBE_TSAUXC_DISABLE_SYSTIME;
    6955                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TSAUXC, tsauxc);
    6956                 :            : 
    6957                 :          0 :         ixgbe_start_timecounters(dev);
    6958                 :            : 
    6959                 :            :         /* Enable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
    6960                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
    6961                 :            :                         (RTE_ETHER_TYPE_1588 |
    6962                 :            :                          IXGBE_ETQF_FILTER_EN |
    6963                 :            :                          IXGBE_ETQF_1588));
    6964                 :            : 
    6965                 :            :         /* Enable timestamping of received PTP packets. */
    6966                 :          0 :         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
    6967                 :          0 :         tsync_ctl |= IXGBE_TSYNCRXCTL_ENABLED;
    6968                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
    6969                 :            : 
    6970                 :            :         /* Enable timestamping of transmitted PTP packets. */
    6971                 :          0 :         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
    6972                 :          0 :         tsync_ctl |= IXGBE_TSYNCTXCTL_ENABLED;
    6973                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
    6974                 :            : 
    6975                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    6976                 :            : 
    6977                 :            :         /* ixgbe uses zero-based timestamping so only adjust timecounter */
    6978                 :            :         ixgbe_timesync_write_time(dev, &ts);
    6979                 :            : 
    6980                 :          0 :         return 0;
    6981                 :            : }
    6982                 :            : 
    6983                 :            : static int
    6984                 :          0 : ixgbe_timesync_disable(struct rte_eth_dev *dev)
    6985                 :            : {
    6986                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    6987                 :            :         uint32_t tsync_ctl;
    6988                 :            : 
    6989                 :            :         /* Disable timestamping of transmitted PTP packets. */
    6990                 :          0 :         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
    6991                 :          0 :         tsync_ctl &= ~IXGBE_TSYNCTXCTL_ENABLED;
    6992                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TSYNCTXCTL, tsync_ctl);
    6993                 :            : 
    6994                 :            :         /* Disable timestamping of received PTP packets. */
    6995                 :          0 :         tsync_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
    6996                 :          0 :         tsync_ctl &= ~IXGBE_TSYNCRXCTL_ENABLED;
    6997                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, tsync_ctl);
    6998                 :            : 
    6999                 :            :         /* Disable L2 filtering of IEEE1588/802.1AS Ethernet frame types. */
    7000                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), 0);
    7001                 :            : 
    7002                 :            :         /* Stop incrementing the System Time registers. */
    7003                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_TIMINCA, 0);
    7004                 :            : 
    7005                 :          0 :         return 0;
    7006                 :            : }
    7007                 :            : 
    7008                 :            : static int
    7009                 :          0 : ixgbe_timesync_read_rx_timestamp(struct rte_eth_dev *dev,
    7010                 :            :                                  struct timespec *timestamp,
    7011                 :            :                                  uint32_t flags __rte_unused)
    7012                 :            : {
    7013                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7014                 :            :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    7015                 :            :         uint32_t tsync_rxctl;
    7016                 :            :         uint64_t rx_tstamp_cycles;
    7017                 :            :         uint64_t ns;
    7018                 :            : 
    7019                 :          0 :         tsync_rxctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
    7020         [ #  # ]:          0 :         if ((tsync_rxctl & IXGBE_TSYNCRXCTL_VALID) == 0)
    7021                 :            :                 return -EINVAL;
    7022                 :            : 
    7023                 :          0 :         rx_tstamp_cycles = ixgbe_read_rx_tstamp_cyclecounter(dev);
    7024                 :            :         ns = rte_timecounter_update(&adapter->rx_tstamp_tc, rx_tstamp_cycles);
    7025                 :          0 :         *timestamp = rte_ns_to_timespec(ns);
    7026                 :            : 
    7027                 :          0 :         return  0;
    7028                 :            : }
    7029                 :            : 
    7030                 :            : static int
    7031                 :          0 : ixgbe_timesync_read_tx_timestamp(struct rte_eth_dev *dev,
    7032                 :            :                                  struct timespec *timestamp)
    7033                 :            : {
    7034                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7035                 :            :         struct ixgbe_adapter *adapter = dev->data->dev_private;
    7036                 :            :         uint32_t tsync_txctl;
    7037                 :            :         uint64_t tx_tstamp_cycles;
    7038                 :            :         uint64_t ns;
    7039                 :            : 
    7040                 :          0 :         tsync_txctl = IXGBE_READ_REG(hw, IXGBE_TSYNCTXCTL);
    7041         [ #  # ]:          0 :         if ((tsync_txctl & IXGBE_TSYNCTXCTL_VALID) == 0)
    7042                 :            :                 return -EINVAL;
    7043                 :            : 
    7044                 :          0 :         tx_tstamp_cycles = ixgbe_read_tx_tstamp_cyclecounter(dev);
    7045                 :            :         ns = rte_timecounter_update(&adapter->tx_tstamp_tc, tx_tstamp_cycles);
    7046                 :          0 :         *timestamp = rte_ns_to_timespec(ns);
    7047                 :            : 
    7048                 :          0 :         return 0;
    7049                 :            : }
    7050                 :            : 
    7051                 :            : static int
    7052                 :          0 : ixgbe_get_reg_length(struct rte_eth_dev *dev)
    7053                 :            : {
    7054                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7055                 :            :         int count = 0;
    7056                 :            :         int g_ind = 0;
    7057                 :            :         const struct reg_info *reg_group;
    7058                 :          0 :         const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
    7059         [ #  # ]:          0 :                                     ixgbe_regs_mac_82598EB : ixgbe_regs_others;
    7060                 :            : 
    7061         [ #  # ]:          0 :         while ((reg_group = reg_set[g_ind++]))
    7062                 :          0 :                 count += ixgbe_regs_group_count(reg_group);
    7063                 :            : 
    7064                 :          0 :         return count;
    7065                 :            : }
    7066                 :            : 
    7067                 :            : static int
    7068                 :            : ixgbevf_get_reg_length(struct rte_eth_dev *dev __rte_unused)
    7069                 :            : {
    7070                 :            :         int count = 0;
    7071                 :            :         int g_ind = 0;
    7072                 :            :         const struct reg_info *reg_group;
    7073                 :            : 
    7074   [ #  #  #  # ]:          0 :         while ((reg_group = ixgbevf_regs[g_ind++]))
    7075                 :          0 :                 count += ixgbe_regs_group_count(reg_group);
    7076                 :            : 
    7077                 :            :         return count;
    7078                 :            : }
    7079                 :            : 
    7080                 :            : static int
    7081                 :          0 : ixgbe_get_regs(struct rte_eth_dev *dev,
    7082                 :            :               struct rte_dev_reg_info *regs)
    7083                 :            : {
    7084                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7085                 :          0 :         uint32_t *data = regs->data;
    7086                 :            :         int g_ind = 0;
    7087                 :            :         int count = 0;
    7088                 :            :         const struct reg_info *reg_group;
    7089                 :          0 :         const struct reg_info **reg_set = (hw->mac.type == ixgbe_mac_82598EB) ?
    7090         [ #  # ]:          0 :                                     ixgbe_regs_mac_82598EB : ixgbe_regs_others;
    7091                 :            : 
    7092         [ #  # ]:          0 :         if (data == NULL) {
    7093                 :          0 :                 regs->length = ixgbe_get_reg_length(dev);
    7094                 :          0 :                 regs->width = sizeof(uint32_t);
    7095                 :          0 :                 return 0;
    7096                 :            :         }
    7097                 :            : 
    7098                 :            :         /* Support only full register dump */
    7099         [ #  # ]:          0 :         if ((regs->length == 0) ||
    7100         [ #  # ]:          0 :             (regs->length == (uint32_t)ixgbe_get_reg_length(dev))) {
    7101                 :          0 :                 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
    7102                 :          0 :                         hw->device_id;
    7103         [ #  # ]:          0 :                 while ((reg_group = reg_set[g_ind++]))
    7104                 :          0 :                         count += ixgbe_read_regs_group(dev, &data[count],
    7105                 :            :                                 reg_group);
    7106                 :            :                 return 0;
    7107                 :            :         }
    7108                 :            : 
    7109                 :            :         return -ENOTSUP;
    7110                 :            : }
    7111                 :            : 
    7112                 :            : static int
    7113                 :          0 : ixgbevf_get_regs(struct rte_eth_dev *dev,
    7114                 :            :                 struct rte_dev_reg_info *regs)
    7115                 :            : {
    7116                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7117                 :          0 :         uint32_t *data = regs->data;
    7118                 :            :         int g_ind = 0;
    7119                 :            :         int count = 0;
    7120                 :            :         const struct reg_info *reg_group;
    7121                 :            : 
    7122         [ #  # ]:          0 :         if (data == NULL) {
    7123                 :          0 :                 regs->length = ixgbevf_get_reg_length(dev);
    7124                 :          0 :                 regs->width = sizeof(uint32_t);
    7125                 :          0 :                 return 0;
    7126                 :            :         }
    7127                 :            : 
    7128                 :            :         /* Support only full register dump */
    7129         [ #  # ]:          0 :         if ((regs->length == 0) ||
    7130         [ #  # ]:          0 :             (regs->length == (uint32_t)ixgbevf_get_reg_length(dev))) {
    7131                 :          0 :                 regs->version = hw->mac.type << 24 | hw->revision_id << 16 |
    7132                 :          0 :                         hw->device_id;
    7133         [ #  # ]:          0 :                 while ((reg_group = ixgbevf_regs[g_ind++]))
    7134                 :          0 :                         count += ixgbe_read_regs_group(dev, &data[count],
    7135                 :            :                                                       reg_group);
    7136                 :            :                 return 0;
    7137                 :            :         }
    7138                 :            : 
    7139                 :            :         return -ENOTSUP;
    7140                 :            : }
    7141                 :            : 
    7142                 :            : static int
    7143                 :          0 : ixgbe_get_eeprom_length(struct rte_eth_dev *dev)
    7144                 :            : {
    7145                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7146                 :            : 
    7147                 :            :         /* Return unit is byte count */
    7148                 :          0 :         return hw->eeprom.word_size * 2;
    7149                 :            : }
    7150                 :            : 
    7151                 :            : static int
    7152                 :          0 : ixgbe_get_eeprom(struct rte_eth_dev *dev,
    7153                 :            :                 struct rte_dev_eeprom_info *in_eeprom)
    7154                 :            : {
    7155                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7156                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    7157                 :          0 :         uint16_t *data = in_eeprom->data;
    7158                 :            :         int first, length;
    7159                 :            : 
    7160                 :          0 :         first = in_eeprom->offset >> 1;
    7161                 :          0 :         length = in_eeprom->length >> 1;
    7162         [ #  # ]:          0 :         if ((first > hw->eeprom.word_size) ||
    7163         [ #  # ]:          0 :             ((first + length) > hw->eeprom.word_size))
    7164                 :            :                 return -EINVAL;
    7165                 :            : 
    7166                 :          0 :         in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
    7167                 :            : 
    7168                 :          0 :         return eeprom->ops.read_buffer(hw, first, length, data);
    7169                 :            : }
    7170                 :            : 
    7171                 :            : static int
    7172                 :          0 : ixgbe_set_eeprom(struct rte_eth_dev *dev,
    7173                 :            :                 struct rte_dev_eeprom_info *in_eeprom)
    7174                 :            : {
    7175                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7176                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    7177                 :          0 :         uint16_t *data = in_eeprom->data;
    7178                 :            :         int first, length;
    7179                 :            : 
    7180                 :          0 :         first = in_eeprom->offset >> 1;
    7181                 :          0 :         length = in_eeprom->length >> 1;
    7182         [ #  # ]:          0 :         if ((first > hw->eeprom.word_size) ||
    7183         [ #  # ]:          0 :             ((first + length) > hw->eeprom.word_size))
    7184                 :            :                 return -EINVAL;
    7185                 :            : 
    7186                 :          0 :         in_eeprom->magic = hw->vendor_id | (hw->device_id << 16);
    7187                 :            : 
    7188                 :          0 :         return eeprom->ops.write_buffer(hw,  first, length, data);
    7189                 :            : }
    7190                 :            : 
    7191                 :            : static int
    7192                 :          0 : ixgbe_get_module_info(struct rte_eth_dev *dev,
    7193                 :            :                       struct rte_eth_dev_module_info *modinfo)
    7194                 :            : {
    7195                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7196                 :            :         uint32_t status;
    7197                 :            :         uint8_t sff8472_rev, addr_mode;
    7198                 :            :         bool page_swap = false;
    7199                 :            : 
    7200                 :            :         /* Check whether we support SFF-8472 or not */
    7201                 :          0 :         status = hw->phy.ops.read_i2c_eeprom(hw,
    7202                 :            :                                              IXGBE_SFF_SFF_8472_COMP,
    7203                 :            :                                              &sff8472_rev);
    7204         [ #  # ]:          0 :         if (status != 0)
    7205                 :            :                 return -EIO;
    7206                 :            : 
    7207                 :            :         /* addressing mode is not supported */
    7208                 :          0 :         status = hw->phy.ops.read_i2c_eeprom(hw,
    7209                 :            :                                              IXGBE_SFF_SFF_8472_SWAP,
    7210                 :            :                                              &addr_mode);
    7211         [ #  # ]:          0 :         if (status != 0)
    7212                 :            :                 return -EIO;
    7213                 :            : 
    7214         [ #  # ]:          0 :         if (addr_mode & IXGBE_SFF_ADDRESSING_MODE) {
    7215                 :          0 :                 PMD_DRV_LOG(ERR,
    7216                 :            :                             "Address change required to access page 0xA2, "
    7217                 :            :                             "but not supported. Please report the module "
    7218                 :            :                             "type to the driver maintainers.");
    7219                 :            :                 page_swap = true;
    7220                 :            :         }
    7221                 :            : 
    7222   [ #  #  #  # ]:          0 :         if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) {
    7223                 :            :                 /* We have a SFP, but it does not support SFF-8472 */
    7224                 :          0 :                 modinfo->type = RTE_ETH_MODULE_SFF_8079;
    7225                 :          0 :                 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8079_LEN;
    7226                 :            :         } else {
    7227                 :            :                 /* We have a SFP which supports a revision of SFF-8472. */
    7228                 :          0 :                 modinfo->type = RTE_ETH_MODULE_SFF_8472;
    7229                 :          0 :                 modinfo->eeprom_len = RTE_ETH_MODULE_SFF_8472_LEN;
    7230                 :            :         }
    7231                 :            : 
    7232                 :            :         return 0;
    7233                 :            : }
    7234                 :            : 
    7235                 :            : static int
    7236                 :          0 : ixgbe_get_module_eeprom(struct rte_eth_dev *dev,
    7237                 :            :                         struct rte_dev_eeprom_info *info)
    7238                 :            : {
    7239                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7240                 :            :         uint32_t status = IXGBE_ERR_PHY_ADDR_INVALID;
    7241                 :          0 :         uint8_t databyte = 0xFF;
    7242                 :          0 :         uint8_t *data = info->data;
    7243                 :            :         uint32_t i = 0;
    7244                 :            : 
    7245         [ #  # ]:          0 :         for (i = info->offset; i < info->offset + info->length; i++) {
    7246         [ #  # ]:          0 :                 if (i < RTE_ETH_MODULE_SFF_8079_LEN)
    7247                 :          0 :                         status = hw->phy.ops.read_i2c_eeprom(hw, i, &databyte);
    7248                 :            :                 else
    7249                 :          0 :                         status = hw->phy.ops.read_i2c_sff8472(hw, i, &databyte);
    7250                 :            : 
    7251         [ #  # ]:          0 :                 if (status != 0)
    7252                 :            :                         return -EIO;
    7253                 :            : 
    7254                 :          0 :                 data[i - info->offset] = databyte;
    7255                 :            :         }
    7256                 :            : 
    7257                 :            :         return 0;
    7258                 :            : }
    7259                 :            : 
    7260                 :            : uint16_t
    7261                 :          0 : ixgbe_reta_size_get(enum ixgbe_mac_type mac_type) {
    7262   [ #  #  #  # ]:          0 :         switch (mac_type) {
    7263                 :            :         case ixgbe_mac_X550:
    7264                 :            :         case ixgbe_mac_X550EM_x:
    7265                 :            :         case ixgbe_mac_X550EM_a:
    7266                 :            :         case ixgbe_mac_E610:
    7267                 :            :                 return RTE_ETH_RSS_RETA_SIZE_512;
    7268                 :          0 :         case ixgbe_mac_X550_vf:
    7269                 :            :         case ixgbe_mac_X550EM_x_vf:
    7270                 :            :         case ixgbe_mac_X550EM_a_vf:
    7271                 :            :         case ixgbe_mac_E610_vf:
    7272                 :          0 :                 return RTE_ETH_RSS_RETA_SIZE_64;
    7273                 :          0 :         case ixgbe_mac_X540_vf:
    7274                 :            :         case ixgbe_mac_82599_vf:
    7275                 :          0 :                 return 0;
    7276                 :          0 :         default:
    7277                 :          0 :                 return RTE_ETH_RSS_RETA_SIZE_128;
    7278                 :            :         }
    7279                 :            : }
    7280                 :            : 
    7281                 :            : uint32_t
    7282                 :          0 : ixgbe_reta_reg_get(enum ixgbe_mac_type mac_type, uint16_t reta_idx) {
    7283      [ #  #  # ]:          0 :         switch (mac_type) {
    7284                 :          0 :         case ixgbe_mac_X550:
    7285                 :            :         case ixgbe_mac_X550EM_x:
    7286                 :            :         case ixgbe_mac_X550EM_a:
    7287                 :            :         case ixgbe_mac_E610:
    7288         [ #  # ]:          0 :                 if (reta_idx < RTE_ETH_RSS_RETA_SIZE_128)
    7289                 :          0 :                         return IXGBE_RETA(reta_idx >> 2);
    7290                 :            :                 else
    7291                 :          0 :                         return IXGBE_ERETA((reta_idx - RTE_ETH_RSS_RETA_SIZE_128) >> 2);
    7292                 :          0 :         case ixgbe_mac_X550_vf:
    7293                 :            :         case ixgbe_mac_X550EM_x_vf:
    7294                 :            :         case ixgbe_mac_X550EM_a_vf:
    7295                 :            :         case ixgbe_mac_E610_vf:
    7296                 :          0 :                 return IXGBE_VFRETA(reta_idx >> 2);
    7297                 :          0 :         default:
    7298                 :          0 :                 return IXGBE_RETA(reta_idx >> 2);
    7299                 :            :         }
    7300                 :            : }
    7301                 :            : 
    7302                 :            : uint32_t
    7303                 :          0 : ixgbe_mrqc_reg_get(enum ixgbe_mac_type mac_type) {
    7304         [ #  # ]:          0 :         switch (mac_type) {
    7305                 :            :         case ixgbe_mac_X550_vf:
    7306                 :            :         case ixgbe_mac_X550EM_x_vf:
    7307                 :            :         case ixgbe_mac_X550EM_a_vf:
    7308                 :            :                 return IXGBE_VFMRQC;
    7309                 :          0 :         default:
    7310                 :          0 :                 return IXGBE_MRQC;
    7311                 :            :         }
    7312                 :            : }
    7313                 :            : 
    7314                 :            : uint32_t
    7315                 :          0 : ixgbe_rssrk_reg_get(enum ixgbe_mac_type mac_type, uint8_t i) {
    7316         [ #  # ]:          0 :         switch (mac_type) {
    7317                 :          0 :         case ixgbe_mac_X550_vf:
    7318                 :            :         case ixgbe_mac_X550EM_x_vf:
    7319                 :            :         case ixgbe_mac_X550EM_a_vf:
    7320                 :          0 :                 return IXGBE_VFRSSRK(i);
    7321                 :          0 :         default:
    7322                 :          0 :                 return IXGBE_RSSRK(i);
    7323                 :            :         }
    7324                 :            : }
    7325                 :            : 
    7326                 :            : bool
    7327                 :          0 : ixgbe_rss_update_sp(enum ixgbe_mac_type mac_type) {
    7328         [ #  # ]:          0 :         switch (mac_type) {
    7329                 :            :         case ixgbe_mac_82599_vf:
    7330                 :            :         case ixgbe_mac_X540_vf:
    7331                 :            :                 return 0;
    7332                 :          0 :         default:
    7333                 :          0 :                 return 1;
    7334                 :            :         }
    7335                 :            : }
    7336                 :            : 
    7337                 :            : static int
    7338                 :          0 : ixgbe_dev_get_dcb_info(struct rte_eth_dev *dev,
    7339                 :            :                         struct rte_eth_dcb_info *dcb_info)
    7340                 :            : {
    7341                 :            :         struct ixgbe_dcb_config *dcb_config =
    7342                 :          0 :                         IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
    7343                 :            :         struct ixgbe_dcb_tc_config *tc;
    7344                 :            :         struct rte_eth_dcb_tc_queue_mapping *tc_queue;
    7345                 :            :         uint8_t nb_tcs;
    7346                 :            :         uint8_t i, j;
    7347                 :            : 
    7348         [ #  # ]:          0 :         if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_DCB_FLAG)
    7349                 :          0 :                 dcb_info->nb_tcs = dcb_config->num_tcs.pg_tcs;
    7350                 :            :         else
    7351                 :          0 :                 dcb_info->nb_tcs = 1;
    7352                 :            : 
    7353                 :            :         tc_queue = &dcb_info->tc_queue;
    7354                 :          0 :         nb_tcs = dcb_info->nb_tcs;
    7355                 :            : 
    7356         [ #  # ]:          0 :         if (dcb_config->vt_mode) { /* vt is enabled*/
    7357                 :            :                 struct rte_eth_vmdq_dcb_conf *vmdq_rx_conf =
    7358                 :            :                                 &dev->data->dev_conf.rx_adv_conf.vmdq_dcb_conf;
    7359         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
    7360                 :          0 :                         dcb_info->prio_tc[i] = vmdq_rx_conf->dcb_tc[i];
    7361         [ #  # ]:          0 :                 if (RTE_ETH_DEV_SRIOV(dev).active > 0) {
    7362         [ #  # ]:          0 :                         for (j = 0; j < nb_tcs; j++) {
    7363                 :          0 :                                 tc_queue->tc_rxq[0][j].base = j;
    7364                 :          0 :                                 tc_queue->tc_rxq[0][j].nb_queue = 1;
    7365                 :          0 :                                 tc_queue->tc_txq[0][j].base = j;
    7366                 :          0 :                                 tc_queue->tc_txq[0][j].nb_queue = 1;
    7367                 :            :                         }
    7368                 :            :                 } else {
    7369         [ #  # ]:          0 :                         for (i = 0; i < vmdq_rx_conf->nb_queue_pools; i++) {
    7370         [ #  # ]:          0 :                                 for (j = 0; j < nb_tcs; j++) {
    7371                 :          0 :                                         tc_queue->tc_rxq[i][j].base =
    7372                 :          0 :                                                 i * nb_tcs + j;
    7373                 :          0 :                                         tc_queue->tc_rxq[i][j].nb_queue = 1;
    7374                 :          0 :                                         tc_queue->tc_txq[i][j].base =
    7375                 :            :                                                 i * nb_tcs + j;
    7376                 :          0 :                                         tc_queue->tc_txq[i][j].nb_queue = 1;
    7377                 :            :                                 }
    7378                 :            :                         }
    7379                 :            :                 }
    7380                 :            :         } else { /* vt is disabled*/
    7381                 :            :                 struct rte_eth_dcb_rx_conf *rx_conf =
    7382                 :            :                                 &dev->data->dev_conf.rx_adv_conf.dcb_rx_conf;
    7383         [ #  # ]:          0 :                 for (i = 0; i < RTE_ETH_DCB_NUM_USER_PRIORITIES; i++)
    7384                 :          0 :                         dcb_info->prio_tc[i] = rx_conf->dcb_tc[i];
    7385         [ #  # ]:          0 :                 if (dcb_info->nb_tcs == RTE_ETH_4_TCS) {
    7386         [ #  # ]:          0 :                         for (i = 0; i < dcb_info->nb_tcs; i++) {
    7387                 :          0 :                                 dcb_info->tc_queue.tc_rxq[0][i].base = i * 32;
    7388                 :          0 :                                 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
    7389                 :            :                         }
    7390                 :          0 :                         dcb_info->tc_queue.tc_txq[0][0].base = 0;
    7391                 :          0 :                         dcb_info->tc_queue.tc_txq[0][1].base = 64;
    7392                 :          0 :                         dcb_info->tc_queue.tc_txq[0][2].base = 96;
    7393                 :          0 :                         dcb_info->tc_queue.tc_txq[0][3].base = 112;
    7394                 :          0 :                         dcb_info->tc_queue.tc_txq[0][0].nb_queue = 64;
    7395                 :          0 :                         dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
    7396                 :          0 :                         dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
    7397                 :          0 :                         dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
    7398         [ #  # ]:          0 :                 } else if (dcb_info->nb_tcs == RTE_ETH_8_TCS) {
    7399         [ #  # ]:          0 :                         for (i = 0; i < dcb_info->nb_tcs; i++) {
    7400                 :          0 :                                 dcb_info->tc_queue.tc_rxq[0][i].base = i * 16;
    7401                 :          0 :                                 dcb_info->tc_queue.tc_rxq[0][i].nb_queue = 16;
    7402                 :            :                         }
    7403                 :          0 :                         dcb_info->tc_queue.tc_txq[0][0].base = 0;
    7404                 :          0 :                         dcb_info->tc_queue.tc_txq[0][1].base = 32;
    7405                 :          0 :                         dcb_info->tc_queue.tc_txq[0][2].base = 64;
    7406                 :          0 :                         dcb_info->tc_queue.tc_txq[0][3].base = 80;
    7407                 :          0 :                         dcb_info->tc_queue.tc_txq[0][4].base = 96;
    7408                 :          0 :                         dcb_info->tc_queue.tc_txq[0][5].base = 104;
    7409                 :          0 :                         dcb_info->tc_queue.tc_txq[0][6].base = 112;
    7410                 :          0 :                         dcb_info->tc_queue.tc_txq[0][7].base = 120;
    7411                 :          0 :                         dcb_info->tc_queue.tc_txq[0][0].nb_queue = 32;
    7412                 :          0 :                         dcb_info->tc_queue.tc_txq[0][1].nb_queue = 32;
    7413                 :          0 :                         dcb_info->tc_queue.tc_txq[0][2].nb_queue = 16;
    7414                 :          0 :                         dcb_info->tc_queue.tc_txq[0][3].nb_queue = 16;
    7415                 :          0 :                         dcb_info->tc_queue.tc_txq[0][4].nb_queue = 8;
    7416                 :          0 :                         dcb_info->tc_queue.tc_txq[0][5].nb_queue = 8;
    7417                 :          0 :                         dcb_info->tc_queue.tc_txq[0][6].nb_queue = 8;
    7418                 :          0 :                         dcb_info->tc_queue.tc_txq[0][7].nb_queue = 8;
    7419                 :            :                 }
    7420                 :            :         }
    7421         [ #  # ]:          0 :         for (i = 0; i < dcb_info->nb_tcs; i++) {
    7422                 :          0 :                 tc = &dcb_config->tc_config[i];
    7423                 :          0 :                 dcb_info->tc_bws[i] = tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent;
    7424                 :            :         }
    7425                 :          0 :         return 0;
    7426                 :            : }
    7427                 :            : 
    7428                 :            : /* Update e-tag ether type */
    7429                 :            : static int
    7430                 :            : ixgbe_update_e_tag_eth_type(struct ixgbe_hw *hw,
    7431                 :            :                             uint16_t ether_type)
    7432                 :            : {
    7433                 :            :         uint32_t etag_etype;
    7434                 :            : 
    7435                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7436                 :          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7437                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7438                 :            :                 return -ENOTSUP;
    7439                 :            :         }
    7440                 :            : 
    7441                 :          0 :         etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
    7442                 :          0 :         etag_etype &= ~IXGBE_ETAG_ETYPE_MASK;
    7443                 :          0 :         etag_etype |= ether_type;
    7444                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
    7445                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    7446                 :            : 
    7447                 :          0 :         return 0;
    7448                 :            : }
    7449                 :            : 
    7450                 :            : /* Enable e-tag tunnel */
    7451                 :            : static int
    7452                 :            : ixgbe_e_tag_enable(struct ixgbe_hw *hw)
    7453                 :            : {
    7454                 :            :         uint32_t etag_etype;
    7455                 :            : 
    7456                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7457         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7458                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7459                 :            :                 return -ENOTSUP;
    7460                 :            :         }
    7461                 :            : 
    7462                 :          0 :         etag_etype = IXGBE_READ_REG(hw, IXGBE_ETAG_ETYPE);
    7463                 :          0 :         etag_etype |= IXGBE_ETAG_ETYPE_VALID;
    7464                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ETAG_ETYPE, etag_etype);
    7465                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    7466                 :            : 
    7467                 :          0 :         return 0;
    7468                 :            : }
    7469                 :            : 
    7470                 :            : static int
    7471                 :          0 : ixgbe_e_tag_filter_del(struct rte_eth_dev *dev,
    7472                 :            :                        struct ixgbe_l2_tunnel_conf *l2_tunnel)
    7473                 :            : {
    7474                 :            :         int ret = 0;
    7475                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7476                 :            :         uint32_t i, rar_entries;
    7477                 :            :         uint32_t rar_low, rar_high;
    7478                 :            : 
    7479                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7480         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7481                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7482                 :            :                 return -ENOTSUP;
    7483                 :            :         }
    7484                 :            : 
    7485                 :          0 :         rar_entries = ixgbe_get_num_rx_addrs(hw);
    7486                 :            : 
    7487         [ #  # ]:          0 :         for (i = 1; i < rar_entries; i++) {
    7488         [ #  # ]:          0 :                 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
    7489         [ #  # ]:          0 :                 rar_low  = IXGBE_READ_REG(hw, IXGBE_RAL(i));
    7490         [ #  # ]:          0 :                 if ((rar_high & IXGBE_RAH_AV) &&
    7491         [ #  # ]:          0 :                     (rar_high & IXGBE_RAH_ADTYPE) &&
    7492                 :          0 :                     ((rar_low & IXGBE_RAL_ETAG_FILTER_MASK) ==
    7493         [ #  # ]:          0 :                      l2_tunnel->tunnel_id)) {
    7494                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
    7495                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
    7496                 :            : 
    7497                 :          0 :                         ixgbe_clear_vmdq(hw, i, IXGBE_CLEAR_VMDQ_ALL);
    7498                 :            : 
    7499                 :          0 :                         return ret;
    7500                 :            :                 }
    7501                 :            :         }
    7502                 :            : 
    7503                 :            :         return ret;
    7504                 :            : }
    7505                 :            : 
    7506                 :            : static int
    7507                 :          0 : ixgbe_e_tag_filter_add(struct rte_eth_dev *dev,
    7508                 :            :                        struct ixgbe_l2_tunnel_conf *l2_tunnel)
    7509                 :            : {
    7510                 :            :         int ret = 0;
    7511                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7512                 :            :         uint32_t i, rar_entries;
    7513                 :            :         uint32_t rar_low, rar_high;
    7514                 :            : 
    7515                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7516         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7517                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7518                 :            :                 return -ENOTSUP;
    7519                 :            :         }
    7520                 :            : 
    7521                 :            :         /* One entry for one tunnel. Try to remove potential existing entry. */
    7522                 :          0 :         ixgbe_e_tag_filter_del(dev, l2_tunnel);
    7523                 :            : 
    7524                 :          0 :         rar_entries = ixgbe_get_num_rx_addrs(hw);
    7525                 :            : 
    7526         [ #  # ]:          0 :         for (i = 1; i < rar_entries; i++) {
    7527         [ #  # ]:          0 :                 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(i));
    7528         [ #  # ]:          0 :                 if (rar_high & IXGBE_RAH_AV) {
    7529                 :            :                         continue;
    7530                 :            :                 } else {
    7531                 :          0 :                         ixgbe_set_vmdq(hw, i, l2_tunnel->pool);
    7532                 :            :                         rar_high = IXGBE_RAH_AV | IXGBE_RAH_ADTYPE;
    7533                 :          0 :                         rar_low = l2_tunnel->tunnel_id;
    7534                 :            : 
    7535         [ #  # ]:          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RAL(i), rar_low);
    7536                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RAH(i), rar_high);
    7537                 :            : 
    7538                 :          0 :                         return ret;
    7539                 :            :                 }
    7540                 :            :         }
    7541                 :            : 
    7542                 :          0 :         PMD_INIT_LOG(NOTICE, "The table of E-tag forwarding rule is full."
    7543                 :            :                      " Please remove a rule before adding a new one.");
    7544                 :          0 :         return -EINVAL;
    7545                 :            : }
    7546                 :            : 
    7547                 :            : static inline struct ixgbe_l2_tn_filter *
    7548                 :            : ixgbe_l2_tn_filter_lookup(struct ixgbe_l2_tn_info *l2_tn_info,
    7549                 :            :                           struct ixgbe_l2_tn_key *key)
    7550                 :            : {
    7551                 :            :         int ret;
    7552                 :            : 
    7553                 :          0 :         ret = rte_hash_lookup(l2_tn_info->hash_handle, (const void *)key);
    7554         [ #  # ]:          0 :         if (ret < 0)
    7555                 :            :                 return NULL;
    7556                 :            : 
    7557                 :          0 :         return l2_tn_info->hash_map[ret];
    7558                 :            : }
    7559                 :            : 
    7560                 :            : static inline int
    7561                 :          0 : ixgbe_insert_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
    7562                 :            :                           struct ixgbe_l2_tn_filter *l2_tn_filter)
    7563                 :            : {
    7564                 :            :         int ret;
    7565                 :            : 
    7566                 :          0 :         ret = rte_hash_add_key(l2_tn_info->hash_handle,
    7567                 :          0 :                                &l2_tn_filter->key);
    7568                 :            : 
    7569         [ #  # ]:          0 :         if (ret < 0) {
    7570                 :          0 :                 PMD_DRV_LOG(ERR,
    7571                 :            :                             "Failed to insert L2 tunnel filter"
    7572                 :            :                             " to hash table %d!",
    7573                 :            :                             ret);
    7574                 :          0 :                 return ret;
    7575                 :            :         }
    7576                 :            : 
    7577                 :          0 :         l2_tn_info->hash_map[ret] = l2_tn_filter;
    7578                 :            : 
    7579                 :          0 :         TAILQ_INSERT_TAIL(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
    7580                 :            : 
    7581                 :          0 :         return 0;
    7582                 :            : }
    7583                 :            : 
    7584                 :            : static inline int
    7585                 :          0 : ixgbe_remove_l2_tn_filter(struct ixgbe_l2_tn_info *l2_tn_info,
    7586                 :            :                           struct ixgbe_l2_tn_key *key)
    7587                 :            : {
    7588                 :            :         int ret;
    7589                 :            :         struct ixgbe_l2_tn_filter *l2_tn_filter;
    7590                 :            : 
    7591                 :          0 :         ret = rte_hash_del_key(l2_tn_info->hash_handle, key);
    7592                 :            : 
    7593         [ #  # ]:          0 :         if (ret < 0) {
    7594                 :          0 :                 PMD_DRV_LOG(ERR,
    7595                 :            :                             "No such L2 tunnel filter to delete %d!",
    7596                 :            :                             ret);
    7597                 :          0 :                 return ret;
    7598                 :            :         }
    7599                 :            : 
    7600                 :          0 :         l2_tn_filter = l2_tn_info->hash_map[ret];
    7601                 :          0 :         l2_tn_info->hash_map[ret] = NULL;
    7602                 :            : 
    7603         [ #  # ]:          0 :         TAILQ_REMOVE(&l2_tn_info->l2_tn_list, l2_tn_filter, entries);
    7604                 :          0 :         rte_free(l2_tn_filter);
    7605                 :            : 
    7606                 :          0 :         return 0;
    7607                 :            : }
    7608                 :            : 
    7609                 :            : /* Add l2 tunnel filter */
    7610                 :            : int
    7611                 :          0 : ixgbe_dev_l2_tunnel_filter_add(struct rte_eth_dev *dev,
    7612                 :            :                                struct ixgbe_l2_tunnel_conf *l2_tunnel,
    7613                 :            :                                bool restore)
    7614                 :            : {
    7615                 :            :         int ret;
    7616                 :          0 :         struct ixgbe_l2_tn_info *l2_tn_info =
    7617                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
    7618                 :            :         struct ixgbe_l2_tn_key key;
    7619                 :            :         struct ixgbe_l2_tn_filter *node;
    7620                 :            : 
    7621         [ #  # ]:          0 :         if (!restore) {
    7622                 :          0 :                 key.l2_tn_type = l2_tunnel->l2_tunnel_type;
    7623                 :          0 :                 key.tn_id = l2_tunnel->tunnel_id;
    7624                 :            : 
    7625                 :            :                 node = ixgbe_l2_tn_filter_lookup(l2_tn_info, &key);
    7626                 :            : 
    7627         [ #  # ]:          0 :                 if (node) {
    7628                 :          0 :                         PMD_DRV_LOG(ERR,
    7629                 :            :                                     "The L2 tunnel filter already exists!");
    7630                 :          0 :                         return -EINVAL;
    7631                 :            :                 }
    7632                 :            : 
    7633                 :          0 :                 node = rte_zmalloc("ixgbe_l2_tn",
    7634                 :            :                                    sizeof(struct ixgbe_l2_tn_filter),
    7635                 :            :                                    0);
    7636         [ #  # ]:          0 :                 if (!node)
    7637                 :            :                         return -ENOMEM;
    7638                 :            : 
    7639         [ #  # ]:          0 :                 rte_memcpy(&node->key,
    7640                 :            :                                  &key,
    7641                 :            :                                  sizeof(struct ixgbe_l2_tn_key));
    7642                 :          0 :                 node->pool = l2_tunnel->pool;
    7643                 :          0 :                 ret = ixgbe_insert_l2_tn_filter(l2_tn_info, node);
    7644         [ #  # ]:          0 :                 if (ret < 0) {
    7645                 :          0 :                         rte_free(node);
    7646                 :          0 :                         return ret;
    7647                 :            :                 }
    7648                 :            :         }
    7649                 :            : 
    7650         [ #  # ]:          0 :         switch (l2_tunnel->l2_tunnel_type) {
    7651                 :          0 :         case RTE_ETH_L2_TUNNEL_TYPE_E_TAG:
    7652                 :          0 :                 ret = ixgbe_e_tag_filter_add(dev, l2_tunnel);
    7653                 :          0 :                 break;
    7654                 :          0 :         default:
    7655                 :          0 :                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
    7656                 :            :                 ret = -EINVAL;
    7657                 :          0 :                 break;
    7658                 :            :         }
    7659                 :            : 
    7660         [ #  # ]:          0 :         if ((!restore) && (ret < 0))
    7661                 :          0 :                 (void)ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
    7662                 :            : 
    7663                 :            :         return ret;
    7664                 :            : }
    7665                 :            : 
    7666                 :            : /* Delete l2 tunnel filter */
    7667                 :            : int
    7668                 :          0 : ixgbe_dev_l2_tunnel_filter_del(struct rte_eth_dev *dev,
    7669                 :            :                                struct ixgbe_l2_tunnel_conf *l2_tunnel)
    7670                 :            : {
    7671                 :            :         int ret;
    7672                 :          0 :         struct ixgbe_l2_tn_info *l2_tn_info =
    7673                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
    7674                 :            :         struct ixgbe_l2_tn_key key;
    7675                 :            : 
    7676                 :          0 :         key.l2_tn_type = l2_tunnel->l2_tunnel_type;
    7677                 :          0 :         key.tn_id = l2_tunnel->tunnel_id;
    7678                 :          0 :         ret = ixgbe_remove_l2_tn_filter(l2_tn_info, &key);
    7679         [ #  # ]:          0 :         if (ret < 0)
    7680                 :            :                 return ret;
    7681                 :            : 
    7682         [ #  # ]:          0 :         switch (l2_tunnel->l2_tunnel_type) {
    7683                 :          0 :         case RTE_ETH_L2_TUNNEL_TYPE_E_TAG:
    7684                 :          0 :                 ret = ixgbe_e_tag_filter_del(dev, l2_tunnel);
    7685                 :          0 :                 break;
    7686                 :          0 :         default:
    7687                 :          0 :                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
    7688                 :            :                 ret = -EINVAL;
    7689                 :          0 :                 break;
    7690                 :            :         }
    7691                 :            : 
    7692                 :            :         return ret;
    7693                 :            : }
    7694                 :            : 
    7695                 :            : static int
    7696                 :            : ixgbe_e_tag_forwarding_en_dis(struct rte_eth_dev *dev, bool en)
    7697                 :            : {
    7698                 :            :         int ret = 0;
    7699                 :            :         uint32_t ctrl;
    7700                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7701                 :            : 
    7702                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7703         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7704                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7705                 :            :                 return -ENOTSUP;
    7706                 :            :         }
    7707                 :            : 
    7708                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
    7709                 :          0 :         ctrl &= ~IXGBE_VT_CTL_POOLING_MODE_MASK;
    7710                 :            :         if (en)
    7711                 :          0 :                 ctrl |= IXGBE_VT_CTL_POOLING_MODE_ETAG;
    7712                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, ctrl);
    7713                 :            : 
    7714                 :          0 :         return ret;
    7715                 :            : }
    7716                 :            : 
    7717                 :            : static int
    7718                 :            : ixgbe_update_vxlan_port(struct ixgbe_hw *hw,
    7719                 :            :                         uint16_t port)
    7720                 :            : {
    7721                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, port);
    7722                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    7723                 :            : 
    7724                 :            :         return 0;
    7725                 :            : }
    7726                 :            : 
    7727                 :            : /* There's only one register for VxLAN UDP port.
    7728                 :            :  * So, we cannot add several ports. Will update it.
    7729                 :            :  */
    7730                 :            : static int
    7731                 :          0 : ixgbe_add_vxlan_port(struct ixgbe_hw *hw,
    7732                 :            :                      uint16_t port)
    7733                 :            : {
    7734         [ #  # ]:          0 :         if (port == 0) {
    7735                 :          0 :                 PMD_DRV_LOG(ERR, "Add VxLAN port 0 is not allowed.");
    7736                 :          0 :                 return -EINVAL;
    7737                 :            :         }
    7738                 :            : 
    7739                 :          0 :         return ixgbe_update_vxlan_port(hw, port);
    7740                 :            : }
    7741                 :            : 
    7742                 :            : /* We cannot delete the VxLAN port. For there's a register for VxLAN
    7743                 :            :  * UDP port, it must have a value.
    7744                 :            :  * So, will reset it to the original value 0.
    7745                 :            :  */
    7746                 :            : static int
    7747                 :          0 : ixgbe_del_vxlan_port(struct ixgbe_hw *hw,
    7748                 :            :                      uint16_t port)
    7749                 :            : {
    7750                 :            :         uint16_t cur_port;
    7751                 :            : 
    7752                 :          0 :         cur_port = (uint16_t)IXGBE_READ_REG(hw, IXGBE_VXLANCTRL);
    7753                 :            : 
    7754         [ #  # ]:          0 :         if (cur_port != port) {
    7755                 :          0 :                 PMD_DRV_LOG(ERR, "Port %u does not exist.", port);
    7756                 :          0 :                 return -EINVAL;
    7757                 :            :         }
    7758                 :            : 
    7759                 :          0 :         return ixgbe_update_vxlan_port(hw, 0);
    7760                 :            : }
    7761                 :            : 
    7762                 :            : /* Add UDP tunneling port */
    7763                 :            : static int
    7764                 :          0 : ixgbe_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
    7765                 :            :                               struct rte_eth_udp_tunnel *udp_tunnel)
    7766                 :            : {
    7767                 :            :         int ret = 0;
    7768                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7769                 :            : 
    7770                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7771         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7772                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7773                 :            :                 return -ENOTSUP;
    7774                 :            :         }
    7775                 :            : 
    7776         [ #  # ]:          0 :         if (udp_tunnel == NULL)
    7777                 :            :                 return -EINVAL;
    7778                 :            : 
    7779      [ #  #  # ]:          0 :         switch (udp_tunnel->prot_type) {
    7780                 :          0 :         case RTE_ETH_TUNNEL_TYPE_VXLAN:
    7781                 :          0 :                 ret = ixgbe_add_vxlan_port(hw, udp_tunnel->udp_port);
    7782                 :          0 :                 break;
    7783                 :            : 
    7784                 :          0 :         case RTE_ETH_TUNNEL_TYPE_GENEVE:
    7785                 :            :         case RTE_ETH_TUNNEL_TYPE_TEREDO:
    7786                 :          0 :                 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
    7787                 :            :                 ret = -EINVAL;
    7788                 :          0 :                 break;
    7789                 :            : 
    7790                 :          0 :         default:
    7791                 :          0 :                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
    7792                 :            :                 ret = -EINVAL;
    7793                 :          0 :                 break;
    7794                 :            :         }
    7795                 :            : 
    7796                 :            :         return ret;
    7797                 :            : }
    7798                 :            : 
    7799                 :            : /* Remove UDP tunneling port */
    7800                 :            : static int
    7801                 :          0 : ixgbe_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
    7802                 :            :                               struct rte_eth_udp_tunnel *udp_tunnel)
    7803                 :            : {
    7804                 :            :         int ret = 0;
    7805                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7806                 :            : 
    7807                 :          0 :         if (hw->mac.type != ixgbe_mac_X550 &&
    7808         [ #  # ]:          0 :             hw->mac.type != ixgbe_mac_X550EM_x &&
    7809                 :            :             hw->mac.type != ixgbe_mac_X550EM_a) {
    7810                 :            :                 return -ENOTSUP;
    7811                 :            :         }
    7812                 :            : 
    7813         [ #  # ]:          0 :         if (udp_tunnel == NULL)
    7814                 :            :                 return -EINVAL;
    7815                 :            : 
    7816      [ #  #  # ]:          0 :         switch (udp_tunnel->prot_type) {
    7817                 :          0 :         case RTE_ETH_TUNNEL_TYPE_VXLAN:
    7818                 :          0 :                 ret = ixgbe_del_vxlan_port(hw, udp_tunnel->udp_port);
    7819                 :          0 :                 break;
    7820                 :          0 :         case RTE_ETH_TUNNEL_TYPE_GENEVE:
    7821                 :            :         case RTE_ETH_TUNNEL_TYPE_TEREDO:
    7822                 :          0 :                 PMD_DRV_LOG(ERR, "Tunnel type is not supported now.");
    7823                 :            :                 ret = -EINVAL;
    7824                 :          0 :                 break;
    7825                 :          0 :         default:
    7826                 :          0 :                 PMD_DRV_LOG(ERR, "Invalid tunnel type");
    7827                 :            :                 ret = -EINVAL;
    7828                 :          0 :                 break;
    7829                 :            :         }
    7830                 :            : 
    7831                 :            :         return ret;
    7832                 :            : }
    7833                 :            : 
    7834                 :            : static int
    7835                 :          0 : ixgbevf_dev_promiscuous_enable(struct rte_eth_dev *dev)
    7836                 :            : {
    7837                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7838                 :            :         int ret;
    7839                 :            : 
    7840      [ #  #  # ]:          0 :         switch (hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_PROMISC)) {
    7841                 :            :         case IXGBE_SUCCESS:
    7842                 :            :                 ret = 0;
    7843                 :            :                 break;
    7844                 :          0 :         case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
    7845                 :            :                 ret = -ENOTSUP;
    7846                 :          0 :                 break;
    7847                 :          0 :         default:
    7848                 :            :                 ret = -EAGAIN;
    7849                 :          0 :                 break;
    7850                 :            :         }
    7851                 :            : 
    7852                 :          0 :         return ret;
    7853                 :            : }
    7854                 :            : 
    7855                 :            : static int
    7856                 :          0 : ixgbevf_dev_promiscuous_disable(struct rte_eth_dev *dev)
    7857                 :            : {
    7858                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7859                 :            :         int mode = IXGBEVF_XCAST_MODE_NONE;
    7860                 :            :         int ret;
    7861                 :            : 
    7862         [ #  # ]:          0 :         if (dev->data->all_multicast)
    7863                 :            :                 mode = IXGBEVF_XCAST_MODE_ALLMULTI;
    7864                 :            : 
    7865      [ #  #  # ]:          0 :         switch (hw->mac.ops.update_xcast_mode(hw, mode)) {
    7866                 :            :         case IXGBE_SUCCESS:
    7867                 :            :                 ret = 0;
    7868                 :            :                 break;
    7869                 :          0 :         case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
    7870                 :            :                 ret = -ENOTSUP;
    7871                 :          0 :                 break;
    7872                 :          0 :         default:
    7873                 :            :                 ret = -EAGAIN;
    7874                 :          0 :                 break;
    7875                 :            :         }
    7876                 :            : 
    7877                 :          0 :         return ret;
    7878                 :            : }
    7879                 :            : 
    7880                 :            : static int
    7881                 :          0 : ixgbevf_dev_allmulticast_enable(struct rte_eth_dev *dev)
    7882                 :            : {
    7883                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7884                 :            :         int ret;
    7885                 :            :         int mode = IXGBEVF_XCAST_MODE_ALLMULTI;
    7886                 :            : 
    7887         [ #  # ]:          0 :         if (dev->data->promiscuous)
    7888                 :            :                 return 0;
    7889                 :            : 
    7890      [ #  #  # ]:          0 :         switch (hw->mac.ops.update_xcast_mode(hw, mode)) {
    7891                 :            :         case IXGBE_SUCCESS:
    7892                 :            :                 ret = 0;
    7893                 :            :                 break;
    7894                 :          0 :         case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
    7895                 :            :                 ret = -ENOTSUP;
    7896                 :          0 :                 break;
    7897                 :          0 :         default:
    7898                 :            :                 ret = -EAGAIN;
    7899                 :          0 :                 break;
    7900                 :            :         }
    7901                 :            : 
    7902                 :            :         return ret;
    7903                 :            : }
    7904                 :            : 
    7905                 :            : static int
    7906                 :          0 : ixgbevf_dev_allmulticast_disable(struct rte_eth_dev *dev)
    7907                 :            : {
    7908                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7909                 :            :         int ret;
    7910                 :            : 
    7911         [ #  # ]:          0 :         if (dev->data->promiscuous)
    7912                 :            :                 return 0;
    7913                 :            : 
    7914      [ #  #  # ]:          0 :         switch (hw->mac.ops.update_xcast_mode(hw, IXGBEVF_XCAST_MODE_MULTI)) {
    7915                 :            :         case IXGBE_SUCCESS:
    7916                 :            :                 ret = 0;
    7917                 :            :                 break;
    7918                 :          0 :         case IXGBE_ERR_FEATURE_NOT_SUPPORTED:
    7919                 :            :                 ret = -ENOTSUP;
    7920                 :          0 :                 break;
    7921                 :          0 :         default:
    7922                 :            :                 ret = -EAGAIN;
    7923                 :          0 :                 break;
    7924                 :            :         }
    7925                 :            : 
    7926                 :            :         return ret;
    7927                 :            : }
    7928                 :            : 
    7929                 :          0 : static void ixgbevf_mbx_process(struct rte_eth_dev *dev)
    7930                 :            : {
    7931                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7932                 :          0 :         u32 in_msg = 0;
    7933                 :            : 
    7934                 :            :         /* peek the message first */
    7935                 :          0 :         in_msg = IXGBE_READ_REG(hw, IXGBE_VFMBMEM);
    7936                 :            : 
    7937                 :            :         /* PF reset VF event */
    7938         [ #  # ]:          0 :         if (in_msg == IXGBE_PF_CONTROL_MSG) {
    7939                 :            :                 /* dummy mbx read to ack pf */
    7940         [ #  # ]:          0 :                 if (ixgbe_read_mbx(hw, &in_msg, 1, 0))
    7941                 :          0 :                         return;
    7942                 :          0 :                 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_RESET,
    7943                 :            :                                              NULL);
    7944                 :            :         }
    7945                 :            : }
    7946                 :            : 
    7947                 :            : static int
    7948                 :          0 : ixgbevf_dev_interrupt_get_status(struct rte_eth_dev *dev)
    7949                 :            : {
    7950                 :            :         uint32_t eicr;
    7951                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    7952                 :            :         struct ixgbe_interrupt *intr =
    7953                 :            :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    7954                 :          0 :         ixgbevf_intr_disable(dev);
    7955                 :            : 
    7956                 :            :         /* read-on-clear nic registers here */
    7957                 :          0 :         eicr = IXGBE_READ_REG(hw, IXGBE_VTEICR);
    7958                 :          0 :         intr->flags = 0;
    7959                 :            : 
    7960                 :            :         /* only one misc vector supported - mailbox */
    7961                 :          0 :         eicr &= IXGBE_VTEICR_MASK;
    7962         [ #  # ]:          0 :         if (eicr == IXGBE_MISC_VEC_ID)
    7963                 :          0 :                 intr->flags |= IXGBE_FLAG_MAILBOX;
    7964                 :            : 
    7965                 :          0 :         return 0;
    7966                 :            : }
    7967                 :            : 
    7968                 :            : static int
    7969                 :          0 : ixgbevf_dev_interrupt_action(struct rte_eth_dev *dev)
    7970                 :            : {
    7971                 :            :         struct ixgbe_interrupt *intr =
    7972                 :          0 :                 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    7973                 :            : 
    7974         [ #  # ]:          0 :         if (intr->flags & IXGBE_FLAG_MAILBOX) {
    7975                 :          0 :                 ixgbevf_mbx_process(dev);
    7976                 :          0 :                 intr->flags &= ~IXGBE_FLAG_MAILBOX;
    7977                 :            :         }
    7978                 :            : 
    7979                 :          0 :         ixgbevf_intr_enable(dev);
    7980                 :            : 
    7981                 :          0 :         return 0;
    7982                 :            : }
    7983                 :            : 
    7984                 :            : static void
    7985                 :          0 : ixgbevf_dev_interrupt_handler(void *param)
    7986                 :            : {
    7987                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    7988                 :            : 
    7989                 :          0 :         ixgbevf_dev_interrupt_get_status(dev);
    7990                 :          0 :         ixgbevf_dev_interrupt_action(dev);
    7991                 :          0 : }
    7992                 :            : 
    7993                 :            : /**
    7994                 :            :  *  ixgbe_disable_sec_tx_path_generic - Stops the transmit data path
    7995                 :            :  *  @hw: pointer to hardware structure
    7996                 :            :  *
    7997                 :            :  *  Stops the transmit data path and waits for the HW to internally empty
    7998                 :            :  *  the Tx security block
    7999                 :            :  **/
    8000                 :          0 : int ixgbe_disable_sec_tx_path_generic(struct ixgbe_hw *hw)
    8001                 :            : {
    8002                 :            : #define IXGBE_MAX_SECTX_POLL 40
    8003                 :            : 
    8004                 :            :         int i;
    8005                 :            :         int sectxreg;
    8006                 :            : 
    8007                 :          0 :         sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
    8008                 :          0 :         sectxreg |= IXGBE_SECTXCTRL_TX_DIS;
    8009                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
    8010         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_SECTX_POLL; i++) {
    8011                 :          0 :                 sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXSTAT);
    8012         [ #  # ]:          0 :                 if (sectxreg & IXGBE_SECTXSTAT_SECTX_RDY)
    8013                 :            :                         break;
    8014                 :            :                 /* Use interrupt-safe sleep just in case */
    8015                 :          0 :                 usec_delay(1000);
    8016                 :            :         }
    8017                 :            : 
    8018                 :            :         /* For informational purposes only */
    8019         [ #  # ]:          0 :         if (i >= IXGBE_MAX_SECTX_POLL)
    8020                 :          0 :                 PMD_DRV_LOG(DEBUG, "Tx unit being enabled before security "
    8021                 :            :                          "path fully disabled.  Continuing with init.");
    8022                 :            : 
    8023                 :          0 :         return IXGBE_SUCCESS;
    8024                 :            : }
    8025                 :            : 
    8026                 :            : /**
    8027                 :            :  *  ixgbe_enable_sec_tx_path_generic - Enables the transmit data path
    8028                 :            :  *  @hw: pointer to hardware structure
    8029                 :            :  *
    8030                 :            :  *  Enables the transmit data path.
    8031                 :            :  **/
    8032                 :          0 : int ixgbe_enable_sec_tx_path_generic(struct ixgbe_hw *hw)
    8033                 :            : {
    8034                 :            :         uint32_t sectxreg;
    8035                 :            : 
    8036                 :          0 :         sectxreg = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
    8037                 :          0 :         sectxreg &= ~IXGBE_SECTXCTRL_TX_DIS;
    8038                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, sectxreg);
    8039                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    8040                 :            : 
    8041                 :          0 :         return IXGBE_SUCCESS;
    8042                 :            : }
    8043                 :            : 
    8044                 :            : /* restore n-tuple filter */
    8045                 :            : static inline void
    8046                 :            : ixgbe_ntuple_filter_restore(struct rte_eth_dev *dev)
    8047                 :            : {
    8048                 :            :         struct ixgbe_filter_info *filter_info =
    8049                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8050                 :            :         struct ixgbe_5tuple_filter *node;
    8051                 :            : 
    8052         [ #  # ]:          0 :         TAILQ_FOREACH(node, &filter_info->fivetuple_list, entries) {
    8053                 :          0 :                 ixgbe_inject_5tuple_filter(dev, node);
    8054                 :            :         }
    8055                 :            : }
    8056                 :            : 
    8057                 :            : /* restore ethernet type filter */
    8058                 :            : static inline void
    8059                 :          0 : ixgbe_ethertype_filter_restore(struct rte_eth_dev *dev)
    8060                 :            : {
    8061                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8062                 :            :         struct ixgbe_filter_info *filter_info =
    8063                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8064                 :            :         int i;
    8065                 :            : 
    8066         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
    8067         [ #  # ]:          0 :                 if (filter_info->ethertype_mask & (1 << i)) {
    8068                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
    8069                 :            :                                         filter_info->ethertype_filters[i].etqf);
    8070                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_ETQS(i),
    8071                 :            :                                         filter_info->ethertype_filters[i].etqs);
    8072                 :          0 :                         IXGBE_WRITE_FLUSH(hw);
    8073                 :            :                 }
    8074                 :            :         }
    8075                 :          0 : }
    8076                 :            : 
    8077                 :            : /* restore SYN filter */
    8078                 :            : static inline void
    8079                 :            : ixgbe_syn_filter_restore(struct rte_eth_dev *dev)
    8080                 :            : {
    8081                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8082                 :            :         struct ixgbe_filter_info *filter_info =
    8083                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8084                 :            :         uint32_t synqf;
    8085                 :            : 
    8086                 :          0 :         synqf = filter_info->syn_info;
    8087                 :            : 
    8088         [ #  # ]:          0 :         if (synqf & IXGBE_SYN_FILTER_ENABLE) {
    8089                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, synqf);
    8090                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    8091                 :            :         }
    8092                 :            : }
    8093                 :            : 
    8094                 :            : /* restore L2 tunnel filter */
    8095                 :            : static inline void
    8096                 :          0 : ixgbe_l2_tn_filter_restore(struct rte_eth_dev *dev)
    8097                 :            : {
    8098                 :            :         struct ixgbe_l2_tn_info *l2_tn_info =
    8099                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
    8100                 :            :         struct ixgbe_l2_tn_filter *node;
    8101                 :            :         struct ixgbe_l2_tunnel_conf l2_tn_conf;
    8102                 :            : 
    8103         [ #  # ]:          0 :         TAILQ_FOREACH(node, &l2_tn_info->l2_tn_list, entries) {
    8104                 :          0 :                 l2_tn_conf.l2_tunnel_type = node->key.l2_tn_type;
    8105                 :          0 :                 l2_tn_conf.tunnel_id      = node->key.tn_id;
    8106                 :          0 :                 l2_tn_conf.pool           = node->pool;
    8107                 :          0 :                 (void)ixgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_conf, TRUE);
    8108                 :            :         }
    8109                 :          0 : }
    8110                 :            : 
    8111                 :            : /* restore rss filter */
    8112                 :            : static inline void
    8113                 :            : ixgbe_rss_filter_restore(struct rte_eth_dev *dev)
    8114                 :            : {
    8115                 :            :         struct ixgbe_filter_info *filter_info =
    8116                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8117                 :            : 
    8118         [ #  # ]:          0 :         if (filter_info->rss_info.conf.queue_num)
    8119                 :          0 :                 ixgbe_config_rss_filter(dev,
    8120                 :            :                         &filter_info->rss_info, TRUE);
    8121                 :            : }
    8122                 :            : 
    8123                 :            : static int
    8124                 :          0 : ixgbe_filter_restore(struct rte_eth_dev *dev)
    8125                 :            : {
    8126                 :            :         ixgbe_ntuple_filter_restore(dev);
    8127                 :          0 :         ixgbe_ethertype_filter_restore(dev);
    8128                 :            :         ixgbe_syn_filter_restore(dev);
    8129                 :          0 :         ixgbe_fdir_filter_restore(dev);
    8130                 :          0 :         ixgbe_l2_tn_filter_restore(dev);
    8131                 :            :         ixgbe_rss_filter_restore(dev);
    8132                 :            : 
    8133                 :          0 :         return 0;
    8134                 :            : }
    8135                 :            : 
    8136                 :            : static void
    8137                 :          0 : ixgbe_l2_tunnel_conf(struct rte_eth_dev *dev)
    8138                 :            : {
    8139                 :            :         struct ixgbe_l2_tn_info *l2_tn_info =
    8140                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
    8141                 :            :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8142                 :            : 
    8143         [ #  # ]:          0 :         if (l2_tn_info->e_tag_en)
    8144                 :            :                 (void)ixgbe_e_tag_enable(hw);
    8145                 :            : 
    8146         [ #  # ]:          0 :         if (l2_tn_info->e_tag_fwd_en)
    8147                 :            :                 (void)ixgbe_e_tag_forwarding_en_dis(dev, 1);
    8148                 :            : 
    8149         [ #  # ]:          0 :         (void)ixgbe_update_e_tag_eth_type(hw, l2_tn_info->e_tag_ether_type);
    8150                 :          0 : }
    8151                 :            : 
    8152                 :            : /* remove all the n-tuple filters */
    8153                 :            : void
    8154                 :          0 : ixgbe_clear_all_ntuple_filter(struct rte_eth_dev *dev)
    8155                 :            : {
    8156                 :            :         struct ixgbe_filter_info *filter_info =
    8157                 :          0 :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8158                 :            :         struct ixgbe_5tuple_filter *p_5tuple;
    8159                 :            : 
    8160         [ #  # ]:          0 :         while ((p_5tuple = TAILQ_FIRST(&filter_info->fivetuple_list)))
    8161                 :          0 :                 ixgbe_remove_5tuple_filter(dev, p_5tuple);
    8162                 :          0 : }
    8163                 :            : 
    8164                 :            : /* remove all the ether type filters */
    8165                 :            : void
    8166                 :          0 : ixgbe_clear_all_ethertype_filter(struct rte_eth_dev *dev)
    8167                 :            : {
    8168                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8169                 :            :         struct ixgbe_filter_info *filter_info =
    8170                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8171                 :            :         int i;
    8172                 :            : 
    8173         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_ETQF_FILTERS; i++) {
    8174         [ #  # ]:          0 :                 if (filter_info->ethertype_mask & (1 << i) &&
    8175         [ #  # ]:          0 :                     !filter_info->ethertype_filters[i].conf) {
    8176                 :            :                         (void)ixgbe_ethertype_filter_remove(filter_info,
    8177                 :            :                                                             (uint8_t)i);
    8178                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_ETQF(i), 0);
    8179                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_ETQS(i), 0);
    8180                 :          0 :                         IXGBE_WRITE_FLUSH(hw);
    8181                 :            :                 }
    8182                 :            :         }
    8183                 :          0 : }
    8184                 :            : 
    8185                 :            : /* remove the SYN filter */
    8186                 :            : void
    8187                 :          0 : ixgbe_clear_syn_filter(struct rte_eth_dev *dev)
    8188                 :            : {
    8189                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8190                 :            :         struct ixgbe_filter_info *filter_info =
    8191                 :            :                 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
    8192                 :            : 
    8193         [ #  # ]:          0 :         if (filter_info->syn_info & IXGBE_SYN_FILTER_ENABLE) {
    8194                 :          0 :                 filter_info->syn_info = 0;
    8195                 :            : 
    8196                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_SYNQF, 0);
    8197                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    8198                 :            :         }
    8199                 :          0 : }
    8200                 :            : 
    8201                 :            : /* remove all the L2 tunnel filters */
    8202                 :            : int
    8203                 :          0 : ixgbe_clear_all_l2_tn_filter(struct rte_eth_dev *dev)
    8204                 :            : {
    8205                 :            :         struct ixgbe_l2_tn_info *l2_tn_info =
    8206                 :          0 :                 IXGBE_DEV_PRIVATE_TO_L2_TN_INFO(dev->data->dev_private);
    8207                 :            :         struct ixgbe_l2_tn_filter *l2_tn_filter;
    8208                 :            :         struct ixgbe_l2_tunnel_conf l2_tn_conf;
    8209                 :            :         int ret = 0;
    8210                 :            : 
    8211         [ #  # ]:          0 :         while ((l2_tn_filter = TAILQ_FIRST(&l2_tn_info->l2_tn_list))) {
    8212                 :          0 :                 l2_tn_conf.l2_tunnel_type = l2_tn_filter->key.l2_tn_type;
    8213                 :          0 :                 l2_tn_conf.tunnel_id      = l2_tn_filter->key.tn_id;
    8214                 :          0 :                 l2_tn_conf.pool           = l2_tn_filter->pool;
    8215                 :          0 :                 ret = ixgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_conf);
    8216         [ #  # ]:          0 :                 if (ret < 0)
    8217                 :          0 :                         return ret;
    8218                 :            :         }
    8219                 :            : 
    8220                 :            :         return 0;
    8221                 :            : }
    8222                 :            : 
    8223                 :            : void
    8224                 :          0 : ixgbe_dev_macsec_setting_save(struct rte_eth_dev *dev,
    8225                 :            :                                 struct ixgbe_macsec_setting *macsec_setting)
    8226                 :            : {
    8227                 :            :         struct ixgbe_macsec_setting *macsec =
    8228                 :          0 :                 IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
    8229                 :            : 
    8230                 :          0 :         macsec->offload_en = macsec_setting->offload_en;
    8231                 :          0 :         macsec->encrypt_en = macsec_setting->encrypt_en;
    8232                 :          0 :         macsec->replayprotect_en = macsec_setting->replayprotect_en;
    8233                 :          0 : }
    8234                 :            : 
    8235                 :            : void
    8236                 :          0 : ixgbe_dev_macsec_setting_reset(struct rte_eth_dev *dev)
    8237                 :            : {
    8238                 :            :         struct ixgbe_macsec_setting *macsec =
    8239                 :          0 :                 IXGBE_DEV_PRIVATE_TO_MACSEC_SETTING(dev->data->dev_private);
    8240                 :            : 
    8241                 :          0 :         macsec->offload_en = 0;
    8242                 :          0 :         macsec->encrypt_en = 0;
    8243                 :          0 :         macsec->replayprotect_en = 0;
    8244                 :          0 : }
    8245                 :            : 
    8246                 :            : void
    8247                 :          0 : ixgbe_dev_macsec_register_enable(struct rte_eth_dev *dev,
    8248                 :            :                                 struct ixgbe_macsec_setting *macsec_setting)
    8249                 :            : {
    8250                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8251                 :            :         uint32_t ctrl;
    8252                 :          0 :         uint8_t en = macsec_setting->encrypt_en;
    8253                 :          0 :         uint8_t rp = macsec_setting->replayprotect_en;
    8254                 :            : 
    8255                 :            :         /**
    8256                 :            :          * Workaround:
    8257                 :            :          * As no ixgbe_disable_sec_rx_path equivalent is
    8258                 :            :          * implemented for tx in the base code, and we are
    8259                 :            :          * not allowed to modify the base code in DPDK, so
    8260                 :            :          * just call the hand-written one directly for now.
    8261                 :            :          * The hardware support has been checked by
    8262                 :            :          * ixgbe_disable_sec_rx_path().
    8263                 :            :          */
    8264                 :          0 :         ixgbe_disable_sec_tx_path_generic(hw);
    8265                 :            : 
    8266                 :            :         /* Enable Ethernet CRC (required by MACsec offload) */
    8267                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_HLREG0);
    8268                 :          0 :         ctrl |= IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_RXCRCSTRP;
    8269                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_HLREG0, ctrl);
    8270                 :            : 
    8271                 :            :         /* Enable the TX and RX crypto engines */
    8272                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
    8273                 :          0 :         ctrl &= ~IXGBE_SECTXCTRL_SECTX_DIS;
    8274                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, ctrl);
    8275                 :            : 
    8276                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
    8277                 :          0 :         ctrl &= ~IXGBE_SECRXCTRL_SECRX_DIS;
    8278                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, ctrl);
    8279                 :            : 
    8280                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
    8281                 :          0 :         ctrl &= ~IXGBE_SECTX_MINSECIFG_MASK;
    8282                 :          0 :         ctrl |= 0x3;
    8283                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, ctrl);
    8284                 :            : 
    8285                 :            :         /* Enable SA lookup */
    8286                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_LSECTXCTRL);
    8287                 :          0 :         ctrl &= ~IXGBE_LSECTXCTRL_EN_MASK;
    8288         [ #  # ]:          0 :         ctrl |= en ? IXGBE_LSECTXCTRL_AUTH_ENCRYPT :
    8289                 :            :                      IXGBE_LSECTXCTRL_AUTH;
    8290                 :            :         ctrl |= IXGBE_LSECTXCTRL_AISCI;
    8291                 :            :         ctrl &= ~IXGBE_LSECTXCTRL_PNTHRSH_MASK;
    8292                 :          0 :         ctrl |= IXGBE_MACSEC_PNTHRSH & IXGBE_LSECTXCTRL_PNTHRSH_MASK;
    8293                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LSECTXCTRL, ctrl);
    8294                 :            : 
    8295                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_LSECRXCTRL);
    8296                 :            :         ctrl &= ~IXGBE_LSECRXCTRL_EN_MASK;
    8297                 :            :         ctrl |= IXGBE_LSECRXCTRL_STRICT << IXGBE_LSECRXCTRL_EN_SHIFT;
    8298                 :            :         ctrl &= ~IXGBE_LSECRXCTRL_PLSH;
    8299         [ #  # ]:          0 :         if (rp)
    8300                 :          0 :                 ctrl |= IXGBE_LSECRXCTRL_RP;
    8301                 :            :         else
    8302                 :          0 :                 ctrl &= ~IXGBE_LSECRXCTRL_RP;
    8303                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LSECRXCTRL, ctrl);
    8304                 :            : 
    8305                 :            :         /* Start the data paths */
    8306                 :          0 :         ixgbe_enable_sec_rx_path(hw);
    8307                 :            :         /**
    8308                 :            :          * Workaround:
    8309                 :            :          * As no ixgbe_enable_sec_rx_path equivalent is
    8310                 :            :          * implemented for tx in the base code, and we are
    8311                 :            :          * not allowed to modify the base code in DPDK, so
    8312                 :            :          * just call the hand-written one directly for now.
    8313                 :            :          */
    8314                 :          0 :         ixgbe_enable_sec_tx_path_generic(hw);
    8315                 :          0 : }
    8316                 :            : 
    8317                 :            : void
    8318                 :          0 : ixgbe_dev_macsec_register_disable(struct rte_eth_dev *dev)
    8319                 :            : {
    8320                 :          0 :         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    8321                 :            :         uint32_t ctrl;
    8322                 :            : 
    8323                 :            :         /**
    8324                 :            :          * Workaround:
    8325                 :            :          * As no ixgbe_disable_sec_rx_path equivalent is
    8326                 :            :          * implemented for tx in the base code, and we are
    8327                 :            :          * not allowed to modify the base code in DPDK, so
    8328                 :            :          * just call the hand-written one directly for now.
    8329                 :            :          * The hardware support has been checked by
    8330                 :            :          * ixgbe_disable_sec_rx_path().
    8331                 :            :          */
    8332                 :          0 :         ixgbe_disable_sec_tx_path_generic(hw);
    8333                 :            : 
    8334                 :            :         /* Disable the TX and RX crypto engines */
    8335                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_SECTXCTRL);
    8336                 :          0 :         ctrl |= IXGBE_SECTXCTRL_SECTX_DIS;
    8337                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECTXCTRL, ctrl);
    8338                 :            : 
    8339                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
    8340                 :          0 :         ctrl |= IXGBE_SECRXCTRL_SECRX_DIS;
    8341                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, ctrl);
    8342                 :            : 
    8343                 :            :         /* Disable SA lookup */
    8344                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_LSECTXCTRL);
    8345                 :          0 :         ctrl &= ~IXGBE_LSECTXCTRL_EN_MASK;
    8346                 :            :         ctrl |= IXGBE_LSECTXCTRL_DISABLE;
    8347                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LSECTXCTRL, ctrl);
    8348                 :            : 
    8349                 :          0 :         ctrl = IXGBE_READ_REG(hw, IXGBE_LSECRXCTRL);
    8350                 :          0 :         ctrl &= ~IXGBE_LSECRXCTRL_EN_MASK;
    8351                 :            :         ctrl |= IXGBE_LSECRXCTRL_DISABLE << IXGBE_LSECRXCTRL_EN_SHIFT;
    8352                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LSECRXCTRL, ctrl);
    8353                 :            : 
    8354                 :            :         /* Start the data paths */
    8355                 :          0 :         ixgbe_enable_sec_rx_path(hw);
    8356                 :            :         /**
    8357                 :            :          * Workaround:
    8358                 :            :          * As no ixgbe_enable_sec_rx_path equivalent is
    8359                 :            :          * implemented for tx in the base code, and we are
    8360                 :            :          * not allowed to modify the base code in DPDK, so
    8361                 :            :          * just call the hand-written one directly for now.
    8362                 :            :          */
    8363                 :          0 :         ixgbe_enable_sec_tx_path_generic(hw);
    8364                 :          0 : }
    8365                 :            : 
    8366                 :        252 : RTE_PMD_REGISTER_PCI(net_ixgbe, rte_ixgbe_pmd);
    8367                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe, pci_id_ixgbe_map);
    8368                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe, "* igb_uio | uio_pci_generic | vfio-pci");
    8369                 :            : RTE_PMD_REGISTER_PARAM_STRING(net_ixgbe,
    8370                 :            :                               IXGBE_DEVARG_FIBER_SDP3_NOT_TX_DISABLE "=<0|1>");
    8371                 :        252 : RTE_PMD_REGISTER_PCI(net_ixgbe_vf, rte_ixgbevf_pmd);
    8372                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe_vf, pci_id_ixgbevf_map);
    8373                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe_vf, "* igb_uio | vfio-pci");
    8374                 :            : RTE_PMD_REGISTER_PARAM_STRING(net_ixgbe_vf,
    8375                 :            :                               IXGBEVF_DEVARG_PFLINK_FULLCHK "=<0|1>");
    8376                 :            : 
    8377         [ -  + ]:        252 : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_init, init, NOTICE);
    8378         [ -  + ]:        252 : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_driver, driver, NOTICE);
    8379                 :            : 
    8380                 :            : #ifdef RTE_ETHDEV_DEBUG_RX
    8381                 :            : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_rx, rx, DEBUG);
    8382                 :            : #endif
    8383                 :            : #ifdef RTE_ETHDEV_DEBUG_TX
    8384                 :            : RTE_LOG_REGISTER_SUFFIX(ixgbe_logtype_tx, tx, DEBUG);
    8385                 :            : #endif

Generated by: LCOV version 1.14