LCOV - code coverage report
Current view: top level - drivers/net/ixgbe/base - ixgbe_82599.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 971 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 44 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 577 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "ixgbe_type.h"
       6                 :            : #include "ixgbe_82599.h"
       7                 :            : #include "ixgbe_api.h"
       8                 :            : #include "ixgbe_common.h"
       9                 :            : #include "ixgbe_phy.h"
      10                 :            : 
      11                 :            : #define IXGBE_82599_MAX_TX_QUEUES 128
      12                 :            : #define IXGBE_82599_MAX_RX_QUEUES 128
      13                 :            : #define IXGBE_82599_RAR_ENTRIES   128
      14                 :            : #define IXGBE_82599_MC_TBL_SIZE   128
      15                 :            : #define IXGBE_82599_VFT_TBL_SIZE  128
      16                 :            : #define IXGBE_82599_RX_PB_SIZE    512
      17                 :            : 
      18                 :            : STATIC s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
      19                 :            :                                          ixgbe_link_speed speed,
      20                 :            :                                          bool autoneg_wait_to_complete);
      21                 :            : STATIC s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw);
      22                 :            : STATIC s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
      23                 :            :                                    u16 offset, u16 *data);
      24                 :            : STATIC s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
      25                 :            :                                           u16 words, u16 *data);
      26                 :            : STATIC s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
      27                 :            :                                         u8 dev_addr, u8 *data);
      28                 :            : STATIC s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
      29                 :            :                                         u8 dev_addr, u8 data);
      30                 :            : 
      31                 :          0 : void ixgbe_init_mac_link_ops_82599(struct ixgbe_hw *hw)
      32                 :            : {
      33                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
      34                 :            : 
      35                 :          0 :         DEBUGFUNC("ixgbe_init_mac_link_ops_82599");
      36                 :            : 
      37                 :            :         /*
      38                 :            :          * enable the laser control functions for SFP+ fiber
      39                 :            :          * and MNG not enabled
      40                 :            :          */
      41   [ #  #  #  # ]:          0 :         if ((mac->ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
      42                 :          0 :             !ixgbe_mng_enabled(hw)) {
      43                 :          0 :                 mac->ops.disable_tx_laser =
      44                 :            :                                        ixgbe_disable_tx_laser_multispeed_fiber;
      45                 :          0 :                 mac->ops.enable_tx_laser =
      46                 :            :                                         ixgbe_enable_tx_laser_multispeed_fiber;
      47                 :          0 :                 mac->ops.flap_tx_laser = ixgbe_flap_tx_laser_multispeed_fiber;
      48                 :            : 
      49                 :            :         } else {
      50                 :          0 :                 mac->ops.disable_tx_laser = NULL;
      51                 :          0 :                 mac->ops.enable_tx_laser = NULL;
      52                 :          0 :                 mac->ops.flap_tx_laser = NULL;
      53                 :            :         }
      54                 :            : 
      55         [ #  # ]:          0 :         if (hw->phy.multispeed_fiber) {
      56                 :            :                 /* Set up dual speed SFP+ support */
      57                 :          0 :                 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
      58                 :          0 :                 mac->ops.setup_mac_link = ixgbe_setup_mac_link_82599;
      59                 :          0 :                 mac->ops.set_rate_select_speed =
      60                 :            :                                                ixgbe_set_hard_rate_select_speed;
      61                 :            :         } else {
      62         [ #  # ]:          0 :                 if ((ixgbe_get_media_type(hw) == ixgbe_media_type_backplane) &&
      63         [ #  # ]:          0 :                      (hw->phy.smart_speed == ixgbe_smart_speed_auto ||
      64         [ #  # ]:          0 :                       hw->phy.smart_speed == ixgbe_smart_speed_on) &&
      65                 :          0 :                       !ixgbe_verify_lesm_fw_enabled_82599(hw)) {
      66                 :          0 :                         mac->ops.setup_link = ixgbe_setup_mac_link_smartspeed;
      67                 :            :                 } else {
      68                 :          0 :                         mac->ops.setup_link = ixgbe_setup_mac_link_82599;
      69                 :            :                 }
      70                 :            :         }
      71                 :          0 : }
      72                 :            : 
      73                 :            : /**
      74                 :            :  * ixgbe_init_phy_ops_82599 - PHY/SFP specific init
      75                 :            :  * @hw: pointer to hardware structure
      76                 :            :  *
      77                 :            :  * Initialize any function pointers that were not able to be
      78                 :            :  * set during init_shared_code because the PHY/SFP type was
      79                 :            :  * not known.  Perform the SFP init if necessary.
      80                 :            :  *
      81                 :            :  **/
      82                 :          0 : s32 ixgbe_init_phy_ops_82599(struct ixgbe_hw *hw)
      83                 :            : {
      84                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
      85                 :            :         struct ixgbe_phy_info *phy = &hw->phy;
      86                 :            :         s32 ret_val = IXGBE_SUCCESS;
      87                 :            :         u32 esdp;
      88                 :            : 
      89                 :          0 :         DEBUGFUNC("ixgbe_init_phy_ops_82599");
      90                 :            : 
      91         [ #  # ]:          0 :         if (hw->device_id == IXGBE_DEV_ID_82599_QSFP_SF_QP) {
      92                 :            :                 /* Store flag indicating I2C bus access control unit. */
      93                 :          0 :                 hw->phy.qsfp_shared_i2c_bus = TRUE;
      94                 :            : 
      95                 :            :                 /* Initialize access to QSFP+ I2C bus */
      96                 :          0 :                 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
      97                 :            :                 esdp |= IXGBE_ESDP_SDP0_DIR;
      98                 :            :                 esdp &= ~IXGBE_ESDP_SDP1_DIR;
      99                 :            :                 esdp &= ~IXGBE_ESDP_SDP0;
     100                 :            :                 esdp &= ~IXGBE_ESDP_SDP0_NATIVE;
     101                 :          0 :                 esdp &= ~IXGBE_ESDP_SDP1_NATIVE;
     102                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
     103                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
     104                 :            : 
     105                 :          0 :                 phy->ops.read_i2c_byte = ixgbe_read_i2c_byte_82599;
     106                 :          0 :                 phy->ops.write_i2c_byte = ixgbe_write_i2c_byte_82599;
     107                 :            :         }
     108                 :            :         /* Identify the PHY or SFP module */
     109                 :          0 :         ret_val = phy->ops.identify(hw);
     110         [ #  # ]:          0 :         if (ret_val == IXGBE_ERR_SFP_NOT_SUPPORTED)
     111                 :          0 :                 goto init_phy_ops_out;
     112                 :            : 
     113                 :            :         /* Setup function pointers based on detected SFP module and speeds */
     114                 :          0 :         ixgbe_init_mac_link_ops_82599(hw);
     115         [ #  # ]:          0 :         if (hw->phy.sfp_type != ixgbe_sfp_type_unknown)
     116                 :          0 :                 hw->phy.ops.reset = NULL;
     117                 :            : 
     118                 :            :         /* If copper media, overwrite with copper function pointers */
     119         [ #  # ]:          0 :         if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
     120                 :          0 :                 mac->ops.setup_link = ixgbe_setup_copper_link_82599;
     121                 :          0 :                 mac->ops.get_link_capabilities =
     122                 :            :                                   ixgbe_get_copper_link_capabilities_generic;
     123                 :            :         }
     124                 :            : 
     125                 :            :         /* Set necessary function pointers based on PHY type */
     126         [ #  # ]:          0 :         switch (hw->phy.type) {
     127                 :          0 :         case ixgbe_phy_tn:
     128                 :          0 :                 phy->ops.setup_link = ixgbe_setup_phy_link_tnx;
     129                 :          0 :                 phy->ops.check_link = ixgbe_check_phy_link_tnx;
     130                 :          0 :                 phy->ops.get_firmware_version =
     131                 :            :                              ixgbe_get_phy_firmware_version_tnx;
     132                 :          0 :                 break;
     133                 :            :         default:
     134                 :            :                 break;
     135                 :            :         }
     136                 :          0 : init_phy_ops_out:
     137                 :          0 :         return ret_val;
     138                 :            : }
     139                 :            : 
     140                 :          0 : s32 ixgbe_setup_sfp_modules_82599(struct ixgbe_hw *hw)
     141                 :            : {
     142                 :            :         s32 ret_val = IXGBE_SUCCESS;
     143                 :            :         u16 list_offset, data_offset, data_value;
     144                 :            : 
     145                 :          0 :         DEBUGFUNC("ixgbe_setup_sfp_modules_82599");
     146                 :            : 
     147         [ #  # ]:          0 :         if (hw->phy.sfp_type != ixgbe_sfp_type_unknown) {
     148                 :          0 :                 ixgbe_init_mac_link_ops_82599(hw);
     149                 :            : 
     150                 :          0 :                 hw->phy.ops.reset = NULL;
     151                 :            : 
     152                 :          0 :                 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw, &list_offset,
     153                 :            :                                                               &data_offset);
     154         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
     155                 :          0 :                         goto setup_sfp_out;
     156                 :            : 
     157                 :            :                 /* PHY config will finish before releasing the semaphore */
     158                 :          0 :                 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
     159                 :            :                                                         IXGBE_GSSR_MAC_CSR_SM);
     160         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS) {
     161                 :            :                         ret_val = IXGBE_ERR_SWFW_SYNC;
     162                 :          0 :                         goto setup_sfp_out;
     163                 :            :                 }
     164                 :            : 
     165         [ #  # ]:          0 :                 if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
     166                 :          0 :                         goto setup_sfp_err;
     167         [ #  # ]:          0 :                 while (data_value != 0xffff) {
     168                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_CORECTL, data_value);
     169                 :          0 :                         IXGBE_WRITE_FLUSH(hw);
     170         [ #  # ]:          0 :                         if (hw->eeprom.ops.read(hw, ++data_offset, &data_value))
     171                 :          0 :                                 goto setup_sfp_err;
     172                 :            :                 }
     173                 :            : 
     174                 :            :                 /* Release the semaphore */
     175                 :          0 :                 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
     176                 :            :                 /* Delay obtaining semaphore again to allow FW access
     177                 :            :                  * prot_autoc_write uses the semaphore too.
     178                 :            :                  */
     179                 :          0 :                 msec_delay(hw->eeprom.semaphore_delay);
     180                 :            : 
     181                 :            :                 /* Restart DSP and set SFI mode */
     182                 :          0 :                 ret_val = hw->mac.ops.prot_autoc_write(hw,
     183                 :          0 :                         hw->mac.orig_autoc | IXGBE_AUTOC_LMS_10G_SERIAL,
     184                 :            :                         false);
     185                 :            : 
     186         [ #  # ]:          0 :                 if (ret_val) {
     187                 :          0 :                         DEBUGOUT("sfp module setup not complete\n");
     188                 :            :                         ret_val = IXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
     189                 :          0 :                         goto setup_sfp_out;
     190                 :            :                 }
     191                 :            : 
     192                 :            :         }
     193                 :            : 
     194                 :          0 : setup_sfp_out:
     195                 :            :         return ret_val;
     196                 :            : 
     197                 :          0 : setup_sfp_err:
     198                 :            :         /* Release the semaphore */
     199                 :          0 :         hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
     200                 :            :         /* Delay obtaining semaphore again to allow FW access */
     201                 :          0 :         msec_delay(hw->eeprom.semaphore_delay);
     202                 :          0 :         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
     203                 :            :                       "eeprom read at offset %d failed", data_offset);
     204                 :          0 :         return IXGBE_ERR_PHY;
     205                 :            : }
     206                 :            : 
     207                 :            : /**
     208                 :            :  * prot_autoc_read_82599 - Hides MAC differences needed for AUTOC read
     209                 :            :  * @hw: pointer to hardware structure
     210                 :            :  * @locked: Return the if we locked for this read.
     211                 :            :  * @reg_val: Value we read from AUTOC
     212                 :            :  *
     213                 :            :  * For this part (82599) we need to wrap read-modify-writes with a possible
     214                 :            :  * FW/SW lock.  It is assumed this lock will be freed with the next
     215                 :            :  * prot_autoc_write_82599().
     216                 :            :  */
     217                 :          0 : s32 prot_autoc_read_82599(struct ixgbe_hw *hw, bool *locked, u32 *reg_val)
     218                 :            : {
     219                 :            :         s32 ret_val;
     220                 :            : 
     221                 :          0 :         *locked = false;
     222                 :            :          /* If LESM is on then we need to hold the SW/FW semaphore. */
     223         [ #  # ]:          0 :         if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
     224                 :          0 :                 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
     225                 :            :                                         IXGBE_GSSR_MAC_CSR_SM);
     226         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
     227                 :            :                         return IXGBE_ERR_SWFW_SYNC;
     228                 :            : 
     229                 :          0 :                 *locked = true;
     230                 :            :         }
     231                 :            : 
     232                 :          0 :         *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
     233                 :          0 :         return IXGBE_SUCCESS;
     234                 :            : }
     235                 :            : 
     236                 :            : /**
     237                 :            :  * prot_autoc_write_82599 - Hides MAC differences needed for AUTOC write
     238                 :            :  * @hw: pointer to hardware structure
     239                 :            :  * @autoc: value to write to AUTOC
     240                 :            :  * @locked: bool to indicate whether the SW/FW lock was already taken by
     241                 :            :  *          previous proc_autoc_read_82599.
     242                 :            :  *
     243                 :            :  * This part (82599) may need to hold the SW/FW lock around all writes to
     244                 :            :  * AUTOC. Likewise after a write we need to do a pipeline reset.
     245                 :            :  */
     246                 :          0 : s32 prot_autoc_write_82599(struct ixgbe_hw *hw, u32 autoc, bool locked)
     247                 :            : {
     248                 :            :         s32 ret_val = IXGBE_SUCCESS;
     249                 :            : 
     250                 :            :         /* Blocked by MNG FW so bail */
     251         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
     252                 :          0 :                 goto out;
     253                 :            : 
     254                 :            :         /* We only need to get the lock if:
     255                 :            :          *  - We didn't do it already (in the read part of a read-modify-write)
     256                 :            :          *  - LESM is enabled.
     257                 :            :          */
     258   [ #  #  #  # ]:          0 :         if (!locked && ixgbe_verify_lesm_fw_enabled_82599(hw)) {
     259                 :          0 :                 ret_val = hw->mac.ops.acquire_swfw_sync(hw,
     260                 :            :                                         IXGBE_GSSR_MAC_CSR_SM);
     261         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
     262                 :            :                         return IXGBE_ERR_SWFW_SYNC;
     263                 :            : 
     264                 :            :                 locked = true;
     265                 :            :         }
     266                 :            : 
     267                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
     268                 :          0 :         ret_val = ixgbe_reset_pipeline_82599(hw);
     269                 :            : 
     270                 :          0 : out:
     271                 :            :         /* Free the SW/FW semaphore as we either grabbed it here or
     272                 :            :          * already had it when this function was called.
     273                 :            :          */
     274         [ #  # ]:          0 :         if (locked)
     275                 :          0 :                 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
     276                 :            : 
     277                 :            :         return ret_val;
     278                 :            : }
     279                 :            : 
     280                 :            : /**
     281                 :            :  * ixgbe_init_ops_82599 - Inits func ptrs and MAC type
     282                 :            :  * @hw: pointer to hardware structure
     283                 :            :  *
     284                 :            :  * Initialize the function pointers and assign the MAC type for 82599.
     285                 :            :  * Does not touch the hardware.
     286                 :            :  **/
     287                 :            : 
     288                 :          0 : s32 ixgbe_init_ops_82599(struct ixgbe_hw *hw)
     289                 :            : {
     290                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
     291                 :            :         struct ixgbe_phy_info *phy = &hw->phy;
     292                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
     293                 :            :         s32 ret_val;
     294                 :            : 
     295                 :          0 :         DEBUGFUNC("ixgbe_init_ops_82599");
     296                 :            : 
     297                 :          0 :         ixgbe_init_phy_ops_generic(hw);
     298                 :          0 :         ret_val = ixgbe_init_ops_generic(hw);
     299                 :            : 
     300                 :            :         /* PHY */
     301                 :          0 :         phy->ops.identify = ixgbe_identify_phy_82599;
     302                 :          0 :         phy->ops.init = ixgbe_init_phy_ops_82599;
     303                 :            : 
     304                 :            :         /* MAC */
     305                 :          0 :         mac->ops.reset_hw = ixgbe_reset_hw_82599;
     306                 :          0 :         mac->ops.enable_relaxed_ordering = ixgbe_enable_relaxed_ordering_gen2;
     307                 :          0 :         mac->ops.get_media_type = ixgbe_get_media_type_82599;
     308                 :          0 :         mac->ops.get_supported_physical_layer =
     309                 :            :                                     ixgbe_get_supported_physical_layer_82599;
     310                 :          0 :         mac->ops.disable_sec_rx_path = ixgbe_disable_sec_rx_path_generic;
     311                 :          0 :         mac->ops.enable_sec_rx_path = ixgbe_enable_sec_rx_path_generic;
     312                 :          0 :         mac->ops.enable_rx_dma = ixgbe_enable_rx_dma_82599;
     313                 :          0 :         mac->ops.read_analog_reg8 = ixgbe_read_analog_reg8_82599;
     314                 :          0 :         mac->ops.write_analog_reg8 = ixgbe_write_analog_reg8_82599;
     315                 :          0 :         mac->ops.start_hw = ixgbe_start_hw_82599;
     316                 :          0 :         mac->ops.get_san_mac_addr = ixgbe_get_san_mac_addr_generic;
     317                 :          0 :         mac->ops.set_san_mac_addr = ixgbe_set_san_mac_addr_generic;
     318                 :          0 :         mac->ops.get_device_caps = ixgbe_get_device_caps_generic;
     319                 :          0 :         mac->ops.get_wwn_prefix = ixgbe_get_wwn_prefix_generic;
     320                 :          0 :         mac->ops.get_fcoe_boot_status = ixgbe_get_fcoe_boot_status_generic;
     321                 :          0 :         mac->ops.prot_autoc_read = prot_autoc_read_82599;
     322                 :          0 :         mac->ops.prot_autoc_write = prot_autoc_write_82599;
     323                 :            : 
     324                 :            :         /* RAR, Multicast, VLAN */
     325                 :          0 :         mac->ops.set_vmdq = ixgbe_set_vmdq_generic;
     326                 :          0 :         mac->ops.set_vmdq_san_mac = ixgbe_set_vmdq_san_mac_generic;
     327                 :          0 :         mac->ops.clear_vmdq = ixgbe_clear_vmdq_generic;
     328                 :          0 :         mac->ops.insert_mac_addr = ixgbe_insert_mac_addr_generic;
     329                 :          0 :         mac->rar_highwater = 1;
     330                 :          0 :         mac->ops.set_vfta = ixgbe_set_vfta_generic;
     331                 :          0 :         mac->ops.set_vlvf = ixgbe_set_vlvf_generic;
     332                 :          0 :         mac->ops.clear_vfta = ixgbe_clear_vfta_generic;
     333                 :          0 :         mac->ops.init_uta_tables = ixgbe_init_uta_tables_generic;
     334                 :          0 :         mac->ops.setup_sfp = ixgbe_setup_sfp_modules_82599;
     335                 :          0 :         mac->ops.set_mac_anti_spoofing = ixgbe_set_mac_anti_spoofing;
     336                 :          0 :         mac->ops.set_vlan_anti_spoofing = ixgbe_set_vlan_anti_spoofing;
     337                 :            : 
     338                 :            :         /* Link */
     339                 :          0 :         mac->ops.get_link_capabilities = ixgbe_get_link_capabilities_82599;
     340                 :          0 :         mac->ops.check_link = ixgbe_check_mac_link_generic;
     341                 :          0 :         mac->ops.setup_rxpba = ixgbe_set_rxpba_generic;
     342                 :          0 :         ixgbe_init_mac_link_ops_82599(hw);
     343                 :            : 
     344                 :          0 :         mac->mcft_size               = IXGBE_82599_MC_TBL_SIZE;
     345                 :          0 :         mac->vft_size                = IXGBE_82599_VFT_TBL_SIZE;
     346                 :          0 :         mac->num_rar_entries = IXGBE_82599_RAR_ENTRIES;
     347                 :          0 :         mac->rx_pb_size              = IXGBE_82599_RX_PB_SIZE;
     348                 :          0 :         mac->max_rx_queues   = IXGBE_82599_MAX_RX_QUEUES;
     349                 :          0 :         mac->max_tx_queues   = IXGBE_82599_MAX_TX_QUEUES;
     350                 :          0 :         mac->max_msix_vectors        = ixgbe_get_pcie_msix_count_generic(hw);
     351                 :            : 
     352                 :          0 :         mac->arc_subsystem_valid = !!(IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw))
     353                 :          0 :                                       & IXGBE_FWSM_MODE_MASK);
     354                 :            : 
     355                 :          0 :         hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
     356                 :            : 
     357                 :            :         /* EEPROM */
     358                 :          0 :         eeprom->ops.read = ixgbe_read_eeprom_82599;
     359                 :          0 :         eeprom->ops.read_buffer = ixgbe_read_eeprom_buffer_82599;
     360                 :            : 
     361                 :            :         /* Manageability interface */
     362                 :          0 :         mac->ops.set_fw_drv_ver = ixgbe_set_fw_drv_ver_generic;
     363                 :            : 
     364                 :          0 :         mac->ops.get_thermal_sensor_data =
     365                 :            :                                          ixgbe_get_thermal_sensor_data_generic;
     366                 :          0 :         mac->ops.init_thermal_sensor_thresh =
     367                 :            :                                       ixgbe_init_thermal_sensor_thresh_generic;
     368                 :            : 
     369                 :          0 :         mac->ops.get_rtrup2tc = ixgbe_dcb_get_rtrup2tc_generic;
     370                 :            : 
     371                 :          0 :         return ret_val;
     372                 :            : }
     373                 :            : 
     374                 :            : /**
     375                 :            :  * ixgbe_get_link_capabilities_82599 - Determines link capabilities
     376                 :            :  * @hw: pointer to hardware structure
     377                 :            :  * @speed: pointer to link speed
     378                 :            :  * @autoneg: true when autoneg or autotry is enabled
     379                 :            :  *
     380                 :            :  * Determines the link capabilities by reading the AUTOC register.
     381                 :            :  **/
     382                 :          0 : s32 ixgbe_get_link_capabilities_82599(struct ixgbe_hw *hw,
     383                 :            :                                       ixgbe_link_speed *speed,
     384                 :            :                                       bool *autoneg)
     385                 :            : {
     386                 :            :         s32 status = IXGBE_SUCCESS;
     387                 :            :         u32 autoc = 0;
     388                 :            : 
     389                 :          0 :         DEBUGFUNC("ixgbe_get_link_capabilities_82599");
     390                 :            : 
     391                 :            : 
     392                 :            :         /* Check if 1G SFP module. */
     393                 :          0 :         if (hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core0 ||
     394         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_cu_core1 ||
     395         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core0 ||
     396         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_lha_core1 ||
     397         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
     398         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1 ||
     399         [ #  # ]:          0 :             hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
     400                 :            :             hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
     401                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
     402                 :          0 :                 *autoneg = true;
     403                 :          0 :                 goto out;
     404                 :            :         }
     405                 :            : 
     406                 :            :         /*
     407                 :            :          * Determine link capabilities based on the stored value of AUTOC,
     408                 :            :          * which represents EEPROM defaults.  If AUTOC value has not
     409                 :            :          * been stored, use the current register values.
     410                 :            :          */
     411         [ #  # ]:          0 :         if (hw->mac.orig_link_settings_stored)
     412                 :          0 :                 autoc = hw->mac.orig_autoc;
     413                 :            :         else
     414                 :          0 :                 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
     415                 :            : 
     416   [ #  #  #  #  :          0 :         switch (autoc & IXGBE_AUTOC_LMS_MASK) {
             #  #  #  # ]
     417                 :          0 :         case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
     418                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
     419                 :          0 :                 *autoneg = false;
     420                 :          0 :                 break;
     421                 :            : 
     422                 :          0 :         case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
     423                 :          0 :                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
     424                 :          0 :                 *autoneg = false;
     425                 :          0 :                 break;
     426                 :            : 
     427                 :          0 :         case IXGBE_AUTOC_LMS_1G_AN:
     428                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
     429                 :          0 :                 *autoneg = true;
     430                 :          0 :                 break;
     431                 :            : 
     432                 :          0 :         case IXGBE_AUTOC_LMS_10G_SERIAL:
     433                 :          0 :                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
     434                 :          0 :                 *autoneg = false;
     435                 :          0 :                 break;
     436                 :            : 
     437                 :          0 :         case IXGBE_AUTOC_LMS_KX4_KX_KR:
     438                 :            :         case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
     439                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
     440         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KR_SUPP)
     441                 :          0 :                         *speed |= IXGBE_LINK_SPEED_10GB_FULL;
     442         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX4_SUPP)
     443                 :          0 :                         *speed |= IXGBE_LINK_SPEED_10GB_FULL;
     444         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX_SUPP)
     445                 :          0 :                         *speed |= IXGBE_LINK_SPEED_1GB_FULL;
     446                 :          0 :                 *autoneg = true;
     447                 :          0 :                 break;
     448                 :            : 
     449                 :          0 :         case IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
     450                 :          0 :                 *speed = IXGBE_LINK_SPEED_100_FULL;
     451         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KR_SUPP)
     452                 :          0 :                         *speed |= IXGBE_LINK_SPEED_10GB_FULL;
     453         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX4_SUPP)
     454                 :          0 :                         *speed |= IXGBE_LINK_SPEED_10GB_FULL;
     455         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX_SUPP)
     456                 :          0 :                         *speed |= IXGBE_LINK_SPEED_1GB_FULL;
     457                 :          0 :                 *autoneg = true;
     458                 :          0 :                 break;
     459                 :            : 
     460                 :          0 :         case IXGBE_AUTOC_LMS_SGMII_1G_100M:
     461                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL | IXGBE_LINK_SPEED_100_FULL;
     462                 :          0 :                 *autoneg = false;
     463                 :          0 :                 break;
     464                 :            : 
     465                 :          0 :         default:
     466                 :            :                 status = IXGBE_ERR_LINK_SETUP;
     467                 :          0 :                 goto out;
     468                 :            :                 break;
     469                 :            :         }
     470                 :            : 
     471         [ #  # ]:          0 :         if (hw->phy.multispeed_fiber) {
     472                 :          0 :                 *speed |= IXGBE_LINK_SPEED_10GB_FULL |
     473                 :            :                           IXGBE_LINK_SPEED_1GB_FULL;
     474                 :            : 
     475                 :            :                 /* QSFP must not enable full auto-negotiation
     476                 :            :                  * Limited autoneg is enabled at 1G
     477                 :            :                  */
     478         [ #  # ]:          0 :                 if (hw->phy.media_type == ixgbe_media_type_fiber_qsfp)
     479                 :          0 :                         *autoneg = false;
     480                 :            :                 else
     481                 :          0 :                         *autoneg = true;
     482                 :            :         }
     483                 :            : 
     484                 :          0 : out:
     485                 :          0 :         return status;
     486                 :            : }
     487                 :            : 
     488                 :            : /**
     489                 :            :  * ixgbe_get_media_type_82599 - Get media type
     490                 :            :  * @hw: pointer to hardware structure
     491                 :            :  *
     492                 :            :  * Returns the media type (fiber, copper, backplane)
     493                 :            :  **/
     494                 :          0 : enum ixgbe_media_type ixgbe_get_media_type_82599(struct ixgbe_hw *hw)
     495                 :            : {
     496                 :            :         enum ixgbe_media_type media_type;
     497                 :            : 
     498                 :          0 :         DEBUGFUNC("ixgbe_get_media_type_82599");
     499                 :            : 
     500                 :            :         /* Detect if there is a copper PHY attached. */
     501         [ #  # ]:          0 :         switch (hw->phy.type) {
     502                 :          0 :         case ixgbe_phy_cu_unknown:
     503                 :            :         case ixgbe_phy_tn:
     504                 :            :                 media_type = ixgbe_media_type_copper;
     505                 :          0 :                 goto out;
     506                 :            :         default:
     507                 :            :                 break;
     508                 :            :         }
     509                 :            : 
     510   [ #  #  #  #  :          0 :         switch (hw->device_id) {
                #  #  # ]
     511                 :            :         case IXGBE_DEV_ID_82599_KX4:
     512                 :            :         case IXGBE_DEV_ID_82599_KX4_MEZZ:
     513                 :            :         case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
     514                 :            :         case IXGBE_DEV_ID_82599_KR:
     515                 :            :         case IXGBE_DEV_ID_82599_BACKPLANE_FCOE:
     516                 :            :         case IXGBE_DEV_ID_82599_XAUI_LOM:
     517                 :            :                 /* Default device ID is mezzanine card KX/KX4 */
     518                 :            :                 media_type = ixgbe_media_type_backplane;
     519                 :            :                 break;
     520                 :          0 :         case IXGBE_DEV_ID_82599_SFP:
     521                 :            :         case IXGBE_DEV_ID_82599_SFP_FCOE:
     522                 :            :         case IXGBE_DEV_ID_82599_SFP_EM:
     523                 :            :         case IXGBE_DEV_ID_82599_SFP_SF2:
     524                 :            :         case IXGBE_DEV_ID_82599_SFP_SF_QP:
     525                 :            :         case IXGBE_DEV_ID_82599EN_SFP:
     526                 :            :                 media_type = ixgbe_media_type_fiber;
     527                 :          0 :                 break;
     528                 :          0 :         case IXGBE_DEV_ID_82599_CX4:
     529                 :            :                 media_type = ixgbe_media_type_cx4;
     530                 :          0 :                 break;
     531                 :          0 :         case IXGBE_DEV_ID_82599_T3_LOM:
     532                 :            :                 media_type = ixgbe_media_type_copper;
     533                 :          0 :                 break;
     534                 :          0 :         case IXGBE_DEV_ID_82599_LS:
     535                 :            :                 media_type = ixgbe_media_type_fiber_lco;
     536                 :          0 :                 break;
     537                 :          0 :         case IXGBE_DEV_ID_82599_QSFP_SF_QP:
     538                 :            :                 media_type = ixgbe_media_type_fiber_qsfp;
     539                 :          0 :                 break;
     540                 :          0 :         default:
     541                 :            :                 media_type = ixgbe_media_type_unknown;
     542                 :          0 :                 break;
     543                 :            :         }
     544                 :          0 : out:
     545                 :          0 :         return media_type;
     546                 :            : }
     547                 :            : 
     548                 :            : /**
     549                 :            :  * ixgbe_stop_mac_link_on_d3_82599 - Disables link on D3
     550                 :            :  * @hw: pointer to hardware structure
     551                 :            :  *
     552                 :            :  * Disables link during D3 power down sequence.
     553                 :            :  *
     554                 :            :  **/
     555                 :          0 : void ixgbe_stop_mac_link_on_d3_82599(struct ixgbe_hw *hw)
     556                 :            : {
     557                 :            :         u32 autoc2_reg;
     558                 :          0 :         u16 ee_ctrl_2 = 0;
     559                 :            : 
     560                 :          0 :         DEBUGFUNC("ixgbe_stop_mac_link_on_d3_82599");
     561                 :          0 :         ixgbe_read_eeprom(hw, IXGBE_EEPROM_CTRL_2, &ee_ctrl_2);
     562                 :            : 
     563   [ #  #  #  # ]:          0 :         if (!ixgbe_mng_present(hw) && !hw->wol_enabled &&
     564         [ #  # ]:          0 :             ee_ctrl_2 & IXGBE_EEPROM_CCD_BIT) {
     565                 :          0 :                 autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
     566                 :          0 :                 autoc2_reg |= IXGBE_AUTOC2_LINK_DISABLE_ON_D3_MASK;
     567                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
     568                 :            :         }
     569                 :          0 : }
     570                 :            : 
     571                 :            : /**
     572                 :            :  * ixgbe_start_mac_link_82599 - Setup MAC link settings
     573                 :            :  * @hw: pointer to hardware structure
     574                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
     575                 :            :  *
     576                 :            :  * Configures link settings based on values in the ixgbe_hw struct.
     577                 :            :  * Restarts the link.  Performs autonegotiation if needed.
     578                 :            :  **/
     579                 :          0 : s32 ixgbe_start_mac_link_82599(struct ixgbe_hw *hw,
     580                 :            :                                bool autoneg_wait_to_complete)
     581                 :            : {
     582                 :            :         u32 autoc_reg;
     583                 :            :         u32 links_reg;
     584                 :            :         u32 i;
     585                 :            :         s32 status = IXGBE_SUCCESS;
     586                 :            :         bool got_lock = false;
     587                 :            : 
     588                 :          0 :         DEBUGFUNC("ixgbe_start_mac_link_82599");
     589                 :            : 
     590                 :            : 
     591                 :            :         /*  reset_pipeline requires us to hold this lock as it writes to
     592                 :            :          *  AUTOC.
     593                 :            :          */
     594         [ #  # ]:          0 :         if (ixgbe_verify_lesm_fw_enabled_82599(hw)) {
     595                 :          0 :                 status = hw->mac.ops.acquire_swfw_sync(hw,
     596                 :            :                                                        IXGBE_GSSR_MAC_CSR_SM);
     597         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
     598                 :          0 :                         goto out;
     599                 :            : 
     600                 :            :                 got_lock = true;
     601                 :            :         }
     602                 :            : 
     603                 :            :         /* Restart link */
     604                 :          0 :         ixgbe_reset_pipeline_82599(hw);
     605                 :            : 
     606         [ #  # ]:          0 :         if (got_lock)
     607                 :          0 :                 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
     608                 :            : 
     609                 :            :         /* Only poll for autoneg to complete if specified to do so */
     610         [ #  # ]:          0 :         if (autoneg_wait_to_complete) {
     611                 :          0 :                 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
     612                 :          0 :                 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
     613         [ #  # ]:          0 :                      IXGBE_AUTOC_LMS_KX4_KX_KR ||
     614                 :            :                     (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
     615         [ #  # ]:          0 :                      IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
     616                 :            :                     (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
     617                 :            :                      IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
     618                 :            :                         links_reg = 0; /* Just in case Autoneg time = 0 */
     619         [ #  # ]:          0 :                         for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
     620                 :          0 :                                 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
     621         [ #  # ]:          0 :                                 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
     622                 :            :                                         break;
     623                 :          0 :                                 msec_delay(100);
     624                 :            :                         }
     625         [ #  # ]:          0 :                         if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
     626                 :            :                                 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
     627                 :          0 :                                 DEBUGOUT("Autoneg did not complete.\n");
     628                 :            :                         }
     629                 :            :                 }
     630                 :            :         }
     631                 :            : 
     632                 :            :         /* Add delay to filter out noises during initial link setup */
     633                 :          0 :         msec_delay(50);
     634                 :            : 
     635                 :          0 : out:
     636                 :          0 :         return status;
     637                 :            : }
     638                 :            : 
     639                 :            : /**
     640                 :            :  * ixgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
     641                 :            :  * @hw: pointer to hardware structure
     642                 :            :  *
     643                 :            :  * The base drivers may require better control over SFP+ module
     644                 :            :  * PHY states.  This includes selectively shutting down the Tx
     645                 :            :  * laser on the PHY, effectively halting physical link.
     646                 :            :  **/
     647                 :          0 : void ixgbe_disable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
     648                 :            : {
     649                 :          0 :         u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
     650                 :            : 
     651                 :            :         /* Blocked by MNG FW so bail */
     652         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
     653                 :            :                 return;
     654                 :            : 
     655                 :            :         /* Disable Tx laser; allow 100us to go dark per spec */
     656                 :          0 :         esdp_reg |= IXGBE_ESDP_SDP3;
     657                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
     658                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     659                 :          0 :         usec_delay(100);
     660                 :            : }
     661                 :            : 
     662                 :            : /**
     663                 :            :  * ixgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
     664                 :            :  * @hw: pointer to hardware structure
     665                 :            :  *
     666                 :            :  * The base drivers may require better control over SFP+ module
     667                 :            :  * PHY states.  This includes selectively turning on the Tx
     668                 :            :  * laser on the PHY, effectively starting physical link.
     669                 :            :  **/
     670                 :          0 : void ixgbe_enable_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
     671                 :            : {
     672                 :          0 :         u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
     673                 :            : 
     674                 :            :         /* Enable Tx laser; allow 100ms to light up */
     675                 :          0 :         esdp_reg &= ~IXGBE_ESDP_SDP3;
     676                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
     677                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     678                 :          0 :         msec_delay(100);
     679                 :          0 : }
     680                 :            : 
     681                 :            : /**
     682                 :            :  * ixgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
     683                 :            :  * @hw: pointer to hardware structure
     684                 :            :  *
     685                 :            :  * When the driver changes the link speeds that it can support,
     686                 :            :  * it sets autotry_restart to true to indicate that we need to
     687                 :            :  * initiate a new autotry session with the link partner.  To do
     688                 :            :  * so, we set the speed then disable and re-enable the Tx laser, to
     689                 :            :  * alert the link partner that it also needs to restart autotry on its
     690                 :            :  * end.  This is consistent with true clause 37 autoneg, which also
     691                 :            :  * involves a loss of signal.
     692                 :            :  **/
     693                 :          0 : void ixgbe_flap_tx_laser_multispeed_fiber(struct ixgbe_hw *hw)
     694                 :            : {
     695                 :          0 :         DEBUGFUNC("ixgbe_flap_tx_laser_multispeed_fiber");
     696                 :            : 
     697                 :            :         /* Blocked by MNG FW so bail */
     698         [ #  # ]:          0 :         if (ixgbe_check_reset_blocked(hw))
     699                 :            :                 return;
     700                 :            : 
     701         [ #  # ]:          0 :         if (hw->mac.autotry_restart) {
     702                 :          0 :                 ixgbe_disable_tx_laser_multispeed_fiber(hw);
     703                 :          0 :                 ixgbe_enable_tx_laser_multispeed_fiber(hw);
     704                 :          0 :                 hw->mac.autotry_restart = false;
     705                 :            :         }
     706                 :            : }
     707                 :            : 
     708                 :            : /**
     709                 :            :  * ixgbe_set_hard_rate_select_speed - Set module link speed
     710                 :            :  * @hw: pointer to hardware structure
     711                 :            :  * @speed: link speed to set
     712                 :            :  *
     713                 :            :  * Set module link speed via RS0/RS1 rate select pins.
     714                 :            :  */
     715                 :          0 : void ixgbe_set_hard_rate_select_speed(struct ixgbe_hw *hw,
     716                 :            :                                         ixgbe_link_speed speed)
     717                 :            : {
     718                 :          0 :         u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
     719                 :            : 
     720      [ #  #  # ]:          0 :         switch (speed) {
     721                 :          0 :         case IXGBE_LINK_SPEED_10GB_FULL:
     722                 :          0 :                 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
     723                 :          0 :                 break;
     724                 :          0 :         case IXGBE_LINK_SPEED_1GB_FULL:
     725                 :          0 :                 esdp_reg &= ~IXGBE_ESDP_SDP5;
     726                 :          0 :                 esdp_reg |= IXGBE_ESDP_SDP5_DIR;
     727                 :          0 :                 break;
     728                 :          0 :         default:
     729                 :          0 :                 DEBUGOUT("Invalid fixed module speed\n");
     730                 :          0 :                 return;
     731                 :            :         }
     732                 :            : 
     733                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
     734                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     735                 :            : }
     736                 :            : 
     737                 :            : /**
     738                 :            :  * ixgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
     739                 :            :  * @hw: pointer to hardware structure
     740                 :            :  * @speed: new link speed
     741                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
     742                 :            :  *
     743                 :            :  * Implements the Intel SmartSpeed algorithm.
     744                 :            :  **/
     745                 :          0 : s32 ixgbe_setup_mac_link_smartspeed(struct ixgbe_hw *hw,
     746                 :            :                                     ixgbe_link_speed speed,
     747                 :            :                                     bool autoneg_wait_to_complete)
     748                 :            : {
     749                 :            :         s32 status = IXGBE_SUCCESS;
     750                 :          0 :         ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
     751                 :            :         s32 i, j;
     752                 :          0 :         bool link_up = false;
     753                 :          0 :         u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
     754                 :            : 
     755                 :          0 :         DEBUGFUNC("ixgbe_setup_mac_link_smartspeed");
     756                 :            : 
     757                 :            :          /* Set autoneg_advertised value based on input link speed */
     758                 :          0 :         hw->phy.autoneg_advertised = 0;
     759                 :            : 
     760         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10GB_FULL)
     761                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
     762                 :            : 
     763         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_1GB_FULL)
     764                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
     765                 :            : 
     766         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_100_FULL)
     767                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_100_FULL;
     768                 :            : 
     769                 :            :         /*
     770                 :            :          * Implement Intel SmartSpeed algorithm.  SmartSpeed will reduce the
     771                 :            :          * autoneg advertisement if link is unable to be established at the
     772                 :            :          * highest negotiated rate.  This can sometimes happen due to integrity
     773                 :            :          * issues with the physical media connection.
     774                 :            :          */
     775                 :            : 
     776                 :            :         /* First, try to get link with full advertisement */
     777                 :          0 :         hw->phy.smart_speed_active = false;
     778         [ #  # ]:          0 :         for (j = 0; j < IXGBE_SMARTSPEED_MAX_RETRIES; j++) {
     779                 :          0 :                 status = ixgbe_setup_mac_link_82599(hw, speed,
     780                 :            :                                                     autoneg_wait_to_complete);
     781         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
     782                 :          0 :                         goto out;
     783                 :            : 
     784                 :            :                 /*
     785                 :            :                  * Wait for the controller to acquire link.  Per IEEE 802.3ap,
     786                 :            :                  * Section 73.10.2, we may have to wait up to 500ms if KR is
     787                 :            :                  * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
     788                 :            :                  * Table 9 in the AN MAS.
     789                 :            :                  */
     790         [ #  # ]:          0 :                 for (i = 0; i < 5; i++) {
     791                 :          0 :                         msec_delay(100);
     792                 :            : 
     793                 :            :                         /* If we have link, just jump out */
     794                 :          0 :                         status = ixgbe_check_link(hw, &link_speed, &link_up,
     795                 :            :                                                   false);
     796         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
     797                 :          0 :                                 goto out;
     798                 :            : 
     799         [ #  # ]:          0 :                         if (link_up)
     800                 :          0 :                                 goto out;
     801                 :            :                 }
     802                 :            :         }
     803                 :            : 
     804                 :            :         /*
     805                 :            :          * We didn't get link.  If we advertised KR plus one of KX4/KX
     806                 :            :          * (or BX4/BX), then disable KR and try again.
     807                 :            :          */
     808         [ #  # ]:          0 :         if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
     809         [ #  # ]:          0 :             ((autoc_reg & IXGBE_AUTOC_KX4_KX_SUPP_MASK) == 0))
     810                 :          0 :                 goto out;
     811                 :            : 
     812                 :            :         /* Turn SmartSpeed on to disable KR support */
     813                 :          0 :         hw->phy.smart_speed_active = true;
     814                 :          0 :         status = ixgbe_setup_mac_link_82599(hw, speed,
     815                 :            :                                             autoneg_wait_to_complete);
     816         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
     817                 :          0 :                 goto out;
     818                 :            : 
     819                 :            :         /*
     820                 :            :          * Wait for the controller to acquire link.  600ms will allow for
     821                 :            :          * the AN link_fail_inhibit_timer as well for multiple cycles of
     822                 :            :          * parallel detect, both 10g and 1g. This allows for the maximum
     823                 :            :          * connect attempts as defined in the AN MAS table 73-7.
     824                 :            :          */
     825         [ #  # ]:          0 :         for (i = 0; i < 6; i++) {
     826                 :          0 :                 msec_delay(100);
     827                 :            : 
     828                 :            :                 /* If we have link, just jump out */
     829                 :          0 :                 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
     830         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
     831                 :          0 :                         goto out;
     832                 :            : 
     833         [ #  # ]:          0 :                 if (link_up)
     834                 :          0 :                         goto out;
     835                 :            :         }
     836                 :            : 
     837                 :            :         /* We didn't get link.  Turn SmartSpeed back off. */
     838                 :          0 :         hw->phy.smart_speed_active = false;
     839                 :          0 :         status = ixgbe_setup_mac_link_82599(hw, speed,
     840                 :            :                                             autoneg_wait_to_complete);
     841                 :            : 
     842                 :          0 : out:
     843   [ #  #  #  # ]:          0 :         if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
     844                 :          0 :                 DEBUGOUT("Smartspeed has downgraded the link speed "
     845                 :            :                 "from the maximum advertised\n");
     846                 :          0 :         return status;
     847                 :            : }
     848                 :            : 
     849                 :            : /**
     850                 :            :  * ixgbe_setup_mac_link_82599 - Set MAC link speed
     851                 :            :  * @hw: pointer to hardware structure
     852                 :            :  * @speed: new link speed
     853                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
     854                 :            :  *
     855                 :            :  * Set the link speed in the AUTOC register and restarts link.
     856                 :            :  **/
     857                 :          0 : s32 ixgbe_setup_mac_link_82599(struct ixgbe_hw *hw,
     858                 :            :                                ixgbe_link_speed speed,
     859                 :            :                                bool autoneg_wait_to_complete)
     860                 :            : {
     861                 :          0 :         bool autoneg = false;
     862                 :            :         s32 status = IXGBE_SUCCESS;
     863                 :            :         u32 pma_pmd_1g, link_mode;
     864                 :          0 :         u32 current_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC); /* holds the value of AUTOC register at this current point in time */
     865                 :            :         u32 orig_autoc = 0; /* holds the cached value of AUTOC register */
     866                 :            :         u32 autoc = current_autoc; /* Temporary variable used for comparison purposes */
     867                 :          0 :         u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
     868                 :          0 :         u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
     869                 :            :         u32 links_reg;
     870                 :            :         u32 i;
     871                 :          0 :         ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
     872                 :            : 
     873                 :          0 :         DEBUGFUNC("ixgbe_setup_mac_link_82599");
     874                 :            : 
     875                 :            :         /* Check to see if speed passed in is supported. */
     876                 :          0 :         status = ixgbe_get_link_capabilities(hw, &link_capabilities, &autoneg);
     877         [ #  # ]:          0 :         if (status)
     878                 :          0 :                 goto out;
     879                 :            : 
     880                 :          0 :         speed &= link_capabilities;
     881                 :            : 
     882         [ #  # ]:          0 :         if (speed == IXGBE_LINK_SPEED_UNKNOWN) {
     883                 :            :                 status = IXGBE_ERR_LINK_SETUP;
     884                 :          0 :                 goto out;
     885                 :            :         }
     886                 :            : 
     887                 :            :         /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
     888         [ #  # ]:          0 :         if (hw->mac.orig_link_settings_stored)
     889                 :          0 :                 orig_autoc = hw->mac.orig_autoc;
     890                 :            :         else
     891                 :            :                 orig_autoc = autoc;
     892                 :            : 
     893                 :          0 :         link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
     894                 :          0 :         pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
     895                 :            : 
     896                 :          0 :         if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
     897   [ #  #  #  # ]:          0 :             link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
     898                 :            :             link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
     899                 :            :                 /* Set KX4/KX/KR support according to speed requested */
     900                 :          0 :                 autoc &= ~(IXGBE_AUTOC_KX4_KX_SUPP_MASK | IXGBE_AUTOC_KR_SUPP);
     901         [ #  # ]:          0 :                 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
     902         [ #  # ]:          0 :                         if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
     903                 :          0 :                                 autoc |= IXGBE_AUTOC_KX4_SUPP;
     904         [ #  # ]:          0 :                         if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
     905         [ #  # ]:          0 :                             (hw->phy.smart_speed_active == false))
     906                 :          0 :                                 autoc |= IXGBE_AUTOC_KR_SUPP;
     907                 :            :                 }
     908         [ #  # ]:          0 :                 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
     909                 :          0 :                         autoc |= IXGBE_AUTOC_KX_SUPP;
     910         [ #  # ]:          0 :         } else if ((pma_pmd_1g == IXGBE_AUTOC_1G_SFI) &&
     911                 :          0 :                    (link_mode == IXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
     912         [ #  # ]:          0 :                     link_mode == IXGBE_AUTOC_LMS_1G_AN)) {
     913                 :            :                 /* Switch from 1G SFI to 10G SFI if requested */
     914                 :          0 :                 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
     915         [ #  # ]:          0 :                     (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)) {
     916                 :          0 :                         autoc &= ~IXGBE_AUTOC_LMS_MASK;
     917                 :          0 :                         autoc |= IXGBE_AUTOC_LMS_10G_SERIAL;
     918                 :            :                 }
     919                 :          0 :         } else if ((pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI) &&
     920         [ #  # ]:          0 :                    (link_mode == IXGBE_AUTOC_LMS_10G_SERIAL)) {
     921                 :            :                 /* Switch from 10G SFI to 1G SFI if requested */
     922                 :          0 :                 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
     923         [ #  # ]:          0 :                     (pma_pmd_1g == IXGBE_AUTOC_1G_SFI)) {
     924                 :          0 :                         autoc &= ~IXGBE_AUTOC_LMS_MASK;
     925   [ #  #  #  # ]:          0 :                         if (autoneg || hw->phy.type == ixgbe_phy_qsfp_intel)
     926                 :          0 :                                 autoc |= IXGBE_AUTOC_LMS_1G_AN;
     927                 :            :                         else
     928                 :            :                                 autoc |= IXGBE_AUTOC_LMS_1G_LINK_NO_AN;
     929                 :            :                 }
     930                 :            :         }
     931                 :            : 
     932         [ #  # ]:          0 :         if (autoc != current_autoc) {
     933                 :            :                 /* Restart link */
     934                 :          0 :                 status = hw->mac.ops.prot_autoc_write(hw, autoc, false);
     935         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
     936                 :          0 :                         goto out;
     937                 :            : 
     938                 :            :                 /* Only poll for autoneg to complete if specified to do so */
     939         [ #  # ]:          0 :                 if (autoneg_wait_to_complete) {
     940         [ #  # ]:          0 :                         if (link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR ||
     941         [ #  # ]:          0 :                             link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
     942                 :            :                             link_mode == IXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
     943                 :            :                                 links_reg = 0; /*Just in case Autoneg time=0*/
     944         [ #  # ]:          0 :                                 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
     945                 :            :                                         links_reg =
     946                 :          0 :                                                IXGBE_READ_REG(hw, IXGBE_LINKS);
     947         [ #  # ]:          0 :                                         if (links_reg & IXGBE_LINKS_KX_AN_COMP)
     948                 :            :                                                 break;
     949                 :          0 :                                         msec_delay(100);
     950                 :            :                                 }
     951         [ #  # ]:          0 :                                 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
     952                 :            :                                         status =
     953                 :            :                                                 IXGBE_ERR_AUTONEG_NOT_COMPLETE;
     954                 :          0 :                                         DEBUGOUT("Autoneg did not complete.\n");
     955                 :            :                                 }
     956                 :            :                         }
     957                 :            :                 }
     958                 :            : 
     959                 :            :                 /* Add delay to filter out noises during initial link setup */
     960                 :          0 :                 msec_delay(50);
     961                 :            :         }
     962                 :            : 
     963                 :          0 : out:
     964                 :          0 :         return status;
     965                 :            : }
     966                 :            : 
     967                 :            : /**
     968                 :            :  * ixgbe_setup_copper_link_82599 - Set the PHY autoneg advertised field
     969                 :            :  * @hw: pointer to hardware structure
     970                 :            :  * @speed: new link speed
     971                 :            :  * @autoneg_wait_to_complete: true if waiting is needed to complete
     972                 :            :  *
     973                 :            :  * Restarts link on PHY and MAC based on settings passed in.
     974                 :            :  **/
     975                 :          0 : STATIC s32 ixgbe_setup_copper_link_82599(struct ixgbe_hw *hw,
     976                 :            :                                          ixgbe_link_speed speed,
     977                 :            :                                          bool autoneg_wait_to_complete)
     978                 :            : {
     979                 :            :         s32 status;
     980                 :            : 
     981                 :          0 :         DEBUGFUNC("ixgbe_setup_copper_link_82599");
     982                 :            : 
     983                 :            :         /* Setup the PHY according to input speed */
     984                 :          0 :         status = hw->phy.ops.setup_link_speed(hw, speed,
     985                 :            :                                               autoneg_wait_to_complete);
     986                 :            :         /* Set up MAC */
     987                 :          0 :         ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
     988                 :            : 
     989                 :          0 :         return status;
     990                 :            : }
     991                 :            : 
     992                 :            : /**
     993                 :            :  * ixgbe_reset_hw_82599 - Perform hardware reset
     994                 :            :  * @hw: pointer to hardware structure
     995                 :            :  *
     996                 :            :  * Resets the hardware by resetting the transmit and receive units, masks
     997                 :            :  * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
     998                 :            :  * reset.
     999                 :            :  **/
    1000                 :          0 : s32 ixgbe_reset_hw_82599(struct ixgbe_hw *hw)
    1001                 :            : {
    1002                 :            :         ixgbe_link_speed link_speed;
    1003                 :            :         s32 status;
    1004                 :            :         u32 ctrl = 0;
    1005                 :            :         u32 i, autoc, autoc2;
    1006                 :            :         u32 curr_lms;
    1007                 :          0 :         bool link_up = false;
    1008                 :            : 
    1009                 :          0 :         DEBUGFUNC("ixgbe_reset_hw_82599");
    1010                 :            : 
    1011                 :            :         /* Call adapter stop to disable tx/rx and clear interrupts */
    1012                 :          0 :         status = hw->mac.ops.stop_adapter(hw);
    1013         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1014                 :          0 :                 goto reset_hw_out;
    1015                 :            : 
    1016                 :            :         /* flush pending Tx transactions */
    1017                 :          0 :         ixgbe_clear_tx_pending(hw);
    1018                 :            : 
    1019                 :            :         /* PHY ops must be identified and initialized prior to reset */
    1020                 :            : 
    1021                 :            :         /* Identify PHY and related function pointers */
    1022                 :          0 :         status = hw->phy.ops.init(hw);
    1023                 :            : 
    1024         [ #  # ]:          0 :         if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
    1025                 :          0 :                 goto reset_hw_out;
    1026                 :            : 
    1027                 :            :         /* Setup SFP module if there is one present. */
    1028         [ #  # ]:          0 :         if (hw->phy.sfp_setup_needed) {
    1029                 :          0 :                 status = hw->mac.ops.setup_sfp(hw);
    1030                 :          0 :                 hw->phy.sfp_setup_needed = false;
    1031                 :            :         }
    1032                 :            : 
    1033         [ #  # ]:          0 :         if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
    1034                 :          0 :                 goto reset_hw_out;
    1035                 :            : 
    1036                 :            :         /* Reset PHY */
    1037   [ #  #  #  # ]:          0 :         if (hw->phy.reset_disable == false && hw->phy.ops.reset != NULL)
    1038                 :          0 :                 hw->phy.ops.reset(hw);
    1039                 :            : 
    1040                 :            :         /* remember AUTOC from before we reset */
    1041                 :          0 :         curr_lms = IXGBE_READ_REG(hw, IXGBE_AUTOC) & IXGBE_AUTOC_LMS_MASK;
    1042                 :            : 
    1043                 :          0 : mac_reset_top:
    1044                 :            :         /*
    1045                 :            :          * Issue global reset to the MAC.  Needs to be SW reset if link is up.
    1046                 :            :          * If link reset is used when link is up, it might reset the PHY when
    1047                 :            :          * mng is using it.  If link is down or the flag to force full link
    1048                 :            :          * reset is set, then perform link reset.
    1049                 :            :          */
    1050                 :            :         ctrl = IXGBE_CTRL_LNK_RST;
    1051         [ #  # ]:          0 :         if (!hw->force_full_reset) {
    1052                 :          0 :                 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
    1053         [ #  # ]:          0 :                 if (link_up)
    1054                 :            :                         ctrl = IXGBE_CTRL_RST;
    1055                 :            :         }
    1056                 :            : 
    1057                 :          0 :         ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
    1058                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
    1059                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1060                 :            : 
    1061                 :            :         /* Poll for reset bit to self-clear meaning reset is complete */
    1062         [ #  # ]:          0 :         for (i = 0; i < 10; i++) {
    1063                 :          0 :                 usec_delay(1);
    1064                 :          0 :                 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
    1065         [ #  # ]:          0 :                 if (!(ctrl & IXGBE_CTRL_RST_MASK))
    1066                 :            :                         break;
    1067                 :            :         }
    1068                 :            : 
    1069         [ #  # ]:          0 :         if (ctrl & IXGBE_CTRL_RST_MASK) {
    1070                 :            :                 status = IXGBE_ERR_RESET_FAILED;
    1071                 :          0 :                 DEBUGOUT("Reset polling failed to complete.\n");
    1072                 :            :         }
    1073                 :            : 
    1074                 :          0 :         msec_delay(50);
    1075                 :            : 
    1076                 :            :         /*
    1077                 :            :          * Double resets are required for recovery from certain error
    1078                 :            :          * conditions.  Between resets, it is necessary to stall to
    1079                 :            :          * allow time for any pending HW events to complete.
    1080                 :            :          */
    1081         [ #  # ]:          0 :         if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
    1082                 :          0 :                 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
    1083                 :          0 :                 goto mac_reset_top;
    1084                 :            :         }
    1085                 :            : 
    1086                 :            :         /*
    1087                 :            :          * Store the original AUTOC/AUTOC2 values if they have not been
    1088                 :            :          * stored off yet.  Otherwise restore the stored original
    1089                 :            :          * values since the reset operation sets back to defaults.
    1090                 :            :          */
    1091                 :          0 :         autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
    1092                 :          0 :         autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
    1093                 :            : 
    1094                 :            :         /* Enable link if disabled in NVM */
    1095         [ #  # ]:          0 :         if (autoc2 & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
    1096                 :          0 :                 autoc2 &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
    1097                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
    1098                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    1099                 :            :         }
    1100                 :            : 
    1101         [ #  # ]:          0 :         if (hw->mac.orig_link_settings_stored == false) {
    1102                 :          0 :                 hw->mac.orig_autoc = autoc;
    1103                 :          0 :                 hw->mac.orig_autoc2 = autoc2;
    1104                 :          0 :                 hw->mac.orig_link_settings_stored = true;
    1105                 :            :         } else {
    1106                 :            : 
    1107                 :            :                 /* If MNG FW is running on a multi-speed device that
    1108                 :            :                  * doesn't autoneg with out driver support we need to
    1109                 :            :                  * leave LMS in the state it was before we MAC reset.
    1110                 :            :                  * Likewise if we support WoL we don't want change the
    1111                 :            :                  * LMS state.
    1112                 :            :                  */
    1113   [ #  #  #  # ]:          0 :                 if ((hw->phy.multispeed_fiber && ixgbe_mng_enabled(hw)) ||
    1114         [ #  # ]:          0 :                     hw->wol_enabled)
    1115                 :          0 :                         hw->mac.orig_autoc =
    1116                 :          0 :                                 (hw->mac.orig_autoc & ~IXGBE_AUTOC_LMS_MASK) |
    1117                 :            :                                 curr_lms;
    1118                 :            : 
    1119         [ #  # ]:          0 :                 if (autoc != hw->mac.orig_autoc) {
    1120                 :          0 :                         status = hw->mac.ops.prot_autoc_write(hw,
    1121                 :            :                                                         hw->mac.orig_autoc,
    1122                 :            :                                                         false);
    1123         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
    1124                 :          0 :                                 goto reset_hw_out;
    1125                 :            :                 }
    1126                 :            : 
    1127                 :          0 :                 if ((autoc2 & IXGBE_AUTOC2_UPPER_MASK) !=
    1128         [ #  # ]:          0 :                     (hw->mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
    1129                 :          0 :                         autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
    1130                 :          0 :                         autoc2 |= (hw->mac.orig_autoc2 &
    1131                 :            :                                    IXGBE_AUTOC2_UPPER_MASK);
    1132                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2);
    1133                 :            :                 }
    1134                 :            :         }
    1135                 :            : 
    1136                 :            :         /* Store the permanent mac address */
    1137                 :          0 :         hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
    1138                 :            : 
    1139                 :            :         /*
    1140                 :            :          * Store MAC address from RAR0, clear receive address registers, and
    1141                 :            :          * clear the multicast table.  Also reset num_rar_entries to 128,
    1142                 :            :          * since we modify this value when programming the SAN MAC address.
    1143                 :            :          */
    1144                 :          0 :         hw->mac.num_rar_entries = 128;
    1145                 :          0 :         hw->mac.ops.init_rx_addrs(hw);
    1146                 :            : 
    1147                 :            :         /* Store the permanent SAN mac address */
    1148                 :          0 :         hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
    1149                 :            : 
    1150                 :            :         /* Add the SAN MAC address to the RAR only if it's a valid address */
    1151         [ #  # ]:          0 :         if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
    1152                 :            :                 /* Save the SAN MAC RAR index */
    1153                 :          0 :                 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
    1154                 :            : 
    1155                 :          0 :                 hw->mac.ops.set_rar(hw, hw->mac.san_mac_rar_index,
    1156                 :            :                                     hw->mac.san_addr, 0, IXGBE_RAH_AV);
    1157                 :            : 
    1158                 :            :                 /* clear VMDq pool/queue selection for this RAR */
    1159                 :          0 :                 hw->mac.ops.clear_vmdq(hw, hw->mac.san_mac_rar_index,
    1160                 :            :                                        IXGBE_CLEAR_VMDQ_ALL);
    1161                 :            : 
    1162                 :            :                 /* Reserve the last RAR for the SAN MAC address */
    1163                 :          0 :                 hw->mac.num_rar_entries--;
    1164                 :            :         }
    1165                 :            : 
    1166                 :            :         /* Store the alternative WWNN/WWPN prefix */
    1167                 :          0 :         hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
    1168                 :            :                                    &hw->mac.wwpn_prefix);
    1169                 :            : 
    1170                 :          0 : reset_hw_out:
    1171                 :          0 :         return status;
    1172                 :            : }
    1173                 :            : 
    1174                 :            : /**
    1175                 :            :  * ixgbe_fdir_check_cmd_complete - poll to check whether FDIRCMD is complete
    1176                 :            :  * @hw: pointer to hardware structure
    1177                 :            :  * @fdircmd: current value of FDIRCMD register
    1178                 :            :  */
    1179                 :            : STATIC s32 ixgbe_fdir_check_cmd_complete(struct ixgbe_hw *hw, u32 *fdircmd)
    1180                 :            : {
    1181                 :            :         int i;
    1182                 :            : 
    1183   [ #  #  #  #  :          0 :         for (i = 0; i < IXGBE_FDIRCMD_CMD_POLL; i++) {
                   #  # ]
    1184                 :          0 :                 *fdircmd = IXGBE_READ_REG(hw, IXGBE_FDIRCMD);
    1185   [ #  #  #  #  :          0 :                 if (!(*fdircmd & IXGBE_FDIRCMD_CMD_MASK))
                   #  # ]
    1186                 :            :                         return IXGBE_SUCCESS;
    1187                 :          0 :                 usec_delay(10);
    1188                 :            :         }
    1189                 :            : 
    1190                 :            :         return IXGBE_ERR_FDIR_CMD_INCOMPLETE;
    1191                 :            : }
    1192                 :            : 
    1193                 :            : /**
    1194                 :            :  * ixgbe_reinit_fdir_tables_82599 - Reinitialize Flow Director tables.
    1195                 :            :  * @hw: pointer to hardware structure
    1196                 :            :  **/
    1197                 :          0 : s32 ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw)
    1198                 :            : {
    1199                 :            :         s32 err;
    1200                 :            :         int i;
    1201                 :          0 :         u32 fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
    1202                 :            :         u32 fdircmd;
    1203                 :          0 :         fdirctrl &= ~IXGBE_FDIRCTRL_INIT_DONE;
    1204                 :            : 
    1205                 :          0 :         DEBUGFUNC("ixgbe_reinit_fdir_tables_82599");
    1206                 :            : 
    1207                 :            :         /*
    1208                 :            :          * Before starting reinitialization process,
    1209                 :            :          * FDIRCMD.CMD must be zero.
    1210                 :            :          */
    1211                 :            :         err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
    1212         [ #  # ]:          0 :         if (err) {
    1213                 :          0 :                 DEBUGOUT("Flow Director previous command did not complete, aborting table re-initialization.\n");
    1214                 :          0 :                 return err;
    1215                 :            :         }
    1216                 :            : 
    1217                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRFREE, 0);
    1218                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1219                 :            :         /*
    1220                 :            :          * 82599 adapters flow director init flow cannot be restarted,
    1221                 :            :          * Workaround 82599 silicon errata by performing the following steps
    1222                 :            :          * before re-writing the FDIRCTRL control register with the same value.
    1223                 :            :          * - write 1 to bit 8 of FDIRCMD register &
    1224                 :            :          * - write 0 to bit 8 of FDIRCMD register
    1225                 :            :          */
    1226                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
    1227                 :            :                         (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
    1228                 :            :                          IXGBE_FDIRCMD_CLEARHT));
    1229                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1230                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
    1231                 :            :                         (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
    1232                 :            :                          ~IXGBE_FDIRCMD_CLEARHT));
    1233                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1234                 :            :         /*
    1235                 :            :          * Clear FDIR Hash register to clear any leftover hashes
    1236                 :            :          * waiting to be programmed.
    1237                 :            :          */
    1238                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, 0x00);
    1239                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1240                 :            : 
    1241                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
    1242                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1243                 :            : 
    1244                 :            :         /* Poll init-done after we write FDIRCTRL register */
    1245         [ #  # ]:          0 :         for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
    1246         [ #  # ]:          0 :                 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
    1247                 :            :                                    IXGBE_FDIRCTRL_INIT_DONE)
    1248                 :            :                         break;
    1249                 :          0 :                 msec_delay(1);
    1250                 :            :         }
    1251         [ #  # ]:          0 :         if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
    1252                 :          0 :                 DEBUGOUT("Flow Director Signature poll time exceeded!\n");
    1253                 :          0 :                 return IXGBE_ERR_FDIR_REINIT_FAILED;
    1254                 :            :         }
    1255                 :            : 
    1256                 :            :         /* Clear FDIR statistics registers (read to clear) */
    1257                 :          0 :         IXGBE_READ_REG(hw, IXGBE_FDIRUSTAT);
    1258                 :          0 :         IXGBE_READ_REG(hw, IXGBE_FDIRFSTAT);
    1259                 :          0 :         IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
    1260                 :          0 :         IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
    1261                 :          0 :         IXGBE_READ_REG(hw, IXGBE_FDIRLEN);
    1262                 :            : 
    1263                 :          0 :         return IXGBE_SUCCESS;
    1264                 :            : }
    1265                 :            : 
    1266                 :            : /**
    1267                 :            :  * ixgbe_fdir_enable_82599 - Initialize Flow Director control registers
    1268                 :            :  * @hw: pointer to hardware structure
    1269                 :            :  * @fdirctrl: value to write to flow director control register
    1270                 :            :  **/
    1271                 :          0 : STATIC void ixgbe_fdir_enable_82599(struct ixgbe_hw *hw, u32 fdirctrl)
    1272                 :            : {
    1273                 :            :         int i;
    1274                 :            : 
    1275                 :          0 :         DEBUGFUNC("ixgbe_fdir_enable_82599");
    1276                 :            : 
    1277                 :            :         /* Prime the keys for hashing */
    1278                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRHKEY, IXGBE_ATR_BUCKET_HASH_KEY);
    1279                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRSKEY, IXGBE_ATR_SIGNATURE_HASH_KEY);
    1280                 :            : 
    1281                 :            :         /*
    1282                 :            :          * Poll init-done after we write the register.  Estimated times:
    1283                 :            :          *      10G: PBALLOC = 11b, timing is 60us
    1284                 :            :          *       1G: PBALLOC = 11b, timing is 600us
    1285                 :            :          *     100M: PBALLOC = 11b, timing is 6ms
    1286                 :            :          *
    1287                 :            :          *     Multiple these timings by 4 if under full Rx load
    1288                 :            :          *
    1289                 :            :          * So we'll poll for IXGBE_FDIR_INIT_DONE_POLL times, sleeping for
    1290                 :            :          * 1 msec per poll time.  If we're at line rate and drop to 100M, then
    1291                 :            :          * this might not finish in our poll time, but we can live with that
    1292                 :            :          * for now.
    1293                 :            :          */
    1294                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCTRL, fdirctrl);
    1295                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1296         [ #  # ]:          0 :         for (i = 0; i < IXGBE_FDIR_INIT_DONE_POLL; i++) {
    1297         [ #  # ]:          0 :                 if (IXGBE_READ_REG(hw, IXGBE_FDIRCTRL) &
    1298                 :            :                                    IXGBE_FDIRCTRL_INIT_DONE)
    1299                 :            :                         break;
    1300                 :          0 :                 msec_delay(1);
    1301                 :            :         }
    1302                 :            : 
    1303         [ #  # ]:          0 :         if (i >= IXGBE_FDIR_INIT_DONE_POLL)
    1304                 :          0 :                 DEBUGOUT("Flow Director poll time exceeded!\n");
    1305                 :          0 : }
    1306                 :            : 
    1307                 :            : /**
    1308                 :            :  * ixgbe_init_fdir_signature_82599 - Initialize Flow Director signature filters
    1309                 :            :  * @hw: pointer to hardware structure
    1310                 :            :  * @fdirctrl: value to write to flow director control register, initially
    1311                 :            :  *           contains just the value of the Rx packet buffer allocation
    1312                 :            :  **/
    1313                 :          0 : s32 ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, u32 fdirctrl)
    1314                 :            : {
    1315                 :          0 :         DEBUGFUNC("ixgbe_init_fdir_signature_82599");
    1316                 :            : 
    1317                 :            :         /*
    1318                 :            :          * Continue setup of fdirctrl register bits:
    1319                 :            :          *  Move the flexible bytes to use the ethertype - shift 6 words
    1320                 :            :          *  Set the maximum length per hash bucket to 0xA filters
    1321                 :            :          *  Send interrupt when 64 filters are left
    1322                 :            :          */
    1323                 :          0 :         fdirctrl |= (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
    1324                 :            :                     (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
    1325                 :            :                     (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
    1326                 :            : 
    1327                 :            :         /* write hashes and fdirctrl register, poll for completion */
    1328                 :          0 :         ixgbe_fdir_enable_82599(hw, fdirctrl);
    1329                 :            : 
    1330                 :          0 :         return IXGBE_SUCCESS;
    1331                 :            : }
    1332                 :            : 
    1333                 :            : /**
    1334                 :            :  * ixgbe_init_fdir_perfect_82599 - Initialize Flow Director perfect filters
    1335                 :            :  * @hw: pointer to hardware structure
    1336                 :            :  * @fdirctrl: value to write to flow director control register, initially
    1337                 :            :  *           contains just the value of the Rx packet buffer allocation
    1338                 :            :  * @cloud_mode: true - cloud mode, false - other mode
    1339                 :            :  **/
    1340                 :          0 : s32 ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, u32 fdirctrl,
    1341                 :            :                         bool cloud_mode)
    1342                 :            : {
    1343                 :            :         UNREFERENCED_1PARAMETER(cloud_mode);
    1344                 :          0 :         DEBUGFUNC("ixgbe_init_fdir_perfect_82599");
    1345                 :            : 
    1346                 :            :         /*
    1347                 :            :          * Continue setup of fdirctrl register bits:
    1348                 :            :          *  Turn perfect match filtering on
    1349                 :            :          *  Report hash in RSS field of Rx wb descriptor
    1350                 :            :          *  Initialize the drop queue to queue 127
    1351                 :            :          *  Move the flexible bytes to use the ethertype - shift 6 words
    1352                 :            :          *  Set the maximum length per hash bucket to 0xA filters
    1353                 :            :          *  Send interrupt when 64 (0x4 * 16) filters are left
    1354                 :            :          */
    1355                 :          0 :         fdirctrl |= IXGBE_FDIRCTRL_PERFECT_MATCH |
    1356                 :            :                     IXGBE_FDIRCTRL_REPORT_STATUS |
    1357                 :            :                     (IXGBE_FDIR_DROP_QUEUE << IXGBE_FDIRCTRL_DROP_Q_SHIFT) |
    1358                 :            :                     (0x6 << IXGBE_FDIRCTRL_FLEX_SHIFT) |
    1359                 :            :                     (0xA << IXGBE_FDIRCTRL_MAX_LENGTH_SHIFT) |
    1360                 :            :                     (4 << IXGBE_FDIRCTRL_FULL_THRESH_SHIFT);
    1361                 :            : 
    1362         [ #  # ]:          0 :         if (cloud_mode)
    1363                 :          0 :                 fdirctrl |=(IXGBE_FDIRCTRL_FILTERMODE_CLOUD <<
    1364                 :            :                                         IXGBE_FDIRCTRL_FILTERMODE_SHIFT);
    1365                 :            : 
    1366                 :            :         /* write hashes and fdirctrl register, poll for completion */
    1367                 :          0 :         ixgbe_fdir_enable_82599(hw, fdirctrl);
    1368                 :            : 
    1369                 :          0 :         return IXGBE_SUCCESS;
    1370                 :            : }
    1371                 :            : 
    1372                 :            : /**
    1373                 :            :  * ixgbe_set_fdir_drop_queue_82599 - Set Flow Director drop queue
    1374                 :            :  * @hw: pointer to hardware structure
    1375                 :            :  * @dropqueue: Rx queue index used for the dropped packets
    1376                 :            :  **/
    1377                 :          0 : void ixgbe_set_fdir_drop_queue_82599(struct ixgbe_hw *hw, u8 dropqueue)
    1378                 :            : {
    1379                 :            :         u32 fdirctrl;
    1380                 :            : 
    1381                 :          0 :         DEBUGFUNC("ixgbe_set_fdir_drop_queue_82599");
    1382                 :            :         /* Clear init done bit and drop queue field */
    1383                 :          0 :         fdirctrl = IXGBE_READ_REG(hw, IXGBE_FDIRCTRL);
    1384                 :          0 :         fdirctrl &= ~(IXGBE_FDIRCTRL_DROP_Q_MASK | IXGBE_FDIRCTRL_INIT_DONE);
    1385                 :            : 
    1386                 :            :         /* Set drop queue */
    1387                 :          0 :         fdirctrl |= (dropqueue << IXGBE_FDIRCTRL_DROP_Q_SHIFT);
    1388                 :          0 :         if ((hw->mac.type == ixgbe_mac_X550) ||
    1389         [ #  # ]:          0 :             (hw->mac.type == ixgbe_mac_X550EM_x) ||
    1390                 :            :             (hw->mac.type == ixgbe_mac_X550EM_a))
    1391                 :          0 :                 fdirctrl |= IXGBE_FDIRCTRL_DROP_NO_MATCH;
    1392                 :            : 
    1393                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
    1394                 :            :                         (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) |
    1395                 :            :                          IXGBE_FDIRCMD_CLEARHT));
    1396                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1397                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
    1398                 :            :                         (IXGBE_READ_REG(hw, IXGBE_FDIRCMD) &
    1399                 :            :                          ~IXGBE_FDIRCMD_CLEARHT));
    1400                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1401                 :            : 
    1402                 :            :         /* write hashes and fdirctrl register, poll for completion */
    1403                 :          0 :         ixgbe_fdir_enable_82599(hw, fdirctrl);
    1404                 :          0 : }
    1405                 :            : 
    1406                 :            : /*
    1407                 :            :  * These defines allow us to quickly generate all of the necessary instructions
    1408                 :            :  * in the function below by simply calling out IXGBE_COMPUTE_SIG_HASH_ITERATION
    1409                 :            :  * for values 0 through 15
    1410                 :            :  */
    1411                 :            : #define IXGBE_ATR_COMMON_HASH_KEY \
    1412                 :            :                 (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
    1413                 :            : #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
    1414                 :            : do { \
    1415                 :            :         u32 n = (_n); \
    1416                 :            :         if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
    1417                 :            :                 common_hash ^= lo_hash_dword >> n; \
    1418                 :            :         else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
    1419                 :            :                 bucket_hash ^= lo_hash_dword >> n; \
    1420                 :            :         else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
    1421                 :            :                 sig_hash ^= lo_hash_dword << (16 - n); \
    1422                 :            :         if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
    1423                 :            :                 common_hash ^= hi_hash_dword >> n; \
    1424                 :            :         else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
    1425                 :            :                 bucket_hash ^= hi_hash_dword >> n; \
    1426                 :            :         else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
    1427                 :            :                 sig_hash ^= hi_hash_dword << (16 - n); \
    1428                 :            : } while (0)
    1429                 :            : 
    1430                 :            : /**
    1431                 :            :  * ixgbe_atr_compute_sig_hash_82599 - Compute the signature hash
    1432                 :            :  * @input: input bitstream to compute the hash on
    1433                 :            :  * @common: compressed common input dword
    1434                 :            :  *
    1435                 :            :  * This function is almost identical to the function above but contains
    1436                 :            :  * several optimizations such as unwinding all of the loops, letting the
    1437                 :            :  * compiler work out all of the conditional ifs since the keys are static
    1438                 :            :  * defines, and computing two keys at once since the hashed dword stream
    1439                 :            :  * will be the same for both keys.
    1440                 :            :  **/
    1441                 :          0 : u32 ixgbe_atr_compute_sig_hash_82599(union ixgbe_atr_hash_dword input,
    1442                 :            :                                      union ixgbe_atr_hash_dword common)
    1443                 :            : {
    1444                 :            :         u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
    1445                 :            :         u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
    1446                 :            : 
    1447                 :            :         /* record the flow_vm_vlan bits as they are a key part to the hash */
    1448         [ #  # ]:          0 :         flow_vm_vlan = IXGBE_NTOHL(input.dword);
    1449                 :            : 
    1450                 :            :         /* generate common hash dword */
    1451         [ #  # ]:          0 :         hi_hash_dword = IXGBE_NTOHL(common.dword);
    1452                 :            : 
    1453                 :            :         /* low dword is word swapped version of common */
    1454                 :          0 :         lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
    1455                 :            : 
    1456                 :            :         /* apply flow ID/VM pool/VLAN ID bits to hash words */
    1457                 :          0 :         hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
    1458                 :            : 
    1459                 :            :         /* Process bits 0 and 16 */
    1460                 :            :         IXGBE_COMPUTE_SIG_HASH_ITERATION(0);
    1461                 :            : 
    1462                 :            :         /*
    1463                 :            :          * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
    1464                 :            :          * delay this because bit 0 of the stream should not be processed
    1465                 :            :          * so we do not add the VLAN until after bit 0 was processed
    1466                 :            :          */
    1467                 :          0 :         lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
    1468                 :            : 
    1469                 :            :         /* Process remaining 30 bit of the key */
    1470                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(1);
    1471                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(2);
    1472                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(3);
    1473                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(4);
    1474                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(5);
    1475                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(6);
    1476                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(7);
    1477                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(8);
    1478                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(9);
    1479                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(10);
    1480                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(11);
    1481                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(12);
    1482                 :          0 :         IXGBE_COMPUTE_SIG_HASH_ITERATION(13);
    1483                 :            :         IXGBE_COMPUTE_SIG_HASH_ITERATION(14);
    1484                 :            :         IXGBE_COMPUTE_SIG_HASH_ITERATION(15);
    1485                 :            : 
    1486                 :            :         /* combine common_hash result with signature and bucket hashes */
    1487                 :          0 :         bucket_hash ^= common_hash;
    1488                 :          0 :         bucket_hash &= IXGBE_ATR_HASH_MASK;
    1489                 :            : 
    1490                 :          0 :         sig_hash ^= common_hash << 16;
    1491                 :          0 :         sig_hash &= IXGBE_ATR_HASH_MASK << 16;
    1492                 :            : 
    1493                 :            :         /* return completed signature hash */
    1494                 :          0 :         return sig_hash ^ bucket_hash;
    1495                 :            : }
    1496                 :            : 
    1497                 :            : /**
    1498                 :            :  * ixgbe_atr_add_signature_filter_82599 - Adds a signature hash filter
    1499                 :            :  * @hw: pointer to hardware structure
    1500                 :            :  * @input: unique input dword
    1501                 :            :  * @common: compressed common input dword
    1502                 :            :  * @queue: queue index to direct traffic to
    1503                 :            :  *
    1504                 :            :  * Note that the tunnel bit in input must not be set when the hardware
    1505                 :            :  * tunneling support does not exist.
    1506                 :            :  **/
    1507                 :          0 : void ixgbe_fdir_add_signature_filter_82599(struct ixgbe_hw *hw,
    1508                 :            :                                            union ixgbe_atr_hash_dword input,
    1509                 :            :                                            union ixgbe_atr_hash_dword common,
    1510                 :            :                                            u8 queue)
    1511                 :            : {
    1512                 :            :         u64 fdirhashcmd;
    1513                 :            :         u8 flow_type;
    1514                 :            :         bool tunnel;
    1515                 :            :         u32 fdircmd;
    1516                 :            : 
    1517                 :          0 :         DEBUGFUNC("ixgbe_fdir_add_signature_filter_82599");
    1518                 :            : 
    1519                 :            :         /*
    1520                 :            :          * Get the flow_type in order to program FDIRCMD properly
    1521                 :            :          * lowest 2 bits are FDIRCMD.L4TYPE, third lowest bit is FDIRCMD.IPV6
    1522                 :            :          * fifth is FDIRCMD.TUNNEL_FILTER
    1523                 :            :          */
    1524                 :            :         tunnel = !!(input.formatted.flow_type & IXGBE_ATR_L4TYPE_TUNNEL_MASK);
    1525                 :          0 :         flow_type = input.formatted.flow_type &
    1526                 :            :                     (IXGBE_ATR_L4TYPE_TUNNEL_MASK - 1);
    1527         [ #  # ]:          0 :         switch (flow_type) {
    1528                 :            :         case IXGBE_ATR_FLOW_TYPE_TCPV4:
    1529                 :            :         case IXGBE_ATR_FLOW_TYPE_UDPV4:
    1530                 :            :         case IXGBE_ATR_FLOW_TYPE_SCTPV4:
    1531                 :            :         case IXGBE_ATR_FLOW_TYPE_TCPV6:
    1532                 :            :         case IXGBE_ATR_FLOW_TYPE_UDPV6:
    1533                 :            :         case IXGBE_ATR_FLOW_TYPE_SCTPV6:
    1534                 :            :                 break;
    1535                 :          0 :         default:
    1536                 :          0 :                 DEBUGOUT(" Error on flow type input\n");
    1537                 :          0 :                 return;
    1538                 :            :         }
    1539                 :            : 
    1540                 :            :         /* configure FDIRCMD register */
    1541                 :            :         fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
    1542                 :            :                   IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
    1543                 :          0 :         fdircmd |= (u32)flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
    1544                 :          0 :         fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
    1545         [ #  # ]:          0 :         if (tunnel)
    1546                 :          0 :                 fdircmd |= IXGBE_FDIRCMD_TUNNEL_FILTER;
    1547                 :            : 
    1548                 :            :         /*
    1549                 :            :          * The lower 32-bits of fdirhashcmd is for FDIRHASH, the upper 32-bits
    1550                 :            :          * is for FDIRCMD.  Then do a 64-bit register write from FDIRHASH.
    1551                 :            :          */
    1552                 :          0 :         fdirhashcmd = (u64)fdircmd << 32;
    1553                 :          0 :         fdirhashcmd |= (u64)ixgbe_atr_compute_sig_hash_82599(input, common);
    1554                 :          0 :         IXGBE_WRITE_REG64(hw, IXGBE_FDIRHASH, fdirhashcmd);
    1555                 :            : 
    1556                 :          0 :         DEBUGOUT2("Tx Queue=%x hash=%x\n", queue, (u32)fdirhashcmd);
    1557                 :            : 
    1558                 :          0 :         return;
    1559                 :            : }
    1560                 :            : 
    1561                 :            : #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
    1562                 :            : do { \
    1563                 :            :         u32 n = (_n); \
    1564                 :            :         if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
    1565                 :            :                 bucket_hash ^= lo_hash_dword >> n; \
    1566                 :            :         if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
    1567                 :            :                 bucket_hash ^= hi_hash_dword >> n; \
    1568                 :            : } while (0)
    1569                 :            : 
    1570                 :            : /**
    1571                 :            :  * ixgbe_atr_compute_perfect_hash_82599 - Compute the perfect filter hash
    1572                 :            :  * @input: input bitstream to compute the hash on
    1573                 :            :  * @input_mask: mask for the input bitstream
    1574                 :            :  *
    1575                 :            :  * This function serves two main purposes.  First it applies the input_mask
    1576                 :            :  * to the atr_input resulting in a cleaned up atr_input data stream.
    1577                 :            :  * Secondly it computes the hash and stores it in the bkt_hash field at
    1578                 :            :  * the end of the input byte stream.  This way it will be available for
    1579                 :            :  * future use without needing to recompute the hash.
    1580                 :            :  **/
    1581                 :          0 : void ixgbe_atr_compute_perfect_hash_82599(union ixgbe_atr_input *input,
    1582                 :            :                                           union ixgbe_atr_input *input_mask)
    1583                 :            : {
    1584                 :            : 
    1585                 :            :         u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
    1586                 :            :         u32 bucket_hash = 0;
    1587                 :            :         u32 hi_dword = 0;
    1588                 :            :         u32 i = 0;
    1589                 :            : 
    1590                 :            :         /* Apply masks to input data */
    1591         [ #  # ]:          0 :         for (i = 0; i < 14; i++)
    1592                 :          0 :                 input->dword_stream[i]  &= input_mask->dword_stream[i];
    1593                 :            : 
    1594                 :            :         /* record the flow_vm_vlan bits as they are a key part to the hash */
    1595         [ #  # ]:          0 :         flow_vm_vlan = IXGBE_NTOHL(input->dword_stream[0]);
    1596                 :            : 
    1597                 :            :         /* generate common hash dword */
    1598         [ #  # ]:          0 :         for (i = 1; i <= 13; i++)
    1599                 :          0 :                 hi_dword ^= input->dword_stream[i];
    1600         [ #  # ]:          0 :         hi_hash_dword = IXGBE_NTOHL(hi_dword);
    1601                 :            : 
    1602                 :            :         /* low dword is word swapped version of common */
    1603                 :          0 :         lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
    1604                 :            : 
    1605                 :            :         /* apply flow ID/VM pool/VLAN ID bits to hash words */
    1606                 :          0 :         hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
    1607                 :            : 
    1608                 :            :         /* Process bits 0 and 16 */
    1609                 :            :         IXGBE_COMPUTE_BKT_HASH_ITERATION(0);
    1610                 :            : 
    1611                 :            :         /*
    1612                 :            :          * apply flow ID/VM pool/VLAN ID bits to lo hash dword, we had to
    1613                 :            :          * delay this because bit 0 of the stream should not be processed
    1614                 :            :          * so we do not add the VLAN until after bit 0 was processed
    1615                 :            :          */
    1616                 :          0 :         lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
    1617                 :            : 
    1618                 :            :         /* Process remaining 30 bit of the key */
    1619         [ #  # ]:          0 :         for (i = 1; i <= 15; i++)
    1620   [ #  #  #  # ]:          0 :                 IXGBE_COMPUTE_BKT_HASH_ITERATION(i);
    1621                 :            : 
    1622                 :            :         /*
    1623                 :            :          * Limit hash to 13 bits since max bucket count is 8K.
    1624                 :            :          * Store result at the end of the input stream.
    1625                 :            :          */
    1626                 :          0 :         input->formatted.bkt_hash = bucket_hash & 0x1FFF;
    1627                 :          0 : }
    1628                 :            : 
    1629                 :            : /**
    1630                 :            :  * ixgbe_get_fdirtcpm_82599 - generate a TCP port from atr_input_masks
    1631                 :            :  * @input_mask: mask to be bit swapped
    1632                 :            :  *
    1633                 :            :  * The source and destination port masks for flow director are bit swapped
    1634                 :            :  * in that bit 15 effects bit 0, 14 effects 1, 13, 2 etc.  In order to
    1635                 :            :  * generate a correctly swapped value we need to bit swap the mask and that
    1636                 :            :  * is what is accomplished by this function.
    1637                 :            :  **/
    1638                 :          0 : STATIC u32 ixgbe_get_fdirtcpm_82599(union ixgbe_atr_input *input_mask)
    1639                 :            : {
    1640         [ #  # ]:          0 :         u32 mask = IXGBE_NTOHS(input_mask->formatted.dst_port);
    1641                 :          0 :         mask <<= IXGBE_FDIRTCPM_DPORTM_SHIFT;
    1642         [ #  # ]:          0 :         mask |= (u32)IXGBE_NTOHS(input_mask->formatted.src_port);
    1643                 :          0 :         mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
    1644                 :          0 :         mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
    1645                 :          0 :         mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
    1646                 :          0 :         return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
    1647                 :            : }
    1648                 :            : 
    1649                 :            : /*
    1650                 :            :  * These two macros are meant to address the fact that we have registers
    1651                 :            :  * that are either all or in part big-endian.  As a result on big-endian
    1652                 :            :  * systems we will end up byte swapping the value to little-endian before
    1653                 :            :  * it is byte swapped again and written to the hardware in the original
    1654                 :            :  * big-endian format.
    1655                 :            :  */
    1656                 :            : #define IXGBE_STORE_AS_BE32(_value) \
    1657                 :            :         (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
    1658                 :            :          (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
    1659                 :            : 
    1660                 :            : #define IXGBE_WRITE_REG_BE32(a, reg, value) \
    1661                 :            :         IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(IXGBE_NTOHL(value)))
    1662                 :            : 
    1663                 :            : #define IXGBE_STORE_AS_BE16(_value) \
    1664                 :            :         IXGBE_NTOHS(((u16)(_value) >> 8) | ((u16)(_value) << 8))
    1665                 :            : 
    1666                 :          0 : s32 ixgbe_fdir_set_input_mask_82599(struct ixgbe_hw *hw,
    1667                 :            :                                     union ixgbe_atr_input *input_mask, bool cloud_mode)
    1668                 :            : {
    1669                 :            :         /* mask IPv6 since it is currently not supported */
    1670                 :            :         u32 fdirm = IXGBE_FDIRM_DIPv6;
    1671                 :            :         u32 fdirtcpm;
    1672                 :            :         u32 fdirip6m;
    1673                 :            :         UNREFERENCED_1PARAMETER(cloud_mode);
    1674                 :          0 :         DEBUGFUNC("ixgbe_fdir_set_atr_input_mask_82599");
    1675                 :            : 
    1676                 :            :         /*
    1677                 :            :          * Program the relevant mask registers.  If src/dst_port or src/dst_addr
    1678                 :            :          * are zero, then assume a full mask for that field.  Also assume that
    1679                 :            :          * a VLAN of 0 is unspecified, so mask that out as well.  L4type
    1680                 :            :          * cannot be masked out in this implementation.
    1681                 :            :          *
    1682                 :            :          * This also assumes IPv4 only.  IPv6 masking isn't supported at this
    1683                 :            :          * point in time.
    1684                 :            :          */
    1685                 :            : 
    1686                 :            :         /* verify bucket hash is cleared on hash generation */
    1687         [ #  # ]:          0 :         if (input_mask->formatted.bkt_hash)
    1688                 :          0 :                 DEBUGOUT(" bucket hash should always be 0 in mask\n");
    1689                 :            : 
    1690                 :            :         /* Program FDIRM and verify partial masks */
    1691      [ #  #  # ]:          0 :         switch (input_mask->formatted.vm_pool & 0x7F) {
    1692                 :          0 :         case 0x0:
    1693                 :            :                 fdirm |= IXGBE_FDIRM_POOL;
    1694                 :            :         case 0x7F:
    1695                 :            :                 break;
    1696                 :          0 :         default:
    1697                 :          0 :                 DEBUGOUT(" Error on vm pool mask\n");
    1698                 :          0 :                 return IXGBE_ERR_CONFIG;
    1699                 :            :         }
    1700                 :            : 
    1701      [ #  #  # ]:          0 :         switch (input_mask->formatted.flow_type & IXGBE_ATR_L4TYPE_MASK) {
    1702                 :          0 :         case 0x0:
    1703                 :          0 :                 fdirm |= IXGBE_FDIRM_L4P;
    1704         [ #  # ]:          0 :                 if (input_mask->formatted.dst_port ||
    1705                 :            :                     input_mask->formatted.src_port) {
    1706                 :          0 :                         DEBUGOUT(" Error on src/dst port mask\n");
    1707                 :          0 :                         return IXGBE_ERR_CONFIG;
    1708                 :            :                 }
    1709                 :            :         case IXGBE_ATR_L4TYPE_MASK:
    1710                 :            :                 break;
    1711                 :          0 :         default:
    1712                 :          0 :                 DEBUGOUT(" Error on flow type mask\n");
    1713                 :          0 :                 return IXGBE_ERR_CONFIG;
    1714                 :            :         }
    1715                 :            : 
    1716   [ #  #  #  #  :          0 :         switch (IXGBE_NTOHS(input_mask->formatted.vlan_id) & 0xEFFF) {
                #  #  # ]
    1717                 :          0 :         case 0x0000:
    1718                 :            :                 /* mask VLAN ID */
    1719                 :          0 :                 fdirm |= IXGBE_FDIRM_VLANID;
    1720                 :            :                 /* fall through */
    1721                 :          0 :         case 0x0FFF:
    1722                 :            :                 /* mask VLAN priority */
    1723                 :          0 :                 fdirm |= IXGBE_FDIRM_VLANP;
    1724                 :          0 :                 break;
    1725                 :          0 :         case 0xE000:
    1726                 :            :                 /* mask VLAN ID only */
    1727                 :          0 :                 fdirm |= IXGBE_FDIRM_VLANID;
    1728                 :            :                 /* fall through */
    1729                 :            :         case 0xEFFF:
    1730                 :            :                 /* no VLAN fields masked */
    1731                 :            :                 break;
    1732                 :          0 :         default:
    1733                 :          0 :                 DEBUGOUT(" Error on VLAN mask\n");
    1734                 :          0 :                 return IXGBE_ERR_CONFIG;
    1735                 :            :         }
    1736                 :            : 
    1737      [ #  #  # ]:          0 :         switch (input_mask->formatted.flex_bytes & 0xFFFF) {
    1738                 :          0 :         case 0x0000:
    1739                 :            :                 /* Mask Flex Bytes */
    1740                 :          0 :                 fdirm |= IXGBE_FDIRM_FLEX;
    1741                 :            :                 /* fall through */
    1742                 :            :         case 0xFFFF:
    1743                 :            :                 break;
    1744                 :          0 :         default:
    1745                 :          0 :                 DEBUGOUT(" Error on flexible byte mask\n");
    1746                 :          0 :                 return IXGBE_ERR_CONFIG;
    1747                 :            :         }
    1748                 :            : 
    1749         [ #  # ]:          0 :         if (cloud_mode) {
    1750                 :          0 :                 fdirm |= IXGBE_FDIRM_L3P;
    1751                 :            :                 fdirip6m = ((u32) 0xFFFFU << IXGBE_FDIRIP6M_DIPM_SHIFT);
    1752                 :            :                 fdirip6m |= IXGBE_FDIRIP6M_ALWAYS_MASK;
    1753                 :            : 
    1754      [ #  #  # ]:          0 :                 switch (input_mask->formatted.inner_mac[0] & 0xFF) {
    1755                 :          0 :                 case 0x00:
    1756                 :            :                         /* Mask inner MAC, fall through */
    1757                 :            :                         fdirip6m |= IXGBE_FDIRIP6M_INNER_MAC;
    1758                 :            :                 case 0xFF:
    1759                 :            :                         break;
    1760                 :          0 :                 default:
    1761                 :          0 :                         DEBUGOUT(" Error on inner_mac byte mask\n");
    1762                 :          0 :                         return IXGBE_ERR_CONFIG;
    1763                 :            :                 }
    1764                 :            : 
    1765   [ #  #  #  # ]:          0 :                 switch (input_mask->formatted.tni_vni & 0xFFFFFFFF) {
    1766                 :          0 :                 case 0x0:
    1767                 :            :                         /* Mask vxlan id */
    1768                 :          0 :                         fdirip6m |= IXGBE_FDIRIP6M_TNI_VNI;
    1769                 :          0 :                         break;
    1770                 :          0 :                 case 0x00FFFFFF:
    1771                 :          0 :                         fdirip6m |= IXGBE_FDIRIP6M_TNI_VNI_24;
    1772                 :          0 :                         break;
    1773                 :            :                 case 0xFFFFFFFF:
    1774                 :            :                         break;
    1775                 :          0 :                 default:
    1776                 :          0 :                         DEBUGOUT(" Error on TNI/VNI byte mask\n");
    1777                 :          0 :                         return IXGBE_ERR_CONFIG;
    1778                 :            :                 }
    1779                 :            : 
    1780      [ #  #  # ]:          0 :                 switch (input_mask->formatted.tunnel_type & 0xFFFF) {
    1781                 :          0 :                 case 0x0:
    1782                 :            :                         /* Mask turnnel type, fall through */
    1783                 :          0 :                         fdirip6m |= IXGBE_FDIRIP6M_TUNNEL_TYPE;
    1784                 :            :                 case 0xFFFF:
    1785                 :            :                         break;
    1786                 :          0 :                 default:
    1787                 :          0 :                         DEBUGOUT(" Error on tunnel type byte mask\n");
    1788                 :          0 :                         return IXGBE_ERR_CONFIG;
    1789                 :            :                 }
    1790   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIP6M, fdirip6m);
             #  #  #  # ]
    1791                 :            : 
    1792                 :            :                 /* Set all bits in FDIRTCPM, FDIRUDPM, FDIRSCTPM,
    1793                 :            :                  * FDIRSIP4M and FDIRDIP4M in cloud mode to allow
    1794                 :            :                  * L3/L3 packets to tunnel.
    1795                 :            :                  */
    1796                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, 0xFFFFFFFF);
    1797                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, 0xFFFFFFFF);
    1798                 :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M, 0xFFFFFFFF);
    1799                 :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M, 0xFFFFFFFF);
    1800         [ #  # ]:          0 :                 switch (hw->mac.type) {
    1801                 :          0 :                 case ixgbe_mac_X550:
    1802                 :            :                 case ixgbe_mac_X550EM_x:
    1803                 :            :                 case ixgbe_mac_X550EM_a:
    1804                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, 0xFFFFFFFF);
    1805                 :            :                         break;
    1806                 :            :                 default:
    1807                 :            :                         break;
    1808                 :            :                 }
    1809                 :            :         }
    1810                 :            : 
    1811                 :            :         /* Now mask VM pool and destination IPv6 - bits 5 and 2 */
    1812                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRM, fdirm);
    1813                 :            : 
    1814         [ #  # ]:          0 :         if (!cloud_mode) {
    1815                 :            :                 /* store the TCP/UDP port masks, bit reversed from port
    1816                 :            :                  * layout */
    1817                 :          0 :                 fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
    1818                 :            : 
    1819                 :            :                 /* write both the same so that UDP and TCP use the same mask */
    1820                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRTCPM, ~fdirtcpm);
    1821                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRUDPM, ~fdirtcpm);
    1822                 :            :                 /* also use it for SCTP */
    1823         [ #  # ]:          0 :                 switch (hw->mac.type) {
    1824                 :          0 :                 case ixgbe_mac_X550:
    1825                 :            :                 case ixgbe_mac_X550EM_x:
    1826                 :            :                 case ixgbe_mac_X550EM_a:
    1827                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FDIRSCTPM, ~fdirtcpm);
    1828                 :            :                         break;
    1829                 :            :                 default:
    1830                 :            :                         break;
    1831                 :            :                 }
    1832                 :            : 
    1833                 :            :                 /* store source and destination IP masks (big-enian) */
    1834   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIP4M,
             #  #  #  # ]
    1835                 :            :                                      ~input_mask->formatted.src_ip[0]);
    1836   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRDIP4M,
             #  #  #  # ]
    1837                 :            :                                      ~input_mask->formatted.dst_ip[0]);
    1838                 :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIP6M, 0xFFFFFFFF);
    1839                 :            :         }
    1840                 :            :         return IXGBE_SUCCESS;
    1841                 :            : }
    1842                 :            : 
    1843                 :          0 : s32 ixgbe_fdir_write_perfect_filter_82599(struct ixgbe_hw *hw,
    1844                 :            :                                           union ixgbe_atr_input *input,
    1845                 :            :                                           u16 soft_id, u8 queue, bool cloud_mode)
    1846                 :            : {
    1847                 :            :         u32 fdirport, fdirvlan, fdirhash, fdircmd;
    1848                 :            :         u32 addr_low, addr_high;
    1849                 :            :         u32 cloud_type = 0;
    1850                 :            :         s32 err;
    1851                 :            :         UNREFERENCED_1PARAMETER(cloud_mode);
    1852                 :            : 
    1853                 :          0 :         DEBUGFUNC("ixgbe_fdir_write_perfect_filter_82599");
    1854         [ #  # ]:          0 :         if (!cloud_mode) {
    1855                 :            :                 /* currently IPv6 is not supported, must be programmed with 0 */
    1856   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0),
             #  #  #  # ]
    1857                 :            :                                      input->formatted.src_ip[0]);
    1858   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1),
             #  #  #  # ]
    1859                 :            :                                      input->formatted.src_ip[1]);
    1860   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2),
             #  #  #  # ]
    1861                 :            :                                      input->formatted.src_ip[2]);
    1862                 :            : 
    1863                 :            :                 /* record the source address (big-endian) */
    1864   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPSA,
             #  #  #  # ]
    1865                 :            :                         input->formatted.src_ip[0]);
    1866                 :            : 
    1867                 :            :                 /* record the first 32 bits of the destination address
    1868                 :            :                  * (big-endian) */
    1869   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRIPDA,
             #  #  #  # ]
    1870                 :            :                         input->formatted.dst_ip[0]);
    1871                 :            : 
    1872                 :            :                 /* record source and destination port (little-endian)*/
    1873         [ #  # ]:          0 :                 fdirport = IXGBE_NTOHS(input->formatted.dst_port);
    1874                 :          0 :                 fdirport <<= IXGBE_FDIRPORT_DESTINATION_SHIFT;
    1875         [ #  # ]:          0 :                 fdirport |= (u32)IXGBE_NTOHS(input->formatted.src_port);
    1876                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRPORT, fdirport);
    1877                 :            :         }
    1878                 :            : 
    1879                 :            :         /* record VLAN (little-endian) and flex_bytes(big-endian) */
    1880         [ #  # ]:          0 :         fdirvlan = IXGBE_STORE_AS_BE16(input->formatted.flex_bytes);
    1881                 :          0 :         fdirvlan <<= IXGBE_FDIRVLAN_FLEX_SHIFT;
    1882         [ #  # ]:          0 :         fdirvlan |= (u32)IXGBE_NTOHS(input->formatted.vlan_id);
    1883                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRVLAN, fdirvlan);
    1884                 :            : 
    1885         [ #  # ]:          0 :         if (cloud_mode) {
    1886         [ #  # ]:          0 :                 if (input->formatted.tunnel_type != 0)
    1887                 :            :                         cloud_type = 0x80000000;
    1888                 :            : 
    1889                 :          0 :                 addr_low = ((u32)input->formatted.inner_mac[0] |
    1890                 :          0 :                                 ((u32)input->formatted.inner_mac[1] << 8) |
    1891                 :          0 :                                 ((u32)input->formatted.inner_mac[2] << 16) |
    1892                 :          0 :                                 ((u32)input->formatted.inner_mac[3] << 24));
    1893                 :          0 :                 addr_high = ((u32)input->formatted.inner_mac[4] |
    1894                 :          0 :                                 ((u32)input->formatted.inner_mac[5] << 8));
    1895                 :          0 :                 cloud_type |= addr_high;
    1896   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(0), addr_low);
             #  #  #  # ]
    1897   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(1), cloud_type);
             #  #  #  # ]
    1898   [ #  #  #  #  :          0 :                 IXGBE_WRITE_REG_BE32(hw, IXGBE_FDIRSIPv6(2), input->formatted.tni_vni);
             #  #  #  # ]
    1899                 :            :         }
    1900                 :            : 
    1901                 :            :         /* configure FDIRHASH register */
    1902                 :          0 :         fdirhash = input->formatted.bkt_hash;
    1903                 :          0 :         fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
    1904                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
    1905                 :            : 
    1906                 :            :         /*
    1907                 :            :          * flush all previous writes to make certain registers are
    1908                 :            :          * programmed prior to issuing the command
    1909                 :            :          */
    1910                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1911                 :            : 
    1912                 :            :         /* configure FDIRCMD register */
    1913                 :            :         fdircmd = IXGBE_FDIRCMD_CMD_ADD_FLOW | IXGBE_FDIRCMD_FILTER_UPDATE |
    1914                 :            :                   IXGBE_FDIRCMD_LAST | IXGBE_FDIRCMD_QUEUE_EN;
    1915         [ #  # ]:          0 :         if (queue == IXGBE_FDIR_DROP_QUEUE)
    1916                 :            :                 fdircmd |= IXGBE_FDIRCMD_DROP;
    1917         [ #  # ]:          0 :         if (input->formatted.flow_type & IXGBE_ATR_L4TYPE_TUNNEL_MASK)
    1918                 :          0 :                 fdircmd |= IXGBE_FDIRCMD_TUNNEL_FILTER;
    1919                 :          0 :         fdircmd |= input->formatted.flow_type << IXGBE_FDIRCMD_FLOW_TYPE_SHIFT;
    1920                 :          0 :         fdircmd |= (u32)queue << IXGBE_FDIRCMD_RX_QUEUE_SHIFT;
    1921                 :          0 :         fdircmd |= (u32)input->formatted.vm_pool << IXGBE_FDIRCMD_VT_POOL_SHIFT;
    1922                 :            : 
    1923                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, fdircmd);
    1924                 :            :         err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
    1925         [ #  # ]:          0 :         if (err) {
    1926                 :          0 :                 DEBUGOUT("Flow Director command did not complete!\n");
    1927                 :          0 :                 return err;
    1928                 :            :         }
    1929                 :            : 
    1930                 :            :         return IXGBE_SUCCESS;
    1931                 :            : }
    1932                 :            : 
    1933                 :          0 : s32 ixgbe_fdir_erase_perfect_filter_82599(struct ixgbe_hw *hw,
    1934                 :            :                                           union ixgbe_atr_input *input,
    1935                 :            :                                           u16 soft_id)
    1936                 :            : {
    1937                 :            :         u32 fdirhash;
    1938                 :            :         u32 fdircmd;
    1939                 :            :         s32 err;
    1940                 :            : 
    1941                 :            :         /* configure FDIRHASH register */
    1942                 :          0 :         fdirhash = input->formatted.bkt_hash;
    1943                 :          0 :         fdirhash |= soft_id << IXGBE_FDIRHASH_SIG_SW_INDEX_SHIFT;
    1944                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
    1945                 :            : 
    1946                 :            :         /* flush hash to HW */
    1947                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1948                 :            : 
    1949                 :            :         /* Query if filter is present */
    1950                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD, IXGBE_FDIRCMD_CMD_QUERY_REM_FILT);
    1951                 :            : 
    1952                 :            :         err = ixgbe_fdir_check_cmd_complete(hw, &fdircmd);
    1953         [ #  # ]:          0 :         if (err) {
    1954                 :          0 :                 DEBUGOUT("Flow Director command did not complete!\n");
    1955                 :          0 :                 return err;
    1956                 :            :         }
    1957                 :            : 
    1958                 :            :         /* if filter exists in hardware then remove it */
    1959         [ #  # ]:          0 :         if (fdircmd & IXGBE_FDIRCMD_FILTER_VALID) {
    1960                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRHASH, fdirhash);
    1961                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    1962                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FDIRCMD,
    1963                 :            :                                 IXGBE_FDIRCMD_CMD_REMOVE_FLOW);
    1964                 :            :         }
    1965                 :            : 
    1966                 :            :         return IXGBE_SUCCESS;
    1967                 :            : }
    1968                 :            : 
    1969                 :            : /**
    1970                 :            :  * ixgbe_fdir_add_perfect_filter_82599 - Adds a perfect filter
    1971                 :            :  * @hw: pointer to hardware structure
    1972                 :            :  * @input: input bitstream
    1973                 :            :  * @input_mask: mask for the input bitstream
    1974                 :            :  * @soft_id: software index for the filters
    1975                 :            :  * @queue: queue index to direct traffic to
    1976                 :            :  * @cloud_mode: unused
    1977                 :            :  *
    1978                 :            :  * Note that the caller to this function must lock before calling, since the
    1979                 :            :  * hardware writes must be protected from one another.
    1980                 :            :  **/
    1981                 :          0 : s32 ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw,
    1982                 :            :                                         union ixgbe_atr_input *input,
    1983                 :            :                                         union ixgbe_atr_input *input_mask,
    1984                 :            :                                         u16 soft_id, u8 queue, bool cloud_mode)
    1985                 :            : {
    1986                 :            :         s32 err = IXGBE_ERR_CONFIG;
    1987                 :            :         UNREFERENCED_1PARAMETER(cloud_mode);
    1988                 :            : 
    1989                 :          0 :         DEBUGFUNC("ixgbe_fdir_add_perfect_filter_82599");
    1990                 :            : 
    1991                 :            :         /*
    1992                 :            :          * Check flow_type formatting, and bail out before we touch the hardware
    1993                 :            :          * if there's a configuration issue
    1994                 :            :          */
    1995   [ #  #  #  # ]:          0 :         switch (input->formatted.flow_type) {
    1996                 :          0 :         case IXGBE_ATR_FLOW_TYPE_IPV4:
    1997                 :            :         case IXGBE_ATR_FLOW_TYPE_TUNNELED_IPV4:
    1998                 :          0 :                 input_mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK;
    1999         [ #  # ]:          0 :                 if (input->formatted.dst_port || input->formatted.src_port) {
    2000                 :          0 :                         DEBUGOUT(" Error on src/dst port\n");
    2001                 :          0 :                         return IXGBE_ERR_CONFIG;
    2002                 :            :                 }
    2003                 :            :                 break;
    2004                 :          0 :         case IXGBE_ATR_FLOW_TYPE_SCTPV4:
    2005                 :            :         case IXGBE_ATR_FLOW_TYPE_TUNNELED_SCTPV4:
    2006         [ #  # ]:          0 :                 if (input->formatted.dst_port || input->formatted.src_port) {
    2007                 :          0 :                         DEBUGOUT(" Error on src/dst port\n");
    2008                 :          0 :                         return IXGBE_ERR_CONFIG;
    2009                 :            :                 }
    2010                 :            :                 /* fall through */
    2011                 :            :         case IXGBE_ATR_FLOW_TYPE_TCPV4:
    2012                 :            :         case IXGBE_ATR_FLOW_TYPE_TUNNELED_TCPV4:
    2013                 :            :         case IXGBE_ATR_FLOW_TYPE_UDPV4:
    2014                 :            :         case IXGBE_ATR_FLOW_TYPE_TUNNELED_UDPV4:
    2015                 :          0 :                 input_mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
    2016                 :            :                                                   IXGBE_ATR_L4TYPE_MASK;
    2017                 :          0 :                 break;
    2018                 :          0 :         default:
    2019                 :          0 :                 DEBUGOUT(" Error on flow type input\n");
    2020                 :          0 :                 return err;
    2021                 :            :         }
    2022                 :            : 
    2023                 :            :         /* program input mask into the HW */
    2024                 :          0 :         err = ixgbe_fdir_set_input_mask_82599(hw, input_mask, cloud_mode);
    2025         [ #  # ]:          0 :         if (err)
    2026                 :            :                 return err;
    2027                 :            : 
    2028                 :            :         /* apply mask and compute/store hash */
    2029                 :          0 :         ixgbe_atr_compute_perfect_hash_82599(input, input_mask);
    2030                 :            : 
    2031                 :            :         /* program filters to filter memory */
    2032                 :          0 :         return ixgbe_fdir_write_perfect_filter_82599(hw, input,
    2033                 :            :                                                      soft_id, queue, cloud_mode);
    2034                 :            : }
    2035                 :            : 
    2036                 :            : /**
    2037                 :            :  * ixgbe_read_analog_reg8_82599 - Reads 8 bit Omer analog register
    2038                 :            :  * @hw: pointer to hardware structure
    2039                 :            :  * @reg: analog register to read
    2040                 :            :  * @val: read value
    2041                 :            :  *
    2042                 :            :  * Performs read operation to Omer analog register specified.
    2043                 :            :  **/
    2044                 :          0 : s32 ixgbe_read_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 *val)
    2045                 :            : {
    2046                 :            :         u32  core_ctl;
    2047                 :            : 
    2048                 :          0 :         DEBUGFUNC("ixgbe_read_analog_reg8_82599");
    2049                 :            : 
    2050                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CORECTL, IXGBE_CORECTL_WRITE_CMD |
    2051                 :            :                         (reg << 8));
    2052                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2053                 :          0 :         usec_delay(10);
    2054                 :          0 :         core_ctl = IXGBE_READ_REG(hw, IXGBE_CORECTL);
    2055                 :          0 :         *val = (u8)core_ctl;
    2056                 :            : 
    2057                 :          0 :         return IXGBE_SUCCESS;
    2058                 :            : }
    2059                 :            : 
    2060                 :            : /**
    2061                 :            :  * ixgbe_write_analog_reg8_82599 - Writes 8 bit Omer analog register
    2062                 :            :  * @hw: pointer to hardware structure
    2063                 :            :  * @reg: atlas register to write
    2064                 :            :  * @val: value to write
    2065                 :            :  *
    2066                 :            :  * Performs write operation to Omer analog register specified.
    2067                 :            :  **/
    2068                 :          0 : s32 ixgbe_write_analog_reg8_82599(struct ixgbe_hw *hw, u32 reg, u8 val)
    2069                 :            : {
    2070                 :            :         u32  core_ctl;
    2071                 :            : 
    2072                 :          0 :         DEBUGFUNC("ixgbe_write_analog_reg8_82599");
    2073                 :            : 
    2074                 :          0 :         core_ctl = (reg << 8) | val;
    2075                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CORECTL, core_ctl);
    2076                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2077                 :          0 :         usec_delay(10);
    2078                 :            : 
    2079                 :          0 :         return IXGBE_SUCCESS;
    2080                 :            : }
    2081                 :            : 
    2082                 :            : /**
    2083                 :            :  * ixgbe_start_hw_82599 - Prepare hardware for Tx/Rx
    2084                 :            :  * @hw: pointer to hardware structure
    2085                 :            :  *
    2086                 :            :  * Starts the hardware using the generic start_hw function
    2087                 :            :  * and the generation start_hw function.
    2088                 :            :  * Then performs revision-specific operations, if any.
    2089                 :            :  **/
    2090                 :          0 : s32 ixgbe_start_hw_82599(struct ixgbe_hw *hw)
    2091                 :            : {
    2092                 :            :         s32 ret_val = IXGBE_SUCCESS;
    2093                 :            : 
    2094                 :          0 :         DEBUGFUNC("ixgbe_start_hw_82599");
    2095                 :            : 
    2096                 :          0 :         ret_val = ixgbe_start_hw_generic(hw);
    2097         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS)
    2098                 :          0 :                 goto out;
    2099                 :            : 
    2100                 :          0 :         ixgbe_start_hw_gen2(hw);
    2101                 :            : 
    2102                 :            :         /* We need to run link autotry after the driver loads */
    2103                 :          0 :         hw->mac.autotry_restart = true;
    2104                 :            : 
    2105                 :            :         if (ret_val == IXGBE_SUCCESS)
    2106                 :          0 :                 ret_val = ixgbe_verify_fw_version_82599(hw);
    2107                 :          0 : out:
    2108                 :          0 :         return ret_val;
    2109                 :            : }
    2110                 :            : 
    2111                 :            : /**
    2112                 :            :  * ixgbe_identify_phy_82599 - Get physical layer module
    2113                 :            :  * @hw: pointer to hardware structure
    2114                 :            :  *
    2115                 :            :  * Determines the physical layer module found on the current adapter.
    2116                 :            :  * If PHY already detected, maintains current PHY type in hw struct,
    2117                 :            :  * otherwise executes the PHY detection routine.
    2118                 :            :  **/
    2119                 :          0 : s32 ixgbe_identify_phy_82599(struct ixgbe_hw *hw)
    2120                 :            : {
    2121                 :            :         s32 status;
    2122                 :            : 
    2123                 :          0 :         DEBUGFUNC("ixgbe_identify_phy_82599");
    2124                 :            : 
    2125                 :            :         /* Detect PHY if not unknown - returns success if already detected. */
    2126                 :          0 :         status = ixgbe_identify_phy_generic(hw);
    2127         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS) {
    2128                 :            :                 /* 82599 10GBASE-T requires an external PHY */
    2129         [ #  # ]:          0 :                 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_copper)
    2130                 :            :                         return status;
    2131                 :            :                 else
    2132                 :          0 :                         status = ixgbe_identify_module_generic(hw);
    2133                 :            :         }
    2134                 :            : 
    2135                 :            :         /* Set PHY type none if no PHY detected */
    2136         [ #  # ]:          0 :         if (hw->phy.type == ixgbe_phy_unknown) {
    2137                 :          0 :                 hw->phy.type = ixgbe_phy_none;
    2138                 :          0 :                 return IXGBE_SUCCESS;
    2139                 :            :         }
    2140                 :            : 
    2141                 :            :         /* Return error if SFP module has been detected but is not supported */
    2142         [ #  # ]:          0 :         if (hw->phy.type == ixgbe_phy_sfp_unsupported)
    2143                 :          0 :                 return IXGBE_ERR_SFP_NOT_SUPPORTED;
    2144                 :            : 
    2145                 :            :         return status;
    2146                 :            : }
    2147                 :            : 
    2148                 :            : /**
    2149                 :            :  * ixgbe_get_supported_physical_layer_82599 - Returns physical layer type
    2150                 :            :  * @hw: pointer to hardware structure
    2151                 :            :  *
    2152                 :            :  * Determines physical layer capabilities of the current configuration.
    2153                 :            :  **/
    2154                 :          0 : u64 ixgbe_get_supported_physical_layer_82599(struct ixgbe_hw *hw)
    2155                 :            : {
    2156                 :            :         u64 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
    2157                 :          0 :         u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
    2158                 :          0 :         u32 autoc2 = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
    2159                 :          0 :         u32 pma_pmd_10g_serial = autoc2 & IXGBE_AUTOC2_10G_SERIAL_PMA_PMD_MASK;
    2160                 :          0 :         u32 pma_pmd_10g_parallel = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
    2161                 :          0 :         u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
    2162                 :          0 :         u16 ext_ability = 0;
    2163                 :            : 
    2164                 :          0 :         DEBUGFUNC("ixgbe_get_support_physical_layer_82599");
    2165                 :            : 
    2166                 :          0 :         hw->phy.ops.identify(hw);
    2167                 :            : 
    2168         [ #  # ]:          0 :         switch (hw->phy.type) {
    2169                 :          0 :         case ixgbe_phy_tn:
    2170                 :            :         case ixgbe_phy_cu_unknown:
    2171                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
    2172                 :            :                 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
    2173         [ #  # ]:          0 :                 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
    2174                 :            :                         physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
    2175         [ #  # ]:          0 :                 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
    2176                 :          0 :                         physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
    2177         [ #  # ]:          0 :                 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
    2178                 :          0 :                         physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
    2179                 :          0 :                 goto out;
    2180                 :            :         default:
    2181                 :            :                 break;
    2182                 :            :         }
    2183                 :            : 
    2184   [ #  #  #  #  :          0 :         switch (autoc & IXGBE_AUTOC_LMS_MASK) {
                      # ]
    2185                 :          0 :         case IXGBE_AUTOC_LMS_1G_AN:
    2186                 :            :         case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
    2187         [ #  # ]:          0 :                 if (pma_pmd_1g == IXGBE_AUTOC_1G_KX_BX) {
    2188                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX |
    2189                 :            :                             IXGBE_PHYSICAL_LAYER_1000BASE_BX;
    2190                 :          0 :                         goto out;
    2191                 :            :                 } else
    2192                 :            :                         /* SFI mode so read SFP module */
    2193                 :          0 :                         goto sfp_check;
    2194                 :            :                 break;
    2195                 :          0 :         case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
    2196         [ #  # ]:          0 :                 if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_CX4)
    2197                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
    2198         [ #  # ]:          0 :                 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_KX4)
    2199                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
    2200         [ #  # ]:          0 :                 else if (pma_pmd_10g_parallel == IXGBE_AUTOC_10G_XAUI)
    2201                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_XAUI;
    2202                 :          0 :                 goto out;
    2203                 :            :                 break;
    2204                 :          0 :         case IXGBE_AUTOC_LMS_10G_SERIAL:
    2205         [ #  # ]:          0 :                 if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_KR) {
    2206                 :            :                         physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR;
    2207                 :          0 :                         goto out;
    2208                 :            :                 } else if (pma_pmd_10g_serial == IXGBE_AUTOC2_10G_SFI)
    2209                 :            :                         goto sfp_check;
    2210                 :            :                 break;
    2211                 :          0 :         case IXGBE_AUTOC_LMS_KX4_KX_KR:
    2212                 :            :         case IXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
    2213         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX_SUPP)
    2214                 :            :                         physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
    2215         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KX4_SUPP)
    2216                 :          0 :                         physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
    2217         [ #  # ]:          0 :                 if (autoc & IXGBE_AUTOC_KR_SUPP)
    2218                 :          0 :                         physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KR;
    2219                 :          0 :                 goto out;
    2220                 :            :                 break;
    2221                 :          0 :         default:
    2222                 :          0 :                 goto out;
    2223                 :            :                 break;
    2224                 :            :         }
    2225                 :            : 
    2226                 :          0 : sfp_check:
    2227                 :            :         /* SFP check must be done last since DA modules are sometimes used to
    2228                 :            :          * test KR mode -  we need to id KR mode correctly before SFP module.
    2229                 :            :          * Call identify_sfp because the pluggable module may have changed */
    2230                 :          0 :         physical_layer = ixgbe_get_supported_phy_sfp_layer_generic(hw);
    2231                 :          0 : out:
    2232                 :          0 :         return physical_layer;
    2233                 :            : }
    2234                 :            : 
    2235                 :            : /**
    2236                 :            :  * ixgbe_enable_rx_dma_82599 - Enable the Rx DMA unit on 82599
    2237                 :            :  * @hw: pointer to hardware structure
    2238                 :            :  * @regval: register value to write to RXCTRL
    2239                 :            :  *
    2240                 :            :  * Enables the Rx DMA unit for 82599
    2241                 :            :  **/
    2242                 :          0 : s32 ixgbe_enable_rx_dma_82599(struct ixgbe_hw *hw, u32 regval)
    2243                 :            : {
    2244                 :            : 
    2245                 :          0 :         DEBUGFUNC("ixgbe_enable_rx_dma_82599");
    2246                 :            : 
    2247                 :            :         /*
    2248                 :            :          * Workaround for 82599 silicon errata when enabling the Rx datapath.
    2249                 :            :          * If traffic is incoming before we enable the Rx unit, it could hang
    2250                 :            :          * the Rx DMA unit.  Therefore, make sure the security engine is
    2251                 :            :          * completely disabled prior to enabling the Rx unit.
    2252                 :            :          */
    2253                 :            : 
    2254                 :          0 :         hw->mac.ops.disable_sec_rx_path(hw);
    2255                 :            : 
    2256         [ #  # ]:          0 :         if (regval & IXGBE_RXCTRL_RXEN)
    2257                 :          0 :                 ixgbe_enable_rx(hw);
    2258                 :            :         else
    2259                 :          0 :                 ixgbe_disable_rx(hw);
    2260                 :            : 
    2261                 :          0 :         hw->mac.ops.enable_sec_rx_path(hw);
    2262                 :            : 
    2263                 :          0 :         return IXGBE_SUCCESS;
    2264                 :            : }
    2265                 :            : 
    2266                 :            : /**
    2267                 :            :  * ixgbe_verify_fw_version_82599 - verify FW version for 82599
    2268                 :            :  * @hw: pointer to hardware structure
    2269                 :            :  *
    2270                 :            :  * Verifies that installed the firmware version is 0.6 or higher
    2271                 :            :  * for SFI devices. All 82599 SFI devices should have version 0.6 or higher.
    2272                 :            :  *
    2273                 :            :  * Returns IXGBE_ERR_EEPROM_VERSION if the FW is not present or
    2274                 :            :  * if the FW version is not supported.
    2275                 :            :  **/
    2276                 :          0 : STATIC s32 ixgbe_verify_fw_version_82599(struct ixgbe_hw *hw)
    2277                 :            : {
    2278                 :            :         s32 status = IXGBE_ERR_EEPROM_VERSION;
    2279                 :            :         u16 fw_offset, fw_ptp_cfg_offset;
    2280                 :            :         u16 fw_version;
    2281                 :            : 
    2282                 :          0 :         DEBUGFUNC("ixgbe_verify_fw_version_82599");
    2283                 :            : 
    2284                 :            :         /* firmware check is only necessary for SFI devices */
    2285         [ #  # ]:          0 :         if (hw->phy.media_type != ixgbe_media_type_fiber) {
    2286                 :            :                 status = IXGBE_SUCCESS;
    2287                 :          0 :                 goto fw_version_out;
    2288                 :            :         }
    2289                 :            : 
    2290                 :            :         /* get the offset to the Firmware Module block */
    2291         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset)) {
    2292                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    2293                 :            :                               "eeprom read at offset %d failed", IXGBE_FW_PTR);
    2294                 :          0 :                 return IXGBE_ERR_EEPROM_VERSION;
    2295                 :            :         }
    2296                 :            : 
    2297         [ #  # ]:          0 :         if ((fw_offset == 0) || (fw_offset == 0xFFFF))
    2298                 :          0 :                 goto fw_version_out;
    2299                 :            : 
    2300                 :            :         /* get the offset to the Pass Through Patch Configuration block */
    2301         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, (fw_offset +
    2302                 :            :                                  IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR),
    2303                 :            :                                  &fw_ptp_cfg_offset)) {
    2304                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    2305                 :            :                               "eeprom read at offset %d failed",
    2306                 :            :                               fw_offset +
    2307                 :            :                               IXGBE_FW_PASSTHROUGH_PATCH_CONFIG_PTR);
    2308                 :          0 :                 return IXGBE_ERR_EEPROM_VERSION;
    2309                 :            :         }
    2310                 :            : 
    2311         [ #  # ]:          0 :         if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
    2312                 :          0 :                 goto fw_version_out;
    2313                 :            : 
    2314                 :            :         /* get the firmware version */
    2315         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, (fw_ptp_cfg_offset +
    2316                 :            :                             IXGBE_FW_PATCH_VERSION_4), &fw_version)) {
    2317                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    2318                 :            :                               "eeprom read at offset %d failed",
    2319                 :            :                               fw_ptp_cfg_offset + IXGBE_FW_PATCH_VERSION_4);
    2320                 :          0 :                 return IXGBE_ERR_EEPROM_VERSION;
    2321                 :            :         }
    2322                 :            : 
    2323         [ #  # ]:          0 :         if (fw_version > 0x5)
    2324                 :            :                 status = IXGBE_SUCCESS;
    2325                 :            : 
    2326                 :          0 : fw_version_out:
    2327                 :            :         return status;
    2328                 :            : }
    2329                 :            : 
    2330                 :            : /**
    2331                 :            :  * ixgbe_verify_lesm_fw_enabled_82599 - Checks LESM FW module state.
    2332                 :            :  * @hw: pointer to hardware structure
    2333                 :            :  *
    2334                 :            :  * Returns true if the LESM FW module is present and enabled. Otherwise
    2335                 :            :  * returns false. Smart Speed must be disabled if LESM FW module is enabled.
    2336                 :            :  **/
    2337                 :          0 : bool ixgbe_verify_lesm_fw_enabled_82599(struct ixgbe_hw *hw)
    2338                 :            : {
    2339                 :            :         bool lesm_enabled = false;
    2340                 :            :         u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
    2341                 :            :         s32 status;
    2342                 :            : 
    2343                 :          0 :         DEBUGFUNC("ixgbe_verify_lesm_fw_enabled_82599");
    2344                 :            : 
    2345                 :            :         /* get the offset to the Firmware Module block */
    2346                 :          0 :         status = hw->eeprom.ops.read(hw, IXGBE_FW_PTR, &fw_offset);
    2347                 :            : 
    2348         [ #  # ]:          0 :         if ((status != IXGBE_SUCCESS) ||
    2349   [ #  #  #  # ]:          0 :             (fw_offset == 0) || (fw_offset == 0xFFFF))
    2350                 :          0 :                 goto out;
    2351                 :            : 
    2352                 :            :         /* get the offset to the LESM Parameters block */
    2353                 :          0 :         status = hw->eeprom.ops.read(hw, (fw_offset +
    2354                 :            :                                      IXGBE_FW_LESM_PARAMETERS_PTR),
    2355                 :            :                                      &fw_lesm_param_offset);
    2356                 :            : 
    2357         [ #  # ]:          0 :         if ((status != IXGBE_SUCCESS) ||
    2358   [ #  #  #  # ]:          0 :             (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF))
    2359                 :          0 :                 goto out;
    2360                 :            : 
    2361                 :            :         /* get the LESM state word */
    2362                 :          0 :         status = hw->eeprom.ops.read(hw, (fw_lesm_param_offset +
    2363                 :            :                                      IXGBE_FW_LESM_STATE_1),
    2364                 :            :                                      &fw_lesm_state);
    2365                 :            : 
    2366   [ #  #  #  # ]:          0 :         if ((status == IXGBE_SUCCESS) &&
    2367                 :            :             (fw_lesm_state & IXGBE_FW_LESM_STATE_ENABLED))
    2368                 :            :                 lesm_enabled = true;
    2369                 :            : 
    2370                 :          0 : out:
    2371                 :          0 :         return lesm_enabled;
    2372                 :            : }
    2373                 :            : 
    2374                 :            : /**
    2375                 :            :  * ixgbe_read_eeprom_buffer_82599 - Read EEPROM word(s) using
    2376                 :            :  * fastest available method
    2377                 :            :  *
    2378                 :            :  * @hw: pointer to hardware structure
    2379                 :            :  * @offset: offset of  word in EEPROM to read
    2380                 :            :  * @words: number of words
    2381                 :            :  * @data: word(s) read from the EEPROM
    2382                 :            :  *
    2383                 :            :  * Retrieves 16 bit word(s) read from EEPROM
    2384                 :            :  **/
    2385                 :          0 : STATIC s32 ixgbe_read_eeprom_buffer_82599(struct ixgbe_hw *hw, u16 offset,
    2386                 :            :                                           u16 words, u16 *data)
    2387                 :            : {
    2388                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    2389                 :            :         s32 ret_val = IXGBE_ERR_CONFIG;
    2390                 :            : 
    2391                 :          0 :         DEBUGFUNC("ixgbe_read_eeprom_buffer_82599");
    2392                 :            : 
    2393                 :            :         /*
    2394                 :            :          * If EEPROM is detected and can be addressed using 14 bits,
    2395                 :            :          * use EERD otherwise use bit bang
    2396                 :            :          */
    2397         [ #  # ]:          0 :         if ((eeprom->type == ixgbe_eeprom_spi) &&
    2398         [ #  # ]:          0 :             (offset + (words - 1) <= IXGBE_EERD_MAX_ADDR))
    2399                 :          0 :                 ret_val = ixgbe_read_eerd_buffer_generic(hw, offset, words,
    2400                 :            :                                                          data);
    2401                 :            :         else
    2402                 :          0 :                 ret_val = ixgbe_read_eeprom_buffer_bit_bang_generic(hw, offset,
    2403                 :            :                                                                     words,
    2404                 :            :                                                                     data);
    2405                 :            : 
    2406                 :          0 :         return ret_val;
    2407                 :            : }
    2408                 :            : 
    2409                 :            : /**
    2410                 :            :  * ixgbe_read_eeprom_82599 - Read EEPROM word using
    2411                 :            :  * fastest available method
    2412                 :            :  *
    2413                 :            :  * @hw: pointer to hardware structure
    2414                 :            :  * @offset: offset of  word in the EEPROM to read
    2415                 :            :  * @data: word read from the EEPROM
    2416                 :            :  *
    2417                 :            :  * Reads a 16 bit word from the EEPROM
    2418                 :            :  **/
    2419                 :          0 : STATIC s32 ixgbe_read_eeprom_82599(struct ixgbe_hw *hw,
    2420                 :            :                                    u16 offset, u16 *data)
    2421                 :            : {
    2422                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    2423                 :            :         s32 ret_val = IXGBE_ERR_CONFIG;
    2424                 :            : 
    2425                 :          0 :         DEBUGFUNC("ixgbe_read_eeprom_82599");
    2426                 :            : 
    2427                 :            :         /*
    2428                 :            :          * If EEPROM is detected and can be addressed using 14 bits,
    2429                 :            :          * use EERD otherwise use bit bang
    2430                 :            :          */
    2431   [ #  #  #  # ]:          0 :         if ((eeprom->type == ixgbe_eeprom_spi) &&
    2432                 :            :             (offset <= IXGBE_EERD_MAX_ADDR))
    2433                 :          0 :                 ret_val = ixgbe_read_eerd_generic(hw, offset, data);
    2434                 :            :         else
    2435                 :          0 :                 ret_val = ixgbe_read_eeprom_bit_bang_generic(hw, offset, data);
    2436                 :            : 
    2437                 :          0 :         return ret_val;
    2438                 :            : }
    2439                 :            : 
    2440                 :            : /**
    2441                 :            :  * ixgbe_reset_pipeline_82599 - perform pipeline reset
    2442                 :            :  *
    2443                 :            :  * @hw: pointer to hardware structure
    2444                 :            :  *
    2445                 :            :  * Reset pipeline by asserting Restart_AN together with LMS change to ensure
    2446                 :            :  * full pipeline reset.  This function assumes the SW/FW lock is held.
    2447                 :            :  **/
    2448                 :          0 : s32 ixgbe_reset_pipeline_82599(struct ixgbe_hw *hw)
    2449                 :            : {
    2450                 :            :         s32 ret_val;
    2451                 :            :         u32 anlp1_reg = 0;
    2452                 :            :         u32 i, autoc_reg, autoc2_reg;
    2453                 :            : 
    2454                 :            :         /* Enable link if disabled in NVM */
    2455                 :          0 :         autoc2_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC2);
    2456         [ #  # ]:          0 :         if (autoc2_reg & IXGBE_AUTOC2_LINK_DISABLE_MASK) {
    2457                 :          0 :                 autoc2_reg &= ~IXGBE_AUTOC2_LINK_DISABLE_MASK;
    2458                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_AUTOC2, autoc2_reg);
    2459                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2460                 :            :         }
    2461                 :            : 
    2462                 :          0 :         autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
    2463                 :          0 :         autoc_reg |= IXGBE_AUTOC_AN_RESTART;
    2464                 :            :         /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
    2465                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_AUTOC,
    2466                 :            :                         autoc_reg ^ (0x4 << IXGBE_AUTOC_LMS_SHIFT));
    2467                 :            :         /* Wait for AN to leave state 0 */
    2468         [ #  # ]:          0 :         for (i = 0; i < 10; i++) {
    2469                 :          0 :                 msec_delay(4);
    2470                 :          0 :                 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
    2471         [ #  # ]:          0 :                 if (anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)
    2472                 :            :                         break;
    2473                 :            :         }
    2474                 :            : 
    2475         [ #  # ]:          0 :         if (!(anlp1_reg & IXGBE_ANLP1_AN_STATE_MASK)) {
    2476                 :          0 :                 DEBUGOUT("auto negotiation not completed\n");
    2477                 :            :                 ret_val = IXGBE_ERR_RESET_FAILED;
    2478                 :          0 :                 goto reset_pipeline_out;
    2479                 :            :         }
    2480                 :            : 
    2481                 :            :         ret_val = IXGBE_SUCCESS;
    2482                 :            : 
    2483                 :          0 : reset_pipeline_out:
    2484                 :            :         /* Write AUTOC register with original LMS field and Restart_AN */
    2485                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
    2486                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2487                 :            : 
    2488                 :          0 :         return ret_val;
    2489                 :            : }
    2490                 :            : 
    2491                 :            : /**
    2492                 :            :  * ixgbe_read_i2c_byte_82599 - Reads 8 bit word over I2C
    2493                 :            :  * @hw: pointer to hardware structure
    2494                 :            :  * @byte_offset: byte offset to read
    2495                 :            :  * @dev_addr: address to read from
    2496                 :            :  * @data: value read
    2497                 :            :  *
    2498                 :            :  * Performs byte read operation to SFP module's EEPROM over I2C interface at
    2499                 :            :  * a specified device address.
    2500                 :            :  **/
    2501                 :          0 : STATIC s32 ixgbe_read_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
    2502                 :            :                                 u8 dev_addr, u8 *data)
    2503                 :            : {
    2504                 :            :         u32 esdp;
    2505                 :            :         s32 status;
    2506                 :            :         s32 timeout = 200;
    2507                 :            : 
    2508                 :          0 :         DEBUGFUNC("ixgbe_read_i2c_byte_82599");
    2509                 :            : 
    2510         [ #  # ]:          0 :         if (hw->phy.qsfp_shared_i2c_bus == TRUE) {
    2511                 :            :                 /* Acquire I2C bus ownership. */
    2512                 :          0 :                 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2513                 :          0 :                 esdp |= IXGBE_ESDP_SDP0;
    2514                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
    2515                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2516                 :            : 
    2517         [ #  # ]:          0 :                 while (timeout) {
    2518                 :          0 :                         esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2519         [ #  # ]:          0 :                         if (esdp & IXGBE_ESDP_SDP1)
    2520                 :            :                                 break;
    2521                 :            : 
    2522                 :          0 :                         msec_delay(5);
    2523                 :          0 :                         timeout--;
    2524                 :            :                 }
    2525                 :            : 
    2526         [ #  # ]:          0 :                 if (!timeout) {
    2527                 :          0 :                         DEBUGOUT("Driver can't access resource,"
    2528                 :            :                                  " acquiring I2C bus timeout.\n");
    2529                 :            :                         status = IXGBE_ERR_I2C;
    2530                 :          0 :                         goto release_i2c_access;
    2531                 :            :                 }
    2532                 :            :         }
    2533                 :            : 
    2534                 :          0 :         status = ixgbe_read_i2c_byte_generic(hw, byte_offset, dev_addr, data);
    2535                 :            : 
    2536                 :          0 : release_i2c_access:
    2537                 :            : 
    2538         [ #  # ]:          0 :         if (hw->phy.qsfp_shared_i2c_bus == TRUE) {
    2539                 :            :                 /* Release I2C bus ownership. */
    2540                 :          0 :                 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2541                 :          0 :                 esdp &= ~IXGBE_ESDP_SDP0;
    2542                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
    2543                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2544                 :            :         }
    2545                 :            : 
    2546                 :          0 :         return status;
    2547                 :            : }
    2548                 :            : 
    2549                 :            : /**
    2550                 :            :  * ixgbe_write_i2c_byte_82599 - Writes 8 bit word over I2C
    2551                 :            :  * @hw: pointer to hardware structure
    2552                 :            :  * @byte_offset: byte offset to write
    2553                 :            :  * @dev_addr: address to read from
    2554                 :            :  * @data: value to write
    2555                 :            :  *
    2556                 :            :  * Performs byte write operation to SFP module's EEPROM over I2C interface at
    2557                 :            :  * a specified device address.
    2558                 :            :  **/
    2559                 :          0 : STATIC s32 ixgbe_write_i2c_byte_82599(struct ixgbe_hw *hw, u8 byte_offset,
    2560                 :            :                                  u8 dev_addr, u8 data)
    2561                 :            : {
    2562                 :            :         u32 esdp;
    2563                 :            :         s32 status;
    2564                 :            :         s32 timeout = 200;
    2565                 :            : 
    2566                 :          0 :         DEBUGFUNC("ixgbe_write_i2c_byte_82599");
    2567                 :            : 
    2568         [ #  # ]:          0 :         if (hw->phy.qsfp_shared_i2c_bus == TRUE) {
    2569                 :            :                 /* Acquire I2C bus ownership. */
    2570                 :          0 :                 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2571                 :          0 :                 esdp |= IXGBE_ESDP_SDP0;
    2572                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
    2573                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2574                 :            : 
    2575         [ #  # ]:          0 :                 while (timeout) {
    2576                 :          0 :                         esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2577         [ #  # ]:          0 :                         if (esdp & IXGBE_ESDP_SDP1)
    2578                 :            :                                 break;
    2579                 :            : 
    2580                 :          0 :                         msec_delay(5);
    2581                 :          0 :                         timeout--;
    2582                 :            :                 }
    2583                 :            : 
    2584         [ #  # ]:          0 :                 if (!timeout) {
    2585                 :          0 :                         DEBUGOUT("Driver can't access resource,"
    2586                 :            :                                  " acquiring I2C bus timeout.\n");
    2587                 :            :                         status = IXGBE_ERR_I2C;
    2588                 :          0 :                         goto release_i2c_access;
    2589                 :            :                 }
    2590                 :            :         }
    2591                 :            : 
    2592                 :          0 :         status = ixgbe_write_i2c_byte_generic(hw, byte_offset, dev_addr, data);
    2593                 :            : 
    2594                 :          0 : release_i2c_access:
    2595                 :            : 
    2596         [ #  # ]:          0 :         if (hw->phy.qsfp_shared_i2c_bus == TRUE) {
    2597                 :            :                 /* Release I2C bus ownership. */
    2598                 :          0 :                 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
    2599                 :          0 :                 esdp &= ~IXGBE_ESDP_SDP0;
    2600                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
    2601                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2602                 :            :         }
    2603                 :            : 
    2604                 :          0 :         return status;
    2605                 :            : }

Generated by: LCOV version 1.14