LCOV - code coverage report
Current view: top level - drivers/net/intel/e1000 - em_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 622 0.2 %
Date: 2025-02-01 18:54:23 Functions: 1 40 2.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 196 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2016 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <sys/queue.h>
       6                 :            : #include <stdio.h>
       7                 :            : #include <errno.h>
       8                 :            : #include <stdint.h>
       9                 :            : #include <stdarg.h>
      10                 :            : 
      11                 :            : #include <rte_common.h>
      12                 :            : #include <rte_interrupts.h>
      13                 :            : #include <rte_byteorder.h>
      14                 :            : #include <rte_debug.h>
      15                 :            : #include <rte_pci.h>
      16                 :            : #include <bus_pci_driver.h>
      17                 :            : #include <rte_ether.h>
      18                 :            : #include <ethdev_driver.h>
      19                 :            : #include <ethdev_pci.h>
      20                 :            : #include <rte_memory.h>
      21                 :            : #include <rte_eal.h>
      22                 :            : #include <rte_malloc.h>
      23                 :            : #include <dev_driver.h>
      24                 :            : 
      25                 :            : #include "e1000_logs.h"
      26                 :            : #include "base/e1000_api.h"
      27                 :            : #include "e1000_ethdev.h"
      28                 :            : 
      29                 :            : #define EM_EIAC                 0x000DC
      30                 :            : 
      31                 :            : #define PMD_ROUNDUP(x,y)        (((x) + (y) - 1)/(y) * (y))
      32                 :            : 
      33                 :            : 
      34                 :            : static int eth_em_configure(struct rte_eth_dev *dev);
      35                 :            : static int eth_em_start(struct rte_eth_dev *dev);
      36                 :            : static int eth_em_stop(struct rte_eth_dev *dev);
      37                 :            : static int eth_em_close(struct rte_eth_dev *dev);
      38                 :            : static int eth_em_promiscuous_enable(struct rte_eth_dev *dev);
      39                 :            : static int eth_em_promiscuous_disable(struct rte_eth_dev *dev);
      40                 :            : static int eth_em_allmulticast_enable(struct rte_eth_dev *dev);
      41                 :            : static int eth_em_allmulticast_disable(struct rte_eth_dev *dev);
      42                 :            : static int eth_em_link_update(struct rte_eth_dev *dev,
      43                 :            :                                 int wait_to_complete);
      44                 :            : static int eth_em_stats_get(struct rte_eth_dev *dev,
      45                 :            :                                 struct rte_eth_stats *rte_stats);
      46                 :            : static int eth_em_stats_reset(struct rte_eth_dev *dev);
      47                 :            : static int eth_em_infos_get(struct rte_eth_dev *dev,
      48                 :            :                                 struct rte_eth_dev_info *dev_info);
      49                 :            : static int eth_em_flow_ctrl_get(struct rte_eth_dev *dev,
      50                 :            :                                 struct rte_eth_fc_conf *fc_conf);
      51                 :            : static int eth_em_flow_ctrl_set(struct rte_eth_dev *dev,
      52                 :            :                                 struct rte_eth_fc_conf *fc_conf);
      53                 :            : static int eth_em_interrupt_setup(struct rte_eth_dev *dev);
      54                 :            : static int eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev);
      55                 :            : static int eth_em_interrupt_get_status(struct rte_eth_dev *dev);
      56                 :            : static int eth_em_interrupt_action(struct rte_eth_dev *dev,
      57                 :            :                                    struct rte_intr_handle *handle);
      58                 :            : static void eth_em_interrupt_handler(void *param);
      59                 :            : 
      60                 :            : static int em_hw_init(struct e1000_hw *hw);
      61                 :            : static int em_hardware_init(struct e1000_hw *hw);
      62                 :            : static void em_hw_control_acquire(struct e1000_hw *hw);
      63                 :            : static void em_hw_control_release(struct e1000_hw *hw);
      64                 :            : static void em_init_manageability(struct e1000_hw *hw);
      65                 :            : static void em_release_manageability(struct e1000_hw *hw);
      66                 :            : 
      67                 :            : static int eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
      68                 :            : 
      69                 :            : static int eth_em_vlan_filter_set(struct rte_eth_dev *dev,
      70                 :            :                 uint16_t vlan_id, int on);
      71                 :            : static int eth_em_vlan_offload_set(struct rte_eth_dev *dev, int mask);
      72                 :            : static void em_vlan_hw_filter_enable(struct rte_eth_dev *dev);
      73                 :            : static void em_vlan_hw_filter_disable(struct rte_eth_dev *dev);
      74                 :            : static void em_vlan_hw_strip_enable(struct rte_eth_dev *dev);
      75                 :            : static void em_vlan_hw_strip_disable(struct rte_eth_dev *dev);
      76                 :            : 
      77                 :            : /*
      78                 :            : static void eth_em_vlan_filter_set(struct rte_eth_dev *dev,
      79                 :            :                                         uint16_t vlan_id, int on);
      80                 :            : */
      81                 :            : 
      82                 :            : static int eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
      83                 :            : static int eth_em_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
      84                 :            : static void em_lsc_intr_disable(struct e1000_hw *hw);
      85                 :            : static void em_rxq_intr_enable(struct e1000_hw *hw);
      86                 :            : static void em_rxq_intr_disable(struct e1000_hw *hw);
      87                 :            : 
      88                 :            : static int eth_em_led_on(struct rte_eth_dev *dev);
      89                 :            : static int eth_em_led_off(struct rte_eth_dev *dev);
      90                 :            : 
      91                 :            : static int em_get_rx_buffer_size(struct e1000_hw *hw);
      92                 :            : static int eth_em_rar_set(struct rte_eth_dev *dev,
      93                 :            :                         struct rte_ether_addr *mac_addr,
      94                 :            :                         uint32_t index, uint32_t pool);
      95                 :            : static void eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index);
      96                 :            : static int eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
      97                 :            :                                          struct rte_ether_addr *addr);
      98                 :            : 
      99                 :            : static int eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
     100                 :            :                                    struct rte_ether_addr *mc_addr_set,
     101                 :            :                                    uint32_t nb_mc_addr);
     102                 :            : 
     103                 :            : #define EM_FC_PAUSE_TIME 0x0680
     104                 :            : #define EM_LINK_UPDATE_CHECK_TIMEOUT  90  /* 9s */
     105                 :            : #define EM_LINK_UPDATE_CHECK_INTERVAL 100 /* ms */
     106                 :            : 
     107                 :            : static enum e1000_fc_mode em_fc_setting = e1000_fc_full;
     108                 :            : 
     109                 :            : /*
     110                 :            :  * The set of PCI devices this driver supports
     111                 :            :  */
     112                 :            : static const struct rte_pci_id pci_id_em_map[] = {
     113                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82540EM) },
     114                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82545EM_COPPER) },
     115                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82545EM_FIBER) },
     116                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_COPPER) },
     117                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_FIBER) },
     118                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82546EB_QUAD_COPPER) },
     119                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_COPPER) },
     120                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_FIBER) },
     121                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES) },
     122                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES_DUAL) },
     123                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_SERDES_QUAD) },
     124                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_COPPER) },
     125                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571PT_QUAD_COPPER) },
     126                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_FIBER) },
     127                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82571EB_QUAD_COPPER_LP) },
     128                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_COPPER) },
     129                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_FIBER) },
     130                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI_SERDES) },
     131                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82572EI) },
     132                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82573L) },
     133                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82574L) },
     134                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82574LA) },
     135                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_82583V) },
     136                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH2_LV_LM) },
     137                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPT_I217_LM) },
     138                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPT_I217_V) },
     139                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPTLP_I218_LM) },
     140                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LPTLP_I218_V) },
     141                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_LM2) },
     142                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_V2) },
     143                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_LM3) },
     144                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_I218_V3) },
     145                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM) },
     146                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V) },
     147                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM2) },
     148                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V2) },
     149                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_LBG_I219_LM3) },
     150                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM4) },
     151                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V4) },
     152                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_LM5) },
     153                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_SPT_I219_V5) },
     154                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_LM6) },
     155                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_V6) },
     156                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_LM7) },
     157                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_CNP_I219_V7) },
     158                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_LM22) },
     159                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_V22) },
     160                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_LM23) },
     161                 :            :         { RTE_PCI_DEVICE(E1000_INTEL_VENDOR_ID, E1000_DEV_ID_PCH_RPL_I219_V23) },
     162                 :            :         { .vendor_id = 0, /* sentinel */ },
     163                 :            : };
     164                 :            : 
     165                 :            : static const struct eth_dev_ops eth_em_ops = {
     166                 :            :         .dev_configure        = eth_em_configure,
     167                 :            :         .dev_start            = eth_em_start,
     168                 :            :         .dev_stop             = eth_em_stop,
     169                 :            :         .dev_close            = eth_em_close,
     170                 :            :         .promiscuous_enable   = eth_em_promiscuous_enable,
     171                 :            :         .promiscuous_disable  = eth_em_promiscuous_disable,
     172                 :            :         .allmulticast_enable  = eth_em_allmulticast_enable,
     173                 :            :         .allmulticast_disable = eth_em_allmulticast_disable,
     174                 :            :         .link_update          = eth_em_link_update,
     175                 :            :         .stats_get            = eth_em_stats_get,
     176                 :            :         .stats_reset          = eth_em_stats_reset,
     177                 :            :         .dev_infos_get        = eth_em_infos_get,
     178                 :            :         .mtu_set              = eth_em_mtu_set,
     179                 :            :         .vlan_filter_set      = eth_em_vlan_filter_set,
     180                 :            :         .vlan_offload_set     = eth_em_vlan_offload_set,
     181                 :            :         .rx_queue_setup       = eth_em_rx_queue_setup,
     182                 :            :         .rx_queue_release     = eth_em_rx_queue_release,
     183                 :            :         .tx_queue_setup       = eth_em_tx_queue_setup,
     184                 :            :         .tx_queue_release     = eth_em_tx_queue_release,
     185                 :            :         .rx_queue_intr_enable = eth_em_rx_queue_intr_enable,
     186                 :            :         .rx_queue_intr_disable = eth_em_rx_queue_intr_disable,
     187                 :            :         .dev_led_on           = eth_em_led_on,
     188                 :            :         .dev_led_off          = eth_em_led_off,
     189                 :            :         .flow_ctrl_get        = eth_em_flow_ctrl_get,
     190                 :            :         .flow_ctrl_set        = eth_em_flow_ctrl_set,
     191                 :            :         .mac_addr_set         = eth_em_default_mac_addr_set,
     192                 :            :         .mac_addr_add         = eth_em_rar_set,
     193                 :            :         .mac_addr_remove      = eth_em_rar_clear,
     194                 :            :         .set_mc_addr_list     = eth_em_set_mc_addr_list,
     195                 :            :         .rxq_info_get         = em_rxq_info_get,
     196                 :            :         .txq_info_get         = em_txq_info_get,
     197                 :            : };
     198                 :            : 
     199                 :            : 
     200                 :            : /**
     201                 :            :  *  eth_em_dev_is_ich8 - Check for ICH8 device
     202                 :            :  *  @hw: pointer to the HW structure
     203                 :            :  *
     204                 :            :  *  return TRUE for ICH8, otherwise FALSE
     205                 :            :  **/
     206                 :            : static bool
     207                 :          0 : eth_em_dev_is_ich8(struct e1000_hw *hw)
     208                 :            : {
     209                 :          0 :         DEBUGFUNC("eth_em_dev_is_ich8");
     210                 :            : 
     211         [ #  # ]:          0 :         switch (hw->device_id) {
     212                 :            :         case E1000_DEV_ID_PCH2_LV_LM:
     213                 :            :         case E1000_DEV_ID_PCH_LPT_I217_LM:
     214                 :            :         case E1000_DEV_ID_PCH_LPT_I217_V:
     215                 :            :         case E1000_DEV_ID_PCH_LPTLP_I218_LM:
     216                 :            :         case E1000_DEV_ID_PCH_LPTLP_I218_V:
     217                 :            :         case E1000_DEV_ID_PCH_I218_V2:
     218                 :            :         case E1000_DEV_ID_PCH_I218_LM2:
     219                 :            :         case E1000_DEV_ID_PCH_I218_V3:
     220                 :            :         case E1000_DEV_ID_PCH_I218_LM3:
     221                 :            :         case E1000_DEV_ID_PCH_SPT_I219_LM:
     222                 :            :         case E1000_DEV_ID_PCH_SPT_I219_V:
     223                 :            :         case E1000_DEV_ID_PCH_SPT_I219_LM2:
     224                 :            :         case E1000_DEV_ID_PCH_SPT_I219_V2:
     225                 :            :         case E1000_DEV_ID_PCH_LBG_I219_LM3:
     226                 :            :         case E1000_DEV_ID_PCH_SPT_I219_LM4:
     227                 :            :         case E1000_DEV_ID_PCH_SPT_I219_V4:
     228                 :            :         case E1000_DEV_ID_PCH_SPT_I219_LM5:
     229                 :            :         case E1000_DEV_ID_PCH_SPT_I219_V5:
     230                 :            :         case E1000_DEV_ID_PCH_CNP_I219_LM6:
     231                 :            :         case E1000_DEV_ID_PCH_CNP_I219_V6:
     232                 :            :         case E1000_DEV_ID_PCH_CNP_I219_LM7:
     233                 :            :         case E1000_DEV_ID_PCH_CNP_I219_V7:
     234                 :            :         case E1000_DEV_ID_PCH_RPL_I219_LM22:
     235                 :            :         case E1000_DEV_ID_PCH_RPL_I219_V22:
     236                 :            :         case E1000_DEV_ID_PCH_RPL_I219_LM23:
     237                 :            :         case E1000_DEV_ID_PCH_RPL_I219_V23:
     238                 :            : 
     239                 :            :                 return 1;
     240                 :          0 :         default:
     241                 :          0 :                 return 0;
     242                 :            :         }
     243                 :            : }
     244                 :            : 
     245                 :            : static int
     246                 :          0 : eth_em_dev_init(struct rte_eth_dev *eth_dev)
     247                 :            : {
     248                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
     249                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     250                 :          0 :         struct e1000_adapter *adapter =
     251                 :          0 :                 E1000_DEV_PRIVATE(eth_dev->data->dev_private);
     252                 :          0 :         struct e1000_hw *hw =
     253                 :            :                 E1000_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
     254                 :          0 :         struct e1000_vfta * shadow_vfta =
     255                 :            :                 E1000_DEV_PRIVATE_TO_VFTA(eth_dev->data->dev_private);
     256                 :            : 
     257                 :          0 :         eth_dev->dev_ops = &eth_em_ops;
     258                 :          0 :         eth_dev->rx_queue_count = eth_em_rx_queue_count;
     259                 :          0 :         eth_dev->rx_descriptor_status = eth_em_rx_descriptor_status;
     260                 :          0 :         eth_dev->tx_descriptor_status = eth_em_tx_descriptor_status;
     261                 :          0 :         eth_dev->rx_pkt_burst = (eth_rx_burst_t)&eth_em_recv_pkts;
     262                 :          0 :         eth_dev->tx_pkt_burst = (eth_tx_burst_t)&eth_em_xmit_pkts;
     263                 :          0 :         eth_dev->tx_pkt_prepare = (eth_tx_prep_t)&eth_em_prep_pkts;
     264                 :            : 
     265                 :            :         /* for secondary processes, we don't initialise any further as primary
     266                 :            :          * has already done this work. Only check we don't need a different
     267                 :            :          * RX function */
     268         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY){
     269         [ #  # ]:          0 :                 if (eth_dev->data->scattered_rx)
     270                 :          0 :                         eth_dev->rx_pkt_burst =
     271                 :            :                                 (eth_rx_burst_t)&eth_em_recv_scattered_pkts;
     272                 :          0 :                 return 0;
     273                 :            :         }
     274                 :            : 
     275                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
     276                 :            : 
     277                 :          0 :         hw->hw_addr = (void *)pci_dev->mem_resource[0].addr;
     278                 :          0 :         hw->device_id = pci_dev->id.device_id;
     279                 :          0 :         adapter->stopped = 0;
     280                 :            : 
     281                 :            :         /* For ICH8 support we'll need to map the flash memory BAR */
     282         [ #  # ]:          0 :         if (eth_em_dev_is_ich8(hw))
     283                 :          0 :                 hw->flash_address = (void *)pci_dev->mem_resource[1].addr;
     284                 :            : 
     285   [ #  #  #  # ]:          0 :         if (e1000_setup_init_funcs(hw, TRUE) != E1000_SUCCESS ||
     286                 :          0 :                         em_hw_init(hw) != 0) {
     287                 :          0 :                 PMD_INIT_LOG(ERR, "port_id %d vendorID=0x%x deviceID=0x%x: "
     288                 :            :                         "failed to init HW",
     289                 :            :                         eth_dev->data->port_id, pci_dev->id.vendor_id,
     290                 :            :                         pci_dev->id.device_id);
     291                 :          0 :                 return -ENODEV;
     292                 :            :         }
     293                 :            : 
     294                 :            :         /* Allocate memory for storing MAC addresses */
     295                 :          0 :         eth_dev->data->mac_addrs = rte_zmalloc("e1000", RTE_ETHER_ADDR_LEN *
     296                 :          0 :                         hw->mac.rar_entry_count, 0);
     297         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
     298                 :          0 :                 PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to "
     299                 :            :                         "store MAC addresses",
     300                 :            :                         RTE_ETHER_ADDR_LEN * hw->mac.rar_entry_count);
     301                 :          0 :                 return -ENOMEM;
     302                 :            :         }
     303                 :            : 
     304                 :            :         /* Copy the permanent MAC address */
     305                 :            :         rte_ether_addr_copy((struct rte_ether_addr *)hw->mac.addr,
     306                 :            :                 eth_dev->data->mac_addrs);
     307                 :            : 
     308                 :            :         /* initialize the vfta */
     309                 :            :         memset(shadow_vfta, 0, sizeof(*shadow_vfta));
     310                 :            : 
     311                 :          0 :         PMD_INIT_LOG(DEBUG, "port_id %d vendorID=0x%x deviceID=0x%x",
     312                 :            :                      eth_dev->data->port_id, pci_dev->id.vendor_id,
     313                 :            :                      pci_dev->id.device_id);
     314                 :            : 
     315                 :          0 :         rte_intr_callback_register(intr_handle,
     316                 :            :                                    eth_em_interrupt_handler, eth_dev);
     317                 :            : 
     318                 :          0 :         return 0;
     319                 :            : }
     320                 :            : 
     321                 :            : static int
     322                 :          0 : eth_em_dev_uninit(struct rte_eth_dev *eth_dev)
     323                 :            : {
     324                 :          0 :         PMD_INIT_FUNC_TRACE();
     325                 :            : 
     326         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     327                 :            :                 return 0;
     328                 :            : 
     329                 :          0 :         eth_em_close(eth_dev);
     330                 :            : 
     331                 :          0 :         return 0;
     332                 :            : }
     333                 :            : 
     334                 :          0 : static int eth_em_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
     335                 :            :         struct rte_pci_device *pci_dev)
     336                 :            : {
     337                 :          0 :         return rte_eth_dev_pci_generic_probe(pci_dev,
     338                 :            :                 sizeof(struct e1000_adapter), eth_em_dev_init);
     339                 :            : }
     340                 :            : 
     341                 :          0 : static int eth_em_pci_remove(struct rte_pci_device *pci_dev)
     342                 :            : {
     343                 :          0 :         return rte_eth_dev_pci_generic_remove(pci_dev, eth_em_dev_uninit);
     344                 :            : }
     345                 :            : 
     346                 :            : static struct rte_pci_driver rte_em_pmd = {
     347                 :            :         .id_table = pci_id_em_map,
     348                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
     349                 :            :         .probe = eth_em_pci_probe,
     350                 :            :         .remove = eth_em_pci_remove,
     351                 :            : };
     352                 :            : 
     353                 :            : static int
     354                 :          0 : em_hw_init(struct e1000_hw *hw)
     355                 :            : {
     356                 :            :         int diag;
     357                 :            : 
     358                 :          0 :         diag = hw->mac.ops.init_params(hw);
     359         [ #  # ]:          0 :         if (diag != 0) {
     360                 :          0 :                 PMD_INIT_LOG(ERR, "MAC Initialization Error");
     361                 :          0 :                 return diag;
     362                 :            :         }
     363                 :          0 :         diag = hw->nvm.ops.init_params(hw);
     364         [ #  # ]:          0 :         if (diag != 0) {
     365                 :          0 :                 PMD_INIT_LOG(ERR, "NVM Initialization Error");
     366                 :          0 :                 return diag;
     367                 :            :         }
     368                 :          0 :         diag = hw->phy.ops.init_params(hw);
     369         [ #  # ]:          0 :         if (diag != 0) {
     370                 :          0 :                 PMD_INIT_LOG(ERR, "PHY Initialization Error");
     371                 :          0 :                 return diag;
     372                 :            :         }
     373                 :          0 :         (void) e1000_get_bus_info(hw);
     374                 :            : 
     375                 :          0 :         hw->mac.autoneg = 1;
     376                 :          0 :         hw->phy.autoneg_wait_to_complete = 0;
     377                 :          0 :         hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
     378                 :            : 
     379                 :          0 :         e1000_init_script_state_82541(hw, TRUE);
     380                 :          0 :         e1000_set_tbi_compatibility_82543(hw, TRUE);
     381                 :            : 
     382                 :            :         /* Copper options */
     383         [ #  # ]:          0 :         if (hw->phy.media_type == e1000_media_type_copper) {
     384                 :          0 :                 hw->phy.mdix = 0; /* AUTO_ALL_MODES */
     385                 :          0 :                 hw->phy.disable_polarity_correction = 0;
     386                 :          0 :                 hw->phy.ms_type = e1000_ms_hw_default;
     387                 :            :         }
     388                 :            : 
     389                 :            :         /*
     390                 :            :          * Start from a known state, this is important in reading the nvm
     391                 :            :          * and mac from that.
     392                 :            :          */
     393                 :          0 :         e1000_reset_hw(hw);
     394                 :            : 
     395                 :            :         /* Make sure we have a good EEPROM before we read from it */
     396         [ #  # ]:          0 :         if (e1000_validate_nvm_checksum(hw) < 0) {
     397                 :            :                 /*
     398                 :            :                  * Some PCI-E parts fail the first check due to
     399                 :            :                  * the link being in sleep state, call it again,
     400                 :            :                  * if it fails a second time its a real issue.
     401                 :            :                  */
     402                 :          0 :                 diag = e1000_validate_nvm_checksum(hw);
     403         [ #  # ]:          0 :                 if (diag < 0) {
     404                 :          0 :                         PMD_INIT_LOG(ERR, "EEPROM checksum invalid");
     405                 :          0 :                         goto error;
     406                 :            :                 }
     407                 :            :         }
     408                 :            : 
     409                 :            :         /* Read the permanent MAC address out of the EEPROM */
     410                 :          0 :         diag = e1000_read_mac_addr(hw);
     411         [ #  # ]:          0 :         if (diag != 0) {
     412                 :          0 :                 PMD_INIT_LOG(ERR, "EEPROM error while reading MAC address");
     413                 :          0 :                 goto error;
     414                 :            :         }
     415                 :            : 
     416                 :            :         /* Now initialize the hardware */
     417                 :          0 :         diag = em_hardware_init(hw);
     418         [ #  # ]:          0 :         if (diag != 0) {
     419                 :          0 :                 PMD_INIT_LOG(ERR, "Hardware initialization failed");
     420                 :          0 :                 goto error;
     421                 :            :         }
     422                 :            : 
     423                 :          0 :         hw->mac.get_link_status = 1;
     424                 :            : 
     425                 :            :         /* Indicate SOL/IDER usage */
     426                 :          0 :         diag = e1000_check_reset_block(hw);
     427         [ #  # ]:          0 :         if (diag < 0) {
     428                 :          0 :                 PMD_INIT_LOG(ERR, "PHY reset is blocked due to "
     429                 :            :                         "SOL/IDER session");
     430                 :            :         }
     431                 :            :         return 0;
     432                 :            : 
     433                 :          0 : error:
     434                 :            :         em_hw_control_release(hw);
     435                 :            :         return diag;
     436                 :            : }
     437                 :            : 
     438                 :            : static int
     439                 :          0 : eth_em_configure(struct rte_eth_dev *dev)
     440                 :            : {
     441                 :            :         struct e1000_interrupt *intr =
     442                 :          0 :                 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
     443                 :            : 
     444                 :          0 :         PMD_INIT_FUNC_TRACE();
     445                 :          0 :         intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
     446                 :            : 
     447                 :          0 :         PMD_INIT_FUNC_TRACE();
     448                 :            : 
     449                 :          0 :         return 0;
     450                 :            : }
     451                 :            : 
     452                 :            : static void
     453                 :            : em_set_pba(struct e1000_hw *hw)
     454                 :            : {
     455                 :            :         uint32_t pba;
     456                 :            : 
     457                 :            :         /*
     458                 :            :          * Packet Buffer Allocation (PBA)
     459                 :            :          * Writing PBA sets the receive portion of the buffer
     460                 :            :          * the remainder is used for the transmit buffer.
     461                 :            :          * Devices before the 82547 had a Packet Buffer of 64K.
     462                 :            :          * After the 82547 the buffer was reduced to 40K.
     463                 :            :          */
     464         [ #  # ]:          0 :         switch (hw->mac.type) {
     465                 :            :                 case e1000_82547:
     466                 :            :                 case e1000_82547_rev_2:
     467                 :            :                 /* 82547: Total Packet Buffer is 40K */
     468                 :            :                         pba = E1000_PBA_22K; /* 22K for Rx, 18K for Tx */
     469                 :            :                         break;
     470                 :            :                 case e1000_82571:
     471                 :            :                 case e1000_82572:
     472                 :            :                 case e1000_80003es2lan:
     473                 :            :                         pba = E1000_PBA_32K; /* 32K for Rx, 16K for Tx */
     474                 :            :                         break;
     475                 :            :                 case e1000_82573: /* 82573: Total Packet Buffer is 32K */
     476                 :            :                         pba = E1000_PBA_12K; /* 12K for Rx, 20K for Tx */
     477                 :            :                         break;
     478                 :            :                 case e1000_82574:
     479                 :            :                 case e1000_82583:
     480                 :            :                         pba = E1000_PBA_20K; /* 20K for Rx, 20K for Tx */
     481                 :            :                         break;
     482                 :            :                 case e1000_ich8lan:
     483                 :            :                         pba = E1000_PBA_8K;
     484                 :            :                         break;
     485                 :            :                 case e1000_ich9lan:
     486                 :            :                 case e1000_ich10lan:
     487                 :            :                         pba = E1000_PBA_10K;
     488                 :            :                         break;
     489                 :            :                 case e1000_pchlan:
     490                 :            :                 case e1000_pch2lan:
     491                 :            :                 case e1000_pch_lpt:
     492                 :            :                 case e1000_pch_spt:
     493                 :            :                 case e1000_pch_cnp:
     494                 :            :                 case e1000_pch_adp:
     495                 :            :                 case e1000_pch_tgp:
     496                 :            :                         pba = E1000_PBA_26K;
     497                 :            :                         break;
     498                 :            :                 default:
     499                 :            :                         pba = E1000_PBA_40K; /* 40K for Rx, 24K for Tx */
     500                 :            :         }
     501                 :            : 
     502                 :          0 :         E1000_WRITE_REG(hw, E1000_PBA, pba);
     503                 :            : }
     504                 :            : 
     505                 :            : static void
     506                 :          0 : eth_em_rxtx_control(struct rte_eth_dev *dev,
     507                 :            :                     bool enable)
     508                 :            : {
     509                 :            :         struct e1000_hw *hw =
     510                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     511                 :            :         uint32_t tctl, rctl;
     512                 :            : 
     513                 :          0 :         tctl = E1000_READ_REG(hw, E1000_TCTL);
     514                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
     515         [ #  # ]:          0 :         if (enable) {
     516                 :            :                 /* enable Tx/Rx */
     517                 :          0 :                 tctl |= E1000_TCTL_EN;
     518                 :          0 :                 rctl |= E1000_RCTL_EN;
     519                 :            :         } else {
     520                 :            :                 /* disable Tx/Rx */
     521                 :          0 :                 tctl &= ~E1000_TCTL_EN;
     522                 :          0 :                 rctl &= ~E1000_RCTL_EN;
     523                 :            :         }
     524                 :          0 :         E1000_WRITE_REG(hw, E1000_TCTL, tctl);
     525                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
     526                 :          0 :         E1000_WRITE_FLUSH(hw);
     527                 :          0 : }
     528                 :            : 
     529                 :            : static int
     530                 :          0 : eth_em_start(struct rte_eth_dev *dev)
     531                 :            : {
     532                 :          0 :         struct e1000_adapter *adapter =
     533                 :          0 :                 E1000_DEV_PRIVATE(dev->data->dev_private);
     534                 :          0 :         struct e1000_hw *hw =
     535                 :            :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     536                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     537                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     538                 :            :         int ret, mask;
     539                 :            :         uint32_t intr_vector = 0;
     540                 :            :         uint32_t *speeds;
     541                 :            :         int num_speeds;
     542                 :            :         bool autoneg;
     543                 :            : 
     544                 :          0 :         PMD_INIT_FUNC_TRACE();
     545                 :            : 
     546                 :          0 :         ret = eth_em_stop(dev);
     547         [ #  # ]:          0 :         if (ret != 0)
     548                 :            :                 return ret;
     549                 :            : 
     550                 :          0 :         e1000_power_up_phy(hw);
     551                 :            : 
     552                 :            :         /* Set default PBA value */
     553                 :            :         em_set_pba(hw);
     554                 :            : 
     555                 :            :         /* Put the address into the Receive Address Array */
     556                 :          0 :         e1000_rar_set(hw, hw->mac.addr, 0);
     557                 :            : 
     558                 :            :         /*
     559                 :            :          * With the 82571 adapter, RAR[0] may be overwritten
     560                 :            :          * when the other port is reset, we make a duplicate
     561                 :            :          * in RAR[14] for that eventuality, this assures
     562                 :            :          * the interface continues to function.
     563                 :            :          */
     564         [ #  # ]:          0 :         if (hw->mac.type == e1000_82571) {
     565                 :          0 :                 e1000_set_laa_state_82571(hw, TRUE);
     566                 :          0 :                 e1000_rar_set(hw, hw->mac.addr, E1000_RAR_ENTRIES - 1);
     567                 :            :         }
     568                 :            : 
     569                 :            :         /* Initialize the hardware */
     570         [ #  # ]:          0 :         if (em_hardware_init(hw)) {
     571                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to initialize the hardware");
     572                 :          0 :                 return -EIO;
     573                 :            :         }
     574                 :            : 
     575                 :          0 :         E1000_WRITE_REG(hw, E1000_VET, RTE_ETHER_TYPE_VLAN);
     576                 :            : 
     577                 :            :         /* Configure for OS presence */
     578                 :          0 :         em_init_manageability(hw);
     579                 :            : 
     580         [ #  # ]:          0 :         if (dev->data->dev_conf.intr_conf.rxq != 0) {
     581                 :          0 :                 intr_vector = dev->data->nb_rx_queues;
     582         [ #  # ]:          0 :                 if (rte_intr_efd_enable(intr_handle, intr_vector))
     583                 :            :                         return -1;
     584                 :            :         }
     585                 :            : 
     586         [ #  # ]:          0 :         if (rte_intr_dp_is_en(intr_handle)) {
     587         [ #  # ]:          0 :                 if (rte_intr_vec_list_alloc(intr_handle, "intr_vec",
     588                 :          0 :                                                    dev->data->nb_rx_queues)) {
     589                 :          0 :                         PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
     590                 :            :                                      " intr_vec", dev->data->nb_rx_queues);
     591                 :          0 :                         return -ENOMEM;
     592                 :            :                 }
     593                 :            : 
     594                 :            :                 /* enable rx interrupt */
     595                 :            :                 em_rxq_intr_enable(hw);
     596                 :            :         }
     597                 :            : 
     598                 :          0 :         eth_em_tx_init(dev);
     599                 :            : 
     600                 :          0 :         ret = eth_em_rx_init(dev);
     601         [ #  # ]:          0 :         if (ret) {
     602                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to initialize RX hardware");
     603                 :          0 :                 em_dev_clear_queues(dev);
     604                 :          0 :                 return ret;
     605                 :            :         }
     606                 :            : 
     607                 :          0 :         e1000_clear_hw_cntrs_base_generic(hw);
     608                 :            : 
     609                 :            :         mask = RTE_ETH_VLAN_STRIP_MASK | RTE_ETH_VLAN_FILTER_MASK |
     610                 :            :                         RTE_ETH_VLAN_EXTEND_MASK;
     611                 :          0 :         ret = eth_em_vlan_offload_set(dev, mask);
     612         [ #  # ]:          0 :         if (ret) {
     613                 :          0 :                 PMD_INIT_LOG(ERR, "Unable to update vlan offload");
     614                 :          0 :                 em_dev_clear_queues(dev);
     615                 :          0 :                 return ret;
     616                 :            :         }
     617                 :            : 
     618                 :            :         /* Set Interrupt Throttling Rate to maximum allowed value. */
     619                 :          0 :         E1000_WRITE_REG(hw, E1000_ITR, UINT16_MAX);
     620                 :            : 
     621                 :            :         /* Setup link speed and duplex */
     622                 :          0 :         speeds = &dev->data->dev_conf.link_speeds;
     623         [ #  # ]:          0 :         if (*speeds == RTE_ETH_LINK_SPEED_AUTONEG) {
     624                 :          0 :                 hw->phy.autoneg_advertised = E1000_ALL_SPEED_DUPLEX;
     625                 :          0 :                 hw->mac.autoneg = 1;
     626                 :            :         } else {
     627                 :            :                 num_speeds = 0;
     628                 :          0 :                 autoneg = (*speeds & RTE_ETH_LINK_SPEED_FIXED) == 0;
     629                 :            : 
     630                 :            :                 /* Reset */
     631                 :          0 :                 hw->phy.autoneg_advertised = 0;
     632                 :            : 
     633         [ #  # ]:          0 :                 if (*speeds & ~(RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
     634                 :            :                                 RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
     635                 :            :                                 RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_FIXED)) {
     636                 :            :                         num_speeds = -1;
     637                 :          0 :                         goto error_invalid_config;
     638                 :            :                 }
     639         [ #  # ]:          0 :                 if (*speeds & RTE_ETH_LINK_SPEED_10M_HD) {
     640                 :          0 :                         hw->phy.autoneg_advertised |= ADVERTISE_10_HALF;
     641                 :            :                         num_speeds++;
     642                 :            :                 }
     643         [ #  # ]:          0 :                 if (*speeds & RTE_ETH_LINK_SPEED_10M) {
     644                 :          0 :                         hw->phy.autoneg_advertised |= ADVERTISE_10_FULL;
     645                 :          0 :                         num_speeds++;
     646                 :            :                 }
     647         [ #  # ]:          0 :                 if (*speeds & RTE_ETH_LINK_SPEED_100M_HD) {
     648                 :          0 :                         hw->phy.autoneg_advertised |= ADVERTISE_100_HALF;
     649                 :          0 :                         num_speeds++;
     650                 :            :                 }
     651         [ #  # ]:          0 :                 if (*speeds & RTE_ETH_LINK_SPEED_100M) {
     652                 :          0 :                         hw->phy.autoneg_advertised |= ADVERTISE_100_FULL;
     653                 :          0 :                         num_speeds++;
     654                 :            :                 }
     655         [ #  # ]:          0 :                 if (*speeds & RTE_ETH_LINK_SPEED_1G) {
     656                 :          0 :                         hw->phy.autoneg_advertised |= ADVERTISE_1000_FULL;
     657                 :          0 :                         num_speeds++;
     658                 :            :                 }
     659   [ #  #  #  # ]:          0 :                 if (num_speeds == 0 || (!autoneg && (num_speeds > 1)))
     660                 :          0 :                         goto error_invalid_config;
     661                 :            : 
     662                 :            :                 /* Set/reset the mac.autoneg based on the link speed,
     663                 :            :                  * fixed or not
     664                 :            :                  */
     665         [ #  # ]:          0 :                 if (!autoneg) {
     666                 :          0 :                         hw->mac.autoneg = 0;
     667                 :          0 :                         hw->mac.forced_speed_duplex =
     668                 :          0 :                                         hw->phy.autoneg_advertised;
     669                 :            :                 } else {
     670                 :          0 :                         hw->mac.autoneg = 1;
     671                 :            :                 }
     672                 :            :         }
     673                 :            : 
     674                 :          0 :         e1000_setup_link(hw);
     675                 :            : 
     676         [ #  # ]:          0 :         if (rte_intr_allow_others(intr_handle)) {
     677                 :            :                 /* check if lsc interrupt is enabled */
     678         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc != 0) {
     679                 :            :                         ret = eth_em_interrupt_setup(dev);
     680                 :            :                         if (ret) {
     681                 :            :                                 PMD_INIT_LOG(ERR, "Unable to setup interrupts");
     682                 :            :                                 em_dev_clear_queues(dev);
     683                 :            :                                 return ret;
     684                 :            :                         }
     685                 :            :                 }
     686                 :            :         } else {
     687                 :          0 :                 rte_intr_callback_unregister(intr_handle,
     688                 :            :                                                 eth_em_interrupt_handler,
     689                 :            :                                                 (void *)dev);
     690         [ #  # ]:          0 :                 if (dev->data->dev_conf.intr_conf.lsc != 0)
     691                 :          0 :                         PMD_INIT_LOG(INFO, "lsc won't enable because of"
     692                 :            :                                      " no intr multiplexn");
     693                 :            :         }
     694                 :            :         /* check if rxq interrupt is enabled */
     695         [ #  # ]:          0 :         if (dev->data->dev_conf.intr_conf.rxq != 0)
     696                 :            :                 eth_em_rxq_interrupt_setup(dev);
     697                 :            : 
     698                 :          0 :         rte_intr_enable(intr_handle);
     699                 :            : 
     700                 :          0 :         adapter->stopped = 0;
     701                 :            : 
     702                 :          0 :         eth_em_rxtx_control(dev, true);
     703                 :          0 :         eth_em_link_update(dev, 0);
     704                 :            : 
     705                 :          0 :         PMD_INIT_LOG(DEBUG, "<<");
     706                 :            : 
     707                 :          0 :         return 0;
     708                 :            : 
     709                 :          0 : error_invalid_config:
     710                 :          0 :         PMD_INIT_LOG(ERR, "Invalid advertised speeds (%u) for port %u",
     711                 :            :                      dev->data->dev_conf.link_speeds, dev->data->port_id);
     712                 :          0 :         em_dev_clear_queues(dev);
     713                 :          0 :         return -EINVAL;
     714                 :            : }
     715                 :            : 
     716                 :            : /*********************************************************************
     717                 :            :  *
     718                 :            :  *  This routine disables all traffic on the adapter by issuing a
     719                 :            :  *  global reset on the MAC.
     720                 :            :  *
     721                 :            :  **********************************************************************/
     722                 :            : static int
     723                 :          0 : eth_em_stop(struct rte_eth_dev *dev)
     724                 :            : {
     725                 :            :         struct rte_eth_link link;
     726                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     727                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     728                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     729                 :            : 
     730                 :          0 :         dev->data->dev_started = 0;
     731                 :            : 
     732                 :          0 :         eth_em_rxtx_control(dev, false);
     733                 :            :         em_rxq_intr_disable(hw);
     734                 :            :         em_lsc_intr_disable(hw);
     735                 :            : 
     736                 :          0 :         e1000_reset_hw(hw);
     737                 :            : 
     738                 :            :         /* Flush desc rings for i219 */
     739         [ #  # ]:          0 :         if (hw->mac.type == e1000_pch_spt || hw->mac.type == e1000_pch_cnp)
     740                 :          0 :                 em_flush_desc_rings(dev);
     741                 :            : 
     742         [ #  # ]:          0 :         if (hw->mac.type >= e1000_82544)
     743                 :          0 :                 E1000_WRITE_REG(hw, E1000_WUC, 0);
     744                 :            : 
     745                 :            :         /* Power down the phy. Needed to make the link go down */
     746                 :          0 :         e1000_power_down_phy(hw);
     747                 :            : 
     748                 :          0 :         em_dev_clear_queues(dev);
     749                 :            : 
     750                 :            :         /* clear the recorded link status */
     751                 :            :         memset(&link, 0, sizeof(link));
     752                 :          0 :         rte_eth_linkstatus_set(dev, &link);
     753                 :            : 
     754         [ #  # ]:          0 :         if (!rte_intr_allow_others(intr_handle))
     755                 :            :                 /* resume to the default handler */
     756                 :          0 :                 rte_intr_callback_register(intr_handle,
     757                 :            :                                            eth_em_interrupt_handler,
     758                 :            :                                            (void *)dev);
     759                 :            : 
     760                 :            :         /* Clean datapath event and queue/vec mapping */
     761                 :          0 :         rte_intr_efd_disable(intr_handle);
     762                 :          0 :         rte_intr_vec_list_free(intr_handle);
     763                 :            : 
     764                 :          0 :         return 0;
     765                 :            : }
     766                 :            : 
     767                 :            : static int
     768                 :          0 : eth_em_close(struct rte_eth_dev *dev)
     769                 :            : {
     770                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     771                 :            :         struct e1000_adapter *adapter =
     772                 :            :                 E1000_DEV_PRIVATE(dev->data->dev_private);
     773                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
     774                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
     775                 :            :         int ret;
     776                 :            : 
     777         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     778                 :            :                 return 0;
     779                 :            : 
     780                 :          0 :         ret = eth_em_stop(dev);
     781                 :          0 :         adapter->stopped = 1;
     782                 :          0 :         em_dev_free_queues(dev);
     783                 :          0 :         e1000_phy_hw_reset(hw);
     784                 :          0 :         em_release_manageability(hw);
     785                 :            :         em_hw_control_release(hw);
     786                 :            : 
     787                 :            :         /* disable uio intr before callback unregister */
     788                 :          0 :         rte_intr_disable(intr_handle);
     789                 :          0 :         rte_intr_callback_unregister(intr_handle,
     790                 :            :                                      eth_em_interrupt_handler, dev);
     791                 :            : 
     792                 :          0 :         return ret;
     793                 :            : }
     794                 :            : 
     795                 :            : static int
     796                 :            : em_get_rx_buffer_size(struct e1000_hw *hw)
     797                 :            : {
     798                 :            :         uint32_t rx_buf_size;
     799                 :            : 
     800                 :          0 :         rx_buf_size = ((E1000_READ_REG(hw, E1000_PBA) & UINT16_MAX) << 10);
     801                 :            :         return rx_buf_size;
     802                 :            : }
     803                 :            : 
     804                 :            : /*********************************************************************
     805                 :            :  *
     806                 :            :  *  Initialize the hardware
     807                 :            :  *
     808                 :            :  **********************************************************************/
     809                 :            : static int
     810                 :          0 : em_hardware_init(struct e1000_hw *hw)
     811                 :            : {
     812                 :            :         uint32_t rx_buf_size;
     813                 :            :         int diag;
     814                 :            : 
     815                 :            :         /* Issue a global reset */
     816                 :          0 :         e1000_reset_hw(hw);
     817                 :            : 
     818                 :            :         /* Let the firmware know the OS is in control */
     819                 :            :         em_hw_control_acquire(hw);
     820                 :            : 
     821                 :            :         /*
     822                 :            :          * These parameters control the automatic generation (Tx) and
     823                 :            :          * response (Rx) to Ethernet PAUSE frames.
     824                 :            :          * - High water mark should allow for at least two standard size (1518)
     825                 :            :          *   frames to be received after sending an XOFF.
     826                 :            :          * - Low water mark works best when it is very near the high water mark.
     827                 :            :          *   This allows the receiver to restart by sending XON when it has
     828                 :            :          *   drained a bit. Here we use an arbitrary value of 1500 which will
     829                 :            :          *   restart after one full frame is pulled from the buffer. There
     830                 :            :          *   could be several smaller frames in the buffer and if so they will
     831                 :            :          *   not trigger the XON until their total number reduces the buffer
     832                 :            :          *   by 1500.
     833                 :            :          * - The pause time is fairly large at 1000 x 512ns = 512 usec.
     834                 :            :          */
     835                 :            :         rx_buf_size = em_get_rx_buffer_size(hw);
     836                 :            : 
     837                 :          0 :         hw->fc.high_water = rx_buf_size -
     838                 :            :                 PMD_ROUNDUP(RTE_ETHER_MAX_LEN * 2, 1024);
     839                 :          0 :         hw->fc.low_water = hw->fc.high_water - 1500;
     840                 :            : 
     841         [ #  # ]:          0 :         if (hw->mac.type == e1000_80003es2lan)
     842                 :          0 :                 hw->fc.pause_time = UINT16_MAX;
     843                 :            :         else
     844                 :          0 :                 hw->fc.pause_time = EM_FC_PAUSE_TIME;
     845                 :            : 
     846                 :          0 :         hw->fc.send_xon = 1;
     847                 :            : 
     848                 :            :         /* Set Flow control, use the tunable location if sane */
     849         [ #  # ]:          0 :         if (em_fc_setting <= e1000_fc_full)
     850                 :          0 :                 hw->fc.requested_mode = em_fc_setting;
     851                 :            :         else
     852                 :          0 :                 hw->fc.requested_mode = e1000_fc_none;
     853                 :            : 
     854                 :            :         /* Workaround: no TX flow ctrl for PCH */
     855         [ #  # ]:          0 :         if (hw->mac.type == e1000_pchlan)
     856                 :          0 :                 hw->fc.requested_mode = e1000_fc_rx_pause;
     857                 :            : 
     858                 :            :         /* Override - settings for PCH2LAN, ya its magic :) */
     859         [ #  # ]:          0 :         if (hw->mac.type == e1000_pch2lan) {
     860                 :          0 :                 hw->fc.high_water = 0x5C20;
     861                 :          0 :                 hw->fc.low_water = 0x5048;
     862                 :          0 :                 hw->fc.pause_time = 0x0650;
     863                 :          0 :                 hw->fc.refresh_time = 0x0400;
     864                 :          0 :         } else if (hw->mac.type == e1000_pch_lpt ||
     865                 :            :                    hw->mac.type == e1000_pch_spt ||
     866                 :            :                    hw->mac.type == e1000_pch_cnp ||
     867         [ #  # ]:          0 :                    hw->mac.type == e1000_pch_adp ||
     868                 :            :                    hw->mac.type == e1000_pch_tgp) {
     869                 :          0 :                 hw->fc.requested_mode = e1000_fc_full;
     870                 :            :         }
     871                 :            : 
     872                 :          0 :         diag = e1000_init_hw(hw);
     873         [ #  # ]:          0 :         if (diag < 0)
     874                 :            :                 return diag;
     875                 :          0 :         e1000_check_for_link(hw);
     876                 :          0 :         return 0;
     877                 :            : }
     878                 :            : 
     879                 :            : /* This function is based on em_update_stats_counters() in e1000/if_em.c */
     880                 :            : static int
     881                 :          0 : eth_em_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *rte_stats)
     882                 :            : {
     883                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
     884                 :            :         struct e1000_hw_stats *stats =
     885                 :            :                         E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
     886                 :            :         int pause_frames;
     887                 :            : 
     888         [ #  # ]:          0 :         if(hw->phy.media_type == e1000_media_type_copper ||
     889         [ #  # ]:          0 :                         (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
     890                 :          0 :                 stats->symerrs += E1000_READ_REG(hw,E1000_SYMERRS);
     891                 :          0 :                 stats->sec += E1000_READ_REG(hw, E1000_SEC);
     892                 :            :         }
     893                 :            : 
     894                 :          0 :         stats->crcerrs += E1000_READ_REG(hw, E1000_CRCERRS);
     895                 :          0 :         stats->mpc += E1000_READ_REG(hw, E1000_MPC);
     896                 :          0 :         stats->scc += E1000_READ_REG(hw, E1000_SCC);
     897                 :          0 :         stats->ecol += E1000_READ_REG(hw, E1000_ECOL);
     898                 :            : 
     899                 :          0 :         stats->mcc += E1000_READ_REG(hw, E1000_MCC);
     900                 :          0 :         stats->latecol += E1000_READ_REG(hw, E1000_LATECOL);
     901                 :          0 :         stats->colc += E1000_READ_REG(hw, E1000_COLC);
     902                 :          0 :         stats->dc += E1000_READ_REG(hw, E1000_DC);
     903                 :          0 :         stats->rlec += E1000_READ_REG(hw, E1000_RLEC);
     904                 :          0 :         stats->xonrxc += E1000_READ_REG(hw, E1000_XONRXC);
     905                 :          0 :         stats->xontxc += E1000_READ_REG(hw, E1000_XONTXC);
     906                 :            : 
     907                 :            :         /*
     908                 :            :          * For watchdog management we need to know if we have been
     909                 :            :          * paused during the last interval, so capture that here.
     910                 :            :          */
     911                 :          0 :         pause_frames = E1000_READ_REG(hw, E1000_XOFFRXC);
     912                 :          0 :         stats->xoffrxc += pause_frames;
     913                 :          0 :         stats->xofftxc += E1000_READ_REG(hw, E1000_XOFFTXC);
     914                 :          0 :         stats->fcruc += E1000_READ_REG(hw, E1000_FCRUC);
     915                 :          0 :         stats->prc64 += E1000_READ_REG(hw, E1000_PRC64);
     916                 :          0 :         stats->prc127 += E1000_READ_REG(hw, E1000_PRC127);
     917                 :          0 :         stats->prc255 += E1000_READ_REG(hw, E1000_PRC255);
     918                 :          0 :         stats->prc511 += E1000_READ_REG(hw, E1000_PRC511);
     919                 :          0 :         stats->prc1023 += E1000_READ_REG(hw, E1000_PRC1023);
     920                 :          0 :         stats->prc1522 += E1000_READ_REG(hw, E1000_PRC1522);
     921                 :          0 :         stats->gprc += E1000_READ_REG(hw, E1000_GPRC);
     922                 :          0 :         stats->bprc += E1000_READ_REG(hw, E1000_BPRC);
     923                 :          0 :         stats->mprc += E1000_READ_REG(hw, E1000_MPRC);
     924                 :          0 :         stats->gptc += E1000_READ_REG(hw, E1000_GPTC);
     925                 :            : 
     926                 :            :         /*
     927                 :            :          * For the 64-bit byte counters the low dword must be read first.
     928                 :            :          * Both registers clear on the read of the high dword.
     929                 :            :          */
     930                 :            : 
     931                 :          0 :         stats->gorc += E1000_READ_REG(hw, E1000_GORCL);
     932                 :          0 :         stats->gorc += ((uint64_t)E1000_READ_REG(hw, E1000_GORCH) << 32);
     933                 :          0 :         stats->gotc += E1000_READ_REG(hw, E1000_GOTCL);
     934                 :          0 :         stats->gotc += ((uint64_t)E1000_READ_REG(hw, E1000_GOTCH) << 32);
     935                 :            : 
     936                 :          0 :         stats->rnbc += E1000_READ_REG(hw, E1000_RNBC);
     937                 :          0 :         stats->ruc += E1000_READ_REG(hw, E1000_RUC);
     938                 :          0 :         stats->rfc += E1000_READ_REG(hw, E1000_RFC);
     939                 :          0 :         stats->roc += E1000_READ_REG(hw, E1000_ROC);
     940                 :          0 :         stats->rjc += E1000_READ_REG(hw, E1000_RJC);
     941                 :            : 
     942                 :          0 :         stats->tor += E1000_READ_REG(hw, E1000_TORH);
     943                 :          0 :         stats->tot += E1000_READ_REG(hw, E1000_TOTH);
     944                 :            : 
     945                 :          0 :         stats->tpr += E1000_READ_REG(hw, E1000_TPR);
     946                 :          0 :         stats->tpt += E1000_READ_REG(hw, E1000_TPT);
     947                 :          0 :         stats->ptc64 += E1000_READ_REG(hw, E1000_PTC64);
     948                 :          0 :         stats->ptc127 += E1000_READ_REG(hw, E1000_PTC127);
     949                 :          0 :         stats->ptc255 += E1000_READ_REG(hw, E1000_PTC255);
     950                 :          0 :         stats->ptc511 += E1000_READ_REG(hw, E1000_PTC511);
     951                 :          0 :         stats->ptc1023 += E1000_READ_REG(hw, E1000_PTC1023);
     952                 :          0 :         stats->ptc1522 += E1000_READ_REG(hw, E1000_PTC1522);
     953                 :          0 :         stats->mptc += E1000_READ_REG(hw, E1000_MPTC);
     954                 :          0 :         stats->bptc += E1000_READ_REG(hw, E1000_BPTC);
     955                 :            : 
     956                 :            :         /* Interrupt Counts */
     957                 :            : 
     958         [ #  # ]:          0 :         if (hw->mac.type >= e1000_82571) {
     959                 :          0 :                 stats->iac += E1000_READ_REG(hw, E1000_IAC);
     960                 :          0 :                 stats->icrxptc += E1000_READ_REG(hw, E1000_ICRXPTC);
     961                 :          0 :                 stats->icrxatc += E1000_READ_REG(hw, E1000_ICRXATC);
     962                 :          0 :                 stats->ictxptc += E1000_READ_REG(hw, E1000_ICTXPTC);
     963                 :          0 :                 stats->ictxatc += E1000_READ_REG(hw, E1000_ICTXATC);
     964                 :          0 :                 stats->ictxqec += E1000_READ_REG(hw, E1000_ICTXQEC);
     965                 :          0 :                 stats->ictxqmtc += E1000_READ_REG(hw, E1000_ICTXQMTC);
     966                 :          0 :                 stats->icrxdmtc += E1000_READ_REG(hw, E1000_ICRXDMTC);
     967                 :          0 :                 stats->icrxoc += E1000_READ_REG(hw, E1000_ICRXOC);
     968                 :            :         }
     969                 :            : 
     970         [ #  # ]:          0 :         if (hw->mac.type >= e1000_82543) {
     971                 :          0 :                 stats->algnerrc += E1000_READ_REG(hw, E1000_ALGNERRC);
     972                 :          0 :                 stats->rxerrc += E1000_READ_REG(hw, E1000_RXERRC);
     973                 :          0 :                 stats->tncrs += E1000_READ_REG(hw, E1000_TNCRS);
     974                 :          0 :                 stats->cexterr += E1000_READ_REG(hw, E1000_CEXTERR);
     975                 :          0 :                 stats->tsctc += E1000_READ_REG(hw, E1000_TSCTC);
     976                 :          0 :                 stats->tsctfc += E1000_READ_REG(hw, E1000_TSCTFC);
     977                 :            :         }
     978                 :            : 
     979         [ #  # ]:          0 :         if (rte_stats == NULL)
     980                 :            :                 return -EINVAL;
     981                 :            : 
     982                 :            :         /* Rx Errors */
     983                 :          0 :         rte_stats->imissed = stats->mpc;
     984                 :          0 :         rte_stats->ierrors = stats->crcerrs + stats->rlec +
     985                 :          0 :                              stats->rxerrc + stats->algnerrc + stats->cexterr;
     986                 :            : 
     987                 :            :         /* Tx Errors */
     988                 :          0 :         rte_stats->oerrors = stats->ecol + stats->latecol;
     989                 :            : 
     990                 :          0 :         rte_stats->ipackets = stats->gprc;
     991                 :          0 :         rte_stats->opackets = stats->gptc;
     992                 :          0 :         rte_stats->ibytes   = stats->gorc;
     993                 :          0 :         rte_stats->obytes   = stats->gotc;
     994                 :          0 :         return 0;
     995                 :            : }
     996                 :            : 
     997                 :            : static int
     998                 :          0 : eth_em_stats_reset(struct rte_eth_dev *dev)
     999                 :            : {
    1000                 :          0 :         struct e1000_hw_stats *hw_stats =
    1001                 :          0 :                         E1000_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
    1002                 :            : 
    1003                 :            :         /* HW registers are cleared on read */
    1004                 :          0 :         eth_em_stats_get(dev, NULL);
    1005                 :            : 
    1006                 :            :         /* Reset software totals */
    1007                 :            :         memset(hw_stats, 0, sizeof(*hw_stats));
    1008                 :            : 
    1009                 :          0 :         return 0;
    1010                 :            : }
    1011                 :            : 
    1012                 :            : static int
    1013                 :          0 : eth_em_rx_queue_intr_enable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
    1014                 :            : {
    1015                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1016                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1017                 :          0 :         struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
    1018                 :            : 
    1019                 :            :         em_rxq_intr_enable(hw);
    1020                 :          0 :         rte_intr_ack(intr_handle);
    1021                 :            : 
    1022                 :          0 :         return 0;
    1023                 :            : }
    1024                 :            : 
    1025                 :            : static int
    1026                 :          0 : eth_em_rx_queue_intr_disable(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id)
    1027                 :            : {
    1028                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1029                 :            : 
    1030                 :            :         em_rxq_intr_disable(hw);
    1031                 :            : 
    1032                 :          0 :         return 0;
    1033                 :            : }
    1034                 :            : 
    1035                 :            : uint32_t
    1036                 :          0 : em_get_max_pktlen(struct rte_eth_dev *dev)
    1037                 :            : {
    1038                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1039                 :            : 
    1040   [ #  #  #  # ]:          0 :         switch (hw->mac.type) {
    1041                 :            :         case e1000_82571:
    1042                 :            :         case e1000_82572:
    1043                 :            :         case e1000_ich9lan:
    1044                 :            :         case e1000_ich10lan:
    1045                 :            :         case e1000_pch2lan:
    1046                 :            :         case e1000_pch_lpt:
    1047                 :            :         case e1000_pch_spt:
    1048                 :            :         case e1000_pch_cnp:
    1049                 :            :         case e1000_pch_adp:
    1050                 :            :         case e1000_pch_tgp:
    1051                 :            :         case e1000_82574:
    1052                 :            :         case e1000_80003es2lan: /* 9K Jumbo Frame size */
    1053                 :            :         case e1000_82583:
    1054                 :            :                 return 0x2412;
    1055                 :          0 :         case e1000_pchlan:
    1056                 :          0 :                 return 0x1000;
    1057                 :            :         /* Adapters that do not support jumbo frames */
    1058                 :          0 :         case e1000_ich8lan:
    1059                 :          0 :                 return RTE_ETHER_MAX_LEN;
    1060                 :          0 :         default:
    1061                 :          0 :                 return MAX_JUMBO_FRAME_SIZE;
    1062                 :            :         }
    1063                 :            : }
    1064                 :            : 
    1065                 :            : static int
    1066                 :          0 : eth_em_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
    1067                 :            : {
    1068                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1069                 :            : 
    1070                 :          0 :         dev_info->min_rx_bufsize = 256; /* See BSIZE field of RCTL register. */
    1071                 :          0 :         dev_info->max_rx_pktlen = em_get_max_pktlen(dev);
    1072                 :          0 :         dev_info->max_mac_addrs = hw->mac.rar_entry_count;
    1073                 :            : 
    1074                 :            :         /*
    1075                 :            :          * Starting with 631xESB hw supports 2 TX/RX queues per port.
    1076                 :            :          * Unfortunately, all these nics have just one TX context.
    1077                 :            :          * So we have few choices for TX:
    1078                 :            :          * - Use just one TX queue.
    1079                 :            :          * - Allow cksum offload only for one TX queue.
    1080                 :            :          * - Don't allow TX cksum offload at all.
    1081                 :            :          * For now, option #1 was chosen.
    1082                 :            :          * To use second RX queue we have to use extended RX descriptor
    1083                 :            :          * (Multiple Receive Queues are mutually exclusive with UDP
    1084                 :            :          * fragmentation and are not supported when a legacy receive
    1085                 :            :          * descriptor format is used).
    1086                 :            :          * Which means separate RX routines - as legacy nics (82540, 82545)
    1087                 :            :          * don't support extended RXD.
    1088                 :            :          * To avoid it we support just one RX queue for now (no RSS).
    1089                 :            :          */
    1090                 :            : 
    1091                 :          0 :         dev_info->max_rx_queues = 2;
    1092                 :          0 :         dev_info->max_tx_queues = 2;
    1093                 :            : 
    1094                 :          0 :         dev_info->rx_queue_offload_capa = em_get_rx_queue_offloads_capa();
    1095                 :          0 :         dev_info->rx_offload_capa = em_get_rx_port_offloads_capa() |
    1096                 :          0 :                                     dev_info->rx_queue_offload_capa;
    1097                 :          0 :         dev_info->tx_queue_offload_capa = em_get_tx_queue_offloads_capa(dev);
    1098                 :          0 :         dev_info->tx_offload_capa = em_get_tx_port_offloads_capa(dev) |
    1099                 :          0 :                                     dev_info->tx_queue_offload_capa;
    1100                 :            : 
    1101                 :          0 :         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
    1102                 :            :                 .nb_max = E1000_MAX_RING_DESC,
    1103                 :            :                 .nb_min = E1000_MIN_RING_DESC,
    1104                 :            :                 .nb_align = EM_RXD_ALIGN,
    1105                 :            :         };
    1106                 :            : 
    1107                 :          0 :         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
    1108                 :            :                 .nb_max = E1000_MAX_RING_DESC,
    1109                 :            :                 .nb_min = E1000_MIN_RING_DESC,
    1110                 :            :                 .nb_align = EM_TXD_ALIGN,
    1111                 :            :                 .nb_seg_max = EM_TX_MAX_SEG,
    1112                 :            :                 .nb_mtu_seg_max = EM_TX_MAX_MTU_SEG,
    1113                 :            :         };
    1114                 :            : 
    1115                 :          0 :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_10M_HD | RTE_ETH_LINK_SPEED_10M |
    1116                 :            :                         RTE_ETH_LINK_SPEED_100M_HD | RTE_ETH_LINK_SPEED_100M |
    1117                 :            :                         RTE_ETH_LINK_SPEED_1G;
    1118                 :            : 
    1119                 :          0 :         dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
    1120                 :            : 
    1121                 :            :         /* Preferred queue parameters */
    1122                 :          0 :         dev_info->default_rxportconf.nb_queues = 1;
    1123                 :          0 :         dev_info->default_txportconf.nb_queues = 1;
    1124                 :          0 :         dev_info->default_txportconf.ring_size = 256;
    1125                 :          0 :         dev_info->default_rxportconf.ring_size = 256;
    1126                 :            : 
    1127                 :          0 :         return 0;
    1128                 :            : }
    1129                 :            : 
    1130                 :            : /* return 0 means link status changed, -1 means not changed */
    1131                 :            : static int
    1132                 :          0 : eth_em_link_update(struct rte_eth_dev *dev, int wait_to_complete)
    1133                 :            : {
    1134                 :          0 :         struct e1000_hw *hw =
    1135                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1136                 :            :         struct rte_eth_link link;
    1137                 :            :         int link_up, count;
    1138                 :            : 
    1139         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1140                 :            :                 return -1;
    1141                 :            : 
    1142                 :            :         link_up = 0;
    1143                 :          0 :         hw->mac.get_link_status = 1;
    1144                 :            : 
    1145                 :            :         /* possible wait-to-complete in up to 9 seconds */
    1146         [ #  # ]:          0 :         for (count = 0; count < EM_LINK_UPDATE_CHECK_TIMEOUT; count ++) {
    1147                 :            :                 /* Read the real link status */
    1148   [ #  #  #  # ]:          0 :                 switch (hw->phy.media_type) {
    1149                 :          0 :                 case e1000_media_type_copper:
    1150                 :            :                         /* Do the work to read phy */
    1151                 :          0 :                         e1000_check_for_link(hw);
    1152                 :          0 :                         link_up = !hw->mac.get_link_status;
    1153                 :          0 :                         break;
    1154                 :            : 
    1155                 :          0 :                 case e1000_media_type_fiber:
    1156                 :          0 :                         e1000_check_for_link(hw);
    1157                 :          0 :                         link_up = (E1000_READ_REG(hw, E1000_STATUS) &
    1158                 :            :                                         E1000_STATUS_LU);
    1159                 :          0 :                         break;
    1160                 :            : 
    1161                 :          0 :                 case e1000_media_type_internal_serdes:
    1162                 :          0 :                         e1000_check_for_link(hw);
    1163                 :          0 :                         link_up = hw->mac.serdes_has_link;
    1164                 :          0 :                         break;
    1165                 :            : 
    1166                 :            :                 default:
    1167                 :            :                         break;
    1168                 :            :                 }
    1169         [ #  # ]:          0 :                 if (link_up || wait_to_complete == 0)
    1170                 :            :                         break;
    1171                 :            :                 rte_delay_ms(EM_LINK_UPDATE_CHECK_INTERVAL);
    1172                 :            :         }
    1173                 :            :         memset(&link, 0, sizeof(link));
    1174                 :            : 
    1175                 :            :         /* Now we check if a transition has happened */
    1176         [ #  # ]:          0 :         if (link_up) {
    1177                 :            :                 uint16_t duplex, speed;
    1178                 :          0 :                 hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
    1179                 :          0 :                 link.link_duplex = (duplex == FULL_DUPLEX) ?
    1180                 :          0 :                                 RTE_ETH_LINK_FULL_DUPLEX :
    1181                 :            :                                 RTE_ETH_LINK_HALF_DUPLEX;
    1182                 :          0 :                 link.link_speed = speed;
    1183                 :          0 :                 link.link_status = RTE_ETH_LINK_UP;
    1184                 :          0 :                 link.link_autoneg = !(dev->data->dev_conf.link_speeds &
    1185                 :            :                                 RTE_ETH_LINK_SPEED_FIXED);
    1186                 :            :         } else {
    1187                 :            :                 link.link_speed = RTE_ETH_SPEED_NUM_NONE;
    1188                 :            :                 link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
    1189                 :            :                 link.link_status = RTE_ETH_LINK_DOWN;
    1190                 :            :                 link.link_autoneg = RTE_ETH_LINK_FIXED;
    1191                 :            :         }
    1192                 :            : 
    1193                 :            :         return rte_eth_linkstatus_set(dev, &link);
    1194                 :            : }
    1195                 :            : 
    1196                 :            : /*
    1197                 :            :  * em_hw_control_acquire sets {CTRL_EXT|FWSM}:DRV_LOAD bit.
    1198                 :            :  * For ASF and Pass Through versions of f/w this means
    1199                 :            :  * that the driver is loaded. For AMT version type f/w
    1200                 :            :  * this means that the network i/f is open.
    1201                 :            :  */
    1202                 :            : static void
    1203                 :            : em_hw_control_acquire(struct e1000_hw *hw)
    1204                 :            : {
    1205                 :            :         uint32_t ctrl_ext, swsm;
    1206                 :            : 
    1207                 :            :         /* Let firmware know the driver has taken over */
    1208         [ #  # ]:          0 :         if (hw->mac.type == e1000_82573) {
    1209                 :          0 :                 swsm = E1000_READ_REG(hw, E1000_SWSM);
    1210                 :          0 :                 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_DRV_LOAD);
    1211                 :            : 
    1212                 :            :         } else {
    1213                 :          0 :                 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
    1214                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
    1215                 :            :                         ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
    1216                 :            :         }
    1217                 :            : }
    1218                 :            : 
    1219                 :            : /*
    1220                 :            :  * em_hw_control_release resets {CTRL_EXTT|FWSM}:DRV_LOAD bit.
    1221                 :            :  * For ASF and Pass Through versions of f/w this means that the
    1222                 :            :  * driver is no longer loaded. For AMT versions of the
    1223                 :            :  * f/w this means that the network i/f is closed.
    1224                 :            :  */
    1225                 :            : static void
    1226                 :            : em_hw_control_release(struct e1000_hw *hw)
    1227                 :            : {
    1228                 :            :         uint32_t ctrl_ext, swsm;
    1229                 :            : 
    1230                 :            :         /* Let firmware taken over control of h/w */
    1231   [ #  #  #  # ]:          0 :         if (hw->mac.type == e1000_82573) {
    1232                 :          0 :                 swsm = E1000_READ_REG(hw, E1000_SWSM);
    1233                 :          0 :                 E1000_WRITE_REG(hw, E1000_SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
    1234                 :            :         } else {
    1235                 :          0 :                 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
    1236                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL_EXT,
    1237                 :            :                         ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
    1238                 :            :         }
    1239                 :            : }
    1240                 :            : 
    1241                 :            : /*
    1242                 :            :  * Bit of a misnomer, what this really means is
    1243                 :            :  * to enable OS management of the system... aka
    1244                 :            :  * to disable special hardware management features.
    1245                 :            :  */
    1246                 :            : static void
    1247                 :          0 : em_init_manageability(struct e1000_hw *hw)
    1248                 :            : {
    1249         [ #  # ]:          0 :         if (e1000_enable_mng_pass_thru(hw)) {
    1250                 :          0 :                 uint32_t manc2h = E1000_READ_REG(hw, E1000_MANC2H);
    1251                 :          0 :                 uint32_t manc = E1000_READ_REG(hw, E1000_MANC);
    1252                 :            : 
    1253                 :            :                 /* disable hardware interception of ARP */
    1254                 :          0 :                 manc &= ~(E1000_MANC_ARP_EN);
    1255                 :            : 
    1256                 :            :                 /* enable receiving management packets to the host */
    1257                 :          0 :                 manc |= E1000_MANC_EN_MNG2HOST;
    1258                 :            :                 manc2h |= 1 << 5;  /* Mng Port 623 */
    1259                 :          0 :                 manc2h |= 1 << 6;  /* Mng Port 664 */
    1260                 :          0 :                 E1000_WRITE_REG(hw, E1000_MANC2H, manc2h);
    1261                 :          0 :                 E1000_WRITE_REG(hw, E1000_MANC, manc);
    1262                 :            :         }
    1263                 :          0 : }
    1264                 :            : 
    1265                 :            : /*
    1266                 :            :  * Give control back to hardware management
    1267                 :            :  * controller if there is one.
    1268                 :            :  */
    1269                 :            : static void
    1270                 :          0 : em_release_manageability(struct e1000_hw *hw)
    1271                 :            : {
    1272                 :            :         uint32_t manc;
    1273                 :            : 
    1274         [ #  # ]:          0 :         if (e1000_enable_mng_pass_thru(hw)) {
    1275                 :          0 :                 manc = E1000_READ_REG(hw, E1000_MANC);
    1276                 :            : 
    1277                 :            :                 /* re-enable hardware interception of ARP */
    1278                 :            :                 manc |= E1000_MANC_ARP_EN;
    1279                 :          0 :                 manc &= ~E1000_MANC_EN_MNG2HOST;
    1280                 :            : 
    1281                 :          0 :                 E1000_WRITE_REG(hw, E1000_MANC, manc);
    1282                 :            :         }
    1283                 :          0 : }
    1284                 :            : 
    1285                 :            : static int
    1286                 :          0 : eth_em_promiscuous_enable(struct rte_eth_dev *dev)
    1287                 :            : {
    1288                 :            :         struct e1000_hw *hw =
    1289                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1290                 :            :         uint32_t rctl;
    1291                 :            : 
    1292                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    1293                 :          0 :         rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
    1294                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1295                 :            : 
    1296                 :          0 :         return 0;
    1297                 :            : }
    1298                 :            : 
    1299                 :            : static int
    1300                 :          0 : eth_em_promiscuous_disable(struct rte_eth_dev *dev)
    1301                 :            : {
    1302                 :            :         struct e1000_hw *hw =
    1303                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1304                 :            :         uint32_t rctl;
    1305                 :            : 
    1306                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    1307                 :          0 :         rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_SBP);
    1308         [ #  # ]:          0 :         if (dev->data->all_multicast == 1)
    1309                 :          0 :                 rctl |= E1000_RCTL_MPE;
    1310                 :            :         else
    1311                 :          0 :                 rctl &= (~E1000_RCTL_MPE);
    1312                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1313                 :            : 
    1314                 :          0 :         return 0;
    1315                 :            : }
    1316                 :            : 
    1317                 :            : static int
    1318                 :          0 : eth_em_allmulticast_enable(struct rte_eth_dev *dev)
    1319                 :            : {
    1320                 :            :         struct e1000_hw *hw =
    1321                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1322                 :            :         uint32_t rctl;
    1323                 :            : 
    1324                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    1325                 :          0 :         rctl |= E1000_RCTL_MPE;
    1326                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1327                 :            : 
    1328                 :          0 :         return 0;
    1329                 :            : }
    1330                 :            : 
    1331                 :            : static int
    1332                 :          0 : eth_em_allmulticast_disable(struct rte_eth_dev *dev)
    1333                 :            : {
    1334                 :            :         struct e1000_hw *hw =
    1335                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1336                 :            :         uint32_t rctl;
    1337                 :            : 
    1338         [ #  # ]:          0 :         if (dev->data->promiscuous == 1)
    1339                 :            :                 return 0; /* must remain in all_multicast mode */
    1340                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    1341                 :          0 :         rctl &= (~E1000_RCTL_MPE);
    1342                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1343                 :            : 
    1344                 :          0 :         return 0;
    1345                 :            : }
    1346                 :            : 
    1347                 :            : static int
    1348                 :          0 : eth_em_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
    1349                 :            : {
    1350                 :            :         struct e1000_hw *hw =
    1351                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1352                 :            :         struct e1000_vfta * shadow_vfta =
    1353                 :            :                 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    1354                 :            :         uint32_t vfta;
    1355                 :            :         uint32_t vid_idx;
    1356                 :            :         uint32_t vid_bit;
    1357                 :            : 
    1358                 :          0 :         vid_idx = (uint32_t) ((vlan_id >> E1000_VFTA_ENTRY_SHIFT) &
    1359                 :            :                               E1000_VFTA_ENTRY_MASK);
    1360                 :          0 :         vid_bit = (uint32_t) (1 << (vlan_id & E1000_VFTA_ENTRY_BIT_SHIFT_MASK));
    1361                 :          0 :         vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, vid_idx);
    1362         [ #  # ]:          0 :         if (on)
    1363                 :          0 :                 vfta |= vid_bit;
    1364                 :            :         else
    1365                 :          0 :                 vfta &= ~vid_bit;
    1366                 :          0 :         E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, vid_idx, vfta);
    1367                 :            : 
    1368                 :            :         /* update local VFTA copy */
    1369                 :          0 :         shadow_vfta->vfta[vid_idx] = vfta;
    1370                 :            : 
    1371                 :          0 :         return 0;
    1372                 :            : }
    1373                 :            : 
    1374                 :            : static void
    1375                 :            : em_vlan_hw_filter_disable(struct rte_eth_dev *dev)
    1376                 :            : {
    1377                 :            :         struct e1000_hw *hw =
    1378                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1379                 :            :         uint32_t reg;
    1380                 :            : 
    1381                 :            :         /* Filter Table Disable */
    1382                 :          0 :         reg = E1000_READ_REG(hw, E1000_RCTL);
    1383                 :            :         reg &= ~E1000_RCTL_CFIEN;
    1384                 :          0 :         reg &= ~E1000_RCTL_VFE;
    1385                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, reg);
    1386                 :          0 : }
    1387                 :            : 
    1388                 :            : static void
    1389                 :          0 : em_vlan_hw_filter_enable(struct rte_eth_dev *dev)
    1390                 :            : {
    1391                 :            :         struct e1000_hw *hw =
    1392                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1393                 :            :         struct e1000_vfta * shadow_vfta =
    1394                 :            :                 E1000_DEV_PRIVATE_TO_VFTA(dev->data->dev_private);
    1395                 :            :         uint32_t reg;
    1396                 :            :         int i;
    1397                 :            : 
    1398                 :            :         /* Filter Table Enable, CFI not used for packet acceptance */
    1399                 :          0 :         reg = E1000_READ_REG(hw, E1000_RCTL);
    1400                 :          0 :         reg &= ~E1000_RCTL_CFIEN;
    1401                 :          0 :         reg |= E1000_RCTL_VFE;
    1402                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, reg);
    1403                 :            : 
    1404                 :            :         /* restore vfta from local copy */
    1405         [ #  # ]:          0 :         for (i = 0; i < IGB_VFTA_SIZE; i++)
    1406                 :          0 :                 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, i, shadow_vfta->vfta[i]);
    1407                 :          0 : }
    1408                 :            : 
    1409                 :            : static void
    1410                 :            : em_vlan_hw_strip_disable(struct rte_eth_dev *dev)
    1411                 :            : {
    1412                 :            :         struct e1000_hw *hw =
    1413                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1414                 :            :         uint32_t reg;
    1415                 :            : 
    1416                 :            :         /* VLAN Mode Disable */
    1417                 :          0 :         reg = E1000_READ_REG(hw, E1000_CTRL);
    1418                 :          0 :         reg &= ~E1000_CTRL_VME;
    1419                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, reg);
    1420                 :            : 
    1421                 :          0 : }
    1422                 :            : 
    1423                 :            : static void
    1424                 :            : em_vlan_hw_strip_enable(struct rte_eth_dev *dev)
    1425                 :            : {
    1426                 :            :         struct e1000_hw *hw =
    1427                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1428                 :            :         uint32_t reg;
    1429                 :            : 
    1430                 :            :         /* VLAN Mode Enable */
    1431                 :          0 :         reg = E1000_READ_REG(hw, E1000_CTRL);
    1432                 :          0 :         reg |= E1000_CTRL_VME;
    1433                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, reg);
    1434                 :          0 : }
    1435                 :            : 
    1436                 :            : static int
    1437                 :          0 : eth_em_vlan_offload_set(struct rte_eth_dev *dev, int mask)
    1438                 :            : {
    1439                 :            :         struct rte_eth_rxmode *rxmode;
    1440                 :            : 
    1441                 :          0 :         rxmode = &dev->data->dev_conf.rxmode;
    1442         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_STRIP_MASK) {
    1443         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
    1444                 :            :                         em_vlan_hw_strip_enable(dev);
    1445                 :            :                 else
    1446                 :            :                         em_vlan_hw_strip_disable(dev);
    1447                 :            :         }
    1448                 :            : 
    1449         [ #  # ]:          0 :         if (mask & RTE_ETH_VLAN_FILTER_MASK) {
    1450         [ #  # ]:          0 :                 if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
    1451                 :          0 :                         em_vlan_hw_filter_enable(dev);
    1452                 :            :                 else
    1453                 :            :                         em_vlan_hw_filter_disable(dev);
    1454                 :            :         }
    1455                 :            : 
    1456                 :          0 :         return 0;
    1457                 :            : }
    1458                 :            : 
    1459                 :            : /*
    1460                 :            :  * It enables the interrupt mask and then enable the interrupt.
    1461                 :            :  *
    1462                 :            :  * @param dev
    1463                 :            :  *  Pointer to struct rte_eth_dev.
    1464                 :            :  *
    1465                 :            :  * @return
    1466                 :            :  *  - On success, zero.
    1467                 :            :  *  - On failure, a negative value.
    1468                 :            :  */
    1469                 :            : static int
    1470                 :            : eth_em_interrupt_setup(struct rte_eth_dev *dev)
    1471                 :            : {
    1472                 :            :         uint32_t regval;
    1473                 :            :         struct e1000_hw *hw =
    1474                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1475                 :            : 
    1476                 :            :         /* clear interrupt */
    1477                 :          0 :         E1000_READ_REG(hw, E1000_ICR);
    1478                 :          0 :         regval = E1000_READ_REG(hw, E1000_IMS);
    1479                 :          0 :         E1000_WRITE_REG(hw, E1000_IMS,
    1480                 :            :                         regval | E1000_ICR_LSC | E1000_ICR_OTHER);
    1481                 :            :         return 0;
    1482                 :            : }
    1483                 :            : 
    1484                 :            : /*
    1485                 :            :  * It clears the interrupt causes and enables the interrupt.
    1486                 :            :  * It will be called once only during nic initialized.
    1487                 :            :  *
    1488                 :            :  * @param dev
    1489                 :            :  *  Pointer to struct rte_eth_dev.
    1490                 :            :  *
    1491                 :            :  * @return
    1492                 :            :  *  - On success, zero.
    1493                 :            :  *  - On failure, a negative value.
    1494                 :            :  */
    1495                 :            : static int
    1496                 :            : eth_em_rxq_interrupt_setup(struct rte_eth_dev *dev)
    1497                 :            : {
    1498                 :            :         struct e1000_hw *hw =
    1499                 :          0 :         E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1500                 :            : 
    1501                 :          0 :         E1000_READ_REG(hw, E1000_ICR);
    1502                 :            :         em_rxq_intr_enable(hw);
    1503                 :          0 :         return 0;
    1504                 :            : }
    1505                 :            : 
    1506                 :            : /*
    1507                 :            :  * It enable receive packet interrupt.
    1508                 :            :  * @param hw
    1509                 :            :  * Pointer to struct e1000_hw
    1510                 :            :  *
    1511                 :            :  * @return
    1512                 :            :  */
    1513                 :            : static void
    1514                 :            : em_rxq_intr_enable(struct e1000_hw *hw)
    1515                 :            : {
    1516                 :          0 :         E1000_WRITE_REG(hw, E1000_IMS, E1000_IMS_RXT0);
    1517                 :          0 :         E1000_WRITE_FLUSH(hw);
    1518                 :          0 : }
    1519                 :            : 
    1520                 :            : /*
    1521                 :            :  * It disabled lsc interrupt.
    1522                 :            :  * @param hw
    1523                 :            :  * Pointer to struct e1000_hw
    1524                 :            :  *
    1525                 :            :  * @return
    1526                 :            :  */
    1527                 :            : static void
    1528                 :            : em_lsc_intr_disable(struct e1000_hw *hw)
    1529                 :            : {
    1530                 :          0 :         E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_LSC | E1000_IMS_OTHER);
    1531                 :          0 :         E1000_WRITE_FLUSH(hw);
    1532                 :            : }
    1533                 :            : 
    1534                 :            : /*
    1535                 :            :  * It disabled receive packet interrupt.
    1536                 :            :  * @param hw
    1537                 :            :  * Pointer to struct e1000_hw
    1538                 :            :  *
    1539                 :            :  * @return
    1540                 :            :  */
    1541                 :            : static void
    1542                 :            : em_rxq_intr_disable(struct e1000_hw *hw)
    1543                 :            : {
    1544                 :          0 :         E1000_READ_REG(hw, E1000_ICR);
    1545                 :          0 :         E1000_WRITE_REG(hw, E1000_IMC, E1000_IMS_RXT0);
    1546                 :          0 :         E1000_WRITE_FLUSH(hw);
    1547                 :            : }
    1548                 :            : 
    1549                 :            : /*
    1550                 :            :  * It reads ICR and gets interrupt causes, check it and set a bit flag
    1551                 :            :  * to update link status.
    1552                 :            :  *
    1553                 :            :  * @param dev
    1554                 :            :  *  Pointer to struct rte_eth_dev.
    1555                 :            :  *
    1556                 :            :  * @return
    1557                 :            :  *  - On success, zero.
    1558                 :            :  *  - On failure, a negative value.
    1559                 :            :  */
    1560                 :            : static int
    1561                 :            : eth_em_interrupt_get_status(struct rte_eth_dev *dev)
    1562                 :            : {
    1563                 :            :         uint32_t icr;
    1564                 :            :         struct e1000_hw *hw =
    1565                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1566                 :            :         struct e1000_interrupt *intr =
    1567                 :            :                 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    1568                 :            : 
    1569                 :            :         /* read-on-clear nic registers here */
    1570                 :          0 :         icr = E1000_READ_REG(hw, E1000_ICR);
    1571         [ #  # ]:          0 :         if (icr & E1000_ICR_LSC) {
    1572                 :          0 :                 intr->flags |= E1000_FLAG_NEED_LINK_UPDATE;
    1573                 :            :         }
    1574                 :            : 
    1575                 :            :         return 0;
    1576                 :            : }
    1577                 :            : 
    1578                 :            : /*
    1579                 :            :  * It executes link_update after knowing an interrupt is present.
    1580                 :            :  *
    1581                 :            :  * @param dev
    1582                 :            :  *  Pointer to struct rte_eth_dev.
    1583                 :            :  *
    1584                 :            :  * @return
    1585                 :            :  *  - On success, zero.
    1586                 :            :  *  - On failure, a negative value.
    1587                 :            :  */
    1588                 :            : static int
    1589                 :          0 : eth_em_interrupt_action(struct rte_eth_dev *dev,
    1590                 :            :                         struct rte_intr_handle *intr_handle)
    1591                 :            : {
    1592                 :          0 :         struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
    1593                 :            :         struct e1000_hw *hw =
    1594                 :          0 :                 E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1595                 :            :         struct e1000_interrupt *intr =
    1596                 :            :                 E1000_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
    1597                 :            :         struct rte_eth_link link;
    1598                 :            :         int ret;
    1599                 :            : 
    1600         [ #  # ]:          0 :         if (!(intr->flags & E1000_FLAG_NEED_LINK_UPDATE))
    1601                 :            :                 return -1;
    1602                 :            : 
    1603                 :          0 :         intr->flags &= ~E1000_FLAG_NEED_LINK_UPDATE;
    1604                 :          0 :         rte_intr_ack(intr_handle);
    1605                 :            : 
    1606                 :            :         /* set get_link_status to check register later */
    1607                 :          0 :         hw->mac.get_link_status = 1;
    1608                 :          0 :         ret = eth_em_link_update(dev, 0);
    1609                 :            : 
    1610                 :            :         /* check if link has changed */
    1611         [ #  # ]:          0 :         if (ret < 0)
    1612                 :            :                 return 0;
    1613                 :            : 
    1614                 :          0 :         rte_eth_linkstatus_get(dev, &link);
    1615                 :            : 
    1616         [ #  # ]:          0 :         if (link.link_status) {
    1617         [ #  # ]:          0 :                 PMD_INIT_LOG(INFO, " Port %d: Link Up - speed %u Mbps - %s",
    1618                 :            :                              dev->data->port_id, link.link_speed,
    1619                 :            :                              link.link_duplex == RTE_ETH_LINK_FULL_DUPLEX ?
    1620                 :            :                              "full-duplex" : "half-duplex");
    1621                 :            :         } else {
    1622                 :          0 :                 PMD_INIT_LOG(INFO, " Port %d: Link Down", dev->data->port_id);
    1623                 :            :         }
    1624                 :          0 :         PMD_INIT_LOG(DEBUG, "PCI Address: " PCI_PRI_FMT,
    1625                 :            :                      pci_dev->addr.domain, pci_dev->addr.bus,
    1626                 :            :                      pci_dev->addr.devid, pci_dev->addr.function);
    1627                 :            : 
    1628                 :          0 :         return 0;
    1629                 :            : }
    1630                 :            : 
    1631                 :            : /**
    1632                 :            :  * Interrupt handler which shall be registered at first.
    1633                 :            :  *
    1634                 :            :  * @param handle
    1635                 :            :  *  Pointer to interrupt handle.
    1636                 :            :  * @param param
    1637                 :            :  *  The address of parameter (struct rte_eth_dev *) registered before.
    1638                 :            :  *
    1639                 :            :  * @return
    1640                 :            :  *  void
    1641                 :            :  */
    1642                 :            : static void
    1643                 :          0 : eth_em_interrupt_handler(void *param)
    1644                 :            : {
    1645                 :            :         struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
    1646                 :            : 
    1647                 :            :         eth_em_interrupt_get_status(dev);
    1648                 :          0 :         eth_em_interrupt_action(dev, dev->intr_handle);
    1649                 :          0 :         rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
    1650                 :          0 : }
    1651                 :            : 
    1652                 :            : static int
    1653                 :          0 : eth_em_led_on(struct rte_eth_dev *dev)
    1654                 :            : {
    1655                 :            :         struct e1000_hw *hw;
    1656                 :            : 
    1657                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1658         [ #  # ]:          0 :         return e1000_led_on(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
    1659                 :            : }
    1660                 :            : 
    1661                 :            : static int
    1662                 :          0 : eth_em_led_off(struct rte_eth_dev *dev)
    1663                 :            : {
    1664                 :            :         struct e1000_hw *hw;
    1665                 :            : 
    1666                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1667         [ #  # ]:          0 :         return e1000_led_off(hw) == E1000_SUCCESS ? 0 : -ENOTSUP;
    1668                 :            : }
    1669                 :            : 
    1670                 :            : static int
    1671                 :          0 : eth_em_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    1672                 :            : {
    1673                 :            :         struct e1000_hw *hw;
    1674                 :            :         uint32_t ctrl;
    1675                 :            :         int tx_pause;
    1676                 :            :         int rx_pause;
    1677                 :            : 
    1678                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1679                 :          0 :         fc_conf->pause_time = hw->fc.pause_time;
    1680                 :          0 :         fc_conf->high_water = hw->fc.high_water;
    1681                 :          0 :         fc_conf->low_water = hw->fc.low_water;
    1682                 :          0 :         fc_conf->send_xon = hw->fc.send_xon;
    1683                 :          0 :         fc_conf->autoneg = hw->mac.autoneg;
    1684                 :            : 
    1685                 :            :         /*
    1686                 :            :          * Return rx_pause and tx_pause status according to actual setting of
    1687                 :            :          * the TFCE and RFCE bits in the CTRL register.
    1688                 :            :          */
    1689                 :          0 :         ctrl = E1000_READ_REG(hw, E1000_CTRL);
    1690         [ #  # ]:          0 :         if (ctrl & E1000_CTRL_TFCE)
    1691                 :            :                 tx_pause = 1;
    1692                 :            :         else
    1693                 :            :                 tx_pause = 0;
    1694                 :            : 
    1695         [ #  # ]:          0 :         if (ctrl & E1000_CTRL_RFCE)
    1696                 :            :                 rx_pause = 1;
    1697                 :            :         else
    1698                 :            :                 rx_pause = 0;
    1699                 :            : 
    1700         [ #  # ]:          0 :         if (rx_pause && tx_pause)
    1701                 :          0 :                 fc_conf->mode = RTE_ETH_FC_FULL;
    1702         [ #  # ]:          0 :         else if (rx_pause)
    1703                 :          0 :                 fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
    1704         [ #  # ]:          0 :         else if (tx_pause)
    1705                 :          0 :                 fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
    1706                 :            :         else
    1707                 :          0 :                 fc_conf->mode = RTE_ETH_FC_NONE;
    1708                 :            : 
    1709                 :          0 :         return 0;
    1710                 :            : }
    1711                 :            : 
    1712                 :            : static int
    1713                 :          0 : eth_em_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
    1714                 :            : {
    1715                 :            :         struct e1000_hw *hw;
    1716                 :            :         int err;
    1717                 :          0 :         enum e1000_fc_mode rte_fcmode_2_e1000_fcmode[] = {
    1718                 :            :                 e1000_fc_none,
    1719                 :            :                 e1000_fc_rx_pause,
    1720                 :            :                 e1000_fc_tx_pause,
    1721                 :            :                 e1000_fc_full
    1722                 :            :         };
    1723                 :            :         uint32_t rx_buf_size;
    1724                 :            :         uint32_t max_high_water;
    1725                 :            :         uint32_t rctl;
    1726                 :            : 
    1727                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1728         [ #  # ]:          0 :         if (fc_conf->autoneg != hw->mac.autoneg)
    1729                 :            :                 return -ENOTSUP;
    1730                 :            :         rx_buf_size = em_get_rx_buffer_size(hw);
    1731                 :          0 :         PMD_INIT_LOG(DEBUG, "Rx packet buffer size = 0x%x", rx_buf_size);
    1732                 :            : 
    1733                 :            :         /* At least reserve one Ethernet frame for watermark */
    1734                 :          0 :         max_high_water = rx_buf_size - RTE_ETHER_MAX_LEN;
    1735         [ #  # ]:          0 :         if ((fc_conf->high_water > max_high_water) ||
    1736         [ #  # ]:          0 :             (fc_conf->high_water < fc_conf->low_water)) {
    1737                 :          0 :                 PMD_INIT_LOG(ERR, "e1000 incorrect high/low water value");
    1738                 :          0 :                 PMD_INIT_LOG(ERR, "high water must <= 0x%x", max_high_water);
    1739                 :          0 :                 return -EINVAL;
    1740                 :            :         }
    1741                 :            : 
    1742                 :          0 :         hw->fc.requested_mode = rte_fcmode_2_e1000_fcmode[fc_conf->mode];
    1743                 :          0 :         hw->fc.pause_time     = fc_conf->pause_time;
    1744                 :          0 :         hw->fc.high_water     = fc_conf->high_water;
    1745                 :          0 :         hw->fc.low_water      = fc_conf->low_water;
    1746                 :          0 :         hw->fc.send_xon            = fc_conf->send_xon;
    1747                 :            : 
    1748                 :          0 :         err = e1000_setup_link_generic(hw);
    1749         [ #  # ]:          0 :         if (err == E1000_SUCCESS) {
    1750                 :            : 
    1751                 :            :                 /* check if we want to forward MAC frames - driver doesn't have native
    1752                 :            :                  * capability to do that, so we'll write the registers ourselves */
    1753                 :            : 
    1754                 :          0 :                 rctl = E1000_READ_REG(hw, E1000_RCTL);
    1755                 :            : 
    1756                 :            :                 /* set or clear MFLCN.PMCF bit depending on configuration */
    1757         [ #  # ]:          0 :                 if (fc_conf->mac_ctrl_frame_fwd != 0)
    1758                 :          0 :                         rctl |= E1000_RCTL_PMCF;
    1759                 :            :                 else
    1760                 :          0 :                         rctl &= ~E1000_RCTL_PMCF;
    1761                 :            : 
    1762                 :          0 :                 E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1763                 :          0 :                 E1000_WRITE_FLUSH(hw);
    1764                 :            : 
    1765                 :          0 :                 return 0;
    1766                 :            :         }
    1767                 :            : 
    1768                 :          0 :         PMD_INIT_LOG(ERR, "e1000_setup_link_generic = 0x%x", err);
    1769                 :          0 :         return -EIO;
    1770                 :            : }
    1771                 :            : 
    1772                 :            : static int
    1773                 :          0 : eth_em_rar_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
    1774                 :            :                 uint32_t index, __rte_unused uint32_t pool)
    1775                 :            : {
    1776                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1777                 :            : 
    1778                 :          0 :         return e1000_rar_set(hw, mac_addr->addr_bytes, index);
    1779                 :            : }
    1780                 :            : 
    1781                 :            : static void
    1782                 :          0 : eth_em_rar_clear(struct rte_eth_dev *dev, uint32_t index)
    1783                 :            : {
    1784                 :            :         uint8_t addr[RTE_ETHER_ADDR_LEN];
    1785                 :          0 :         struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1786                 :            : 
    1787                 :            :         memset(addr, 0, sizeof(addr));
    1788                 :            : 
    1789                 :          0 :         e1000_rar_set(hw, addr, index);
    1790                 :          0 : }
    1791                 :            : 
    1792                 :            : static int
    1793                 :          0 : eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
    1794                 :            :                             struct rte_ether_addr *addr)
    1795                 :            : {
    1796                 :          0 :         eth_em_rar_clear(dev, 0);
    1797                 :            : 
    1798                 :          0 :         return eth_em_rar_set(dev, (void *)addr, 0, 0);
    1799                 :            : }
    1800                 :            : 
    1801                 :            : static int
    1802                 :          0 : eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
    1803                 :            : {
    1804                 :            :         struct e1000_hw *hw;
    1805                 :            :         uint32_t frame_size;
    1806                 :            :         uint32_t rctl;
    1807                 :            : 
    1808                 :          0 :         frame_size = mtu + E1000_ETH_OVERHEAD;
    1809                 :            : 
    1810                 :            :         /*
    1811                 :            :          * If device is started, refuse mtu that requires the support of
    1812                 :            :          * scattered packets when this feature has not been enabled before.
    1813                 :            :          */
    1814         [ #  # ]:          0 :         if (dev->data->dev_started && !dev->data->scattered_rx &&
    1815         [ #  # ]:          0 :             frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
    1816                 :          0 :                 PMD_INIT_LOG(ERR, "Stop port first.");
    1817                 :          0 :                 return -EINVAL;
    1818                 :            :         }
    1819                 :            : 
    1820                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1821                 :          0 :         rctl = E1000_READ_REG(hw, E1000_RCTL);
    1822                 :            : 
    1823                 :            :         /* switch to jumbo mode if needed */
    1824         [ #  # ]:          0 :         if (mtu > RTE_ETHER_MTU)
    1825                 :          0 :                 rctl |= E1000_RCTL_LPE;
    1826                 :            :         else
    1827                 :          0 :                 rctl &= ~E1000_RCTL_LPE;
    1828                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, rctl);
    1829                 :            : 
    1830                 :          0 :         return 0;
    1831                 :            : }
    1832                 :            : 
    1833                 :            : static int
    1834                 :          0 : eth_em_set_mc_addr_list(struct rte_eth_dev *dev,
    1835                 :            :                         struct rte_ether_addr *mc_addr_set,
    1836                 :            :                         uint32_t nb_mc_addr)
    1837                 :            : {
    1838                 :            :         struct e1000_hw *hw;
    1839                 :            : 
    1840                 :          0 :         hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
    1841                 :          0 :         e1000_update_mc_addr_list(hw, (u8 *)mc_addr_set, nb_mc_addr);
    1842                 :          0 :         return 0;
    1843                 :            : }
    1844                 :            : 
    1845                 :        252 : RTE_PMD_REGISTER_PCI(net_e1000_em, rte_em_pmd);
    1846                 :            : RTE_PMD_REGISTER_PCI_TABLE(net_e1000_em, pci_id_em_map);
    1847                 :            : RTE_PMD_REGISTER_KMOD_DEP(net_e1000_em, "* igb_uio | uio_pci_generic | vfio-pci");

Generated by: LCOV version 1.14