LCOV - code coverage report
Current view: top level - drivers/net/ixgbe/base - ixgbe_common.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1929 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 111 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 974 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2024 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "ixgbe_common.h"
       6                 :            : #include "ixgbe_phy.h"
       7                 :            : #include "ixgbe_dcb.h"
       8                 :            : #include "ixgbe_dcb_82599.h"
       9                 :            : #include "ixgbe_api.h"
      10                 :            : 
      11                 :            : STATIC s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
      12                 :            : STATIC s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
      13                 :            : STATIC void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
      14                 :            : STATIC s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
      15                 :            : STATIC void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
      16                 :            : STATIC void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
      17                 :            :                                         u16 count);
      18                 :            : STATIC u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
      19                 :            : STATIC void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
      20                 :            : STATIC void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
      21                 :            : STATIC void ixgbe_release_eeprom(struct ixgbe_hw *hw);
      22                 :            : 
      23                 :            : STATIC s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
      24                 :            : STATIC s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
      25                 :            :                                          u16 *san_mac_offset);
      26                 :            : STATIC s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
      27                 :            :                                              u16 words, u16 *data);
      28                 :            : STATIC s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
      29                 :            :                                               u16 words, u16 *data);
      30                 :            : STATIC s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
      31                 :            :                                                  u16 offset);
      32                 :            : 
      33                 :            : /**
      34                 :            :  * ixgbe_init_ops_generic - Inits function ptrs
      35                 :            :  * @hw: pointer to the hardware structure
      36                 :            :  *
      37                 :            :  * Initialize the function pointers.
      38                 :            :  **/
      39                 :          0 : s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw)
      40                 :            : {
      41                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
      42                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
      43                 :          0 :         u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
      44                 :            : 
      45                 :          0 :         DEBUGFUNC("ixgbe_init_ops_generic");
      46                 :            : 
      47                 :            :         /* EEPROM */
      48                 :          0 :         eeprom->ops.init_params = ixgbe_init_eeprom_params_generic;
      49                 :            :         /* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */
      50         [ #  # ]:          0 :         if (eec & IXGBE_EEC_PRES) {
      51                 :          0 :                 eeprom->ops.read = ixgbe_read_eerd_generic;
      52                 :          0 :                 eeprom->ops.read_buffer = ixgbe_read_eerd_buffer_generic;
      53                 :            :         } else {
      54                 :          0 :                 eeprom->ops.read = ixgbe_read_eeprom_bit_bang_generic;
      55                 :          0 :                 eeprom->ops.read_buffer =
      56                 :            :                                  ixgbe_read_eeprom_buffer_bit_bang_generic;
      57                 :            :         }
      58                 :          0 :         eeprom->ops.write = ixgbe_write_eeprom_generic;
      59                 :          0 :         eeprom->ops.write_buffer = ixgbe_write_eeprom_buffer_bit_bang_generic;
      60                 :          0 :         eeprom->ops.validate_checksum =
      61                 :            :                                       ixgbe_validate_eeprom_checksum_generic;
      62                 :          0 :         eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_generic;
      63                 :          0 :         eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_generic;
      64                 :          0 :         eeprom->ops.read_pba_string = ixgbe_read_pba_string_generic;
      65                 :            : 
      66                 :            :         /* MAC */
      67                 :          0 :         mac->ops.init_hw = ixgbe_init_hw_generic;
      68                 :          0 :         mac->ops.reset_hw = NULL;
      69                 :          0 :         mac->ops.start_hw = ixgbe_start_hw_generic;
      70                 :          0 :         mac->ops.clear_hw_cntrs = ixgbe_clear_hw_cntrs_generic;
      71                 :          0 :         mac->ops.get_media_type = NULL;
      72                 :          0 :         mac->ops.get_supported_physical_layer = NULL;
      73                 :          0 :         mac->ops.enable_rx_dma = ixgbe_enable_rx_dma_generic;
      74                 :          0 :         mac->ops.get_mac_addr = ixgbe_get_mac_addr_generic;
      75                 :          0 :         mac->ops.stop_adapter = ixgbe_stop_adapter_generic;
      76                 :          0 :         mac->ops.get_bus_info = ixgbe_get_bus_info_generic;
      77                 :          0 :         mac->ops.set_lan_id = ixgbe_set_lan_id_multi_port_pcie;
      78                 :          0 :         mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync;
      79                 :          0 :         mac->ops.release_swfw_sync = ixgbe_release_swfw_sync;
      80                 :          0 :         mac->ops.prot_autoc_read = prot_autoc_read_generic;
      81                 :          0 :         mac->ops.prot_autoc_write = prot_autoc_write_generic;
      82                 :            : 
      83                 :            :         /* LEDs */
      84                 :          0 :         mac->ops.led_on = ixgbe_led_on_generic;
      85                 :          0 :         mac->ops.led_off = ixgbe_led_off_generic;
      86                 :          0 :         mac->ops.blink_led_start = ixgbe_blink_led_start_generic;
      87                 :          0 :         mac->ops.blink_led_stop = ixgbe_blink_led_stop_generic;
      88                 :          0 :         mac->ops.init_led_link_act = ixgbe_init_led_link_act_generic;
      89                 :            : 
      90                 :            :         /* RAR, Multicast, VLAN */
      91                 :          0 :         mac->ops.set_rar = ixgbe_set_rar_generic;
      92                 :          0 :         mac->ops.clear_rar = ixgbe_clear_rar_generic;
      93                 :          0 :         mac->ops.insert_mac_addr = NULL;
      94                 :          0 :         mac->ops.set_vmdq = NULL;
      95                 :          0 :         mac->ops.clear_vmdq = NULL;
      96                 :          0 :         mac->ops.init_rx_addrs = ixgbe_init_rx_addrs_generic;
      97                 :          0 :         mac->ops.update_uc_addr_list = ixgbe_update_uc_addr_list_generic;
      98                 :          0 :         mac->ops.update_mc_addr_list = ixgbe_update_mc_addr_list_generic;
      99                 :          0 :         mac->ops.enable_mc = ixgbe_enable_mc_generic;
     100                 :          0 :         mac->ops.disable_mc = ixgbe_disable_mc_generic;
     101                 :          0 :         mac->ops.clear_vfta = NULL;
     102                 :          0 :         mac->ops.set_vfta = NULL;
     103                 :          0 :         mac->ops.set_vlvf = NULL;
     104                 :          0 :         mac->ops.init_uta_tables = NULL;
     105                 :          0 :         mac->ops.enable_rx = ixgbe_enable_rx_generic;
     106                 :          0 :         mac->ops.disable_rx = ixgbe_disable_rx_generic;
     107                 :            : 
     108                 :            :         /* Flow Control */
     109                 :          0 :         mac->ops.fc_enable = ixgbe_fc_enable_generic;
     110                 :          0 :         mac->ops.setup_fc = ixgbe_setup_fc_generic;
     111                 :          0 :         mac->ops.fc_autoneg = ixgbe_fc_autoneg;
     112                 :            : 
     113                 :            :         /* Link */
     114                 :          0 :         mac->ops.get_link_capabilities = NULL;
     115                 :          0 :         mac->ops.setup_link = NULL;
     116                 :          0 :         mac->ops.check_link = NULL;
     117                 :          0 :         mac->ops.dmac_config = NULL;
     118                 :          0 :         mac->ops.dmac_update_tcs = NULL;
     119                 :          0 :         mac->ops.dmac_config_tcs = NULL;
     120                 :            : 
     121                 :          0 :         return IXGBE_SUCCESS;
     122                 :            : }
     123                 :            : 
     124                 :            : /**
     125                 :            :  * ixgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
     126                 :            :  * of flow control
     127                 :            :  * @hw: pointer to hardware structure
     128                 :            :  *
     129                 :            :  * This function returns true if the device supports flow control
     130                 :            :  * autonegotiation, and false if it does not.
     131                 :            :  *
     132                 :            :  **/
     133                 :          0 : bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
     134                 :            : {
     135                 :            :         bool supported = false;
     136                 :            :         ixgbe_link_speed speed;
     137                 :            :         bool link_up;
     138                 :            : 
     139                 :          0 :         DEBUGFUNC("ixgbe_device_supports_autoneg_fc");
     140                 :            : 
     141   [ #  #  #  # ]:          0 :         switch (hw->phy.media_type) {
     142                 :          0 :         case ixgbe_media_type_fiber_qsfp:
     143                 :            :         case ixgbe_media_type_fiber:
     144                 :            :                 /* flow control autoneg block list */
     145         [ #  # ]:          0 :                 switch (hw->device_id) {
     146                 :            :                 case IXGBE_DEV_ID_X550EM_A_SFP:
     147                 :            :                 case IXGBE_DEV_ID_X550EM_A_SFP_N:
     148                 :            :                 case IXGBE_DEV_ID_X550EM_A_QSFP:
     149                 :            :                 case IXGBE_DEV_ID_X550EM_A_QSFP_N:
     150                 :            :                 case IXGBE_DEV_ID_E610_SFP:
     151                 :            :                         supported = false;
     152                 :            :                         break;
     153                 :          0 :                 default:
     154                 :          0 :                         hw->mac.ops.check_link(hw, &speed, &link_up, false);
     155                 :            :                         /* if link is down, assume supported */
     156         [ #  # ]:          0 :                         if (link_up)
     157                 :          0 :                                 supported = speed == IXGBE_LINK_SPEED_1GB_FULL ?
     158                 :          0 :                                 true : false;
     159                 :            :                         else
     160                 :            :                                 supported = true;
     161                 :            :                 }
     162                 :            : 
     163                 :            :                 break;
     164                 :          0 :         case ixgbe_media_type_backplane:
     165         [ #  # ]:          0 :                 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_XFI)
     166                 :            :                         supported = false;
     167                 :            :                 else
     168                 :            :                         supported = true;
     169                 :            :                 break;
     170                 :          0 :         case ixgbe_media_type_copper:
     171                 :            :                 /* only some copper devices support flow control autoneg */
     172         [ #  # ]:          0 :                 switch (hw->device_id) {
     173                 :            :                 case IXGBE_DEV_ID_82599_T3_LOM:
     174                 :            :                 case IXGBE_DEV_ID_X540T:
     175                 :            :                 case IXGBE_DEV_ID_X540T1:
     176                 :            :                 case IXGBE_DEV_ID_X550T:
     177                 :            :                 case IXGBE_DEV_ID_X550T1:
     178                 :            :                 case IXGBE_DEV_ID_X550EM_X_10G_T:
     179                 :            :                 case IXGBE_DEV_ID_X550EM_A_10G_T:
     180                 :            :                 case IXGBE_DEV_ID_X550EM_A_1G_T:
     181                 :            :                 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
     182                 :            :                 case IXGBE_DEV_ID_E610_10G_T:
     183                 :            :                 case IXGBE_DEV_ID_E610_2_5G_T:
     184                 :            :                         supported = true;
     185                 :            :                         break;
     186                 :          0 :                 default:
     187                 :            :                         supported = false;
     188                 :            :                 }
     189                 :            :         default:
     190                 :            :                 break;
     191                 :            :         }
     192                 :            : 
     193                 :          0 :         return supported;
     194                 :            : }
     195                 :            : 
     196                 :            : /**
     197                 :            :  * ixgbe_setup_fc_generic - Set up flow control
     198                 :            :  * @hw: pointer to hardware structure
     199                 :            :  *
     200                 :            :  * Called at init time to set up flow control.
     201                 :            :  **/
     202                 :          0 : s32 ixgbe_setup_fc_generic(struct ixgbe_hw *hw)
     203                 :            : {
     204                 :            :         s32 ret_val = IXGBE_SUCCESS;
     205                 :          0 :         u32 reg = 0, reg_bp = 0;
     206                 :          0 :         u16 reg_cu = 0;
     207                 :          0 :         bool locked = false;
     208                 :            : 
     209                 :          0 :         DEBUGFUNC("ixgbe_setup_fc_generic");
     210                 :            : 
     211                 :            :         /* Validate the requested mode */
     212   [ #  #  #  # ]:          0 :         if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
     213                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
     214                 :            :                            "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
     215                 :            :                 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
     216                 :          0 :                 goto out;
     217                 :            :         }
     218                 :            : 
     219                 :            :         /*
     220                 :            :          * 10gig parts do not have a word in the EEPROM to determine the
     221                 :            :          * default flow control setting, so we explicitly set it to full.
     222                 :            :          */
     223         [ #  # ]:          0 :         if (hw->fc.requested_mode == ixgbe_fc_default)
     224                 :          0 :                 hw->fc.requested_mode = ixgbe_fc_full;
     225                 :            : 
     226                 :            :         /*
     227                 :            :          * Set up the 1G and 10G flow control advertisement registers so the
     228                 :            :          * HW will be able to do fc autoneg once the cable is plugged in.  If
     229                 :            :          * we link at 10G, the 1G advertisement is harmless and vice versa.
     230                 :            :          */
     231   [ #  #  #  # ]:          0 :         switch (hw->phy.media_type) {
     232                 :          0 :         case ixgbe_media_type_backplane:
     233                 :            :                 /* some MAC's need RMW protection on AUTOC */
     234                 :          0 :                 ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &reg_bp);
     235         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
     236                 :          0 :                         goto out;
     237                 :            : 
     238                 :          0 :                 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
     239                 :          0 :                 break;
     240                 :          0 :         case ixgbe_media_type_fiber_qsfp:
     241                 :            :         case ixgbe_media_type_fiber:
     242                 :          0 :                 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
     243                 :            : 
     244                 :          0 :                 break;
     245                 :          0 :         case ixgbe_media_type_copper:
     246                 :          0 :                 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
     247                 :            :                                      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg_cu);
     248                 :          0 :                 break;
     249                 :            :         default:
     250                 :            :                 break;
     251                 :            :         }
     252                 :            : 
     253                 :            :         /*
     254                 :            :          * The possible values of fc.requested_mode are:
     255                 :            :          * 0: Flow control is completely disabled
     256                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
     257                 :            :          *    but not send pause frames).
     258                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
     259                 :            :          *    we do not support receiving pause frames).
     260                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
     261                 :            :          * other: Invalid.
     262                 :            :          */
     263   [ #  #  #  # ]:          0 :         switch (hw->fc.requested_mode) {
     264                 :          0 :         case ixgbe_fc_none:
     265                 :            :                 /* Flow control completely disabled by software override. */
     266                 :          0 :                 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
     267         [ #  # ]:          0 :                 if (hw->phy.media_type == ixgbe_media_type_backplane)
     268                 :          0 :                         reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
     269                 :            :                                     IXGBE_AUTOC_ASM_PAUSE);
     270         [ #  # ]:          0 :                 else if (hw->phy.media_type == ixgbe_media_type_copper)
     271                 :          0 :                         reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
     272                 :            :                 break;
     273                 :          0 :         case ixgbe_fc_tx_pause:
     274                 :            :                 /*
     275                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
     276                 :            :                  * disabled by software override.
     277                 :            :                  */
     278                 :            :                 reg |= IXGBE_PCS1GANA_ASM_PAUSE;
     279                 :          0 :                 reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
     280         [ #  # ]:          0 :                 if (hw->phy.media_type == ixgbe_media_type_backplane) {
     281                 :          0 :                         reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
     282                 :          0 :                         reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
     283         [ #  # ]:          0 :                 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
     284                 :          0 :                         reg_cu |= IXGBE_TAF_ASM_PAUSE;
     285                 :          0 :                         reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
     286                 :            :                 }
     287                 :            :                 break;
     288                 :          0 :         case ixgbe_fc_rx_pause:
     289                 :            :                 /*
     290                 :            :                  * Rx Flow control is enabled and Tx Flow control is
     291                 :            :                  * disabled by software override. Since there really
     292                 :            :                  * isn't a way to advertise that we are capable of RX
     293                 :            :                  * Pause ONLY, we will advertise that we support both
     294                 :            :                  * symmetric and asymmetric Rx PAUSE, as such we fall
     295                 :            :                  * through to the fc_full statement.  Later, we will
     296                 :            :                  * disable the adapter's ability to send PAUSE frames.
     297                 :            :                  */
     298                 :            :         case ixgbe_fc_full:
     299                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
     300                 :          0 :                 reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
     301         [ #  # ]:          0 :                 if (hw->phy.media_type == ixgbe_media_type_backplane)
     302                 :          0 :                         reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
     303                 :            :                                   IXGBE_AUTOC_ASM_PAUSE;
     304         [ #  # ]:          0 :                 else if (hw->phy.media_type == ixgbe_media_type_copper)
     305                 :          0 :                         reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
     306                 :            :                 break;
     307                 :          0 :         default:
     308                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
     309                 :            :                              "Flow control param set incorrectly\n");
     310                 :            :                 ret_val = IXGBE_ERR_CONFIG;
     311                 :          0 :                 goto out;
     312                 :            :                 break;
     313                 :            :         }
     314                 :            : 
     315         [ #  # ]:          0 :         if (hw->mac.type < ixgbe_mac_X540) {
     316                 :            :                 /*
     317                 :            :                  * Enable auto-negotiation between the MAC & PHY;
     318                 :            :                  * the MAC will advertise clause 37 flow control.
     319                 :            :                  */
     320                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
     321                 :          0 :                 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
     322                 :            : 
     323                 :            :                 /* Disable AN timeout */
     324         [ #  # ]:          0 :                 if (hw->fc.strict_ieee)
     325                 :          0 :                         reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
     326                 :            : 
     327                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
     328                 :          0 :                 DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
     329                 :            :         }
     330                 :            : 
     331                 :            :         /*
     332                 :            :          * AUTOC restart handles negotiation of 1G and 10G on backplane
     333                 :            :          * and copper. There is no need to set the PCS1GCTL register.
     334                 :            :          *
     335                 :            :          */
     336         [ #  # ]:          0 :         if (hw->phy.media_type == ixgbe_media_type_backplane) {
     337                 :          0 :                 reg_bp |= IXGBE_AUTOC_AN_RESTART;
     338                 :          0 :                 ret_val = hw->mac.ops.prot_autoc_write(hw, reg_bp, locked);
     339         [ #  # ]:          0 :                 if (ret_val)
     340                 :          0 :                         goto out;
     341   [ #  #  #  # ]:          0 :         } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
     342                 :          0 :                     (ixgbe_device_supports_autoneg_fc(hw))) {
     343                 :          0 :                 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
     344                 :            :                                       IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg_cu);
     345                 :            :         }
     346                 :            : 
     347                 :          0 :         DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
     348                 :          0 : out:
     349                 :          0 :         return ret_val;
     350                 :            : }
     351                 :            : 
     352                 :            : /**
     353                 :            :  * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
     354                 :            :  * @hw: pointer to hardware structure
     355                 :            :  *
     356                 :            :  * Starts the hardware by filling the bus info structure and media type, clears
     357                 :            :  * all on chip counters, initializes receive address registers, multicast
     358                 :            :  * table, VLAN filter table, calls routine to set up link and flow control
     359                 :            :  * settings, and leaves transmit and receive units disabled and uninitialized
     360                 :            :  **/
     361                 :          0 : s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
     362                 :            : {
     363                 :            :         s32 ret_val;
     364                 :            :         u32 ctrl_ext;
     365                 :            :         u16 device_caps;
     366                 :            : 
     367                 :          0 :         DEBUGFUNC("ixgbe_start_hw_generic");
     368                 :            : 
     369                 :            :         /* Set the media type */
     370                 :          0 :         hw->phy.media_type = hw->mac.ops.get_media_type(hw);
     371                 :            : 
     372                 :            :         /* PHY ops initialization must be done in reset_hw() */
     373                 :            : 
     374                 :            :         /* Clear the VLAN filter table */
     375                 :          0 :         hw->mac.ops.clear_vfta(hw);
     376                 :            : 
     377                 :            :         /* Clear statistics registers */
     378                 :          0 :         hw->mac.ops.clear_hw_cntrs(hw);
     379                 :            : 
     380                 :            :         /* Set No Snoop Disable */
     381                 :          0 :         ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
     382                 :          0 :         ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
     383                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
     384                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     385                 :            : 
     386                 :            :         /* Setup flow control */
     387                 :          0 :         ret_val = ixgbe_setup_fc(hw);
     388         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS && ret_val != IXGBE_NOT_IMPLEMENTED) {
     389                 :          0 :                 DEBUGOUT1("Flow control setup failed, returning %d\n", ret_val);
     390                 :          0 :                 return ret_val;
     391                 :            :         }
     392                 :            : 
     393                 :            :         /* Cache bit indicating need for crosstalk fix */
     394         [ #  # ]:          0 :         switch (hw->mac.type) {
     395                 :          0 :         case ixgbe_mac_82599EB:
     396                 :            :         case ixgbe_mac_X550EM_x:
     397                 :            :         case ixgbe_mac_X550EM_a:
     398                 :          0 :                 hw->mac.ops.get_device_caps(hw, &device_caps);
     399         [ #  # ]:          0 :                 if (device_caps & IXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
     400                 :          0 :                         hw->need_crosstalk_fix = false;
     401                 :            :                 else
     402                 :          0 :                         hw->need_crosstalk_fix = true;
     403                 :            :                 break;
     404                 :          0 :         default:
     405                 :          0 :                 hw->need_crosstalk_fix = false;
     406                 :          0 :                 break;
     407                 :            :         }
     408                 :            : 
     409                 :            :         /* Clear adapter stopped flag */
     410                 :          0 :         hw->adapter_stopped = false;
     411                 :            : 
     412                 :          0 :         return IXGBE_SUCCESS;
     413                 :            : }
     414                 :            : 
     415                 :            : /**
     416                 :            :  * ixgbe_start_hw_gen2 - Init sequence for common device family
     417                 :            :  * @hw: pointer to hw structure
     418                 :            :  *
     419                 :            :  * Performs the init sequence common to the second generation
     420                 :            :  * of 10 GbE devices.
     421                 :            :  * Devices in the second generation:
     422                 :            :  *    82599
     423                 :            :  *    X540
     424                 :            :  **/
     425                 :          0 : void ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
     426                 :            : {
     427                 :            :         u32 i;
     428                 :            :         u32 regval;
     429                 :            : 
     430                 :            :         /* Clear the rate limiters */
     431         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++) {
     432                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
     433                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
     434                 :            :         }
     435                 :          0 :         IXGBE_WRITE_FLUSH(hw);
     436                 :            : 
     437                 :            :         /* Disable relaxed ordering */
     438         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++) {
     439                 :          0 :                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
     440                 :          0 :                 regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
     441                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
     442                 :            :         }
     443                 :            : 
     444         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++) {
     445   [ #  #  #  # ]:          0 :                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
     446                 :          0 :                 regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
     447                 :            :                             IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
     448                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
     449                 :            :         }
     450                 :          0 : }
     451                 :            : 
     452                 :            : /**
     453                 :            :  * ixgbe_init_hw_generic - Generic hardware initialization
     454                 :            :  * @hw: pointer to hardware structure
     455                 :            :  *
     456                 :            :  * Initialize the hardware by resetting the hardware, filling the bus info
     457                 :            :  * structure and media type, clears all on chip counters, initializes receive
     458                 :            :  * address registers, multicast table, VLAN filter table, calls routine to set
     459                 :            :  * up link and flow control settings, and leaves transmit and receive units
     460                 :            :  * disabled and uninitialized
     461                 :            :  **/
     462                 :          0 : s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
     463                 :            : {
     464                 :            :         s32 status;
     465                 :            : 
     466                 :          0 :         DEBUGFUNC("ixgbe_init_hw_generic");
     467                 :            : 
     468                 :            :         /* Reset the hardware */
     469                 :          0 :         status = hw->mac.ops.reset_hw(hw);
     470                 :            : 
     471         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS || status == IXGBE_ERR_SFP_NOT_PRESENT) {
     472                 :            :                 /* Start the HW */
     473                 :          0 :                 status = hw->mac.ops.start_hw(hw);
     474                 :            :         }
     475                 :            : 
     476                 :            :         /* Initialize the LED link active for LED blink support */
     477         [ #  # ]:          0 :         if (hw->mac.ops.init_led_link_act)
     478                 :          0 :                 hw->mac.ops.init_led_link_act(hw);
     479                 :            : 
     480         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
     481                 :          0 :                 DEBUGOUT1("Failed to initialize HW, STATUS = %d\n", status);
     482                 :            : 
     483                 :          0 :         return status;
     484                 :            : }
     485                 :            : 
     486                 :            : /**
     487                 :            :  * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
     488                 :            :  * @hw: pointer to hardware structure
     489                 :            :  *
     490                 :            :  * Clears all hardware statistics counters by reading them from the hardware
     491                 :            :  * Statistics counters are clear on read.
     492                 :            :  **/
     493                 :          0 : s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
     494                 :            : {
     495                 :            :         u16 i = 0;
     496                 :            : 
     497                 :          0 :         DEBUGFUNC("ixgbe_clear_hw_cntrs_generic");
     498                 :            : 
     499                 :          0 :         IXGBE_READ_REG(hw, IXGBE_CRCERRS);
     500                 :          0 :         IXGBE_READ_REG(hw, IXGBE_ILLERRC);
     501                 :          0 :         IXGBE_READ_REG(hw, IXGBE_ERRBC);
     502                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MSPDC);
     503         [ #  # ]:          0 :         for (i = 0; i < 8; i++)
     504                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_MPC(i));
     505                 :            : 
     506                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MLFC);
     507                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MRFC);
     508                 :          0 :         IXGBE_READ_REG(hw, IXGBE_RLEC);
     509                 :          0 :         IXGBE_READ_REG(hw, IXGBE_LXONTXC);
     510                 :          0 :         IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
     511         [ #  # ]:          0 :         if (hw->mac.type >= ixgbe_mac_82599EB) {
     512                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
     513                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
     514                 :            :         } else {
     515                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
     516                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
     517                 :            :         }
     518                 :            : 
     519         [ #  # ]:          0 :         for (i = 0; i < 8; i++) {
     520                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
     521                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
     522         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_82599EB) {
     523                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
     524                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
     525                 :            :                 } else {
     526                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
     527                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
     528                 :            :                 }
     529                 :            :         }
     530         [ #  # ]:          0 :         if (hw->mac.type >= ixgbe_mac_82599EB)
     531         [ #  # ]:          0 :                 for (i = 0; i < 8; i++)
     532                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
     533                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC64);
     534                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC127);
     535                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC255);
     536                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC511);
     537                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC1023);
     538                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PRC1522);
     539                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GPRC);
     540                 :          0 :         IXGBE_READ_REG(hw, IXGBE_BPRC);
     541                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MPRC);
     542                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GPTC);
     543                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GORCL);
     544                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GORCH);
     545                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GOTCL);
     546                 :          0 :         IXGBE_READ_REG(hw, IXGBE_GOTCH);
     547         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
     548         [ #  # ]:          0 :                 for (i = 0; i < 8; i++)
     549                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_RNBC(i));
     550                 :          0 :         IXGBE_READ_REG(hw, IXGBE_RUC);
     551                 :          0 :         IXGBE_READ_REG(hw, IXGBE_RFC);
     552                 :          0 :         IXGBE_READ_REG(hw, IXGBE_ROC);
     553                 :          0 :         IXGBE_READ_REG(hw, IXGBE_RJC);
     554                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MNGPRC);
     555                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MNGPDC);
     556                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MNGPTC);
     557                 :          0 :         IXGBE_READ_REG(hw, IXGBE_TORL);
     558                 :          0 :         IXGBE_READ_REG(hw, IXGBE_TORH);
     559                 :          0 :         IXGBE_READ_REG(hw, IXGBE_TPR);
     560                 :          0 :         IXGBE_READ_REG(hw, IXGBE_TPT);
     561                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC64);
     562                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC127);
     563                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC255);
     564                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC511);
     565                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC1023);
     566                 :          0 :         IXGBE_READ_REG(hw, IXGBE_PTC1522);
     567                 :          0 :         IXGBE_READ_REG(hw, IXGBE_MPTC);
     568                 :          0 :         IXGBE_READ_REG(hw, IXGBE_BPTC);
     569         [ #  # ]:          0 :         for (i = 0; i < 16; i++) {
     570                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
     571                 :          0 :                 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
     572         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_82599EB) {
     573                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
     574                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
     575                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
     576                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
     577                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
     578                 :            :                 } else {
     579                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBRC(i));
     580                 :          0 :                         IXGBE_READ_REG(hw, IXGBE_QBTC(i));
     581                 :            :                 }
     582                 :            :         }
     583                 :            : 
     584         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_X540 ||
     585         [ #  # ]:          0 :             hw->mac.type == ixgbe_mac_X550 ||
     586                 :            :             hw->mac.type == ixgbe_mac_E610) {
     587         [ #  # ]:          0 :                 if (hw->phy.id == 0)
     588                 :          0 :                         ixgbe_identify_phy(hw);
     589                 :            :         }
     590                 :            : 
     591                 :          0 :         return IXGBE_SUCCESS;
     592                 :            : }
     593                 :            : 
     594                 :            : /**
     595                 :            :  * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
     596                 :            :  * @hw: pointer to hardware structure
     597                 :            :  * @pba_num: stores the part number string from the EEPROM
     598                 :            :  * @pba_num_size: part number string buffer length
     599                 :            :  *
     600                 :            :  * Reads the part number string from the EEPROM.
     601                 :            :  **/
     602                 :          0 : s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
     603                 :            :                                   u32 pba_num_size)
     604                 :            : {
     605                 :            :         s32 ret_val;
     606                 :            :         u16 data;
     607                 :            :         u16 pba_ptr;
     608                 :            :         u16 offset;
     609                 :            :         u16 length;
     610                 :            : 
     611                 :          0 :         DEBUGFUNC("ixgbe_read_pba_string_generic");
     612                 :            : 
     613         [ #  # ]:          0 :         if (pba_num == NULL) {
     614                 :          0 :                 DEBUGOUT("PBA string buffer was null\n");
     615                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
     616                 :            :         }
     617                 :            : 
     618                 :          0 :         ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
     619         [ #  # ]:          0 :         if (ret_val) {
     620                 :          0 :                 DEBUGOUT("NVM Read Error\n");
     621                 :          0 :                 return ret_val;
     622                 :            :         }
     623                 :            : 
     624                 :          0 :         ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
     625         [ #  # ]:          0 :         if (ret_val) {
     626                 :          0 :                 DEBUGOUT("NVM Read Error\n");
     627                 :          0 :                 return ret_val;
     628                 :            :         }
     629                 :            : 
     630                 :            :         /*
     631                 :            :          * if data is not ptr guard the PBA must be in legacy format which
     632                 :            :          * means pba_ptr is actually our second data word for the PBA number
     633                 :            :          * and we can decode it into an ascii string
     634                 :            :          */
     635         [ #  # ]:          0 :         if (data != IXGBE_PBANUM_PTR_GUARD) {
     636                 :          0 :                 DEBUGOUT("NVM PBA number is not stored as string\n");
     637                 :            : 
     638                 :            :                 /* we will need 11 characters to store the PBA */
     639         [ #  # ]:          0 :                 if (pba_num_size < 11) {
     640                 :          0 :                         DEBUGOUT("PBA string buffer too small\n");
     641                 :          0 :                         return IXGBE_ERR_NO_SPACE;
     642                 :            :                 }
     643                 :            : 
     644                 :            :                 /* extract hex string from data and pba_ptr */
     645                 :          0 :                 pba_num[0] = (data >> 12) & 0xF;
     646                 :          0 :                 pba_num[1] = (data >> 8) & 0xF;
     647                 :          0 :                 pba_num[2] = (data >> 4) & 0xF;
     648                 :          0 :                 pba_num[3] = data & 0xF;
     649                 :          0 :                 pba_num[4] = (pba_ptr >> 12) & 0xF;
     650                 :          0 :                 pba_num[5] = (pba_ptr >> 8) & 0xF;
     651                 :          0 :                 pba_num[6] = '-';
     652                 :          0 :                 pba_num[7] = 0;
     653                 :          0 :                 pba_num[8] = (pba_ptr >> 4) & 0xF;
     654                 :          0 :                 pba_num[9] = pba_ptr & 0xF;
     655                 :            : 
     656                 :            :                 /* put a null character on the end of our string */
     657                 :          0 :                 pba_num[10] = '\0';
     658                 :            : 
     659                 :            :                 /* switch all the data but the '-' to hex char */
     660         [ #  # ]:          0 :                 for (offset = 0; offset < 10; offset++) {
     661         [ #  # ]:          0 :                         if (pba_num[offset] < 0xA)
     662                 :          0 :                                 pba_num[offset] += '0';
     663         [ #  # ]:          0 :                         else if (pba_num[offset] < 0x10)
     664                 :          0 :                                 pba_num[offset] += 'A' - 0xA;
     665                 :            :                 }
     666                 :            : 
     667                 :            :                 return IXGBE_SUCCESS;
     668                 :            :         }
     669                 :            : 
     670                 :          0 :         ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
     671         [ #  # ]:          0 :         if (ret_val) {
     672                 :          0 :                 DEBUGOUT("NVM Read Error\n");
     673                 :          0 :                 return ret_val;
     674                 :            :         }
     675                 :            : 
     676   [ #  #  #  # ]:          0 :         if (length == 0xFFFF || length == 0 || length > hw->eeprom.word_size) {
     677                 :          0 :                 DEBUGOUT("NVM PBA number section invalid length\n");
     678                 :          0 :                 return IXGBE_ERR_PBA_SECTION;
     679                 :            :         }
     680                 :            : 
     681                 :            :         /* check if pba_num buffer is big enough */
     682         [ #  # ]:          0 :         if (pba_num_size  < (((u32)length * 2) - 1)) {
     683                 :          0 :                 DEBUGOUT("PBA string buffer too small\n");
     684                 :          0 :                 return IXGBE_ERR_NO_SPACE;
     685                 :            :         }
     686                 :            : 
     687                 :            :         /* trim pba length from start of string */
     688                 :          0 :         pba_ptr++;
     689                 :          0 :         length--;
     690                 :            : 
     691         [ #  # ]:          0 :         for (offset = 0; offset < length; offset++) {
     692                 :          0 :                 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
     693         [ #  # ]:          0 :                 if (ret_val) {
     694                 :          0 :                         DEBUGOUT("NVM Read Error\n");
     695                 :          0 :                         return ret_val;
     696                 :            :                 }
     697                 :          0 :                 pba_num[offset * 2] = (u8)(data >> 8);
     698                 :          0 :                 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
     699                 :            :         }
     700                 :          0 :         pba_num[offset * 2] = '\0';
     701                 :            : 
     702                 :          0 :         return IXGBE_SUCCESS;
     703                 :            : }
     704                 :            : 
     705                 :            : /**
     706                 :            :  * ixgbe_read_pba_num_generic - Reads part number from EEPROM
     707                 :            :  * @hw: pointer to hardware structure
     708                 :            :  * @pba_num: stores the part number from the EEPROM
     709                 :            :  *
     710                 :            :  * Reads the part number from the EEPROM.
     711                 :            :  **/
     712                 :          0 : s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
     713                 :            : {
     714                 :            :         s32 ret_val;
     715                 :            :         u16 data;
     716                 :            : 
     717                 :          0 :         DEBUGFUNC("ixgbe_read_pba_num_generic");
     718                 :            : 
     719                 :          0 :         ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
     720         [ #  # ]:          0 :         if (ret_val) {
     721                 :          0 :                 DEBUGOUT("NVM Read Error\n");
     722                 :          0 :                 return ret_val;
     723         [ #  # ]:          0 :         } else if (data == IXGBE_PBANUM_PTR_GUARD) {
     724                 :          0 :                 DEBUGOUT("NVM Not supported\n");
     725                 :          0 :                 return IXGBE_NOT_IMPLEMENTED;
     726                 :            :         }
     727                 :          0 :         *pba_num = (u32)(data << 16);
     728                 :            : 
     729                 :          0 :         ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
     730         [ #  # ]:          0 :         if (ret_val) {
     731                 :          0 :                 DEBUGOUT("NVM Read Error\n");
     732                 :          0 :                 return ret_val;
     733                 :            :         }
     734                 :          0 :         *pba_num |= (u32)data;
     735                 :            : 
     736                 :          0 :         return IXGBE_SUCCESS;
     737                 :            : }
     738                 :            : 
     739                 :            : /**
     740                 :            :  * ixgbe_read_pba_raw
     741                 :            :  * @hw: pointer to the HW structure
     742                 :            :  * @eeprom_buf: optional pointer to EEPROM image
     743                 :            :  * @eeprom_buf_size: size of EEPROM image in words
     744                 :            :  * @max_pba_block_size: PBA block size limit
     745                 :            :  * @pba: pointer to output PBA structure
     746                 :            :  *
     747                 :            :  * Reads PBA from EEPROM image when eeprom_buf is not NULL.
     748                 :            :  * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
     749                 :            :  *
     750                 :            :  **/
     751                 :          0 : s32 ixgbe_read_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
     752                 :            :                        u32 eeprom_buf_size, u16 max_pba_block_size,
     753                 :            :                        struct ixgbe_pba *pba)
     754                 :            : {
     755                 :            :         s32 ret_val;
     756                 :            :         u16 pba_block_size;
     757                 :            : 
     758         [ #  # ]:          0 :         if (pba == NULL)
     759                 :            :                 return IXGBE_ERR_PARAM;
     760                 :            : 
     761         [ #  # ]:          0 :         if (eeprom_buf == NULL) {
     762                 :          0 :                 ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
     763                 :            :                                                      &pba->word[0]);
     764         [ #  # ]:          0 :                 if (ret_val)
     765                 :            :                         return ret_val;
     766                 :            :         } else {
     767         [ #  # ]:          0 :                 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
     768                 :          0 :                         pba->word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
     769                 :          0 :                         pba->word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
     770                 :            :                 } else {
     771                 :            :                         return IXGBE_ERR_PARAM;
     772                 :            :                 }
     773                 :            :         }
     774                 :            : 
     775         [ #  # ]:          0 :         if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
     776         [ #  # ]:          0 :                 if (pba->pba_block == NULL)
     777                 :            :                         return IXGBE_ERR_PARAM;
     778                 :            : 
     779                 :          0 :                 ret_val = ixgbe_get_pba_block_size(hw, eeprom_buf,
     780                 :            :                                                    eeprom_buf_size,
     781                 :            :                                                    &pba_block_size);
     782         [ #  # ]:          0 :                 if (ret_val)
     783                 :            :                         return ret_val;
     784                 :            : 
     785         [ #  # ]:          0 :                 if (pba_block_size > max_pba_block_size)
     786                 :            :                         return IXGBE_ERR_PARAM;
     787                 :            : 
     788         [ #  # ]:          0 :                 if (eeprom_buf == NULL) {
     789                 :          0 :                         ret_val = hw->eeprom.ops.read_buffer(hw, pba->word[1],
     790                 :            :                                                              pba_block_size,
     791                 :            :                                                              pba->pba_block);
     792         [ #  # ]:          0 :                         if (ret_val)
     793                 :          0 :                                 return ret_val;
     794                 :            :                 } else {
     795         [ #  # ]:          0 :                         if (eeprom_buf_size > (u32)(pba->word[1] +
     796                 :            :                                               pba_block_size)) {
     797                 :          0 :                                 memcpy(pba->pba_block,
     798                 :          0 :                                        &eeprom_buf[pba->word[1]],
     799                 :            :                                        pba_block_size * sizeof(u16));
     800                 :            :                         } else {
     801                 :            :                                 return IXGBE_ERR_PARAM;
     802                 :            :                         }
     803                 :            :                 }
     804                 :            :         }
     805                 :            : 
     806                 :            :         return IXGBE_SUCCESS;
     807                 :            : }
     808                 :            : 
     809                 :            : /**
     810                 :            :  * ixgbe_write_pba_raw
     811                 :            :  * @hw: pointer to the HW structure
     812                 :            :  * @eeprom_buf: optional pointer to EEPROM image
     813                 :            :  * @eeprom_buf_size: size of EEPROM image in words
     814                 :            :  * @pba: pointer to PBA structure
     815                 :            :  *
     816                 :            :  * Writes PBA to EEPROM image when eeprom_buf is not NULL.
     817                 :            :  * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
     818                 :            :  *
     819                 :            :  **/
     820                 :          0 : s32 ixgbe_write_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
     821                 :            :                         u32 eeprom_buf_size, struct ixgbe_pba *pba)
     822                 :            : {
     823                 :            :         s32 ret_val;
     824                 :            : 
     825         [ #  # ]:          0 :         if (pba == NULL)
     826                 :            :                 return IXGBE_ERR_PARAM;
     827                 :            : 
     828         [ #  # ]:          0 :         if (eeprom_buf == NULL) {
     829                 :          0 :                 ret_val = hw->eeprom.ops.write_buffer(hw, IXGBE_PBANUM0_PTR, 2,
     830                 :            :                                                       &pba->word[0]);
     831         [ #  # ]:          0 :                 if (ret_val)
     832                 :            :                         return ret_val;
     833                 :            :         } else {
     834         [ #  # ]:          0 :                 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
     835                 :          0 :                         eeprom_buf[IXGBE_PBANUM0_PTR] = pba->word[0];
     836                 :          0 :                         eeprom_buf[IXGBE_PBANUM1_PTR] = pba->word[1];
     837                 :            :                 } else {
     838                 :            :                         return IXGBE_ERR_PARAM;
     839                 :            :                 }
     840                 :            :         }
     841                 :            : 
     842         [ #  # ]:          0 :         if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
     843         [ #  # ]:          0 :                 if (pba->pba_block == NULL)
     844                 :            :                         return IXGBE_ERR_PARAM;
     845                 :            : 
     846         [ #  # ]:          0 :                 if (eeprom_buf == NULL) {
     847                 :          0 :                         ret_val = hw->eeprom.ops.write_buffer(hw, pba->word[1],
     848                 :          0 :                                                               pba->pba_block[0],
     849                 :            :                                                               pba->pba_block);
     850         [ #  # ]:          0 :                         if (ret_val)
     851                 :          0 :                                 return ret_val;
     852                 :            :                 } else {
     853                 :          0 :                         if (eeprom_buf_size > (u32)(pba->word[1] +
     854         [ #  # ]:          0 :                                               pba->pba_block[0])) {
     855                 :          0 :                                 memcpy(&eeprom_buf[pba->word[1]],
     856                 :            :                                        pba->pba_block,
     857                 :          0 :                                        pba->pba_block[0] * sizeof(u16));
     858                 :            :                         } else {
     859                 :            :                                 return IXGBE_ERR_PARAM;
     860                 :            :                         }
     861                 :            :                 }
     862                 :            :         }
     863                 :            : 
     864                 :            :         return IXGBE_SUCCESS;
     865                 :            : }
     866                 :            : 
     867                 :            : /**
     868                 :            :  * ixgbe_get_pba_block_size
     869                 :            :  * @hw: pointer to the HW structure
     870                 :            :  * @eeprom_buf: optional pointer to EEPROM image
     871                 :            :  * @eeprom_buf_size: size of EEPROM image in words
     872                 :            :  * @pba_data_size: pointer to output variable
     873                 :            :  *
     874                 :            :  * Returns the size of the PBA block in words. Function operates on EEPROM
     875                 :            :  * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
     876                 :            :  * EEPROM device.
     877                 :            :  *
     878                 :            :  **/
     879                 :          0 : s32 ixgbe_get_pba_block_size(struct ixgbe_hw *hw, u16 *eeprom_buf,
     880                 :            :                              u32 eeprom_buf_size, u16 *pba_block_size)
     881                 :            : {
     882                 :            :         s32 ret_val;
     883                 :            :         u16 pba_word[2];
     884                 :            :         u16 length;
     885                 :            : 
     886                 :          0 :         DEBUGFUNC("ixgbe_get_pba_block_size");
     887                 :            : 
     888         [ #  # ]:          0 :         if (eeprom_buf == NULL) {
     889                 :          0 :                 ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
     890                 :            :                                                      &pba_word[0]);
     891         [ #  # ]:          0 :                 if (ret_val)
     892                 :            :                         return ret_val;
     893                 :            :         } else {
     894         [ #  # ]:          0 :                 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
     895                 :          0 :                         pba_word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
     896                 :          0 :                         pba_word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
     897                 :            :                 } else {
     898                 :            :                         return IXGBE_ERR_PARAM;
     899                 :            :                 }
     900                 :            :         }
     901                 :            : 
     902         [ #  # ]:          0 :         if (pba_word[0] == IXGBE_PBANUM_PTR_GUARD) {
     903         [ #  # ]:          0 :                 if (eeprom_buf == NULL) {
     904                 :          0 :                         ret_val = hw->eeprom.ops.read(hw, pba_word[1] + 0,
     905                 :            :                                                       &length);
     906         [ #  # ]:          0 :                         if (ret_val)
     907                 :            :                                 return ret_val;
     908                 :            :                 } else {
     909         [ #  # ]:          0 :                         if (eeprom_buf_size > pba_word[1])
     910                 :          0 :                                 length = eeprom_buf[pba_word[1] + 0];
     911                 :            :                         else
     912                 :            :                                 return IXGBE_ERR_PARAM;
     913                 :            :                 }
     914                 :            : 
     915         [ #  # ]:          0 :                 if (length == 0xFFFF || length == 0)
     916                 :            :                         return IXGBE_ERR_PBA_SECTION;
     917                 :            :         } else {
     918                 :            :                 /* PBA number in legacy format, there is no PBA Block. */
     919                 :          0 :                 length = 0;
     920                 :            :         }
     921                 :            : 
     922         [ #  # ]:          0 :         if (pba_block_size != NULL)
     923                 :          0 :                 *pba_block_size = length;
     924                 :            : 
     925                 :            :         return IXGBE_SUCCESS;
     926                 :            : }
     927                 :            : 
     928                 :            : /**
     929                 :            :  * ixgbe_get_mac_addr_generic - Generic get MAC address
     930                 :            :  * @hw: pointer to hardware structure
     931                 :            :  * @mac_addr: Adapter MAC address
     932                 :            :  *
     933                 :            :  * Reads the adapter's MAC address from first Receive Address Register (RAR0)
     934                 :            :  * A reset of the adapter must be performed prior to calling this function
     935                 :            :  * in order for the MAC address to have been loaded from the EEPROM into RAR0
     936                 :            :  **/
     937                 :          0 : s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
     938                 :            : {
     939                 :            :         u32 rar_high;
     940                 :            :         u32 rar_low;
     941                 :            :         u16 i;
     942                 :            : 
     943                 :          0 :         DEBUGFUNC("ixgbe_get_mac_addr_generic");
     944                 :            : 
     945                 :          0 :         rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
     946                 :          0 :         rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
     947                 :            : 
     948         [ #  # ]:          0 :         for (i = 0; i < 4; i++)
     949                 :          0 :                 mac_addr[i] = (u8)(rar_low >> (i*8));
     950                 :            : 
     951         [ #  # ]:          0 :         for (i = 0; i < 2; i++)
     952                 :          0 :                 mac_addr[i+4] = (u8)(rar_high >> (i*8));
     953                 :            : 
     954                 :          0 :         return IXGBE_SUCCESS;
     955                 :            : }
     956                 :            : 
     957                 :            : /**
     958                 :            :  * ixgbe_set_pci_config_data_generic - Generic store PCI bus info
     959                 :            :  * @hw: pointer to hardware structure
     960                 :            :  * @link_status: the link status returned by the PCI config space
     961                 :            :  *
     962                 :            :  * Stores the PCI bus info (speed, width, type) within the ixgbe_hw structure
     963                 :            :  **/
     964                 :          0 : void ixgbe_set_pci_config_data_generic(struct ixgbe_hw *hw, u16 link_status)
     965                 :            : {
     966                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
     967                 :            : 
     968         [ #  # ]:          0 :         if (hw->bus.type == ixgbe_bus_type_unknown)
     969                 :          0 :                 hw->bus.type = ixgbe_bus_type_pci_express;
     970                 :            : 
     971   [ #  #  #  #  :          0 :         switch (link_status & IXGBE_PCI_LINK_WIDTH) {
                      # ]
     972                 :          0 :         case IXGBE_PCI_LINK_WIDTH_1:
     973                 :          0 :                 hw->bus.width = ixgbe_bus_width_pcie_x1;
     974                 :          0 :                 break;
     975                 :          0 :         case IXGBE_PCI_LINK_WIDTH_2:
     976                 :          0 :                 hw->bus.width = ixgbe_bus_width_pcie_x2;
     977                 :          0 :                 break;
     978                 :          0 :         case IXGBE_PCI_LINK_WIDTH_4:
     979                 :          0 :                 hw->bus.width = ixgbe_bus_width_pcie_x4;
     980                 :          0 :                 break;
     981                 :          0 :         case IXGBE_PCI_LINK_WIDTH_8:
     982                 :          0 :                 hw->bus.width = ixgbe_bus_width_pcie_x8;
     983                 :          0 :                 break;
     984                 :          0 :         default:
     985                 :          0 :                 hw->bus.width = ixgbe_bus_width_unknown;
     986                 :          0 :                 break;
     987                 :            :         }
     988                 :            : 
     989   [ #  #  #  #  :          0 :         switch (link_status & IXGBE_PCI_LINK_SPEED) {
                      # ]
     990                 :          0 :         case IXGBE_PCI_LINK_SPEED_2500:
     991                 :          0 :                 hw->bus.speed = ixgbe_bus_speed_2500;
     992                 :          0 :                 break;
     993                 :          0 :         case IXGBE_PCI_LINK_SPEED_5000:
     994                 :          0 :                 hw->bus.speed = ixgbe_bus_speed_5000;
     995                 :          0 :                 break;
     996                 :          0 :         case IXGBE_PCI_LINK_SPEED_8000:
     997                 :          0 :                 hw->bus.speed = ixgbe_bus_speed_8000;
     998                 :          0 :                 break;
     999                 :          0 :         case IXGBE_PCI_LINK_SPEED_16000:
    1000                 :          0 :                 hw->bus.speed = ixgbe_bus_speed_16000;
    1001                 :          0 :                 break;
    1002                 :          0 :         default:
    1003                 :          0 :                 hw->bus.speed = ixgbe_bus_speed_unknown;
    1004                 :          0 :                 break;
    1005                 :            :         }
    1006                 :            : 
    1007                 :          0 :         mac->ops.set_lan_id(hw);
    1008                 :          0 : }
    1009                 :            : 
    1010                 :            : /**
    1011                 :            :  * ixgbe_get_bus_info_generic - Generic set PCI bus info
    1012                 :            :  * @hw: pointer to hardware structure
    1013                 :            :  *
    1014                 :            :  * Gets the PCI bus info (speed, width, type) then calls helper function to
    1015                 :            :  * store this data within the ixgbe_hw structure.
    1016                 :            :  **/
    1017                 :          0 : s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
    1018                 :            : {
    1019                 :            :         u16 link_status;
    1020                 :            : 
    1021                 :          0 :         DEBUGFUNC("ixgbe_get_bus_info_generic");
    1022                 :            : 
    1023                 :            :         /* Get the negotiated link width and speed from PCI config space */
    1024                 :            :         link_status = IXGBE_READ_PCIE_WORD(hw, hw->mac.type == ixgbe_mac_E610 ?
    1025                 :            :                                            IXGBE_PCI_LINK_STATUS_E610 :
    1026                 :            :                                            IXGBE_PCI_LINK_STATUS);
    1027                 :            : 
    1028                 :          0 :         ixgbe_set_pci_config_data_generic(hw, link_status);
    1029                 :            : 
    1030                 :          0 :         return IXGBE_SUCCESS;
    1031                 :            : }
    1032                 :            : 
    1033                 :            : /**
    1034                 :            :  * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
    1035                 :            :  * @hw: pointer to the HW structure
    1036                 :            :  *
    1037                 :            :  * Determines the LAN function id by reading memory-mapped registers and swaps
    1038                 :            :  * the port value if requested, and set MAC instance for devices that share
    1039                 :            :  * CS4227.
    1040                 :            :  **/
    1041                 :          0 : void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
    1042                 :            : {
    1043                 :            :         struct ixgbe_bus_info *bus = &hw->bus;
    1044                 :            :         u32 reg;
    1045                 :            :         u16 ee_ctrl_4;
    1046                 :            : 
    1047                 :          0 :         DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie");
    1048                 :            : 
    1049                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
    1050                 :          0 :         bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
    1051                 :          0 :         bus->lan_id = (u8)bus->func;
    1052                 :            : 
    1053                 :            :         /* check for a port swap */
    1054                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_FACTPS_BY_MAC(hw));
    1055         [ #  # ]:          0 :         if (reg & IXGBE_FACTPS_LFS)
    1056                 :          0 :                 bus->func ^= 0x1;
    1057                 :            : 
    1058                 :            :         /* Get MAC instance from EEPROM for configuring CS4227 */
    1059         [ #  # ]:          0 :         if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP) {
    1060                 :          0 :                 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_4, &ee_ctrl_4);
    1061                 :          0 :                 bus->instance_id = (ee_ctrl_4 & IXGBE_EE_CTRL_4_INST_ID) >>
    1062                 :            :                                    IXGBE_EE_CTRL_4_INST_ID_SHIFT;
    1063                 :            :         }
    1064                 :          0 : }
    1065                 :            : 
    1066                 :            : /**
    1067                 :            :  * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
    1068                 :            :  * @hw: pointer to hardware structure
    1069                 :            :  *
    1070                 :            :  * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
    1071                 :            :  * disables transmit and receive units. The adapter_stopped flag is used by
    1072                 :            :  * the shared code and drivers to determine if the adapter is in a stopped
    1073                 :            :  * state and should not touch the hardware.
    1074                 :            :  **/
    1075                 :          0 : s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
    1076                 :            : {
    1077                 :            :         u32 reg_val;
    1078                 :            :         u16 i;
    1079                 :            : 
    1080                 :          0 :         DEBUGFUNC("ixgbe_stop_adapter_generic");
    1081                 :            : 
    1082                 :            :         /*
    1083                 :            :          * Set the adapter_stopped flag so other driver functions stop touching
    1084                 :            :          * the hardware
    1085                 :            :          */
    1086                 :          0 :         hw->adapter_stopped = true;
    1087                 :            : 
    1088                 :            :         /* Disable the receive unit */
    1089                 :          0 :         ixgbe_disable_rx(hw);
    1090                 :            : 
    1091                 :            :         /* Clear interrupt mask to stop interrupts from being generated */
    1092                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
    1093                 :            : 
    1094                 :            :         /* Clear any pending interrupts, flush previous writes */
    1095                 :          0 :         IXGBE_READ_REG(hw, IXGBE_EICR);
    1096                 :            : 
    1097                 :            :         /* Disable the transmit unit.  Each queue must be disabled. */
    1098         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++)
    1099                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
    1100                 :            : 
    1101                 :            :         /* Disable the receive unit by stopping each queue */
    1102         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++) {
    1103         [ #  # ]:          0 :                 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
    1104                 :          0 :                 reg_val &= ~IXGBE_RXDCTL_ENABLE;
    1105                 :          0 :                 reg_val |= IXGBE_RXDCTL_SWFLSH;
    1106                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
    1107                 :            :         }
    1108                 :            : 
    1109                 :            :         /* flush all queues disables */
    1110                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1111                 :          0 :         msec_delay(2);
    1112                 :            : 
    1113                 :            :         /*
    1114                 :            :          * Prevent the PCI-E bus from hanging by disabling PCI-E primary
    1115                 :            :          * access and verify no pending requests
    1116                 :            :          */
    1117                 :          0 :         return ixgbe_disable_pcie_primary(hw);
    1118                 :            : }
    1119                 :            : 
    1120                 :            : /**
    1121                 :            :  * ixgbe_init_led_link_act_generic - Store the LED index link/activity.
    1122                 :            :  * @hw: pointer to hardware structure
    1123                 :            :  *
    1124                 :            :  * Store the index for the link active LED. This will be used to support
    1125                 :            :  * blinking the LED.
    1126                 :            :  **/
    1127                 :          0 : s32 ixgbe_init_led_link_act_generic(struct ixgbe_hw *hw)
    1128                 :            : {
    1129                 :            :         struct ixgbe_mac_info *mac = &hw->mac;
    1130                 :            :         u32 led_reg, led_mode;
    1131                 :            :         u8 i;
    1132                 :            : 
    1133                 :          0 :         led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    1134                 :            : 
    1135                 :            :         /* Get LED link active from the LEDCTL register */
    1136         [ #  # ]:          0 :         for (i = 0; i < 4; i++) {
    1137                 :          0 :                 led_mode = led_reg >> IXGBE_LED_MODE_SHIFT(i);
    1138                 :            : 
    1139         [ #  # ]:          0 :                 if ((led_mode & IXGBE_LED_MODE_MASK_BASE) ==
    1140                 :            :                      IXGBE_LED_LINK_ACTIVE) {
    1141                 :          0 :                         mac->led_link_act = i;
    1142                 :          0 :                         return IXGBE_SUCCESS;
    1143                 :            :                 }
    1144                 :            :         }
    1145                 :            : 
    1146                 :            :         /*
    1147                 :            :          * If LEDCTL register does not have the LED link active set, then use
    1148                 :            :          * known MAC defaults.
    1149                 :            :          */
    1150         [ #  # ]:          0 :         switch (hw->mac.type) {
    1151                 :          0 :         case ixgbe_mac_X550EM_a:
    1152                 :            :         case ixgbe_mac_X550EM_x:
    1153                 :          0 :                 mac->led_link_act = 1;
    1154                 :          0 :                 break;
    1155                 :          0 :         default:
    1156                 :          0 :                 mac->led_link_act = 2;
    1157                 :            :         }
    1158                 :            :         return IXGBE_SUCCESS;
    1159                 :            : }
    1160                 :            : 
    1161                 :            : /**
    1162                 :            :  * ixgbe_led_on_generic - Turns on the software controllable LEDs.
    1163                 :            :  * @hw: pointer to hardware structure
    1164                 :            :  * @index: led number to turn on
    1165                 :            :  **/
    1166                 :          0 : s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
    1167                 :            : {
    1168                 :          0 :         u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    1169                 :            : 
    1170                 :          0 :         DEBUGFUNC("ixgbe_led_on_generic");
    1171                 :            : 
    1172         [ #  # ]:          0 :         if (index > 3)
    1173                 :            :                 return IXGBE_ERR_PARAM;
    1174                 :            : 
    1175                 :            :         /* To turn on the LED, set mode to ON. */
    1176                 :          0 :         led_reg &= ~IXGBE_LED_MODE_MASK(index);
    1177                 :          0 :         led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
    1178                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
    1179                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1180                 :            : 
    1181                 :          0 :         return IXGBE_SUCCESS;
    1182                 :            : }
    1183                 :            : 
    1184                 :            : /**
    1185                 :            :  * ixgbe_led_off_generic - Turns off the software controllable LEDs.
    1186                 :            :  * @hw: pointer to hardware structure
    1187                 :            :  * @index: led number to turn off
    1188                 :            :  **/
    1189                 :          0 : s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
    1190                 :            : {
    1191                 :          0 :         u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    1192                 :            : 
    1193                 :          0 :         DEBUGFUNC("ixgbe_led_off_generic");
    1194                 :            : 
    1195         [ #  # ]:          0 :         if (index > 3)
    1196                 :            :                 return IXGBE_ERR_PARAM;
    1197                 :            : 
    1198                 :            :         /* To turn off the LED, set mode to OFF. */
    1199                 :          0 :         led_reg &= ~IXGBE_LED_MODE_MASK(index);
    1200                 :          0 :         led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
    1201                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
    1202                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1203                 :            : 
    1204                 :          0 :         return IXGBE_SUCCESS;
    1205                 :            : }
    1206                 :            : 
    1207                 :            : /**
    1208                 :            :  * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
    1209                 :            :  * @hw: pointer to hardware structure
    1210                 :            :  *
    1211                 :            :  * Initializes the EEPROM parameters ixgbe_eeprom_info within the
    1212                 :            :  * ixgbe_hw struct in order to set up EEPROM access.
    1213                 :            :  **/
    1214                 :          0 : s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
    1215                 :            : {
    1216                 :            :         struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
    1217                 :            :         u32 eec;
    1218                 :            :         u16 eeprom_size;
    1219                 :            : 
    1220                 :          0 :         DEBUGFUNC("ixgbe_init_eeprom_params_generic");
    1221                 :            : 
    1222         [ #  # ]:          0 :         if (eeprom->type == ixgbe_eeprom_uninitialized) {
    1223                 :          0 :                 eeprom->type = ixgbe_eeprom_none;
    1224                 :            :                 /* Set default semaphore delay to 10ms which is a well
    1225                 :            :                  * tested value */
    1226                 :          0 :                 eeprom->semaphore_delay = 10;
    1227                 :            :                 /* Clear EEPROM page size, it will be initialized as needed */
    1228                 :          0 :                 eeprom->word_page_size = 0;
    1229                 :            : 
    1230                 :            :                 /*
    1231                 :            :                  * Check for EEPROM present first.
    1232                 :            :                  * If not present leave as none
    1233                 :            :                  */
    1234                 :          0 :                 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    1235         [ #  # ]:          0 :                 if (eec & IXGBE_EEC_PRES) {
    1236                 :          0 :                         eeprom->type = ixgbe_eeprom_spi;
    1237                 :            : 
    1238                 :            :                         /*
    1239                 :            :                          * SPI EEPROM is assumed here.  This code would need to
    1240                 :            :                          * change if a future EEPROM is not SPI.
    1241                 :            :                          */
    1242                 :          0 :                         eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
    1243                 :            :                                             IXGBE_EEC_SIZE_SHIFT);
    1244                 :          0 :                         eeprom->word_size = 1 << (eeprom_size +
    1245                 :            :                                              IXGBE_EEPROM_WORD_SIZE_SHIFT);
    1246                 :            :                 }
    1247                 :            : 
    1248         [ #  # ]:          0 :                 if (eec & IXGBE_EEC_ADDR_SIZE)
    1249                 :          0 :                         eeprom->address_bits = 16;
    1250                 :            :                 else
    1251                 :          0 :                         eeprom->address_bits = 8;
    1252                 :          0 :                 DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: "
    1253                 :            :                           "%d\n", eeprom->type, eeprom->word_size,
    1254                 :            :                           eeprom->address_bits);
    1255                 :            :         }
    1256                 :            : 
    1257                 :          0 :         return IXGBE_SUCCESS;
    1258                 :            : }
    1259                 :            : 
    1260                 :            : /**
    1261                 :            :  * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
    1262                 :            :  * @hw: pointer to hardware structure
    1263                 :            :  * @offset: offset within the EEPROM to write
    1264                 :            :  * @words: number of word(s)
    1265                 :            :  * @data: 16 bit word(s) to write to EEPROM
    1266                 :            :  *
    1267                 :            :  * Reads 16 bit word(s) from EEPROM through bit-bang method
    1268                 :            :  **/
    1269                 :          0 : s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
    1270                 :            :                                                u16 words, u16 *data)
    1271                 :            : {
    1272                 :            :         s32 status = IXGBE_SUCCESS;
    1273                 :            :         u16 i, count;
    1274                 :            : 
    1275                 :          0 :         DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang_generic");
    1276                 :            : 
    1277                 :          0 :         hw->eeprom.ops.init_params(hw);
    1278                 :            : 
    1279         [ #  # ]:          0 :         if (words == 0) {
    1280                 :            :                 status = IXGBE_ERR_INVALID_ARGUMENT;
    1281                 :          0 :                 goto out;
    1282                 :            :         }
    1283                 :            : 
    1284         [ #  # ]:          0 :         if (offset + words > hw->eeprom.word_size) {
    1285                 :            :                 status = IXGBE_ERR_EEPROM;
    1286                 :          0 :                 goto out;
    1287                 :            :         }
    1288                 :            : 
    1289                 :            :         /*
    1290                 :            :          * The EEPROM page size cannot be queried from the chip. We do lazy
    1291                 :            :          * initialization. It is worth to do that when we write large buffer.
    1292                 :            :          */
    1293   [ #  #  #  # ]:          0 :         if ((hw->eeprom.word_page_size == 0) &&
    1294                 :            :             (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
    1295                 :          0 :                 ixgbe_detect_eeprom_page_size_generic(hw, offset);
    1296                 :            : 
    1297                 :            :         /*
    1298                 :            :          * We cannot hold synchronization semaphores for too long
    1299                 :            :          * to avoid other entity starvation. However it is more efficient
    1300                 :            :          * to read in bursts than synchronizing access for each word.
    1301                 :            :          */
    1302         [ #  # ]:          0 :         for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
    1303                 :          0 :                 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
    1304                 :          0 :                         IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
    1305                 :          0 :                 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
    1306                 :          0 :                                                             count, &data[i]);
    1307                 :            : 
    1308         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1309                 :            :                         break;
    1310                 :            :         }
    1311                 :            : 
    1312                 :          0 : out:
    1313                 :          0 :         return status;
    1314                 :            : }
    1315                 :            : 
    1316                 :            : /**
    1317                 :            :  * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
    1318                 :            :  * @hw: pointer to hardware structure
    1319                 :            :  * @offset: offset within the EEPROM to be written to
    1320                 :            :  * @words: number of word(s)
    1321                 :            :  * @data: 16 bit word(s) to be written to the EEPROM
    1322                 :            :  *
    1323                 :            :  * If ixgbe_eeprom_update_checksum is not called after this function, the
    1324                 :            :  * EEPROM will most likely contain an invalid checksum.
    1325                 :            :  **/
    1326                 :          0 : STATIC s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
    1327                 :            :                                               u16 words, u16 *data)
    1328                 :            : {
    1329                 :            :         s32 status;
    1330                 :            :         u16 word;
    1331                 :            :         u16 page_size;
    1332                 :            :         u16 i;
    1333                 :            :         u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
    1334                 :            : 
    1335                 :          0 :         DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang");
    1336                 :            : 
    1337                 :            :         /* Prepare the EEPROM for writing  */
    1338                 :          0 :         status = ixgbe_acquire_eeprom(hw);
    1339                 :            : 
    1340         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    1341         [ #  # ]:          0 :                 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
    1342                 :          0 :                         ixgbe_release_eeprom(hw);
    1343                 :            :                         status = IXGBE_ERR_EEPROM;
    1344                 :            :                 }
    1345                 :            :         }
    1346                 :            : 
    1347         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    1348         [ #  # ]:          0 :                 for (i = 0; i < words; i++) {
    1349                 :          0 :                         ixgbe_standby_eeprom(hw);
    1350                 :            : 
    1351                 :            :                         /*  Send the WRITE ENABLE command (8 bit opcode )  */
    1352                 :          0 :                         ixgbe_shift_out_eeprom_bits(hw,
    1353                 :            :                                                    IXGBE_EEPROM_WREN_OPCODE_SPI,
    1354                 :            :                                                    IXGBE_EEPROM_OPCODE_BITS);
    1355                 :            : 
    1356                 :          0 :                         ixgbe_standby_eeprom(hw);
    1357                 :            : 
    1358                 :            :                         /*
    1359                 :            :                          * Some SPI eeproms use the 8th address bit embedded
    1360                 :            :                          * in the opcode
    1361                 :            :                          */
    1362         [ #  # ]:          0 :                         if ((hw->eeprom.address_bits == 8) &&
    1363         [ #  # ]:          0 :                             ((offset + i) >= 128))
    1364                 :            :                                 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
    1365                 :            : 
    1366                 :            :                         /* Send the Write command (8-bit opcode + addr) */
    1367                 :          0 :                         ixgbe_shift_out_eeprom_bits(hw, write_opcode,
    1368                 :            :                                                     IXGBE_EEPROM_OPCODE_BITS);
    1369                 :          0 :                         ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
    1370                 :          0 :                                                     hw->eeprom.address_bits);
    1371                 :            : 
    1372                 :          0 :                         page_size = hw->eeprom.word_page_size;
    1373                 :            : 
    1374                 :            :                         /* Send the data in burst via SPI*/
    1375                 :            :                         do {
    1376                 :          0 :                                 word = data[i];
    1377                 :          0 :                                 word = (word >> 8) | (word << 8);
    1378                 :          0 :                                 ixgbe_shift_out_eeprom_bits(hw, word, 16);
    1379                 :            : 
    1380         [ #  # ]:          0 :                                 if (page_size == 0)
    1381                 :            :                                         break;
    1382                 :            : 
    1383                 :            :                                 /* do not wrap around page */
    1384         [ #  # ]:          0 :                                 if (((offset + i) & (page_size - 1)) ==
    1385                 :            :                                     (page_size - 1))
    1386                 :            :                                         break;
    1387         [ #  # ]:          0 :                         } while (++i < words);
    1388                 :            : 
    1389                 :          0 :                         ixgbe_standby_eeprom(hw);
    1390                 :          0 :                         msec_delay(10);
    1391                 :            :                 }
    1392                 :            :                 /* Done with writing - release the EEPROM */
    1393                 :          0 :                 ixgbe_release_eeprom(hw);
    1394                 :            :         }
    1395                 :            : 
    1396                 :          0 :         return status;
    1397                 :            : }
    1398                 :            : 
    1399                 :            : /**
    1400                 :            :  * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
    1401                 :            :  * @hw: pointer to hardware structure
    1402                 :            :  * @offset: offset within the EEPROM to be written to
    1403                 :            :  * @data: 16 bit word to be written to the EEPROM
    1404                 :            :  *
    1405                 :            :  * If ixgbe_eeprom_update_checksum is not called after this function, the
    1406                 :            :  * EEPROM will most likely contain an invalid checksum.
    1407                 :            :  **/
    1408                 :          0 : s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
    1409                 :            : {
    1410                 :            :         s32 status;
    1411                 :            : 
    1412                 :          0 :         DEBUGFUNC("ixgbe_write_eeprom_generic");
    1413                 :            : 
    1414                 :          0 :         hw->eeprom.ops.init_params(hw);
    1415                 :            : 
    1416         [ #  # ]:          0 :         if (offset >= hw->eeprom.word_size) {
    1417                 :            :                 status = IXGBE_ERR_EEPROM;
    1418                 :          0 :                 goto out;
    1419                 :            :         }
    1420                 :            : 
    1421                 :          0 :         status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
    1422                 :            : 
    1423                 :          0 : out:
    1424                 :          0 :         return status;
    1425                 :            : }
    1426                 :            : 
    1427                 :            : /**
    1428                 :            :  * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
    1429                 :            :  * @hw: pointer to hardware structure
    1430                 :            :  * @offset: offset within the EEPROM to be read
    1431                 :            :  * @data: read 16 bit words(s) from EEPROM
    1432                 :            :  * @words: number of word(s)
    1433                 :            :  *
    1434                 :            :  * Reads 16 bit word(s) from EEPROM through bit-bang method
    1435                 :            :  **/
    1436                 :          0 : s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
    1437                 :            :                                               u16 words, u16 *data)
    1438                 :            : {
    1439                 :            :         s32 status = IXGBE_SUCCESS;
    1440                 :            :         u16 i, count;
    1441                 :            : 
    1442                 :          0 :         DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang_generic");
    1443                 :            : 
    1444                 :          0 :         hw->eeprom.ops.init_params(hw);
    1445                 :            : 
    1446         [ #  # ]:          0 :         if (words == 0) {
    1447                 :            :                 status = IXGBE_ERR_INVALID_ARGUMENT;
    1448                 :          0 :                 goto out;
    1449                 :            :         }
    1450                 :            : 
    1451         [ #  # ]:          0 :         if (offset + words > hw->eeprom.word_size) {
    1452                 :            :                 status = IXGBE_ERR_EEPROM;
    1453                 :          0 :                 goto out;
    1454                 :            :         }
    1455                 :            : 
    1456                 :            :         /*
    1457                 :            :          * We cannot hold synchronization semaphores for too long
    1458                 :            :          * to avoid other entity starvation. However it is more efficient
    1459                 :            :          * to read in bursts than synchronizing access for each word.
    1460                 :            :          */
    1461         [ #  # ]:          0 :         for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
    1462                 :          0 :                 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
    1463                 :          0 :                         IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
    1464                 :            : 
    1465                 :          0 :                 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
    1466                 :          0 :                                                            count, &data[i]);
    1467                 :            : 
    1468         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    1469                 :            :                         break;
    1470                 :            :         }
    1471                 :            : 
    1472                 :          0 : out:
    1473                 :          0 :         return status;
    1474                 :            : }
    1475                 :            : 
    1476                 :            : /**
    1477                 :            :  * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
    1478                 :            :  * @hw: pointer to hardware structure
    1479                 :            :  * @offset: offset within the EEPROM to be read
    1480                 :            :  * @words: number of word(s)
    1481                 :            :  * @data: read 16 bit word(s) from EEPROM
    1482                 :            :  *
    1483                 :            :  * Reads 16 bit word(s) from EEPROM through bit-bang method
    1484                 :            :  **/
    1485                 :          0 : STATIC s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
    1486                 :            :                                              u16 words, u16 *data)
    1487                 :            : {
    1488                 :            :         s32 status;
    1489                 :            :         u16 word_in;
    1490                 :            :         u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
    1491                 :            :         u16 i;
    1492                 :            : 
    1493                 :          0 :         DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang");
    1494                 :            : 
    1495                 :            :         /* Prepare the EEPROM for reading  */
    1496                 :          0 :         status = ixgbe_acquire_eeprom(hw);
    1497                 :            : 
    1498         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    1499         [ #  # ]:          0 :                 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
    1500                 :          0 :                         ixgbe_release_eeprom(hw);
    1501                 :            :                         status = IXGBE_ERR_EEPROM;
    1502                 :            :                 }
    1503                 :            :         }
    1504                 :            : 
    1505         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    1506         [ #  # ]:          0 :                 for (i = 0; i < words; i++) {
    1507                 :          0 :                         ixgbe_standby_eeprom(hw);
    1508                 :            :                         /*
    1509                 :            :                          * Some SPI eeproms use the 8th address bit embedded
    1510                 :            :                          * in the opcode
    1511                 :            :                          */
    1512         [ #  # ]:          0 :                         if ((hw->eeprom.address_bits == 8) &&
    1513         [ #  # ]:          0 :                             ((offset + i) >= 128))
    1514                 :            :                                 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
    1515                 :            : 
    1516                 :            :                         /* Send the READ command (opcode + addr) */
    1517                 :          0 :                         ixgbe_shift_out_eeprom_bits(hw, read_opcode,
    1518                 :            :                                                     IXGBE_EEPROM_OPCODE_BITS);
    1519                 :          0 :                         ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
    1520                 :          0 :                                                     hw->eeprom.address_bits);
    1521                 :            : 
    1522                 :            :                         /* Read the data. */
    1523                 :          0 :                         word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
    1524                 :          0 :                         data[i] = (word_in >> 8) | (word_in << 8);
    1525                 :            :                 }
    1526                 :            : 
    1527                 :            :                 /* End this read operation */
    1528                 :          0 :                 ixgbe_release_eeprom(hw);
    1529                 :            :         }
    1530                 :            : 
    1531                 :          0 :         return status;
    1532                 :            : }
    1533                 :            : 
    1534                 :            : /**
    1535                 :            :  * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
    1536                 :            :  * @hw: pointer to hardware structure
    1537                 :            :  * @offset: offset within the EEPROM to be read
    1538                 :            :  * @data: read 16 bit value from EEPROM
    1539                 :            :  *
    1540                 :            :  * Reads 16 bit value from EEPROM through bit-bang method
    1541                 :            :  **/
    1542                 :          0 : s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
    1543                 :            :                                        u16 *data)
    1544                 :            : {
    1545                 :            :         s32 status;
    1546                 :            : 
    1547                 :          0 :         DEBUGFUNC("ixgbe_read_eeprom_bit_bang_generic");
    1548                 :            : 
    1549                 :          0 :         hw->eeprom.ops.init_params(hw);
    1550                 :            : 
    1551         [ #  # ]:          0 :         if (offset >= hw->eeprom.word_size) {
    1552                 :            :                 status = IXGBE_ERR_EEPROM;
    1553                 :          0 :                 goto out;
    1554                 :            :         }
    1555                 :            : 
    1556                 :          0 :         status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
    1557                 :            : 
    1558                 :          0 : out:
    1559                 :          0 :         return status;
    1560                 :            : }
    1561                 :            : 
    1562                 :            : /**
    1563                 :            :  * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
    1564                 :            :  * @hw: pointer to hardware structure
    1565                 :            :  * @offset: offset of word in the EEPROM to read
    1566                 :            :  * @words: number of word(s)
    1567                 :            :  * @data: 16 bit word(s) from the EEPROM
    1568                 :            :  *
    1569                 :            :  * Reads a 16 bit word(s) from the EEPROM using the EERD register.
    1570                 :            :  **/
    1571                 :          0 : s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
    1572                 :            :                                    u16 words, u16 *data)
    1573                 :            : {
    1574                 :            :         u32 eerd;
    1575                 :            :         s32 status = IXGBE_SUCCESS;
    1576                 :            :         u32 i;
    1577                 :            : 
    1578                 :          0 :         DEBUGFUNC("ixgbe_read_eerd_buffer_generic");
    1579                 :            : 
    1580                 :          0 :         hw->eeprom.ops.init_params(hw);
    1581                 :            : 
    1582         [ #  # ]:          0 :         if (words == 0) {
    1583                 :            :                 status = IXGBE_ERR_INVALID_ARGUMENT;
    1584                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
    1585                 :          0 :                 goto out;
    1586                 :            :         }
    1587                 :            : 
    1588         [ #  # ]:          0 :         if (offset >= hw->eeprom.word_size) {
    1589                 :            :                 status = IXGBE_ERR_EEPROM;
    1590                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
    1591                 :          0 :                 goto out;
    1592                 :            :         }
    1593                 :            : 
    1594         [ #  # ]:          0 :         for (i = 0; i < words; i++) {
    1595                 :          0 :                 eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
    1596                 :            :                        IXGBE_EEPROM_RW_REG_START;
    1597                 :            : 
    1598                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
    1599                 :          0 :                 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
    1600                 :            : 
    1601         [ #  # ]:          0 :                 if (status == IXGBE_SUCCESS) {
    1602                 :          0 :                         data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
    1603                 :            :                                    IXGBE_EEPROM_RW_REG_DATA);
    1604                 :            :                 } else {
    1605                 :          0 :                         DEBUGOUT("Eeprom read timed out\n");
    1606                 :          0 :                         goto out;
    1607                 :            :                 }
    1608                 :            :         }
    1609                 :          0 : out:
    1610                 :          0 :         return status;
    1611                 :            : }
    1612                 :            : 
    1613                 :            : /**
    1614                 :            :  * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
    1615                 :            :  * @hw: pointer to hardware structure
    1616                 :            :  * @offset: offset within the EEPROM to be used as a scratch pad
    1617                 :            :  *
    1618                 :            :  * Discover EEPROM page size by writing marching data at given offset.
    1619                 :            :  * This function is called only when we are writing a new large buffer
    1620                 :            :  * at given offset so the data would be overwritten anyway.
    1621                 :            :  **/
    1622                 :          0 : STATIC s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
    1623                 :            :                                                  u16 offset)
    1624                 :            : {
    1625                 :            :         u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
    1626                 :            :         s32 status = IXGBE_SUCCESS;
    1627                 :            :         u16 i;
    1628                 :            : 
    1629                 :          0 :         DEBUGFUNC("ixgbe_detect_eeprom_page_size_generic");
    1630                 :            : 
    1631         [ #  # ]:          0 :         for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
    1632                 :          0 :                 data[i] = i;
    1633                 :            : 
    1634                 :          0 :         hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
    1635                 :          0 :         status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
    1636                 :            :                                              IXGBE_EEPROM_PAGE_SIZE_MAX, data);
    1637                 :          0 :         hw->eeprom.word_page_size = 0;
    1638         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1639                 :          0 :                 goto out;
    1640                 :            : 
    1641                 :          0 :         status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
    1642         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    1643                 :          0 :                 goto out;
    1644                 :            : 
    1645                 :            :         /*
    1646                 :            :          * When writing in burst more than the actual page size
    1647                 :            :          * EEPROM address wraps around current page.
    1648                 :            :          */
    1649                 :          0 :         hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
    1650                 :            : 
    1651                 :          0 :         DEBUGOUT1("Detected EEPROM page size = %d words.",
    1652                 :            :                   hw->eeprom.word_page_size);
    1653                 :          0 : out:
    1654                 :          0 :         return status;
    1655                 :            : }
    1656                 :            : 
    1657                 :            : /**
    1658                 :            :  * ixgbe_read_eerd_generic - Read EEPROM word using EERD
    1659                 :            :  * @hw: pointer to hardware structure
    1660                 :            :  * @offset: offset of  word in the EEPROM to read
    1661                 :            :  * @data: word read from the EEPROM
    1662                 :            :  *
    1663                 :            :  * Reads a 16 bit word from the EEPROM using the EERD register.
    1664                 :            :  **/
    1665                 :          0 : s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
    1666                 :            : {
    1667                 :          0 :         return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
    1668                 :            : }
    1669                 :            : 
    1670                 :            : /**
    1671                 :            :  * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
    1672                 :            :  * @hw: pointer to hardware structure
    1673                 :            :  * @offset: offset of  word in the EEPROM to write
    1674                 :            :  * @words: number of word(s)
    1675                 :            :  * @data: word(s) write to the EEPROM
    1676                 :            :  *
    1677                 :            :  * Write a 16 bit word(s) to the EEPROM using the EEWR register.
    1678                 :            :  **/
    1679                 :          0 : s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
    1680                 :            :                                     u16 words, u16 *data)
    1681                 :            : {
    1682                 :            :         u32 eewr;
    1683                 :            :         s32 status = IXGBE_SUCCESS;
    1684                 :            :         u16 i;
    1685                 :            : 
    1686                 :          0 :         DEBUGFUNC("ixgbe_write_eewr_generic");
    1687                 :            : 
    1688                 :          0 :         hw->eeprom.ops.init_params(hw);
    1689                 :            : 
    1690         [ #  # ]:          0 :         if (words == 0) {
    1691                 :            :                 status = IXGBE_ERR_INVALID_ARGUMENT;
    1692                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
    1693                 :          0 :                 goto out;
    1694                 :            :         }
    1695                 :            : 
    1696         [ #  # ]:          0 :         if (offset >= hw->eeprom.word_size) {
    1697                 :            :                 status = IXGBE_ERR_EEPROM;
    1698                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
    1699                 :          0 :                 goto out;
    1700                 :            :         }
    1701                 :            : 
    1702         [ #  # ]:          0 :         for (i = 0; i < words; i++) {
    1703                 :          0 :                 eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
    1704                 :          0 :                         (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
    1705                 :            :                         IXGBE_EEPROM_RW_REG_START;
    1706                 :            : 
    1707                 :          0 :                 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
    1708         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS) {
    1709                 :          0 :                         DEBUGOUT("Eeprom write EEWR timed out\n");
    1710                 :          0 :                         goto out;
    1711                 :            :                 }
    1712                 :            : 
    1713                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
    1714                 :            : 
    1715                 :          0 :                 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
    1716         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS) {
    1717                 :          0 :                         DEBUGOUT("Eeprom write EEWR timed out\n");
    1718                 :          0 :                         goto out;
    1719                 :            :                 }
    1720                 :            :         }
    1721                 :            : 
    1722                 :          0 : out:
    1723                 :          0 :         return status;
    1724                 :            : }
    1725                 :            : 
    1726                 :            : /**
    1727                 :            :  * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
    1728                 :            :  * @hw: pointer to hardware structure
    1729                 :            :  * @offset: offset of  word in the EEPROM to write
    1730                 :            :  * @data: word write to the EEPROM
    1731                 :            :  *
    1732                 :            :  * Write a 16 bit word to the EEPROM using the EEWR register.
    1733                 :            :  **/
    1734                 :          0 : s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
    1735                 :            : {
    1736                 :          0 :         return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
    1737                 :            : }
    1738                 :            : 
    1739                 :            : /**
    1740                 :            :  * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
    1741                 :            :  * @hw: pointer to hardware structure
    1742                 :            :  * @ee_reg: EEPROM flag for polling
    1743                 :            :  *
    1744                 :            :  * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
    1745                 :            :  * read or write is done respectively.
    1746                 :            :  **/
    1747                 :          0 : s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
    1748                 :            : {
    1749                 :            :         u32 i;
    1750                 :            :         u32 reg;
    1751                 :            :         s32 status = IXGBE_ERR_EEPROM;
    1752                 :            : 
    1753                 :          0 :         DEBUGFUNC("ixgbe_poll_eerd_eewr_done");
    1754                 :            : 
    1755         [ #  # ]:          0 :         for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
    1756         [ #  # ]:          0 :                 if (ee_reg == IXGBE_NVM_POLL_READ)
    1757                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_EERD);
    1758                 :            :                 else
    1759                 :          0 :                         reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
    1760                 :            : 
    1761         [ #  # ]:          0 :                 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
    1762                 :            :                         status = IXGBE_SUCCESS;
    1763                 :            :                         break;
    1764                 :            :                 }
    1765                 :          0 :                 usec_delay(5);
    1766                 :            :         }
    1767                 :            : 
    1768         [ #  # ]:          0 :         if (i == IXGBE_EERD_EEWR_ATTEMPTS)
    1769                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING,
    1770                 :            :                              "EEPROM read/write done polling timed out");
    1771                 :            : 
    1772                 :          0 :         return status;
    1773                 :            : }
    1774                 :            : 
    1775                 :            : /**
    1776                 :            :  * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
    1777                 :            :  * @hw: pointer to hardware structure
    1778                 :            :  *
    1779                 :            :  * Prepares EEPROM for access using bit-bang method. This function should
    1780                 :            :  * be called before issuing a command to the EEPROM.
    1781                 :            :  **/
    1782                 :          0 : STATIC s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
    1783                 :            : {
    1784                 :            :         s32 status = IXGBE_SUCCESS;
    1785                 :            :         u32 eec;
    1786                 :            :         u32 i;
    1787                 :            : 
    1788                 :          0 :         DEBUGFUNC("ixgbe_acquire_eeprom");
    1789                 :            : 
    1790         [ #  # ]:          0 :         if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM)
    1791                 :            :             != IXGBE_SUCCESS)
    1792                 :            :                 status = IXGBE_ERR_SWFW_SYNC;
    1793                 :            : 
    1794                 :            :         if (status == IXGBE_SUCCESS) {
    1795                 :          0 :                 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    1796                 :            : 
    1797                 :            :                 /* Request EEPROM Access */
    1798                 :          0 :                 eec |= IXGBE_EEC_REQ;
    1799                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    1800                 :            : 
    1801         [ #  # ]:          0 :                 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
    1802                 :          0 :                         eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    1803         [ #  # ]:          0 :                         if (eec & IXGBE_EEC_GNT)
    1804                 :            :                                 break;
    1805                 :          0 :                         usec_delay(5);
    1806                 :            :                 }
    1807                 :            : 
    1808                 :            :                 /* Release if grant not acquired */
    1809         [ #  # ]:          0 :                 if (!(eec & IXGBE_EEC_GNT)) {
    1810                 :          0 :                         eec &= ~IXGBE_EEC_REQ;
    1811                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    1812                 :          0 :                         DEBUGOUT("Could not acquire EEPROM grant\n");
    1813                 :            : 
    1814                 :          0 :                         hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    1815                 :            :                         status = IXGBE_ERR_EEPROM;
    1816                 :            :                 }
    1817                 :            : 
    1818                 :            :                 /* Setup EEPROM for Read/Write */
    1819                 :            :                 if (status == IXGBE_SUCCESS) {
    1820                 :            :                         /* Clear CS and SK */
    1821                 :          0 :                         eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
    1822                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    1823                 :          0 :                         IXGBE_WRITE_FLUSH(hw);
    1824                 :          0 :                         usec_delay(1);
    1825                 :            :                 }
    1826                 :            :         }
    1827                 :          0 :         return status;
    1828                 :            : }
    1829                 :            : 
    1830                 :            : /**
    1831                 :            :  * ixgbe_get_eeprom_semaphore - Get hardware semaphore
    1832                 :            :  * @hw: pointer to hardware structure
    1833                 :            :  *
    1834                 :            :  * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
    1835                 :            :  **/
    1836                 :          0 : STATIC s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
    1837                 :            : {
    1838                 :            :         s32 status = IXGBE_ERR_EEPROM;
    1839                 :            :         u32 timeout = 2000;
    1840                 :            :         u32 i;
    1841                 :            :         u32 swsm;
    1842                 :            : 
    1843                 :          0 :         DEBUGFUNC("ixgbe_get_eeprom_semaphore");
    1844                 :            : 
    1845                 :            : 
    1846                 :            :         /* Get SMBI software semaphore between device drivers first */
    1847         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    1848                 :            :                 /*
    1849                 :            :                  * If the SMBI bit is 0 when we read it, then the bit will be
    1850                 :            :                  * set and we have the semaphore
    1851                 :            :                  */
    1852                 :          0 :                 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
    1853         [ #  # ]:          0 :                 if (!(swsm & IXGBE_SWSM_SMBI)) {
    1854                 :            :                         status = IXGBE_SUCCESS;
    1855                 :            :                         break;
    1856                 :            :                 }
    1857                 :          0 :                 usec_delay(50);
    1858                 :            :         }
    1859                 :            : 
    1860         [ #  # ]:          0 :         if (i == timeout) {
    1861                 :          0 :                 DEBUGOUT("Driver can't access the Eeprom - SMBI Semaphore "
    1862                 :            :                          "not granted.\n");
    1863                 :            :                 /*
    1864                 :            :                  * this release is particularly important because our attempts
    1865                 :            :                  * above to get the semaphore may have succeeded, and if there
    1866                 :            :                  * was a timeout, we should unconditionally clear the semaphore
    1867                 :            :                  * bits to free the driver to make progress
    1868                 :            :                  */
    1869                 :          0 :                 ixgbe_release_eeprom_semaphore(hw);
    1870                 :            : 
    1871                 :          0 :                 usec_delay(50);
    1872                 :            :                 /*
    1873                 :            :                  * one last try
    1874                 :            :                  * If the SMBI bit is 0 when we read it, then the bit will be
    1875                 :            :                  * set and we have the semaphore
    1876                 :            :                  */
    1877                 :          0 :                 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
    1878         [ #  # ]:          0 :                 if (!(swsm & IXGBE_SWSM_SMBI))
    1879                 :            :                         status = IXGBE_SUCCESS;
    1880                 :            :         }
    1881                 :            : 
    1882                 :            :         /* Now get the semaphore between SW/FW through the SWESMBI bit */
    1883         [ #  # ]:          0 :         if (status == IXGBE_SUCCESS) {
    1884         [ #  # ]:          0 :                 for (i = 0; i < timeout; i++) {
    1885                 :          0 :                         swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
    1886                 :            : 
    1887                 :            :                         /* Set the SW EEPROM semaphore bit to request access */
    1888                 :          0 :                         swsm |= IXGBE_SWSM_SWESMBI;
    1889                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_SWSM_BY_MAC(hw), swsm);
    1890                 :            : 
    1891                 :            :                         /*
    1892                 :            :                          * If we set the bit successfully then we got the
    1893                 :            :                          * semaphore.
    1894                 :            :                          */
    1895                 :          0 :                         swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
    1896         [ #  # ]:          0 :                         if (swsm & IXGBE_SWSM_SWESMBI)
    1897                 :            :                                 break;
    1898                 :            : 
    1899                 :          0 :                         usec_delay(50);
    1900                 :            :                 }
    1901                 :            : 
    1902                 :            :                 /*
    1903                 :            :                  * Release semaphores and return error if SW EEPROM semaphore
    1904                 :            :                  * was not granted because we don't have access to the EEPROM
    1905                 :            :                  */
    1906         [ #  # ]:          0 :                 if (i >= timeout) {
    1907                 :          0 :                         ERROR_REPORT1(IXGBE_ERROR_POLLING,
    1908                 :            :                             "SWESMBI Software EEPROM semaphore not granted.\n");
    1909                 :          0 :                         ixgbe_release_eeprom_semaphore(hw);
    1910                 :            :                         status = IXGBE_ERR_EEPROM;
    1911                 :            :                 }
    1912                 :            :         } else {
    1913                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_POLLING,
    1914                 :            :                              "Software semaphore SMBI between device drivers "
    1915                 :            :                              "not granted.\n");
    1916                 :            :         }
    1917                 :            : 
    1918                 :          0 :         return status;
    1919                 :            : }
    1920                 :            : 
    1921                 :            : /**
    1922                 :            :  * ixgbe_release_eeprom_semaphore - Release hardware semaphore
    1923                 :            :  * @hw: pointer to hardware structure
    1924                 :            :  *
    1925                 :            :  * This function clears hardware semaphore bits.
    1926                 :            :  **/
    1927                 :          0 : STATIC void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
    1928                 :            : {
    1929                 :            :         u32 swsm;
    1930                 :            : 
    1931                 :          0 :         DEBUGFUNC("ixgbe_release_eeprom_semaphore");
    1932                 :            : 
    1933                 :          0 :         swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
    1934                 :            : 
    1935                 :            :         /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
    1936                 :          0 :         swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
    1937                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
    1938                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1939                 :          0 : }
    1940                 :            : 
    1941                 :            : /**
    1942                 :            :  * ixgbe_ready_eeprom - Polls for EEPROM ready
    1943                 :            :  * @hw: pointer to hardware structure
    1944                 :            :  **/
    1945                 :          0 : STATIC s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
    1946                 :            : {
    1947                 :            :         s32 status = IXGBE_SUCCESS;
    1948                 :            :         u16 i;
    1949                 :            :         u8 spi_stat_reg;
    1950                 :            : 
    1951                 :          0 :         DEBUGFUNC("ixgbe_ready_eeprom");
    1952                 :            : 
    1953                 :            :         /*
    1954                 :            :          * Read "Status Register" repeatedly until the LSB is cleared.  The
    1955                 :            :          * EEPROM will signal that the command has been completed by clearing
    1956                 :            :          * bit 0 of the internal status register.  If it's not cleared within
    1957                 :            :          * 5 milliseconds, then error out.
    1958                 :            :          */
    1959         [ #  # ]:          0 :         for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
    1960                 :          0 :                 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
    1961                 :            :                                             IXGBE_EEPROM_OPCODE_BITS);
    1962                 :          0 :                 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
    1963         [ #  # ]:          0 :                 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
    1964                 :            :                         break;
    1965                 :            : 
    1966                 :          0 :                 usec_delay(5);
    1967                 :          0 :                 ixgbe_standby_eeprom(hw);
    1968                 :            :         };
    1969                 :            : 
    1970                 :            :         /*
    1971                 :            :          * On some parts, SPI write time could vary from 0-20mSec on 3.3V
    1972                 :            :          * devices (and only 0-5mSec on 5V devices)
    1973                 :            :          */
    1974         [ #  # ]:          0 :         if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
    1975                 :          0 :                 DEBUGOUT("SPI EEPROM Status error\n");
    1976                 :            :                 status = IXGBE_ERR_EEPROM;
    1977                 :            :         }
    1978                 :            : 
    1979                 :          0 :         return status;
    1980                 :            : }
    1981                 :            : 
    1982                 :            : /**
    1983                 :            :  * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
    1984                 :            :  * @hw: pointer to hardware structure
    1985                 :            :  **/
    1986                 :          0 : STATIC void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
    1987                 :            : {
    1988                 :            :         u32 eec;
    1989                 :            : 
    1990                 :          0 :         DEBUGFUNC("ixgbe_standby_eeprom");
    1991                 :            : 
    1992                 :          0 :         eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    1993                 :            : 
    1994                 :            :         /* Toggle CS to flush commands */
    1995                 :          0 :         eec |= IXGBE_EEC_CS;
    1996                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    1997                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    1998                 :          0 :         usec_delay(1);
    1999                 :            :         eec &= ~IXGBE_EEC_CS;
    2000                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    2001                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2002                 :          0 :         usec_delay(1);
    2003                 :          0 : }
    2004                 :            : 
    2005                 :            : /**
    2006                 :            :  * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
    2007                 :            :  * @hw: pointer to hardware structure
    2008                 :            :  * @data: data to send to the EEPROM
    2009                 :            :  * @count: number of bits to shift out
    2010                 :            :  **/
    2011                 :          0 : STATIC void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
    2012                 :            :                                         u16 count)
    2013                 :            : {
    2014                 :            :         u32 eec;
    2015                 :            :         u32 mask;
    2016                 :            :         u32 i;
    2017                 :            : 
    2018                 :          0 :         DEBUGFUNC("ixgbe_shift_out_eeprom_bits");
    2019                 :            : 
    2020                 :          0 :         eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    2021                 :            : 
    2022                 :            :         /*
    2023                 :            :          * Mask is used to shift "count" bits of "data" out to the EEPROM
    2024                 :            :          * one bit at a time.  Determine the starting bit based on count
    2025                 :            :          */
    2026                 :          0 :         mask = 0x01 << (count - 1);
    2027                 :            : 
    2028         [ #  # ]:          0 :         for (i = 0; i < count; i++) {
    2029                 :            :                 /*
    2030                 :            :                  * A "1" is shifted out to the EEPROM by setting bit "DI" to a
    2031                 :            :                  * "1", and then raising and then lowering the clock (the SK
    2032                 :            :                  * bit controls the clock input to the EEPROM).  A "0" is
    2033                 :            :                  * shifted out to the EEPROM by setting "DI" to "0" and then
    2034                 :            :                  * raising and then lowering the clock.
    2035                 :            :                  */
    2036         [ #  # ]:          0 :                 if (data & mask)
    2037                 :          0 :                         eec |= IXGBE_EEC_DI;
    2038                 :            :                 else
    2039                 :          0 :                         eec &= ~IXGBE_EEC_DI;
    2040                 :            : 
    2041                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    2042                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    2043                 :            : 
    2044                 :          0 :                 usec_delay(1);
    2045                 :            : 
    2046                 :          0 :                 ixgbe_raise_eeprom_clk(hw, &eec);
    2047                 :          0 :                 ixgbe_lower_eeprom_clk(hw, &eec);
    2048                 :            : 
    2049                 :            :                 /*
    2050                 :            :                  * Shift mask to signify next bit of data to shift in to the
    2051                 :            :                  * EEPROM
    2052                 :            :                  */
    2053                 :          0 :                 mask = mask >> 1;
    2054                 :            :         };
    2055                 :            : 
    2056                 :            :         /* We leave the "DI" bit set to "0" when we leave this routine. */
    2057                 :          0 :         eec &= ~IXGBE_EEC_DI;
    2058                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    2059                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2060                 :          0 : }
    2061                 :            : 
    2062                 :            : /**
    2063                 :            :  * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
    2064                 :            :  * @hw: pointer to hardware structure
    2065                 :            :  * @count: number of bits to shift
    2066                 :            :  **/
    2067                 :          0 : STATIC u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
    2068                 :            : {
    2069                 :            :         u32 eec;
    2070                 :            :         u32 i;
    2071                 :            :         u16 data = 0;
    2072                 :            : 
    2073                 :          0 :         DEBUGFUNC("ixgbe_shift_in_eeprom_bits");
    2074                 :            : 
    2075                 :            :         /*
    2076                 :            :          * In order to read a register from the EEPROM, we need to shift
    2077                 :            :          * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
    2078                 :            :          * the clock input to the EEPROM (setting the SK bit), and then reading
    2079                 :            :          * the value of the "DO" bit.  During this "shifting in" process the
    2080                 :            :          * "DI" bit should always be clear.
    2081                 :            :          */
    2082                 :          0 :         eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    2083                 :            : 
    2084                 :          0 :         eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
    2085                 :            : 
    2086         [ #  # ]:          0 :         for (i = 0; i < count; i++) {
    2087                 :          0 :                 data = data << 1;
    2088                 :          0 :                 ixgbe_raise_eeprom_clk(hw, &eec);
    2089                 :            : 
    2090                 :          0 :                 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    2091                 :            : 
    2092                 :          0 :                 eec &= ~(IXGBE_EEC_DI);
    2093         [ #  # ]:          0 :                 if (eec & IXGBE_EEC_DO)
    2094                 :          0 :                         data |= 1;
    2095                 :            : 
    2096                 :          0 :                 ixgbe_lower_eeprom_clk(hw, &eec);
    2097                 :            :         }
    2098                 :            : 
    2099                 :          0 :         return data;
    2100                 :            : }
    2101                 :            : 
    2102                 :            : /**
    2103                 :            :  * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
    2104                 :            :  * @hw: pointer to hardware structure
    2105                 :            :  * @eec: EEC register's current value
    2106                 :            :  **/
    2107                 :          0 : STATIC void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
    2108                 :            : {
    2109                 :          0 :         DEBUGFUNC("ixgbe_raise_eeprom_clk");
    2110                 :            : 
    2111                 :            :         /*
    2112                 :            :          * Raise the clock input to the EEPROM
    2113                 :            :          * (setting the SK bit), then delay
    2114                 :            :          */
    2115                 :          0 :         *eec = *eec | IXGBE_EEC_SK;
    2116                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), *eec);
    2117                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2118                 :          0 :         usec_delay(1);
    2119                 :          0 : }
    2120                 :            : 
    2121                 :            : /**
    2122                 :            :  * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
    2123                 :            :  * @hw: pointer to hardware structure
    2124                 :            :  * @eec: EEC's current value
    2125                 :            :  **/
    2126                 :          0 : STATIC void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
    2127                 :            : {
    2128                 :          0 :         DEBUGFUNC("ixgbe_lower_eeprom_clk");
    2129                 :            : 
    2130                 :            :         /*
    2131                 :            :          * Lower the clock input to the EEPROM (clearing the SK bit), then
    2132                 :            :          * delay
    2133                 :            :          */
    2134                 :          0 :         *eec = *eec & ~IXGBE_EEC_SK;
    2135                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), *eec);
    2136                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2137                 :          0 :         usec_delay(1);
    2138                 :          0 : }
    2139                 :            : 
    2140                 :            : /**
    2141                 :            :  * ixgbe_release_eeprom - Release EEPROM, release semaphores
    2142                 :            :  * @hw: pointer to hardware structure
    2143                 :            :  **/
    2144                 :          0 : STATIC void ixgbe_release_eeprom(struct ixgbe_hw *hw)
    2145                 :            : {
    2146                 :            :         u32 eec;
    2147                 :            : 
    2148                 :          0 :         DEBUGFUNC("ixgbe_release_eeprom");
    2149                 :            : 
    2150                 :          0 :         eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
    2151                 :            : 
    2152                 :            :         eec |= IXGBE_EEC_CS;  /* Pull CS high */
    2153                 :          0 :         eec &= ~IXGBE_EEC_SK; /* Lower SCK */
    2154                 :            : 
    2155                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    2156                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    2157                 :            : 
    2158                 :          0 :         usec_delay(1);
    2159                 :            : 
    2160                 :            :         /* Stop requesting EEPROM access */
    2161                 :          0 :         eec &= ~IXGBE_EEC_REQ;
    2162                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
    2163                 :            : 
    2164                 :          0 :         hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
    2165                 :            : 
    2166                 :            :         /* Delay before attempt to obtain semaphore again to allow FW access */
    2167                 :          0 :         msec_delay(hw->eeprom.semaphore_delay);
    2168                 :          0 : }
    2169                 :            : 
    2170                 :            : /**
    2171                 :            :  * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
    2172                 :            :  * @hw: pointer to hardware structure
    2173                 :            :  *
    2174                 :            :  * Returns a negative error code on error, or the 16-bit checksum
    2175                 :            :  **/
    2176                 :          0 : s32 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
    2177                 :            : {
    2178                 :            :         u16 i;
    2179                 :            :         u16 j;
    2180                 :            :         u16 checksum = 0;
    2181                 :          0 :         u16 length = 0;
    2182                 :          0 :         u16 pointer = 0;
    2183                 :          0 :         u16 word = 0;
    2184                 :            : 
    2185                 :          0 :         DEBUGFUNC("ixgbe_calc_eeprom_checksum_generic");
    2186                 :            : 
    2187                 :            :         /* Include 0x0-0x3F in the checksum */
    2188         [ #  # ]:          0 :         for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
    2189         [ #  # ]:          0 :                 if (hw->eeprom.ops.read(hw, i, &word)) {
    2190                 :          0 :                         DEBUGOUT("EEPROM read failed\n");
    2191                 :          0 :                         return IXGBE_ERR_EEPROM;
    2192                 :            :                 }
    2193                 :          0 :                 checksum += word;
    2194                 :            :         }
    2195                 :            : 
    2196                 :            :         /* Include all data from pointers except for the fw pointer */
    2197         [ #  # ]:          0 :         for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
    2198         [ #  # ]:          0 :                 if (hw->eeprom.ops.read(hw, i, &pointer)) {
    2199                 :          0 :                         DEBUGOUT("EEPROM read failed\n");
    2200                 :          0 :                         return IXGBE_ERR_EEPROM;
    2201                 :            :                 }
    2202                 :            : 
    2203                 :            :                 /* If the pointer seems invalid */
    2204         [ #  # ]:          0 :                 if (pointer == 0xFFFF || pointer == 0)
    2205                 :          0 :                         continue;
    2206                 :            : 
    2207         [ #  # ]:          0 :                 if (hw->eeprom.ops.read(hw, pointer, &length)) {
    2208                 :          0 :                         DEBUGOUT("EEPROM read failed\n");
    2209                 :          0 :                         return IXGBE_ERR_EEPROM;
    2210                 :            :                 }
    2211                 :            : 
    2212         [ #  # ]:          0 :                 if (length == 0xFFFF || length == 0)
    2213                 :          0 :                         continue;
    2214                 :            : 
    2215         [ #  # ]:          0 :                 for (j = pointer + 1; j <= pointer + length; j++) {
    2216         [ #  # ]:          0 :                         if (hw->eeprom.ops.read(hw, j, &word)) {
    2217                 :          0 :                                 DEBUGOUT("EEPROM read failed\n");
    2218                 :          0 :                                 return IXGBE_ERR_EEPROM;
    2219                 :            :                         }
    2220                 :          0 :                         checksum += word;
    2221                 :            :                 }
    2222                 :            :         }
    2223                 :            : 
    2224                 :          0 :         checksum = (u16)IXGBE_EEPROM_SUM - checksum;
    2225                 :            : 
    2226                 :          0 :         return (s32)checksum;
    2227                 :            : }
    2228                 :            : 
    2229                 :            : /**
    2230                 :            :  * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
    2231                 :            :  * @hw: pointer to hardware structure
    2232                 :            :  * @checksum_val: calculated checksum
    2233                 :            :  *
    2234                 :            :  * Performs checksum calculation and validates the EEPROM checksum.  If the
    2235                 :            :  * caller does not need checksum_val, the value can be NULL.
    2236                 :            :  **/
    2237                 :          0 : s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
    2238                 :            :                                            u16 *checksum_val)
    2239                 :            : {
    2240                 :            :         s32 status;
    2241                 :            :         u16 checksum;
    2242                 :          0 :         u16 read_checksum = 0;
    2243                 :            : 
    2244                 :          0 :         DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");
    2245                 :            : 
    2246                 :            :         /* Read the first word from the EEPROM. If this times out or fails, do
    2247                 :            :          * not continue or we could be in for a very long wait while every
    2248                 :            :          * EEPROM read fails
    2249                 :            :          */
    2250                 :          0 :         status = hw->eeprom.ops.read(hw, 0, &checksum);
    2251         [ #  # ]:          0 :         if (status) {
    2252                 :          0 :                 DEBUGOUT("EEPROM read failed\n");
    2253                 :          0 :                 return status;
    2254                 :            :         }
    2255                 :            : 
    2256                 :          0 :         status = hw->eeprom.ops.calc_checksum(hw);
    2257         [ #  # ]:          0 :         if (status < 0)
    2258                 :            :                 return status;
    2259                 :            : 
    2260                 :          0 :         checksum = (u16)(status & 0xffff);
    2261                 :            : 
    2262                 :          0 :         status = hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
    2263         [ #  # ]:          0 :         if (status) {
    2264                 :          0 :                 DEBUGOUT("EEPROM read failed\n");
    2265                 :          0 :                 return status;
    2266                 :            :         }
    2267                 :            : 
    2268                 :            :         /* Verify read checksum from EEPROM is the same as
    2269                 :            :          * calculated checksum
    2270                 :            :          */
    2271         [ #  # ]:          0 :         if (read_checksum != checksum)
    2272                 :            :                 status = IXGBE_ERR_EEPROM_CHECKSUM;
    2273                 :            : 
    2274                 :            :         /* If the user cares, return the calculated checksum */
    2275         [ #  # ]:          0 :         if (checksum_val)
    2276                 :          0 :                 *checksum_val = checksum;
    2277                 :            : 
    2278                 :            :         return status;
    2279                 :            : }
    2280                 :            : 
    2281                 :            : /**
    2282                 :            :  * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
    2283                 :            :  * @hw: pointer to hardware structure
    2284                 :            :  **/
    2285                 :          0 : s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
    2286                 :            : {
    2287                 :            :         s32 status;
    2288                 :            :         u16 checksum;
    2289                 :            : 
    2290                 :          0 :         DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");
    2291                 :            : 
    2292                 :            :         /* Read the first word from the EEPROM. If this times out or fails, do
    2293                 :            :          * not continue or we could be in for a very long wait while every
    2294                 :            :          * EEPROM read fails
    2295                 :            :          */
    2296                 :          0 :         status = hw->eeprom.ops.read(hw, 0, &checksum);
    2297         [ #  # ]:          0 :         if (status) {
    2298                 :          0 :                 DEBUGOUT("EEPROM read failed\n");
    2299                 :          0 :                 return status;
    2300                 :            :         }
    2301                 :            : 
    2302                 :          0 :         status = hw->eeprom.ops.calc_checksum(hw);
    2303         [ #  # ]:          0 :         if (status < 0)
    2304                 :            :                 return status;
    2305                 :            : 
    2306                 :          0 :         checksum = (u16)(status & 0xffff);
    2307                 :            : 
    2308                 :          0 :         status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, checksum);
    2309                 :            : 
    2310                 :          0 :         return status;
    2311                 :            : }
    2312                 :            : 
    2313                 :            : /**
    2314                 :            :  * ixgbe_validate_mac_addr - Validate MAC address
    2315                 :            :  * @mac_addr: pointer to MAC address.
    2316                 :            :  *
    2317                 :            :  * Tests a MAC address to ensure it is a valid Individual Address.
    2318                 :            :  **/
    2319                 :          0 : s32 ixgbe_validate_mac_addr(u8 *mac_addr)
    2320                 :            : {
    2321                 :            :         s32 status = IXGBE_SUCCESS;
    2322                 :            : 
    2323                 :          0 :         DEBUGFUNC("ixgbe_validate_mac_addr");
    2324                 :            : 
    2325                 :            :         /* Make sure it is not a multicast address */
    2326         [ #  # ]:          0 :         if (IXGBE_IS_MULTICAST(mac_addr)) {
    2327                 :            :                 status = IXGBE_ERR_INVALID_MAC_ADDR;
    2328                 :            :         /* Not a broadcast address */
    2329                 :            :         } else if (IXGBE_IS_BROADCAST(mac_addr)) {
    2330                 :            :                 status = IXGBE_ERR_INVALID_MAC_ADDR;
    2331                 :            :         /* Reject the zero address */
    2332   [ #  #  #  #  :          0 :         } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
                   #  # ]
    2333   [ #  #  #  #  :          0 :                    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
                   #  # ]
    2334                 :            :                 status = IXGBE_ERR_INVALID_MAC_ADDR;
    2335                 :            :         }
    2336                 :          0 :         return status;
    2337                 :            : }
    2338                 :            : 
    2339                 :            : /**
    2340                 :            :  * ixgbe_set_rar_generic - Set Rx address register
    2341                 :            :  * @hw: pointer to hardware structure
    2342                 :            :  * @index: Receive address register to write
    2343                 :            :  * @addr: Address to put into receive address register
    2344                 :            :  * @vmdq: VMDq "set" or "pool" index
    2345                 :            :  * @enable_addr: set flag that address is active
    2346                 :            :  *
    2347                 :            :  * Puts an ethernet address into a receive address register.
    2348                 :            :  **/
    2349                 :          0 : s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
    2350                 :            :                           u32 enable_addr)
    2351                 :            : {
    2352                 :            :         u32 rar_low, rar_high;
    2353                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    2354                 :            : 
    2355                 :          0 :         DEBUGFUNC("ixgbe_set_rar_generic");
    2356                 :            : 
    2357                 :            :         /* Make sure we are using a valid rar index range */
    2358         [ #  # ]:          0 :         if (index >= rar_entries) {
    2359                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
    2360                 :            :                              "RAR index %d is out of range.\n", index);
    2361                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
    2362                 :            :         }
    2363                 :            : 
    2364                 :            :         /* setup VMDq pool selection before this RAR gets enabled */
    2365                 :          0 :         hw->mac.ops.set_vmdq(hw, index, vmdq);
    2366                 :            : 
    2367                 :            :         /*
    2368                 :            :          * HW expects these in little endian so we reverse the byte
    2369                 :            :          * order from network order (big endian) to little endian
    2370                 :            :          */
    2371                 :          0 :         rar_low = ((u32)addr[0] |
    2372                 :          0 :                    ((u32)addr[1] << 8) |
    2373                 :          0 :                    ((u32)addr[2] << 16) |
    2374                 :          0 :                    ((u32)addr[3] << 24));
    2375                 :            :         /*
    2376                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
    2377                 :            :          * so save everything except the lower 16 bits that hold part
    2378                 :            :          * of the address and the address valid bit.
    2379                 :            :          */
    2380         [ #  # ]:          0 :         rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
    2381                 :          0 :         rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
    2382                 :          0 :         rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
    2383                 :            : 
    2384         [ #  # ]:          0 :         if (enable_addr != 0)
    2385                 :          0 :                 rar_high |= IXGBE_RAH_AV;
    2386                 :            : 
    2387         [ #  # ]:          0 :         IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
    2388                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
    2389                 :            : 
    2390                 :          0 :         return IXGBE_SUCCESS;
    2391                 :            : }
    2392                 :            : 
    2393                 :            : /**
    2394                 :            :  * ixgbe_clear_rar_generic - Remove Rx address register
    2395                 :            :  * @hw: pointer to hardware structure
    2396                 :            :  * @index: Receive address register to write
    2397                 :            :  *
    2398                 :            :  * Clears an ethernet address from a receive address register.
    2399                 :            :  **/
    2400                 :          0 : s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
    2401                 :            : {
    2402                 :            :         u32 rar_high;
    2403                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    2404                 :            : 
    2405                 :          0 :         DEBUGFUNC("ixgbe_clear_rar_generic");
    2406                 :            : 
    2407                 :            :         /* Make sure we are using a valid rar index range */
    2408         [ #  # ]:          0 :         if (index >= rar_entries) {
    2409                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
    2410                 :            :                              "RAR index %d is out of range.\n", index);
    2411                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
    2412                 :            :         }
    2413                 :            : 
    2414                 :            :         /*
    2415                 :            :          * Some parts put the VMDq setting in the extra RAH bits,
    2416                 :            :          * so save everything except the lower 16 bits that hold part
    2417                 :            :          * of the address and the address valid bit.
    2418                 :            :          */
    2419         [ #  # ]:          0 :         rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
    2420                 :          0 :         rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
    2421                 :            : 
    2422         [ #  # ]:          0 :         IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
    2423                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
    2424                 :            : 
    2425                 :            :         /* clear VMDq pool/queue selection for this RAR */
    2426                 :          0 :         hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
    2427                 :            : 
    2428                 :          0 :         return IXGBE_SUCCESS;
    2429                 :            : }
    2430                 :            : 
    2431                 :            : /**
    2432                 :            :  * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
    2433                 :            :  * @hw: pointer to hardware structure
    2434                 :            :  *
    2435                 :            :  * Places the MAC address in receive address register 0 and clears the rest
    2436                 :            :  * of the receive address registers. Clears the multicast table. Assumes
    2437                 :            :  * the receiver is in reset when the routine is called.
    2438                 :            :  **/
    2439                 :          0 : s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
    2440                 :            : {
    2441                 :            :         u32 i;
    2442                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    2443                 :            : 
    2444                 :          0 :         DEBUGFUNC("ixgbe_init_rx_addrs_generic");
    2445                 :            : 
    2446                 :            :         /*
    2447                 :            :          * If the current mac address is valid, assume it is a software override
    2448                 :            :          * to the permanent address.
    2449                 :            :          * Otherwise, use the permanent address from the eeprom.
    2450                 :            :          */
    2451         [ #  # ]:          0 :         if (ixgbe_validate_mac_addr(hw->mac.addr) ==
    2452                 :            :             IXGBE_ERR_INVALID_MAC_ADDR) {
    2453                 :            :                 /* Get the MAC address from the RAR0 for later reference */
    2454                 :          0 :                 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
    2455                 :            : 
    2456                 :          0 :                 DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
    2457                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
    2458                 :            :                           hw->mac.addr[2]);
    2459                 :          0 :                 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
    2460                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
    2461                 :            :         } else {
    2462                 :            :                 /* Setup the receive address. */
    2463                 :          0 :                 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
    2464                 :          0 :                 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
    2465                 :            :                           hw->mac.addr[0], hw->mac.addr[1],
    2466                 :            :                           hw->mac.addr[2]);
    2467                 :          0 :                 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
    2468                 :            :                           hw->mac.addr[4], hw->mac.addr[5]);
    2469                 :            : 
    2470                 :          0 :                 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
    2471                 :            :         }
    2472                 :            : 
    2473                 :            :         /* clear VMDq pool/queue selection for RAR 0 */
    2474                 :          0 :         hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
    2475                 :            : 
    2476                 :          0 :         hw->addr_ctrl.overflow_promisc = 0;
    2477                 :            : 
    2478                 :          0 :         hw->addr_ctrl.rar_used_count = 1;
    2479                 :            : 
    2480                 :            :         /* Zero out the other receive addresses. */
    2481                 :          0 :         DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1);
    2482         [ #  # ]:          0 :         for (i = 1; i < rar_entries; i++) {
    2483         [ #  # ]:          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
    2484         [ #  # ]:          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
    2485                 :            :         }
    2486                 :            : 
    2487                 :            :         /* Clear the MTA */
    2488                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
    2489                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
    2490                 :            : 
    2491                 :          0 :         DEBUGOUT(" Clearing MTA\n");
    2492         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
    2493                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
    2494                 :            : 
    2495                 :          0 :         ixgbe_init_uta_tables(hw);
    2496                 :            : 
    2497                 :          0 :         return IXGBE_SUCCESS;
    2498                 :            : }
    2499                 :            : 
    2500                 :            : /**
    2501                 :            :  * ixgbe_add_uc_addr - Adds a secondary unicast address.
    2502                 :            :  * @hw: pointer to hardware structure
    2503                 :            :  * @addr: new address
    2504                 :            :  * @vmdq: VMDq "set" or "pool" index
    2505                 :            :  *
    2506                 :            :  * Adds it to unused receive address register or goes into promiscuous mode.
    2507                 :            :  **/
    2508                 :          0 : void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
    2509                 :            : {
    2510                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    2511                 :            :         u32 rar;
    2512                 :            : 
    2513                 :          0 :         DEBUGFUNC("ixgbe_add_uc_addr");
    2514                 :            : 
    2515                 :          0 :         DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
    2516                 :            :                   addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
    2517                 :            : 
    2518                 :            :         /*
    2519                 :            :          * Place this address in the RAR if there is room,
    2520                 :            :          * else put the controller into promiscuous mode
    2521                 :            :          */
    2522         [ #  # ]:          0 :         if (hw->addr_ctrl.rar_used_count < rar_entries) {
    2523                 :            :                 rar = hw->addr_ctrl.rar_used_count;
    2524                 :          0 :                 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
    2525                 :          0 :                 DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar);
    2526                 :          0 :                 hw->addr_ctrl.rar_used_count++;
    2527                 :            :         } else {
    2528                 :          0 :                 hw->addr_ctrl.overflow_promisc++;
    2529                 :            :         }
    2530                 :            : 
    2531                 :          0 :         DEBUGOUT("ixgbe_add_uc_addr Complete\n");
    2532                 :          0 : }
    2533                 :            : 
    2534                 :            : /**
    2535                 :            :  * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
    2536                 :            :  * @hw: pointer to hardware structure
    2537                 :            :  * @addr_list: the list of new addresses
    2538                 :            :  * @addr_count: number of addresses
    2539                 :            :  * @next: iterator function to walk the address list
    2540                 :            :  *
    2541                 :            :  * The given list replaces any existing list.  Clears the secondary addrs from
    2542                 :            :  * receive address registers.  Uses unused receive address registers for the
    2543                 :            :  * first secondary addresses, and falls back to promiscuous mode as needed.
    2544                 :            :  *
    2545                 :            :  * Drivers using secondary unicast addresses must set user_set_promisc when
    2546                 :            :  * manually putting the device into promiscuous mode.
    2547                 :            :  **/
    2548                 :          0 : s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
    2549                 :            :                                       u32 addr_count, ixgbe_mc_addr_itr next)
    2550                 :            : {
    2551                 :            :         u8 *addr;
    2552                 :            :         u32 i;
    2553                 :          0 :         u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
    2554                 :            :         u32 uc_addr_in_use;
    2555                 :            :         u32 fctrl;
    2556                 :            :         u32 vmdq;
    2557                 :            : 
    2558                 :          0 :         DEBUGFUNC("ixgbe_update_uc_addr_list_generic");
    2559                 :            : 
    2560                 :            :         /*
    2561                 :            :          * Clear accounting of old secondary address list,
    2562                 :            :          * don't count RAR[0]
    2563                 :            :          */
    2564                 :          0 :         uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
    2565                 :          0 :         hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
    2566                 :          0 :         hw->addr_ctrl.overflow_promisc = 0;
    2567                 :            : 
    2568                 :            :         /* Zero out the other receive addresses */
    2569                 :          0 :         DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use+1);
    2570         [ #  # ]:          0 :         for (i = 0; i < uc_addr_in_use; i++) {
    2571         [ #  # ]:          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
    2572         [ #  # ]:          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
    2573                 :            :         }
    2574                 :            : 
    2575                 :            :         /* Add the new addresses */
    2576         [ #  # ]:          0 :         for (i = 0; i < addr_count; i++) {
    2577                 :          0 :                 DEBUGOUT(" Adding the secondary addresses:\n");
    2578                 :          0 :                 addr = next(hw, &addr_list, &vmdq);
    2579                 :          0 :                 ixgbe_add_uc_addr(hw, addr, vmdq);
    2580                 :            :         }
    2581                 :            : 
    2582         [ #  # ]:          0 :         if (hw->addr_ctrl.overflow_promisc) {
    2583                 :            :                 /* enable promisc if not already in overflow or set by user */
    2584   [ #  #  #  # ]:          0 :                 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
    2585                 :          0 :                         DEBUGOUT(" Entering address overflow promisc mode\n");
    2586                 :          0 :                         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    2587                 :          0 :                         fctrl |= IXGBE_FCTRL_UPE;
    2588                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    2589                 :            :                 }
    2590                 :            :         } else {
    2591                 :            :                 /* only disable if set by overflow, not by user */
    2592   [ #  #  #  # ]:          0 :                 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
    2593                 :          0 :                         DEBUGOUT(" Leaving address overflow promisc mode\n");
    2594                 :          0 :                         fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
    2595                 :          0 :                         fctrl &= ~IXGBE_FCTRL_UPE;
    2596                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
    2597                 :            :                 }
    2598                 :            :         }
    2599                 :            : 
    2600                 :          0 :         DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n");
    2601                 :          0 :         return IXGBE_SUCCESS;
    2602                 :            : }
    2603                 :            : 
    2604                 :            : /**
    2605                 :            :  * ixgbe_mta_vector - Determines bit-vector in multicast table to set
    2606                 :            :  * @hw: pointer to hardware structure
    2607                 :            :  * @mc_addr: the multicast address
    2608                 :            :  *
    2609                 :            :  * Extracts the 12 bits, from a multicast address, to determine which
    2610                 :            :  * bit-vector to set in the multicast table. The hardware uses 12 bits, from
    2611                 :            :  * incoming rx multicast addresses, to determine the bit-vector to check in
    2612                 :            :  * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
    2613                 :            :  * by the MO field of the MCSTCTRL. The MO field is set during initialization
    2614                 :            :  * to mc_filter_type.
    2615                 :            :  **/
    2616                 :          0 : STATIC s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
    2617                 :            : {
    2618                 :            :         u32 vector = 0;
    2619                 :            : 
    2620                 :          0 :         DEBUGFUNC("ixgbe_mta_vector");
    2621                 :            : 
    2622   [ #  #  #  #  :          0 :         switch (hw->mac.mc_filter_type) {
                      # ]
    2623                 :          0 :         case 0:   /* use bits [47:36] of the address */
    2624                 :          0 :                 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
    2625                 :          0 :                 break;
    2626                 :          0 :         case 1:   /* use bits [46:35] of the address */
    2627                 :          0 :                 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
    2628                 :          0 :                 break;
    2629                 :          0 :         case 2:   /* use bits [45:34] of the address */
    2630                 :          0 :                 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
    2631                 :          0 :                 break;
    2632                 :          0 :         case 3:   /* use bits [43:32] of the address */
    2633                 :          0 :                 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
    2634                 :          0 :                 break;
    2635                 :          0 :         default:  /* Invalid mc_filter_type */
    2636                 :          0 :                 DEBUGOUT("MC filter type param set incorrectly\n");
    2637                 :          0 :                 ASSERT(0);
    2638                 :            :                 break;
    2639                 :            :         }
    2640                 :            : 
    2641                 :            :         /* vector can only be 12-bits or boundary will be exceeded */
    2642                 :          0 :         vector &= 0xFFF;
    2643                 :          0 :         return vector;
    2644                 :            : }
    2645                 :            : 
    2646                 :            : /**
    2647                 :            :  * ixgbe_set_mta - Set bit-vector in multicast table
    2648                 :            :  * @hw: pointer to hardware structure
    2649                 :            :  * @mc_addr: Multicast address
    2650                 :            :  *
    2651                 :            :  * Sets the bit-vector in the multicast table.
    2652                 :            :  **/
    2653                 :          0 : void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
    2654                 :            : {
    2655                 :            :         u32 vector;
    2656                 :            :         u32 vector_bit;
    2657                 :            :         u32 vector_reg;
    2658                 :            : 
    2659                 :          0 :         DEBUGFUNC("ixgbe_set_mta");
    2660                 :            : 
    2661                 :          0 :         hw->addr_ctrl.mta_in_use++;
    2662                 :            : 
    2663                 :          0 :         vector = ixgbe_mta_vector(hw, mc_addr);
    2664                 :          0 :         DEBUGOUT1(" bit-vector = 0x%03X\n", vector);
    2665                 :            : 
    2666                 :            :         /*
    2667                 :            :          * The MTA is a register array of 128 32-bit registers. It is treated
    2668                 :            :          * like an array of 4096 bits.  We want to set bit
    2669                 :            :          * BitArray[vector_value]. So we figure out what register the bit is
    2670                 :            :          * in, read it, OR in the new bit, then write back the new value.  The
    2671                 :            :          * register is determined by the upper 7 bits of the vector value and
    2672                 :            :          * the bit within that register are determined by the lower 5 bits of
    2673                 :            :          * the value.
    2674                 :            :          */
    2675                 :          0 :         vector_reg = (vector >> 5) & 0x7F;
    2676                 :          0 :         vector_bit = vector & 0x1F;
    2677                 :          0 :         hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
    2678                 :          0 : }
    2679                 :            : 
    2680                 :            : /**
    2681                 :            :  * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
    2682                 :            :  * @hw: pointer to hardware structure
    2683                 :            :  * @mc_addr_list: the list of new multicast addresses
    2684                 :            :  * @mc_addr_count: number of addresses
    2685                 :            :  * @next: iterator function to walk the multicast address list
    2686                 :            :  * @clear: flag, when set clears the table beforehand
    2687                 :            :  *
    2688                 :            :  * When the clear flag is set, the given list replaces any existing list.
    2689                 :            :  * Hashes the given addresses into the multicast table.
    2690                 :            :  **/
    2691                 :          0 : s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
    2692                 :            :                                       u32 mc_addr_count, ixgbe_mc_addr_itr next,
    2693                 :            :                                       bool clear)
    2694                 :            : {
    2695                 :            :         u32 i;
    2696                 :            :         u32 vmdq;
    2697                 :            : 
    2698                 :          0 :         DEBUGFUNC("ixgbe_update_mc_addr_list_generic");
    2699                 :            : 
    2700                 :            :         /*
    2701                 :            :          * Set the new number of MC addresses that we are being requested to
    2702                 :            :          * use.
    2703                 :            :          */
    2704                 :          0 :         hw->addr_ctrl.num_mc_addrs = mc_addr_count;
    2705                 :          0 :         hw->addr_ctrl.mta_in_use = 0;
    2706                 :            : 
    2707                 :            :         /* Clear mta_shadow */
    2708         [ #  # ]:          0 :         if (clear) {
    2709                 :          0 :                 DEBUGOUT(" Clearing MTA\n");
    2710                 :          0 :                 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
    2711                 :            :         }
    2712                 :            : 
    2713                 :            :         /* Update mta_shadow */
    2714         [ #  # ]:          0 :         for (i = 0; i < mc_addr_count; i++) {
    2715                 :          0 :                 DEBUGOUT(" Adding the multicast addresses:\n");
    2716                 :          0 :                 ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
    2717                 :            :         }
    2718                 :            : 
    2719                 :            :         /* Enable mta */
    2720         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mcft_size; i++)
    2721                 :          0 :                 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
    2722                 :            :                                       hw->mac.mta_shadow[i]);
    2723                 :            : 
    2724         [ #  # ]:          0 :         if (hw->addr_ctrl.mta_in_use > 0)
    2725                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
    2726                 :            :                                 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
    2727                 :            : 
    2728                 :          0 :         DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n");
    2729                 :          0 :         return IXGBE_SUCCESS;
    2730                 :            : }
    2731                 :            : 
    2732                 :            : /**
    2733                 :            :  * ixgbe_enable_mc_generic - Enable multicast address in RAR
    2734                 :            :  * @hw: pointer to hardware structure
    2735                 :            :  *
    2736                 :            :  * Enables multicast address in RAR and the use of the multicast hash table.
    2737                 :            :  **/
    2738                 :          0 : s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
    2739                 :            : {
    2740                 :            :         struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
    2741                 :            : 
    2742                 :          0 :         DEBUGFUNC("ixgbe_enable_mc_generic");
    2743                 :            : 
    2744         [ #  # ]:          0 :         if (a->mta_in_use > 0)
    2745                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
    2746                 :            :                                 hw->mac.mc_filter_type);
    2747                 :            : 
    2748                 :          0 :         return IXGBE_SUCCESS;
    2749                 :            : }
    2750                 :            : 
    2751                 :            : /**
    2752                 :            :  * ixgbe_disable_mc_generic - Disable multicast address in RAR
    2753                 :            :  * @hw: pointer to hardware structure
    2754                 :            :  *
    2755                 :            :  * Disables multicast address in RAR and the use of the multicast hash table.
    2756                 :            :  **/
    2757                 :          0 : s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
    2758                 :            : {
    2759                 :            :         struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
    2760                 :            : 
    2761                 :          0 :         DEBUGFUNC("ixgbe_disable_mc_generic");
    2762                 :            : 
    2763         [ #  # ]:          0 :         if (a->mta_in_use > 0)
    2764                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
    2765                 :            : 
    2766                 :          0 :         return IXGBE_SUCCESS;
    2767                 :            : }
    2768                 :            : 
    2769                 :            : /**
    2770                 :            :  * ixgbe_fc_enable_generic - Enable flow control
    2771                 :            :  * @hw: pointer to hardware structure
    2772                 :            :  *
    2773                 :            :  * Enable flow control according to the current settings.
    2774                 :            :  **/
    2775                 :          0 : s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
    2776                 :            : {
    2777                 :            :         s32 ret_val = IXGBE_SUCCESS;
    2778                 :            :         u32 mflcn_reg, fccfg_reg;
    2779                 :            :         u32 reg;
    2780                 :            :         u32 fcrtl, fcrth;
    2781                 :            :         int i;
    2782                 :            : 
    2783                 :          0 :         DEBUGFUNC("ixgbe_fc_enable_generic");
    2784                 :            : 
    2785                 :            :         /* Validate the water mark configuration */
    2786         [ #  # ]:          0 :         if (!hw->fc.pause_time) {
    2787                 :            :                 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
    2788                 :          0 :                 goto out;
    2789                 :            :         }
    2790                 :            : 
    2791                 :            :         /* Low water mark of zero causes XOFF floods */
    2792         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
    2793         [ #  # ]:          0 :                 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
    2794         [ #  # ]:          0 :                     hw->fc.high_water[i]) {
    2795   [ #  #  #  # ]:          0 :                         if (!hw->fc.low_water[i] ||
    2796                 :            :                             hw->fc.low_water[i] >= hw->fc.high_water[i]) {
    2797                 :          0 :                                 DEBUGOUT("Invalid water mark configuration\n");
    2798                 :            :                                 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
    2799                 :          0 :                                 goto out;
    2800                 :            :                         }
    2801                 :            :                 }
    2802                 :            :         }
    2803                 :            : 
    2804                 :            :         /* Negotiate the fc mode to use */
    2805                 :          0 :         hw->mac.ops.fc_autoneg(hw);
    2806                 :            : 
    2807                 :            :         /* Disable any previous flow control settings */
    2808                 :          0 :         mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
    2809                 :          0 :         mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
    2810                 :            : 
    2811                 :          0 :         fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
    2812                 :          0 :         fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
    2813                 :            : 
    2814                 :            :         /*
    2815                 :            :          * The possible values of fc.current_mode are:
    2816                 :            :          * 0: Flow control is completely disabled
    2817                 :            :          * 1: Rx flow control is enabled (we can receive pause frames,
    2818                 :            :          *    but not send pause frames).
    2819                 :            :          * 2: Tx flow control is enabled (we can send pause frames but
    2820                 :            :          *    we do not support receiving pause frames).
    2821                 :            :          * 3: Both Rx and Tx flow control (symmetric) are enabled.
    2822                 :            :          * other: Invalid.
    2823                 :            :          */
    2824   [ #  #  #  #  :          0 :         switch (hw->fc.current_mode) {
                      # ]
    2825                 :            :         case ixgbe_fc_none:
    2826                 :            :                 /*
    2827                 :            :                  * Flow control is disabled by software override or autoneg.
    2828                 :            :                  * The code below will actually disable it in the HW.
    2829                 :            :                  */
    2830                 :            :                 break;
    2831                 :          0 :         case ixgbe_fc_rx_pause:
    2832                 :            :                 /*
    2833                 :            :                  * Rx Flow control is enabled and Tx Flow control is
    2834                 :            :                  * disabled by software override. Since there really
    2835                 :            :                  * isn't a way to advertise that we are capable of RX
    2836                 :            :                  * Pause ONLY, we will advertise that we support both
    2837                 :            :                  * symmetric and asymmetric Rx PAUSE.  Later, we will
    2838                 :            :                  * disable the adapter's ability to send PAUSE frames.
    2839                 :            :                  */
    2840                 :          0 :                 mflcn_reg |= IXGBE_MFLCN_RFCE;
    2841                 :          0 :                 break;
    2842                 :          0 :         case ixgbe_fc_tx_pause:
    2843                 :            :                 /*
    2844                 :            :                  * Tx Flow control is enabled, and Rx Flow control is
    2845                 :            :                  * disabled by software override.
    2846                 :            :                  */
    2847                 :          0 :                 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
    2848                 :          0 :                 break;
    2849                 :          0 :         case ixgbe_fc_full:
    2850                 :            :                 /* Flow control (both Rx and Tx) is enabled by SW override. */
    2851                 :          0 :                 mflcn_reg |= IXGBE_MFLCN_RFCE;
    2852                 :          0 :                 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
    2853                 :          0 :                 break;
    2854                 :          0 :         default:
    2855                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
    2856                 :            :                              "Flow control param set incorrectly\n");
    2857                 :            :                 ret_val = IXGBE_ERR_CONFIG;
    2858                 :          0 :                 goto out;
    2859                 :            :                 break;
    2860                 :            :         }
    2861                 :            : 
    2862                 :            :         /* Set 802.3x based flow control settings. */
    2863                 :          0 :         mflcn_reg |= IXGBE_MFLCN_DPF;
    2864                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
    2865                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
    2866                 :            : 
    2867                 :            : 
    2868                 :            :         /* Set up and enable Rx high/low water mark thresholds, enable XON. */
    2869         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
    2870         [ #  # ]:          0 :                 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
    2871         [ #  # ]:          0 :                     hw->fc.high_water[i]) {
    2872                 :          0 :                         fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
    2873                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
    2874                 :          0 :                         fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
    2875                 :            :                 } else {
    2876                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
    2877                 :            :                         /*
    2878                 :            :                          * In order to prevent Tx hangs when the internal Tx
    2879                 :            :                          * switch is enabled we must set the high water mark
    2880                 :            :                          * to the Rx packet buffer size - 24KB.  This allows
    2881                 :            :                          * the Tx switch to function even under heavy Rx
    2882                 :            :                          * workloads.
    2883                 :            :                          */
    2884                 :          0 :                         fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 24576;
    2885                 :            :                 }
    2886                 :            : 
    2887                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
    2888                 :            :         }
    2889                 :            : 
    2890                 :            :         /* Configure pause time (2 TCs per register) */
    2891                 :          0 :         reg = hw->fc.pause_time * 0x00010001;
    2892         [ #  # ]:          0 :         for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
    2893                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
    2894                 :            : 
    2895                 :            :         /* Configure flow control refresh threshold value */
    2896                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
    2897                 :            : 
    2898                 :          0 : out:
    2899                 :          0 :         return ret_val;
    2900                 :            : }
    2901                 :            : 
    2902                 :            : /**
    2903                 :            :  * ixgbe_negotiate_fc - Negotiate flow control
    2904                 :            :  * @hw: pointer to hardware structure
    2905                 :            :  * @adv_reg: flow control advertised settings
    2906                 :            :  * @lp_reg: link partner's flow control settings
    2907                 :            :  * @adv_sym: symmetric pause bit in advertisement
    2908                 :            :  * @adv_asm: asymmetric pause bit in advertisement
    2909                 :            :  * @lp_sym: symmetric pause bit in link partner advertisement
    2910                 :            :  * @lp_asm: asymmetric pause bit in link partner advertisement
    2911                 :            :  *
    2912                 :            :  * Find the intersection between advertised settings and link partner's
    2913                 :            :  * advertised settings
    2914                 :            :  **/
    2915                 :          0 : s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
    2916                 :            :                        u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
    2917                 :            : {
    2918         [ #  # ]:          0 :         if ((!(adv_reg)) ||  (!(lp_reg))) {
    2919                 :          0 :                 ERROR_REPORT3(IXGBE_ERROR_UNSUPPORTED,
    2920                 :            :                              "Local or link partner's advertised flow control "
    2921                 :            :                              "settings are NULL. Local: %x, link partner: %x\n",
    2922                 :            :                              adv_reg, lp_reg);
    2923                 :          0 :                 return IXGBE_ERR_FC_NOT_NEGOTIATED;
    2924                 :            :         }
    2925                 :            : 
    2926   [ #  #  #  # ]:          0 :         if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
    2927                 :            :                 /*
    2928                 :            :                  * Now we need to check if the user selected Rx ONLY
    2929                 :            :                  * of pause frames.  In this case, we had to advertise
    2930                 :            :                  * FULL flow control because we could not advertise RX
    2931                 :            :                  * ONLY. Hence, we must now check to see if we need to
    2932                 :            :                  * turn OFF the TRANSMISSION of PAUSE frames.
    2933                 :            :                  */
    2934         [ #  # ]:          0 :                 if (hw->fc.requested_mode == ixgbe_fc_full) {
    2935                 :          0 :                         hw->fc.current_mode = ixgbe_fc_full;
    2936                 :          0 :                         DEBUGOUT("Flow Control = FULL.\n");
    2937                 :            :                 } else {
    2938                 :          0 :                         hw->fc.current_mode = ixgbe_fc_rx_pause;
    2939                 :          0 :                         DEBUGOUT("Flow Control=RX PAUSE frames only\n");
    2940                 :            :                 }
    2941   [ #  #  #  # ]:          0 :         } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
    2942   [ #  #  #  # ]:          0 :                    (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
    2943                 :          0 :                 hw->fc.current_mode = ixgbe_fc_tx_pause;
    2944                 :          0 :                 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
    2945   [ #  #  #  # ]:          0 :         } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
    2946   [ #  #  #  # ]:          0 :                    !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
    2947                 :          0 :                 hw->fc.current_mode = ixgbe_fc_rx_pause;
    2948                 :          0 :                 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
    2949                 :            :         } else {
    2950                 :          0 :                 hw->fc.current_mode = ixgbe_fc_none;
    2951                 :          0 :                 DEBUGOUT("Flow Control = NONE.\n");
    2952                 :            :         }
    2953                 :            :         return IXGBE_SUCCESS;
    2954                 :            : }
    2955                 :            : 
    2956                 :            : /**
    2957                 :            :  * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
    2958                 :            :  * @hw: pointer to hardware structure
    2959                 :            :  *
    2960                 :            :  * Enable flow control according on 1 gig fiber.
    2961                 :            :  **/
    2962                 :          0 : STATIC s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
    2963                 :            : {
    2964                 :            :         u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
    2965                 :            :         s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
    2966                 :            : 
    2967                 :            :         /*
    2968                 :            :          * On multispeed fiber at 1g, bail out if
    2969                 :            :          * - link is up but AN did not complete, or if
    2970                 :            :          * - link is up and AN completed but timed out
    2971                 :            :          */
    2972                 :            : 
    2973                 :          0 :         linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
    2974         [ #  # ]:          0 :         if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
    2975         [ #  # ]:          0 :             (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
    2976                 :          0 :                 DEBUGOUT("Auto-Negotiation did not complete or timed out\n");
    2977                 :          0 :                 goto out;
    2978                 :            :         }
    2979                 :            : 
    2980                 :          0 :         pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
    2981                 :          0 :         pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
    2982                 :            : 
    2983                 :          0 :         ret_val =  ixgbe_negotiate_fc(hw, pcs_anadv_reg,
    2984                 :            :                                       pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
    2985                 :            :                                       IXGBE_PCS1GANA_ASM_PAUSE,
    2986                 :            :                                       IXGBE_PCS1GANA_SYM_PAUSE,
    2987                 :            :                                       IXGBE_PCS1GANA_ASM_PAUSE);
    2988                 :            : 
    2989                 :          0 : out:
    2990                 :          0 :         return ret_val;
    2991                 :            : }
    2992                 :            : 
    2993                 :            : /**
    2994                 :            :  * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
    2995                 :            :  * @hw: pointer to hardware structure
    2996                 :            :  *
    2997                 :            :  * Enable flow control according to IEEE clause 37.
    2998                 :            :  **/
    2999                 :          0 : STATIC s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
    3000                 :            : {
    3001                 :            :         u32 links2, anlp1_reg, autoc_reg, links;
    3002                 :            :         s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
    3003                 :            : 
    3004                 :            :         /*
    3005                 :            :          * On backplane, bail out if
    3006                 :            :          * - backplane autoneg was not completed, or if
    3007                 :            :          * - we are 82599 and link partner is not AN enabled
    3008                 :            :          */
    3009                 :          0 :         links = IXGBE_READ_REG(hw, IXGBE_LINKS);
    3010         [ #  # ]:          0 :         if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
    3011                 :          0 :                 DEBUGOUT("Auto-Negotiation did not complete\n");
    3012                 :          0 :                 goto out;
    3013                 :            :         }
    3014                 :            : 
    3015         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82599EB) {
    3016                 :          0 :                 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
    3017         [ #  # ]:          0 :                 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
    3018                 :          0 :                         DEBUGOUT("Link partner is not AN enabled\n");
    3019                 :          0 :                         goto out;
    3020                 :            :                 }
    3021                 :            :         }
    3022                 :            :         /*
    3023                 :            :          * Read the 10g AN autoc and LP ability registers and resolve
    3024                 :            :          * local flow control settings accordingly
    3025                 :            :          */
    3026                 :          0 :         autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
    3027                 :          0 :         anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
    3028                 :            : 
    3029                 :          0 :         ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
    3030                 :            :                 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
    3031                 :            :                 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
    3032                 :            : 
    3033                 :          0 : out:
    3034                 :          0 :         return ret_val;
    3035                 :            : }
    3036                 :            : 
    3037                 :            : /**
    3038                 :            :  * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
    3039                 :            :  * @hw: pointer to hardware structure
    3040                 :            :  *
    3041                 :            :  * Enable flow control according to IEEE clause 37.
    3042                 :            :  **/
    3043                 :          0 : STATIC s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
    3044                 :            : {
    3045                 :          0 :         u16 technology_ability_reg = 0;
    3046                 :          0 :         u16 lp_technology_ability_reg = 0;
    3047                 :            : 
    3048                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
    3049                 :            :                              IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    3050                 :            :                              &technology_ability_reg);
    3051                 :          0 :         hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_LP,
    3052                 :            :                              IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
    3053                 :            :                              &lp_technology_ability_reg);
    3054                 :            : 
    3055                 :          0 :         return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
    3056                 :            :                                   (u32)lp_technology_ability_reg,
    3057                 :            :                                   IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
    3058                 :            :                                   IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
    3059                 :            : }
    3060                 :            : 
    3061                 :            : /**
    3062                 :            :  * ixgbe_fc_autoneg - Configure flow control
    3063                 :            :  * @hw: pointer to hardware structure
    3064                 :            :  *
    3065                 :            :  * Compares our advertised flow control capabilities to those advertised by
    3066                 :            :  * our link partner, and determines the proper flow control mode to use.
    3067                 :            :  **/
    3068                 :          0 : void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
    3069                 :            : {
    3070                 :            :         s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
    3071                 :            :         ixgbe_link_speed speed;
    3072                 :            :         bool link_up;
    3073                 :            : 
    3074                 :          0 :         DEBUGFUNC("ixgbe_fc_autoneg");
    3075                 :            : 
    3076                 :            :         /*
    3077                 :            :          * AN should have completed when the cable was plugged in.
    3078                 :            :          * Look for reasons to bail out.  Bail out if:
    3079                 :            :          * - FC autoneg is disabled, or if
    3080                 :            :          * - link is not up.
    3081                 :            :          */
    3082         [ #  # ]:          0 :         if (hw->fc.disable_fc_autoneg) {
    3083                 :            :                 /* TODO: This should be just an informative log */
    3084                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_CAUTION,
    3085                 :            :                               "Flow control autoneg is disabled");
    3086                 :          0 :                 goto out;
    3087                 :            :         }
    3088                 :            : 
    3089                 :          0 :         hw->mac.ops.check_link(hw, &speed, &link_up, false);
    3090         [ #  # ]:          0 :         if (!link_up) {
    3091                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "The link is down");
    3092                 :          0 :                 goto out;
    3093                 :            :         }
    3094                 :            : 
    3095   [ #  #  #  # ]:          0 :         switch (hw->phy.media_type) {
    3096                 :            :         /* Autoneg flow control on fiber adapters */
    3097                 :          0 :         case ixgbe_media_type_fiber_qsfp:
    3098                 :            :         case ixgbe_media_type_fiber:
    3099         [ #  # ]:          0 :                 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
    3100                 :          0 :                         ret_val = ixgbe_fc_autoneg_fiber(hw);
    3101                 :            :                 break;
    3102                 :            : 
    3103                 :            :         /* Autoneg flow control on backplane adapters */
    3104                 :          0 :         case ixgbe_media_type_backplane:
    3105                 :          0 :                 ret_val = ixgbe_fc_autoneg_backplane(hw);
    3106                 :          0 :                 break;
    3107                 :            : 
    3108                 :            :         /* Autoneg flow control on copper adapters */
    3109                 :          0 :         case ixgbe_media_type_copper:
    3110         [ #  # ]:          0 :                 if (ixgbe_device_supports_autoneg_fc(hw))
    3111                 :          0 :                         ret_val = ixgbe_fc_autoneg_copper(hw);
    3112                 :            :                 break;
    3113                 :            : 
    3114                 :            :         default:
    3115                 :            :                 break;
    3116                 :            :         }
    3117                 :            : 
    3118                 :          0 : out:
    3119         [ #  # ]:          0 :         if (ret_val == IXGBE_SUCCESS) {
    3120                 :          0 :                 hw->fc.fc_was_autonegged = true;
    3121                 :            :         } else {
    3122                 :          0 :                 hw->fc.fc_was_autonegged = false;
    3123                 :          0 :                 hw->fc.current_mode = hw->fc.requested_mode;
    3124                 :            :         }
    3125                 :          0 : }
    3126                 :            : 
    3127                 :            : /*
    3128                 :            :  * ixgbe_pcie_timeout_poll - Return number of times to poll for completion
    3129                 :            :  * @hw: pointer to hardware structure
    3130                 :            :  *
    3131                 :            :  * System-wide timeout range is encoded in PCIe Device Control2 register.
    3132                 :            :  *
    3133                 :            :  * Add 10% to specified maximum and return the number of times to poll for
    3134                 :            :  * completion timeout, in units of 100 microsec.  Never return less than
    3135                 :            :  * 800 = 80 millisec.
    3136                 :            :  */
    3137                 :            : STATIC u32 ixgbe_pcie_timeout_poll(struct ixgbe_hw *hw)
    3138                 :            : {
    3139                 :            :         s16 devctl2;
    3140                 :            :         u32 pollcnt;
    3141                 :            : 
    3142                 :            :         devctl2 = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2);
    3143                 :            :         devctl2 &= IXGBE_PCIDEVCTRL2_TIMEO_MASK;
    3144                 :            : 
    3145                 :            :         switch (devctl2) {
    3146                 :            :         case IXGBE_PCIDEVCTRL2_65_130ms:
    3147                 :            :                 pollcnt = 1300;         /* 130 millisec */
    3148                 :            :                 break;
    3149                 :            :         case IXGBE_PCIDEVCTRL2_260_520ms:
    3150                 :            :                 pollcnt = 5200;         /* 520 millisec */
    3151                 :            :                 break;
    3152                 :            :         case IXGBE_PCIDEVCTRL2_1_2s:
    3153                 :            :                 pollcnt = 20000;        /* 2 sec */
    3154                 :            :                 break;
    3155                 :            :         case IXGBE_PCIDEVCTRL2_4_8s:
    3156                 :            :                 pollcnt = 80000;        /* 8 sec */
    3157                 :            :                 break;
    3158                 :            :         case IXGBE_PCIDEVCTRL2_17_34s:
    3159                 :            :                 pollcnt = 34000;        /* 34 sec */
    3160                 :            :                 break;
    3161                 :            :         case IXGBE_PCIDEVCTRL2_50_100us:        /* 100 microsecs */
    3162                 :            :         case IXGBE_PCIDEVCTRL2_1_2ms:           /* 2 millisecs */
    3163                 :            :         case IXGBE_PCIDEVCTRL2_16_32ms:         /* 32 millisec */
    3164                 :            :         case IXGBE_PCIDEVCTRL2_16_32ms_def:     /* 32 millisec default */
    3165                 :            :         default:
    3166                 :            :                 pollcnt = 800;          /* 80 millisec minimum */
    3167                 :            :                 break;
    3168                 :            :         }
    3169                 :            : 
    3170                 :            :         /* add 10% to spec maximum */
    3171                 :            :         return (pollcnt * 11) / 10;
    3172                 :            : }
    3173                 :            : 
    3174                 :            : /**
    3175                 :            :  * ixgbe_disable_pcie_primary - Disable PCI-express primary access
    3176                 :            :  * @hw: pointer to hardware structure
    3177                 :            :  *
    3178                 :            :  * Disables PCI-Express primary access and verifies there are no pending
    3179                 :            :  * requests. IXGBE_ERR_PRIMARY_REQUESTS_PENDING is returned if primary disable
    3180                 :            :  * bit hasn't caused the primary requests to be disabled, else IXGBE_SUCCESS
    3181                 :            :  * is returned signifying primary requests disabled.
    3182                 :            :  **/
    3183                 :          0 : s32 ixgbe_disable_pcie_primary(struct ixgbe_hw *hw)
    3184                 :            : {
    3185                 :            :         s32 status = IXGBE_SUCCESS;
    3186                 :            :         u32 i, poll;
    3187                 :            :         u16 value;
    3188                 :            : 
    3189                 :          0 :         DEBUGFUNC("ixgbe_disable_pcie_primary");
    3190                 :            : 
    3191                 :            :         /* Always set this bit to ensure any future transactions are blocked */
    3192                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
    3193                 :            : 
    3194                 :            :         /* Exit if primary requests are blocked */
    3195         [ #  # ]:          0 :         if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO) ||
    3196                 :            :             IXGBE_REMOVED(hw->hw_addr))
    3197                 :          0 :                 goto out;
    3198                 :            : 
    3199                 :            :         /* Poll for primary request bit to clear */
    3200         [ #  # ]:          0 :         for (i = 0; i < IXGBE_PCI_PRIMARY_DISABLE_TIMEOUT; i++) {
    3201                 :          0 :                 usec_delay(100);
    3202         [ #  # ]:          0 :                 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
    3203                 :          0 :                         goto out;
    3204                 :            :         }
    3205                 :            : 
    3206                 :            :         /*
    3207                 :            :          * Two consecutive resets are required via CTRL.RST per datasheet
    3208                 :            :          * 5.2.5.3.2 Primary Disable.  We set a flag to inform the reset routine
    3209                 :            :          * of this need. The first reset prevents new primary requests from
    3210                 :            :          * being issued by our device.  We then must wait 1usec or more for any
    3211                 :            :          * remaining completions from the PCIe bus to trickle in, and then reset
    3212                 :            :          * again to clear out any effects they may have had on our device.
    3213                 :            :          */
    3214                 :          0 :         DEBUGOUT("GIO Primary Disable bit didn't clear - requesting resets\n");
    3215                 :          0 :         hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
    3216                 :            : 
    3217         [ #  # ]:          0 :         if (hw->mac.type >= ixgbe_mac_X550)
    3218                 :          0 :                 goto out;
    3219                 :            : 
    3220                 :            :         /*
    3221                 :            :          * Before proceeding, make sure that the PCIe block does not have
    3222                 :            :          * transactions pending.
    3223                 :            :          */
    3224                 :            :         poll = ixgbe_pcie_timeout_poll(hw);
    3225                 :            :         for (i = 0; i < poll; i++) {
    3226                 :          0 :                 usec_delay(100);
    3227                 :            :                 value = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS);
    3228                 :            :                 if (IXGBE_REMOVED(hw->hw_addr))
    3229                 :            :                         goto out;
    3230                 :            :                 if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
    3231                 :          0 :                         goto out;
    3232                 :            :         }
    3233                 :            : 
    3234                 :            :         ERROR_REPORT1(IXGBE_ERROR_POLLING,
    3235                 :            :                      "PCIe transaction pending bit also did not clear.\n");
    3236                 :            :         status = IXGBE_ERR_PRIMARY_REQUESTS_PENDING;
    3237                 :            : 
    3238                 :          0 : out:
    3239                 :          0 :         return status;
    3240                 :            : }
    3241                 :            : 
    3242                 :            : /**
    3243                 :            :  * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
    3244                 :            :  * @hw: pointer to hardware structure
    3245                 :            :  * @mask: Mask to specify which semaphore to acquire
    3246                 :            :  *
    3247                 :            :  * Acquires the SWFW semaphore through the GSSR register for the specified
    3248                 :            :  * function (CSR, PHY0, PHY1, EEPROM, Flash)
    3249                 :            :  **/
    3250                 :          0 : s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u32 mask)
    3251                 :            : {
    3252                 :            :         u32 gssr = 0;
    3253                 :            :         u32 swmask = mask;
    3254                 :          0 :         u32 fwmask = mask << 5;
    3255                 :            :         u32 timeout = 200;
    3256                 :            :         u32 i;
    3257                 :            : 
    3258                 :          0 :         DEBUGFUNC("ixgbe_acquire_swfw_sync");
    3259                 :            : 
    3260         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    3261                 :            :                 /*
    3262                 :            :                  * SW NVM semaphore bit is used for access to all
    3263                 :            :                  * SW_FW_SYNC bits (not just NVM)
    3264                 :            :                  */
    3265         [ #  # ]:          0 :                 if (ixgbe_get_eeprom_semaphore(hw))
    3266                 :            :                         return IXGBE_ERR_SWFW_SYNC;
    3267                 :            : 
    3268                 :          0 :                 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
    3269         [ #  # ]:          0 :                 if (!(gssr & (fwmask | swmask))) {
    3270                 :          0 :                         gssr |= swmask;
    3271                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
    3272                 :          0 :                         ixgbe_release_eeprom_semaphore(hw);
    3273                 :          0 :                         return IXGBE_SUCCESS;
    3274                 :            :                 } else {
    3275                 :            :                         /* Resource is currently in use by FW or SW */
    3276                 :          0 :                         ixgbe_release_eeprom_semaphore(hw);
    3277                 :          0 :                         msec_delay(5);
    3278                 :            :                 }
    3279                 :            :         }
    3280                 :            : 
    3281                 :            :         /* If time expired clear the bits holding the lock and retry */
    3282         [ #  # ]:          0 :         if (gssr & (fwmask | swmask))
    3283                 :          0 :                 ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask));
    3284                 :            : 
    3285                 :          0 :         msec_delay(5);
    3286                 :          0 :         return IXGBE_ERR_SWFW_SYNC;
    3287                 :            : }
    3288                 :            : 
    3289                 :            : /**
    3290                 :            :  * ixgbe_release_swfw_sync - Release SWFW semaphore
    3291                 :            :  * @hw: pointer to hardware structure
    3292                 :            :  * @mask: Mask to specify which semaphore to release
    3293                 :            :  *
    3294                 :            :  * Releases the SWFW semaphore through the GSSR register for the specified
    3295                 :            :  * function (CSR, PHY0, PHY1, EEPROM, Flash)
    3296                 :            :  **/
    3297                 :          0 : void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u32 mask)
    3298                 :            : {
    3299                 :            :         u32 gssr;
    3300                 :            :         u32 swmask = mask;
    3301                 :            : 
    3302                 :          0 :         DEBUGFUNC("ixgbe_release_swfw_sync");
    3303                 :            : 
    3304                 :          0 :         ixgbe_get_eeprom_semaphore(hw);
    3305                 :            : 
    3306                 :          0 :         gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
    3307                 :          0 :         gssr &= ~swmask;
    3308                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
    3309                 :            : 
    3310                 :          0 :         ixgbe_release_eeprom_semaphore(hw);
    3311                 :          0 : }
    3312                 :            : 
    3313                 :            : /**
    3314                 :            :  * ixgbe_disable_sec_rx_path_generic - Stops the receive data path
    3315                 :            :  * @hw: pointer to hardware structure
    3316                 :            :  *
    3317                 :            :  * Stops the receive data path and waits for the HW to internally empty
    3318                 :            :  * the Rx security block
    3319                 :            :  **/
    3320                 :          0 : s32 ixgbe_disable_sec_rx_path_generic(struct ixgbe_hw *hw)
    3321                 :            : {
    3322                 :            : #define IXGBE_MAX_SECRX_POLL 4000
    3323                 :            : 
    3324                 :            :         int i;
    3325                 :            :         int secrxreg;
    3326                 :            : 
    3327                 :          0 :         DEBUGFUNC("ixgbe_disable_sec_rx_path_generic");
    3328                 :            : 
    3329                 :            : 
    3330                 :          0 :         secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
    3331                 :          0 :         secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
    3332                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
    3333         [ #  # ]:          0 :         for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
    3334                 :          0 :                 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
    3335         [ #  # ]:          0 :                 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
    3336                 :            :                         break;
    3337                 :            :                 else
    3338                 :            :                         /* Use interrupt-safe sleep just in case */
    3339                 :          0 :                         usec_delay(10);
    3340                 :            :         }
    3341                 :            : 
    3342                 :            :         /* For informational purposes only */
    3343         [ #  # ]:          0 :         if (i >= IXGBE_MAX_SECRX_POLL)
    3344                 :          0 :                 DEBUGOUT("Rx unit being enabled before security "
    3345                 :            :                          "path fully disabled.  Continuing with init.\n");
    3346                 :            : 
    3347                 :          0 :         return IXGBE_SUCCESS;
    3348                 :            : }
    3349                 :            : 
    3350                 :            : /**
    3351                 :            :  * prot_autoc_read_generic - Hides MAC differences needed for AUTOC read
    3352                 :            :  * @hw: pointer to hardware structure
    3353                 :            :  * @locked: bool to indicate whether the SW/FW lock was taken
    3354                 :            :  * @reg_val: Value we read from AUTOC
    3355                 :            :  *
    3356                 :            :  * The default case requires no protection so just to the register read.
    3357                 :            :  */
    3358                 :          0 : s32 prot_autoc_read_generic(struct ixgbe_hw *hw, bool *locked, u32 *reg_val)
    3359                 :            : {
    3360                 :          0 :         *locked = false;
    3361                 :          0 :         *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
    3362                 :          0 :         return IXGBE_SUCCESS;
    3363                 :            : }
    3364                 :            : 
    3365                 :            : /**
    3366                 :            :  * prot_autoc_write_generic - Hides MAC differences needed for AUTOC write
    3367                 :            :  * @hw: pointer to hardware structure
    3368                 :            :  * @reg_val: value to write to AUTOC
    3369                 :            :  * @locked: bool to indicate whether the SW/FW lock was already taken by
    3370                 :            :  *          previous read.
    3371                 :            :  *
    3372                 :            :  * The default case requires no protection so just to the register write.
    3373                 :            :  */
    3374                 :          0 : s32 prot_autoc_write_generic(struct ixgbe_hw *hw, u32 reg_val, bool locked)
    3375                 :            : {
    3376                 :            :         UNREFERENCED_1PARAMETER(locked);
    3377                 :            : 
    3378                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_val);
    3379                 :          0 :         return IXGBE_SUCCESS;
    3380                 :            : }
    3381                 :            : 
    3382                 :            : /**
    3383                 :            :  * ixgbe_enable_sec_rx_path_generic - Enables the receive data path
    3384                 :            :  * @hw: pointer to hardware structure
    3385                 :            :  *
    3386                 :            :  * Enables the receive data path.
    3387                 :            :  **/
    3388                 :          0 : s32 ixgbe_enable_sec_rx_path_generic(struct ixgbe_hw *hw)
    3389                 :            : {
    3390                 :            :         u32 secrxreg;
    3391                 :            : 
    3392                 :          0 :         DEBUGFUNC("ixgbe_enable_sec_rx_path_generic");
    3393                 :            : 
    3394                 :          0 :         secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
    3395                 :          0 :         secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
    3396                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
    3397                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    3398                 :            : 
    3399                 :          0 :         return IXGBE_SUCCESS;
    3400                 :            : }
    3401                 :            : 
    3402                 :            : /**
    3403                 :            :  * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
    3404                 :            :  * @hw: pointer to hardware structure
    3405                 :            :  * @regval: register value to write to RXCTRL
    3406                 :            :  *
    3407                 :            :  * Enables the Rx DMA unit
    3408                 :            :  **/
    3409                 :          0 : s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
    3410                 :            : {
    3411                 :          0 :         DEBUGFUNC("ixgbe_enable_rx_dma_generic");
    3412                 :            : 
    3413         [ #  # ]:          0 :         if (regval & IXGBE_RXCTRL_RXEN)
    3414                 :          0 :                 ixgbe_enable_rx(hw);
    3415                 :            :         else
    3416                 :          0 :                 ixgbe_disable_rx(hw);
    3417                 :            : 
    3418                 :          0 :         return IXGBE_SUCCESS;
    3419                 :            : }
    3420                 :            : 
    3421                 :            : /**
    3422                 :            :  * ixgbe_blink_led_start_generic - Blink LED based on index.
    3423                 :            :  * @hw: pointer to hardware structure
    3424                 :            :  * @index: led number to blink
    3425                 :            :  **/
    3426                 :          0 : s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
    3427                 :            : {
    3428                 :          0 :         ixgbe_link_speed speed = 0;
    3429                 :          0 :         bool link_up = 0;
    3430                 :          0 :         u32 autoc_reg = 0;
    3431                 :          0 :         u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    3432                 :            :         s32 ret_val = IXGBE_SUCCESS;
    3433                 :          0 :         bool locked = false;
    3434                 :            : 
    3435                 :          0 :         DEBUGFUNC("ixgbe_blink_led_start_generic");
    3436                 :            : 
    3437         [ #  # ]:          0 :         if (index > 3)
    3438                 :            :                 return IXGBE_ERR_PARAM;
    3439                 :            : 
    3440                 :            :         /*
    3441                 :            :          * Link must be up to auto-blink the LEDs;
    3442                 :            :          * Force it if link is down.
    3443                 :            :          */
    3444                 :          0 :         hw->mac.ops.check_link(hw, &speed, &link_up, false);
    3445                 :            : 
    3446         [ #  # ]:          0 :         if (!link_up) {
    3447                 :          0 :                 ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
    3448         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
    3449                 :          0 :                         goto out;
    3450                 :            : 
    3451                 :          0 :                 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
    3452                 :          0 :                 autoc_reg |= IXGBE_AUTOC_FLU;
    3453                 :            : 
    3454                 :          0 :                 ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
    3455         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
    3456                 :          0 :                         goto out;
    3457                 :            : 
    3458                 :          0 :                 IXGBE_WRITE_FLUSH(hw);
    3459                 :          0 :                 msec_delay(10);
    3460                 :            :         }
    3461                 :            : 
    3462                 :          0 :         led_reg &= ~IXGBE_LED_MODE_MASK(index);
    3463                 :          0 :         led_reg |= IXGBE_LED_BLINK(index);
    3464                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
    3465                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    3466                 :            : 
    3467                 :            : out:
    3468                 :            :         return ret_val;
    3469                 :            : }
    3470                 :            : 
    3471                 :            : /**
    3472                 :            :  * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
    3473                 :            :  * @hw: pointer to hardware structure
    3474                 :            :  * @index: led number to stop blinking
    3475                 :            :  **/
    3476                 :          0 : s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
    3477                 :            : {
    3478                 :          0 :         u32 autoc_reg = 0;
    3479                 :          0 :         u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
    3480                 :            :         s32 ret_val = IXGBE_SUCCESS;
    3481                 :          0 :         bool locked = false;
    3482                 :            : 
    3483                 :          0 :         DEBUGFUNC("ixgbe_blink_led_stop_generic");
    3484                 :            : 
    3485         [ #  # ]:          0 :         if (index > 3)
    3486                 :            :                 return IXGBE_ERR_PARAM;
    3487                 :            : 
    3488                 :            : 
    3489                 :          0 :         ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
    3490         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS)
    3491                 :          0 :                 goto out;
    3492                 :            : 
    3493                 :          0 :         autoc_reg &= ~IXGBE_AUTOC_FLU;
    3494                 :          0 :         autoc_reg |= IXGBE_AUTOC_AN_RESTART;
    3495                 :            : 
    3496                 :          0 :         ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
    3497         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS)
    3498                 :          0 :                 goto out;
    3499                 :            : 
    3500                 :          0 :         led_reg &= ~IXGBE_LED_MODE_MASK(index);
    3501                 :          0 :         led_reg &= ~IXGBE_LED_BLINK(index);
    3502                 :          0 :         led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
    3503                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
    3504                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    3505                 :            : 
    3506                 :            : out:
    3507                 :            :         return ret_val;
    3508                 :            : }
    3509                 :            : 
    3510                 :            : /**
    3511                 :            :  * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
    3512                 :            :  * @hw: pointer to hardware structure
    3513                 :            :  * @san_mac_offset: SAN MAC address offset
    3514                 :            :  *
    3515                 :            :  * This function will read the EEPROM location for the SAN MAC address
    3516                 :            :  * pointer, and returns the value at that location.  This is used in both
    3517                 :            :  * get and set mac_addr routines.
    3518                 :            :  **/
    3519                 :          0 : STATIC s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
    3520                 :            :                                          u16 *san_mac_offset)
    3521                 :            : {
    3522                 :            :         s32 ret_val;
    3523                 :            : 
    3524                 :          0 :         DEBUGFUNC("ixgbe_get_san_mac_addr_offset");
    3525                 :            : 
    3526                 :            :         /*
    3527                 :            :          * First read the EEPROM pointer to see if the MAC addresses are
    3528                 :            :          * available.
    3529                 :            :          */
    3530                 :          0 :         ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR,
    3531                 :            :                                       san_mac_offset);
    3532         [ #  # ]:          0 :         if (ret_val) {
    3533                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    3534                 :            :                               "eeprom at offset %d failed",
    3535                 :            :                               IXGBE_SAN_MAC_ADDR_PTR);
    3536                 :            :         }
    3537                 :            : 
    3538                 :          0 :         return ret_val;
    3539                 :            : }
    3540                 :            : 
    3541                 :            : /**
    3542                 :            :  * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
    3543                 :            :  * @hw: pointer to hardware structure
    3544                 :            :  * @san_mac_addr: SAN MAC address
    3545                 :            :  *
    3546                 :            :  * Reads the SAN MAC address from the EEPROM, if it's available.  This is
    3547                 :            :  * per-port, so set_lan_id() must be called before reading the addresses.
    3548                 :            :  * set_lan_id() is called by identify_sfp(), but this cannot be relied
    3549                 :            :  * upon for non-SFP connections, so we must call it here.
    3550                 :            :  **/
    3551                 :          0 : s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
    3552                 :            : {
    3553                 :            :         u16 san_mac_data, san_mac_offset;
    3554                 :            :         u8 i;
    3555                 :            :         s32 ret_val;
    3556                 :            : 
    3557                 :          0 :         DEBUGFUNC("ixgbe_get_san_mac_addr_generic");
    3558                 :            : 
    3559                 :            :         /*
    3560                 :            :          * First read the EEPROM pointer to see if the MAC addresses are
    3561                 :            :          * available.  If they're not, no point in calling set_lan_id() here.
    3562                 :            :          */
    3563                 :          0 :         ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
    3564   [ #  #  #  #  :          0 :         if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
                   #  # ]
    3565                 :          0 :                 goto san_mac_addr_out;
    3566                 :            : 
    3567                 :            :         /* make sure we know which port we need to program */
    3568                 :          0 :         hw->mac.ops.set_lan_id(hw);
    3569                 :            :         /* apply the port offset to the address offset */
    3570         [ #  # ]:          0 :         (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
    3571                 :            :                          (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
    3572         [ #  # ]:          0 :         for (i = 0; i < 3; i++) {
    3573                 :          0 :                 ret_val = hw->eeprom.ops.read(hw, san_mac_offset,
    3574                 :            :                                               &san_mac_data);
    3575         [ #  # ]:          0 :                 if (ret_val) {
    3576                 :          0 :                         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    3577                 :            :                                       "eeprom read at offset %d failed",
    3578                 :            :                                       san_mac_offset);
    3579                 :          0 :                         goto san_mac_addr_out;
    3580                 :            :                 }
    3581                 :          0 :                 san_mac_addr[i * 2] = (u8)(san_mac_data);
    3582                 :          0 :                 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
    3583                 :          0 :                 san_mac_offset++;
    3584                 :            :         }
    3585                 :            :         return IXGBE_SUCCESS;
    3586                 :            : 
    3587                 :            : san_mac_addr_out:
    3588                 :            :         /*
    3589                 :            :          * No addresses available in this EEPROM.  It's not an
    3590                 :            :          * error though, so just wipe the local address and return.
    3591                 :            :          */
    3592         [ #  # ]:          0 :         for (i = 0; i < 6; i++)
    3593                 :          0 :                 san_mac_addr[i] = 0xFF;
    3594                 :            :         return IXGBE_SUCCESS;
    3595                 :            : }
    3596                 :            : 
    3597                 :            : /**
    3598                 :            :  * ixgbe_set_san_mac_addr_generic - Write the SAN MAC address to the EEPROM
    3599                 :            :  * @hw: pointer to hardware structure
    3600                 :            :  * @san_mac_addr: SAN MAC address
    3601                 :            :  *
    3602                 :            :  * Write a SAN MAC address to the EEPROM.
    3603                 :            :  **/
    3604                 :          0 : s32 ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
    3605                 :            : {
    3606                 :            :         s32 ret_val;
    3607                 :            :         u16 san_mac_data, san_mac_offset;
    3608                 :            :         u8 i;
    3609                 :            : 
    3610                 :          0 :         DEBUGFUNC("ixgbe_set_san_mac_addr_generic");
    3611                 :            : 
    3612                 :            :         /* Look for SAN mac address pointer.  If not defined, return */
    3613                 :          0 :         ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
    3614   [ #  #  #  #  :          0 :         if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
                   #  # ]
    3615                 :            :                 return IXGBE_ERR_NO_SAN_ADDR_PTR;
    3616                 :            : 
    3617                 :            :         /* Make sure we know which port we need to write */
    3618                 :          0 :         hw->mac.ops.set_lan_id(hw);
    3619                 :            :         /* Apply the port offset to the address offset */
    3620         [ #  # ]:          0 :         (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
    3621                 :            :                          (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
    3622                 :            : 
    3623         [ #  # ]:          0 :         for (i = 0; i < 3; i++) {
    3624                 :          0 :                 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
    3625                 :          0 :                 san_mac_data |= (u16)(san_mac_addr[i * 2]);
    3626                 :          0 :                 hw->eeprom.ops.write(hw, san_mac_offset, san_mac_data);
    3627                 :          0 :                 san_mac_offset++;
    3628                 :            :         }
    3629                 :            : 
    3630                 :            :         return IXGBE_SUCCESS;
    3631                 :            : }
    3632                 :            : 
    3633                 :            : /**
    3634                 :            :  * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
    3635                 :            :  * @hw: pointer to hardware structure
    3636                 :            :  *
    3637                 :            :  * Read PCIe configuration space, and get the MSI-X vector count from
    3638                 :            :  * the capabilities table.
    3639                 :            :  **/
    3640                 :          0 : u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
    3641                 :            : {
    3642                 :            :         u16 msix_count = 1;
    3643                 :            :         u16 max_msix_count;
    3644                 :            :         u16 pcie_offset;
    3645                 :            : 
    3646         [ #  # ]:          0 :         switch (hw->mac.type) {
    3647                 :            :         case ixgbe_mac_82598EB:
    3648                 :            :                 pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
    3649                 :            :                 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
    3650                 :            :                 break;
    3651                 :            :         case ixgbe_mac_82599EB:
    3652                 :            :         case ixgbe_mac_X540:
    3653                 :            :         case ixgbe_mac_X550:
    3654                 :            :         case ixgbe_mac_X550EM_x:
    3655                 :            :         case ixgbe_mac_X550EM_a:
    3656                 :            :                 pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
    3657                 :            :                 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
    3658                 :            :                 break;
    3659                 :            :         case ixgbe_mac_E610:
    3660                 :            :                 pcie_offset = IXGBE_PCIE_MSIX_E610_CAPS;
    3661                 :            :                 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
    3662                 :            :                 break;
    3663                 :            :         default:
    3664                 :            :                 return msix_count;
    3665                 :            :         }
    3666                 :            : 
    3667                 :          0 :         DEBUGFUNC("ixgbe_get_pcie_msix_count_generic");
    3668                 :            :         msix_count = IXGBE_READ_PCIE_WORD(hw, pcie_offset);
    3669                 :            :         if (IXGBE_REMOVED(hw->hw_addr))
    3670                 :            :                 msix_count = 0;
    3671                 :            :         msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
    3672                 :            : 
    3673                 :            :         /* MSI-X count is zero-based in HW */
    3674                 :            :         msix_count++;
    3675                 :            : 
    3676                 :            :         if (msix_count > max_msix_count)
    3677                 :            :                 msix_count = max_msix_count;
    3678                 :            : 
    3679                 :          0 :         return msix_count;
    3680                 :            : }
    3681                 :            : 
    3682                 :            : /**
    3683                 :            :  * ixgbe_insert_mac_addr_generic - Find a RAR for this mac address
    3684                 :            :  * @hw: pointer to hardware structure
    3685                 :            :  * @addr: Address to put into receive address register
    3686                 :            :  * @vmdq: VMDq pool to assign
    3687                 :            :  *
    3688                 :            :  * Puts an ethernet address into a receive address register, or
    3689                 :            :  * finds the rar that it is already in; adds to the pool list
    3690                 :            :  **/
    3691                 :          0 : s32 ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
    3692                 :            : {
    3693                 :            :         static const u32 NO_EMPTY_RAR_FOUND = 0xFFFFFFFF;
    3694                 :            :         u32 first_empty_rar = NO_EMPTY_RAR_FOUND;
    3695                 :            :         u32 rar;
    3696                 :            :         u32 rar_low, rar_high;
    3697                 :            :         u32 addr_low, addr_high;
    3698                 :            : 
    3699                 :          0 :         DEBUGFUNC("ixgbe_insert_mac_addr_generic");
    3700                 :            : 
    3701                 :            :         /* swap bytes for HW little endian */
    3702                 :          0 :         addr_low  = addr[0] | (addr[1] << 8)
    3703                 :          0 :                             | (addr[2] << 16)
    3704                 :          0 :                             | (addr[3] << 24);
    3705                 :          0 :         addr_high = addr[4] | (addr[5] << 8);
    3706                 :            : 
    3707                 :            :         /*
    3708                 :            :          * Either find the mac_id in rar or find the first empty space.
    3709                 :            :          * rar_highwater points to just after the highest currently used
    3710                 :            :          * rar in order to shorten the search.  It grows when we add a new
    3711                 :            :          * rar to the top.
    3712                 :            :          */
    3713         [ #  # ]:          0 :         for (rar = 0; rar < hw->mac.rar_highwater; rar++) {
    3714         [ #  # ]:          0 :                 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
    3715                 :            : 
    3716                 :          0 :                 if (((IXGBE_RAH_AV & rar_high) == 0)
    3717         [ #  # ]:          0 :                     && first_empty_rar == NO_EMPTY_RAR_FOUND) {
    3718                 :            :                         first_empty_rar = rar;
    3719         [ #  # ]:          0 :                 } else if ((rar_high & 0xFFFF) == addr_high) {
    3720         [ #  # ]:          0 :                         rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(rar));
    3721         [ #  # ]:          0 :                         if (rar_low == addr_low)
    3722                 :            :                                 break;    /* found it already in the rars */
    3723                 :            :                 }
    3724                 :            :         }
    3725                 :            : 
    3726         [ #  # ]:          0 :         if (rar < hw->mac.rar_highwater) {
    3727                 :            :                 /* already there so just add to the pool bits */
    3728                 :          0 :                 ixgbe_set_vmdq(hw, rar, vmdq);
    3729         [ #  # ]:          0 :         } else if (first_empty_rar != NO_EMPTY_RAR_FOUND) {
    3730                 :            :                 /* stick it into first empty RAR slot we found */
    3731                 :            :                 rar = first_empty_rar;
    3732                 :          0 :                 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
    3733         [ #  # ]:          0 :         } else if (rar == hw->mac.rar_highwater) {
    3734                 :            :                 /* add it to the top of the list and inc the highwater mark */
    3735                 :          0 :                 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
    3736                 :          0 :                 hw->mac.rar_highwater++;
    3737         [ #  # ]:          0 :         } else if (rar >= hw->mac.num_rar_entries) {
    3738                 :            :                 return IXGBE_ERR_INVALID_MAC_ADDR;
    3739                 :            :         }
    3740                 :            : 
    3741                 :            :         /*
    3742                 :            :          * If we found rar[0], make sure the default pool bit (we use pool 0)
    3743                 :            :          * remains cleared to be sure default pool packets will get delivered
    3744                 :            :          */
    3745         [ #  # ]:          0 :         if (rar == 0)
    3746                 :          0 :                 ixgbe_clear_vmdq(hw, rar, 0);
    3747                 :            : 
    3748                 :          0 :         return rar;
    3749                 :            : }
    3750                 :            : 
    3751                 :            : /**
    3752                 :            :  * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
    3753                 :            :  * @hw: pointer to hardware struct
    3754                 :            :  * @rar: receive address register index to disassociate
    3755                 :            :  * @vmdq: VMDq pool index to remove from the rar
    3756                 :            :  **/
    3757                 :          0 : s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
    3758                 :            : {
    3759                 :            :         u32 mpsar_lo, mpsar_hi;
    3760                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    3761                 :            : 
    3762                 :          0 :         DEBUGFUNC("ixgbe_clear_vmdq_generic");
    3763                 :            : 
    3764                 :            :         /* Make sure we are using a valid rar index range */
    3765         [ #  # ]:          0 :         if (rar >= rar_entries) {
    3766                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
    3767                 :            :                              "RAR index %d is out of range.\n", rar);
    3768                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
    3769                 :            :         }
    3770                 :            : 
    3771                 :          0 :         mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
    3772                 :          0 :         mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
    3773                 :            : 
    3774                 :            :         if (IXGBE_REMOVED(hw->hw_addr))
    3775                 :            :                 goto done;
    3776                 :            : 
    3777         [ #  # ]:          0 :         if (!mpsar_lo && !mpsar_hi)
    3778                 :          0 :                 goto done;
    3779                 :            : 
    3780         [ #  # ]:          0 :         if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
    3781         [ #  # ]:          0 :                 if (mpsar_lo) {
    3782                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
    3783                 :          0 :                         mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
    3784                 :            :                 }
    3785         [ #  # ]:          0 :                 if (mpsar_hi) {
    3786                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
    3787                 :          0 :                         mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
    3788                 :            :                 }
    3789         [ #  # ]:          0 :         } else if (vmdq < 32) {
    3790                 :          0 :                 mpsar_lo &= ~(1 << vmdq);
    3791                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
    3792                 :            :         } else {
    3793                 :          0 :                 mpsar_hi &= ~(1 << (vmdq - 32));
    3794                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
    3795                 :            :         }
    3796                 :            : 
    3797                 :            :         /* was that the last pool using this rar? */
    3798   [ #  #  #  # ]:          0 :         if (mpsar_lo == 0 && mpsar_hi == 0 &&
    3799         [ #  # ]:          0 :             rar != 0 && rar != hw->mac.san_mac_rar_index)
    3800                 :          0 :                 hw->mac.ops.clear_rar(hw, rar);
    3801                 :          0 : done:
    3802                 :            :         return IXGBE_SUCCESS;
    3803                 :            : }
    3804                 :            : 
    3805                 :            : /**
    3806                 :            :  * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
    3807                 :            :  * @hw: pointer to hardware struct
    3808                 :            :  * @rar: receive address register index to associate with a VMDq index
    3809                 :            :  * @vmdq: VMDq pool index
    3810                 :            :  **/
    3811                 :          0 : s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
    3812                 :            : {
    3813                 :            :         u32 mpsar;
    3814                 :          0 :         u32 rar_entries = hw->mac.num_rar_entries;
    3815                 :            : 
    3816                 :          0 :         DEBUGFUNC("ixgbe_set_vmdq_generic");
    3817                 :            : 
    3818                 :            :         /* Make sure we are using a valid rar index range */
    3819         [ #  # ]:          0 :         if (rar >= rar_entries) {
    3820                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
    3821                 :            :                              "RAR index %d is out of range.\n", rar);
    3822                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
    3823                 :            :         }
    3824                 :            : 
    3825         [ #  # ]:          0 :         if (vmdq < 32) {
    3826                 :          0 :                 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
    3827                 :          0 :                 mpsar |= 1 << vmdq;
    3828                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
    3829                 :            :         } else {
    3830                 :          0 :                 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
    3831                 :          0 :                 mpsar |= 1 << (vmdq - 32);
    3832                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
    3833                 :            :         }
    3834                 :            :         return IXGBE_SUCCESS;
    3835                 :            : }
    3836                 :            : 
    3837                 :            : /**
    3838                 :            :  * ixgbe_set_vmdq_san_mac_generic - Associate default VMDq pool index with
    3839                 :            :  * a rx address
    3840                 :            :  * @hw: pointer to hardware struct
    3841                 :            :  * @vmdq: VMDq pool index
    3842                 :            :  *
    3843                 :            :  * This function should only be involved in the IOV mode.
    3844                 :            :  * In IOV mode, Default pool is next pool after the number of
    3845                 :            :  * VFs advertized and not 0.
    3846                 :            :  * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
    3847                 :            :  **/
    3848                 :          0 : s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
    3849                 :            : {
    3850                 :          0 :         u32 rar = hw->mac.san_mac_rar_index;
    3851                 :            : 
    3852                 :          0 :         DEBUGFUNC("ixgbe_set_vmdq_san_mac");
    3853                 :            : 
    3854         [ #  # ]:          0 :         if (vmdq < 32) {
    3855                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
    3856                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
    3857                 :            :         } else {
    3858                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
    3859                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
    3860                 :            :         }
    3861                 :            : 
    3862                 :          0 :         return IXGBE_SUCCESS;
    3863                 :            : }
    3864                 :            : 
    3865                 :            : /**
    3866                 :            :  * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
    3867                 :            :  * @hw: pointer to hardware structure
    3868                 :            :  **/
    3869                 :          0 : s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
    3870                 :            : {
    3871                 :            :         int i;
    3872                 :            : 
    3873                 :          0 :         DEBUGFUNC("ixgbe_init_uta_tables_generic");
    3874                 :          0 :         DEBUGOUT(" Clearing UTA\n");
    3875                 :            : 
    3876         [ #  # ]:          0 :         for (i = 0; i < 128; i++)
    3877                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
    3878                 :            : 
    3879                 :          0 :         return IXGBE_SUCCESS;
    3880                 :            : }
    3881                 :            : 
    3882                 :            : /**
    3883                 :            :  * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
    3884                 :            :  * @hw: pointer to hardware structure
    3885                 :            :  * @vlan: VLAN id to write to VLAN filter
    3886                 :            :  * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
    3887                 :            :  *                vlanid not found
    3888                 :            :  *
    3889                 :            :  *
    3890                 :            :  * return the VLVF index where this VLAN id should be placed
    3891                 :            :  *
    3892                 :            :  **/
    3893                 :          0 : s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan, bool vlvf_bypass)
    3894                 :            : {
    3895                 :            :         s32 regindex, first_empty_slot;
    3896                 :            :         u32 bits;
    3897                 :            : 
    3898                 :            :         /* short cut the special case */
    3899         [ #  # ]:          0 :         if (vlan == 0)
    3900                 :            :                 return 0;
    3901                 :            : 
    3902                 :            :         /* if vlvf_bypass is set we don't want to use an empty slot, we
    3903                 :            :          * will simply bypass the VLVF if there are no entries present in the
    3904                 :            :          * VLVF that contain our VLAN
    3905                 :            :          */
    3906         [ #  # ]:          0 :         first_empty_slot = vlvf_bypass ? IXGBE_ERR_NO_SPACE : 0;
    3907                 :            : 
    3908                 :            :         /* add VLAN enable bit for comparison */
    3909                 :          0 :         vlan |= IXGBE_VLVF_VIEN;
    3910                 :            : 
    3911                 :            :         /* Search for the vlan id in the VLVF entries. Save off the first empty
    3912                 :            :          * slot found along the way.
    3913                 :            :          *
    3914                 :            :          * pre-decrement loop covering (IXGBE_VLVF_ENTRIES - 1) .. 1
    3915                 :            :          */
    3916         [ #  # ]:          0 :         for (regindex = IXGBE_VLVF_ENTRIES; --regindex;) {
    3917                 :          0 :                 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
    3918         [ #  # ]:          0 :                 if (bits == vlan)
    3919                 :          0 :                         return regindex;
    3920         [ #  # ]:          0 :                 if (!first_empty_slot && !bits)
    3921                 :            :                         first_empty_slot = regindex;
    3922                 :            :         }
    3923                 :            : 
    3924                 :            :         /* If we are here then we didn't find the VLAN.  Return first empty
    3925                 :            :          * slot we found during our search, else error.
    3926                 :            :          */
    3927         [ #  # ]:          0 :         if (!first_empty_slot)
    3928                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "No space in VLVF.\n");
    3929                 :            : 
    3930         [ #  # ]:          0 :         return first_empty_slot ? first_empty_slot : IXGBE_ERR_NO_SPACE;
    3931                 :            : }
    3932                 :            : 
    3933                 :            : /**
    3934                 :            :  * ixgbe_set_vfta_generic - Set VLAN filter table
    3935                 :            :  * @hw: pointer to hardware structure
    3936                 :            :  * @vlan: VLAN id to write to VLAN filter
    3937                 :            :  * @vind: VMDq output index that maps queue to VLAN id in VLVFB
    3938                 :            :  * @vlan_on: boolean flag to turn on/off VLAN
    3939                 :            :  * @vlvf_bypass: boolean flag indicating updating default pool is okay
    3940                 :            :  *
    3941                 :            :  * Turn on/off specified VLAN in the VLAN filter table.
    3942                 :            :  **/
    3943                 :          0 : s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
    3944                 :            :                            bool vlan_on, bool vlvf_bypass)
    3945                 :            : {
    3946                 :            :         u32 regidx, vfta_delta, vfta;
    3947                 :            :         s32 ret_val;
    3948                 :            : 
    3949                 :          0 :         DEBUGFUNC("ixgbe_set_vfta_generic");
    3950                 :            : 
    3951         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    3952                 :            :                 return IXGBE_ERR_PARAM;
    3953                 :            : 
    3954                 :            :         /*
    3955                 :            :          * this is a 2 part operation - first the VFTA, then the
    3956                 :            :          * VLVF and VLVFB if VT Mode is set
    3957                 :            :          * We don't write the VFTA until we know the VLVF part succeeded.
    3958                 :            :          */
    3959                 :            : 
    3960                 :            :         /* Part 1
    3961                 :            :          * The VFTA is a bitstring made up of 128 32-bit registers
    3962                 :            :          * that enable the particular VLAN id, much like the MTA:
    3963                 :            :          *    bits[11-5]: which register
    3964                 :            :          *    bits[4-0]:  which bit in the register
    3965                 :            :          */
    3966                 :          0 :         regidx = vlan / 32;
    3967                 :          0 :         vfta_delta = 1 << (vlan % 32);
    3968                 :          0 :         vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regidx));
    3969                 :            : 
    3970                 :            :         /*
    3971                 :            :          * vfta_delta represents the difference between the current value
    3972                 :            :          * of vfta and the value we want in the register.  Since the diff
    3973                 :            :          * is an XOR mask we can just update the vfta using an XOR
    3974                 :            :          */
    3975         [ #  # ]:          0 :         vfta_delta &= vlan_on ? ~vfta : vfta;
    3976                 :          0 :         vfta ^= vfta_delta;
    3977                 :            : 
    3978                 :            :         /* Part 2
    3979                 :            :          * Call ixgbe_set_vlvf_generic to set VLVFB and VLVF
    3980                 :            :          */
    3981                 :          0 :         ret_val = ixgbe_set_vlvf_generic(hw, vlan, vind, vlan_on, &vfta_delta,
    3982                 :            :                                          vfta, vlvf_bypass);
    3983         [ #  # ]:          0 :         if (ret_val != IXGBE_SUCCESS) {
    3984         [ #  # ]:          0 :                 if (vlvf_bypass)
    3985                 :          0 :                         goto vfta_update;
    3986                 :            :                 return ret_val;
    3987                 :            :         }
    3988                 :            : 
    3989                 :          0 : vfta_update:
    3990                 :            :         /* Update VFTA now that we are ready for traffic */
    3991         [ #  # ]:          0 :         if (vfta_delta)
    3992                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regidx), vfta);
    3993                 :            : 
    3994                 :            :         return IXGBE_SUCCESS;
    3995                 :            : }
    3996                 :            : 
    3997                 :            : /**
    3998                 :            :  * ixgbe_set_vlvf_generic - Set VLAN Pool Filter
    3999                 :            :  * @hw: pointer to hardware structure
    4000                 :            :  * @vlan: VLAN id to write to VLAN filter
    4001                 :            :  * @vind: VMDq output index that maps queue to VLAN id in VLVFB
    4002                 :            :  * @vlan_on: boolean flag to turn on/off VLAN in VLVF
    4003                 :            :  * @vfta_delta: pointer to the difference between the current value of VFTA
    4004                 :            :  *               and the desired value
    4005                 :            :  * @vfta: the desired value of the VFTA
    4006                 :            :  * @vlvf_bypass: boolean flag indicating updating default pool is okay
    4007                 :            :  *
    4008                 :            :  * Turn on/off specified bit in VLVF table.
    4009                 :            :  **/
    4010                 :          0 : s32 ixgbe_set_vlvf_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
    4011                 :            :                            bool vlan_on, u32 *vfta_delta, u32 vfta,
    4012                 :            :                            bool vlvf_bypass)
    4013                 :            : {
    4014                 :            :         u32 bits;
    4015                 :            :         s32 vlvf_index;
    4016                 :            : 
    4017                 :          0 :         DEBUGFUNC("ixgbe_set_vlvf_generic");
    4018                 :            : 
    4019         [ #  # ]:          0 :         if (vlan > 4095 || vind > 63)
    4020                 :            :                 return IXGBE_ERR_PARAM;
    4021                 :            : 
    4022                 :            :         /* If VT Mode is set
    4023                 :            :          *   Either vlan_on
    4024                 :            :          *     make sure the vlan is in VLVF
    4025                 :            :          *     set the vind bit in the matching VLVFB
    4026                 :            :          *   Or !vlan_on
    4027                 :            :          *     clear the pool bit and possibly the vind
    4028                 :            :          */
    4029         [ #  # ]:          0 :         if (!(IXGBE_READ_REG(hw, IXGBE_VT_CTL) & IXGBE_VT_CTL_VT_ENABLE))
    4030                 :            :                 return IXGBE_SUCCESS;
    4031                 :            : 
    4032                 :          0 :         vlvf_index = ixgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
    4033         [ #  # ]:          0 :         if (vlvf_index < 0)
    4034                 :            :                 return vlvf_index;
    4035                 :            : 
    4036                 :          0 :         bits = IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32));
    4037                 :            : 
    4038                 :            :         /* set the pool bit */
    4039                 :          0 :         bits |= 1 << (vind % 32);
    4040         [ #  # ]:          0 :         if (vlan_on)
    4041                 :          0 :                 goto vlvf_update;
    4042                 :            : 
    4043                 :            :         /* clear the pool bit */
    4044                 :          0 :         bits ^= 1 << (vind % 32);
    4045                 :            : 
    4046   [ #  #  #  # ]:          0 :         if (!bits &&
    4047                 :          0 :             !IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + 1 - vind / 32))) {
    4048                 :            :                 /* Clear VFTA first, then disable VLVF.  Otherwise
    4049                 :            :                  * we run the risk of stray packets leaking into
    4050                 :            :                  * the PF via the default pool
    4051                 :            :                  */
    4052         [ #  # ]:          0 :                 if (*vfta_delta)
    4053                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_VFTA(vlan / 32), vfta);
    4054                 :            : 
    4055                 :            :                 /* disable VLVF and clear remaining bit from pool */
    4056                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
    4057                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), 0);
    4058                 :            : 
    4059                 :          0 :                 return IXGBE_SUCCESS;
    4060                 :            :         }
    4061                 :            : 
    4062                 :            :         /* If there are still bits set in the VLVFB registers
    4063                 :            :          * for the VLAN ID indicated we need to see if the
    4064                 :            :          * caller is requesting that we clear the VFTA entry bit.
    4065                 :            :          * If the caller has requested that we clear the VFTA
    4066                 :            :          * entry bit but there are still pools/VFs using this VLAN
    4067                 :            :          * ID entry then ignore the request.  We're not worried
    4068                 :            :          * about the case where we're turning the VFTA VLAN ID
    4069                 :            :          * entry bit on, only when requested to turn it off as
    4070                 :            :          * there may be multiple pools and/or VFs using the
    4071                 :            :          * VLAN ID entry.  In that case we cannot clear the
    4072                 :            :          * VFTA bit until all pools/VFs using that VLAN ID have also
    4073                 :            :          * been cleared.  This will be indicated by "bits" being
    4074                 :            :          * zero.
    4075                 :            :          */
    4076                 :          0 :         *vfta_delta = 0;
    4077                 :            : 
    4078                 :          0 : vlvf_update:
    4079                 :            :         /* record pool change and enable VLAN ID if not already enabled */
    4080                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), bits);
    4081                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), IXGBE_VLVF_VIEN | vlan);
    4082                 :            : 
    4083                 :          0 :         return IXGBE_SUCCESS;
    4084                 :            : }
    4085                 :            : 
    4086                 :            : /**
    4087                 :            :  * ixgbe_clear_vfta_generic - Clear VLAN filter table
    4088                 :            :  * @hw: pointer to hardware structure
    4089                 :            :  *
    4090                 :            :  * Clears the VLAN filer table, and the VMDq index associated with the filter
    4091                 :            :  **/
    4092                 :          0 : s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
    4093                 :            : {
    4094                 :            :         u32 offset;
    4095                 :            : 
    4096                 :          0 :         DEBUGFUNC("ixgbe_clear_vfta_generic");
    4097                 :            : 
    4098         [ #  # ]:          0 :         for (offset = 0; offset < hw->mac.vft_size; offset++)
    4099                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
    4100                 :            : 
    4101         [ #  # ]:          0 :         for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
    4102                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
    4103                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
    4104                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2 + 1), 0);
    4105                 :            :         }
    4106                 :            : 
    4107                 :          0 :         return IXGBE_SUCCESS;
    4108                 :            : }
    4109                 :            : 
    4110                 :            : /**
    4111                 :            :  * ixgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
    4112                 :            :  * @hw: pointer to hardware structure
    4113                 :            :  *
    4114                 :            :  * Contains the logic to identify if we need to verify link for the
    4115                 :            :  * crosstalk fix
    4116                 :            :  **/
    4117                 :            : static bool ixgbe_need_crosstalk_fix(struct ixgbe_hw *hw)
    4118                 :            : {
    4119                 :            : 
    4120                 :            :         /* Does FW say we need the fix */
    4121   [ #  #  #  # ]:          0 :         if (!hw->need_crosstalk_fix)
    4122                 :            :                 return false;
    4123                 :            : 
    4124                 :            :         /* Only consider SFP+ PHYs i.e. media type fiber */
    4125   [ #  #  #  # ]:          0 :         switch (hw->mac.ops.get_media_type(hw)) {
    4126                 :            :         case ixgbe_media_type_fiber:
    4127                 :            :         case ixgbe_media_type_fiber_qsfp:
    4128                 :            :                 break;
    4129                 :            :         default:
    4130                 :            :                 return false;
    4131                 :            :         }
    4132                 :            : 
    4133                 :            :         return true;
    4134                 :            : }
    4135                 :            : 
    4136                 :            : /**
    4137                 :            :  * ixgbe_check_mac_link_generic - Determine link and speed status
    4138                 :            :  * @hw: pointer to hardware structure
    4139                 :            :  * @speed: pointer to link speed
    4140                 :            :  * @link_up: true when link is up
    4141                 :            :  * @link_up_wait_to_complete: bool used to wait for link up or not
    4142                 :            :  *
    4143                 :            :  * Reads the links register to determine if link is up and the current speed
    4144                 :            :  **/
    4145                 :          0 : s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
    4146                 :            :                                  bool *link_up, bool link_up_wait_to_complete)
    4147                 :            : {
    4148                 :            :         u32 links_reg, links_orig;
    4149                 :            :         u32 i;
    4150                 :            : 
    4151                 :          0 :         DEBUGFUNC("ixgbe_check_mac_link_generic");
    4152                 :            : 
    4153                 :            :         /* If Crosstalk fix enabled do the sanity check of making sure
    4154                 :            :          * the SFP+ cage is full.
    4155                 :            :          */
    4156                 :            :         if (ixgbe_need_crosstalk_fix(hw)) {
    4157                 :            :                 u32 sfp_cage_full;
    4158                 :            : 
    4159      [ #  #  # ]:          0 :                 switch (hw->mac.type) {
    4160                 :          0 :                 case ixgbe_mac_82599EB:
    4161                 :          0 :                         sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
    4162                 :            :                                         IXGBE_ESDP_SDP2;
    4163                 :          0 :                         break;
    4164                 :          0 :                 case ixgbe_mac_X550EM_x:
    4165                 :            :                 case ixgbe_mac_X550EM_a:
    4166                 :          0 :                         sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
    4167                 :            :                                         IXGBE_ESDP_SDP0;
    4168                 :          0 :                         break;
    4169                 :            :                 default:
    4170                 :            :                         /* sanity check - No SFP+ devices here */
    4171                 :            :                         sfp_cage_full = false;
    4172                 :            :                         break;
    4173                 :            :                 }
    4174                 :            : 
    4175         [ #  # ]:          0 :                 if (!sfp_cage_full) {
    4176                 :          0 :                         *link_up = false;
    4177                 :          0 :                         *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4178                 :          0 :                         return IXGBE_SUCCESS;
    4179                 :            :                 }
    4180                 :            :         }
    4181                 :            : 
    4182                 :            :         /* clear the old state */
    4183                 :          0 :         links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
    4184                 :            : 
    4185                 :          0 :         links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
    4186                 :            : 
    4187         [ #  # ]:          0 :         if (links_orig != links_reg) {
    4188                 :          0 :                 DEBUGOUT2("LINKS changed from %08X to %08X\n",
    4189                 :            :                           links_orig, links_reg);
    4190                 :            :         }
    4191                 :            : 
    4192         [ #  # ]:          0 :         if (link_up_wait_to_complete) {
    4193         [ #  # ]:          0 :                 for (i = 0; i < hw->mac.max_link_up_time; i++) {
    4194         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_UP) {
    4195                 :          0 :                                 *link_up = true;
    4196                 :          0 :                                 break;
    4197                 :            :                         } else {
    4198                 :          0 :                                 *link_up = false;
    4199                 :            :                         }
    4200                 :          0 :                         msec_delay(100);
    4201                 :          0 :                         links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
    4202                 :            :                 }
    4203                 :            :         } else {
    4204         [ #  # ]:          0 :                 if (links_reg & IXGBE_LINKS_UP) {
    4205                 :            :                         if (ixgbe_need_crosstalk_fix(hw)) {
    4206                 :            :                                 /* Check the link state again after a delay
    4207                 :            :                                  * to filter out spurious link up
    4208                 :            :                                  * notifications.
    4209                 :            :                                  */
    4210                 :          0 :                                 msec_delay(5);
    4211                 :          0 :                                 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
    4212         [ #  # ]:          0 :                                 if (!(links_reg & IXGBE_LINKS_UP)) {
    4213                 :          0 :                                         *link_up = false;
    4214                 :          0 :                                         *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4215                 :          0 :                                         return IXGBE_SUCCESS;
    4216                 :            :                                 }
    4217                 :            : 
    4218                 :            :                         }
    4219                 :          0 :                         *link_up = true;
    4220                 :            :                 } else {
    4221                 :          0 :                         *link_up = false;
    4222                 :            :                 }
    4223                 :            :         }
    4224                 :            : 
    4225   [ #  #  #  #  :          0 :         switch (links_reg & IXGBE_LINKS_SPEED_82599) {
                      # ]
    4226                 :          0 :         case IXGBE_LINKS_SPEED_10G_82599:
    4227                 :          0 :                 *speed = IXGBE_LINK_SPEED_10GB_FULL;
    4228         [ #  # ]:          0 :                 if (hw->mac.type >= ixgbe_mac_X550) {
    4229         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
    4230                 :          0 :                                 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
    4231                 :            :                 }
    4232                 :            :                 break;
    4233                 :          0 :         case IXGBE_LINKS_SPEED_1G_82599:
    4234                 :          0 :                 *speed = IXGBE_LINK_SPEED_1GB_FULL;
    4235                 :          0 :                 break;
    4236                 :          0 :         case IXGBE_LINKS_SPEED_100_82599:
    4237                 :          0 :                 *speed = IXGBE_LINK_SPEED_100_FULL;
    4238         [ #  # ]:          0 :                 if (hw->mac.type == ixgbe_mac_X550 || hw->mac.type == ixgbe_mac_E610) {
    4239         [ #  # ]:          0 :                         if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
    4240                 :          0 :                                 *speed = IXGBE_LINK_SPEED_5GB_FULL;
    4241                 :            :                 }
    4242                 :            :                 break;
    4243                 :          0 :         case IXGBE_LINKS_SPEED_10_X550EM_A:
    4244                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4245         [ #  # ]:          0 :                 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
    4246                 :            :                     hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
    4247                 :          0 :                         *speed = IXGBE_LINK_SPEED_10_FULL;
    4248                 :            :                 break;
    4249                 :          0 :         default:
    4250                 :          0 :                 *speed = IXGBE_LINK_SPEED_UNKNOWN;
    4251                 :            :         }
    4252                 :            : 
    4253                 :            :         return IXGBE_SUCCESS;
    4254                 :            : }
    4255                 :            : 
    4256                 :            : /**
    4257                 :            :  * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
    4258                 :            :  * the EEPROM
    4259                 :            :  * @hw: pointer to hardware structure
    4260                 :            :  * @wwnn_prefix: the alternative WWNN prefix
    4261                 :            :  * @wwpn_prefix: the alternative WWPN prefix
    4262                 :            :  *
    4263                 :            :  * This function will read the EEPROM from the alternative SAN MAC address
    4264                 :            :  * block to check the support for the alternative WWNN/WWPN prefix support.
    4265                 :            :  **/
    4266                 :          0 : s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
    4267                 :            :                                  u16 *wwpn_prefix)
    4268                 :            : {
    4269                 :            :         u16 offset, caps;
    4270                 :            :         u16 alt_san_mac_blk_offset;
    4271                 :            : 
    4272                 :          0 :         DEBUGFUNC("ixgbe_get_wwn_prefix_generic");
    4273                 :            : 
    4274                 :            :         /* clear output first */
    4275                 :          0 :         *wwnn_prefix = 0xFFFF;
    4276                 :          0 :         *wwpn_prefix = 0xFFFF;
    4277                 :            : 
    4278                 :            :         /* check if alternative SAN MAC is supported */
    4279                 :            :         offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
    4280         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset))
    4281                 :          0 :                 goto wwn_prefix_err;
    4282                 :            : 
    4283         [ #  # ]:          0 :         if ((alt_san_mac_blk_offset == 0) ||
    4284                 :            :             (alt_san_mac_blk_offset == 0xFFFF))
    4285                 :          0 :                 goto wwn_prefix_out;
    4286                 :            : 
    4287                 :            :         /* check capability in alternative san mac address block */
    4288                 :            :         offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
    4289         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, &caps))
    4290                 :          0 :                 goto wwn_prefix_err;
    4291         [ #  # ]:          0 :         if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
    4292                 :          0 :                 goto wwn_prefix_out;
    4293                 :            : 
    4294                 :            :         /* get the corresponding prefix for WWNN/WWPN */
    4295                 :          0 :         offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
    4296         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, wwnn_prefix)) {
    4297                 :          0 :                 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    4298                 :            :                               "eeprom read at offset %d failed", offset);
    4299                 :            :         }
    4300                 :            : 
    4301                 :          0 :         offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
    4302         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, wwpn_prefix))
    4303                 :          0 :                 goto wwn_prefix_err;
    4304                 :            : 
    4305                 :          0 : wwn_prefix_out:
    4306                 :            :         return IXGBE_SUCCESS;
    4307                 :            : 
    4308                 :          0 : wwn_prefix_err:
    4309                 :          0 :         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    4310                 :            :                       "eeprom read at offset %d failed", offset);
    4311                 :          0 :         return IXGBE_SUCCESS;
    4312                 :            : }
    4313                 :            : 
    4314                 :            : /**
    4315                 :            :  * ixgbe_get_fcoe_boot_status_generic - Get FCOE boot status from EEPROM
    4316                 :            :  * @hw: pointer to hardware structure
    4317                 :            :  * @bs: the fcoe boot status
    4318                 :            :  *
    4319                 :            :  * This function will read the FCOE boot status from the iSCSI FCOE block
    4320                 :            :  **/
    4321                 :          0 : s32 ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, u16 *bs)
    4322                 :            : {
    4323                 :            :         u16 offset, caps, flags;
    4324                 :            :         s32 status;
    4325                 :            : 
    4326                 :          0 :         DEBUGFUNC("ixgbe_get_fcoe_boot_status_generic");
    4327                 :            : 
    4328                 :            :         /* clear output first */
    4329                 :          0 :         *bs = ixgbe_fcoe_bootstatus_unavailable;
    4330                 :            : 
    4331                 :            :         /* check if FCOE IBA block is present */
    4332                 :          0 :         offset = IXGBE_FCOE_IBA_CAPS_BLK_PTR;
    4333                 :          0 :         status = hw->eeprom.ops.read(hw, offset, &caps);
    4334         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    4335                 :          0 :                 goto out;
    4336                 :            : 
    4337         [ #  # ]:          0 :         if (!(caps & IXGBE_FCOE_IBA_CAPS_FCOE))
    4338                 :          0 :                 goto out;
    4339                 :            : 
    4340                 :            :         /* check if iSCSI FCOE block is populated */
    4341                 :          0 :         status = hw->eeprom.ops.read(hw, IXGBE_ISCSI_FCOE_BLK_PTR, &offset);
    4342         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    4343                 :          0 :                 goto out;
    4344                 :            : 
    4345         [ #  # ]:          0 :         if ((offset == 0) || (offset == 0xFFFF))
    4346                 :          0 :                 goto out;
    4347                 :            : 
    4348                 :            :         /* read fcoe flags in iSCSI FCOE block */
    4349                 :            :         offset = offset + IXGBE_ISCSI_FCOE_FLAGS_OFFSET;
    4350                 :          0 :         status = hw->eeprom.ops.read(hw, offset, &flags);
    4351         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    4352                 :          0 :                 goto out;
    4353                 :            : 
    4354         [ #  # ]:          0 :         if (flags & IXGBE_ISCSI_FCOE_FLAGS_ENABLE)
    4355                 :          0 :                 *bs = ixgbe_fcoe_bootstatus_enabled;
    4356                 :            :         else
    4357                 :          0 :                 *bs = ixgbe_fcoe_bootstatus_disabled;
    4358                 :            : 
    4359                 :          0 : out:
    4360                 :          0 :         return status;
    4361                 :            : }
    4362                 :            : 
    4363                 :            : /**
    4364                 :            :  * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
    4365                 :            :  * @hw: pointer to hardware structure
    4366                 :            :  * @enable: enable or disable switch for MAC anti-spoofing
    4367                 :            :  * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
    4368                 :            :  *
    4369                 :            :  **/
    4370                 :          0 : void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
    4371                 :            : {
    4372                 :          0 :         int vf_target_reg = vf >> 3;
    4373                 :            :         int vf_target_shift = vf % 8;
    4374                 :            :         u32 pfvfspoof;
    4375                 :            : 
    4376         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
    4377                 :            :                 return;
    4378                 :            : 
    4379                 :          0 :         pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
    4380         [ #  # ]:          0 :         if (enable)
    4381                 :          0 :                 pfvfspoof |= (1 << vf_target_shift);
    4382                 :            :         else
    4383                 :          0 :                 pfvfspoof &= ~(1 << vf_target_shift);
    4384                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
    4385                 :            : }
    4386                 :            : 
    4387                 :            : /**
    4388                 :            :  * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
    4389                 :            :  * @hw: pointer to hardware structure
    4390                 :            :  * @enable: enable or disable switch for VLAN anti-spoofing
    4391                 :            :  * @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
    4392                 :            :  *
    4393                 :            :  **/
    4394                 :          0 : void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
    4395                 :            : {
    4396                 :          0 :         int vf_target_reg = vf >> 3;
    4397                 :          0 :         int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
    4398                 :            :         u32 pfvfspoof;
    4399                 :            : 
    4400         [ #  # ]:          0 :         if (hw->mac.type == ixgbe_mac_82598EB)
    4401                 :            :                 return;
    4402                 :            : 
    4403                 :          0 :         pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
    4404         [ #  # ]:          0 :         if (enable)
    4405                 :          0 :                 pfvfspoof |= (1 << vf_target_shift);
    4406                 :            :         else
    4407                 :          0 :                 pfvfspoof &= ~(1 << vf_target_shift);
    4408                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
    4409                 :            : }
    4410                 :            : 
    4411                 :            : /**
    4412                 :            :  * ixgbe_get_device_caps_generic - Get additional device capabilities
    4413                 :            :  * @hw: pointer to hardware structure
    4414                 :            :  * @device_caps: the EEPROM word with the extra device capabilities
    4415                 :            :  *
    4416                 :            :  * This function will read the EEPROM location for the device capabilities,
    4417                 :            :  * and return the word through device_caps.
    4418                 :            :  **/
    4419                 :          0 : s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
    4420                 :            : {
    4421                 :          0 :         DEBUGFUNC("ixgbe_get_device_caps_generic");
    4422                 :            : 
    4423                 :          0 :         hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
    4424                 :            : 
    4425                 :          0 :         return IXGBE_SUCCESS;
    4426                 :            : }
    4427                 :            : 
    4428                 :            : /**
    4429                 :            :  * ixgbe_enable_relaxed_ordering_gen2 - Enable relaxed ordering
    4430                 :            :  * @hw: pointer to hardware structure
    4431                 :            :  *
    4432                 :            :  **/
    4433                 :          0 : void ixgbe_enable_relaxed_ordering_gen2(struct ixgbe_hw *hw)
    4434                 :            : {
    4435                 :            :         u32 regval;
    4436                 :            :         u32 i;
    4437                 :            : 
    4438                 :          0 :         DEBUGFUNC("ixgbe_enable_relaxed_ordering_gen2");
    4439                 :            : 
    4440                 :            :         /* Enable relaxed ordering */
    4441         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_tx_queues; i++) {
    4442                 :          0 :                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
    4443                 :          0 :                 regval |= IXGBE_DCA_TXCTRL_DESC_WRO_EN;
    4444                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
    4445                 :            :         }
    4446                 :            : 
    4447         [ #  # ]:          0 :         for (i = 0; i < hw->mac.max_rx_queues; i++) {
    4448   [ #  #  #  # ]:          0 :                 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
    4449                 :          0 :                 regval |= IXGBE_DCA_RXCTRL_DATA_WRO_EN |
    4450                 :            :                           IXGBE_DCA_RXCTRL_HEAD_WRO_EN;
    4451                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
    4452                 :            :         }
    4453                 :            : 
    4454                 :          0 : }
    4455                 :            : 
    4456                 :            : /**
    4457                 :            :  * ixgbe_calculate_checksum - Calculate checksum for buffer
    4458                 :            :  * @buffer: pointer to EEPROM
    4459                 :            :  * @length: size of EEPROM to calculate a checksum for
    4460                 :            :  * Calculates the checksum for some buffer on a specified length.  The
    4461                 :            :  * checksum calculated is returned.
    4462                 :            :  **/
    4463                 :          0 : u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
    4464                 :            : {
    4465                 :            :         u32 i;
    4466                 :            :         u8 sum = 0;
    4467                 :            : 
    4468                 :          0 :         DEBUGFUNC("ixgbe_calculate_checksum");
    4469                 :            : 
    4470         [ #  # ]:          0 :         if (!buffer)
    4471                 :            :                 return 0;
    4472                 :            : 
    4473         [ #  # ]:          0 :         for (i = 0; i < length; i++)
    4474                 :          0 :                 sum += buffer[i];
    4475                 :            : 
    4476                 :          0 :         return (u8) (0 - sum);
    4477                 :            : }
    4478                 :            : 
    4479                 :            : /**
    4480                 :            :  * ixgbe_hic_unlocked - Issue command to manageability block unlocked
    4481                 :            :  * @hw: pointer to the HW structure
    4482                 :            :  * @buffer: command to write and where the return status will be placed
    4483                 :            :  * @length: length of buffer, must be multiple of 4 bytes
    4484                 :            :  * @timeout: time in ms to wait for command completion
    4485                 :            :  *
    4486                 :            :  * Communicates with the manageability block. On success return IXGBE_SUCCESS
    4487                 :            :  * else returns semaphore error when encountering an error acquiring
    4488                 :            :  * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
    4489                 :            :  *
    4490                 :            :  * This function assumes that the IXGBE_GSSR_SW_MNG_SM semaphore is held
    4491                 :            :  * by the caller.
    4492                 :            :  **/
    4493                 :          0 : s32 ixgbe_hic_unlocked(struct ixgbe_hw *hw, u32 *buffer, u32 length,
    4494                 :            :                        u32 timeout)
    4495                 :            : {
    4496                 :            :         u32 hicr, i, fwsts;
    4497                 :            :         u16 dword_len;
    4498                 :            : 
    4499                 :          0 :         DEBUGFUNC("ixgbe_hic_unlocked");
    4500                 :            : 
    4501         [ #  # ]:          0 :         if (!length || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
    4502                 :          0 :                 DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
    4503                 :          0 :                 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4504                 :            :         }
    4505                 :            : 
    4506                 :            :         /* Set bit 9 of FWSTS clearing FW reset indication */
    4507                 :          0 :         fwsts = IXGBE_READ_REG(hw, IXGBE_FWSTS);
    4508                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_FWSTS, fwsts | IXGBE_FWSTS_FWRI);
    4509                 :            : 
    4510                 :            :         /* Check that the host interface is enabled. */
    4511                 :          0 :         hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
    4512         [ #  # ]:          0 :         if (!(hicr & IXGBE_HICR_EN)) {
    4513                 :          0 :                 DEBUGOUT("IXGBE_HOST_EN bit disabled.\n");
    4514                 :          0 :                 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4515                 :            :         }
    4516                 :            : 
    4517                 :            :         /* Calculate length in DWORDs. We must be DWORD aligned */
    4518         [ #  # ]:          0 :         if (length % sizeof(u32)) {
    4519                 :          0 :                 DEBUGOUT("Buffer length failure, not aligned to dword");
    4520                 :          0 :                 return IXGBE_ERR_INVALID_ARGUMENT;
    4521                 :            :         }
    4522                 :            : 
    4523                 :          0 :         dword_len = length >> 2;
    4524                 :            : 
    4525                 :            :         /* The device driver writes the relevant command block
    4526                 :            :          * into the ram area.
    4527                 :            :          */
    4528         [ #  # ]:          0 :         for (i = 0; i < dword_len; i++)
    4529                 :          0 :                 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
    4530                 :            :                                       i, IXGBE_CPU_TO_LE32(buffer[i]));
    4531                 :            : 
    4532                 :            :         /* Setting this bit tells the ARC that a new command is pending. */
    4533                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
    4534                 :            : 
    4535         [ #  # ]:          0 :         for (i = 0; i < timeout; i++) {
    4536                 :          0 :                 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
    4537         [ #  # ]:          0 :                 if (!(hicr & IXGBE_HICR_C))
    4538                 :            :                         break;
    4539                 :          0 :                 msec_delay(1);
    4540                 :            :         }
    4541                 :            : 
    4542                 :            :         /* For each command except "Apply Update" perform
    4543                 :            :          * status checks in the HICR registry.
    4544                 :            :          */
    4545         [ #  # ]:          0 :         if ((buffer[0] & IXGBE_HOST_INTERFACE_MASK_CMD) ==
    4546                 :            :             IXGBE_HOST_INTERFACE_APPLY_UPDATE_CMD)
    4547                 :            :                 return IXGBE_SUCCESS;
    4548                 :            : 
    4549                 :            :         /* Check command completion */
    4550         [ #  # ]:          0 :         if ((timeout && i == timeout) ||
    4551         [ #  # ]:          0 :             !(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV)) {
    4552                 :          0 :                 ERROR_REPORT1(IXGBE_ERROR_CAUTION,
    4553                 :            :                               "Command has failed with no status valid.\n");
    4554                 :          0 :                 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4555                 :            :         }
    4556                 :            : 
    4557                 :            :         return IXGBE_SUCCESS;
    4558                 :            : }
    4559                 :            : 
    4560                 :            : /**
    4561                 :            :  * ixgbe_host_interface_command - Issue command to manageability block
    4562                 :            :  * @hw: pointer to the HW structure
    4563                 :            :  * @buffer: contains the command to write and where the return status will
    4564                 :            :  *  be placed
    4565                 :            :  * @length: length of buffer, must be multiple of 4 bytes
    4566                 :            :  * @timeout: time in ms to wait for command completion
    4567                 :            :  * @return_data: read and return data from the buffer (true) or not (false)
    4568                 :            :  *  Needed because FW structures are big endian and decoding of
    4569                 :            :  *  these fields can be 8 bit or 16 bit based on command. Decoding
    4570                 :            :  *  is not easily understood without making a table of commands.
    4571                 :            :  *  So we will leave this up to the caller to read back the data
    4572                 :            :  *  in these cases.
    4573                 :            :  *
    4574                 :            :  * Communicates with the manageability block. On success return IXGBE_SUCCESS
    4575                 :            :  * else returns semaphore error when encountering an error acquiring
    4576                 :            :  * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
    4577                 :            :  **/
    4578                 :          0 : s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
    4579                 :            :                                  u32 length, u32 timeout, bool return_data)
    4580                 :            : {
    4581                 :            :         u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
    4582                 :            :         struct ixgbe_hic_hdr *resp = (struct ixgbe_hic_hdr *)buffer;
    4583                 :            :         u16 buf_len;
    4584                 :            :         s32 status;
    4585                 :            :         u32 bi;
    4586                 :            :         u32 dword_len;
    4587                 :            : 
    4588                 :          0 :         DEBUGFUNC("ixgbe_host_interface_command");
    4589                 :            : 
    4590         [ #  # ]:          0 :         if (length == 0 || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
    4591                 :          0 :                 DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
    4592                 :          0 :                 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4593                 :            :         }
    4594                 :            : 
    4595                 :            :         /* Take management host interface semaphore */
    4596                 :          0 :         status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
    4597         [ #  # ]:          0 :         if (status)
    4598                 :            :                 return status;
    4599                 :            : 
    4600                 :          0 :         status = ixgbe_hic_unlocked(hw, buffer, length, timeout);
    4601         [ #  # ]:          0 :         if (status)
    4602                 :          0 :                 goto rel_out;
    4603                 :            : 
    4604         [ #  # ]:          0 :         if (!return_data)
    4605                 :          0 :                 goto rel_out;
    4606                 :            : 
    4607                 :            :         /* Calculate length in DWORDs */
    4608                 :            :         dword_len = hdr_size >> 2;
    4609                 :            : 
    4610                 :            :         /* first pull in the header so we know the buffer length */
    4611         [ #  # ]:          0 :         for (bi = 0; bi < dword_len; bi++) {
    4612                 :          0 :                 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
    4613                 :            :                 IXGBE_LE32_TO_CPUS((uintptr_t)&buffer[bi]);
    4614                 :            :         }
    4615                 :            : 
    4616                 :            :         /*
    4617                 :            :          * If there is any thing in data position pull it in
    4618                 :            :          * Read Flash command requires reading buffer length from
    4619                 :            :          * two byes instead of one byte
    4620                 :            :          */
    4621         [ #  # ]:          0 :         if (resp->cmd == IXGBE_HOST_INTERFACE_FLASH_READ_CMD ||
    4622                 :            :             resp->cmd == IXGBE_HOST_INTERFACE_SHADOW_RAM_READ_CMD) {
    4623         [ #  # ]:          0 :                 for (; bi < dword_len + 2; bi++) {
    4624                 :          0 :                         buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
    4625                 :            :                                                           bi);
    4626                 :            :                         IXGBE_LE32_TO_CPUS(&buffer[bi]);
    4627                 :            :                 }
    4628                 :          0 :                 buf_len = (((u16)(resp->cmd_or_resp.ret_status) << 3)
    4629                 :          0 :                                   & 0xF00) | resp->buf_len;
    4630                 :            :                 hdr_size += (2 << 2);
    4631                 :            :         } else {
    4632                 :          0 :                 buf_len = resp->buf_len;
    4633                 :            :         }
    4634         [ #  # ]:          0 :         if (!buf_len)
    4635                 :          0 :                 goto rel_out;
    4636                 :            : 
    4637         [ #  # ]:          0 :         if (length < buf_len + hdr_size) {
    4638                 :          0 :                 DEBUGOUT("Buffer not large enough for reply message.\n");
    4639                 :            :                 status = IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4640                 :          0 :                 goto rel_out;
    4641                 :            :         }
    4642                 :            : 
    4643                 :            :         /* Calculate length in DWORDs, add 3 for odd lengths */
    4644                 :          0 :         dword_len = (buf_len + 3) >> 2;
    4645                 :            : 
    4646                 :            :         /* Pull in the rest of the buffer (bi is where we left off) */
    4647         [ #  # ]:          0 :         for (; bi <= dword_len; bi++) {
    4648                 :          0 :                 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
    4649                 :            :                 IXGBE_LE32_TO_CPUS((uintptr_t)&buffer[bi]);
    4650                 :            :         }
    4651                 :            : 
    4652                 :          0 : rel_out:
    4653                 :          0 :         hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
    4654                 :            : 
    4655                 :          0 :         return status;
    4656                 :            : }
    4657                 :            : 
    4658                 :            : /**
    4659                 :            :  * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
    4660                 :            :  * @hw: pointer to the HW structure
    4661                 :            :  * @maj: driver version major number
    4662                 :            :  * @min: driver version minor number
    4663                 :            :  * @build: driver version build number
    4664                 :            :  * @sub: driver version sub build number
    4665                 :            :  * @len: unused
    4666                 :            :  * @driver_ver: unused
    4667                 :            :  *
    4668                 :            :  * Sends driver version number to firmware through the manageability
    4669                 :            :  * block.  On success return IXGBE_SUCCESS
    4670                 :            :  * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
    4671                 :            :  * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
    4672                 :            :  **/
    4673                 :          0 : s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
    4674                 :            :                                  u8 build, u8 sub, u16 len,
    4675                 :            :                                  const char *driver_ver)
    4676                 :            : {
    4677                 :            :         struct ixgbe_hic_drv_info fw_cmd;
    4678                 :            :         int i;
    4679                 :            :         s32 ret_val = IXGBE_SUCCESS;
    4680                 :            : 
    4681                 :          0 :         DEBUGFUNC("ixgbe_set_fw_drv_ver_generic");
    4682                 :            :         UNREFERENCED_2PARAMETER(len, driver_ver);
    4683                 :            : 
    4684                 :          0 :         fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
    4685                 :          0 :         fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
    4686                 :          0 :         fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
    4687                 :          0 :         fw_cmd.port_num = (u8)hw->bus.func;
    4688                 :          0 :         fw_cmd.ver_maj = maj;
    4689                 :          0 :         fw_cmd.ver_min = min;
    4690                 :          0 :         fw_cmd.ver_build = build;
    4691                 :          0 :         fw_cmd.ver_sub = sub;
    4692                 :          0 :         fw_cmd.hdr.checksum = 0;
    4693                 :          0 :         fw_cmd.pad = 0;
    4694                 :          0 :         fw_cmd.pad2 = 0;
    4695                 :          0 :         fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
    4696                 :            :                                 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
    4697                 :            : 
    4698         [ #  # ]:          0 :         for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
    4699                 :          0 :                 ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
    4700                 :            :                                                        sizeof(fw_cmd),
    4701                 :            :                                                        IXGBE_HI_COMMAND_TIMEOUT,
    4702                 :            :                                                        true);
    4703         [ #  # ]:          0 :                 if (ret_val != IXGBE_SUCCESS)
    4704                 :            :                         continue;
    4705                 :            : 
    4706         [ #  # ]:          0 :                 if (fw_cmd.hdr.cmd_or_resp.ret_status ==
    4707                 :            :                     FW_CEM_RESP_STATUS_SUCCESS)
    4708                 :            :                         ret_val = IXGBE_SUCCESS;
    4709                 :            :                 else
    4710                 :            :                         ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
    4711                 :            : 
    4712                 :            :                 break;
    4713                 :            :         }
    4714                 :            : 
    4715                 :          0 :         return ret_val;
    4716                 :            : }
    4717                 :            : 
    4718                 :            : /**
    4719                 :            :  * ixgbe_set_rxpba_generic - Initialize Rx packet buffer
    4720                 :            :  * @hw: pointer to hardware structure
    4721                 :            :  * @num_pb: number of packet buffers to allocate
    4722                 :            :  * @headroom: reserve n KB of headroom
    4723                 :            :  * @strategy: packet buffer allocation strategy
    4724                 :            :  **/
    4725                 :          0 : void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb, u32 headroom,
    4726                 :            :                              int strategy)
    4727                 :            : {
    4728                 :          0 :         u32 pbsize = hw->mac.rx_pb_size;
    4729                 :            :         int i = 0;
    4730                 :            :         u32 rxpktsize, txpktsize, txpbthresh;
    4731                 :            : 
    4732                 :            :         /* Reserve headroom */
    4733                 :          0 :         pbsize -= headroom;
    4734                 :            : 
    4735         [ #  # ]:          0 :         if (!num_pb)
    4736                 :            :                 num_pb = 1;
    4737                 :            : 
    4738                 :            :         /* Divide remaining packet buffer space amongst the number of packet
    4739                 :            :          * buffers requested using supplied strategy.
    4740                 :            :          */
    4741      [ #  #  # ]:          0 :         switch (strategy) {
    4742                 :          0 :         case PBA_STRATEGY_WEIGHTED:
    4743                 :            :                 /* ixgbe_dcb_pba_80_48 strategy weight first half of packet
    4744                 :            :                  * buffer with 5/8 of the packet buffer space.
    4745                 :            :                  */
    4746                 :          0 :                 rxpktsize = (pbsize * 5) / (num_pb * 4);
    4747                 :          0 :                 pbsize -= rxpktsize * (num_pb / 2);
    4748                 :          0 :                 rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
    4749         [ #  # ]:          0 :                 for (; i < (num_pb / 2); i++)
    4750                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
    4751                 :          0 :                 rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
    4752         [ #  # ]:          0 :                 for (; i < num_pb; i++)
    4753                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
    4754                 :            :                 break;
    4755                 :          0 :         case PBA_STRATEGY_EQUAL:
    4756                 :          0 :                 rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
    4757         [ #  # ]:          0 :                 for (; i < num_pb; i++)
    4758                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
    4759                 :            :                 break;
    4760                 :            :         default:
    4761                 :            :                 break;
    4762                 :            :         }
    4763                 :            : 
    4764                 :            :         /* Only support an equally distributed Tx packet buffer strategy. */
    4765                 :          0 :         txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
    4766                 :          0 :         txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
    4767         [ #  # ]:          0 :         for (i = 0; i < num_pb; i++) {
    4768                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
    4769                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
    4770                 :            :         }
    4771                 :            : 
    4772                 :            :         /* Clear unused TCs, if any, to zero buffer size*/
    4773         [ #  # ]:          0 :         for (; i < IXGBE_MAX_PB; i++) {
    4774                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
    4775                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
    4776                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
    4777                 :            :         }
    4778                 :          0 : }
    4779                 :            : 
    4780                 :            : /**
    4781                 :            :  * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
    4782                 :            :  * @hw: pointer to the hardware structure
    4783                 :            :  *
    4784                 :            :  * The 82599 and x540 MACs can experience issues if TX work is still pending
    4785                 :            :  * when a reset occurs.  This function prevents this by flushing the PCIe
    4786                 :            :  * buffers on the system.
    4787                 :            :  **/
    4788                 :          0 : void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
    4789                 :            : {
    4790                 :            :         u32 gcr_ext, hlreg0, i, poll;
    4791                 :            :         u16 value;
    4792                 :            : 
    4793                 :            :         /*
    4794                 :            :          * If double reset is not requested then all transactions should
    4795                 :            :          * already be clear and as such there is no work to do
    4796                 :            :          */
    4797         [ #  # ]:          0 :         if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
    4798                 :            :                 return;
    4799                 :            : 
    4800                 :            :         /*
    4801                 :            :          * Set loopback enable to prevent any transmits from being sent
    4802                 :            :          * should the link come up.  This assumes that the RXCTRL.RXEN bit
    4803                 :            :          * has already been cleared.
    4804                 :            :          */
    4805                 :          0 :         hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
    4806                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
    4807                 :            : 
    4808                 :            :         /* Wait for a last completion before clearing buffers */
    4809                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    4810                 :          0 :         msec_delay(3);
    4811                 :            : 
    4812                 :            :         /*
    4813                 :            :          * Before proceeding, make sure that the PCIe block does not have
    4814                 :            :          * transactions pending.
    4815                 :            :          */
    4816                 :            :         poll = ixgbe_pcie_timeout_poll(hw);
    4817                 :            :         for (i = 0; i < poll; i++) {
    4818                 :          0 :                 usec_delay(100);
    4819                 :            :                 value = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS);
    4820                 :            :                 if (IXGBE_REMOVED(hw->hw_addr))
    4821                 :            :                         goto out;
    4822                 :            :                 if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
    4823                 :          0 :                         goto out;
    4824                 :            :         }
    4825                 :            : 
    4826                 :            : out:
    4827                 :            :         /* initiate cleaning flow for buffers in the PCIe transaction layer */
    4828                 :          0 :         gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
    4829                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
    4830                 :            :                         gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
    4831                 :            : 
    4832                 :            :         /* Flush all writes and allow 20usec for all transactions to clear */
    4833                 :          0 :         IXGBE_WRITE_FLUSH(hw);
    4834                 :          0 :         usec_delay(20);
    4835                 :            : 
    4836                 :            :         /* restore previous register values */
    4837                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
    4838                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
    4839                 :            : }
    4840                 :            : 
    4841                 :            : STATIC const u8 ixgbe_emc_temp_data[4] = {
    4842                 :            :         IXGBE_EMC_INTERNAL_DATA,
    4843                 :            :         IXGBE_EMC_DIODE1_DATA,
    4844                 :            :         IXGBE_EMC_DIODE2_DATA,
    4845                 :            :         IXGBE_EMC_DIODE3_DATA
    4846                 :            : };
    4847                 :            : STATIC const u8 ixgbe_emc_therm_limit[4] = {
    4848                 :            :         IXGBE_EMC_INTERNAL_THERM_LIMIT,
    4849                 :            :         IXGBE_EMC_DIODE1_THERM_LIMIT,
    4850                 :            :         IXGBE_EMC_DIODE2_THERM_LIMIT,
    4851                 :            :         IXGBE_EMC_DIODE3_THERM_LIMIT
    4852                 :            : };
    4853                 :            : 
    4854                 :            : /**
    4855                 :            :  * ixgbe_get_thermal_sensor_data_generic - Gathers thermal sensor data
    4856                 :            :  * @hw: pointer to hardware structure
    4857                 :            :  *
    4858                 :            :  * Returns the thermal sensor data structure
    4859                 :            :  **/
    4860                 :          0 : s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
    4861                 :            : {
    4862                 :            :         s32 status = IXGBE_SUCCESS;
    4863                 :            :         u16 ets_offset;
    4864                 :            :         u16 ets_cfg;
    4865                 :            :         u16 ets_sensor;
    4866                 :            :         u8  num_sensors;
    4867                 :            :         u8  sensor_index;
    4868                 :            :         u8  sensor_location;
    4869                 :            :         u8  i;
    4870                 :            :         struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
    4871                 :            : 
    4872                 :          0 :         DEBUGFUNC("ixgbe_get_thermal_sensor_data_generic");
    4873                 :            : 
    4874                 :            :         /* Only support thermal sensors attached to 82599 physical port 0 */
    4875         [ #  # ]:          0 :         if ((hw->mac.type != ixgbe_mac_82599EB) ||
    4876         [ #  # ]:          0 :             (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
    4877                 :            :                 status = IXGBE_NOT_IMPLEMENTED;
    4878                 :          0 :                 goto out;
    4879                 :            :         }
    4880                 :            : 
    4881                 :          0 :         status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, &ets_offset);
    4882         [ #  # ]:          0 :         if (status)
    4883                 :          0 :                 goto out;
    4884                 :            : 
    4885         [ #  # ]:          0 :         if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF)) {
    4886                 :            :                 status = IXGBE_NOT_IMPLEMENTED;
    4887                 :          0 :                 goto out;
    4888                 :            :         }
    4889                 :            : 
    4890                 :          0 :         status = hw->eeprom.ops.read(hw, ets_offset, &ets_cfg);
    4891         [ #  # ]:          0 :         if (status)
    4892                 :          0 :                 goto out;
    4893                 :            : 
    4894         [ #  # ]:          0 :         if (((ets_cfg & IXGBE_ETS_TYPE_MASK) >> IXGBE_ETS_TYPE_SHIFT)
    4895                 :            :                 != IXGBE_ETS_TYPE_EMC) {
    4896                 :            :                 status = IXGBE_NOT_IMPLEMENTED;
    4897                 :          0 :                 goto out;
    4898                 :            :         }
    4899                 :            : 
    4900                 :          0 :         num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
    4901         [ #  # ]:          0 :         if (num_sensors > IXGBE_MAX_SENSORS)
    4902                 :            :                 num_sensors = IXGBE_MAX_SENSORS;
    4903                 :            : 
    4904         [ #  # ]:          0 :         for (i = 0; i < num_sensors; i++) {
    4905                 :          0 :                 status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
    4906                 :            :                                              &ets_sensor);
    4907         [ #  # ]:          0 :                 if (status)
    4908                 :          0 :                         goto out;
    4909                 :            : 
    4910                 :          0 :                 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
    4911                 :            :                                 IXGBE_ETS_DATA_INDEX_SHIFT);
    4912                 :          0 :                 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
    4913                 :            :                                    IXGBE_ETS_DATA_LOC_SHIFT);
    4914                 :            : 
    4915         [ #  # ]:          0 :                 if (sensor_location != 0) {
    4916                 :          0 :                         status = hw->phy.ops.read_i2c_byte(hw,
    4917                 :          0 :                                         ixgbe_emc_temp_data[sensor_index],
    4918                 :            :                                         IXGBE_I2C_THERMAL_SENSOR_ADDR,
    4919                 :          0 :                                         &data->sensor[i].temp);
    4920         [ #  # ]:          0 :                         if (status)
    4921                 :          0 :                                 goto out;
    4922                 :            :                 }
    4923                 :            :         }
    4924                 :          0 : out:
    4925                 :          0 :         return status;
    4926                 :            : }
    4927                 :            : 
    4928                 :            : /**
    4929                 :            :  * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
    4930                 :            :  * @hw: pointer to hardware structure
    4931                 :            :  *
    4932                 :            :  * Inits the thermal sensor thresholds according to the NVM map
    4933                 :            :  * and save off the threshold and location values into mac.thermal_sensor_data
    4934                 :            :  **/
    4935                 :          0 : s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
    4936                 :            : {
    4937                 :            :         s32 status = IXGBE_SUCCESS;
    4938                 :            :         u16 offset;
    4939                 :            :         u16 ets_offset;
    4940                 :            :         u16 ets_cfg;
    4941                 :            :         u16 ets_sensor;
    4942                 :            :         u8  low_thresh_delta;
    4943                 :            :         u8  num_sensors;
    4944                 :            :         u8  sensor_index;
    4945                 :            :         u8  sensor_location;
    4946                 :            :         u8  therm_limit;
    4947                 :            :         u8  i;
    4948                 :          0 :         struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
    4949                 :            : 
    4950                 :          0 :         DEBUGFUNC("ixgbe_init_thermal_sensor_thresh_generic");
    4951                 :            : 
    4952                 :            :         memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
    4953                 :            : 
    4954                 :            :         /* Only support thermal sensors attached to 82599 physical port 0 */
    4955         [ #  # ]:          0 :         if ((hw->mac.type != ixgbe_mac_82599EB) ||
    4956         [ #  # ]:          0 :             (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1))
    4957                 :          0 :                 return IXGBE_NOT_IMPLEMENTED;
    4958                 :            : 
    4959                 :            :         offset = IXGBE_ETS_CFG;
    4960         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, &ets_offset))
    4961                 :          0 :                 goto eeprom_err;
    4962         [ #  # ]:          0 :         if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
    4963                 :            :                 return IXGBE_NOT_IMPLEMENTED;
    4964                 :            : 
    4965                 :            :         offset = ets_offset;
    4966         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, offset, &ets_cfg))
    4967                 :          0 :                 goto eeprom_err;
    4968         [ #  # ]:          0 :         if (((ets_cfg & IXGBE_ETS_TYPE_MASK) >> IXGBE_ETS_TYPE_SHIFT)
    4969                 :            :                 != IXGBE_ETS_TYPE_EMC)
    4970                 :            :                 return IXGBE_NOT_IMPLEMENTED;
    4971                 :            : 
    4972                 :          0 :         low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
    4973                 :            :                              IXGBE_ETS_LTHRES_DELTA_SHIFT);
    4974                 :          0 :         num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
    4975                 :            : 
    4976         [ #  # ]:          0 :         for (i = 0; i < num_sensors; i++) {
    4977                 :          0 :                 offset = ets_offset + 1 + i;
    4978         [ #  # ]:          0 :                 if (hw->eeprom.ops.read(hw, offset, &ets_sensor)) {
    4979                 :          0 :                         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    4980                 :            :                                       "eeprom read at offset %d failed",
    4981                 :            :                                       offset);
    4982                 :          0 :                         continue;
    4983                 :            :                 }
    4984                 :          0 :                 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
    4985                 :            :                                 IXGBE_ETS_DATA_INDEX_SHIFT);
    4986                 :          0 :                 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
    4987                 :            :                                    IXGBE_ETS_DATA_LOC_SHIFT);
    4988                 :          0 :                 therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
    4989                 :            : 
    4990                 :          0 :                 hw->phy.ops.write_i2c_byte(hw,
    4991                 :          0 :                         ixgbe_emc_therm_limit[sensor_index],
    4992                 :            :                         IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
    4993                 :            : 
    4994         [ #  # ]:          0 :                 if ((i < IXGBE_MAX_SENSORS) && (sensor_location != 0)) {
    4995                 :          0 :                         data->sensor[i].location = sensor_location;
    4996                 :          0 :                         data->sensor[i].caution_thresh = therm_limit;
    4997                 :          0 :                         data->sensor[i].max_op_thresh = therm_limit -
    4998                 :            :                                                         low_thresh_delta;
    4999                 :            :                 }
    5000                 :            :         }
    5001                 :            :         return status;
    5002                 :            : 
    5003                 :          0 : eeprom_err:
    5004                 :          0 :         ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
    5005                 :            :                       "eeprom read at offset %d failed", offset);
    5006                 :          0 :         return IXGBE_NOT_IMPLEMENTED;
    5007                 :            : }
    5008                 :            : 
    5009                 :            : /**
    5010                 :            :  * ixgbe_get_orom_version - Return option ROM from EEPROM
    5011                 :            :  *
    5012                 :            :  * @hw: pointer to hardware structure
    5013                 :            :  * @nvm_ver: pointer to output structure
    5014                 :            :  *
    5015                 :            :  * if valid option ROM version, nvm_ver->or_valid set to true
    5016                 :            :  * else nvm_ver->or_valid is false.
    5017                 :            :  **/
    5018                 :          0 : void ixgbe_get_orom_version(struct ixgbe_hw *hw,
    5019                 :            :                             struct ixgbe_nvm_version *nvm_ver)
    5020                 :            : {
    5021                 :            :         u16 offset, eeprom_cfg_blkh, eeprom_cfg_blkl;
    5022                 :            : 
    5023                 :          0 :         nvm_ver->or_valid = false;
    5024                 :            :         /* Option Rom may or may not be present.  Start with pointer */
    5025                 :          0 :         hw->eeprom.ops.read(hw, NVM_OROM_OFFSET, &offset);
    5026                 :            : 
    5027                 :            :         /* make sure offset is valid */
    5028         [ #  # ]:          0 :         if ((offset == 0x0) || (offset == NVM_INVALID_PTR))
    5029                 :          0 :                 return;
    5030                 :            : 
    5031                 :          0 :         hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_HI, &eeprom_cfg_blkh);
    5032                 :          0 :         hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_LOW, &eeprom_cfg_blkl);
    5033                 :            : 
    5034                 :            :         /* option rom exists and is valid */
    5035   [ #  #  #  # ]:          0 :         if ((eeprom_cfg_blkl | eeprom_cfg_blkh) == 0x0 ||
    5036         [ #  # ]:          0 :             eeprom_cfg_blkl == NVM_VER_INVALID ||
    5037                 :            :             eeprom_cfg_blkh == NVM_VER_INVALID)
    5038                 :            :                 return;
    5039                 :            : 
    5040                 :          0 :         nvm_ver->or_valid = true;
    5041                 :          0 :         nvm_ver->or_major = eeprom_cfg_blkl >> NVM_OROM_SHIFT;
    5042                 :          0 :         nvm_ver->or_build = (eeprom_cfg_blkl << NVM_OROM_SHIFT) |
    5043                 :            :                             (eeprom_cfg_blkh >> NVM_OROM_SHIFT);
    5044                 :          0 :         nvm_ver->or_patch = eeprom_cfg_blkh & NVM_OROM_PATCH_MASK;
    5045                 :            : }
    5046                 :            : 
    5047                 :            : /**
    5048                 :            :  * ixgbe_get_oem_prod_version - Return OEM Product version
    5049                 :            :  *
    5050                 :            :  * @hw: pointer to hardware structure
    5051                 :            :  * @nvm_ver: pointer to output structure
    5052                 :            :  *
    5053                 :            :  * if valid OEM product version, nvm_ver->oem_valid set to true
    5054                 :            :  * else nvm_ver->oem_valid is false.
    5055                 :            :  **/
    5056                 :          0 : void ixgbe_get_oem_prod_version(struct ixgbe_hw *hw,
    5057                 :            :                                 struct ixgbe_nvm_version *nvm_ver)
    5058                 :            : {
    5059                 :            :         u16 rel_num, prod_ver, mod_len, cap, offset;
    5060                 :            : 
    5061                 :          0 :         nvm_ver->oem_valid = false;
    5062                 :          0 :         hw->eeprom.ops.read(hw, NVM_OEM_PROD_VER_PTR, &offset);
    5063                 :            : 
    5064                 :            :         /* Return is offset to OEM Product Version block is invalid */
    5065         [ #  # ]:          0 :         if (offset == 0x0 || offset == NVM_INVALID_PTR)
    5066                 :          0 :                 return;
    5067                 :            : 
    5068                 :            :         /* Read product version block */
    5069                 :          0 :         hw->eeprom.ops.read(hw, offset, &mod_len);
    5070                 :          0 :         hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_CAP_OFF, &cap);
    5071                 :            : 
    5072                 :            :         /* Return if OEM product version block is invalid */
    5073         [ #  # ]:          0 :         if (mod_len != NVM_OEM_PROD_VER_MOD_LEN ||
    5074         [ #  # ]:          0 :             (cap & NVM_OEM_PROD_VER_CAP_MASK) != 0x0)
    5075                 :            :                 return;
    5076                 :            : 
    5077                 :          0 :         hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_L, &prod_ver);
    5078                 :          0 :         hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_H, &rel_num);
    5079                 :            : 
    5080                 :            :         /* Return if version is invalid */
    5081   [ #  #  #  # ]:          0 :         if ((rel_num | prod_ver) == 0x0 ||
    5082         [ #  # ]:          0 :             rel_num == NVM_VER_INVALID || prod_ver == NVM_VER_INVALID)
    5083                 :            :                 return;
    5084                 :            : 
    5085                 :          0 :         nvm_ver->oem_major = prod_ver >> NVM_VER_SHIFT;
    5086                 :          0 :         nvm_ver->oem_minor = prod_ver & NVM_VER_MASK;
    5087                 :          0 :         nvm_ver->oem_release = rel_num;
    5088                 :          0 :         nvm_ver->oem_valid = true;
    5089                 :            : }
    5090                 :            : 
    5091                 :            : /**
    5092                 :            :  * ixgbe_get_etk_id - Return Etrack ID from EEPROM
    5093                 :            :  *
    5094                 :            :  * @hw: pointer to hardware structure
    5095                 :            :  * @nvm_ver: pointer to output structure
    5096                 :            :  *
    5097                 :            :  * word read errors will return 0xFFFF
    5098                 :            :  **/
    5099                 :          0 : void ixgbe_get_etk_id(struct ixgbe_hw *hw, struct ixgbe_nvm_version *nvm_ver)
    5100                 :            : {
    5101                 :            :         u16 etk_id_l, etk_id_h;
    5102                 :            : 
    5103         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_LOW, &etk_id_l))
    5104                 :          0 :                 etk_id_l = NVM_VER_INVALID;
    5105         [ #  # ]:          0 :         if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_HI, &etk_id_h))
    5106                 :          0 :                 etk_id_h = NVM_VER_INVALID;
    5107                 :            : 
    5108                 :            :         /* The word order for the version format is determined by high order
    5109                 :            :          * word bit 15.
    5110                 :            :          */
    5111         [ #  # ]:          0 :         if ((etk_id_h & NVM_ETK_VALID) == 0) {
    5112                 :          0 :                 nvm_ver->etk_id = etk_id_h;
    5113                 :          0 :                 nvm_ver->etk_id |= (etk_id_l << NVM_ETK_SHIFT);
    5114                 :            :         } else {
    5115                 :          0 :                 nvm_ver->etk_id = etk_id_l;
    5116                 :          0 :                 nvm_ver->etk_id |= (etk_id_h << NVM_ETK_SHIFT);
    5117                 :            :         }
    5118                 :          0 : }
    5119                 :            : 
    5120                 :            : 
    5121                 :            : /**
    5122                 :            :  * ixgbe_dcb_get_rtrup2tc_generic - read rtrup2tc reg
    5123                 :            :  * @hw: pointer to hardware structure
    5124                 :            :  * @map: pointer to u8 arr for returning map
    5125                 :            :  *
    5126                 :            :  * Read the rtrup2tc HW register and resolve its content into map
    5127                 :            :  **/
    5128                 :          0 : void ixgbe_dcb_get_rtrup2tc_generic(struct ixgbe_hw *hw, u8 *map)
    5129                 :            : {
    5130                 :            :         u32 reg, i;
    5131                 :            : 
    5132                 :          0 :         reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
    5133         [ #  # ]:          0 :         for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++)
    5134                 :          0 :                 map[i] = IXGBE_RTRUP2TC_UP_MASK &
    5135                 :          0 :                         (reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
    5136                 :          0 :         return;
    5137                 :            : }
    5138                 :            : 
    5139                 :          0 : void ixgbe_disable_rx_generic(struct ixgbe_hw *hw)
    5140                 :            : {
    5141                 :            :         u32 pfdtxgswc;
    5142                 :            :         u32 rxctrl;
    5143                 :            : 
    5144                 :          0 :         rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
    5145         [ #  # ]:          0 :         if (rxctrl & IXGBE_RXCTRL_RXEN) {
    5146         [ #  # ]:          0 :                 if (hw->mac.type != ixgbe_mac_82598EB) {
    5147                 :          0 :                         pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
    5148         [ #  # ]:          0 :                         if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
    5149                 :          0 :                                 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
    5150                 :          0 :                                 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
    5151                 :          0 :                                 hw->mac.set_lben = true;
    5152                 :            :                         } else {
    5153                 :          0 :                                 hw->mac.set_lben = false;
    5154                 :            :                         }
    5155                 :            :                 }
    5156                 :          0 :                 rxctrl &= ~IXGBE_RXCTRL_RXEN;
    5157                 :          0 :                 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
    5158                 :            :         }
    5159                 :          0 : }
    5160                 :            : 
    5161                 :          0 : void ixgbe_enable_rx_generic(struct ixgbe_hw *hw)
    5162                 :            : {
    5163                 :            :         u32 pfdtxgswc;
    5164                 :            :         u32 rxctrl;
    5165                 :            : 
    5166                 :          0 :         rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
    5167                 :          0 :         IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, (rxctrl | IXGBE_RXCTRL_RXEN));
    5168                 :            : 
    5169         [ #  # ]:          0 :         if (hw->mac.type != ixgbe_mac_82598EB) {
    5170         [ #  # ]:          0 :                 if (hw->mac.set_lben) {
    5171                 :          0 :                         pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
    5172                 :          0 :                         pfdtxgswc |= IXGBE_PFDTXGSWC_VT_LBEN;
    5173                 :          0 :                         IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
    5174                 :          0 :                         hw->mac.set_lben = false;
    5175                 :            :                 }
    5176                 :            :         }
    5177                 :          0 : }
    5178                 :            : 
    5179                 :            : /**
    5180                 :            :  * ixgbe_mng_present - returns true when management capability is present
    5181                 :            :  * @hw: pointer to hardware structure
    5182                 :            :  */
    5183                 :          0 : bool ixgbe_mng_present(struct ixgbe_hw *hw)
    5184                 :            : {
    5185                 :            :         u32 fwsm;
    5186                 :            : 
    5187         [ #  # ]:          0 :         if (hw->mac.type < ixgbe_mac_82599EB)
    5188                 :            :                 return false;
    5189                 :            : 
    5190                 :          0 :         fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw));
    5191                 :            : 
    5192                 :          0 :         return !!(fwsm & IXGBE_FWSM_FW_MODE_PT);
    5193                 :            : }
    5194                 :            : 
    5195                 :            : /**
    5196                 :            :  * ixgbe_mng_enabled - Is the manageability engine enabled?
    5197                 :            :  * @hw: pointer to hardware structure
    5198                 :            :  *
    5199                 :            :  * Returns true if the manageability engine is enabled.
    5200                 :            :  **/
    5201                 :          0 : bool ixgbe_mng_enabled(struct ixgbe_hw *hw)
    5202                 :            : {
    5203                 :            :         u32 fwsm, manc, factps;
    5204                 :            : 
    5205                 :          0 :         fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw));
    5206         [ #  # ]:          0 :         if ((fwsm & IXGBE_FWSM_MODE_MASK) != IXGBE_FWSM_FW_MODE_PT)
    5207                 :            :                 return false;
    5208                 :            : 
    5209                 :          0 :         manc = IXGBE_READ_REG(hw, IXGBE_MANC);
    5210         [ #  # ]:          0 :         if (!(manc & IXGBE_MANC_RCV_TCO_EN))
    5211                 :            :                 return false;
    5212                 :            : 
    5213         [ #  # ]:          0 :         if (hw->mac.type <= ixgbe_mac_X540) {
    5214                 :          0 :                 factps = IXGBE_READ_REG(hw, IXGBE_FACTPS_BY_MAC(hw));
    5215         [ #  # ]:          0 :                 if (factps & IXGBE_FACTPS_MNGCG)
    5216                 :          0 :                         return false;
    5217                 :            :         }
    5218                 :            : 
    5219                 :            :         return true;
    5220                 :            : }
    5221                 :            : 
    5222                 :            : /**
    5223                 :            :  * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
    5224                 :            :  * @hw: pointer to hardware structure
    5225                 :            :  * @speed: new link speed
    5226                 :            :  * @autoneg_wait_to_complete: true when waiting for completion is needed
    5227                 :            :  *
    5228                 :            :  * Set the link speed in the MAC and/or PHY register and restarts link.
    5229                 :            :  **/
    5230                 :          0 : s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
    5231                 :            :                                           ixgbe_link_speed speed,
    5232                 :            :                                           bool autoneg_wait_to_complete)
    5233                 :            : {
    5234                 :          0 :         ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
    5235                 :            :         ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
    5236                 :            :         s32 status = IXGBE_SUCCESS;
    5237                 :            :         u32 speedcnt = 0;
    5238                 :            :         u32 i = 0;
    5239                 :          0 :         bool autoneg, link_up = false;
    5240                 :            : 
    5241                 :          0 :         DEBUGFUNC("ixgbe_setup_mac_link_multispeed_fiber");
    5242                 :            : 
    5243                 :            :         /* Mask off requested but non-supported speeds */
    5244                 :          0 :         status = ixgbe_get_link_capabilities(hw, &link_speed, &autoneg);
    5245         [ #  # ]:          0 :         if (status != IXGBE_SUCCESS)
    5246                 :            :                 return status;
    5247                 :            : 
    5248                 :          0 :         speed &= link_speed;
    5249                 :            : 
    5250                 :            :         /* Try each speed one by one, highest priority first.  We do this in
    5251                 :            :          * software because 10Gb fiber doesn't support speed autonegotiation.
    5252                 :            :          */
    5253         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
    5254                 :            :                 speedcnt++;
    5255                 :            :                 highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
    5256                 :            : 
    5257                 :            :                 /* Set the module link speed */
    5258      [ #  #  # ]:          0 :                 switch (hw->phy.media_type) {
    5259                 :          0 :                 case ixgbe_media_type_fiber:
    5260                 :          0 :                         ixgbe_set_rate_select_speed(hw,
    5261                 :            :                                                     IXGBE_LINK_SPEED_10GB_FULL);
    5262                 :          0 :                         break;
    5263                 :            :                 case ixgbe_media_type_fiber_qsfp:
    5264                 :            :                         /* QSFP module automatically detects MAC link speed */
    5265                 :            :                         break;
    5266                 :          0 :                 default:
    5267                 :          0 :                         DEBUGOUT("Unexpected media type.\n");
    5268                 :          0 :                         break;
    5269                 :            :                 }
    5270                 :            : 
    5271                 :            :                 /* Allow module to change analog characteristics (1G->10G) */
    5272                 :          0 :                 msec_delay(40);
    5273                 :            : 
    5274                 :          0 :                 status = ixgbe_setup_mac_link(hw,
    5275                 :            :                                               IXGBE_LINK_SPEED_10GB_FULL,
    5276                 :            :                                               autoneg_wait_to_complete);
    5277         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    5278                 :            :                         return status;
    5279                 :            : 
    5280                 :            :                 /* Flap the Tx laser if it has not already been done */
    5281                 :          0 :                 ixgbe_flap_tx_laser(hw);
    5282                 :            : 
    5283                 :            :                 /* Wait for the controller to acquire link.  Per IEEE 802.3ap,
    5284                 :            :                  * Section 73.10.2, we may have to wait up to 1000ms if KR is
    5285                 :            :                  * attempted.  82599 uses the same timing for 10g SFI.
    5286                 :            :                  */
    5287         [ #  # ]:          0 :                 for (i = 0; i < 10; i++) {
    5288                 :            :                         /* Wait for the link partner to also set speed */
    5289                 :          0 :                         msec_delay(100);
    5290                 :            : 
    5291                 :            :                         /* If we have link, just jump out */
    5292                 :          0 :                         status = ixgbe_check_link(hw, &link_speed,
    5293                 :            :                                                   &link_up, false);
    5294         [ #  # ]:          0 :                         if (status != IXGBE_SUCCESS)
    5295                 :          0 :                                 return status;
    5296                 :            : 
    5297         [ #  # ]:          0 :                         if (link_up)
    5298                 :          0 :                                 goto out;
    5299                 :            :                 }
    5300                 :            :         }
    5301                 :            : 
    5302         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
    5303                 :          0 :                 speedcnt++;
    5304         [ #  # ]:          0 :                 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
    5305                 :            :                         highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
    5306                 :            : 
    5307                 :            :                 /* Set the module link speed */
    5308      [ #  #  # ]:          0 :                 switch (hw->phy.media_type) {
    5309                 :          0 :                 case ixgbe_media_type_fiber:
    5310                 :          0 :                         ixgbe_set_rate_select_speed(hw,
    5311                 :            :                                                     IXGBE_LINK_SPEED_1GB_FULL);
    5312                 :          0 :                         break;
    5313                 :            :                 case ixgbe_media_type_fiber_qsfp:
    5314                 :            :                         /* QSFP module automatically detects link speed */
    5315                 :            :                         break;
    5316                 :          0 :                 default:
    5317                 :          0 :                         DEBUGOUT("Unexpected media type.\n");
    5318                 :          0 :                         break;
    5319                 :            :                 }
    5320                 :            : 
    5321                 :            :                 /* Allow module to change analog characteristics (10G->1G) */
    5322                 :          0 :                 msec_delay(40);
    5323                 :            : 
    5324                 :          0 :                 status = ixgbe_setup_mac_link(hw,
    5325                 :            :                                               IXGBE_LINK_SPEED_1GB_FULL,
    5326                 :            :                                               autoneg_wait_to_complete);
    5327         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    5328                 :            :                         return status;
    5329                 :            : 
    5330                 :            :                 /* Flap the Tx laser if it has not already been done */
    5331                 :          0 :                 ixgbe_flap_tx_laser(hw);
    5332                 :            : 
    5333                 :            :                 /* Wait for the link partner to also set speed */
    5334                 :          0 :                 msec_delay(100);
    5335                 :            : 
    5336                 :            :                 /* If we have link, just jump out */
    5337                 :          0 :                 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
    5338         [ #  # ]:          0 :                 if (status != IXGBE_SUCCESS)
    5339                 :            :                         return status;
    5340                 :            : 
    5341         [ #  # ]:          0 :                 if (link_up)
    5342                 :          0 :                         goto out;
    5343                 :            :         }
    5344                 :            : 
    5345                 :            :         /* We didn't get link.  Configure back to the highest speed we tried,
    5346                 :            :          * (if there was more than one).  We call ourselves back with just the
    5347                 :            :          * single highest speed that the user requested.
    5348                 :            :          */
    5349         [ #  # ]:          0 :         if (speedcnt > 1)
    5350                 :          0 :                 status = ixgbe_setup_mac_link_multispeed_fiber(hw,
    5351                 :            :                                                       highest_link_speed,
    5352                 :            :                                                       autoneg_wait_to_complete);
    5353                 :            : 
    5354                 :          0 : out:
    5355                 :            :         /* Set autoneg_advertised value based on input link speed */
    5356                 :          0 :         hw->phy.autoneg_advertised = 0;
    5357                 :            : 
    5358         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_10GB_FULL)
    5359                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
    5360                 :            : 
    5361         [ #  # ]:          0 :         if (speed & IXGBE_LINK_SPEED_1GB_FULL)
    5362                 :          0 :                 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
    5363                 :            : 
    5364                 :            :         return status;
    5365                 :            : }
    5366                 :            : 
    5367                 :            : /**
    5368                 :            :  * ixgbe_set_soft_rate_select_speed - Set module link speed
    5369                 :            :  * @hw: pointer to hardware structure
    5370                 :            :  * @speed: link speed to set
    5371                 :            :  *
    5372                 :            :  * Set module link speed via the soft rate select.
    5373                 :            :  */
    5374                 :          0 : void ixgbe_set_soft_rate_select_speed(struct ixgbe_hw *hw,
    5375                 :            :                                         ixgbe_link_speed speed)
    5376                 :            : {
    5377                 :            :         s32 status;
    5378                 :            :         u8 rs, eeprom_data;
    5379                 :            : 
    5380      [ #  #  # ]:          0 :         switch (speed) {
    5381                 :            :         case IXGBE_LINK_SPEED_10GB_FULL:
    5382                 :            :                 /* one bit mask same as setting on */
    5383                 :            :                 rs = IXGBE_SFF_SOFT_RS_SELECT_10G;
    5384                 :            :                 break;
    5385                 :          0 :         case IXGBE_LINK_SPEED_1GB_FULL:
    5386                 :            :                 rs = IXGBE_SFF_SOFT_RS_SELECT_1G;
    5387                 :          0 :                 break;
    5388                 :          0 :         default:
    5389                 :          0 :                 DEBUGOUT("Invalid fixed module speed\n");
    5390                 :          0 :                 return;
    5391                 :            :         }
    5392                 :            : 
    5393                 :            :         /* Set RS0 */
    5394                 :          0 :         status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
    5395                 :            :                                            IXGBE_I2C_EEPROM_DEV_ADDR2,
    5396                 :            :                                            &eeprom_data);
    5397         [ #  # ]:          0 :         if (status) {
    5398                 :          0 :                 DEBUGOUT("Failed to read Rx Rate Select RS0\n");
    5399                 :          0 :                 goto out;
    5400                 :            :         }
    5401                 :            : 
    5402                 :          0 :         eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
    5403                 :            : 
    5404                 :          0 :         status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
    5405                 :            :                                             IXGBE_I2C_EEPROM_DEV_ADDR2,
    5406                 :            :                                             eeprom_data);
    5407         [ #  # ]:          0 :         if (status) {
    5408                 :          0 :                 DEBUGOUT("Failed to write Rx Rate Select RS0\n");
    5409                 :          0 :                 goto out;
    5410                 :            :         }
    5411                 :            : 
    5412                 :            :         /* Set RS1 */
    5413                 :          0 :         status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
    5414                 :            :                                            IXGBE_I2C_EEPROM_DEV_ADDR2,
    5415                 :            :                                            &eeprom_data);
    5416         [ #  # ]:          0 :         if (status) {
    5417                 :          0 :                 DEBUGOUT("Failed to read Rx Rate Select RS1\n");
    5418                 :          0 :                 goto out;
    5419                 :            :         }
    5420                 :            : 
    5421                 :          0 :         eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
    5422                 :            : 
    5423                 :          0 :         status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
    5424                 :            :                                             IXGBE_I2C_EEPROM_DEV_ADDR2,
    5425                 :            :                                             eeprom_data);
    5426         [ #  # ]:          0 :         if (status) {
    5427                 :          0 :                 DEBUGOUT("Failed to write Rx Rate Select RS1\n");
    5428                 :          0 :                 goto out;
    5429                 :            :         }
    5430                 :          0 : out:
    5431                 :            :         return;
    5432                 :            : }

Generated by: LCOV version 1.14