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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2001-2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : /* 82562G 10/100 Network Connection
       6                 :            :  * 82562G-2 10/100 Network Connection
       7                 :            :  * 82562GT 10/100 Network Connection
       8                 :            :  * 82562GT-2 10/100 Network Connection
       9                 :            :  * 82562V 10/100 Network Connection
      10                 :            :  * 82562V-2 10/100 Network Connection
      11                 :            :  * 82566DC-2 Gigabit Network Connection
      12                 :            :  * 82566DC Gigabit Network Connection
      13                 :            :  * 82566DM-2 Gigabit Network Connection
      14                 :            :  * 82566DM Gigabit Network Connection
      15                 :            :  * 82566MC Gigabit Network Connection
      16                 :            :  * 82566MM Gigabit Network Connection
      17                 :            :  * 82567LM Gigabit Network Connection
      18                 :            :  * 82567LF Gigabit Network Connection
      19                 :            :  * 82567V Gigabit Network Connection
      20                 :            :  * 82567LM-2 Gigabit Network Connection
      21                 :            :  * 82567LF-2 Gigabit Network Connection
      22                 :            :  * 82567V-2 Gigabit Network Connection
      23                 :            :  * 82567LF-3 Gigabit Network Connection
      24                 :            :  * 82567LM-3 Gigabit Network Connection
      25                 :            :  * 82567LM-4 Gigabit Network Connection
      26                 :            :  * 82577LM Gigabit Network Connection
      27                 :            :  * 82577LC Gigabit Network Connection
      28                 :            :  * 82578DM Gigabit Network Connection
      29                 :            :  * 82578DC Gigabit Network Connection
      30                 :            :  * 82579LM Gigabit Network Connection
      31                 :            :  * 82579V Gigabit Network Connection
      32                 :            :  * Ethernet Connection I217-LM
      33                 :            :  * Ethernet Connection I217-V
      34                 :            :  * Ethernet Connection I218-V
      35                 :            :  * Ethernet Connection I218-LM
      36                 :            :  * Ethernet Connection (2) I218-LM
      37                 :            :  * Ethernet Connection (2) I218-V
      38                 :            :  * Ethernet Connection (3) I218-LM
      39                 :            :  * Ethernet Connection (3) I218-V
      40                 :            :  */
      41                 :            : 
      42                 :            : #include "e1000_api.h"
      43                 :            : 
      44                 :            : STATIC s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
      45                 :            : STATIC s32  e1000_acquire_swflag_ich8lan(struct e1000_hw *hw);
      46                 :            : STATIC void e1000_release_swflag_ich8lan(struct e1000_hw *hw);
      47                 :            : STATIC s32  e1000_acquire_nvm_ich8lan(struct e1000_hw *hw);
      48                 :            : STATIC void e1000_release_nvm_ich8lan(struct e1000_hw *hw);
      49                 :            : STATIC bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
      50                 :            : STATIC bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
      51                 :            : STATIC int  e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
      52                 :            : STATIC int  e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
      53                 :            : STATIC s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw);
      54                 :            : STATIC void e1000_update_mc_addr_list_pch2lan(struct e1000_hw *hw,
      55                 :            :                                               u8 *mc_addr_list,
      56                 :            :                                               u32 mc_addr_count);
      57                 :            : STATIC s32  e1000_check_reset_block_ich8lan(struct e1000_hw *hw);
      58                 :            : STATIC s32  e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw);
      59                 :            : STATIC s32  e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
      60                 :            : STATIC s32  e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw,
      61                 :            :                                             bool active);
      62                 :            : STATIC s32  e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,
      63                 :            :                                             bool active);
      64                 :            : STATIC s32  e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
      65                 :            :                                    u16 words, u16 *data);
      66                 :            : STATIC s32  e1000_read_nvm_spt(struct e1000_hw *hw, u16 offset, u16 words,
      67                 :            :                                u16 *data);
      68                 :            : STATIC s32  e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
      69                 :            :                                     u16 words, u16 *data);
      70                 :            : STATIC s32  e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw);
      71                 :            : STATIC s32  e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw);
      72                 :            : STATIC s32  e1000_update_nvm_checksum_spt(struct e1000_hw *hw);
      73                 :            : STATIC s32  e1000_valid_led_default_ich8lan(struct e1000_hw *hw,
      74                 :            :                                             u16 *data);
      75                 :            : STATIC s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
      76                 :            : STATIC s32  e1000_get_bus_info_ich8lan(struct e1000_hw *hw);
      77                 :            : STATIC s32  e1000_reset_hw_ich8lan(struct e1000_hw *hw);
      78                 :            : STATIC s32  e1000_init_hw_ich8lan(struct e1000_hw *hw);
      79                 :            : STATIC s32  e1000_setup_link_ich8lan(struct e1000_hw *hw);
      80                 :            : STATIC s32  e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
      81                 :            : STATIC s32  e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
      82                 :            : STATIC s32  e1000_get_link_up_info_ich8lan(struct e1000_hw *hw,
      83                 :            :                                            u16 *speed, u16 *duplex);
      84                 :            : STATIC s32  e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
      85                 :            : STATIC s32  e1000_led_on_ich8lan(struct e1000_hw *hw);
      86                 :            : STATIC s32  e1000_led_off_ich8lan(struct e1000_hw *hw);
      87                 :            : STATIC s32  e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
      88                 :            : STATIC s32  e1000_setup_led_pchlan(struct e1000_hw *hw);
      89                 :            : STATIC s32  e1000_cleanup_led_pchlan(struct e1000_hw *hw);
      90                 :            : STATIC s32  e1000_led_on_pchlan(struct e1000_hw *hw);
      91                 :            : STATIC s32  e1000_led_off_pchlan(struct e1000_hw *hw);
      92                 :            : STATIC void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
      93                 :            : STATIC s32  e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
      94                 :            : STATIC void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
      95                 :            : STATIC s32  e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
      96                 :            : STATIC s32  e1000_read_flash_byte_ich8lan(struct e1000_hw *hw,
      97                 :            :                                           u32 offset, u8 *data);
      98                 :            : STATIC s32  e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
      99                 :            :                                           u8 size, u16 *data);
     100                 :            : STATIC s32  e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
     101                 :            :                                             u32 *data);
     102                 :            : STATIC s32  e1000_read_flash_dword_ich8lan(struct e1000_hw *hw,
     103                 :            :                                            u32 offset, u32 *data);
     104                 :            : STATIC s32  e1000_write_flash_data32_ich8lan(struct e1000_hw *hw,
     105                 :            :                                              u32 offset, u32 data);
     106                 :            : STATIC s32  e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
     107                 :            :                                                   u32 offset, u32 dword);
     108                 :            : STATIC s32  e1000_read_flash_word_ich8lan(struct e1000_hw *hw,
     109                 :            :                                           u32 offset, u16 *data);
     110                 :            : STATIC s32  e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
     111                 :            :                                                  u32 offset, u8 byte);
     112                 :            : STATIC s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
     113                 :            : STATIC void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
     114                 :            : STATIC s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw);
     115                 :            : STATIC s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
     116                 :            : STATIC s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
     117                 :            : STATIC void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
     118                 :            : 
     119                 :            : /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
     120                 :            : /* Offset 04h HSFSTS */
     121                 :            : union ich8_hws_flash_status {
     122                 :            :         struct ich8_hsfsts {
     123                 :            :                 u16 flcdone:1; /* bit 0 Flash Cycle Done */
     124                 :            :                 u16 flcerr:1; /* bit 1 Flash Cycle Error */
     125                 :            :                 u16 dael:1; /* bit 2 Direct Access error Log */
     126                 :            :                 u16 berasesz:2; /* bit 4:3 Sector Erase Size */
     127                 :            :                 u16 flcinprog:1; /* bit 5 flash cycle in Progress */
     128                 :            :                 u16 reserved1:2; /* bit 13:6 Reserved */
     129                 :            :                 u16 reserved2:6; /* bit 13:6 Reserved */
     130                 :            :                 u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
     131                 :            :                 u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
     132                 :            :         } hsf_status;
     133                 :            :         u16 regval;
     134                 :            : };
     135                 :            : 
     136                 :            : /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
     137                 :            : /* Offset 06h FLCTL */
     138                 :            : union ich8_hws_flash_ctrl {
     139                 :            :         struct ich8_hsflctl {
     140                 :            :                 u16 flcgo:1;   /* 0 Flash Cycle Go */
     141                 :            :                 u16 flcycle:2;   /* 2:1 Flash Cycle */
     142                 :            :                 u16 reserved:5;   /* 7:3 Reserved  */
     143                 :            :                 u16 fldbcount:2;   /* 9:8 Flash Data Byte Count */
     144                 :            :                 u16 flockdn:6;   /* 15:10 Reserved */
     145                 :            :         } hsf_ctrl;
     146                 :            :         u16 regval;
     147                 :            : };
     148                 :            : 
     149                 :            : /* ICH Flash Region Access Permissions */
     150                 :            : union ich8_hws_flash_regacc {
     151                 :            :         struct ich8_flracc {
     152                 :            :                 u32 grra:8; /* 0:7 GbE region Read Access */
     153                 :            :                 u32 grwa:8; /* 8:15 GbE region Write Access */
     154                 :            :                 u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
     155                 :            :                 u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
     156                 :            :         } hsf_flregacc;
     157                 :            :         u16 regval;
     158                 :            : };
     159                 :            : 
     160                 :            : /**
     161                 :            :  *  e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
     162                 :            :  *  @hw: pointer to the HW structure
     163                 :            :  *
     164                 :            :  *  Test access to the PHY registers by reading the PHY ID registers.  If
     165                 :            :  *  the PHY ID is already known (e.g. resume path) compare it with known ID,
     166                 :            :  *  otherwise assume the read PHY ID is correct if it is valid.
     167                 :            :  *
     168                 :            :  *  Assumes the sw/fw/hw semaphore is already acquired.
     169                 :            :  **/
     170                 :          0 : STATIC bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
     171                 :            : {
     172                 :          0 :         u16 phy_reg = 0;
     173                 :            :         u32 phy_id = 0;
     174                 :            :         s32 ret_val = 0;
     175                 :            :         u16 retry_count;
     176                 :            :         u32 mac_reg = 0;
     177                 :            : 
     178         [ #  # ]:          0 :         for (retry_count = 0; retry_count < 2; retry_count++) {
     179                 :          0 :                 ret_val = hw->phy.ops.read_reg_locked(hw, PHY_ID1, &phy_reg);
     180   [ #  #  #  # ]:          0 :                 if (ret_val || (phy_reg == 0xFFFF))
     181                 :          0 :                         continue;
     182                 :          0 :                 phy_id = (u32)(phy_reg << 16);
     183                 :            : 
     184                 :          0 :                 ret_val = hw->phy.ops.read_reg_locked(hw, PHY_ID2, &phy_reg);
     185   [ #  #  #  # ]:          0 :                 if (ret_val || (phy_reg == 0xFFFF)) {
     186                 :            :                         phy_id = 0;
     187                 :          0 :                         continue;
     188                 :            :                 }
     189                 :          0 :                 phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
     190                 :          0 :                 break;
     191                 :            :         }
     192                 :            : 
     193         [ #  # ]:          0 :         if (hw->phy.id) {
     194         [ #  # ]:          0 :                 if  (hw->phy.id == phy_id)
     195                 :          0 :                         goto out;
     196         [ #  # ]:          0 :         } else if (phy_id) {
     197                 :          0 :                 hw->phy.id = phy_id;
     198                 :          0 :                 hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
     199                 :          0 :                 goto out;
     200                 :            :         }
     201                 :            : 
     202                 :            :         /* In case the PHY needs to be in mdio slow mode,
     203                 :            :          * set slow mode and try to get the PHY id again.
     204                 :            :          */
     205         [ #  # ]:          0 :         if (hw->mac.type < e1000_pch_lpt) {
     206                 :          0 :                 hw->phy.ops.release(hw);
     207                 :          0 :                 ret_val = e1000_set_mdio_slow_mode_hv(hw);
     208         [ #  # ]:          0 :                 if (!ret_val)
     209                 :          0 :                         ret_val = e1000_get_phy_id(hw);
     210                 :          0 :                 hw->phy.ops.acquire(hw);
     211                 :            :         }
     212                 :            : 
     213         [ #  # ]:          0 :         if (ret_val)
     214                 :            :                 return false;
     215                 :          0 : out:
     216         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_lpt) {
     217                 :            :                 /* Only unforce SMBus if ME is not active */
     218         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_FWSM) &
     219                 :            :                     E1000_ICH_FWSM_FW_VALID)) {
     220                 :            :                         /* Unforce SMBus mode in PHY */
     221                 :          0 :                         hw->phy.ops.read_reg_locked(hw, CV_SMB_CTRL, &phy_reg);
     222                 :          0 :                         phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
     223                 :          0 :                         hw->phy.ops.write_reg_locked(hw, CV_SMB_CTRL, phy_reg);
     224                 :            : 
     225                 :            :                         /* Unforce SMBus mode in MAC */
     226                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
     227                 :          0 :                         mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
     228                 :          0 :                         E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
     229                 :            :                 }
     230                 :            :         }
     231                 :            : 
     232                 :            :         return true;
     233                 :            : }
     234                 :            : 
     235                 :            : /**
     236                 :            :  *  e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
     237                 :            :  *  @hw: pointer to the HW structure
     238                 :            :  *
     239                 :            :  *  Toggling the LANPHYPC pin value fully power-cycles the PHY and is
     240                 :            :  *  used to reset the PHY to a quiescent state when necessary.
     241                 :            :  **/
     242                 :          0 : STATIC void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
     243                 :            : {
     244                 :            :         u32 mac_reg;
     245                 :            : 
     246                 :          0 :         DEBUGFUNC("e1000_toggle_lanphypc_pch_lpt");
     247                 :            : 
     248                 :            :         /* Set Phy Config Counter to 50msec */
     249                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM3);
     250                 :          0 :         mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
     251                 :          0 :         mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
     252                 :          0 :         E1000_WRITE_REG(hw, E1000_FEXTNVM3, mac_reg);
     253                 :            : 
     254                 :            :         /* Toggle LANPHYPC Value bit */
     255                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_CTRL);
     256                 :            :         mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
     257                 :          0 :         mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
     258                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, mac_reg);
     259                 :          0 :         E1000_WRITE_FLUSH(hw);
     260                 :          0 :         msec_delay(1);
     261                 :            :         mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
     262                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, mac_reg);
     263                 :          0 :         E1000_WRITE_FLUSH(hw);
     264                 :            : 
     265         [ #  # ]:          0 :         if (hw->mac.type < e1000_pch_lpt) {
     266                 :          0 :                 msec_delay(50);
     267                 :            :         } else {
     268                 :            :                 u16 count = 20;
     269                 :            : 
     270                 :            :                 do {
     271                 :          0 :                         msec_delay(5);
     272                 :          0 :                 } while (!(E1000_READ_REG(hw, E1000_CTRL_EXT) &
     273   [ #  #  #  # ]:          0 :                            E1000_CTRL_EXT_LPCD) && count--);
     274                 :            : 
     275                 :          0 :                 msec_delay(30);
     276                 :            :         }
     277                 :          0 : }
     278                 :            : 
     279                 :            : /**
     280                 :            :  *  e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
     281                 :            :  *  @hw: pointer to the HW structure
     282                 :            :  *
     283                 :            :  *  Workarounds/flow necessary for PHY initialization during driver load
     284                 :            :  *  and resume paths.
     285                 :            :  **/
     286                 :          0 : STATIC s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
     287                 :            : {
     288                 :          0 :         u32 mac_reg, fwsm = E1000_READ_REG(hw, E1000_FWSM);
     289                 :            :         s32 ret_val;
     290                 :            : 
     291                 :          0 :         DEBUGFUNC("e1000_init_phy_workarounds_pchlan");
     292                 :            : 
     293                 :            :         /* Gate automatic PHY configuration by hardware on managed and
     294                 :            :          * non-managed 82579 and newer adapters.
     295                 :            :          */
     296                 :          0 :         e1000_gate_hw_phy_config_ich8lan(hw, true);
     297                 :            : 
     298                 :            :         /* It is not possible to be certain of the current state of ULP
     299                 :            :          * so forcibly disable it.
     300                 :            :          */
     301                 :          0 :         hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
     302                 :            : 
     303                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
     304         [ #  # ]:          0 :         if (ret_val) {
     305                 :          0 :                 DEBUGOUT("Failed to initialize PHY flow\n");
     306                 :          0 :                 goto out;
     307                 :            :         }
     308                 :            : 
     309                 :            :         /* The MAC-PHY interconnect may be in SMBus mode.  If the PHY is
     310                 :            :          * inaccessible and resetting the PHY is not blocked, toggle the
     311                 :            :          * LANPHYPC Value bit to force the interconnect to PCIe mode.
     312                 :            :          */
     313   [ #  #  #  # ]:          0 :         switch (hw->mac.type) {
     314                 :          0 :         case e1000_pch_lpt:
     315                 :            :         case e1000_pch_spt:
     316                 :            :         case e1000_pch_cnp:
     317                 :            :         case e1000_pch_adp:
     318         [ #  # ]:          0 :                 if (e1000_phy_is_accessible_pchlan(hw))
     319                 :            :                         break;
     320                 :            : 
     321                 :            :                 /* Before toggling LANPHYPC, see if PHY is accessible by
     322                 :            :                  * forcing MAC to SMBus mode first.
     323                 :            :                  */
     324                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
     325                 :          0 :                 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
     326                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
     327                 :            : 
     328                 :            :                 /* Wait 50 milliseconds for MAC to finish any retries
     329                 :            :                  * that it might be trying to perform from previous
     330                 :            :                  * attempts to acknowledge any phy read requests.
     331                 :            :                  */
     332                 :          0 :                  msec_delay(50);
     333                 :            : 
     334                 :            :                 /* fall-through */
     335                 :          0 :         case e1000_pch2lan:
     336         [ #  # ]:          0 :                 if (e1000_phy_is_accessible_pchlan(hw))
     337                 :            :                         break;
     338                 :            : 
     339                 :            :                 /* fall-through */
     340                 :            :         case e1000_pchlan:
     341         [ #  # ]:          0 :                 if ((hw->mac.type == e1000_pchlan) &&
     342         [ #  # ]:          0 :                     (fwsm & E1000_ICH_FWSM_FW_VALID))
     343                 :            :                         break;
     344                 :            : 
     345         [ #  # ]:          0 :                 if (hw->phy.ops.check_reset_block(hw)) {
     346                 :          0 :                         DEBUGOUT("Required LANPHYPC toggle blocked by ME\n");
     347                 :            :                         ret_val = -E1000_ERR_PHY;
     348                 :          0 :                         break;
     349                 :            :                 }
     350                 :            : 
     351                 :            :                 /* Toggle LANPHYPC Value bit */
     352                 :          0 :                 e1000_toggle_lanphypc_pch_lpt(hw);
     353         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_lpt) {
     354         [ #  # ]:          0 :                         if (e1000_phy_is_accessible_pchlan(hw))
     355                 :            :                                 break;
     356                 :            : 
     357                 :            :                         /* Toggling LANPHYPC brings the PHY out of SMBus mode
     358                 :            :                          * so ensure that the MAC is also out of SMBus mode
     359                 :            :                          */
     360                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
     361                 :          0 :                         mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
     362                 :          0 :                         E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
     363                 :            : 
     364         [ #  # ]:          0 :                         if (e1000_phy_is_accessible_pchlan(hw))
     365                 :            :                                 break;
     366                 :            : 
     367                 :            :                         ret_val = -E1000_ERR_PHY;
     368                 :            :                 }
     369                 :            :                 break;
     370                 :            :         default:
     371                 :            :                 break;
     372                 :            :         }
     373                 :            : 
     374                 :          0 :         hw->phy.ops.release(hw);
     375         [ #  # ]:          0 :         if (!ret_val) {
     376                 :            : 
     377                 :            :                 /* Check to see if able to reset PHY.  Print error if not */
     378         [ #  # ]:          0 :                 if (hw->phy.ops.check_reset_block(hw)) {
     379                 :            :                         ERROR_REPORT("Reset blocked by ME\n");
     380                 :          0 :                         goto out;
     381                 :            :                 }
     382                 :            : 
     383                 :            :                 /* Reset the PHY before any access to it.  Doing so, ensures
     384                 :            :                  * that the PHY is in a known good state before we read/write
     385                 :            :                  * PHY registers.  The generic reset is sufficient here,
     386                 :            :                  * because we haven't determined the PHY type yet.
     387                 :            :                  */
     388                 :          0 :                 ret_val = e1000_phy_hw_reset_generic(hw);
     389         [ #  # ]:          0 :                 if (ret_val)
     390                 :          0 :                         goto out;
     391                 :            : 
     392                 :            :                 /* On a successful reset, possibly need to wait for the PHY
     393                 :            :                  * to quiesce to an accessible state before returning control
     394                 :            :                  * to the calling function.  If the PHY does not quiesce, then
     395                 :            :                  * return E1000E_BLK_PHY_RESET, as this is the condition that
     396                 :            :                  *  the PHY is in.
     397                 :            :                  */
     398                 :          0 :                 ret_val = hw->phy.ops.check_reset_block(hw);
     399                 :            :                 if (ret_val)
     400                 :            :                         ERROR_REPORT("ME blocked access to PHY after reset\n");
     401                 :            :         }
     402                 :            : 
     403                 :          0 : out:
     404                 :            :         /* Ungate automatic PHY configuration on non-managed 82579 */
     405         [ #  # ]:          0 :         if ((hw->mac.type == e1000_pch2lan) &&
     406         [ #  # ]:          0 :             !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
     407                 :          0 :                 msec_delay(10);
     408                 :          0 :                 e1000_gate_hw_phy_config_ich8lan(hw, false);
     409                 :            :         }
     410                 :            : 
     411                 :          0 :         return ret_val;
     412                 :            : }
     413                 :            : 
     414                 :            : /**
     415                 :            :  *  e1000_init_phy_params_pchlan - Initialize PHY function pointers
     416                 :            :  *  @hw: pointer to the HW structure
     417                 :            :  *
     418                 :            :  *  Initialize family-specific PHY parameters and function pointers.
     419                 :            :  **/
     420                 :          0 : STATIC s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
     421                 :            : {
     422                 :            :         struct e1000_phy_info *phy = &hw->phy;
     423                 :            :         s32 ret_val;
     424                 :            : 
     425                 :          0 :         DEBUGFUNC("e1000_init_phy_params_pchlan");
     426                 :            : 
     427                 :          0 :         phy->addr            = 1;
     428                 :          0 :         phy->reset_delay_us  = 100;
     429                 :            : 
     430                 :          0 :         phy->ops.acquire     = e1000_acquire_swflag_ich8lan;
     431                 :          0 :         phy->ops.check_reset_block = e1000_check_reset_block_ich8lan;
     432                 :          0 :         phy->ops.get_cfg_done        = e1000_get_cfg_done_ich8lan;
     433                 :          0 :         phy->ops.set_page    = e1000_set_page_igp;
     434                 :          0 :         phy->ops.read_reg    = e1000_read_phy_reg_hv;
     435                 :          0 :         phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
     436                 :          0 :         phy->ops.read_reg_page       = e1000_read_phy_reg_page_hv;
     437                 :          0 :         phy->ops.release     = e1000_release_swflag_ich8lan;
     438                 :          0 :         phy->ops.reset               = e1000_phy_hw_reset_ich8lan;
     439                 :          0 :         phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
     440                 :          0 :         phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
     441                 :          0 :         phy->ops.write_reg   = e1000_write_phy_reg_hv;
     442                 :          0 :         phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
     443                 :          0 :         phy->ops.write_reg_page      = e1000_write_phy_reg_page_hv;
     444                 :          0 :         phy->ops.power_up    = e1000_power_up_phy_copper;
     445                 :          0 :         phy->ops.power_down  = e1000_power_down_phy_copper_ich8lan;
     446                 :          0 :         phy->autoneg_mask    = AUTONEG_ADVERTISE_SPEED_DEFAULT;
     447                 :            : 
     448                 :          0 :         phy->id = e1000_phy_unknown;
     449                 :            : 
     450                 :          0 :         ret_val = e1000_init_phy_workarounds_pchlan(hw);
     451         [ #  # ]:          0 :         if (ret_val)
     452                 :            :                 return ret_val;
     453                 :            : 
     454         [ #  # ]:          0 :         if (phy->id == e1000_phy_unknown)
     455         [ #  # ]:          0 :                 switch (hw->mac.type) {
     456                 :          0 :                 default:
     457                 :          0 :                         ret_val = e1000_get_phy_id(hw);
     458         [ #  # ]:          0 :                         if (ret_val)
     459                 :            :                                 return ret_val;
     460         [ #  # ]:          0 :                         if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
     461                 :            :                                 break;
     462                 :            :                         /* fall-through */
     463                 :            :                 case e1000_pch2lan:
     464                 :            :                 case e1000_pch_lpt:
     465                 :            :                 case e1000_pch_spt:
     466                 :            :                 case e1000_pch_cnp:
     467                 :            :                 case e1000_pch_adp:
     468                 :            :                         /* In case the PHY needs to be in mdio slow mode,
     469                 :            :                          * set slow mode and try to get the PHY id again.
     470                 :            :                          */
     471                 :          0 :                         ret_val = e1000_set_mdio_slow_mode_hv(hw);
     472         [ #  # ]:          0 :                         if (ret_val)
     473                 :            :                                 return ret_val;
     474                 :          0 :                         ret_val = e1000_get_phy_id(hw);
     475         [ #  # ]:          0 :                         if (ret_val)
     476                 :            :                                 return ret_val;
     477                 :            :                         break;
     478                 :            :                 }
     479                 :          0 :         phy->type = e1000_get_phy_type_from_id(phy->id);
     480                 :            : 
     481      [ #  #  # ]:          0 :         switch (phy->type) {
     482                 :          0 :         case e1000_phy_82577:
     483                 :            :         case e1000_phy_82579:
     484                 :            :         case e1000_phy_i217:
     485                 :          0 :                 phy->ops.check_polarity = e1000_check_polarity_82577;
     486                 :          0 :                 phy->ops.force_speed_duplex =
     487                 :            :                         e1000_phy_force_speed_duplex_82577;
     488                 :          0 :                 phy->ops.get_cable_length = e1000_get_cable_length_82577;
     489                 :          0 :                 phy->ops.get_info = e1000_get_phy_info_82577;
     490                 :          0 :                 phy->ops.commit = e1000_phy_sw_reset_generic;
     491                 :          0 :                 break;
     492                 :          0 :         case e1000_phy_82578:
     493                 :          0 :                 phy->ops.check_polarity = e1000_check_polarity_m88;
     494                 :          0 :                 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
     495                 :          0 :                 phy->ops.get_cable_length = e1000_get_cable_length_m88;
     496                 :          0 :                 phy->ops.get_info = e1000_get_phy_info_m88;
     497                 :          0 :                 break;
     498                 :            :         default:
     499                 :            :                 ret_val = -E1000_ERR_PHY;
     500                 :            :                 break;
     501                 :            :         }
     502                 :            : 
     503                 :            :         return ret_val;
     504                 :            : }
     505                 :            : 
     506                 :            : /**
     507                 :            :  *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers
     508                 :            :  *  @hw: pointer to the HW structure
     509                 :            :  *
     510                 :            :  *  Initialize family-specific PHY parameters and function pointers.
     511                 :            :  **/
     512                 :          0 : STATIC s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
     513                 :            : {
     514                 :            :         struct e1000_phy_info *phy = &hw->phy;
     515                 :            :         s32 ret_val;
     516                 :            :         u16 i = 0;
     517                 :            : 
     518                 :          0 :         DEBUGFUNC("e1000_init_phy_params_ich8lan");
     519                 :            : 
     520                 :          0 :         phy->addr            = 1;
     521                 :          0 :         phy->reset_delay_us  = 100;
     522                 :            : 
     523                 :          0 :         phy->ops.acquire     = e1000_acquire_swflag_ich8lan;
     524                 :          0 :         phy->ops.check_reset_block = e1000_check_reset_block_ich8lan;
     525                 :          0 :         phy->ops.get_cable_length = e1000_get_cable_length_igp_2;
     526                 :          0 :         phy->ops.get_cfg_done        = e1000_get_cfg_done_ich8lan;
     527                 :          0 :         phy->ops.read_reg    = e1000_read_phy_reg_igp;
     528                 :          0 :         phy->ops.release     = e1000_release_swflag_ich8lan;
     529                 :          0 :         phy->ops.reset               = e1000_phy_hw_reset_ich8lan;
     530                 :          0 :         phy->ops.set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan;
     531                 :          0 :         phy->ops.set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan;
     532                 :          0 :         phy->ops.write_reg   = e1000_write_phy_reg_igp;
     533                 :          0 :         phy->ops.power_up    = e1000_power_up_phy_copper;
     534                 :          0 :         phy->ops.power_down  = e1000_power_down_phy_copper_ich8lan;
     535                 :            : 
     536                 :            :         /* We may need to do this twice - once for IGP and if that fails,
     537                 :            :          * we'll set BM func pointers and try again
     538                 :            :          */
     539                 :          0 :         ret_val = e1000_determine_phy_address(hw);
     540         [ #  # ]:          0 :         if (ret_val) {
     541                 :          0 :                 phy->ops.write_reg = e1000_write_phy_reg_bm;
     542                 :          0 :                 phy->ops.read_reg  = e1000_read_phy_reg_bm;
     543                 :          0 :                 ret_val = e1000_determine_phy_address(hw);
     544         [ #  # ]:          0 :                 if (ret_val) {
     545                 :          0 :                         DEBUGOUT("Cannot determine PHY addr. Erroring out\n");
     546                 :          0 :                         return ret_val;
     547                 :            :                 }
     548                 :            :         }
     549                 :            : 
     550                 :          0 :         phy->id = 0;
     551         [ #  # ]:          0 :         while ((e1000_phy_unknown == e1000_get_phy_type_from_id(phy->id)) &&
     552         [ #  # ]:          0 :                (i++ < 100)) {
     553                 :          0 :                 msec_delay(1);
     554                 :          0 :                 ret_val = e1000_get_phy_id(hw);
     555         [ #  # ]:          0 :                 if (ret_val)
     556                 :          0 :                         return ret_val;
     557                 :            :         }
     558                 :            : 
     559                 :            :         /* Verify phy id */
     560   [ #  #  #  # ]:          0 :         switch (phy->id) {
     561                 :          0 :         case IGP03E1000_E_PHY_ID:
     562                 :          0 :                 phy->type = e1000_phy_igp_3;
     563                 :          0 :                 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
     564                 :          0 :                 phy->ops.read_reg_locked = e1000_read_phy_reg_igp_locked;
     565                 :          0 :                 phy->ops.write_reg_locked = e1000_write_phy_reg_igp_locked;
     566                 :          0 :                 phy->ops.get_info = e1000_get_phy_info_igp;
     567                 :          0 :                 phy->ops.check_polarity = e1000_check_polarity_igp;
     568                 :          0 :                 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_igp;
     569                 :          0 :                 break;
     570                 :          0 :         case IFE_E_PHY_ID:
     571                 :            :         case IFE_PLUS_E_PHY_ID:
     572                 :            :         case IFE_C_E_PHY_ID:
     573                 :          0 :                 phy->type = e1000_phy_ife;
     574                 :          0 :                 phy->autoneg_mask = E1000_ALL_NOT_GIG;
     575                 :          0 :                 phy->ops.get_info = e1000_get_phy_info_ife;
     576                 :          0 :                 phy->ops.check_polarity = e1000_check_polarity_ife;
     577                 :          0 :                 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
     578                 :          0 :                 break;
     579                 :          0 :         case BME1000_E_PHY_ID:
     580                 :          0 :                 phy->type = e1000_phy_bm;
     581                 :          0 :                 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
     582                 :          0 :                 phy->ops.read_reg = e1000_read_phy_reg_bm;
     583                 :          0 :                 phy->ops.write_reg = e1000_write_phy_reg_bm;
     584                 :          0 :                 phy->ops.commit = e1000_phy_sw_reset_generic;
     585                 :          0 :                 phy->ops.get_info = e1000_get_phy_info_m88;
     586                 :          0 :                 phy->ops.check_polarity = e1000_check_polarity_m88;
     587                 :          0 :                 phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_m88;
     588                 :          0 :                 break;
     589                 :            :         default:
     590                 :            :                 return -E1000_ERR_PHY;
     591                 :            :                 break;
     592                 :            :         }
     593                 :            : 
     594                 :            :         return E1000_SUCCESS;
     595                 :            : }
     596                 :            : 
     597                 :            : /**
     598                 :            :  *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
     599                 :            :  *  @hw: pointer to the HW structure
     600                 :            :  *
     601                 :            :  *  Initialize family-specific NVM parameters and function
     602                 :            :  *  pointers.
     603                 :            :  **/
     604                 :          0 : STATIC s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
     605                 :            : {
     606                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
     607                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
     608                 :            :         u32 gfpreg, sector_base_addr, sector_end_addr;
     609                 :            :         u16 i;
     610                 :            :         u32 nvm_size;
     611                 :            : 
     612                 :          0 :         DEBUGFUNC("e1000_init_nvm_params_ich8lan");
     613                 :            : 
     614                 :          0 :         nvm->type = e1000_nvm_flash_sw;
     615                 :            : 
     616         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt) {
     617                 :            :                 /* in SPT, gfpreg doesn't exist. NVM size is taken from the
     618                 :            :                  * STRAP register. This is because in SPT the GbE Flash region
     619                 :            :                  * is no longer accessed through the flash registers. Instead,
     620                 :            :                  * the mechanism has changed, and the Flash region access
     621                 :            :                  * registers are now implemented in GbE memory space.
     622                 :            :                  */
     623                 :          0 :                 nvm->flash_base_addr = 0;
     624                 :          0 :                 nvm_size =
     625                 :          0 :                     (((E1000_READ_REG(hw, E1000_STRAP) >> 1) & 0x1F) + 1)
     626                 :            :                     * NVM_SIZE_MULTIPLIER;
     627                 :          0 :                 nvm->flash_bank_size = nvm_size / 2;
     628                 :            :                 /* Adjust to word count */
     629                 :          0 :                 nvm->flash_bank_size /= sizeof(u16);
     630                 :            :                 /* Set the base address for flash register access */
     631                 :          0 :                 hw->flash_address = hw->hw_addr + E1000_FLASH_BASE_ADDR;
     632                 :            :         } else {
     633                 :            :                 /* Can't read flash registers if register set isn't mapped. */
     634         [ #  # ]:          0 :                 if (!hw->flash_address) {
     635                 :          0 :                         DEBUGOUT("ERROR: Flash registers not mapped\n");
     636                 :          0 :                         return -E1000_ERR_CONFIG;
     637                 :            :                 }
     638                 :            : 
     639                 :            :                 gfpreg = E1000_READ_FLASH_REG(hw, ICH_FLASH_GFPREG);
     640                 :            : 
     641                 :            :                 /* sector_X_addr is a "sector"-aligned address (4096 bytes)
     642                 :            :                  * Add 1 to sector_end_addr since this sector is included in
     643                 :            :                  * the overall size.
     644                 :            :                  */
     645                 :          0 :                 sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
     646                 :          0 :                 sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
     647                 :            : 
     648                 :            :                 /* flash_base_addr is byte-aligned */
     649                 :          0 :                 nvm->flash_base_addr = sector_base_addr
     650                 :          0 :                                        << FLASH_SECTOR_ADDR_SHIFT;
     651                 :            : 
     652                 :            :                 /* find total size of the NVM, then cut in half since the total
     653                 :            :                  * size represents two separate NVM banks.
     654                 :            :                  */
     655                 :          0 :                 nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
     656                 :          0 :                                         << FLASH_SECTOR_ADDR_SHIFT);
     657                 :          0 :                 nvm->flash_bank_size /= 2;
     658                 :            :                 /* Adjust to word count */
     659                 :          0 :                 nvm->flash_bank_size /= sizeof(u16);
     660                 :            :         }
     661                 :            : 
     662                 :          0 :         nvm->word_size = E1000_SHADOW_RAM_WORDS;
     663                 :            : 
     664                 :            :         /* Clear shadow ram */
     665         [ #  # ]:          0 :         for (i = 0; i < nvm->word_size; i++) {
     666                 :          0 :                 dev_spec->shadow_ram[i].modified = false;
     667                 :          0 :                 dev_spec->shadow_ram[i].value    = 0xFFFF;
     668                 :            :         }
     669                 :            : 
     670                 :          0 :         E1000_MUTEX_INIT(&dev_spec->nvm_mutex);
     671                 :          0 :         E1000_MUTEX_INIT(&dev_spec->swflag_mutex);
     672                 :            : 
     673                 :            :         /* Function Pointers */
     674                 :          0 :         nvm->ops.acquire     = e1000_acquire_nvm_ich8lan;
     675                 :          0 :         nvm->ops.release     = e1000_release_nvm_ich8lan;
     676         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt) {
     677                 :          0 :                 nvm->ops.read        = e1000_read_nvm_spt;
     678                 :          0 :                 nvm->ops.update      = e1000_update_nvm_checksum_spt;
     679                 :            :         } else {
     680                 :          0 :                 nvm->ops.read        = e1000_read_nvm_ich8lan;
     681                 :          0 :                 nvm->ops.update      = e1000_update_nvm_checksum_ich8lan;
     682                 :            :         }
     683                 :          0 :         nvm->ops.valid_led_default = e1000_valid_led_default_ich8lan;
     684                 :          0 :         nvm->ops.validate    = e1000_validate_nvm_checksum_ich8lan;
     685                 :          0 :         nvm->ops.write               = e1000_write_nvm_ich8lan;
     686                 :            : 
     687                 :          0 :         return E1000_SUCCESS;
     688                 :            : }
     689                 :            : 
     690                 :            : /**
     691                 :            :  *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers
     692                 :            :  *  @hw: pointer to the HW structure
     693                 :            :  *
     694                 :            :  *  Initialize family-specific MAC parameters and function
     695                 :            :  *  pointers.
     696                 :            :  **/
     697                 :          0 : STATIC s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
     698                 :            : {
     699                 :            :         struct e1000_mac_info *mac = &hw->mac;
     700                 :            :         u16 pci_cfg;
     701                 :            : 
     702                 :          0 :         DEBUGFUNC("e1000_init_mac_params_ich8lan");
     703                 :            : 
     704                 :            :         /* Set media type function pointer */
     705                 :          0 :         hw->phy.media_type = e1000_media_type_copper;
     706                 :            : 
     707                 :            :         /* Set mta register count */
     708                 :          0 :         mac->mta_reg_count = 32;
     709                 :            :         /* Set rar entry count */
     710                 :          0 :         mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
     711         [ #  # ]:          0 :         if (mac->type == e1000_ich8lan)
     712                 :          0 :                 mac->rar_entry_count--;
     713                 :            :         /* Set if part includes ASF firmware */
     714                 :          0 :         mac->asf_firmware_present = true;
     715                 :            :         /* FWSM register */
     716                 :          0 :         mac->has_fwsm = true;
     717                 :            :         /* ARC subsystem not supported */
     718                 :          0 :         mac->arc_subsystem_valid = false;
     719                 :            :         /* Adaptive IFS supported */
     720                 :          0 :         mac->adaptive_ifs = true;
     721                 :            : 
     722                 :            :         /* Function pointers */
     723                 :            : 
     724                 :            :         /* bus type/speed/width */
     725                 :          0 :         mac->ops.get_bus_info = e1000_get_bus_info_ich8lan;
     726                 :            :         /* function id */
     727                 :          0 :         mac->ops.set_lan_id = e1000_set_lan_id_single_port;
     728                 :            :         /* reset */
     729                 :          0 :         mac->ops.reset_hw = e1000_reset_hw_ich8lan;
     730                 :            :         /* hw initialization */
     731                 :          0 :         mac->ops.init_hw = e1000_init_hw_ich8lan;
     732                 :            :         /* link setup */
     733                 :          0 :         mac->ops.setup_link = e1000_setup_link_ich8lan;
     734                 :            :         /* physical interface setup */
     735                 :          0 :         mac->ops.setup_physical_interface = e1000_setup_copper_link_ich8lan;
     736                 :            :         /* check for link */
     737                 :          0 :         mac->ops.check_for_link = e1000_check_for_copper_link_ich8lan;
     738                 :            :         /* link info */
     739                 :          0 :         mac->ops.get_link_up_info = e1000_get_link_up_info_ich8lan;
     740                 :            :         /* multicast address update */
     741                 :          0 :         mac->ops.update_mc_addr_list = e1000_update_mc_addr_list_generic;
     742                 :            :         /* clear hardware counters */
     743                 :          0 :         mac->ops.clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan;
     744                 :            : 
     745                 :            :         /* LED and other operations */
     746   [ #  #  #  #  :          0 :         switch (mac->type) {
                      # ]
     747                 :          0 :         case e1000_ich8lan:
     748                 :            :         case e1000_ich9lan:
     749                 :            :         case e1000_ich10lan:
     750                 :            :                 /* check management mode */
     751                 :          0 :                 mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
     752                 :            :                 /* ID LED init */
     753                 :          0 :                 mac->ops.id_led_init = e1000_id_led_init_generic;
     754                 :            :                 /* blink LED */
     755                 :          0 :                 mac->ops.blink_led = e1000_blink_led_generic;
     756                 :            :                 /* setup LED */
     757                 :          0 :                 mac->ops.setup_led = e1000_setup_led_generic;
     758                 :            :                 /* cleanup LED */
     759                 :          0 :                 mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
     760                 :            :                 /* turn on/off LED */
     761                 :          0 :                 mac->ops.led_on = e1000_led_on_ich8lan;
     762                 :          0 :                 mac->ops.led_off = e1000_led_off_ich8lan;
     763                 :          0 :                 break;
     764                 :          0 :         case e1000_pch2lan:
     765                 :          0 :                 mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
     766                 :          0 :                 mac->ops.rar_set = e1000_rar_set_pch2lan;
     767                 :            :                 /* fall-through */
     768                 :          0 :         case e1000_pch_lpt:
     769                 :            :         case e1000_pch_spt:
     770                 :            :         case e1000_pch_cnp:
     771                 :            :         case e1000_pch_adp:
     772                 :            :                 /* multicast address update for pch2 */
     773                 :          0 :                 mac->ops.update_mc_addr_list =
     774                 :            :                         e1000_update_mc_addr_list_pch2lan;
     775                 :            :                 /* fall-through */
     776                 :          0 :         case e1000_pchlan:
     777                 :            :                 /* save PCH revision_id */
     778                 :          0 :                 e1000_read_pci_cfg(hw, E1000_PCI_REVISION_ID_REG, &pci_cfg);
     779                 :            :                 /* SPT uses full byte for revision ID,
     780                 :            :                  * as opposed to previous generations
     781                 :            :                  */
     782         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
     783                 :          0 :                         hw->revision_id = (u8)(pci_cfg &= 0x00FF);
     784                 :            :                 else
     785                 :          0 :                         hw->revision_id = (u8)(pci_cfg &= 0x000F);
     786                 :            :                 /* check management mode */
     787                 :          0 :                 mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
     788                 :            :                 /* ID LED init */
     789                 :          0 :                 mac->ops.id_led_init = e1000_id_led_init_pchlan;
     790                 :            :                 /* setup LED */
     791                 :          0 :                 mac->ops.setup_led = e1000_setup_led_pchlan;
     792                 :            :                 /* cleanup LED */
     793                 :          0 :                 mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
     794                 :            :                 /* turn on/off LED */
     795                 :          0 :                 mac->ops.led_on = e1000_led_on_pchlan;
     796                 :          0 :                 mac->ops.led_off = e1000_led_off_pchlan;
     797                 :          0 :                 break;
     798                 :            :         default:
     799                 :            :                 break;
     800                 :            :         }
     801                 :            : 
     802         [ #  # ]:          0 :         if (mac->type >= e1000_pch_lpt) {
     803                 :          0 :                 mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
     804                 :          0 :                 mac->ops.rar_set = e1000_rar_set_pch_lpt;
     805                 :          0 :                 mac->ops.setup_physical_interface = e1000_setup_copper_link_pch_lpt;
     806                 :            :         }
     807                 :            : 
     808                 :            :         /* Enable PCS Lock-loss workaround for ICH8 */
     809         [ #  # ]:          0 :         if (mac->type == e1000_ich8lan)
     810                 :          0 :                 e1000_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
     811                 :            : 
     812                 :          0 :         return E1000_SUCCESS;
     813                 :            : }
     814                 :            : 
     815                 :            : /**
     816                 :            :  *  __e1000_access_emi_reg_locked - Read/write EMI register
     817                 :            :  *  @hw: pointer to the HW structure
     818                 :            :  *  @address: EMI address to program
     819                 :            :  *  @data: pointer to value to read/write from/to the EMI address
     820                 :            :  *  @read: boolean flag to indicate read or write
     821                 :            :  *
     822                 :            :  *  This helper function assumes the SW/FW/HW Semaphore is already acquired.
     823                 :            :  **/
     824                 :          0 : STATIC s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
     825                 :            :                                          u16 *data, bool read)
     826                 :            : {
     827                 :            :         s32 ret_val;
     828                 :            : 
     829                 :          0 :         DEBUGFUNC("__e1000_access_emi_reg_locked");
     830                 :            : 
     831                 :          0 :         ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_ADDR, address);
     832         [ #  # ]:          0 :         if (ret_val)
     833                 :            :                 return ret_val;
     834                 :            : 
     835         [ #  # ]:          0 :         if (read)
     836                 :          0 :                 ret_val = hw->phy.ops.read_reg_locked(hw, I82579_EMI_DATA,
     837                 :            :                                                       data);
     838                 :            :         else
     839                 :          0 :                 ret_val = hw->phy.ops.write_reg_locked(hw, I82579_EMI_DATA,
     840                 :          0 :                                                        *data);
     841                 :            : 
     842                 :            :         return ret_val;
     843                 :            : }
     844                 :            : 
     845                 :            : /**
     846                 :            :  *  e1000_read_emi_reg_locked - Read Extended Management Interface register
     847                 :            :  *  @hw: pointer to the HW structure
     848                 :            :  *  @addr: EMI address to program
     849                 :            :  *  @data: value to be read from the EMI address
     850                 :            :  *
     851                 :            :  *  Assumes the SW/FW/HW Semaphore is already acquired.
     852                 :            :  **/
     853                 :          0 : s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
     854                 :            : {
     855                 :          0 :         DEBUGFUNC("e1000_read_emi_reg_locked");
     856                 :            : 
     857                 :          0 :         return __e1000_access_emi_reg_locked(hw, addr, data, true);
     858                 :            : }
     859                 :            : 
     860                 :            : /**
     861                 :            :  *  e1000_write_emi_reg_locked - Write Extended Management Interface register
     862                 :            :  *  @hw: pointer to the HW structure
     863                 :            :  *  @addr: EMI address to program
     864                 :            :  *  @data: value to be written to the EMI address
     865                 :            :  *
     866                 :            :  *  Assumes the SW/FW/HW Semaphore is already acquired.
     867                 :            :  **/
     868                 :          0 : s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
     869                 :            : {
     870                 :          0 :         DEBUGFUNC("e1000_read_emi_reg_locked");
     871                 :            : 
     872                 :          0 :         return __e1000_access_emi_reg_locked(hw, addr, &data, false);
     873                 :            : }
     874                 :            : 
     875                 :            : /**
     876                 :            :  *  e1000_set_eee_pchlan - Enable/disable EEE support
     877                 :            :  *  @hw: pointer to the HW structure
     878                 :            :  *
     879                 :            :  *  Enable/disable EEE based on setting in dev_spec structure, the duplex of
     880                 :            :  *  the link and the EEE capabilities of the link partner.  The LPI Control
     881                 :            :  *  register bits will remain set only if/when link is up.
     882                 :            :  *
     883                 :            :  *  EEE LPI must not be asserted earlier than one second after link is up.
     884                 :            :  *  On 82579, EEE LPI should not be enabled until such time otherwise there
     885                 :            :  *  can be link issues with some switches.  Other devices can have EEE LPI
     886                 :            :  *  enabled immediately upon link up since they have a timer in hardware which
     887                 :            :  *  prevents LPI from being asserted too early.
     888                 :            :  **/
     889                 :          0 : s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
     890                 :            : {
     891                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
     892                 :            :         s32 ret_val;
     893                 :            :         u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
     894                 :            : 
     895                 :          0 :         DEBUGFUNC("e1000_set_eee_pchlan");
     896                 :            : 
     897      [ #  #  # ]:          0 :         switch (hw->phy.type) {
     898                 :            :         case e1000_phy_82579:
     899                 :            :                 lpa = I82579_EEE_LP_ABILITY;
     900                 :            :                 pcs_status = I82579_EEE_PCS_STATUS;
     901                 :            :                 adv_addr = I82579_EEE_ADVERTISEMENT;
     902                 :            :                 break;
     903                 :          0 :         case e1000_phy_i217:
     904                 :            :                 lpa = I217_EEE_LP_ABILITY;
     905                 :            :                 pcs_status = I217_EEE_PCS_STATUS;
     906                 :            :                 adv_addr = I217_EEE_ADVERTISEMENT;
     907                 :          0 :                 break;
     908                 :            :         default:
     909                 :            :                 return E1000_SUCCESS;
     910                 :            :         }
     911                 :            : 
     912                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
     913         [ #  # ]:          0 :         if (ret_val)
     914                 :            :                 return ret_val;
     915                 :            : 
     916                 :          0 :         ret_val = hw->phy.ops.read_reg_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
     917         [ #  # ]:          0 :         if (ret_val)
     918                 :          0 :                 goto release;
     919                 :            : 
     920                 :            :         /* Clear bits that enable EEE in various speeds */
     921                 :          0 :         lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
     922                 :            : 
     923                 :            :         /* Enable EEE if not disabled by user */
     924         [ #  # ]:          0 :         if (!dev_spec->eee_disable) {
     925                 :            :                 /* Save off link partner's EEE ability */
     926                 :          0 :                 ret_val = e1000_read_emi_reg_locked(hw, lpa,
     927                 :            :                                                     &dev_spec->eee_lp_ability);
     928         [ #  # ]:          0 :                 if (ret_val)
     929                 :          0 :                         goto release;
     930                 :            : 
     931                 :            :                 /* Read EEE advertisement */
     932                 :          0 :                 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
     933         [ #  # ]:          0 :                 if (ret_val)
     934                 :          0 :                         goto release;
     935                 :            : 
     936                 :            :                 /* Enable EEE only for speeds in which the link partner is
     937                 :            :                  * EEE capable and for which we advertise EEE.
     938                 :            :                  */
     939         [ #  # ]:          0 :                 if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
     940                 :          0 :                         lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
     941                 :            : 
     942         [ #  # ]:          0 :                 if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
     943                 :          0 :                         hw->phy.ops.read_reg_locked(hw, PHY_LP_ABILITY, &data);
     944         [ #  # ]:          0 :                         if (data & NWAY_LPAR_100TX_FD_CAPS)
     945                 :          0 :                                 lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
     946                 :            :                         else
     947                 :            :                                 /* EEE is not supported in 100Half, so ignore
     948                 :            :                                  * partner's EEE in 100 ability if full-duplex
     949                 :            :                                  * is not advertised.
     950                 :            :                                  */
     951                 :          0 :                                 dev_spec->eee_lp_ability &=
     952                 :            :                                     ~I82579_EEE_100_SUPPORTED;
     953                 :            :                 }
     954                 :            :         }
     955                 :            : 
     956         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_82579) {
     957                 :          0 :                 ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
     958                 :            :                                                     &data);
     959         [ #  # ]:          0 :                 if (ret_val)
     960                 :          0 :                         goto release;
     961                 :            : 
     962                 :          0 :                 data &= ~I82579_LPI_100_PLL_SHUT;
     963                 :          0 :                 ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
     964                 :            :                                                      data);
     965                 :            :         }
     966                 :            : 
     967                 :            :         /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
     968                 :          0 :         ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
     969         [ #  # ]:          0 :         if (ret_val)
     970                 :          0 :                 goto release;
     971                 :            : 
     972                 :          0 :         ret_val = hw->phy.ops.write_reg_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
     973                 :          0 : release:
     974                 :          0 :         hw->phy.ops.release(hw);
     975                 :            : 
     976                 :          0 :         return ret_val;
     977                 :            : }
     978                 :            : 
     979                 :            : /**
     980                 :            :  *  e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
     981                 :            :  *  @hw:   pointer to the HW structure
     982                 :            :  *  @link: link up bool flag
     983                 :            :  *
     984                 :            :  *  When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
     985                 :            :  *  preventing further DMA write requests.  Workaround the issue by disabling
     986                 :            :  *  the de-assertion of the clock request when in 1Gpbs mode.
     987                 :            :  *  Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
     988                 :            :  *  speeds in order to avoid Tx hangs.
     989                 :            :  **/
     990                 :          0 : STATIC s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
     991                 :            : {
     992                 :          0 :         u32 fextnvm6 = E1000_READ_REG(hw, E1000_FEXTNVM6);
     993                 :          0 :         u32 status = E1000_READ_REG(hw, E1000_STATUS);
     994                 :            :         s32 ret_val = E1000_SUCCESS;
     995                 :            :         u16 reg;
     996                 :            : 
     997   [ #  #  #  # ]:          0 :         if (link && (status & E1000_STATUS_SPEED_1000)) {
     998                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
     999         [ #  # ]:          0 :                 if (ret_val)
    1000                 :            :                         return ret_val;
    1001                 :            : 
    1002                 :            :                 ret_val =
    1003                 :          0 :                     e1000_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
    1004                 :            :                                                &reg);
    1005         [ #  # ]:          0 :                 if (ret_val)
    1006                 :          0 :                         goto release;
    1007                 :            : 
    1008                 :            :                 ret_val =
    1009                 :          0 :                     e1000_write_kmrn_reg_locked(hw,
    1010                 :            :                                                 E1000_KMRNCTRLSTA_K1_CONFIG,
    1011                 :          0 :                                                 reg &
    1012                 :            :                                                 ~E1000_KMRNCTRLSTA_K1_ENABLE);
    1013         [ #  # ]:          0 :                 if (ret_val)
    1014                 :          0 :                         goto release;
    1015                 :            : 
    1016                 :          0 :                 usec_delay(10);
    1017                 :            : 
    1018                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM6,
    1019                 :            :                                 fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
    1020                 :            : 
    1021                 :            :                 ret_val =
    1022                 :          0 :                     e1000_write_kmrn_reg_locked(hw,
    1023                 :            :                                                 E1000_KMRNCTRLSTA_K1_CONFIG,
    1024                 :            :                                                 reg);
    1025                 :          0 : release:
    1026                 :          0 :                 hw->phy.ops.release(hw);
    1027                 :            :         } else {
    1028                 :            :                 /* clear FEXTNVM6 bit 8 on link down or 10/100 */
    1029                 :          0 :                 fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
    1030                 :            : 
    1031   [ #  #  #  # ]:          0 :                 if ((hw->phy.revision > 5) || !link ||
    1032         [ #  # ]:          0 :                     ((status & E1000_STATUS_SPEED_100) &&
    1033                 :            :                      (status & E1000_STATUS_FD)))
    1034                 :          0 :                         goto update_fextnvm6;
    1035                 :            : 
    1036                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, I217_INBAND_CTRL, &reg);
    1037         [ #  # ]:          0 :                 if (ret_val)
    1038                 :            :                         return ret_val;
    1039                 :            : 
    1040                 :            :                 /* Clear link status transmit timeout */
    1041                 :          0 :                 reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
    1042                 :            : 
    1043         [ #  # ]:          0 :                 if (status & E1000_STATUS_SPEED_100) {
    1044                 :            :                         /* Set inband Tx timeout to 5x10us for 100Half */
    1045                 :          0 :                         reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
    1046                 :            : 
    1047                 :            :                         /* Do not extend the K1 entry latency for 100Half */
    1048                 :          0 :                         fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
    1049                 :            :                 } else {
    1050                 :            :                         /* Set inband Tx timeout to 50x10us for 10Full/Half */
    1051                 :          0 :                         reg |= 50 <<
    1052                 :            :                                I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
    1053                 :            : 
    1054                 :            :                         /* Extend the K1 entry latency for 10 Mbps */
    1055                 :          0 :                         fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
    1056                 :            :                 }
    1057                 :            : 
    1058                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, I217_INBAND_CTRL, reg);
    1059         [ #  # ]:          0 :                 if (ret_val)
    1060                 :            :                         return ret_val;
    1061                 :            : 
    1062                 :          0 : update_fextnvm6:
    1063                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM6, fextnvm6);
    1064                 :            :         }
    1065                 :            : 
    1066                 :            :         return ret_val;
    1067                 :            : }
    1068                 :            : 
    1069                 :            : /**
    1070                 :            :  *  e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
    1071                 :            :  *  @hw: pointer to the HW structure
    1072                 :            :  *  @to_sx: boolean indicating a system power state transition to Sx
    1073                 :            :  *
    1074                 :            :  *  When link is down, configure ULP mode to significantly reduce the power
    1075                 :            :  *  to the PHY.  If on a Manageability Engine (ME) enabled system, tell the
    1076                 :            :  *  ME firmware to start the ULP configuration.  If not on an ME enabled
    1077                 :            :  *  system, configure the ULP mode by software.
    1078                 :            :  */
    1079                 :          0 : s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
    1080                 :            : {
    1081                 :            :         u32 mac_reg;
    1082                 :            :         s32 ret_val = E1000_SUCCESS;
    1083                 :            :         u16 phy_reg;
    1084                 :          0 :         u16 oem_reg = 0;
    1085                 :            : 
    1086         [ #  # ]:          0 :         if ((hw->mac.type < e1000_pch_lpt) ||
    1087   [ #  #  #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_LM) ||
    1088         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_V) ||
    1089         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_I218_LM2) ||
    1090                 :          0 :             (hw->device_id == E1000_DEV_ID_PCH_I218_V2) ||
    1091         [ #  # ]:          0 :             (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
    1092                 :            :                 return 0;
    1093                 :            : 
    1094         [ #  # ]:          0 :         if (!to_sx) {
    1095                 :            :                 int i = 0;
    1096                 :            :                 /* Poll up to 5 seconds for Cable Disconnected indication */
    1097         [ #  # ]:          0 :                 while (!(E1000_READ_REG(hw, E1000_FEXT) &
    1098                 :            :                          E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
    1099                 :            :                         /* Bail if link is re-acquired */
    1100         [ #  # ]:          0 :                         if (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)
    1101                 :            :                                 return -E1000_ERR_PHY;
    1102         [ #  # ]:          0 :                         if (i++ == 100)
    1103                 :            :                                 break;
    1104                 :            : 
    1105                 :          0 :                         msec_delay(50);
    1106                 :            :                 }
    1107         [ #  # ]:          0 :                 DEBUGOUT2("CABLE_DISCONNECTED %s set after %dmsec\n",
    1108                 :            :                           (E1000_READ_REG(hw, E1000_FEXT) &
    1109                 :            :                            E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not",
    1110                 :            :                           i * 50);
    1111         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_FEXT) &
    1112                 :            :                     E1000_FEXT_PHY_CABLE_DISCONNECTED))
    1113                 :            :                         return 0;
    1114                 :            :         }
    1115                 :            : 
    1116         [ #  # ]:          0 :         if (E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID) {
    1117                 :            :                 /* Request ME configure ULP mode in the PHY */
    1118                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_H2ME);
    1119                 :          0 :                 mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
    1120                 :          0 :                 E1000_WRITE_REG(hw, E1000_H2ME, mac_reg);
    1121                 :            : 
    1122                 :          0 :                 goto out;
    1123                 :            :         }
    1124                 :            : 
    1125                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    1126         [ #  # ]:          0 :         if (ret_val)
    1127                 :          0 :                 goto out;
    1128                 :            : 
    1129                 :            :         /* During S0 Idle keep the phy in PCI-E mode */
    1130         [ #  # ]:          0 :         if (hw->dev_spec.ich8lan.smbus_disable)
    1131                 :          0 :                 goto skip_smbus;
    1132                 :            : 
    1133                 :            :         /* Force SMBus mode in PHY */
    1134                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
    1135         [ #  # ]:          0 :         if (ret_val)
    1136                 :          0 :                 goto release;
    1137                 :          0 :         phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
    1138                 :          0 :         e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
    1139                 :            : 
    1140                 :            :         /* Force SMBus mode in MAC */
    1141                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
    1142                 :          0 :         mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
    1143                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
    1144                 :            : 
    1145                 :            :         /* Si workaround for ULP entry flow on i127/rev6 h/w.  Enable
    1146                 :            :          * LPLU and disable Gig speed when entering ULP
    1147                 :            :          */
    1148   [ #  #  #  # ]:          0 :         if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6)) {
    1149                 :          0 :                 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_OEM_BITS,
    1150                 :            :                                                        &oem_reg);
    1151         [ #  # ]:          0 :                 if (ret_val)
    1152                 :          0 :                         goto release;
    1153                 :            : 
    1154                 :          0 :                 phy_reg = oem_reg;
    1155                 :          0 :                 phy_reg |= HV_OEM_BITS_LPLU | HV_OEM_BITS_GBE_DIS;
    1156                 :            : 
    1157                 :          0 :                 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
    1158                 :            :                                                         phy_reg);
    1159                 :            : 
    1160         [ #  # ]:          0 :                 if (ret_val)
    1161                 :          0 :                         goto release;
    1162                 :            :         }
    1163                 :            : 
    1164                 :          0 : skip_smbus:
    1165         [ #  # ]:          0 :         if (!to_sx) {
    1166                 :            :                 /* Change the 'Link Status Change' interrupt to trigger
    1167                 :            :                  * on 'Cable Status Change'
    1168                 :            :                  */
    1169                 :          0 :                 ret_val = e1000_read_kmrn_reg_locked(hw,
    1170                 :            :                                                      E1000_KMRNCTRLSTA_OP_MODES,
    1171                 :            :                                                      &phy_reg);
    1172         [ #  # ]:          0 :                 if (ret_val)
    1173                 :          0 :                         goto release;
    1174                 :          0 :                 phy_reg |= E1000_KMRNCTRLSTA_OP_MODES_LSC2CSC;
    1175                 :          0 :                 e1000_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_OP_MODES,
    1176                 :            :                                             phy_reg);
    1177                 :            :         }
    1178                 :            : 
    1179                 :            :         /* Set Inband ULP Exit, Reset to SMBus mode and
    1180                 :            :          * Disable SMBus Release on PERST# in PHY
    1181                 :            :          */
    1182                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
    1183         [ #  # ]:          0 :         if (ret_val)
    1184                 :          0 :                 goto release;
    1185                 :          0 :         phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
    1186                 :            :                     I218_ULP_CONFIG1_DISABLE_SMB_PERST);
    1187         [ #  # ]:          0 :         if (to_sx) {
    1188         [ #  # ]:          0 :                 if (E1000_READ_REG(hw, E1000_WUFC) & E1000_WUFC_LNKC)
    1189                 :          0 :                         phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
    1190                 :            :                 else
    1191                 :          0 :                         phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
    1192                 :            : 
    1193                 :          0 :                 phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
    1194                 :          0 :                 phy_reg &= ~I218_ULP_CONFIG1_INBAND_EXIT;
    1195                 :            :         } else {
    1196                 :          0 :                 phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
    1197                 :          0 :                 phy_reg &= ~I218_ULP_CONFIG1_STICKY_ULP;
    1198                 :          0 :                 phy_reg &= ~I218_ULP_CONFIG1_WOL_HOST;
    1199                 :            :         }
    1200                 :          0 :         e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
    1201                 :            : 
    1202                 :            :         /* Set Disable SMBus Release on PERST# in MAC */
    1203                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM7);
    1204                 :          0 :         mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
    1205                 :          0 :         E1000_WRITE_REG(hw, E1000_FEXTNVM7, mac_reg);
    1206                 :            : 
    1207                 :            :         /* Commit ULP changes in PHY by starting auto ULP configuration */
    1208                 :          0 :         phy_reg |= I218_ULP_CONFIG1_START;
    1209                 :          0 :         e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
    1210                 :            : 
    1211         [ #  # ]:          0 :         if (!to_sx) {
    1212                 :            :                 /* Disable Tx so that the MAC doesn't send any (buffered)
    1213                 :            :                  * packets to the PHY.
    1214                 :            :                  */
    1215                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_TCTL);
    1216                 :          0 :                 mac_reg &= ~E1000_TCTL_EN;
    1217                 :          0 :                 E1000_WRITE_REG(hw, E1000_TCTL, mac_reg);
    1218                 :            :         }
    1219                 :            : 
    1220   [ #  #  #  #  :          0 :         if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6) &&
                   #  # ]
    1221         [ #  # ]:          0 :             to_sx && (E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
    1222                 :          0 :                 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
    1223                 :            :                                                         oem_reg);
    1224         [ #  # ]:          0 :                 if (ret_val)
    1225                 :          0 :                         goto release;
    1226                 :            :         }
    1227                 :            : 
    1228                 :          0 : release:
    1229                 :          0 :         hw->phy.ops.release(hw);
    1230                 :          0 : out:
    1231         [ #  # ]:          0 :         if (ret_val)
    1232                 :          0 :                 DEBUGOUT1("Error in ULP enable flow: %d\n", ret_val);
    1233                 :            :         else
    1234                 :          0 :                 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
    1235                 :            : 
    1236                 :            :         return ret_val;
    1237                 :            : }
    1238                 :            : 
    1239                 :            : /**
    1240                 :            :  *  e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
    1241                 :            :  *  @hw: pointer to the HW structure
    1242                 :            :  *  @force: boolean indicating whether or not to force disabling ULP
    1243                 :            :  *
    1244                 :            :  *  Un-configure ULP mode when link is up, the system is transitioned from
    1245                 :            :  *  Sx or the driver is unloaded.  If on a Manageability Engine (ME) enabled
    1246                 :            :  *  system, poll for an indication from ME that ULP has been un-configured.
    1247                 :            :  *  If not on an ME enabled system, un-configure the ULP mode by software.
    1248                 :            :  *
    1249                 :            :  *  During nominal operation, this function is called when link is acquired
    1250                 :            :  *  to disable ULP mode (force=false); otherwise, for example when unloading
    1251                 :            :  *  the driver or during Sx->S0 transitions, this is called with force=true
    1252                 :            :  *  to forcibly disable ULP.
    1253                 :            : 
    1254                 :            :  *  When the cable is plugged in while the device is in D0, a Cable Status
    1255                 :            :  *  Change interrupt is generated which causes this function to be called
    1256                 :            :  *  to partially disable ULP mode and restart autonegotiation.  This function
    1257                 :            :  *  is then called again due to the resulting Link Status Change interrupt
    1258                 :            :  *  to finish cleaning up after the ULP flow.
    1259                 :            :  */
    1260                 :          0 : s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
    1261                 :            : {
    1262                 :            :         s32 ret_val = E1000_SUCCESS;
    1263                 :            :         u8 ulp_exit_timeout = 30;
    1264                 :            :         u32 mac_reg;
    1265                 :            :         u16 phy_reg;
    1266                 :            :         int i = 0;
    1267                 :            : 
    1268         [ #  # ]:          0 :         if ((hw->mac.type < e1000_pch_lpt) ||
    1269   [ #  #  #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_LM) ||
    1270         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_V) ||
    1271         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_I218_LM2) ||
    1272                 :          0 :             (hw->device_id == E1000_DEV_ID_PCH_I218_V2) ||
    1273         [ #  # ]:          0 :             (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
    1274                 :            :                 return 0;
    1275                 :            : 
    1276         [ #  # ]:          0 :         if (E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID) {
    1277         [ #  # ]:          0 :                 if (force) {
    1278                 :            :                         /* Request ME un-configure ULP mode in the PHY */
    1279                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_H2ME);
    1280                 :          0 :                         mac_reg &= ~E1000_H2ME_ULP;
    1281                 :          0 :                         mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
    1282                 :          0 :                         E1000_WRITE_REG(hw, E1000_H2ME, mac_reg);
    1283                 :            :                 }
    1284                 :            : 
    1285         [ #  # ]:          0 :                 if (hw->mac.type == e1000_pch_cnp)
    1286                 :            :                         ulp_exit_timeout = 100;
    1287                 :            : 
    1288         [ #  # ]:          0 :                 while (E1000_READ_REG(hw, E1000_FWSM) &
    1289                 :            :                        E1000_FWSM_ULP_CFG_DONE) {
    1290         [ #  # ]:          0 :                         if (i++ == ulp_exit_timeout) {
    1291                 :            :                                 ret_val = -E1000_ERR_PHY;
    1292                 :          0 :                                 goto out;
    1293                 :            :                         }
    1294                 :            : 
    1295                 :          0 :                         msec_delay(10);
    1296                 :            :                 }
    1297                 :          0 :                 DEBUGOUT1("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
    1298                 :            : 
    1299         [ #  # ]:          0 :                 if (force) {
    1300                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_H2ME);
    1301                 :          0 :                         mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
    1302                 :          0 :                         E1000_WRITE_REG(hw, E1000_H2ME, mac_reg);
    1303                 :            :                 } else {
    1304                 :            :                         /* Clear H2ME.ULP after ME ULP configuration */
    1305                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_H2ME);
    1306                 :          0 :                         mac_reg &= ~E1000_H2ME_ULP;
    1307                 :          0 :                         E1000_WRITE_REG(hw, E1000_H2ME, mac_reg);
    1308                 :            : 
    1309                 :            :                         /* Restore link speed advertisements and restart
    1310                 :            :                          * Auto-negotiation
    1311                 :            :                          */
    1312         [ #  # ]:          0 :                         if (hw->mac.autoneg) {
    1313                 :          0 :                                 ret_val = e1000_phy_setup_autoneg(hw);
    1314         [ #  # ]:          0 :                                 if (ret_val)
    1315                 :          0 :                                         goto out;
    1316                 :            :                         } else {
    1317                 :          0 :                                 ret_val = e1000_setup_copper_link_generic(hw);
    1318         [ #  # ]:          0 :                                 if (ret_val)
    1319                 :          0 :                                         goto out;
    1320                 :            :                         }
    1321                 :          0 :                         ret_val = e1000_oem_bits_config_ich8lan(hw, true);
    1322                 :            :                 }
    1323                 :            : 
    1324                 :          0 :                 goto out;
    1325                 :            :         }
    1326                 :            : 
    1327                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    1328         [ #  # ]:          0 :         if (ret_val)
    1329                 :          0 :                 goto out;
    1330                 :            : 
    1331                 :            :         /* Revert the change to the 'Link Status Change'
    1332                 :            :          * interrupt to trigger on 'Cable Status Change'
    1333                 :            :          */
    1334                 :          0 :         ret_val = e1000_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_OP_MODES,
    1335                 :            :                                              &phy_reg);
    1336         [ #  # ]:          0 :         if (ret_val)
    1337                 :          0 :                 goto release;
    1338                 :          0 :         phy_reg &= ~E1000_KMRNCTRLSTA_OP_MODES_LSC2CSC;
    1339                 :          0 :         e1000_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_OP_MODES, phy_reg);
    1340                 :            : 
    1341         [ #  # ]:          0 :         if (force)
    1342                 :            :                 /* Toggle LANPHYPC Value bit */
    1343                 :          0 :                 e1000_toggle_lanphypc_pch_lpt(hw);
    1344                 :            : 
    1345                 :            :         /* Unforce SMBus mode in PHY */
    1346                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
    1347         [ #  # ]:          0 :         if (ret_val) {
    1348                 :            :                 /* The MAC might be in PCIe mode, so temporarily force to
    1349                 :            :                  * SMBus mode in order to access the PHY.
    1350                 :            :                  */
    1351                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
    1352                 :          0 :                 mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
    1353                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
    1354                 :            : 
    1355                 :          0 :                 msec_delay(50);
    1356                 :            : 
    1357                 :          0 :                 ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
    1358                 :            :                                                        &phy_reg);
    1359         [ #  # ]:          0 :                 if (ret_val)
    1360                 :          0 :                         goto release;
    1361                 :            :         }
    1362                 :          0 :         phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
    1363                 :          0 :         e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
    1364                 :            : 
    1365                 :            :         /* Unforce SMBus mode in MAC */
    1366                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
    1367                 :          0 :         mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
    1368                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, mac_reg);
    1369                 :            : 
    1370                 :            :         /* When ULP mode was previously entered, K1 was disabled by the
    1371                 :            :          * hardware.  Re-Enable K1 in the PHY when exiting ULP.
    1372                 :            :          */
    1373                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
    1374         [ #  # ]:          0 :         if (ret_val)
    1375                 :          0 :                 goto release;
    1376                 :          0 :         phy_reg |= HV_PM_CTRL_K1_ENABLE;
    1377                 :          0 :         e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
    1378                 :            : 
    1379                 :            :         /* Clear ULP enabled configuration */
    1380                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
    1381         [ #  # ]:          0 :         if (ret_val)
    1382                 :          0 :                 goto release;
    1383                 :            :         /* CSC interrupt received due to ULP Indication */
    1384   [ #  #  #  # ]:          0 :         if ((phy_reg & I218_ULP_CONFIG1_IND) || force) {
    1385                 :          0 :                 phy_reg &= ~(I218_ULP_CONFIG1_IND |
    1386                 :            :                              I218_ULP_CONFIG1_STICKY_ULP |
    1387                 :            :                              I218_ULP_CONFIG1_RESET_TO_SMBUS |
    1388                 :            :                              I218_ULP_CONFIG1_WOL_HOST |
    1389                 :            :                              I218_ULP_CONFIG1_INBAND_EXIT |
    1390                 :            :                              I218_ULP_CONFIG1_EN_ULP_LANPHYPC |
    1391                 :            :                              I218_ULP_CONFIG1_DIS_CLR_STICKY_ON_PERST |
    1392                 :            :                              I218_ULP_CONFIG1_DISABLE_SMB_PERST);
    1393                 :          0 :                 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
    1394                 :            : 
    1395                 :            :                 /* Commit ULP changes by starting auto ULP configuration */
    1396                 :          0 :                 phy_reg |= I218_ULP_CONFIG1_START;
    1397                 :          0 :                 e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
    1398                 :            : 
    1399                 :            :                 /* Clear Disable SMBus Release on PERST# in MAC */
    1400                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM7);
    1401                 :          0 :                 mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
    1402                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM7, mac_reg);
    1403                 :            : 
    1404         [ #  # ]:          0 :                 if (!force) {
    1405                 :          0 :                         hw->phy.ops.release(hw);
    1406                 :            : 
    1407         [ #  # ]:          0 :                         if (hw->mac.autoneg)
    1408                 :          0 :                                 e1000_phy_setup_autoneg(hw);
    1409                 :            :                         else
    1410                 :          0 :                                 e1000_setup_copper_link_generic(hw);
    1411                 :            : 
    1412                 :          0 :                         e1000_sw_lcd_config_ich8lan(hw);
    1413                 :            : 
    1414                 :          0 :                         e1000_oem_bits_config_ich8lan(hw, true);
    1415                 :            : 
    1416                 :            :                         /* Set ULP state to unknown and return non-zero to
    1417                 :            :                          * indicate no link (yet) and re-enter on the next LSC
    1418                 :            :                          * to finish disabling ULP flow.
    1419                 :            :                          */
    1420                 :          0 :                         hw->dev_spec.ich8lan.ulp_state =
    1421                 :            :                             e1000_ulp_state_unknown;
    1422                 :            : 
    1423                 :          0 :                         return 1;
    1424                 :            :                 }
    1425                 :            :         }
    1426                 :            : 
    1427                 :            :         /* Re-enable Tx */
    1428                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_TCTL);
    1429                 :          0 :         mac_reg |= E1000_TCTL_EN;
    1430                 :          0 :         E1000_WRITE_REG(hw, E1000_TCTL, mac_reg);
    1431                 :            : 
    1432                 :          0 : release:
    1433                 :          0 :         hw->phy.ops.release(hw);
    1434         [ #  # ]:          0 :         if (force) {
    1435                 :          0 :                 hw->phy.ops.reset(hw);
    1436                 :          0 :                 msec_delay(50);
    1437                 :            :         }
    1438                 :          0 : out:
    1439         [ #  # ]:          0 :         if (ret_val)
    1440                 :          0 :                 DEBUGOUT1("Error in ULP disable flow: %d\n", ret_val);
    1441                 :            :         else
    1442                 :          0 :                 hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
    1443                 :            : 
    1444                 :            :         return ret_val;
    1445                 :            : }
    1446                 :            : 
    1447                 :            : 
    1448                 :            : 
    1449                 :            : /**
    1450                 :            :  *  e1000_check_for_copper_link_ich8lan - Check for link (Copper)
    1451                 :            :  *  @hw: pointer to the HW structure
    1452                 :            :  *
    1453                 :            :  *  Checks to see of the link status of the hardware has changed.  If a
    1454                 :            :  *  change in link status has been detected, then we read the PHY registers
    1455                 :            :  *  to get the current speed/duplex if link exists.
    1456                 :            :  **/
    1457                 :          0 : STATIC s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
    1458                 :            : {
    1459                 :            :         struct e1000_mac_info *mac = &hw->mac;
    1460                 :            :         s32 ret_val, tipg_reg = 0;
    1461                 :            :         u16 emi_addr, emi_val = 0;
    1462                 :          0 :         bool link = false;
    1463                 :            :         u16 phy_reg;
    1464                 :            : 
    1465                 :          0 :         DEBUGFUNC("e1000_check_for_copper_link_ich8lan");
    1466                 :            : 
    1467                 :            :         /* We only want to go out to the PHY registers to see if Auto-Neg
    1468                 :            :          * has completed and/or if our link status has changed.  The
    1469                 :            :          * get_link_status flag is set upon receiving a Link Status
    1470                 :            :          * Change or Rx Sequence Error interrupt.
    1471                 :            :          */
    1472         [ #  # ]:          0 :         if (!mac->get_link_status)
    1473                 :            :                 return E1000_SUCCESS;
    1474                 :            : 
    1475         [ #  # ]:          0 :         if ((hw->mac.type < e1000_pch_lpt) ||
    1476   [ #  #  #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_LM) ||
    1477                 :            :             (hw->device_id == E1000_DEV_ID_PCH_LPT_I217_V)) {
    1478                 :            :                 /* First we want to see if the MII Status Register reports
    1479                 :            :                  * link.  If so, then we want to get the current speed/duplex
    1480                 :            :                  * of the PHY.
    1481                 :            :                  */
    1482                 :          0 :                 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
    1483         [ #  # ]:          0 :                 if (ret_val)
    1484                 :            :                         return ret_val;
    1485                 :            :         } else {
    1486                 :            :                 /* Check the MAC's STATUS register to determine link state
    1487                 :            :                  * since the PHY could be inaccessible while in ULP mode.
    1488                 :            :                  */
    1489                 :          0 :                 link = !!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU);
    1490         [ #  # ]:          0 :                 if (link)
    1491                 :          0 :                         ret_val = e1000_disable_ulp_lpt_lp(hw, false);
    1492                 :            :                 else
    1493                 :          0 :                         ret_val = e1000_enable_ulp_lpt_lp(hw, false);
    1494         [ #  # ]:          0 :                 if (ret_val)
    1495                 :            :                         return ret_val;
    1496                 :            :         }
    1497                 :            : 
    1498         [ #  # ]:          0 :         if (hw->mac.type == e1000_pchlan) {
    1499                 :          0 :                 ret_val = e1000_k1_gig_workaround_hv(hw, link);
    1500         [ #  # ]:          0 :                 if (ret_val)
    1501                 :            :                         return ret_val;
    1502                 :            :         }
    1503                 :            : 
    1504                 :            :         /* When connected at 10Mbps half-duplex, some parts are excessively
    1505                 :            :          * aggressive resulting in many collisions. To avoid this, increase
    1506                 :            :          * the IPG and reduce Rx latency in the PHY.
    1507                 :            :          */
    1508   [ #  #  #  # ]:          0 :         if ((hw->mac.type >= e1000_pch2lan) && link) {
    1509                 :            :                 u16 speed, duplex;
    1510                 :            : 
    1511                 :          0 :                 e1000_get_speed_and_duplex_copper_generic(hw, &speed, &duplex);
    1512                 :          0 :                 tipg_reg = E1000_READ_REG(hw, E1000_TIPG);
    1513                 :          0 :                 tipg_reg &= ~E1000_TIPG_IPGT_MASK;
    1514                 :            : 
    1515   [ #  #  #  # ]:          0 :                 if (duplex == HALF_DUPLEX && speed == SPEED_10) {
    1516                 :          0 :                         tipg_reg |= 0xFF;
    1517                 :            :                         /* Reduce Rx latency in analog PHY */
    1518                 :          0 :                         emi_val = 0;
    1519   [ #  #  #  # ]:          0 :                 } else if (hw->mac.type >= e1000_pch_spt &&
    1520         [ #  # ]:          0 :                            duplex == FULL_DUPLEX && speed != SPEED_1000) {
    1521                 :          0 :                         tipg_reg |= 0xC;
    1522                 :          0 :                         emi_val = 1;
    1523                 :            :                 } else {
    1524                 :            :                         /* Roll back the default values */
    1525                 :          0 :                         tipg_reg |= 0x08;
    1526                 :            :                         emi_val = 1;
    1527                 :            :                 }
    1528                 :            : 
    1529                 :          0 :                 E1000_WRITE_REG(hw, E1000_TIPG, tipg_reg);
    1530                 :            : 
    1531                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    1532         [ #  # ]:          0 :                 if (ret_val)
    1533                 :          0 :                         return ret_val;
    1534                 :            : 
    1535         [ #  # ]:          0 :                 if (hw->mac.type == e1000_pch2lan)
    1536                 :            :                         emi_addr = I82579_RX_CONFIG;
    1537                 :            :                 else
    1538                 :            :                         emi_addr = I217_RX_CONFIG;
    1539                 :          0 :                 ret_val = e1000_write_emi_reg_locked(hw, emi_addr, emi_val);
    1540                 :            : 
    1541                 :            : 
    1542         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_lpt) {
    1543                 :          0 :                         hw->phy.ops.read_reg_locked(hw, I217_PLL_CLOCK_GATE_REG,
    1544                 :            :                                                     &phy_reg);
    1545                 :          0 :                         phy_reg &= ~I217_PLL_CLOCK_GATE_MASK;
    1546         [ #  # ]:          0 :                         if (speed == SPEED_100 || speed == SPEED_10)
    1547                 :          0 :                                 phy_reg |= 0x3E8;
    1548                 :            :                         else
    1549                 :          0 :                                 phy_reg |= 0xFA;
    1550                 :          0 :                         hw->phy.ops.write_reg_locked(hw,
    1551                 :            :                                                      I217_PLL_CLOCK_GATE_REG,
    1552                 :            :                                                      phy_reg);
    1553                 :            : 
    1554         [ #  # ]:          0 :                         if (speed == SPEED_1000) {
    1555                 :          0 :                                 hw->phy.ops.read_reg_locked(hw, HV_PM_CTRL,
    1556                 :            :                                                             &phy_reg);
    1557                 :            : 
    1558                 :          0 :                                 phy_reg |= HV_PM_CTRL_K1_CLK_REQ;
    1559                 :            : 
    1560                 :          0 :                                 hw->phy.ops.write_reg_locked(hw, HV_PM_CTRL,
    1561                 :            :                                                              phy_reg);
    1562                 :            :                                 }
    1563                 :            :                  }
    1564                 :          0 :                 hw->phy.ops.release(hw);
    1565                 :            : 
    1566         [ #  # ]:          0 :                 if (ret_val)
    1567                 :            :                         return ret_val;
    1568                 :            : 
    1569         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt) {
    1570                 :            :                         u16 data;
    1571                 :            :                         u16 ptr_gap;
    1572                 :            : 
    1573         [ #  # ]:          0 :                         if (speed == SPEED_1000) {
    1574                 :          0 :                                 ret_val = hw->phy.ops.acquire(hw);
    1575         [ #  # ]:          0 :                                 if (ret_val)
    1576                 :          0 :                                         return ret_val;
    1577                 :            : 
    1578                 :          0 :                                 ret_val = hw->phy.ops.read_reg_locked(hw,
    1579                 :            :                                                               PHY_REG(776, 20),
    1580                 :            :                                                               &data);
    1581         [ #  # ]:          0 :                                 if (ret_val) {
    1582                 :          0 :                                         hw->phy.ops.release(hw);
    1583                 :          0 :                                         return ret_val;
    1584                 :            :                                 }
    1585                 :            : 
    1586                 :          0 :                                 ptr_gap = (data & (0x3FF << 2)) >> 2;
    1587         [ #  # ]:          0 :                                 if (ptr_gap < 0x18) {
    1588                 :          0 :                                         data &= ~(0x3FF << 2);
    1589                 :          0 :                                         data |= (0x18 << 2);
    1590                 :            :                                         ret_val =
    1591                 :          0 :                                                 hw->phy.ops.write_reg_locked(hw,
    1592                 :            :                                                         PHY_REG(776, 20), data);
    1593                 :            :                                 }
    1594                 :          0 :                                 hw->phy.ops.release(hw);
    1595         [ #  # ]:          0 :                                 if (ret_val)
    1596                 :            :                                         return ret_val;
    1597                 :            :                         } else {
    1598                 :          0 :                                 ret_val = hw->phy.ops.acquire(hw);
    1599         [ #  # ]:          0 :                                 if (ret_val)
    1600                 :            :                                         return ret_val;
    1601                 :            : 
    1602                 :          0 :                                 ret_val = hw->phy.ops.write_reg_locked(hw,
    1603                 :            :                                                              PHY_REG(776, 20),
    1604                 :            :                                                              0xC023);
    1605                 :          0 :                                 hw->phy.ops.release(hw);
    1606         [ #  # ]:          0 :                                 if (ret_val)
    1607                 :            :                                         return ret_val;
    1608                 :            : 
    1609                 :            :                         }
    1610                 :            :                 }
    1611                 :            :         }
    1612                 :            : 
    1613                 :            :         /* I217 Packet Loss issue:
    1614                 :            :          * ensure that FEXTNVM4 Beacon Duration is set correctly
    1615                 :            :          * on power up.
    1616                 :            :          * Set the Beacon Duration for I217 to 8 usec
    1617                 :            :          */
    1618         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_lpt) {
    1619                 :            :                 u32 mac_reg;
    1620                 :            : 
    1621                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM4);
    1622                 :          0 :                 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
    1623                 :          0 :                 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
    1624                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM4, mac_reg);
    1625                 :            :         }
    1626                 :            : 
    1627                 :            :         /* Work-around I218 hang issue */
    1628                 :          0 :         if ((hw->device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
    1629         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
    1630         [ #  # ]:          0 :             (hw->device_id == E1000_DEV_ID_PCH_I218_LM3) ||
    1631                 :            :             (hw->device_id == E1000_DEV_ID_PCH_I218_V3)) {
    1632                 :          0 :                 ret_val = e1000_k1_workaround_lpt_lp(hw, link);
    1633         [ #  # ]:          0 :                 if (ret_val)
    1634                 :            :                         return ret_val;
    1635                 :            :         }
    1636                 :            :         /* Clear link partner's EEE ability */
    1637                 :          0 :         hw->dev_spec.ich8lan.eee_lp_ability = 0;
    1638                 :            : 
    1639                 :            :         /* Configure K0s minimum time */
    1640         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_lpt) {
    1641                 :          0 :                 e1000_configure_k0s_lpt(hw, K1_ENTRY_LATENCY, K1_MIN_TIME);
    1642                 :            :         }
    1643                 :            : 
    1644         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_lpt) {
    1645                 :          0 :                 u32 fextnvm6 = E1000_READ_REG(hw, E1000_FEXTNVM6);
    1646                 :            : 
    1647         [ #  # ]:          0 :                 if (hw->mac.type == e1000_pch_spt) {
    1648                 :            :                         /* FEXTNVM6 K1-off workaround - for SPT only */
    1649                 :          0 :                         u32 pcieanacfg = E1000_READ_REG(hw, E1000_PCIEANACFG);
    1650                 :            : 
    1651         [ #  # ]:          0 :                         if (pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE)
    1652                 :          0 :                                 fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
    1653                 :            :                         else
    1654                 :          0 :                                 fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
    1655                 :            :                 }
    1656                 :            : 
    1657         [ #  # ]:          0 :                 if (hw->dev_spec.ich8lan.disable_k1_off == true)
    1658                 :          0 :                         fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
    1659                 :            : 
    1660                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM6, fextnvm6);
    1661                 :            :         }
    1662                 :            : 
    1663         [ #  # ]:          0 :         if (!link)
    1664                 :            :                 return E1000_SUCCESS; /* No link detected */
    1665                 :            : 
    1666                 :          0 :         mac->get_link_status = false;
    1667                 :            : 
    1668      [ #  #  # ]:          0 :         switch (hw->mac.type) {
    1669                 :          0 :         case e1000_pch2lan:
    1670                 :          0 :                 ret_val = e1000_k1_workaround_lv(hw);
    1671         [ #  # ]:          0 :                 if (ret_val)
    1672                 :            :                         return ret_val;
    1673                 :            :                 /* fall-thru */
    1674                 :            :         case e1000_pchlan:
    1675         [ #  # ]:          0 :                 if (hw->phy.type == e1000_phy_82578) {
    1676                 :          0 :                         ret_val = e1000_link_stall_workaround_hv(hw);
    1677         [ #  # ]:          0 :                         if (ret_val)
    1678                 :            :                                 return ret_val;
    1679                 :            :                 }
    1680                 :            : 
    1681                 :            :                 /* Workaround for PCHx parts in half-duplex:
    1682                 :            :                  * Set the number of preambles removed from the packet
    1683                 :            :                  * when it is passed from the PHY to the MAC to prevent
    1684                 :            :                  * the MAC from misinterpreting the packet type.
    1685                 :            :                  */
    1686                 :          0 :                 hw->phy.ops.read_reg(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
    1687                 :          0 :                 phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
    1688                 :            : 
    1689         [ #  # ]:          0 :                 if ((E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_FD) !=
    1690                 :            :                     E1000_STATUS_FD)
    1691                 :          0 :                         phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
    1692                 :            : 
    1693                 :          0 :                 hw->phy.ops.write_reg(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
    1694                 :          0 :                 break;
    1695                 :            :         default:
    1696                 :            :                 break;
    1697                 :            :         }
    1698                 :            : 
    1699                 :            :         /* Check if there was DownShift, must be checked
    1700                 :            :          * immediately after link-up
    1701                 :            :          */
    1702                 :          0 :         e1000_check_downshift_generic(hw);
    1703                 :            : 
    1704                 :            :         /* Enable/Disable EEE after link up */
    1705         [ #  # ]:          0 :         if (hw->phy.type > e1000_phy_82579) {
    1706                 :          0 :                 ret_val = e1000_set_eee_pchlan(hw);
    1707         [ #  # ]:          0 :                 if (ret_val)
    1708                 :            :                         return ret_val;
    1709                 :            :         }
    1710                 :            : 
    1711                 :            :         /* If we are forcing speed/duplex, then we simply return since
    1712                 :            :          * we have already determined whether we have link or not.
    1713                 :            :          */
    1714         [ #  # ]:          0 :         if (!mac->autoneg)
    1715                 :            :                 return -E1000_ERR_CONFIG;
    1716                 :            : 
    1717                 :            :         /* Auto-Neg is enabled.  Auto Speed Detection takes care
    1718                 :            :          * of MAC speed/duplex configuration.  So we only need to
    1719                 :            :          * configure Collision Distance in the MAC.
    1720                 :            :          */
    1721                 :          0 :         mac->ops.config_collision_dist(hw);
    1722                 :            : 
    1723                 :            :         /* Configure Flow Control now that Auto-Neg has completed.
    1724                 :            :          * First, we need to restore the desired flow control
    1725                 :            :          * settings because we may have had to re-autoneg with a
    1726                 :            :          * different link partner.
    1727                 :            :          */
    1728                 :          0 :         ret_val = e1000_config_fc_after_link_up_generic(hw);
    1729         [ #  # ]:          0 :         if (ret_val)
    1730                 :          0 :                 DEBUGOUT("Error configuring flow control\n");
    1731                 :            : 
    1732                 :            :         return ret_val;
    1733                 :            : }
    1734                 :            : 
    1735                 :            : /**
    1736                 :            :  *  e1000_init_function_pointers_ich8lan - Initialize ICH8 function pointers
    1737                 :            :  *  @hw: pointer to the HW structure
    1738                 :            :  *
    1739                 :            :  *  Initialize family-specific function pointers for PHY, MAC, and NVM.
    1740                 :            :  **/
    1741                 :          0 : void e1000_init_function_pointers_ich8lan(struct e1000_hw *hw)
    1742                 :            : {
    1743                 :          0 :         DEBUGFUNC("e1000_init_function_pointers_ich8lan");
    1744                 :            : 
    1745                 :          0 :         hw->mac.ops.init_params = e1000_init_mac_params_ich8lan;
    1746                 :          0 :         hw->nvm.ops.init_params = e1000_init_nvm_params_ich8lan;
    1747      [ #  #  # ]:          0 :         switch (hw->mac.type) {
    1748                 :          0 :         case e1000_ich8lan:
    1749                 :            :         case e1000_ich9lan:
    1750                 :            :         case e1000_ich10lan:
    1751                 :          0 :                 hw->phy.ops.init_params = e1000_init_phy_params_ich8lan;
    1752                 :          0 :                 break;
    1753                 :          0 :         case e1000_pchlan:
    1754                 :            :         case e1000_pch2lan:
    1755                 :            :         case e1000_pch_lpt:
    1756                 :            :         case e1000_pch_spt:
    1757                 :            :         case e1000_pch_cnp:
    1758                 :            :         case e1000_pch_adp:
    1759                 :          0 :                 hw->phy.ops.init_params = e1000_init_phy_params_pchlan;
    1760                 :          0 :                 break;
    1761                 :            :         default:
    1762                 :            :                 break;
    1763                 :            :         }
    1764                 :          0 : }
    1765                 :            : 
    1766                 :            : /**
    1767                 :            :  *  e1000_acquire_nvm_ich8lan - Acquire NVM mutex
    1768                 :            :  *  @hw: pointer to the HW structure
    1769                 :            :  *
    1770                 :            :  *  Acquires the mutex for performing NVM operations.
    1771                 :            :  **/
    1772                 :          0 : STATIC s32 e1000_acquire_nvm_ich8lan(struct e1000_hw *hw)
    1773                 :            : {
    1774                 :          0 :         DEBUGFUNC("e1000_acquire_nvm_ich8lan");
    1775                 :            : 
    1776                 :          0 :         E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.nvm_mutex);
    1777                 :            : 
    1778                 :          0 :         return E1000_SUCCESS;
    1779                 :            : }
    1780                 :            : 
    1781                 :            : /**
    1782                 :            :  *  e1000_release_nvm_ich8lan - Release NVM mutex
    1783                 :            :  *  @hw: pointer to the HW structure
    1784                 :            :  *
    1785                 :            :  *  Releases the mutex used while performing NVM operations.
    1786                 :            :  **/
    1787                 :          0 : STATIC void e1000_release_nvm_ich8lan(struct e1000_hw *hw)
    1788                 :            : {
    1789                 :          0 :         DEBUGFUNC("e1000_release_nvm_ich8lan");
    1790                 :            : 
    1791                 :          0 :         E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.nvm_mutex);
    1792                 :            : 
    1793                 :          0 :         return;
    1794                 :            : }
    1795                 :            : 
    1796                 :            : /**
    1797                 :            :  *  e1000_acquire_swflag_ich8lan - Acquire software control flag
    1798                 :            :  *  @hw: pointer to the HW structure
    1799                 :            :  *
    1800                 :            :  *  Acquires the software control flag for performing PHY and select
    1801                 :            :  *  MAC CSR accesses.
    1802                 :            :  **/
    1803                 :          0 : STATIC s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
    1804                 :            : {
    1805                 :            :         u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
    1806                 :            :         s32 ret_val = E1000_SUCCESS;
    1807                 :            : 
    1808                 :          0 :         DEBUGFUNC("e1000_acquire_swflag_ich8lan");
    1809                 :            : 
    1810                 :          0 :         E1000_MUTEX_LOCK(&hw->dev_spec.ich8lan.swflag_mutex);
    1811                 :            : 
    1812         [ #  # ]:          0 :         while (timeout) {
    1813                 :          0 :                 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    1814         [ #  # ]:          0 :                 if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
    1815                 :            :                         break;
    1816                 :            : 
    1817                 :          0 :                 msec_delay_irq(1);
    1818                 :          0 :                 timeout--;
    1819                 :            :         }
    1820                 :            : 
    1821         [ #  # ]:          0 :         if (!timeout) {
    1822                 :          0 :                 DEBUGOUT("SW has already locked the resource.\n");
    1823                 :            :                 ret_val = -E1000_ERR_CONFIG;
    1824                 :          0 :                 goto out;
    1825                 :            :         }
    1826                 :            : 
    1827                 :            :         timeout = SW_FLAG_TIMEOUT;
    1828                 :            : 
    1829                 :          0 :         extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
    1830                 :          0 :         E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
    1831                 :            : 
    1832         [ #  # ]:          0 :         while (timeout) {
    1833                 :          0 :                 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    1834         [ #  # ]:          0 :                 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
    1835                 :            :                         break;
    1836                 :            : 
    1837                 :          0 :                 msec_delay_irq(1);
    1838                 :          0 :                 timeout--;
    1839                 :            :         }
    1840                 :            : 
    1841         [ #  # ]:          0 :         if (!timeout) {
    1842                 :          0 :                 DEBUGOUT2("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
    1843                 :            :                           E1000_READ_REG(hw, E1000_FWSM), extcnf_ctrl);
    1844                 :          0 :                 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
    1845                 :          0 :                 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
    1846                 :            :                 ret_val = -E1000_ERR_CONFIG;
    1847                 :          0 :                 goto out;
    1848                 :            :         }
    1849                 :            : 
    1850                 :          0 : out:
    1851                 :            :         if (ret_val)
    1852                 :          0 :                 E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
    1853                 :            : 
    1854                 :          0 :         return ret_val;
    1855                 :            : }
    1856                 :            : 
    1857                 :            : /**
    1858                 :            :  *  e1000_release_swflag_ich8lan - Release software control flag
    1859                 :            :  *  @hw: pointer to the HW structure
    1860                 :            :  *
    1861                 :            :  *  Releases the software control flag for performing PHY and select
    1862                 :            :  *  MAC CSR accesses.
    1863                 :            :  **/
    1864                 :          0 : STATIC void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
    1865                 :            : {
    1866                 :            :         u32 extcnf_ctrl;
    1867                 :            : 
    1868                 :          0 :         DEBUGFUNC("e1000_release_swflag_ich8lan");
    1869                 :            : 
    1870                 :          0 :         extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    1871                 :            : 
    1872         [ #  # ]:          0 :         if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
    1873                 :          0 :                 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
    1874                 :          0 :                 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
    1875                 :            :         } else {
    1876                 :          0 :                 DEBUGOUT("Semaphore unexpectedly released by sw/fw/hw\n");
    1877                 :            :         }
    1878                 :            : 
    1879                 :          0 :         E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
    1880                 :            : 
    1881                 :          0 :         return;
    1882                 :            : }
    1883                 :            : 
    1884                 :            : /**
    1885                 :            :  *  e1000_check_mng_mode_ich8lan - Checks management mode
    1886                 :            :  *  @hw: pointer to the HW structure
    1887                 :            :  *
    1888                 :            :  *  This checks if the adapter has any manageability enabled.
    1889                 :            :  *  This is a function pointer entry point only called by read/write
    1890                 :            :  *  routines for the PHY and NVM parts.
    1891                 :            :  **/
    1892                 :          0 : STATIC bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
    1893                 :            : {
    1894                 :            :         u32 fwsm;
    1895                 :            : 
    1896                 :          0 :         DEBUGFUNC("e1000_check_mng_mode_ich8lan");
    1897                 :            : 
    1898                 :          0 :         fwsm = E1000_READ_REG(hw, E1000_FWSM);
    1899                 :            : 
    1900                 :          0 :         return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
    1901                 :            :                ((fwsm & E1000_FWSM_MODE_MASK) ==
    1902                 :            :                 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
    1903                 :            : }
    1904                 :            : 
    1905                 :            : /**
    1906                 :            :  *  e1000_check_mng_mode_pchlan - Checks management mode
    1907                 :            :  *  @hw: pointer to the HW structure
    1908                 :            :  *
    1909                 :            :  *  This checks if the adapter has iAMT enabled.
    1910                 :            :  *  This is a function pointer entry point only called by read/write
    1911                 :            :  *  routines for the PHY and NVM parts.
    1912                 :            :  **/
    1913                 :          0 : STATIC bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
    1914                 :            : {
    1915                 :            :         u32 fwsm;
    1916                 :            : 
    1917                 :          0 :         DEBUGFUNC("e1000_check_mng_mode_pchlan");
    1918                 :            : 
    1919                 :          0 :         fwsm = E1000_READ_REG(hw, E1000_FWSM);
    1920                 :            : 
    1921                 :          0 :         return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
    1922                 :            :                (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
    1923                 :            : }
    1924                 :            : 
    1925                 :            : /**
    1926                 :            :  *  e1000_rar_set_pch2lan - Set receive address register
    1927                 :            :  *  @hw: pointer to the HW structure
    1928                 :            :  *  @addr: pointer to the receive address
    1929                 :            :  *  @index: receive address array register
    1930                 :            :  *
    1931                 :            :  *  Sets the receive address array register at index to the address passed
    1932                 :            :  *  in by addr.  For 82579, RAR[0] is the base address register that is to
    1933                 :            :  *  contain the MAC address but RAR[1-6] are reserved for manageability (ME).
    1934                 :            :  *  Use SHRA[0-3] in place of those reserved for ME.
    1935                 :            :  **/
    1936                 :          0 : STATIC int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
    1937                 :            : {
    1938                 :            :         u32 rar_low, rar_high;
    1939                 :            : 
    1940                 :          0 :         DEBUGFUNC("e1000_rar_set_pch2lan");
    1941                 :            : 
    1942                 :            :         /* HW expects these in little endian so we reverse the byte order
    1943                 :            :          * from network order (big endian) to little endian
    1944                 :            :          */
    1945                 :          0 :         rar_low = ((u32) addr[0] |
    1946                 :          0 :                    ((u32) addr[1] << 8) |
    1947                 :          0 :                    ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
    1948                 :            : 
    1949                 :          0 :         rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
    1950                 :            : 
    1951                 :            :         /* If MAC address zero, no need to set the AV bit */
    1952         [ #  # ]:          0 :         if (rar_low || rar_high)
    1953                 :          0 :                 rar_high |= E1000_RAH_AV;
    1954                 :            : 
    1955         [ #  # ]:          0 :         if (index == 0) {
    1956                 :          0 :                 E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
    1957                 :          0 :                 E1000_WRITE_FLUSH(hw);
    1958                 :          0 :                 E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
    1959                 :          0 :                 E1000_WRITE_FLUSH(hw);
    1960                 :          0 :                 return E1000_SUCCESS;
    1961                 :            :         }
    1962                 :            : 
    1963                 :            :         /* RAR[1-6] are owned by manageability.  Skip those and program the
    1964                 :            :          * next address into the SHRA register array.
    1965                 :            :          */
    1966         [ #  # ]:          0 :         if (index < (u32) (hw->mac.rar_entry_count)) {
    1967                 :            :                 s32 ret_val;
    1968                 :            : 
    1969                 :          0 :                 ret_val = e1000_acquire_swflag_ich8lan(hw);
    1970         [ #  # ]:          0 :                 if (ret_val)
    1971                 :          0 :                         goto out;
    1972                 :            : 
    1973                 :          0 :                 E1000_WRITE_REG(hw, E1000_SHRAL(index - 1), rar_low);
    1974                 :          0 :                 E1000_WRITE_FLUSH(hw);
    1975                 :          0 :                 E1000_WRITE_REG(hw, E1000_SHRAH(index - 1), rar_high);
    1976                 :          0 :                 E1000_WRITE_FLUSH(hw);
    1977                 :            : 
    1978                 :          0 :                 e1000_release_swflag_ich8lan(hw);
    1979                 :            : 
    1980                 :            :                 /* verify the register updates */
    1981   [ #  #  #  # ]:          0 :                 if ((E1000_READ_REG(hw, E1000_SHRAL(index - 1)) == rar_low) &&
    1982                 :          0 :                     (E1000_READ_REG(hw, E1000_SHRAH(index - 1)) == rar_high))
    1983                 :            :                         return E1000_SUCCESS;
    1984                 :            : 
    1985                 :          0 :                 DEBUGOUT2("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
    1986                 :            :                          (index - 1), E1000_READ_REG(hw, E1000_FWSM));
    1987                 :            :         }
    1988                 :            : 
    1989                 :          0 : out:
    1990                 :          0 :         DEBUGOUT1("Failed to write receive address at index %d\n", index);
    1991                 :          0 :         return -E1000_ERR_CONFIG;
    1992                 :            : }
    1993                 :            : 
    1994                 :            : /**
    1995                 :            :  *  e1000_rar_set_pch_lpt - Set receive address registers
    1996                 :            :  *  @hw: pointer to the HW structure
    1997                 :            :  *  @addr: pointer to the receive address
    1998                 :            :  *  @index: receive address array register
    1999                 :            :  *
    2000                 :            :  *  Sets the receive address register array at index to the address passed
    2001                 :            :  *  in by addr. For LPT, RAR[0] is the base address register that is to
    2002                 :            :  *  contain the MAC address. SHRA[0-10] are the shared receive address
    2003                 :            :  *  registers that are shared between the Host and manageability engine (ME).
    2004                 :            :  **/
    2005                 :          0 : STATIC int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
    2006                 :            : {
    2007                 :            :         u32 rar_low, rar_high;
    2008                 :            :         u32 wlock_mac;
    2009                 :            : 
    2010                 :          0 :         DEBUGFUNC("e1000_rar_set_pch_lpt");
    2011                 :            : 
    2012                 :            :         /* HW expects these in little endian so we reverse the byte order
    2013                 :            :          * from network order (big endian) to little endian
    2014                 :            :          */
    2015                 :          0 :         rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
    2016                 :          0 :                    ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
    2017                 :            : 
    2018                 :          0 :         rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
    2019                 :            : 
    2020                 :            :         /* If MAC address zero, no need to set the AV bit */
    2021         [ #  # ]:          0 :         if (rar_low || rar_high)
    2022                 :          0 :                 rar_high |= E1000_RAH_AV;
    2023                 :            : 
    2024         [ #  # ]:          0 :         if (index == 0) {
    2025                 :          0 :                 E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
    2026                 :          0 :                 E1000_WRITE_FLUSH(hw);
    2027                 :          0 :                 E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
    2028                 :          0 :                 E1000_WRITE_FLUSH(hw);
    2029                 :          0 :                 return E1000_SUCCESS;
    2030                 :            :         }
    2031                 :            : 
    2032                 :            :         /* The manageability engine (ME) can lock certain SHRAR registers that
    2033                 :            :          * it is using - those registers are unavailable for use.
    2034                 :            :          */
    2035         [ #  # ]:          0 :         if (index < hw->mac.rar_entry_count) {
    2036                 :          0 :                 wlock_mac = E1000_READ_REG(hw, E1000_FWSM) &
    2037                 :            :                             E1000_FWSM_WLOCK_MAC_MASK;
    2038                 :          0 :                 wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
    2039                 :            : 
    2040                 :            :                 /* Check if all SHRAR registers are locked */
    2041         [ #  # ]:          0 :                 if (wlock_mac == 1)
    2042                 :          0 :                         goto out;
    2043                 :            : 
    2044         [ #  # ]:          0 :                 if ((wlock_mac == 0) || (index <= wlock_mac)) {
    2045                 :            :                         s32 ret_val;
    2046                 :            : 
    2047                 :          0 :                         ret_val = e1000_acquire_swflag_ich8lan(hw);
    2048                 :            : 
    2049         [ #  # ]:          0 :                         if (ret_val)
    2050                 :          0 :                                 goto out;
    2051                 :            : 
    2052                 :          0 :                         E1000_WRITE_REG(hw, E1000_SHRAL_PCH_LPT(index - 1),
    2053                 :            :                                         rar_low);
    2054                 :          0 :                         E1000_WRITE_FLUSH(hw);
    2055                 :          0 :                         E1000_WRITE_REG(hw, E1000_SHRAH_PCH_LPT(index - 1),
    2056                 :            :                                         rar_high);
    2057                 :          0 :                         E1000_WRITE_FLUSH(hw);
    2058                 :            : 
    2059                 :          0 :                         e1000_release_swflag_ich8lan(hw);
    2060                 :            : 
    2061                 :            :                         /* verify the register updates */
    2062   [ #  #  #  # ]:          0 :                         if ((E1000_READ_REG(hw, E1000_SHRAL_PCH_LPT(index - 1)) == rar_low) &&
    2063                 :          0 :                             (E1000_READ_REG(hw, E1000_SHRAH_PCH_LPT(index - 1)) == rar_high))
    2064                 :            :                                 return E1000_SUCCESS;
    2065                 :            :                 }
    2066                 :            :         }
    2067                 :            : 
    2068                 :          0 : out:
    2069                 :          0 :         DEBUGOUT1("Failed to write receive address at index %d\n", index);
    2070                 :          0 :         return -E1000_ERR_CONFIG;
    2071                 :            : }
    2072                 :            : 
    2073                 :            : /**
    2074                 :            :  *  e1000_update_mc_addr_list_pch2lan - Update Multicast addresses
    2075                 :            :  *  @hw: pointer to the HW structure
    2076                 :            :  *  @mc_addr_list: array of multicast addresses to program
    2077                 :            :  *  @mc_addr_count: number of multicast addresses to program
    2078                 :            :  *
    2079                 :            :  *  Updates entire Multicast Table Array of the PCH2 MAC and PHY.
    2080                 :            :  *  The caller must have a packed mc_addr_list of multicast addresses.
    2081                 :            :  **/
    2082                 :          0 : STATIC void e1000_update_mc_addr_list_pch2lan(struct e1000_hw *hw,
    2083                 :            :                                               u8 *mc_addr_list,
    2084                 :            :                                               u32 mc_addr_count)
    2085                 :            : {
    2086                 :          0 :         u16 phy_reg = 0;
    2087                 :            :         int i;
    2088                 :            :         s32 ret_val;
    2089                 :            : 
    2090                 :          0 :         DEBUGFUNC("e1000_update_mc_addr_list_pch2lan");
    2091                 :            : 
    2092                 :          0 :         e1000_update_mc_addr_list_generic(hw, mc_addr_list, mc_addr_count);
    2093                 :            : 
    2094                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2095         [ #  # ]:          0 :         if (ret_val)
    2096                 :          0 :                 return;
    2097                 :            : 
    2098                 :          0 :         ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    2099         [ #  # ]:          0 :         if (ret_val)
    2100                 :          0 :                 goto release;
    2101                 :            : 
    2102         [ #  # ]:          0 :         for (i = 0; i < hw->mac.mta_reg_count; i++) {
    2103                 :          0 :                 hw->phy.ops.write_reg_page(hw, BM_MTA(i),
    2104                 :          0 :                                            (u16)(hw->mac.mta_shadow[i] &
    2105                 :            :                                                  0xFFFF));
    2106                 :          0 :                 hw->phy.ops.write_reg_page(hw, (BM_MTA(i) + 1),
    2107                 :          0 :                                            (u16)((hw->mac.mta_shadow[i] >> 16) &
    2108                 :            :                                                  0xFFFF));
    2109                 :            :         }
    2110                 :            : 
    2111                 :          0 :         e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    2112                 :            : 
    2113                 :          0 : release:
    2114                 :          0 :         hw->phy.ops.release(hw);
    2115                 :            : }
    2116                 :            : 
    2117                 :            : /**
    2118                 :            :  *  e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
    2119                 :            :  *  @hw: pointer to the HW structure
    2120                 :            :  *
    2121                 :            :  *  Checks if firmware is blocking the reset of the PHY.
    2122                 :            :  *  This is a function pointer entry point only called by
    2123                 :            :  *  reset routines.
    2124                 :            :  **/
    2125                 :          0 : STATIC s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
    2126                 :            : {
    2127                 :            :         u32 fwsm;
    2128                 :            :         bool blocked = false;
    2129                 :            :         int i = 0;
    2130                 :            : 
    2131                 :          0 :         DEBUGFUNC("e1000_check_reset_block_ich8lan");
    2132                 :            : 
    2133                 :            :         do {
    2134                 :          0 :                 fwsm = E1000_READ_REG(hw, E1000_FWSM);
    2135         [ #  # ]:          0 :                 if (!(fwsm & E1000_ICH_FWSM_RSPCIPHY)) {
    2136                 :            :                         blocked = true;
    2137                 :          0 :                         msec_delay(10);
    2138                 :            :                         continue;
    2139                 :            :                 }
    2140                 :            :                 blocked = false;
    2141         [ #  # ]:          0 :         } while (blocked && (i++ < 30));
    2142         [ #  # ]:          0 :         return blocked ? E1000_BLK_PHY_RESET : E1000_SUCCESS;
    2143                 :            : }
    2144                 :            : 
    2145                 :            : /**
    2146                 :            :  *  e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
    2147                 :            :  *  @hw: pointer to the HW structure
    2148                 :            :  *
    2149                 :            :  *  Assumes semaphore already acquired.
    2150                 :            :  *
    2151                 :            :  **/
    2152                 :          0 : STATIC s32 e1000_write_smbus_addr(struct e1000_hw *hw)
    2153                 :            : {
    2154                 :            :         u16 phy_data;
    2155                 :          0 :         u32 strap = E1000_READ_REG(hw, E1000_STRAP);
    2156                 :          0 :         u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
    2157                 :            :                 E1000_STRAP_SMT_FREQ_SHIFT;
    2158                 :            :         s32 ret_val;
    2159                 :            : 
    2160                 :            :         strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
    2161                 :            : 
    2162                 :          0 :         ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
    2163         [ #  # ]:          0 :         if (ret_val)
    2164                 :            :                 return ret_val;
    2165                 :            : 
    2166                 :          0 :         phy_data &= ~HV_SMB_ADDR_MASK;
    2167                 :          0 :         phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
    2168                 :          0 :         phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
    2169                 :            : 
    2170         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_i217) {
    2171                 :            :                 /* Restore SMBus frequency */
    2172         [ #  # ]:          0 :                 if (freq--) {
    2173                 :          0 :                         phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
    2174                 :          0 :                         phy_data |= (freq & (1 << 0)) <<
    2175                 :            :                                 HV_SMB_ADDR_FREQ_LOW_SHIFT;
    2176                 :          0 :                         phy_data |= (freq & (1 << 1)) <<
    2177                 :            :                                 (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
    2178                 :            :                 } else {
    2179                 :          0 :                         DEBUGOUT("Unsupported SMB frequency in PHY\n");
    2180                 :            :                 }
    2181                 :            :         }
    2182                 :            : 
    2183                 :          0 :         return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
    2184                 :            : }
    2185                 :            : 
    2186                 :            : /**
    2187                 :            :  *  e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
    2188                 :            :  *  @hw:   pointer to the HW structure
    2189                 :            :  *
    2190                 :            :  *  SW should configure the LCD from the NVM extended configuration region
    2191                 :            :  *  as a workaround for certain parts.
    2192                 :            :  **/
    2193                 :          0 : STATIC s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
    2194                 :            : {
    2195                 :            :         struct e1000_phy_info *phy = &hw->phy;
    2196                 :            :         u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
    2197                 :            :         s32 ret_val = E1000_SUCCESS;
    2198                 :            :         u16 word_addr, reg_data, reg_addr, phy_page = 0;
    2199                 :            : 
    2200                 :          0 :         DEBUGFUNC("e1000_sw_lcd_config_ich8lan");
    2201                 :            : 
    2202                 :            :         /* Initialize the PHY from the NVM on ICH platforms.  This
    2203                 :            :          * is needed due to an issue where the NVM configuration is
    2204                 :            :          * not properly autoloaded after power transitions.
    2205                 :            :          * Therefore, after each PHY reset, we will load the
    2206                 :            :          * configuration data out of the NVM manually.
    2207                 :            :          */
    2208      [ #  #  # ]:          0 :         switch (hw->mac.type) {
    2209                 :          0 :         case e1000_ich8lan:
    2210         [ #  # ]:          0 :                 if (phy->type != e1000_phy_igp_3)
    2211                 :            :                         return ret_val;
    2212                 :            : 
    2213         [ #  # ]:          0 :                 if ((hw->device_id == E1000_DEV_ID_ICH8_IGP_AMT) ||
    2214                 :            :                     (hw->device_id == E1000_DEV_ID_ICH8_IGP_C)) {
    2215                 :            :                         sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
    2216                 :            :                         break;
    2217                 :            :                 }
    2218                 :            :                 /* Fall-thru */
    2219                 :            :         case e1000_pchlan:
    2220                 :            :         case e1000_pch2lan:
    2221                 :            :         case e1000_pch_lpt:
    2222                 :            :         case e1000_pch_spt:
    2223                 :            :         case e1000_pch_cnp:
    2224                 :            :         case e1000_pch_adp:
    2225                 :            :                 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
    2226                 :          0 :                 break;
    2227                 :            :         default:
    2228                 :            :                 return ret_val;
    2229                 :            :         }
    2230                 :            : 
    2231                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2232         [ #  # ]:          0 :         if (ret_val)
    2233                 :            :                 return ret_val;
    2234                 :            : 
    2235                 :          0 :         data = E1000_READ_REG(hw, E1000_FEXTNVM);
    2236         [ #  # ]:          0 :         if (!(data & sw_cfg_mask))
    2237                 :          0 :                 goto release;
    2238                 :            : 
    2239                 :            :         /* Make sure HW does not configure LCD from PHY
    2240                 :            :          * extended configuration before SW configuration
    2241                 :            :          */
    2242                 :          0 :         data = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    2243         [ #  # ]:          0 :         if ((hw->mac.type < e1000_pch2lan) &&
    2244         [ #  # ]:          0 :             (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
    2245                 :          0 :                         goto release;
    2246                 :            : 
    2247                 :          0 :         cnf_size = E1000_READ_REG(hw, E1000_EXTCNF_SIZE);
    2248                 :            :         cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
    2249                 :          0 :         cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
    2250         [ #  # ]:          0 :         if (!cnf_size)
    2251                 :          0 :                 goto release;
    2252                 :            : 
    2253                 :            :         cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
    2254                 :          0 :         cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
    2255                 :            : 
    2256         [ #  # ]:          0 :         if (((hw->mac.type == e1000_pchlan) &&
    2257   [ #  #  #  # ]:          0 :              !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
    2258                 :            :             (hw->mac.type > e1000_pchlan)) {
    2259                 :            :                 /* HW configures the SMBus address and LEDs when the
    2260                 :            :                  * OEM and LCD Write Enable bits are set in the NVM.
    2261                 :            :                  * When both NVM bits are cleared, SW will configure
    2262                 :            :                  * them instead.
    2263                 :            :                  */
    2264                 :          0 :                 ret_val = e1000_write_smbus_addr(hw);
    2265         [ #  # ]:          0 :                 if (ret_val)
    2266                 :          0 :                         goto release;
    2267                 :            : 
    2268                 :          0 :                 data = E1000_READ_REG(hw, E1000_LEDCTL);
    2269                 :          0 :                 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
    2270                 :            :                                                         (u16)data);
    2271         [ #  # ]:          0 :                 if (ret_val)
    2272                 :          0 :                         goto release;
    2273                 :            :         }
    2274                 :            : 
    2275                 :            :         /* Configure LCD from extended configuration region. */
    2276                 :            : 
    2277                 :            :         /* cnf_base_addr is in DWORD */
    2278                 :          0 :         word_addr = (u16)(cnf_base_addr << 1);
    2279                 :            : 
    2280         [ #  # ]:          0 :         for (i = 0; i < cnf_size; i++) {
    2281                 :          0 :                 ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2), 1,
    2282                 :            :                                            &reg_data);
    2283         [ #  # ]:          0 :                 if (ret_val)
    2284                 :          0 :                         goto release;
    2285                 :            : 
    2286                 :          0 :                 ret_val = hw->nvm.ops.read(hw, (word_addr + i * 2 + 1),
    2287                 :            :                                            1, &reg_addr);
    2288         [ #  # ]:          0 :                 if (ret_val)
    2289                 :          0 :                         goto release;
    2290                 :            : 
    2291                 :            :                 /* Save off the PHY page for future writes. */
    2292         [ #  # ]:          0 :                 if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
    2293                 :          0 :                         phy_page = reg_data;
    2294                 :          0 :                         continue;
    2295                 :            :                 }
    2296                 :            : 
    2297                 :          0 :                 reg_addr &= PHY_REG_MASK;
    2298                 :          0 :                 reg_addr |= phy_page;
    2299                 :            : 
    2300                 :          0 :                 ret_val = phy->ops.write_reg_locked(hw, (u32)reg_addr,
    2301                 :            :                                                     reg_data);
    2302         [ #  # ]:          0 :                 if (ret_val)
    2303                 :          0 :                         goto release;
    2304                 :            :         }
    2305                 :            : 
    2306                 :          0 : release:
    2307                 :          0 :         hw->phy.ops.release(hw);
    2308                 :          0 :         return ret_val;
    2309                 :            : }
    2310                 :            : 
    2311                 :            : /**
    2312                 :            :  *  e1000_k1_gig_workaround_hv - K1 Si workaround
    2313                 :            :  *  @hw:   pointer to the HW structure
    2314                 :            :  *  @link: link up bool flag
    2315                 :            :  *
    2316                 :            :  *  If K1 is enabled for 1Gbps, the MAC might stall when transitioning
    2317                 :            :  *  from a lower speed.  This workaround disables K1 whenever link is at 1Gig
    2318                 :            :  *  If link is down, the function will restore the default K1 setting located
    2319                 :            :  *  in the NVM.
    2320                 :            :  **/
    2321                 :          0 : STATIC s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
    2322                 :            : {
    2323                 :            :         s32 ret_val = E1000_SUCCESS;
    2324                 :          0 :         u16 status_reg = 0;
    2325                 :          0 :         bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
    2326                 :            : 
    2327                 :          0 :         DEBUGFUNC("e1000_k1_gig_workaround_hv");
    2328                 :            : 
    2329         [ #  # ]:          0 :         if (hw->mac.type != e1000_pchlan)
    2330                 :            :                 return E1000_SUCCESS;
    2331                 :            : 
    2332                 :            :         /* Wrap the whole flow with the sw flag */
    2333                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2334         [ #  # ]:          0 :         if (ret_val)
    2335                 :            :                 return ret_val;
    2336                 :            : 
    2337                 :            :         /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
    2338         [ #  # ]:          0 :         if (link) {
    2339         [ #  # ]:          0 :                 if (hw->phy.type == e1000_phy_82578) {
    2340                 :          0 :                         ret_val = hw->phy.ops.read_reg_locked(hw, BM_CS_STATUS,
    2341                 :            :                                                               &status_reg);
    2342         [ #  # ]:          0 :                         if (ret_val)
    2343                 :          0 :                                 goto release;
    2344                 :            : 
    2345                 :          0 :                         status_reg &= (BM_CS_STATUS_LINK_UP |
    2346                 :            :                                        BM_CS_STATUS_RESOLVED |
    2347                 :            :                                        BM_CS_STATUS_SPEED_MASK);
    2348                 :            : 
    2349         [ #  # ]:          0 :                         if (status_reg == (BM_CS_STATUS_LINK_UP |
    2350                 :            :                                            BM_CS_STATUS_RESOLVED |
    2351                 :            :                                            BM_CS_STATUS_SPEED_1000))
    2352                 :            :                                 k1_enable = false;
    2353                 :            :                 }
    2354                 :            : 
    2355         [ #  # ]:          0 :                 if (hw->phy.type == e1000_phy_82577) {
    2356                 :          0 :                         ret_val = hw->phy.ops.read_reg_locked(hw, HV_M_STATUS,
    2357                 :            :                                                               &status_reg);
    2358         [ #  # ]:          0 :                         if (ret_val)
    2359                 :          0 :                                 goto release;
    2360                 :            : 
    2361                 :          0 :                         status_reg &= (HV_M_STATUS_LINK_UP |
    2362                 :            :                                        HV_M_STATUS_AUTONEG_COMPLETE |
    2363                 :            :                                        HV_M_STATUS_SPEED_MASK);
    2364                 :            : 
    2365         [ #  # ]:          0 :                         if (status_reg == (HV_M_STATUS_LINK_UP |
    2366                 :            :                                            HV_M_STATUS_AUTONEG_COMPLETE |
    2367                 :            :                                            HV_M_STATUS_SPEED_1000))
    2368                 :            :                                 k1_enable = false;
    2369                 :            :                 }
    2370                 :            : 
    2371                 :            :                 /* Link stall fix for link up */
    2372                 :          0 :                 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
    2373                 :            :                                                        0x0100);
    2374         [ #  # ]:          0 :                 if (ret_val)
    2375                 :          0 :                         goto release;
    2376                 :            : 
    2377                 :            :         } else {
    2378                 :            :                 /* Link stall fix for link down */
    2379                 :          0 :                 ret_val = hw->phy.ops.write_reg_locked(hw, PHY_REG(770, 19),
    2380                 :            :                                                        0x4100);
    2381         [ #  # ]:          0 :                 if (ret_val)
    2382                 :          0 :                         goto release;
    2383                 :            :         }
    2384                 :            : 
    2385                 :          0 :         ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
    2386                 :            : 
    2387                 :          0 : release:
    2388                 :          0 :         hw->phy.ops.release(hw);
    2389                 :            : 
    2390                 :          0 :         return ret_val;
    2391                 :            : }
    2392                 :            : 
    2393                 :            : /**
    2394                 :            :  *  e1000_configure_k1_ich8lan - Configure K1 power state
    2395                 :            :  *  @hw: pointer to the HW structure
    2396                 :            :  *  @k1_enable: K1 state to configure
    2397                 :            :  *
    2398                 :            :  *  Configure the K1 power state based on the provided parameter.
    2399                 :            :  *  Assumes semaphore already acquired.
    2400                 :            :  *
    2401                 :            :  *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
    2402                 :            :  **/
    2403                 :          0 : s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
    2404                 :            : {
    2405                 :            :         s32 ret_val;
    2406                 :            :         u32 ctrl_reg = 0;
    2407                 :            :         u32 ctrl_ext = 0;
    2408                 :            :         u32 reg = 0;
    2409                 :          0 :         u16 kmrn_reg = 0;
    2410                 :            : 
    2411                 :          0 :         DEBUGFUNC("e1000_configure_k1_ich8lan");
    2412                 :            : 
    2413                 :          0 :         ret_val = e1000_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
    2414                 :            :                                              &kmrn_reg);
    2415         [ #  # ]:          0 :         if (ret_val)
    2416                 :            :                 return ret_val;
    2417                 :            : 
    2418         [ #  # ]:          0 :         if (k1_enable)
    2419                 :          0 :                 kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
    2420                 :            :         else
    2421                 :          0 :                 kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
    2422                 :            : 
    2423                 :          0 :         ret_val = e1000_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
    2424                 :            :                                               kmrn_reg);
    2425         [ #  # ]:          0 :         if (ret_val)
    2426                 :            :                 return ret_val;
    2427                 :            : 
    2428                 :          0 :         usec_delay(20);
    2429                 :          0 :         ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
    2430                 :          0 :         ctrl_reg = E1000_READ_REG(hw, E1000_CTRL);
    2431                 :            : 
    2432                 :          0 :         reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
    2433                 :          0 :         reg |= E1000_CTRL_FRCSPD;
    2434                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, reg);
    2435                 :            : 
    2436                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
    2437                 :          0 :         E1000_WRITE_FLUSH(hw);
    2438                 :          0 :         usec_delay(20);
    2439                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, ctrl_reg);
    2440                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
    2441                 :          0 :         E1000_WRITE_FLUSH(hw);
    2442                 :          0 :         usec_delay(20);
    2443                 :            : 
    2444                 :          0 :         return E1000_SUCCESS;
    2445                 :            : }
    2446                 :            : 
    2447                 :            : /**
    2448                 :            :  *  e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
    2449                 :            :  *  @hw:       pointer to the HW structure
    2450                 :            :  *  @d0_state: boolean if entering d0 or d3 device state
    2451                 :            :  *
    2452                 :            :  *  SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
    2453                 :            :  *  collectively called OEM bits.  The OEM Write Enable bit and SW Config bit
    2454                 :            :  *  in NVM determines whether HW should configure LPLU and Gbe Disable.
    2455                 :            :  **/
    2456                 :          0 : STATIC s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
    2457                 :            : {
    2458                 :            :         s32 ret_val = 0;
    2459                 :            :         u32 mac_reg;
    2460                 :            :         u16 oem_reg;
    2461                 :            : 
    2462                 :          0 :         DEBUGFUNC("e1000_oem_bits_config_ich8lan");
    2463                 :            : 
    2464         [ #  # ]:          0 :         if (hw->mac.type < e1000_pchlan)
    2465                 :            :                 return ret_val;
    2466                 :            : 
    2467                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2468         [ #  # ]:          0 :         if (ret_val)
    2469                 :            :                 return ret_val;
    2470                 :            : 
    2471         [ #  # ]:          0 :         if (hw->mac.type == e1000_pchlan) {
    2472                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    2473         [ #  # ]:          0 :                 if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
    2474                 :          0 :                         goto release;
    2475                 :            :         }
    2476                 :            : 
    2477                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM);
    2478         [ #  # ]:          0 :         if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
    2479                 :          0 :                 goto release;
    2480                 :            : 
    2481                 :          0 :         mac_reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
    2482                 :            : 
    2483                 :          0 :         ret_val = hw->phy.ops.read_reg_locked(hw, HV_OEM_BITS, &oem_reg);
    2484         [ #  # ]:          0 :         if (ret_val)
    2485                 :          0 :                 goto release;
    2486                 :            : 
    2487                 :          0 :         oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
    2488                 :            : 
    2489         [ #  # ]:          0 :         if (d0_state) {
    2490         [ #  # ]:          0 :                 if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
    2491                 :          0 :                         oem_reg |= HV_OEM_BITS_GBE_DIS;
    2492                 :            : 
    2493         [ #  # ]:          0 :                 if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
    2494                 :          0 :                         oem_reg |= HV_OEM_BITS_LPLU;
    2495                 :            :         } else {
    2496         [ #  # ]:          0 :                 if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
    2497                 :            :                     E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
    2498                 :          0 :                         oem_reg |= HV_OEM_BITS_GBE_DIS;
    2499                 :            : 
    2500         [ #  # ]:          0 :                 if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
    2501                 :            :                     E1000_PHY_CTRL_NOND0A_LPLU))
    2502                 :          0 :                         oem_reg |= HV_OEM_BITS_LPLU;
    2503                 :            :         }
    2504                 :            : 
    2505                 :            :         /* Set Restart auto-neg to activate the bits */
    2506   [ #  #  #  #  :          0 :         if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
                   #  # ]
    2507                 :          0 :             !hw->phy.ops.check_reset_block(hw))
    2508                 :          0 :                 oem_reg |= HV_OEM_BITS_RESTART_AN;
    2509                 :            : 
    2510                 :          0 :         ret_val = hw->phy.ops.write_reg_locked(hw, HV_OEM_BITS, oem_reg);
    2511                 :            : 
    2512                 :          0 : release:
    2513                 :          0 :         hw->phy.ops.release(hw);
    2514                 :            : 
    2515                 :          0 :         return ret_val;
    2516                 :            : }
    2517                 :            : 
    2518                 :            : 
    2519                 :            : /**
    2520                 :            :  *  e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
    2521                 :            :  *  @hw:   pointer to the HW structure
    2522                 :            :  **/
    2523                 :          0 : STATIC s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
    2524                 :            : {
    2525                 :            :         s32 ret_val;
    2526                 :            :         u16 data;
    2527                 :            : 
    2528                 :          0 :         DEBUGFUNC("e1000_set_mdio_slow_mode_hv");
    2529                 :            : 
    2530                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, HV_KMRN_MODE_CTRL, &data);
    2531         [ #  # ]:          0 :         if (ret_val)
    2532                 :            :                 return ret_val;
    2533                 :            : 
    2534                 :          0 :         data |= HV_KMRN_MDIO_SLOW;
    2535                 :            : 
    2536                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, HV_KMRN_MODE_CTRL, data);
    2537                 :            : 
    2538                 :          0 :         return ret_val;
    2539                 :            : }
    2540                 :            : 
    2541                 :            : /**
    2542                 :            :  *  e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
    2543                 :            :  *  done after every PHY reset.
    2544                 :            :  *  @hw: pointer to the HW structure
    2545                 :            :  **/
    2546                 :          0 : STATIC s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
    2547                 :            : {
    2548                 :            :         s32 ret_val = E1000_SUCCESS;
    2549                 :            :         u16 phy_data;
    2550                 :            : 
    2551                 :          0 :         DEBUGFUNC("e1000_hv_phy_workarounds_ich8lan");
    2552                 :            : 
    2553         [ #  # ]:          0 :         if (hw->mac.type != e1000_pchlan)
    2554                 :            :                 return E1000_SUCCESS;
    2555                 :            : 
    2556                 :            :         /* Set MDIO slow mode before any other MDIO access */
    2557         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_82577) {
    2558                 :          0 :                 ret_val = e1000_set_mdio_slow_mode_hv(hw);
    2559         [ #  # ]:          0 :                 if (ret_val)
    2560                 :            :                         return ret_val;
    2561                 :            :         }
    2562                 :            : 
    2563         [ #  # ]:          0 :         if (((hw->phy.type == e1000_phy_82577) &&
    2564   [ #  #  #  # ]:          0 :              ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
    2565         [ #  # ]:          0 :             ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
    2566                 :            :                 /* Disable generation of early preamble */
    2567                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 25), 0x4431);
    2568         [ #  # ]:          0 :                 if (ret_val)
    2569                 :            :                         return ret_val;
    2570                 :            : 
    2571                 :            :                 /* Preamble tuning for SSC */
    2572                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, HV_KMRN_FIFO_CTRLSTA,
    2573                 :            :                                                 0xA204);
    2574         [ #  # ]:          0 :                 if (ret_val)
    2575                 :            :                         return ret_val;
    2576                 :            :         }
    2577                 :            : 
    2578         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_82578) {
    2579                 :            :                 /* Return registers to default by doing a soft reset then
    2580                 :            :                  * writing 0x3140 to the control register.
    2581                 :            :                  */
    2582         [ #  # ]:          0 :                 if (hw->phy.revision < 2) {
    2583                 :          0 :                         e1000_phy_sw_reset_generic(hw);
    2584                 :          0 :                         ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL,
    2585                 :            :                                                         0x3140);
    2586                 :            :                 }
    2587                 :            :         }
    2588                 :            : 
    2589                 :            :         /* Select page 0 */
    2590                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2591         [ #  # ]:          0 :         if (ret_val)
    2592                 :            :                 return ret_val;
    2593                 :            : 
    2594                 :          0 :         hw->phy.addr = 1;
    2595                 :          0 :         ret_val = e1000_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
    2596                 :          0 :         hw->phy.ops.release(hw);
    2597         [ #  # ]:          0 :         if (ret_val)
    2598                 :            :                 return ret_val;
    2599                 :            : 
    2600                 :            :         /* Configure the K1 Si workaround during phy reset assuming there is
    2601                 :            :          * link so that it disables K1 if link is in 1Gbps.
    2602                 :            :          */
    2603                 :          0 :         ret_val = e1000_k1_gig_workaround_hv(hw, true);
    2604         [ #  # ]:          0 :         if (ret_val)
    2605                 :            :                 return ret_val;
    2606                 :            : 
    2607                 :            :         /* Workaround for link disconnects on a busy hub in half duplex */
    2608                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2609         [ #  # ]:          0 :         if (ret_val)
    2610                 :            :                 return ret_val;
    2611                 :          0 :         ret_val = hw->phy.ops.read_reg_locked(hw, BM_PORT_GEN_CFG, &phy_data);
    2612         [ #  # ]:          0 :         if (ret_val)
    2613                 :          0 :                 goto release;
    2614                 :          0 :         ret_val = hw->phy.ops.write_reg_locked(hw, BM_PORT_GEN_CFG,
    2615                 :          0 :                                                phy_data & 0x00FF);
    2616         [ #  # ]:          0 :         if (ret_val)
    2617                 :          0 :                 goto release;
    2618                 :            : 
    2619                 :            :         /* set MSE higher to enable link to stay up when noise is high */
    2620                 :          0 :         ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
    2621                 :          0 : release:
    2622                 :          0 :         hw->phy.ops.release(hw);
    2623                 :            : 
    2624                 :          0 :         return ret_val;
    2625                 :            : }
    2626                 :            : 
    2627                 :            : /**
    2628                 :            :  *  e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
    2629                 :            :  *  @hw:   pointer to the HW structure
    2630                 :            :  **/
    2631                 :          0 : void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
    2632                 :            : {
    2633                 :            :         u32 mac_reg;
    2634                 :          0 :         u16 i, phy_reg = 0;
    2635                 :            :         s32 ret_val;
    2636                 :            : 
    2637                 :          0 :         DEBUGFUNC("e1000_copy_rx_addrs_to_phy_ich8lan");
    2638                 :            : 
    2639                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2640         [ #  # ]:          0 :         if (ret_val)
    2641                 :          0 :                 return;
    2642                 :          0 :         ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    2643         [ #  # ]:          0 :         if (ret_val)
    2644                 :          0 :                 goto release;
    2645                 :            : 
    2646                 :            :         /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
    2647         [ #  # ]:          0 :         for (i = 0; i < (hw->mac.rar_entry_count); i++) {
    2648         [ #  # ]:          0 :                 mac_reg = E1000_READ_REG(hw, E1000_RAL(i));
    2649                 :          0 :                 hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
    2650                 :            :                                            (u16)(mac_reg & 0xFFFF));
    2651                 :          0 :                 hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
    2652                 :          0 :                                            (u16)((mac_reg >> 16) & 0xFFFF));
    2653                 :            : 
    2654         [ #  # ]:          0 :                 mac_reg = E1000_READ_REG(hw, E1000_RAH(i));
    2655                 :          0 :                 hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
    2656                 :            :                                            (u16)(mac_reg & 0xFFFF));
    2657                 :          0 :                 hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
    2658                 :          0 :                                            (u16)((mac_reg & E1000_RAH_AV)
    2659                 :          0 :                                                  >> 16));
    2660                 :            :         }
    2661                 :            : 
    2662                 :          0 :         e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
    2663                 :            : 
    2664                 :          0 : release:
    2665                 :          0 :         hw->phy.ops.release(hw);
    2666                 :            : }
    2667                 :            : 
    2668                 :          0 : STATIC u32 e1000_calc_rx_da_crc(u8 mac[])
    2669                 :            : {
    2670                 :            :         u32 poly = 0xEDB88320;  /* Polynomial for 802.3 CRC calculation */
    2671                 :            :         u32 i, j, mask, crc;
    2672                 :            : 
    2673                 :          0 :         DEBUGFUNC("e1000_calc_rx_da_crc");
    2674                 :            : 
    2675                 :            :         crc = 0xffffffff;
    2676         [ #  # ]:          0 :         for (i = 0; i < 6; i++) {
    2677                 :          0 :                 crc = crc ^ mac[i];
    2678         [ #  # ]:          0 :                 for (j = 8; j > 0; j--) {
    2679                 :          0 :                         mask = (crc & 1) * (-1);
    2680                 :          0 :                         crc = (crc >> 1) ^ (poly & mask);
    2681                 :            :                 }
    2682                 :            :         }
    2683                 :          0 :         return ~crc;
    2684                 :            : }
    2685                 :            : 
    2686                 :            : /**
    2687                 :            :  *  e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
    2688                 :            :  *  with 82579 PHY
    2689                 :            :  *  @hw: pointer to the HW structure
    2690                 :            :  *  @enable: flag to enable/disable workaround when enabling/disabling jumbos
    2691                 :            :  **/
    2692                 :          0 : s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
    2693                 :            : {
    2694                 :            :         s32 ret_val = E1000_SUCCESS;
    2695                 :            :         u16 phy_reg, data;
    2696                 :            :         u32 mac_reg;
    2697                 :            :         u16 i;
    2698                 :            : 
    2699                 :          0 :         DEBUGFUNC("e1000_lv_jumbo_workaround_ich8lan");
    2700                 :            : 
    2701         [ #  # ]:          0 :         if (hw->mac.type < e1000_pch2lan)
    2702                 :            :                 return E1000_SUCCESS;
    2703                 :            : 
    2704                 :            :         /* disable Rx path while enabling/disabling workaround */
    2705                 :          0 :         hw->phy.ops.read_reg(hw, PHY_REG(769, 20), &phy_reg);
    2706                 :          0 :         ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 20),
    2707                 :            :                                         phy_reg | (1 << 14));
    2708         [ #  # ]:          0 :         if (ret_val)
    2709                 :            :                 return ret_val;
    2710                 :            : 
    2711         [ #  # ]:          0 :         if (enable) {
    2712                 :            :                 /* Write Rx addresses (rar_entry_count for RAL/H, and
    2713                 :            :                  * SHRAL/H) and initial CRC values to the MAC
    2714                 :            :                  */
    2715         [ #  # ]:          0 :                 for (i = 0; i < hw->mac.rar_entry_count; i++) {
    2716                 :          0 :                         u8 mac_addr[ETH_ADDR_LEN] = {0};
    2717                 :            :                         u32 addr_high, addr_low;
    2718                 :            : 
    2719         [ #  # ]:          0 :                         addr_high = E1000_READ_REG(hw, E1000_RAH(i));
    2720         [ #  # ]:          0 :                         if (!(addr_high & E1000_RAH_AV))
    2721                 :          0 :                                 continue;
    2722         [ #  # ]:          0 :                         addr_low = E1000_READ_REG(hw, E1000_RAL(i));
    2723                 :          0 :                         mac_addr[0] = (addr_low & 0xFF);
    2724                 :          0 :                         mac_addr[1] = ((addr_low >> 8) & 0xFF);
    2725                 :          0 :                         mac_addr[2] = ((addr_low >> 16) & 0xFF);
    2726                 :          0 :                         mac_addr[3] = ((addr_low >> 24) & 0xFF);
    2727                 :          0 :                         mac_addr[4] = (addr_high & 0xFF);
    2728                 :          0 :                         mac_addr[5] = ((addr_high >> 8) & 0xFF);
    2729                 :            : 
    2730                 :          0 :                         E1000_WRITE_REG(hw, E1000_PCH_RAICC(i),
    2731                 :            :                                         e1000_calc_rx_da_crc(mac_addr));
    2732                 :            :                 }
    2733                 :            : 
    2734                 :            :                 /* Write Rx addresses to the PHY */
    2735                 :          0 :                 e1000_copy_rx_addrs_to_phy_ich8lan(hw);
    2736                 :            : 
    2737                 :            :                 /* Enable jumbo frame workaround in the MAC */
    2738                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_FFLT_DBG);
    2739                 :          0 :                 mac_reg &= ~(1 << 14);
    2740                 :          0 :                 mac_reg |= (7 << 15);
    2741                 :          0 :                 E1000_WRITE_REG(hw, E1000_FFLT_DBG, mac_reg);
    2742                 :            : 
    2743                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_RCTL);
    2744                 :          0 :                 mac_reg |= E1000_RCTL_SECRC;
    2745                 :          0 :                 E1000_WRITE_REG(hw, E1000_RCTL, mac_reg);
    2746                 :            : 
    2747                 :          0 :                 ret_val = e1000_read_kmrn_reg_generic(hw,
    2748                 :            :                                                 E1000_KMRNCTRLSTA_CTRL_OFFSET,
    2749                 :            :                                                 &data);
    2750         [ #  # ]:          0 :                 if (ret_val)
    2751                 :            :                         return ret_val;
    2752                 :          0 :                 ret_val = e1000_write_kmrn_reg_generic(hw,
    2753                 :            :                                                 E1000_KMRNCTRLSTA_CTRL_OFFSET,
    2754                 :            :                                                 data | (1 << 0));
    2755         [ #  # ]:          0 :                 if (ret_val)
    2756                 :            :                         return ret_val;
    2757                 :          0 :                 ret_val = e1000_read_kmrn_reg_generic(hw,
    2758                 :            :                                                 E1000_KMRNCTRLSTA_HD_CTRL,
    2759                 :            :                                                 &data);
    2760         [ #  # ]:          0 :                 if (ret_val)
    2761                 :            :                         return ret_val;
    2762                 :          0 :                 data &= ~(0xF << 8);
    2763                 :          0 :                 data |= (0xB << 8);
    2764                 :          0 :                 ret_val = e1000_write_kmrn_reg_generic(hw,
    2765                 :            :                                                 E1000_KMRNCTRLSTA_HD_CTRL,
    2766                 :            :                                                 data);
    2767         [ #  # ]:          0 :                 if (ret_val)
    2768                 :            :                         return ret_val;
    2769                 :            : 
    2770                 :            :                 /* Enable jumbo frame workaround in the PHY */
    2771                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(769, 23), &data);
    2772                 :          0 :                 data &= ~(0x7F << 5);
    2773                 :          0 :                 data |= (0x37 << 5);
    2774                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 23), data);
    2775         [ #  # ]:          0 :                 if (ret_val)
    2776                 :            :                         return ret_val;
    2777                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(769, 16), &data);
    2778                 :          0 :                 data &= ~(1 << 13);
    2779                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 16), data);
    2780         [ #  # ]:          0 :                 if (ret_val)
    2781                 :            :                         return ret_val;
    2782                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(776, 20), &data);
    2783                 :          0 :                 data &= ~(0x3FF << 2);
    2784                 :          0 :                 data |= (E1000_TX_PTR_GAP << 2);
    2785                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(776, 20), data);
    2786         [ #  # ]:          0 :                 if (ret_val)
    2787                 :            :                         return ret_val;
    2788                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(776, 23), 0xF100);
    2789         [ #  # ]:          0 :                 if (ret_val)
    2790                 :            :                         return ret_val;
    2791                 :          0 :                 hw->phy.ops.read_reg(hw, HV_PM_CTRL, &data);
    2792                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, HV_PM_CTRL, data |
    2793                 :            :                                                 (1 << 10));
    2794         [ #  # ]:          0 :                 if (ret_val)
    2795                 :            :                         return ret_val;
    2796                 :            :         } else {
    2797                 :            :                 /* Write MAC register values back to h/w defaults */
    2798                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_FFLT_DBG);
    2799                 :          0 :                 mac_reg &= ~(0xF << 14);
    2800                 :          0 :                 E1000_WRITE_REG(hw, E1000_FFLT_DBG, mac_reg);
    2801                 :            : 
    2802                 :          0 :                 mac_reg = E1000_READ_REG(hw, E1000_RCTL);
    2803                 :          0 :                 mac_reg &= ~E1000_RCTL_SECRC;
    2804                 :          0 :                 E1000_WRITE_REG(hw, E1000_RCTL, mac_reg);
    2805                 :            : 
    2806                 :          0 :                 ret_val = e1000_read_kmrn_reg_generic(hw,
    2807                 :            :                                                 E1000_KMRNCTRLSTA_CTRL_OFFSET,
    2808                 :            :                                                 &data);
    2809         [ #  # ]:          0 :                 if (ret_val)
    2810                 :            :                         return ret_val;
    2811                 :          0 :                 ret_val = e1000_write_kmrn_reg_generic(hw,
    2812                 :            :                                                 E1000_KMRNCTRLSTA_CTRL_OFFSET,
    2813                 :          0 :                                                 data & ~(1 << 0));
    2814         [ #  # ]:          0 :                 if (ret_val)
    2815                 :            :                         return ret_val;
    2816                 :          0 :                 ret_val = e1000_read_kmrn_reg_generic(hw,
    2817                 :            :                                                 E1000_KMRNCTRLSTA_HD_CTRL,
    2818                 :            :                                                 &data);
    2819         [ #  # ]:          0 :                 if (ret_val)
    2820                 :            :                         return ret_val;
    2821                 :          0 :                 data &= ~(0xF << 8);
    2822                 :          0 :                 data |= (0xB << 8);
    2823                 :          0 :                 ret_val = e1000_write_kmrn_reg_generic(hw,
    2824                 :            :                                                 E1000_KMRNCTRLSTA_HD_CTRL,
    2825                 :            :                                                 data);
    2826         [ #  # ]:          0 :                 if (ret_val)
    2827                 :            :                         return ret_val;
    2828                 :            : 
    2829                 :            :                 /* Write PHY register values back to h/w defaults */
    2830                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(769, 23), &data);
    2831                 :          0 :                 data &= ~(0x7F << 5);
    2832                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 23), data);
    2833         [ #  # ]:          0 :                 if (ret_val)
    2834                 :            :                         return ret_val;
    2835                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(769, 16), &data);
    2836                 :          0 :                 data |= (1 << 13);
    2837                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(769, 16), data);
    2838         [ #  # ]:          0 :                 if (ret_val)
    2839                 :            :                         return ret_val;
    2840                 :          0 :                 hw->phy.ops.read_reg(hw, PHY_REG(776, 20), &data);
    2841                 :          0 :                 data &= ~(0x3FF << 2);
    2842                 :          0 :                 data |= (0x8 << 2);
    2843                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(776, 20), data);
    2844         [ #  # ]:          0 :                 if (ret_val)
    2845                 :            :                         return ret_val;
    2846                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, PHY_REG(776, 23), 0x7E00);
    2847         [ #  # ]:          0 :                 if (ret_val)
    2848                 :            :                         return ret_val;
    2849                 :          0 :                 hw->phy.ops.read_reg(hw, HV_PM_CTRL, &data);
    2850                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, HV_PM_CTRL, data &
    2851                 :            :                                                 ~(1 << 10));
    2852         [ #  # ]:          0 :                 if (ret_val)
    2853                 :            :                         return ret_val;
    2854                 :            :         }
    2855                 :            : 
    2856                 :            :         /* re-enable Rx path after enabling/disabling workaround */
    2857                 :          0 :         return hw->phy.ops.write_reg(hw, PHY_REG(769, 20), phy_reg &
    2858                 :            :                                      ~(1 << 14));
    2859                 :            : }
    2860                 :            : 
    2861                 :            : /**
    2862                 :            :  *  e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
    2863                 :            :  *  done after every PHY reset.
    2864                 :            :  *  @hw: pointer to the HW structure
    2865                 :            :  **/
    2866                 :          0 : STATIC s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
    2867                 :            : {
    2868                 :            :         s32 ret_val = E1000_SUCCESS;
    2869                 :            : 
    2870                 :          0 :         DEBUGFUNC("e1000_lv_phy_workarounds_ich8lan");
    2871                 :            : 
    2872         [ #  # ]:          0 :         if (hw->mac.type != e1000_pch2lan)
    2873                 :            :                 return E1000_SUCCESS;
    2874                 :            : 
    2875                 :            :         /* Set MDIO slow mode before any other MDIO access */
    2876                 :          0 :         ret_val = e1000_set_mdio_slow_mode_hv(hw);
    2877         [ #  # ]:          0 :         if (ret_val)
    2878                 :            :                 return ret_val;
    2879                 :            : 
    2880                 :          0 :         ret_val = hw->phy.ops.acquire(hw);
    2881         [ #  # ]:          0 :         if (ret_val)
    2882                 :            :                 return ret_val;
    2883                 :            :         /* set MSE higher to enable link to stay up when noise is high */
    2884                 :          0 :         ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
    2885         [ #  # ]:          0 :         if (ret_val)
    2886                 :          0 :                 goto release;
    2887                 :            :         /* drop link after 5 times MSE threshold was reached */
    2888                 :          0 :         ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
    2889                 :          0 : release:
    2890                 :          0 :         hw->phy.ops.release(hw);
    2891                 :            : 
    2892                 :          0 :         return ret_val;
    2893                 :            : }
    2894                 :            : 
    2895                 :            : /**
    2896                 :            :  *  e1000_k1_gig_workaround_lv - K1 Si workaround
    2897                 :            :  *  @hw:   pointer to the HW structure
    2898                 :            :  *
    2899                 :            :  *  Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
    2900                 :            :  *  Disable K1 for 1000 and 100 speeds
    2901                 :            :  **/
    2902                 :          0 : STATIC s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
    2903                 :            : {
    2904                 :            :         s32 ret_val = E1000_SUCCESS;
    2905                 :          0 :         u16 status_reg = 0;
    2906                 :            : 
    2907                 :          0 :         DEBUGFUNC("e1000_k1_workaround_lv");
    2908                 :            : 
    2909         [ #  # ]:          0 :         if (hw->mac.type != e1000_pch2lan)
    2910                 :            :                 return E1000_SUCCESS;
    2911                 :            : 
    2912                 :            :         /* Set K1 beacon duration based on 10Mbs speed */
    2913                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, HV_M_STATUS, &status_reg);
    2914         [ #  # ]:          0 :         if (ret_val)
    2915                 :            :                 return ret_val;
    2916                 :            : 
    2917         [ #  # ]:          0 :         if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
    2918                 :            :             == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
    2919         [ #  # ]:          0 :                 if (status_reg &
    2920                 :            :                     (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
    2921                 :            :                         u16 pm_phy_reg;
    2922                 :            : 
    2923                 :            :                         /* LV 1G/100 Packet drop issue wa  */
    2924                 :          0 :                         ret_val = hw->phy.ops.read_reg(hw, HV_PM_CTRL,
    2925                 :            :                                                        &pm_phy_reg);
    2926         [ #  # ]:          0 :                         if (ret_val)
    2927                 :          0 :                                 return ret_val;
    2928                 :          0 :                         pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
    2929                 :          0 :                         ret_val = hw->phy.ops.write_reg(hw, HV_PM_CTRL,
    2930                 :            :                                                         pm_phy_reg);
    2931         [ #  # ]:          0 :                         if (ret_val)
    2932                 :            :                                 return ret_val;
    2933                 :            :                 } else {
    2934                 :            :                         u32 mac_reg;
    2935                 :          0 :                         mac_reg = E1000_READ_REG(hw, E1000_FEXTNVM4);
    2936                 :          0 :                         mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
    2937                 :          0 :                         mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
    2938                 :          0 :                         E1000_WRITE_REG(hw, E1000_FEXTNVM4, mac_reg);
    2939                 :            :                 }
    2940                 :            :         }
    2941                 :            : 
    2942                 :            :         return ret_val;
    2943                 :            : }
    2944                 :            : 
    2945                 :            : /**
    2946                 :            :  *  e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
    2947                 :            :  *  @hw:   pointer to the HW structure
    2948                 :            :  *  @gate: boolean set to true to gate, false to ungate
    2949                 :            :  *
    2950                 :            :  *  Gate/ungate the automatic PHY configuration via hardware; perform
    2951                 :            :  *  the configuration via software instead.
    2952                 :            :  **/
    2953                 :          0 : STATIC void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
    2954                 :            : {
    2955                 :            :         u32 extcnf_ctrl;
    2956                 :            : 
    2957                 :          0 :         DEBUGFUNC("e1000_gate_hw_phy_config_ich8lan");
    2958                 :            : 
    2959         [ #  # ]:          0 :         if (hw->mac.type < e1000_pch2lan)
    2960                 :            :                 return;
    2961                 :            : 
    2962                 :          0 :         extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
    2963                 :            : 
    2964         [ #  # ]:          0 :         if (gate)
    2965                 :          0 :                 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
    2966                 :            :         else
    2967                 :          0 :                 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
    2968                 :            : 
    2969                 :          0 :         E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
    2970                 :            : }
    2971                 :            : 
    2972                 :            : /**
    2973                 :            :  *  e1000_lan_init_done_ich8lan - Check for PHY config completion
    2974                 :            :  *  @hw: pointer to the HW structure
    2975                 :            :  *
    2976                 :            :  *  Check the appropriate indication the MAC has finished configuring the
    2977                 :            :  *  PHY after a software reset.
    2978                 :            :  **/
    2979                 :          0 : STATIC void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
    2980                 :            : {
    2981                 :            :         u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
    2982                 :            : 
    2983                 :          0 :         DEBUGFUNC("e1000_lan_init_done_ich8lan");
    2984                 :            : 
    2985                 :            :         /* Wait for basic configuration completes before proceeding */
    2986                 :            :         do {
    2987                 :          0 :                 data = E1000_READ_REG(hw, E1000_STATUS);
    2988                 :          0 :                 data &= E1000_STATUS_LAN_INIT_DONE;
    2989                 :          0 :                 usec_delay(100);
    2990   [ #  #  #  # ]:          0 :         } while ((!data) && --loop);
    2991                 :            : 
    2992                 :            :         /* If basic configuration is incomplete before the above loop
    2993                 :            :          * count reaches 0, loading the configuration from NVM will
    2994                 :            :          * leave the PHY in a bad state possibly resulting in no link.
    2995                 :            :          */
    2996         [ #  # ]:          0 :         if (loop == 0)
    2997                 :          0 :                 DEBUGOUT("LAN_INIT_DONE not set, increase timeout\n");
    2998                 :            : 
    2999                 :            :         /* Clear the Init Done bit for the next init event */
    3000                 :          0 :         data = E1000_READ_REG(hw, E1000_STATUS);
    3001                 :          0 :         data &= ~E1000_STATUS_LAN_INIT_DONE;
    3002                 :          0 :         E1000_WRITE_REG(hw, E1000_STATUS, data);
    3003                 :          0 : }
    3004                 :            : 
    3005                 :            : /**
    3006                 :            :  *  e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
    3007                 :            :  *  @hw: pointer to the HW structure
    3008                 :            :  **/
    3009                 :          0 : STATIC s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
    3010                 :            : {
    3011                 :            :         s32 ret_val = E1000_SUCCESS;
    3012                 :            :         u16 reg;
    3013                 :            : 
    3014                 :          0 :         DEBUGFUNC("e1000_post_phy_reset_ich8lan");
    3015                 :            : 
    3016         [ #  # ]:          0 :         if (hw->phy.ops.check_reset_block(hw))
    3017                 :            :                 return E1000_SUCCESS;
    3018                 :            : 
    3019                 :            :         /* Allow time for h/w to get to quiescent state after reset */
    3020                 :          0 :         msec_delay(10);
    3021                 :            : 
    3022                 :            :         /* Perform any necessary post-reset workarounds */
    3023      [ #  #  # ]:          0 :         switch (hw->mac.type) {
    3024                 :          0 :         case e1000_pchlan:
    3025                 :          0 :                 ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
    3026         [ #  # ]:          0 :                 if (ret_val)
    3027                 :            :                         return ret_val;
    3028                 :            :                 break;
    3029                 :          0 :         case e1000_pch2lan:
    3030                 :          0 :                 ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
    3031         [ #  # ]:          0 :                 if (ret_val)
    3032                 :            :                         return ret_val;
    3033                 :            :                 break;
    3034                 :            :         default:
    3035                 :            :                 break;
    3036                 :            :         }
    3037                 :            : 
    3038                 :            :         /* Clear the host wakeup bit after lcd reset */
    3039         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pchlan) {
    3040                 :          0 :                 hw->phy.ops.read_reg(hw, BM_PORT_GEN_CFG, &reg);
    3041                 :          0 :                 reg &= ~BM_WUC_HOST_WU_BIT;
    3042                 :          0 :                 hw->phy.ops.write_reg(hw, BM_PORT_GEN_CFG, reg);
    3043                 :            :         }
    3044                 :            : 
    3045                 :            :         /* Configure the LCD with the extended configuration region in NVM */
    3046                 :          0 :         ret_val = e1000_sw_lcd_config_ich8lan(hw);
    3047         [ #  # ]:          0 :         if (ret_val)
    3048                 :            :                 return ret_val;
    3049                 :            : 
    3050                 :            :         /* Configure the LCD with the OEM bits in NVM */
    3051                 :          0 :         ret_val = e1000_oem_bits_config_ich8lan(hw, true);
    3052                 :            : 
    3053         [ #  # ]:          0 :         if (hw->mac.type == e1000_pch2lan) {
    3054                 :            :                 /* Ungate automatic PHY configuration on non-managed 82579 */
    3055         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_FWSM) &
    3056                 :            :                     E1000_ICH_FWSM_FW_VALID)) {
    3057                 :          0 :                         msec_delay(10);
    3058                 :          0 :                         e1000_gate_hw_phy_config_ich8lan(hw, false);
    3059                 :            :                 }
    3060                 :            : 
    3061                 :            :                 /* Set EEE LPI Update Timer to 200usec */
    3062                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    3063         [ #  # ]:          0 :                 if (ret_val)
    3064                 :            :                         return ret_val;
    3065                 :          0 :                 ret_val = e1000_write_emi_reg_locked(hw,
    3066                 :            :                                                      I82579_LPI_UPDATE_TIMER,
    3067                 :            :                                                      0x1387);
    3068                 :          0 :                 hw->phy.ops.release(hw);
    3069                 :            :         }
    3070                 :            : 
    3071                 :            :         return ret_val;
    3072                 :            : }
    3073                 :            : 
    3074                 :            : /**
    3075                 :            :  *  e1000_phy_hw_reset_ich8lan - Performs a PHY reset
    3076                 :            :  *  @hw: pointer to the HW structure
    3077                 :            :  *
    3078                 :            :  *  Resets the PHY
    3079                 :            :  *  This is a function pointer entry point called by drivers
    3080                 :            :  *  or other shared routines.
    3081                 :            :  **/
    3082                 :          0 : STATIC s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
    3083                 :            : {
    3084                 :            :         s32 ret_val = E1000_SUCCESS;
    3085                 :            : 
    3086                 :          0 :         DEBUGFUNC("e1000_phy_hw_reset_ich8lan");
    3087                 :            : 
    3088                 :            :         /* Gate automatic PHY configuration by hardware on non-managed 82579 */
    3089         [ #  # ]:          0 :         if ((hw->mac.type == e1000_pch2lan) &&
    3090         [ #  # ]:          0 :             !(E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID))
    3091                 :          0 :                 e1000_gate_hw_phy_config_ich8lan(hw, true);
    3092                 :            : 
    3093                 :          0 :         ret_val = e1000_phy_hw_reset_generic(hw);
    3094         [ #  # ]:          0 :         if (ret_val)
    3095                 :            :                 return ret_val;
    3096                 :            : 
    3097                 :          0 :         return e1000_post_phy_reset_ich8lan(hw);
    3098                 :            : }
    3099                 :            : 
    3100                 :            : /**
    3101                 :            :  *  e1000_set_lplu_state_pchlan - Set Low Power Link Up state
    3102                 :            :  *  @hw: pointer to the HW structure
    3103                 :            :  *  @active: true to enable LPLU, false to disable
    3104                 :            :  *
    3105                 :            :  *  Sets the LPLU state according to the active flag.  For PCH, if OEM write
    3106                 :            :  *  bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
    3107                 :            :  *  the phy speed. This function will manually set the LPLU bit and restart
    3108                 :            :  *  auto-neg as hw would do. D3 and D0 LPLU will call the same function
    3109                 :            :  *  since it configures the same bit.
    3110                 :            :  **/
    3111                 :          0 : STATIC s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
    3112                 :            : {
    3113                 :            :         s32 ret_val;
    3114                 :            :         u16 oem_reg;
    3115                 :            : 
    3116                 :          0 :         DEBUGFUNC("e1000_set_lplu_state_pchlan");
    3117                 :          0 :         ret_val = hw->phy.ops.read_reg(hw, HV_OEM_BITS, &oem_reg);
    3118         [ #  # ]:          0 :         if (ret_val)
    3119                 :            :                 return ret_val;
    3120                 :            : 
    3121         [ #  # ]:          0 :         if (active)
    3122                 :          0 :                 oem_reg |= HV_OEM_BITS_LPLU;
    3123                 :            :         else
    3124                 :          0 :                 oem_reg &= ~HV_OEM_BITS_LPLU;
    3125                 :            : 
    3126         [ #  # ]:          0 :         if (!hw->phy.ops.check_reset_block(hw))
    3127                 :          0 :                 oem_reg |= HV_OEM_BITS_RESTART_AN;
    3128                 :            : 
    3129                 :          0 :         return hw->phy.ops.write_reg(hw, HV_OEM_BITS, oem_reg);
    3130                 :            : }
    3131                 :            : 
    3132                 :            : /**
    3133                 :            :  *  e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
    3134                 :            :  *  @hw: pointer to the HW structure
    3135                 :            :  *  @active: true to enable LPLU, false to disable
    3136                 :            :  *
    3137                 :            :  *  Sets the LPLU D0 state according to the active flag.  When
    3138                 :            :  *  activating LPLU this function also disables smart speed
    3139                 :            :  *  and vice versa.  LPLU will not be activated unless the
    3140                 :            :  *  device autonegotiation advertisement meets standards of
    3141                 :            :  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
    3142                 :            :  *  This is a function pointer entry point only called by
    3143                 :            :  *  PHY setup routines.
    3144                 :            :  **/
    3145                 :          0 : STATIC s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
    3146                 :            : {
    3147                 :            :         struct e1000_phy_info *phy = &hw->phy;
    3148                 :            :         u32 phy_ctrl;
    3149                 :            :         s32 ret_val = E1000_SUCCESS;
    3150                 :            :         u16 data;
    3151                 :            : 
    3152                 :          0 :         DEBUGFUNC("e1000_set_d0_lplu_state_ich8lan");
    3153                 :            : 
    3154         [ #  # ]:          0 :         if (phy->type == e1000_phy_ife)
    3155                 :            :                 return E1000_SUCCESS;
    3156                 :            : 
    3157                 :          0 :         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
    3158                 :            : 
    3159         [ #  # ]:          0 :         if (active) {
    3160                 :          0 :                 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
    3161                 :          0 :                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    3162                 :            : 
    3163         [ #  # ]:          0 :                 if (phy->type != e1000_phy_igp_3)
    3164                 :            :                         return E1000_SUCCESS;
    3165                 :            : 
    3166                 :            :                 /* Call gig speed drop workaround on LPLU before accessing
    3167                 :            :                  * any PHY registers
    3168                 :            :                  */
    3169         [ #  # ]:          0 :                 if (hw->mac.type == e1000_ich8lan)
    3170                 :          0 :                         e1000_gig_downshift_workaround_ich8lan(hw);
    3171                 :            : 
    3172                 :            :                 /* When LPLU is enabled, we should disable SmartSpeed */
    3173                 :          0 :                 ret_val = phy->ops.read_reg(hw,
    3174                 :            :                                             IGP01E1000_PHY_PORT_CONFIG,
    3175                 :            :                                             &data);
    3176         [ #  # ]:          0 :                 if (ret_val)
    3177                 :            :                         return ret_val;
    3178                 :          0 :                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
    3179                 :          0 :                 ret_val = phy->ops.write_reg(hw,
    3180                 :            :                                              IGP01E1000_PHY_PORT_CONFIG,
    3181                 :            :                                              data);
    3182         [ #  # ]:          0 :                 if (ret_val)
    3183                 :          0 :                         return ret_val;
    3184                 :            :         } else {
    3185                 :          0 :                 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
    3186                 :          0 :                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    3187                 :            : 
    3188         [ #  # ]:          0 :                 if (phy->type != e1000_phy_igp_3)
    3189                 :            :                         return E1000_SUCCESS;
    3190                 :            : 
    3191                 :            :                 /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
    3192                 :            :                  * during Dx states where the power conservation is most
    3193                 :            :                  * important.  During driver activity we should enable
    3194                 :            :                  * SmartSpeed, so performance is maintained.
    3195                 :            :                  */
    3196         [ #  # ]:          0 :                 if (phy->smart_speed == e1000_smart_speed_on) {
    3197                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    3198                 :            :                                                     IGP01E1000_PHY_PORT_CONFIG,
    3199                 :            :                                                     &data);
    3200         [ #  # ]:          0 :                         if (ret_val)
    3201                 :            :                                 return ret_val;
    3202                 :            : 
    3203                 :          0 :                         data |= IGP01E1000_PSCFR_SMART_SPEED;
    3204                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    3205                 :            :                                                      IGP01E1000_PHY_PORT_CONFIG,
    3206                 :            :                                                      data);
    3207         [ #  # ]:          0 :                         if (ret_val)
    3208                 :          0 :                                 return ret_val;
    3209         [ #  # ]:          0 :                 } else if (phy->smart_speed == e1000_smart_speed_off) {
    3210                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    3211                 :            :                                                     IGP01E1000_PHY_PORT_CONFIG,
    3212                 :            :                                                     &data);
    3213         [ #  # ]:          0 :                         if (ret_val)
    3214                 :            :                                 return ret_val;
    3215                 :            : 
    3216                 :          0 :                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
    3217                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    3218                 :            :                                                      IGP01E1000_PHY_PORT_CONFIG,
    3219                 :            :                                                      data);
    3220         [ #  # ]:          0 :                         if (ret_val)
    3221                 :          0 :                                 return ret_val;
    3222                 :            :                 }
    3223                 :            :         }
    3224                 :            : 
    3225                 :            :         return E1000_SUCCESS;
    3226                 :            : }
    3227                 :            : 
    3228                 :            : /**
    3229                 :            :  *  e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
    3230                 :            :  *  @hw: pointer to the HW structure
    3231                 :            :  *  @active: true to enable LPLU, false to disable
    3232                 :            :  *
    3233                 :            :  *  Sets the LPLU D3 state according to the active flag.  When
    3234                 :            :  *  activating LPLU this function also disables smart speed
    3235                 :            :  *  and vice versa.  LPLU will not be activated unless the
    3236                 :            :  *  device autonegotiation advertisement meets standards of
    3237                 :            :  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
    3238                 :            :  *  This is a function pointer entry point only called by
    3239                 :            :  *  PHY setup routines.
    3240                 :            :  **/
    3241                 :          0 : STATIC s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
    3242                 :            : {
    3243                 :            :         struct e1000_phy_info *phy = &hw->phy;
    3244                 :            :         u32 phy_ctrl;
    3245                 :            :         s32 ret_val = E1000_SUCCESS;
    3246                 :            :         u16 data;
    3247                 :            : 
    3248                 :          0 :         DEBUGFUNC("e1000_set_d3_lplu_state_ich8lan");
    3249                 :            : 
    3250                 :          0 :         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
    3251                 :            : 
    3252         [ #  # ]:          0 :         if (!active) {
    3253                 :          0 :                 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
    3254                 :          0 :                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    3255                 :            : 
    3256         [ #  # ]:          0 :                 if (phy->type != e1000_phy_igp_3)
    3257                 :            :                         return E1000_SUCCESS;
    3258                 :            : 
    3259                 :            :                 /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used
    3260                 :            :                  * during Dx states where the power conservation is most
    3261                 :            :                  * important.  During driver activity we should enable
    3262                 :            :                  * SmartSpeed, so performance is maintained.
    3263                 :            :                  */
    3264         [ #  # ]:          0 :                 if (phy->smart_speed == e1000_smart_speed_on) {
    3265                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    3266                 :            :                                                     IGP01E1000_PHY_PORT_CONFIG,
    3267                 :            :                                                     &data);
    3268         [ #  # ]:          0 :                         if (ret_val)
    3269                 :            :                                 return ret_val;
    3270                 :            : 
    3271                 :          0 :                         data |= IGP01E1000_PSCFR_SMART_SPEED;
    3272                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    3273                 :            :                                                      IGP01E1000_PHY_PORT_CONFIG,
    3274                 :            :                                                      data);
    3275         [ #  # ]:          0 :                         if (ret_val)
    3276                 :          0 :                                 return ret_val;
    3277         [ #  # ]:          0 :                 } else if (phy->smart_speed == e1000_smart_speed_off) {
    3278                 :          0 :                         ret_val = phy->ops.read_reg(hw,
    3279                 :            :                                                     IGP01E1000_PHY_PORT_CONFIG,
    3280                 :            :                                                     &data);
    3281         [ #  # ]:          0 :                         if (ret_val)
    3282                 :            :                                 return ret_val;
    3283                 :            : 
    3284                 :          0 :                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
    3285                 :          0 :                         ret_val = phy->ops.write_reg(hw,
    3286                 :            :                                                      IGP01E1000_PHY_PORT_CONFIG,
    3287                 :            :                                                      data);
    3288         [ #  # ]:          0 :                         if (ret_val)
    3289                 :          0 :                                 return ret_val;
    3290                 :            :                 }
    3291         [ #  # ]:          0 :         } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
    3292         [ #  # ]:          0 :                    (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
    3293                 :            :                    (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
    3294                 :          0 :                 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
    3295                 :          0 :                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    3296                 :            : 
    3297         [ #  # ]:          0 :                 if (phy->type != e1000_phy_igp_3)
    3298                 :            :                         return E1000_SUCCESS;
    3299                 :            : 
    3300                 :            :                 /* Call gig speed drop workaround on LPLU before accessing
    3301                 :            :                  * any PHY registers
    3302                 :            :                  */
    3303         [ #  # ]:          0 :                 if (hw->mac.type == e1000_ich8lan)
    3304                 :          0 :                         e1000_gig_downshift_workaround_ich8lan(hw);
    3305                 :            : 
    3306                 :            :                 /* When LPLU is enabled, we should disable SmartSpeed */
    3307                 :          0 :                 ret_val = phy->ops.read_reg(hw,
    3308                 :            :                                             IGP01E1000_PHY_PORT_CONFIG,
    3309                 :            :                                             &data);
    3310         [ #  # ]:          0 :                 if (ret_val)
    3311                 :            :                         return ret_val;
    3312                 :            : 
    3313                 :          0 :                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
    3314                 :          0 :                 ret_val = phy->ops.write_reg(hw,
    3315                 :            :                                              IGP01E1000_PHY_PORT_CONFIG,
    3316                 :            :                                              data);
    3317                 :            :         }
    3318                 :            : 
    3319                 :            :         return ret_val;
    3320                 :            : }
    3321                 :            : 
    3322                 :            : /**
    3323                 :            :  *  e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
    3324                 :            :  *  @hw: pointer to the HW structure
    3325                 :            :  *  @bank:  pointer to the variable that returns the active bank
    3326                 :            :  *
    3327                 :            :  *  Reads signature byte from the NVM using the flash access registers.
    3328                 :            :  *  Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
    3329                 :            :  **/
    3330                 :          0 : STATIC s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
    3331                 :            : {
    3332                 :            :         u32 eecd;
    3333                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    3334                 :          0 :         u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
    3335                 :            :         u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
    3336                 :          0 :         u32 nvm_dword = 0;
    3337                 :          0 :         u8 sig_byte = 0;
    3338                 :            :         s32 ret_val;
    3339                 :            : 
    3340                 :          0 :         DEBUGFUNC("e1000_valid_nvm_bank_detect_ich8lan");
    3341                 :            : 
    3342      [ #  #  # ]:          0 :         switch (hw->mac.type) {
    3343                 :          0 :         case e1000_pch_spt:
    3344                 :            :         case e1000_pch_cnp:
    3345                 :            :         case e1000_pch_adp:
    3346                 :          0 :                 bank1_offset = nvm->flash_bank_size;
    3347                 :            :                 act_offset = E1000_ICH_NVM_SIG_WORD;
    3348                 :            : 
    3349                 :            :                 /* set bank to 0 in case flash read fails */
    3350                 :          0 :                 *bank = 0;
    3351                 :            : 
    3352                 :            :                 /* Check bank 0 */
    3353                 :          0 :                 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset,
    3354                 :            :                                                          &nvm_dword);
    3355         [ #  # ]:          0 :                 if (ret_val)
    3356                 :            :                         return ret_val;
    3357                 :          0 :                 sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
    3358         [ #  # ]:          0 :                 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
    3359                 :            :                     E1000_ICH_NVM_SIG_VALUE) {
    3360                 :          0 :                         *bank = 0;
    3361                 :          0 :                         return E1000_SUCCESS;
    3362                 :            :                 }
    3363                 :            : 
    3364                 :            :                 /* Check bank 1 */
    3365                 :          0 :                 ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset +
    3366                 :            :                                                          bank1_offset,
    3367                 :            :                                                          &nvm_dword);
    3368         [ #  # ]:          0 :                 if (ret_val)
    3369                 :            :                         return ret_val;
    3370                 :          0 :                 sig_byte = (u8)((nvm_dword & 0xFF00) >> 8);
    3371         [ #  # ]:          0 :                 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
    3372                 :            :                     E1000_ICH_NVM_SIG_VALUE) {
    3373                 :          0 :                         *bank = 1;
    3374                 :          0 :                         return E1000_SUCCESS;
    3375                 :            :                 }
    3376                 :            : 
    3377                 :          0 :                 DEBUGOUT("ERROR: No valid NVM bank present\n");
    3378                 :          0 :                 return -E1000_ERR_NVM;
    3379                 :          0 :         case e1000_ich8lan:
    3380                 :            :         case e1000_ich9lan:
    3381                 :          0 :                 eecd = E1000_READ_REG(hw, E1000_EECD);
    3382         [ #  # ]:          0 :                 if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
    3383                 :            :                     E1000_EECD_SEC1VAL_VALID_MASK) {
    3384         [ #  # ]:          0 :                         if (eecd & E1000_EECD_SEC1VAL)
    3385                 :          0 :                                 *bank = 1;
    3386                 :            :                         else
    3387                 :          0 :                                 *bank = 0;
    3388                 :            : 
    3389                 :          0 :                         return E1000_SUCCESS;
    3390                 :            :                 }
    3391                 :          0 :                 DEBUGOUT("Unable to determine valid NVM bank via EEC - reading flash signature\n");
    3392                 :            :                 /* fall-thru */
    3393                 :          0 :         default:
    3394                 :            :                 /* set bank to 0 in case flash read fails */
    3395                 :          0 :                 *bank = 0;
    3396                 :            : 
    3397                 :            :                 /* Check bank 0 */
    3398                 :          0 :                 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
    3399                 :            :                                                         &sig_byte);
    3400         [ #  # ]:          0 :                 if (ret_val)
    3401                 :            :                         return ret_val;
    3402         [ #  # ]:          0 :                 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
    3403                 :            :                     E1000_ICH_NVM_SIG_VALUE) {
    3404                 :          0 :                         *bank = 0;
    3405                 :          0 :                         return E1000_SUCCESS;
    3406                 :            :                 }
    3407                 :            : 
    3408                 :            :                 /* Check bank 1 */
    3409                 :          0 :                 ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
    3410                 :            :                                                         bank1_offset,
    3411                 :            :                                                         &sig_byte);
    3412         [ #  # ]:          0 :                 if (ret_val)
    3413                 :            :                         return ret_val;
    3414         [ #  # ]:          0 :                 if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
    3415                 :            :                     E1000_ICH_NVM_SIG_VALUE) {
    3416                 :          0 :                         *bank = 1;
    3417                 :          0 :                         return E1000_SUCCESS;
    3418                 :            :                 }
    3419                 :            : 
    3420                 :          0 :                 DEBUGOUT("ERROR: No valid NVM bank present\n");
    3421                 :          0 :                 return -E1000_ERR_NVM;
    3422                 :            :         }
    3423                 :            : }
    3424                 :            : 
    3425                 :            : /**
    3426                 :            :  *  e1000_read_nvm_spt - NVM access for SPT
    3427                 :            :  *  @hw: pointer to the HW structure
    3428                 :            :  *  @offset: The offset (in bytes) of the word(s) to read.
    3429                 :            :  *  @words: Size of data to read in words.
    3430                 :            :  *  @data: pointer to the word(s) to read at offset.
    3431                 :            :  *
    3432                 :            :  *  Reads a word(s) from the NVM
    3433                 :            :  **/
    3434                 :          0 : STATIC s32 e1000_read_nvm_spt(struct e1000_hw *hw, u16 offset, u16 words,
    3435                 :            :                               u16 *data)
    3436                 :            : {
    3437                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    3438                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    3439                 :            :         u32 act_offset;
    3440                 :            :         s32 ret_val = E1000_SUCCESS;
    3441                 :          0 :         u32 bank = 0;
    3442                 :          0 :         u32 dword = 0;
    3443                 :            :         u16 offset_to_read;
    3444                 :            :         u16 i;
    3445                 :            : 
    3446                 :          0 :         DEBUGFUNC("e1000_read_nvm_spt");
    3447                 :            : 
    3448   [ #  #  #  #  :          0 :         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
                   #  # ]
    3449                 :            :             (words == 0)) {
    3450                 :          0 :                 DEBUGOUT("nvm parameter(s) out of bounds\n");
    3451                 :            :                 ret_val = -E1000_ERR_NVM;
    3452                 :          0 :                 goto out;
    3453                 :            :         }
    3454                 :            : 
    3455                 :          0 :         nvm->ops.acquire(hw);
    3456                 :            : 
    3457                 :          0 :         ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
    3458         [ #  # ]:          0 :         if (ret_val != E1000_SUCCESS) {
    3459                 :          0 :                 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
    3460                 :          0 :                 bank = 0;
    3461                 :            :         }
    3462                 :            : 
    3463         [ #  # ]:          0 :         act_offset = (bank) ? nvm->flash_bank_size : 0;
    3464                 :          0 :         act_offset += offset;
    3465                 :            : 
    3466                 :            :         ret_val = E1000_SUCCESS;
    3467                 :            : 
    3468         [ #  # ]:          0 :         for (i = 0; i < words; i += 2) {
    3469         [ #  # ]:          0 :                 if (words - i == 1) {
    3470         [ #  # ]:          0 :                         if (dev_spec->shadow_ram[offset + i].modified) {
    3471                 :          0 :                                 data[i] =
    3472                 :          0 :                                     dev_spec->shadow_ram[offset + i].value;
    3473                 :            :                         } else {
    3474                 :          0 :                                 offset_to_read = act_offset + i -
    3475                 :          0 :                                                  ((act_offset + i) % 2);
    3476                 :            :                                 ret_val =
    3477                 :          0 :                                    e1000_read_flash_dword_ich8lan(hw,
    3478                 :            :                                                                  offset_to_read,
    3479                 :            :                                                                  &dword);
    3480         [ #  # ]:          0 :                                 if (ret_val)
    3481                 :            :                                         break;
    3482         [ #  # ]:          0 :                                 if ((act_offset + i) % 2 == 0)
    3483                 :          0 :                                         data[i] = (u16)(dword & 0xFFFF);
    3484                 :            :                                 else
    3485                 :          0 :                                         data[i] = (u16)((dword >> 16) & 0xFFFF);
    3486                 :            :                         }
    3487                 :            :                 } else {
    3488                 :          0 :                         offset_to_read = act_offset + i;
    3489         [ #  # ]:          0 :                         if (!(dev_spec->shadow_ram[offset + i].modified) ||
    3490         [ #  # ]:          0 :                             !(dev_spec->shadow_ram[offset + i + 1].modified)) {
    3491                 :            :                                 ret_val =
    3492                 :          0 :                                    e1000_read_flash_dword_ich8lan(hw,
    3493                 :            :                                                                  offset_to_read,
    3494                 :            :                                                                  &dword);
    3495         [ #  # ]:          0 :                                 if (ret_val)
    3496                 :            :                                         break;
    3497                 :            :                         }
    3498         [ #  # ]:          0 :                         if (dev_spec->shadow_ram[offset + i].modified)
    3499                 :          0 :                                 data[i] =
    3500                 :          0 :                                     dev_spec->shadow_ram[offset + i].value;
    3501                 :            :                         else
    3502                 :          0 :                                 data[i] = (u16)(dword & 0xFFFF);
    3503         [ #  # ]:          0 :                         if (dev_spec->shadow_ram[offset + i + 1].modified)
    3504                 :          0 :                                 data[i + 1] =
    3505                 :          0 :                                    dev_spec->shadow_ram[offset + i + 1].value;
    3506                 :            :                         else
    3507                 :          0 :                                 data[i + 1] = (u16)(dword >> 16 & 0xFFFF);
    3508                 :            :                 }
    3509                 :            :         }
    3510                 :            : 
    3511                 :          0 :         nvm->ops.release(hw);
    3512                 :            : 
    3513                 :            : out:
    3514         [ #  # ]:          0 :         if (ret_val)
    3515                 :          0 :                 DEBUGOUT1("NVM read error: %d\n", ret_val);
    3516                 :            : 
    3517                 :          0 :         return ret_val;
    3518                 :            : }
    3519                 :            : 
    3520                 :            : /**
    3521                 :            :  *  e1000_read_nvm_ich8lan - Read word(s) from the NVM
    3522                 :            :  *  @hw: pointer to the HW structure
    3523                 :            :  *  @offset: The offset (in bytes) of the word(s) to read.
    3524                 :            :  *  @words: Size of data to read in words
    3525                 :            :  *  @data: Pointer to the word(s) to read at offset.
    3526                 :            :  *
    3527                 :            :  *  Reads a word(s) from the NVM using the flash access registers.
    3528                 :            :  **/
    3529                 :          0 : STATIC s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
    3530                 :            :                                   u16 *data)
    3531                 :            : {
    3532                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    3533                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    3534                 :            :         u32 act_offset;
    3535                 :            :         s32 ret_val = E1000_SUCCESS;
    3536                 :          0 :         u32 bank = 0;
    3537                 :            :         u16 i, word;
    3538                 :            : 
    3539                 :          0 :         DEBUGFUNC("e1000_read_nvm_ich8lan");
    3540                 :            : 
    3541   [ #  #  #  #  :          0 :         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
                   #  # ]
    3542                 :            :             (words == 0)) {
    3543                 :          0 :                 DEBUGOUT("nvm parameter(s) out of bounds\n");
    3544                 :            :                 ret_val = -E1000_ERR_NVM;
    3545                 :          0 :                 goto out;
    3546                 :            :         }
    3547                 :            : 
    3548                 :          0 :         nvm->ops.acquire(hw);
    3549                 :            : 
    3550                 :          0 :         ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
    3551         [ #  # ]:          0 :         if (ret_val != E1000_SUCCESS) {
    3552                 :          0 :                 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
    3553                 :          0 :                 bank = 0;
    3554                 :            :         }
    3555                 :            : 
    3556         [ #  # ]:          0 :         act_offset = (bank) ? nvm->flash_bank_size : 0;
    3557                 :          0 :         act_offset += offset;
    3558                 :            : 
    3559                 :            :         ret_val = E1000_SUCCESS;
    3560         [ #  # ]:          0 :         for (i = 0; i < words; i++) {
    3561         [ #  # ]:          0 :                 if (dev_spec->shadow_ram[offset + i].modified) {
    3562                 :          0 :                         data[i] = dev_spec->shadow_ram[offset + i].value;
    3563                 :            :                 } else {
    3564                 :          0 :                         ret_val = e1000_read_flash_word_ich8lan(hw,
    3565                 :            :                                                                 act_offset + i,
    3566                 :            :                                                                 &word);
    3567         [ #  # ]:          0 :                         if (ret_val)
    3568                 :            :                                 break;
    3569                 :          0 :                         data[i] = word;
    3570                 :            :                 }
    3571                 :            :         }
    3572                 :            : 
    3573                 :          0 :         nvm->ops.release(hw);
    3574                 :            : 
    3575                 :            : out:
    3576         [ #  # ]:          0 :         if (ret_val)
    3577                 :          0 :                 DEBUGOUT1("NVM read error: %d\n", ret_val);
    3578                 :            : 
    3579                 :          0 :         return ret_val;
    3580                 :            : }
    3581                 :            : 
    3582                 :            : /**
    3583                 :            :  *  e1000_flash_cycle_init_ich8lan - Initialize flash
    3584                 :            :  *  @hw: pointer to the HW structure
    3585                 :            :  *
    3586                 :            :  *  This function does initial flash setup so that a new read/write/erase cycle
    3587                 :            :  *  can be started.
    3588                 :            :  **/
    3589                 :          0 : STATIC s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
    3590                 :            : {
    3591                 :            :         union ich8_hws_flash_status hsfsts;
    3592                 :            :         s32 ret_val = -E1000_ERR_NVM;
    3593                 :            : 
    3594                 :          0 :         DEBUGFUNC("e1000_flash_cycle_init_ich8lan");
    3595                 :            : 
    3596                 :          0 :         hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
    3597                 :            : 
    3598                 :            :         /* Check if the flash descriptor is valid */
    3599         [ #  # ]:          0 :         if (!hsfsts.hsf_status.fldesvalid) {
    3600                 :          0 :                 DEBUGOUT("Flash descriptor invalid.  SW Sequencing must be used.\n");
    3601                 :          0 :                 return -E1000_ERR_NVM;
    3602                 :            :         }
    3603                 :            : 
    3604                 :            :         /* Clear FCERR and DAEL in hw status by writing 1 */
    3605                 :          0 :         hsfsts.hsf_status.flcerr = 1;
    3606                 :          0 :         hsfsts.hsf_status.dael = 1;
    3607         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt)
    3608                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    3609                 :            :                                       hsfsts.regval & 0xFFFF);
    3610                 :            :         else
    3611                 :          0 :                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
    3612                 :            : 
    3613                 :            :         /* Either we should have a hardware SPI cycle in progress
    3614                 :            :          * bit to check against, in order to start a new cycle or
    3615                 :            :          * FDONE bit should be changed in the hardware so that it
    3616                 :            :          * is 1 after hardware reset, which can then be used as an
    3617                 :            :          * indication whether a cycle is in progress or has been
    3618                 :            :          * completed.
    3619                 :            :          */
    3620                 :            : 
    3621         [ #  # ]:          0 :         if (!hsfsts.hsf_status.flcinprog) {
    3622                 :            :                 /* There is no cycle running at present,
    3623                 :            :                  * so we can start a cycle.
    3624                 :            :                  * Begin by setting Flash Cycle Done.
    3625                 :            :                  */
    3626                 :          0 :                 hsfsts.hsf_status.flcdone = 1;
    3627         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
    3628                 :          0 :                         E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    3629                 :            :                                               hsfsts.regval & 0xFFFF);
    3630                 :            :                 else
    3631                 :          0 :                         E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS,
    3632                 :            :                                                 hsfsts.regval);
    3633                 :            :                 ret_val = E1000_SUCCESS;
    3634                 :            :         } else {
    3635                 :            :                 s32 i;
    3636                 :            : 
    3637                 :            :                 /* Otherwise poll for sometime so the current
    3638                 :            :                  * cycle has a chance to end before giving up.
    3639                 :            :                  */
    3640         [ #  # ]:          0 :                 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
    3641                 :          0 :                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
    3642                 :            :                                                               ICH_FLASH_HSFSTS);
    3643         [ #  # ]:          0 :                         if (!hsfsts.hsf_status.flcinprog) {
    3644                 :            :                                 ret_val = E1000_SUCCESS;
    3645                 :            :                                 break;
    3646                 :            :                         }
    3647                 :          0 :                         usec_delay(1);
    3648                 :            :                 }
    3649         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS) {
    3650                 :            :                         /* Successful in waiting for previous cycle to timeout,
    3651                 :            :                          * now set the Flash Cycle Done.
    3652                 :            :                          */
    3653                 :          0 :                         hsfsts.hsf_status.flcdone = 1;
    3654         [ #  # ]:          0 :                         if (hw->mac.type >= e1000_pch_spt)
    3655                 :          0 :                                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    3656                 :            :                                                       hsfsts.regval & 0xFFFF);
    3657                 :            :                         else
    3658                 :          0 :                                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS,
    3659                 :            :                                                         hsfsts.regval);
    3660                 :            :                 } else {
    3661                 :          0 :                         DEBUGOUT("Flash controller busy, cannot get access\n");
    3662                 :            :                 }
    3663                 :            :         }
    3664                 :            : 
    3665                 :            :         return ret_val;
    3666                 :            : }
    3667                 :            : 
    3668                 :            : /**
    3669                 :            :  *  e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
    3670                 :            :  *  @hw: pointer to the HW structure
    3671                 :            :  *  @timeout: maximum time to wait for completion
    3672                 :            :  *
    3673                 :            :  *  This function starts a flash cycle and waits for its completion.
    3674                 :            :  **/
    3675                 :          0 : STATIC s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
    3676                 :            : {
    3677                 :            :         union ich8_hws_flash_ctrl hsflctl;
    3678                 :            :         union ich8_hws_flash_status hsfsts;
    3679                 :            :         u32 i = 0;
    3680                 :            : 
    3681                 :          0 :         DEBUGFUNC("e1000_flash_cycle_ich8lan");
    3682                 :            : 
    3683                 :            :         /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
    3684         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt)
    3685                 :          0 :                 hsflctl.regval = E1000_READ_FLASH_REG(hw, ICH_FLASH_HSFSTS)>>16;
    3686                 :            :         else
    3687                 :          0 :                 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
    3688                 :          0 :         hsflctl.hsf_ctrl.flcgo = 1;
    3689                 :            : 
    3690         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt)
    3691                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    3692                 :            :                                       hsflctl.regval << 16);
    3693                 :            :         else
    3694                 :          0 :                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
    3695                 :            : 
    3696                 :            :         /* wait till FDONE bit is set to 1 */
    3697                 :            :         do {
    3698                 :          0 :                 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
    3699         [ #  # ]:          0 :                 if (hsfsts.hsf_status.flcdone)
    3700                 :            :                         break;
    3701                 :          0 :                 usec_delay(1);
    3702         [ #  # ]:          0 :         } while (i++ < timeout);
    3703                 :            : 
    3704         [ #  # ]:          0 :         if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
    3705                 :          0 :                 return E1000_SUCCESS;
    3706                 :            : 
    3707                 :            :         return -E1000_ERR_NVM;
    3708                 :            : }
    3709                 :            : 
    3710                 :            : /**
    3711                 :            :  *  e1000_read_flash_dword_ich8lan - Read dword from flash
    3712                 :            :  *  @hw: pointer to the HW structure
    3713                 :            :  *  @offset: offset to data location
    3714                 :            :  *  @data: pointer to the location for storing the data
    3715                 :            :  *
    3716                 :            :  *  Reads the flash dword at offset into data.  Offset is converted
    3717                 :            :  *  to bytes before read.
    3718                 :            :  **/
    3719                 :          0 : STATIC s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw, u32 offset,
    3720                 :            :                                           u32 *data)
    3721                 :            : {
    3722                 :          0 :         DEBUGFUNC("e1000_read_flash_dword_ich8lan");
    3723                 :            : 
    3724         [ #  # ]:          0 :         if (!data)
    3725                 :            :                 return -E1000_ERR_NVM;
    3726                 :            : 
    3727                 :            :         /* Must convert word offset into bytes. */
    3728                 :          0 :         offset <<= 1;
    3729                 :            : 
    3730                 :          0 :         return e1000_read_flash_data32_ich8lan(hw, offset, data);
    3731                 :            : }
    3732                 :            : 
    3733                 :            : /**
    3734                 :            :  *  e1000_read_flash_word_ich8lan - Read word from flash
    3735                 :            :  *  @hw: pointer to the HW structure
    3736                 :            :  *  @offset: offset to data location
    3737                 :            :  *  @data: pointer to the location for storing the data
    3738                 :            :  *
    3739                 :            :  *  Reads the flash word at offset into data.  Offset is converted
    3740                 :            :  *  to bytes before read.
    3741                 :            :  **/
    3742                 :          0 : STATIC s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
    3743                 :            :                                          u16 *data)
    3744                 :            : {
    3745                 :          0 :         DEBUGFUNC("e1000_read_flash_word_ich8lan");
    3746                 :            : 
    3747         [ #  # ]:          0 :         if (!data)
    3748                 :            :                 return -E1000_ERR_NVM;
    3749                 :            : 
    3750                 :            :         /* Must convert offset into bytes. */
    3751                 :          0 :         offset <<= 1;
    3752                 :            : 
    3753                 :          0 :         return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
    3754                 :            : }
    3755                 :            : 
    3756                 :            : /**
    3757                 :            :  *  e1000_read_flash_byte_ich8lan - Read byte from flash
    3758                 :            :  *  @hw: pointer to the HW structure
    3759                 :            :  *  @offset: The offset of the byte to read.
    3760                 :            :  *  @data: Pointer to a byte to store the value read.
    3761                 :            :  *
    3762                 :            :  *  Reads a single byte from the NVM using the flash access registers.
    3763                 :            :  **/
    3764                 :          0 : STATIC s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
    3765                 :            :                                          u8 *data)
    3766                 :            : {
    3767                 :            :         s32 ret_val;
    3768                 :          0 :         u16 word = 0;
    3769                 :            : 
    3770                 :            :         /* In SPT, only 32 bits access is supported,
    3771                 :            :          * so this function should not be called.
    3772                 :            :          */
    3773         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt)
    3774                 :            :                 return -E1000_ERR_NVM;
    3775                 :            :         else
    3776                 :          0 :                 ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
    3777                 :            : 
    3778         [ #  # ]:          0 :         if (ret_val)
    3779                 :            :                 return ret_val;
    3780                 :            : 
    3781                 :          0 :         *data = (u8)word;
    3782                 :            : 
    3783                 :          0 :         return E1000_SUCCESS;
    3784                 :            : }
    3785                 :            : 
    3786                 :            : /**
    3787                 :            :  *  e1000_read_flash_data_ich8lan - Read byte or word from NVM
    3788                 :            :  *  @hw: pointer to the HW structure
    3789                 :            :  *  @offset: The offset (in bytes) of the byte or word to read.
    3790                 :            :  *  @size: Size of data to read, 1=byte 2=word
    3791                 :            :  *  @data: Pointer to the word to store the value read.
    3792                 :            :  *
    3793                 :            :  *  Reads a byte or word from the NVM using the flash access registers.
    3794                 :            :  **/
    3795                 :          0 : STATIC s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
    3796                 :            :                                          u8 size, u16 *data)
    3797                 :            : {
    3798                 :            :         union ich8_hws_flash_status hsfsts;
    3799                 :            :         union ich8_hws_flash_ctrl hsflctl;
    3800                 :            :         u32 flash_linear_addr;
    3801                 :            :         u32 flash_data = 0;
    3802                 :            :         s32 ret_val = -E1000_ERR_NVM;
    3803                 :            :         u8 count = 0;
    3804                 :            : 
    3805                 :          0 :         DEBUGFUNC("e1000_read_flash_data_ich8lan");
    3806                 :            : 
    3807   [ #  #  #  # ]:          0 :         if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
    3808                 :            :                 return -E1000_ERR_NVM;
    3809                 :          0 :         flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
    3810                 :          0 :                              hw->nvm.flash_base_addr);
    3811                 :            : 
    3812                 :            :         do {
    3813                 :          0 :                 usec_delay(1);
    3814                 :            :                 /* Steps */
    3815                 :          0 :                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
    3816         [ #  # ]:          0 :                 if (ret_val != E1000_SUCCESS)
    3817                 :            :                         break;
    3818                 :          0 :                 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
    3819                 :            : 
    3820                 :            :                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
    3821                 :          0 :                 hsflctl.hsf_ctrl.fldbcount = size - 1;
    3822                 :          0 :                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
    3823                 :          0 :                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
    3824                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
    3825                 :            : 
    3826                 :          0 :                 ret_val = e1000_flash_cycle_ich8lan(hw,
    3827                 :            :                                                 ICH_FLASH_READ_COMMAND_TIMEOUT);
    3828                 :            : 
    3829                 :            :                 /* Check if FCERR is set to 1, if set to 1, clear it
    3830                 :            :                  * and try the whole sequence a few more times, else
    3831                 :            :                  * read in (shift in) the Flash Data0, the order is
    3832                 :            :                  * least significant byte first msb to lsb
    3833                 :            :                  */
    3834         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS) {
    3835                 :          0 :                         flash_data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);
    3836         [ #  # ]:          0 :                         if (size == 1)
    3837                 :          0 :                                 *data = (u8)(flash_data & 0x000000FF);
    3838                 :            :                         else if (size == 2)
    3839                 :          0 :                                 *data = (u16)(flash_data & 0x0000FFFF);
    3840                 :            :                         break;
    3841                 :            :                 } else {
    3842                 :            :                         /* If we've gotten here, then things are probably
    3843                 :            :                          * completely hosed, but if the error condition is
    3844                 :            :                          * detected, it won't hurt to give it another try...
    3845                 :            :                          * ICH_FLASH_CYCLE_REPEAT_COUNT times.
    3846                 :            :                          */
    3847                 :          0 :                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
    3848                 :            :                                                               ICH_FLASH_HSFSTS);
    3849         [ #  # ]:          0 :                         if (hsfsts.hsf_status.flcerr) {
    3850                 :            :                                 /* Repeat for some time before giving up. */
    3851                 :          0 :                                 continue;
    3852         [ #  # ]:          0 :                         } else if (!hsfsts.hsf_status.flcdone) {
    3853                 :          0 :                                 DEBUGOUT("Timeout error - flash cycle did not complete.\n");
    3854                 :          0 :                                 break;
    3855                 :            :                         }
    3856                 :            :                 }
    3857         [ #  # ]:          0 :         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
    3858                 :            : 
    3859                 :            :         return ret_val;
    3860                 :            : }
    3861                 :            : 
    3862                 :            : /**
    3863                 :            :  *  e1000_read_flash_data32_ich8lan - Read dword from NVM
    3864                 :            :  *  @hw: pointer to the HW structure
    3865                 :            :  *  @offset: The offset (in bytes) of the dword to read.
    3866                 :            :  *  @data: Pointer to the dword to store the value read.
    3867                 :            :  *
    3868                 :            :  *  Reads a byte or word from the NVM using the flash access registers.
    3869                 :            :  **/
    3870                 :          0 : STATIC s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
    3871                 :            :                                            u32 *data)
    3872                 :            : {
    3873                 :            :         union ich8_hws_flash_status hsfsts;
    3874                 :            :         union ich8_hws_flash_ctrl hsflctl;
    3875                 :            :         u32 flash_linear_addr;
    3876                 :            :         s32 ret_val = -E1000_ERR_NVM;
    3877                 :            :         u8 count = 0;
    3878                 :            : 
    3879                 :          0 :         DEBUGFUNC("e1000_read_flash_data_ich8lan");
    3880                 :            : 
    3881         [ #  # ]:          0 :                 if (offset > ICH_FLASH_LINEAR_ADDR_MASK ||
    3882         [ #  # ]:          0 :                     hw->mac.type < e1000_pch_spt)
    3883                 :            :                         return -E1000_ERR_NVM;
    3884                 :          0 :         flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
    3885                 :          0 :                              hw->nvm.flash_base_addr);
    3886                 :            : 
    3887                 :            :         do {
    3888                 :          0 :                 usec_delay(1);
    3889                 :            :                 /* Steps */
    3890                 :          0 :                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
    3891         [ #  # ]:          0 :                 if (ret_val != E1000_SUCCESS)
    3892                 :            :                         break;
    3893                 :            :                 /* In SPT, This register is in Lan memory space, not flash.
    3894                 :            :                  * Therefore, only 32 bit access is supported
    3895                 :            :                  */
    3896                 :          0 :                 hsflctl.regval = E1000_READ_FLASH_REG(hw, ICH_FLASH_HSFSTS)>>16;
    3897                 :            : 
    3898                 :            :                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
    3899                 :          0 :                 hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
    3900                 :          0 :                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
    3901                 :            :                 /* In SPT, This register is in Lan memory space, not flash.
    3902                 :            :                  * Therefore, only 32 bit access is supported
    3903                 :            :                  */
    3904                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    3905                 :            :                                       (u32)hsflctl.regval << 16);
    3906                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
    3907                 :            : 
    3908                 :          0 :                 ret_val = e1000_flash_cycle_ich8lan(hw,
    3909                 :            :                                                 ICH_FLASH_READ_COMMAND_TIMEOUT);
    3910                 :            : 
    3911                 :            :                 /* Check if FCERR is set to 1, if set to 1, clear it
    3912                 :            :                  * and try the whole sequence a few more times, else
    3913                 :            :                  * read in (shift in) the Flash Data0, the order is
    3914                 :            :                  * least significant byte first msb to lsb
    3915                 :            :                  */
    3916         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS) {
    3917                 :          0 :                         *data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);
    3918                 :          0 :                         break;
    3919                 :            :                 } else {
    3920                 :            :                         /* If we've gotten here, then things are probably
    3921                 :            :                          * completely hosed, but if the error condition is
    3922                 :            :                          * detected, it won't hurt to give it another try...
    3923                 :            :                          * ICH_FLASH_CYCLE_REPEAT_COUNT times.
    3924                 :            :                          */
    3925                 :          0 :                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
    3926                 :            :                                                               ICH_FLASH_HSFSTS);
    3927         [ #  # ]:          0 :                         if (hsfsts.hsf_status.flcerr) {
    3928                 :            :                                 /* Repeat for some time before giving up. */
    3929                 :          0 :                                 continue;
    3930         [ #  # ]:          0 :                         } else if (!hsfsts.hsf_status.flcdone) {
    3931                 :          0 :                                 DEBUGOUT("Timeout error - flash cycle did not complete.\n");
    3932                 :          0 :                                 break;
    3933                 :            :                         }
    3934                 :            :                 }
    3935         [ #  # ]:          0 :         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
    3936                 :            : 
    3937                 :            :         return ret_val;
    3938                 :            : }
    3939                 :            : 
    3940                 :            : /**
    3941                 :            :  *  e1000_write_nvm_ich8lan - Write word(s) to the NVM
    3942                 :            :  *  @hw: pointer to the HW structure
    3943                 :            :  *  @offset: The offset (in bytes) of the word(s) to write.
    3944                 :            :  *  @words: Size of data to write in words
    3945                 :            :  *  @data: Pointer to the word(s) to write at offset.
    3946                 :            :  *
    3947                 :            :  *  Writes a byte or word to the NVM using the flash access registers.
    3948                 :            :  **/
    3949                 :          0 : STATIC s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
    3950                 :            :                                    u16 *data)
    3951                 :            : {
    3952                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    3953                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    3954                 :            :         u16 i;
    3955                 :            : 
    3956                 :          0 :         DEBUGFUNC("e1000_write_nvm_ich8lan");
    3957                 :            : 
    3958   [ #  #  #  #  :          0 :         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
                   #  # ]
    3959                 :            :             (words == 0)) {
    3960                 :          0 :                 DEBUGOUT("nvm parameter(s) out of bounds\n");
    3961                 :          0 :                 return -E1000_ERR_NVM;
    3962                 :            :         }
    3963                 :            : 
    3964                 :          0 :         nvm->ops.acquire(hw);
    3965                 :            : 
    3966         [ #  # ]:          0 :         for (i = 0; i < words; i++) {
    3967                 :          0 :                 dev_spec->shadow_ram[offset + i].modified = true;
    3968                 :          0 :                 dev_spec->shadow_ram[offset + i].value = data[i];
    3969                 :            :         }
    3970                 :            : 
    3971                 :          0 :         nvm->ops.release(hw);
    3972                 :            : 
    3973                 :          0 :         return E1000_SUCCESS;
    3974                 :            : }
    3975                 :            : 
    3976                 :            : /**
    3977                 :            :  *  e1000_update_nvm_checksum_spt - Update the checksum for NVM
    3978                 :            :  *  @hw: pointer to the HW structure
    3979                 :            :  *
    3980                 :            :  *  The NVM checksum is updated by calling the generic update_nvm_checksum,
    3981                 :            :  *  which writes the checksum to the shadow ram.  The changes in the shadow
    3982                 :            :  *  ram are then committed to the EEPROM by processing each bank at a time
    3983                 :            :  *  checking for the modified bit and writing only the pending changes.
    3984                 :            :  *  After a successful commit, the shadow ram is cleared and is ready for
    3985                 :            :  *  future writes.
    3986                 :            :  **/
    3987                 :          0 : STATIC s32 e1000_update_nvm_checksum_spt(struct e1000_hw *hw)
    3988                 :            : {
    3989                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    3990                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    3991                 :            :         u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
    3992                 :            :         s32 ret_val;
    3993                 :          0 :         u32 dword = 0;
    3994                 :            : 
    3995                 :          0 :         DEBUGFUNC("e1000_update_nvm_checksum_spt");
    3996                 :            : 
    3997                 :          0 :         ret_val = e1000_update_nvm_checksum_generic(hw);
    3998         [ #  # ]:          0 :         if (ret_val)
    3999                 :          0 :                 goto out;
    4000                 :            : 
    4001         [ #  # ]:          0 :         if (nvm->type != e1000_nvm_flash_sw)
    4002                 :          0 :                 goto out;
    4003                 :            : 
    4004                 :          0 :         nvm->ops.acquire(hw);
    4005                 :            : 
    4006                 :            :         /* We're writing to the opposite bank so if we're on bank 1,
    4007                 :            :          * write to bank 0 etc.  We also need to erase the segment that
    4008                 :            :          * is going to be written
    4009                 :            :          */
    4010                 :          0 :         ret_val =  e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
    4011         [ #  # ]:          0 :         if (ret_val != E1000_SUCCESS) {
    4012                 :          0 :                 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
    4013                 :          0 :                 bank = 0;
    4014                 :            :         }
    4015                 :            : 
    4016         [ #  # ]:          0 :         if (bank == 0) {
    4017                 :          0 :                 new_bank_offset = nvm->flash_bank_size;
    4018                 :            :                 old_bank_offset = 0;
    4019                 :          0 :                 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
    4020         [ #  # ]:          0 :                 if (ret_val)
    4021                 :          0 :                         goto release;
    4022                 :            :         } else {
    4023                 :          0 :                 old_bank_offset = nvm->flash_bank_size;
    4024                 :            :                 new_bank_offset = 0;
    4025                 :          0 :                 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
    4026         [ #  # ]:          0 :                 if (ret_val)
    4027                 :          0 :                         goto release;
    4028                 :            :         }
    4029         [ #  # ]:          0 :         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i += 2) {
    4030                 :            :                 /* Determine whether to write the value stored
    4031                 :            :                  * in the other NVM bank or a modified value stored
    4032                 :            :                  * in the shadow RAM
    4033                 :            :                  */
    4034                 :          0 :                 ret_val = e1000_read_flash_dword_ich8lan(hw,
    4035                 :            :                                                          i + old_bank_offset,
    4036                 :            :                                                          &dword);
    4037                 :            : 
    4038         [ #  # ]:          0 :                 if (dev_spec->shadow_ram[i].modified) {
    4039                 :          0 :                         dword &= 0xffff0000;
    4040                 :          0 :                         dword |= (dev_spec->shadow_ram[i].value & 0xffff);
    4041                 :            :                 }
    4042         [ #  # ]:          0 :                 if (dev_spec->shadow_ram[i + 1].modified) {
    4043                 :          0 :                         dword &= 0x0000ffff;
    4044                 :          0 :                         dword |= ((dev_spec->shadow_ram[i + 1].value & 0xffff)
    4045                 :          0 :                                   << 16);
    4046                 :            :                 }
    4047         [ #  # ]:          0 :                 if (ret_val)
    4048                 :            :                         break;
    4049                 :            : 
    4050                 :            :                 /* If the word is 0x13, then make sure the signature bits
    4051                 :            :                  * (15:14) are 11b until the commit has completed.
    4052                 :            :                  * This will allow us to write 10b which indicates the
    4053                 :            :                  * signature is valid.  We want to do this after the write
    4054                 :            :                  * has completed so that we don't mark the segment valid
    4055                 :            :                  * while the write is still in progress
    4056                 :            :                  */
    4057         [ #  # ]:          0 :                 if (i == E1000_ICH_NVM_SIG_WORD - 1)
    4058                 :          0 :                         dword |= E1000_ICH_NVM_SIG_MASK << 16;
    4059                 :            : 
    4060                 :            :                 /* Convert offset to bytes. */
    4061                 :          0 :                 act_offset = (i + new_bank_offset) << 1;
    4062                 :            : 
    4063                 :          0 :                 usec_delay(100);
    4064                 :            : 
    4065                 :            :                 /* Write the data to the new bank. Offset in words*/
    4066                 :            :                 act_offset = i + new_bank_offset;
    4067                 :          0 :                 ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset,
    4068                 :            :                                                                 dword);
    4069         [ #  # ]:          0 :                 if (ret_val)
    4070                 :            :                         break;
    4071                 :            :          }
    4072                 :            : 
    4073                 :            :         /* Don't bother writing the segment valid bits if sector
    4074                 :            :          * programming failed.
    4075                 :            :          */
    4076         [ #  # ]:          0 :         if (ret_val) {
    4077                 :          0 :                 DEBUGOUT("Flash commit failed.\n");
    4078                 :          0 :                 goto release;
    4079                 :            :         }
    4080                 :            : 
    4081                 :            :         /* Finally validate the new segment by setting bit 15:14
    4082                 :            :          * to 10b in word 0x13 , this can be done without an
    4083                 :            :          * erase as well since these bits are 11 to start with
    4084                 :            :          * and we need to change bit 14 to 0b
    4085                 :            :          */
    4086                 :            :         act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
    4087                 :            : 
    4088                 :            :         /*offset in words but we read dword*/
    4089                 :          0 :         --act_offset;
    4090                 :          0 :         ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
    4091                 :            : 
    4092         [ #  # ]:          0 :         if (ret_val)
    4093                 :          0 :                 goto release;
    4094                 :            : 
    4095                 :          0 :         dword &= 0xBFFFFFFF;
    4096                 :          0 :         ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
    4097                 :            : 
    4098         [ #  # ]:          0 :         if (ret_val)
    4099                 :          0 :                 goto release;
    4100                 :            : 
    4101                 :            :         /* offset in words but we read dword*/
    4102                 :          0 :         act_offset = old_bank_offset + E1000_ICH_NVM_SIG_WORD - 1;
    4103                 :          0 :         ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
    4104                 :            : 
    4105         [ #  # ]:          0 :         if (ret_val)
    4106                 :          0 :                 goto release;
    4107                 :            : 
    4108                 :          0 :         dword &= 0x00FFFFFF;
    4109                 :          0 :         ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
    4110                 :            : 
    4111         [ #  # ]:          0 :         if (ret_val)
    4112                 :          0 :                 goto release;
    4113                 :            : 
    4114                 :            :         /* Great!  Everything worked, we can now clear the cached entries. */
    4115         [ #  # ]:          0 :         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
    4116                 :          0 :                 dev_spec->shadow_ram[i].modified = false;
    4117                 :          0 :                 dev_spec->shadow_ram[i].value = 0xFFFF;
    4118                 :            :         }
    4119                 :            : 
    4120                 :          0 : release:
    4121                 :          0 :         nvm->ops.release(hw);
    4122                 :            : 
    4123                 :            :         /* Reload the EEPROM, or else modifications will not appear
    4124                 :            :          * until after the next adapter reset.
    4125                 :            :          */
    4126         [ #  # ]:          0 :         if (!ret_val) {
    4127                 :          0 :                 nvm->ops.reload(hw);
    4128                 :          0 :                 msec_delay(10);
    4129                 :            :         }
    4130                 :            : 
    4131                 :          0 : out:
    4132         [ #  # ]:          0 :         if (ret_val)
    4133                 :          0 :                 DEBUGOUT1("NVM update error: %d\n", ret_val);
    4134                 :            : 
    4135                 :          0 :         return ret_val;
    4136                 :            : }
    4137                 :            : 
    4138                 :            : /**
    4139                 :            :  *  e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
    4140                 :            :  *  @hw: pointer to the HW structure
    4141                 :            :  *
    4142                 :            :  *  The NVM checksum is updated by calling the generic update_nvm_checksum,
    4143                 :            :  *  which writes the checksum to the shadow ram.  The changes in the shadow
    4144                 :            :  *  ram are then committed to the EEPROM by processing each bank at a time
    4145                 :            :  *  checking for the modified bit and writing only the pending changes.
    4146                 :            :  *  After a successful commit, the shadow ram is cleared and is ready for
    4147                 :            :  *  future writes.
    4148                 :            :  **/
    4149                 :          0 : STATIC s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
    4150                 :            : {
    4151                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    4152                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    4153                 :            :         u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
    4154                 :            :         s32 ret_val;
    4155                 :          0 :         u16 data = 0;
    4156                 :            : 
    4157                 :          0 :         DEBUGFUNC("e1000_update_nvm_checksum_ich8lan");
    4158                 :            : 
    4159                 :          0 :         ret_val = e1000_update_nvm_checksum_generic(hw);
    4160         [ #  # ]:          0 :         if (ret_val)
    4161                 :          0 :                 goto out;
    4162                 :            : 
    4163         [ #  # ]:          0 :         if (nvm->type != e1000_nvm_flash_sw)
    4164                 :          0 :                 goto out;
    4165                 :            : 
    4166                 :          0 :         nvm->ops.acquire(hw);
    4167                 :            : 
    4168                 :            :         /* We're writing to the opposite bank so if we're on bank 1,
    4169                 :            :          * write to bank 0 etc.  We also need to erase the segment that
    4170                 :            :          * is going to be written
    4171                 :            :          */
    4172                 :          0 :         ret_val =  e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
    4173         [ #  # ]:          0 :         if (ret_val != E1000_SUCCESS) {
    4174                 :          0 :                 DEBUGOUT("Could not detect valid bank, assuming bank 0\n");
    4175                 :          0 :                 bank = 0;
    4176                 :            :         }
    4177                 :            : 
    4178         [ #  # ]:          0 :         if (bank == 0) {
    4179                 :          0 :                 new_bank_offset = nvm->flash_bank_size;
    4180                 :            :                 old_bank_offset = 0;
    4181                 :          0 :                 ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
    4182         [ #  # ]:          0 :                 if (ret_val)
    4183                 :          0 :                         goto release;
    4184                 :            :         } else {
    4185                 :          0 :                 old_bank_offset = nvm->flash_bank_size;
    4186                 :            :                 new_bank_offset = 0;
    4187                 :          0 :                 ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
    4188         [ #  # ]:          0 :                 if (ret_val)
    4189                 :          0 :                         goto release;
    4190                 :            :         }
    4191         [ #  # ]:          0 :         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
    4192         [ #  # ]:          0 :                 if (dev_spec->shadow_ram[i].modified) {
    4193                 :          0 :                         data = dev_spec->shadow_ram[i].value;
    4194                 :            :                 } else {
    4195                 :          0 :                         ret_val = e1000_read_flash_word_ich8lan(hw, i +
    4196                 :            :                                                                 old_bank_offset,
    4197                 :            :                                                                 &data);
    4198         [ #  # ]:          0 :                         if (ret_val)
    4199                 :            :                                 break;
    4200                 :            :                 }
    4201                 :            :                 /* If the word is 0x13, then make sure the signature bits
    4202                 :            :                  * (15:14) are 11b until the commit has completed.
    4203                 :            :                  * This will allow us to write 10b which indicates the
    4204                 :            :                  * signature is valid.  We want to do this after the write
    4205                 :            :                  * has completed so that we don't mark the segment valid
    4206                 :            :                  * while the write is still in progress
    4207                 :            :                  */
    4208         [ #  # ]:          0 :                 if (i == E1000_ICH_NVM_SIG_WORD)
    4209                 :          0 :                         data |= E1000_ICH_NVM_SIG_MASK;
    4210                 :            : 
    4211                 :            :                 /* Convert offset to bytes. */
    4212                 :          0 :                 act_offset = (i + new_bank_offset) << 1;
    4213                 :            : 
    4214                 :          0 :                 usec_delay(100);
    4215                 :            : 
    4216                 :            :                 /* Write the bytes to the new bank. */
    4217                 :          0 :                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
    4218                 :            :                                                                act_offset,
    4219                 :          0 :                                                                (u8)data);
    4220         [ #  # ]:          0 :                 if (ret_val)
    4221                 :            :                         break;
    4222                 :            : 
    4223                 :          0 :                 usec_delay(100);
    4224                 :          0 :                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
    4225                 :            :                                                           act_offset + 1,
    4226                 :          0 :                                                           (u8)(data >> 8));
    4227         [ #  # ]:          0 :                 if (ret_val)
    4228                 :            :                         break;
    4229                 :            :         }
    4230                 :            : 
    4231                 :            :         /* Don't bother writing the segment valid bits if sector
    4232                 :            :          * programming failed.
    4233                 :            :          */
    4234         [ #  # ]:          0 :         if (ret_val) {
    4235                 :          0 :                 DEBUGOUT("Flash commit failed.\n");
    4236                 :          0 :                 goto release;
    4237                 :            :         }
    4238                 :            : 
    4239                 :            :         /* Finally validate the new segment by setting bit 15:14
    4240                 :            :          * to 10b in word 0x13 , this can be done without an
    4241                 :            :          * erase as well since these bits are 11 to start with
    4242                 :            :          * and we need to change bit 14 to 0b
    4243                 :            :          */
    4244                 :          0 :         act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
    4245                 :          0 :         ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
    4246         [ #  # ]:          0 :         if (ret_val)
    4247                 :          0 :                 goto release;
    4248                 :            : 
    4249                 :          0 :         data &= 0xBFFF;
    4250                 :          0 :         ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset * 2 + 1,
    4251                 :          0 :                                                        (u8)(data >> 8));
    4252         [ #  # ]:          0 :         if (ret_val)
    4253                 :          0 :                 goto release;
    4254                 :            : 
    4255                 :            :         /* And invalidate the previously valid segment by setting
    4256                 :            :          * its signature word (0x13) high_byte to 0b. This can be
    4257                 :            :          * done without an erase because flash erase sets all bits
    4258                 :            :          * to 1's. We can write 1's to 0's without an erase
    4259                 :            :          */
    4260                 :          0 :         act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
    4261                 :            : 
    4262                 :          0 :         ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
    4263                 :            : 
    4264         [ #  # ]:          0 :         if (ret_val)
    4265                 :          0 :                 goto release;
    4266                 :            : 
    4267                 :            :         /* Great!  Everything worked, we can now clear the cached entries. */
    4268         [ #  # ]:          0 :         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
    4269                 :          0 :                 dev_spec->shadow_ram[i].modified = false;
    4270                 :          0 :                 dev_spec->shadow_ram[i].value = 0xFFFF;
    4271                 :            :         }
    4272                 :            : 
    4273                 :          0 : release:
    4274                 :          0 :         nvm->ops.release(hw);
    4275                 :            : 
    4276                 :            :         /* Reload the EEPROM, or else modifications will not appear
    4277                 :            :          * until after the next adapter reset.
    4278                 :            :          */
    4279         [ #  # ]:          0 :         if (!ret_val) {
    4280                 :          0 :                 nvm->ops.reload(hw);
    4281                 :          0 :                 msec_delay(10);
    4282                 :            :         }
    4283                 :            : 
    4284                 :          0 : out:
    4285         [ #  # ]:          0 :         if (ret_val)
    4286                 :          0 :                 DEBUGOUT1("NVM update error: %d\n", ret_val);
    4287                 :            : 
    4288                 :          0 :         return ret_val;
    4289                 :            : }
    4290                 :            : 
    4291                 :            : /**
    4292                 :            :  *  e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
    4293                 :            :  *  @hw: pointer to the HW structure
    4294                 :            :  *
    4295                 :            :  *  Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
    4296                 :            :  *  If the bit is 0, that the EEPROM had been modified, but the checksum was not
    4297                 :            :  *  calculated, in which case we need to calculate the checksum and set bit 6.
    4298                 :            :  **/
    4299                 :          0 : STATIC s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
    4300                 :            : {
    4301                 :            :         s32 ret_val;
    4302                 :            :         u16 data;
    4303                 :            :         u16 word;
    4304                 :            :         u16 valid_csum_mask;
    4305                 :            : 
    4306                 :          0 :         DEBUGFUNC("e1000_validate_nvm_checksum_ich8lan");
    4307                 :            : 
    4308                 :            :         /* Read NVM and check Invalid Image CSUM bit.  If this bit is 0,
    4309                 :            :          * the checksum needs to be fixed.  This bit is an indication that
    4310                 :            :          * the NVM was prepared by OEM software and did not calculate
    4311                 :            :          * the checksum...a likely scenario.
    4312                 :            :          */
    4313         [ #  # ]:          0 :         switch (hw->mac.type) {
    4314                 :            :         case e1000_pch_lpt:
    4315                 :            :         case e1000_pch_spt:
    4316                 :            :         case e1000_pch_cnp:
    4317                 :            :         case e1000_pch_adp:
    4318                 :            :                 word = NVM_COMPAT;
    4319                 :            :                 valid_csum_mask = NVM_COMPAT_VALID_CSUM;
    4320                 :            :                 break;
    4321                 :          0 :         default:
    4322                 :            :                 word = NVM_FUTURE_INIT_WORD1;
    4323                 :            :                 valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
    4324                 :          0 :                 break;
    4325                 :            :         }
    4326                 :            : 
    4327                 :          0 :         ret_val = hw->nvm.ops.read(hw, word, 1, &data);
    4328         [ #  # ]:          0 :         if (ret_val)
    4329                 :            :                 return ret_val;
    4330                 :            : 
    4331         [ #  # ]:          0 :         if (!(data & valid_csum_mask)) {
    4332                 :          0 :                 data |= valid_csum_mask;
    4333                 :          0 :                 ret_val = hw->nvm.ops.write(hw, word, 1, &data);
    4334         [ #  # ]:          0 :                 if (ret_val)
    4335                 :            :                         return ret_val;
    4336                 :          0 :                 ret_val = hw->nvm.ops.update(hw);
    4337         [ #  # ]:          0 :                 if (ret_val)
    4338                 :            :                         return ret_val;
    4339                 :            :         }
    4340                 :            : 
    4341                 :          0 :         return e1000_validate_nvm_checksum_generic(hw);
    4342                 :            : }
    4343                 :            : 
    4344                 :            : /**
    4345                 :            :  *  e1000_write_flash_data_ich8lan - Writes bytes to the NVM
    4346                 :            :  *  @hw: pointer to the HW structure
    4347                 :            :  *  @offset: The offset (in bytes) of the byte/word to read.
    4348                 :            :  *  @size: Size of data to read, 1=byte 2=word
    4349                 :            :  *  @data: The byte(s) to write to the NVM.
    4350                 :            :  *
    4351                 :            :  *  Writes one/two bytes to the NVM using the flash access registers.
    4352                 :            :  **/
    4353                 :          0 : STATIC s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
    4354                 :            :                                           u8 size, u16 data)
    4355                 :            : {
    4356                 :            :         union ich8_hws_flash_status hsfsts;
    4357                 :            :         union ich8_hws_flash_ctrl hsflctl;
    4358                 :            :         u32 flash_linear_addr;
    4359                 :            :         u32 flash_data = 0;
    4360                 :            :         s32 ret_val;
    4361                 :            :         u8 count = 0;
    4362                 :            : 
    4363                 :          0 :         DEBUGFUNC("e1000_write_ich8_data");
    4364                 :            : 
    4365         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt) {
    4366         [ #  # ]:          0 :                 if (size != 4 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
    4367                 :            :                         return -E1000_ERR_NVM;
    4368                 :            :         } else {
    4369   [ #  #  #  # ]:          0 :                 if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
    4370                 :            :                         return -E1000_ERR_NVM;
    4371                 :            :         }
    4372                 :            : 
    4373                 :          0 :         flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
    4374                 :          0 :                              hw->nvm.flash_base_addr);
    4375                 :            : 
    4376                 :            :         do {
    4377                 :          0 :                 usec_delay(1);
    4378                 :            :                 /* Steps */
    4379                 :          0 :                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
    4380         [ #  # ]:          0 :                 if (ret_val != E1000_SUCCESS)
    4381                 :            :                         break;
    4382                 :            :                 /* In SPT, This register is in Lan memory space, not
    4383                 :            :                  * flash.  Therefore, only 32 bit access is supported
    4384                 :            :                  */
    4385         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
    4386                 :          0 :                         hsflctl.regval =
    4387                 :          0 :                             E1000_READ_FLASH_REG(hw, ICH_FLASH_HSFSTS)>>16;
    4388                 :            :                 else
    4389                 :          0 :                         hsflctl.regval =
    4390                 :          0 :                             E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
    4391                 :            : 
    4392                 :            :                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
    4393                 :          0 :                 hsflctl.hsf_ctrl.fldbcount = size - 1;
    4394                 :          0 :                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
    4395                 :            :                 /* In SPT, This register is in Lan memory space,
    4396                 :            :                  * not flash.  Therefore, only 32 bit access is
    4397                 :            :                  * supported
    4398                 :            :                  */
    4399         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
    4400                 :          0 :                         E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    4401                 :            :                                               hsflctl.regval << 16);
    4402                 :            :                 else
    4403                 :          0 :                         E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL,
    4404                 :            :                                                 hsflctl.regval);
    4405                 :            : 
    4406                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
    4407                 :            : 
    4408         [ #  # ]:          0 :                 if (size == 1)
    4409                 :          0 :                         flash_data = (u32)data & 0x00FF;
    4410                 :            :                 else
    4411                 :          0 :                         flash_data = (u32)data;
    4412                 :            : 
    4413                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
    4414                 :            : 
    4415                 :            :                 /* check if FCERR is set to 1 , if set to 1, clear it
    4416                 :            :                  * and try the whole sequence a few more times else done
    4417                 :            :                  */
    4418                 :            :                 ret_val =
    4419                 :          0 :                     e1000_flash_cycle_ich8lan(hw,
    4420                 :            :                                               ICH_FLASH_WRITE_COMMAND_TIMEOUT);
    4421         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS)
    4422                 :            :                         break;
    4423                 :            : 
    4424                 :            :                 /* If we're here, then things are most likely
    4425                 :            :                  * completely hosed, but if the error condition
    4426                 :            :                  * is detected, it won't hurt to give it another
    4427                 :            :                  * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
    4428                 :            :                  */
    4429                 :          0 :                 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
    4430         [ #  # ]:          0 :                 if (hsfsts.hsf_status.flcerr)
    4431                 :            :                         /* Repeat for some time before giving up. */
    4432                 :          0 :                         continue;
    4433         [ #  # ]:          0 :                 if (!hsfsts.hsf_status.flcdone) {
    4434                 :          0 :                         DEBUGOUT("Timeout error - flash cycle did not complete.\n");
    4435                 :          0 :                         break;
    4436                 :            :                 }
    4437         [ #  # ]:          0 :         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
    4438                 :            : 
    4439                 :            :         return ret_val;
    4440                 :            : }
    4441                 :            : 
    4442                 :            : /**
    4443                 :            : *  e1000_write_flash_data32_ich8lan - Writes 4 bytes to the NVM
    4444                 :            : *  @hw: pointer to the HW structure
    4445                 :            : *  @offset: The offset (in bytes) of the dwords to read.
    4446                 :            : *  @data: The 4 bytes to write to the NVM.
    4447                 :            : *
    4448                 :            : *  Writes one/two/four bytes to the NVM using the flash access registers.
    4449                 :            : **/
    4450                 :          0 : STATIC s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
    4451                 :            :                                             u32 data)
    4452                 :            : {
    4453                 :            :         union ich8_hws_flash_status hsfsts;
    4454                 :            :         union ich8_hws_flash_ctrl hsflctl;
    4455                 :            :         u32 flash_linear_addr;
    4456                 :            :         s32 ret_val;
    4457                 :            :         u8 count = 0;
    4458                 :            : 
    4459                 :          0 :         DEBUGFUNC("e1000_write_flash_data32_ich8lan");
    4460                 :            : 
    4461         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_spt) {
    4462         [ #  # ]:          0 :                 if (offset > ICH_FLASH_LINEAR_ADDR_MASK)
    4463                 :            :                         return -E1000_ERR_NVM;
    4464                 :            :         }
    4465                 :          0 :         flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
    4466                 :          0 :                              hw->nvm.flash_base_addr);
    4467                 :            :         do {
    4468                 :          0 :                 usec_delay(1);
    4469                 :            :                 /* Steps */
    4470                 :          0 :                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
    4471         [ #  # ]:          0 :                 if (ret_val != E1000_SUCCESS)
    4472                 :            :                         break;
    4473                 :            : 
    4474                 :            :                 /* In SPT, This register is in Lan memory space, not
    4475                 :            :                  * flash.  Therefore, only 32 bit access is supported
    4476                 :            :                  */
    4477         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
    4478                 :          0 :                         hsflctl.regval = E1000_READ_FLASH_REG(hw,
    4479                 :            :                                                               ICH_FLASH_HSFSTS)
    4480                 :          0 :                                          >> 16;
    4481                 :            :                 else
    4482                 :          0 :                         hsflctl.regval = E1000_READ_FLASH_REG16(hw,
    4483                 :            :                                                               ICH_FLASH_HSFCTL);
    4484                 :            : 
    4485                 :          0 :                 hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
    4486                 :          0 :                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
    4487                 :            : 
    4488                 :            :                 /* In SPT, This register is in Lan memory space,
    4489                 :            :                  * not flash.  Therefore, only 32 bit access is
    4490                 :            :                  * supported
    4491                 :            :                  */
    4492         [ #  # ]:          0 :                 if (hw->mac.type >= e1000_pch_spt)
    4493                 :          0 :                         E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    4494                 :            :                                               hsflctl.regval << 16);
    4495                 :            :                 else
    4496                 :          0 :                         E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL,
    4497                 :            :                                                 hsflctl.regval);
    4498                 :            : 
    4499                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
    4500                 :            : 
    4501                 :          0 :                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FDATA0, data);
    4502                 :            : 
    4503                 :            :                 /* check if FCERR is set to 1 , if set to 1, clear it
    4504                 :            :                  * and try the whole sequence a few more times else done
    4505                 :            :                  */
    4506                 :          0 :                 ret_val = e1000_flash_cycle_ich8lan(hw,
    4507                 :            :                                                ICH_FLASH_WRITE_COMMAND_TIMEOUT);
    4508                 :            : 
    4509         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS)
    4510                 :            :                         break;
    4511                 :            : 
    4512                 :            :                 /* If we're here, then things are most likely
    4513                 :            :                  * completely hosed, but if the error condition
    4514                 :            :                  * is detected, it won't hurt to give it another
    4515                 :            :                  * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
    4516                 :            :                  */
    4517                 :          0 :                 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
    4518                 :            : 
    4519         [ #  # ]:          0 :                 if (hsfsts.hsf_status.flcerr)
    4520                 :            :                         /* Repeat for some time before giving up. */
    4521                 :          0 :                         continue;
    4522         [ #  # ]:          0 :                 if (!hsfsts.hsf_status.flcdone) {
    4523                 :          0 :                         DEBUGOUT("Timeout error - flash cycle did not complete.\n");
    4524                 :          0 :                         break;
    4525                 :            :                 }
    4526         [ #  # ]:          0 :         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
    4527                 :            : 
    4528                 :            :         return ret_val;
    4529                 :            : }
    4530                 :            : 
    4531                 :            : /**
    4532                 :            :  *  e1000_write_flash_byte_ich8lan - Write a single byte to NVM
    4533                 :            :  *  @hw: pointer to the HW structure
    4534                 :            :  *  @offset: The index of the byte to read.
    4535                 :            :  *  @data: The byte to write to the NVM.
    4536                 :            :  *
    4537                 :            :  *  Writes a single byte to the NVM using the flash access registers.
    4538                 :            :  **/
    4539                 :          0 : STATIC s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
    4540                 :            :                                           u8 data)
    4541                 :            : {
    4542                 :            :         u16 word = (u16)data;
    4543                 :            : 
    4544                 :          0 :         DEBUGFUNC("e1000_write_flash_byte_ich8lan");
    4545                 :            : 
    4546                 :          0 :         return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
    4547                 :            : }
    4548                 :            : 
    4549                 :            : /**
    4550                 :            : *  e1000_retry_write_flash_dword_ich8lan - Writes a dword to NVM
    4551                 :            : *  @hw: pointer to the HW structure
    4552                 :            : *  @offset: The offset of the word to write.
    4553                 :            : *  @dword: The dword to write to the NVM.
    4554                 :            : *
    4555                 :            : *  Writes a single dword to the NVM using the flash access registers.
    4556                 :            : *  Goes through a retry algorithm before giving up.
    4557                 :            : **/
    4558                 :          0 : STATIC s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
    4559                 :            :                                                  u32 offset, u32 dword)
    4560                 :            : {
    4561                 :            :         s32 ret_val;
    4562                 :            :         u16 program_retries;
    4563                 :            : 
    4564                 :          0 :         DEBUGFUNC("e1000_retry_write_flash_dword_ich8lan");
    4565                 :            : 
    4566                 :            :         /* Must convert word offset into bytes. */
    4567                 :          0 :         offset <<= 1;
    4568                 :            : 
    4569                 :          0 :         ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
    4570                 :            : 
    4571         [ #  # ]:          0 :         if (!ret_val)
    4572                 :            :                 return ret_val;
    4573         [ #  # ]:          0 :         for (program_retries = 0; program_retries < 100; program_retries++) {
    4574                 :          0 :                 DEBUGOUT2("Retrying Byte %8.8X at offset %u\n", dword, offset);
    4575                 :          0 :                 usec_delay(100);
    4576                 :          0 :                 ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
    4577         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS)
    4578                 :            :                         break;
    4579                 :            :         }
    4580         [ #  # ]:          0 :         if (program_retries == 100)
    4581                 :          0 :                 return -E1000_ERR_NVM;
    4582                 :            : 
    4583                 :            :         return E1000_SUCCESS;
    4584                 :            : }
    4585                 :            : 
    4586                 :            : /**
    4587                 :            :  *  e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
    4588                 :            :  *  @hw: pointer to the HW structure
    4589                 :            :  *  @offset: The offset of the byte to write.
    4590                 :            :  *  @byte: The byte to write to the NVM.
    4591                 :            :  *
    4592                 :            :  *  Writes a single byte to the NVM using the flash access registers.
    4593                 :            :  *  Goes through a retry algorithm before giving up.
    4594                 :            :  **/
    4595                 :          0 : STATIC s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
    4596                 :            :                                                 u32 offset, u8 byte)
    4597                 :            : {
    4598                 :            :         s32 ret_val;
    4599                 :            :         u16 program_retries;
    4600                 :            : 
    4601                 :          0 :         DEBUGFUNC("e1000_retry_write_flash_byte_ich8lan");
    4602                 :            : 
    4603                 :          0 :         ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
    4604         [ #  # ]:          0 :         if (!ret_val)
    4605                 :            :                 return ret_val;
    4606                 :            : 
    4607         [ #  # ]:          0 :         for (program_retries = 0; program_retries < 100; program_retries++) {
    4608                 :          0 :                 DEBUGOUT2("Retrying Byte %2.2X at offset %u\n", byte, offset);
    4609                 :          0 :                 usec_delay(100);
    4610                 :          0 :                 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
    4611         [ #  # ]:          0 :                 if (ret_val == E1000_SUCCESS)
    4612                 :            :                         break;
    4613                 :            :         }
    4614         [ #  # ]:          0 :         if (program_retries == 100)
    4615                 :          0 :                 return -E1000_ERR_NVM;
    4616                 :            : 
    4617                 :            :         return E1000_SUCCESS;
    4618                 :            : }
    4619                 :            : 
    4620                 :            : /**
    4621                 :            :  *  e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
    4622                 :            :  *  @hw: pointer to the HW structure
    4623                 :            :  *  @bank: 0 for first bank, 1 for second bank, etc.
    4624                 :            :  *
    4625                 :            :  *  Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
    4626                 :            :  *  bank N is 4096 * N + flash_reg_addr.
    4627                 :            :  **/
    4628                 :          0 : STATIC s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
    4629                 :            : {
    4630                 :            :         struct e1000_nvm_info *nvm = &hw->nvm;
    4631                 :            :         union ich8_hws_flash_status hsfsts;
    4632                 :            :         union ich8_hws_flash_ctrl hsflctl;
    4633                 :            :         u32 flash_linear_addr;
    4634                 :            :         /* bank size is in 16bit words - adjust to bytes */
    4635                 :          0 :         u32 flash_bank_size = nvm->flash_bank_size * 2;
    4636                 :            :         s32 ret_val;
    4637                 :            :         s32 count = 0;
    4638                 :            :         s32 j, iteration, sector_size;
    4639                 :            : 
    4640                 :          0 :         DEBUGFUNC("e1000_erase_flash_bank_ich8lan");
    4641                 :            : 
    4642                 :          0 :         hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
    4643                 :            : 
    4644                 :            :         /* Determine HW Sector size: Read BERASE bits of hw flash status
    4645                 :            :          * register
    4646                 :            :          * 00: The Hw sector is 256 bytes, hence we need to erase 16
    4647                 :            :          *     consecutive sectors.  The start index for the nth Hw sector
    4648                 :            :          *     can be calculated as = bank * 4096 + n * 256
    4649                 :            :          * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
    4650                 :            :          *     The start index for the nth Hw sector can be calculated
    4651                 :            :          *     as = bank * 4096
    4652                 :            :          * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
    4653                 :            :          *     (ich9 only, otherwise error condition)
    4654                 :            :          * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
    4655                 :            :          */
    4656   [ #  #  #  #  :          0 :         switch (hsfsts.hsf_status.berasesz) {
                      # ]
    4657                 :          0 :         case 0:
    4658                 :            :                 /* Hw sector size 256 */
    4659                 :            :                 sector_size = ICH_FLASH_SEG_SIZE_256;
    4660                 :          0 :                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
    4661                 :          0 :                 break;
    4662                 :            :         case 1:
    4663                 :            :                 sector_size = ICH_FLASH_SEG_SIZE_4K;
    4664                 :            :                 iteration = 1;
    4665                 :            :                 break;
    4666                 :          0 :         case 2:
    4667                 :            :                 sector_size = ICH_FLASH_SEG_SIZE_8K;
    4668                 :            :                 iteration = 1;
    4669                 :          0 :                 break;
    4670                 :          0 :         case 3:
    4671                 :            :                 sector_size = ICH_FLASH_SEG_SIZE_64K;
    4672                 :            :                 iteration = 1;
    4673                 :          0 :                 break;
    4674                 :            :         default:
    4675                 :            :                 return -E1000_ERR_NVM;
    4676                 :            :         }
    4677                 :            : 
    4678                 :            :         /* Start with the base address, then add the sector offset. */
    4679                 :          0 :         flash_linear_addr = hw->nvm.flash_base_addr;
    4680         [ #  # ]:          0 :         flash_linear_addr += (bank) ? flash_bank_size : 0;
    4681                 :            : 
    4682         [ #  # ]:          0 :         for (j = 0; j < iteration; j++) {
    4683                 :            :                 do {
    4684                 :            :                         u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
    4685                 :            : 
    4686                 :            :                         /* Steps */
    4687                 :          0 :                         ret_val = e1000_flash_cycle_init_ich8lan(hw);
    4688         [ #  # ]:          0 :                         if (ret_val)
    4689                 :          0 :                                 return ret_val;
    4690                 :            : 
    4691                 :            :                         /* Write a value 11 (block Erase) in Flash
    4692                 :            :                          * Cycle field in hw flash control
    4693                 :            :                          */
    4694         [ #  # ]:          0 :                         if (hw->mac.type >= e1000_pch_spt)
    4695                 :          0 :                                 hsflctl.regval =
    4696                 :          0 :                                     E1000_READ_FLASH_REG(hw,
    4697                 :          0 :                                                          ICH_FLASH_HSFSTS)>>16;
    4698                 :            :                         else
    4699                 :          0 :                                 hsflctl.regval =
    4700                 :          0 :                                     E1000_READ_FLASH_REG16(hw,
    4701                 :            :                                                            ICH_FLASH_HSFCTL);
    4702                 :            : 
    4703                 :          0 :                         hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
    4704         [ #  # ]:          0 :                         if (hw->mac.type >= e1000_pch_spt)
    4705                 :          0 :                                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_HSFSTS,
    4706                 :            :                                                       hsflctl.regval << 16);
    4707                 :            :                         else
    4708                 :          0 :                                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL,
    4709                 :            :                                                         hsflctl.regval);
    4710                 :            : 
    4711                 :            :                         /* Write the last 24 bits of an index within the
    4712                 :            :                          * block into Flash Linear address field in Flash
    4713                 :            :                          * Address.
    4714                 :            :                          */
    4715                 :          0 :                         flash_linear_addr += (j * sector_size);
    4716                 :          0 :                         E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR,
    4717                 :            :                                               flash_linear_addr);
    4718                 :            : 
    4719                 :          0 :                         ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
    4720         [ #  # ]:          0 :                         if (ret_val == E1000_SUCCESS)
    4721                 :            :                                 break;
    4722                 :            : 
    4723                 :            :                         /* Check if FCERR is set to 1.  If 1,
    4724                 :            :                          * clear it and try the whole sequence
    4725                 :            :                          * a few more times else Done
    4726                 :            :                          */
    4727                 :          0 :                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
    4728                 :            :                                                       ICH_FLASH_HSFSTS);
    4729         [ #  # ]:          0 :                         if (hsfsts.hsf_status.flcerr)
    4730                 :            :                                 /* repeat for some time before giving up */
    4731                 :          0 :                                 continue;
    4732         [ #  # ]:          0 :                         else if (!hsfsts.hsf_status.flcdone)
    4733                 :          0 :                                 return ret_val;
    4734         [ #  # ]:          0 :                 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
    4735                 :            :         }
    4736                 :            : 
    4737                 :            :         return E1000_SUCCESS;
    4738                 :            : }
    4739                 :            : 
    4740                 :            : /**
    4741                 :            :  *  e1000_valid_led_default_ich8lan - Set the default LED settings
    4742                 :            :  *  @hw: pointer to the HW structure
    4743                 :            :  *  @data: Pointer to the LED settings
    4744                 :            :  *
    4745                 :            :  *  Reads the LED default settings from the NVM to data.  If the NVM LED
    4746                 :            :  *  settings is all 0's or F's, set the LED default to a valid LED default
    4747                 :            :  *  setting.
    4748                 :            :  **/
    4749                 :          0 : STATIC s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
    4750                 :            : {
    4751                 :            :         s32 ret_val;
    4752                 :            : 
    4753                 :          0 :         DEBUGFUNC("e1000_valid_led_default_ich8lan");
    4754                 :            : 
    4755                 :          0 :         ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
    4756         [ #  # ]:          0 :         if (ret_val) {
    4757                 :          0 :                 DEBUGOUT("NVM Read Error\n");
    4758                 :          0 :                 return ret_val;
    4759                 :            :         }
    4760                 :            : 
    4761         [ #  # ]:          0 :         if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
    4762                 :          0 :                 *data = ID_LED_DEFAULT_ICH8LAN;
    4763                 :            : 
    4764                 :            :         return E1000_SUCCESS;
    4765                 :            : }
    4766                 :            : 
    4767                 :            : /**
    4768                 :            :  *  e1000_id_led_init_pchlan - store LED configurations
    4769                 :            :  *  @hw: pointer to the HW structure
    4770                 :            :  *
    4771                 :            :  *  PCH does not control LEDs via the LEDCTL register, rather it uses
    4772                 :            :  *  the PHY LED configuration register.
    4773                 :            :  *
    4774                 :            :  *  PCH also does not have an "always on" or "always off" mode which
    4775                 :            :  *  complicates the ID feature.  Instead of using the "on" mode to indicate
    4776                 :            :  *  in ledctl_mode2 the LEDs to use for ID (see e1000_id_led_init_generic()),
    4777                 :            :  *  use "link_up" mode.  The LEDs will still ID on request if there is no
    4778                 :            :  *  link based on logic in e1000_led_[on|off]_pchlan().
    4779                 :            :  **/
    4780                 :          0 : STATIC s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
    4781                 :            : {
    4782                 :            :         struct e1000_mac_info *mac = &hw->mac;
    4783                 :            :         s32 ret_val;
    4784                 :            :         const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
    4785                 :            :         const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
    4786                 :            :         u16 data, i, temp, shift;
    4787                 :            : 
    4788                 :          0 :         DEBUGFUNC("e1000_id_led_init_pchlan");
    4789                 :            : 
    4790                 :            :         /* Get default ID LED modes */
    4791                 :          0 :         ret_val = hw->nvm.ops.valid_led_default(hw, &data);
    4792         [ #  # ]:          0 :         if (ret_val)
    4793                 :            :                 return ret_val;
    4794                 :            : 
    4795                 :          0 :         mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
    4796                 :          0 :         mac->ledctl_mode1 = mac->ledctl_default;
    4797                 :          0 :         mac->ledctl_mode2 = mac->ledctl_default;
    4798                 :            : 
    4799         [ #  # ]:          0 :         for (i = 0; i < 4; i++) {
    4800                 :          0 :                 temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
    4801                 :          0 :                 shift = (i * 5);
    4802      [ #  #  # ]:          0 :                 switch (temp) {
    4803                 :          0 :                 case ID_LED_ON1_DEF2:
    4804                 :            :                 case ID_LED_ON1_ON2:
    4805                 :            :                 case ID_LED_ON1_OFF2:
    4806                 :          0 :                         mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
    4807                 :          0 :                         mac->ledctl_mode1 |= (ledctl_on << shift);
    4808                 :          0 :                         break;
    4809                 :          0 :                 case ID_LED_OFF1_DEF2:
    4810                 :            :                 case ID_LED_OFF1_ON2:
    4811                 :            :                 case ID_LED_OFF1_OFF2:
    4812                 :          0 :                         mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
    4813                 :          0 :                         mac->ledctl_mode1 |= (ledctl_off << shift);
    4814                 :          0 :                         break;
    4815                 :            :                 default:
    4816                 :            :                         /* Do nothing */
    4817                 :            :                         break;
    4818                 :            :                 }
    4819      [ #  #  # ]:          0 :                 switch (temp) {
    4820                 :          0 :                 case ID_LED_DEF1_ON2:
    4821                 :            :                 case ID_LED_ON1_ON2:
    4822                 :            :                 case ID_LED_OFF1_ON2:
    4823                 :          0 :                         mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
    4824                 :          0 :                         mac->ledctl_mode2 |= (ledctl_on << shift);
    4825                 :          0 :                         break;
    4826                 :          0 :                 case ID_LED_DEF1_OFF2:
    4827                 :            :                 case ID_LED_ON1_OFF2:
    4828                 :            :                 case ID_LED_OFF1_OFF2:
    4829                 :          0 :                         mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
    4830                 :          0 :                         mac->ledctl_mode2 |= (ledctl_off << shift);
    4831                 :          0 :                         break;
    4832                 :            :                 default:
    4833                 :            :                         /* Do nothing */
    4834                 :            :                         break;
    4835                 :            :                 }
    4836                 :            :         }
    4837                 :            : 
    4838                 :            :         return E1000_SUCCESS;
    4839                 :            : }
    4840                 :            : 
    4841                 :            : /**
    4842                 :            :  *  e1000_get_bus_info_ich8lan - Get/Set the bus type and width
    4843                 :            :  *  @hw: pointer to the HW structure
    4844                 :            :  *
    4845                 :            :  *  ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
    4846                 :            :  *  register, so the bus width is hard coded.
    4847                 :            :  **/
    4848                 :          0 : STATIC s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
    4849                 :            : {
    4850                 :            :         struct e1000_bus_info *bus = &hw->bus;
    4851                 :            :         s32 ret_val;
    4852                 :            : 
    4853                 :          0 :         DEBUGFUNC("e1000_get_bus_info_ich8lan");
    4854                 :            : 
    4855                 :          0 :         ret_val = e1000_get_bus_info_pcie_generic(hw);
    4856                 :            : 
    4857                 :            :         /* ICH devices are "PCI Express"-ish.  They have
    4858                 :            :          * a configuration space, but do not contain
    4859                 :            :          * PCI Express Capability registers, so bus width
    4860                 :            :          * must be hardcoded.
    4861                 :            :          */
    4862         [ #  # ]:          0 :         if (bus->width == e1000_bus_width_unknown)
    4863                 :          0 :                 bus->width = e1000_bus_width_pcie_x1;
    4864                 :            : 
    4865                 :          0 :         return ret_val;
    4866                 :            : }
    4867                 :            : 
    4868                 :            : /**
    4869                 :            :  *  e1000_reset_hw_ich8lan - Reset the hardware
    4870                 :            :  *  @hw: pointer to the HW structure
    4871                 :            :  *
    4872                 :            :  *  Does a full reset of the hardware which includes a reset of the PHY and
    4873                 :            :  *  MAC.
    4874                 :            :  **/
    4875                 :          0 : STATIC s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
    4876                 :            : {
    4877                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    4878                 :            :         u16 kum_cfg;
    4879                 :            :         u32 ctrl, reg;
    4880                 :            :         s32 ret_val;
    4881                 :            :         u16 pci_cfg;
    4882                 :            : 
    4883                 :          0 :         DEBUGFUNC("e1000_reset_hw_ich8lan");
    4884                 :            : 
    4885                 :            :         /* Prevent the PCI-E bus from sticking if there is no TLP connection
    4886                 :            :          * on the last TLP read/write transaction when MAC is reset.
    4887                 :            :          */
    4888                 :          0 :         ret_val = e1000_disable_pcie_master_generic(hw);
    4889         [ #  # ]:          0 :         if (ret_val)
    4890                 :          0 :                 DEBUGOUT("PCI-E Master disable polling has failed.\n");
    4891                 :            : 
    4892                 :          0 :         DEBUGOUT("Masking off all interrupts\n");
    4893                 :          0 :         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
    4894                 :            : 
    4895                 :            :         /* Disable the Transmit and Receive units.  Then delay to allow
    4896                 :            :          * any pending transactions to complete before we hit the MAC
    4897                 :            :          * with the global reset.
    4898                 :            :          */
    4899                 :          0 :         E1000_WRITE_REG(hw, E1000_RCTL, 0);
    4900                 :          0 :         E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
    4901                 :          0 :         E1000_WRITE_FLUSH(hw);
    4902                 :            : 
    4903                 :          0 :         msec_delay(10);
    4904                 :            : 
    4905                 :            :         /* Workaround for ICH8 bit corruption issue in FIFO memory */
    4906         [ #  # ]:          0 :         if (hw->mac.type == e1000_ich8lan) {
    4907                 :            :                 /* Set Tx and Rx buffer allocation to 8k apiece. */
    4908                 :          0 :                 E1000_WRITE_REG(hw, E1000_PBA, E1000_PBA_8K);
    4909                 :            :                 /* Set Packet Buffer Size to 16k. */
    4910                 :          0 :                 E1000_WRITE_REG(hw, E1000_PBS, E1000_PBS_16K);
    4911                 :            :         }
    4912                 :            : 
    4913         [ #  # ]:          0 :         if (hw->mac.type == e1000_pchlan) {
    4914                 :            :                 /* Save the NVM K1 bit setting*/
    4915                 :          0 :                 ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
    4916         [ #  # ]:          0 :                 if (ret_val)
    4917                 :            :                         return ret_val;
    4918                 :            : 
    4919         [ #  # ]:          0 :                 if (kum_cfg & E1000_NVM_K1_ENABLE)
    4920                 :          0 :                         dev_spec->nvm_k1_enabled = true;
    4921                 :            :                 else
    4922                 :          0 :                         dev_spec->nvm_k1_enabled = false;
    4923                 :            :         }
    4924                 :            : 
    4925                 :          0 :         ctrl = E1000_READ_REG(hw, E1000_CTRL);
    4926                 :            : 
    4927         [ #  # ]:          0 :         if (!hw->phy.ops.check_reset_block(hw)) {
    4928                 :            :                 /* Full-chip reset requires MAC and PHY reset at the same
    4929                 :            :                  * time to make sure the interface between MAC and the
    4930                 :            :                  * external PHY is reset.
    4931                 :            :                  */
    4932                 :          0 :                 ctrl |= E1000_CTRL_PHY_RST;
    4933                 :            : 
    4934                 :            :                 /* Gate automatic PHY configuration by hardware on
    4935                 :            :                  * non-managed 82579
    4936                 :            :                  */
    4937         [ #  # ]:          0 :                 if ((hw->mac.type == e1000_pch2lan) &&
    4938         [ #  # ]:          0 :                     !(E1000_READ_REG(hw, E1000_FWSM) & E1000_ICH_FWSM_FW_VALID))
    4939                 :          0 :                         e1000_gate_hw_phy_config_ich8lan(hw, true);
    4940                 :            :         }
    4941                 :          0 :         ret_val = e1000_acquire_swflag_ich8lan(hw);
    4942                 :            : 
    4943                 :            :         /* Read from EXTCNF_CTRL in e1000_acquire_swflag_ich8lan function
    4944                 :            :          * may occur during global reset and cause system hang.
    4945                 :            :          * Configuration space access creates the needed delay.
    4946                 :            :          * Write to E1000_STRAP RO register E1000_PCI_VENDOR_ID_REGISTER value
    4947                 :            :          * insures configuration space read is done before global reset.
    4948                 :            :          */
    4949                 :          0 :         e1000_read_pci_cfg(hw, E1000_PCI_VENDOR_ID_REGISTER, &pci_cfg);
    4950                 :          0 :         E1000_WRITE_REG(hw, E1000_STRAP, pci_cfg);
    4951                 :          0 :         DEBUGOUT("Issuing a global reset to ich8lan\n");
    4952                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_RST));
    4953                 :            :         /* cannot issue a flush here because it hangs the hardware */
    4954                 :          0 :         msec_delay(20);
    4955                 :            : 
    4956                 :            :         /* Configuration space access improve HW level time sync mechanism.
    4957                 :            :          * Write to E1000_STRAP RO register E1000_PCI_VENDOR_ID_REGISTER
    4958                 :            :          * value to insure configuration space read is done
    4959                 :            :          * before any access to mac register.
    4960                 :            :          */
    4961                 :          0 :         e1000_read_pci_cfg(hw, E1000_PCI_VENDOR_ID_REGISTER, &pci_cfg);
    4962                 :          0 :         E1000_WRITE_REG(hw, E1000_STRAP, pci_cfg);
    4963                 :            : 
    4964                 :            :         /* Set Phy Config Counter to 50msec */
    4965         [ #  # ]:          0 :         if (hw->mac.type == e1000_pch2lan) {
    4966                 :          0 :                 reg = E1000_READ_REG(hw, E1000_FEXTNVM3);
    4967                 :          0 :                 reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
    4968                 :          0 :                 reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
    4969                 :          0 :                 E1000_WRITE_REG(hw, E1000_FEXTNVM3, reg);
    4970                 :            :         }
    4971                 :            : 
    4972         [ #  # ]:          0 :         if (!ret_val)
    4973                 :          0 :                 E1000_MUTEX_UNLOCK(&hw->dev_spec.ich8lan.swflag_mutex);
    4974                 :            : 
    4975         [ #  # ]:          0 :         if (ctrl & E1000_CTRL_PHY_RST) {
    4976                 :          0 :                 ret_val = hw->phy.ops.get_cfg_done(hw);
    4977         [ #  # ]:          0 :                 if (ret_val)
    4978                 :            :                         return ret_val;
    4979                 :            : 
    4980                 :          0 :                 ret_val = e1000_post_phy_reset_ich8lan(hw);
    4981         [ #  # ]:          0 :                 if (ret_val)
    4982                 :            :                         return ret_val;
    4983                 :            :         }
    4984                 :            : 
    4985                 :            :         /* For PCH, this write will make sure that any noise
    4986                 :            :          * will be detected as a CRC error and be dropped rather than show up
    4987                 :            :          * as a bad packet to the DMA engine.
    4988                 :            :          */
    4989         [ #  # ]:          0 :         if (hw->mac.type == e1000_pchlan)
    4990                 :          0 :                 E1000_WRITE_REG(hw, E1000_CRC_OFFSET, 0x65656565);
    4991                 :            : 
    4992                 :          0 :         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
    4993                 :          0 :         E1000_READ_REG(hw, E1000_ICR);
    4994                 :            : 
    4995                 :          0 :         reg = E1000_READ_REG(hw, E1000_KABGTXD);
    4996                 :          0 :         reg |= E1000_KABGTXD_BGSQLBIAS;
    4997                 :          0 :         E1000_WRITE_REG(hw, E1000_KABGTXD, reg);
    4998                 :            : 
    4999                 :          0 :         return E1000_SUCCESS;
    5000                 :            : }
    5001                 :            : 
    5002                 :            : /**
    5003                 :            :  *  e1000_init_hw_ich8lan - Initialize the hardware
    5004                 :            :  *  @hw: pointer to the HW structure
    5005                 :            :  *
    5006                 :            :  *  Prepares the hardware for transmit and receive by doing the following:
    5007                 :            :  *   - initialize hardware bits
    5008                 :            :  *   - initialize LED identification
    5009                 :            :  *   - setup receive address registers
    5010                 :            :  *   - setup flow control
    5011                 :            :  *   - setup transmit descriptors
    5012                 :            :  *   - clear statistics
    5013                 :            :  **/
    5014                 :          0 : STATIC s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
    5015                 :            : {
    5016                 :            :         struct e1000_mac_info *mac = &hw->mac;
    5017                 :            :         u32 ctrl_ext, txdctl, snoop;
    5018                 :            :         s32 ret_val;
    5019                 :            :         u16 i;
    5020                 :            : 
    5021                 :          0 :         DEBUGFUNC("e1000_init_hw_ich8lan");
    5022                 :            : 
    5023                 :          0 :         e1000_initialize_hw_bits_ich8lan(hw);
    5024                 :            : 
    5025                 :            :         /* Initialize identification LED */
    5026                 :          0 :         ret_val = mac->ops.id_led_init(hw);
    5027                 :            :         /* An error is not fatal and we should not stop init due to this */
    5028         [ #  # ]:          0 :         if (ret_val)
    5029                 :          0 :                 DEBUGOUT("Error initializing identification LED\n");
    5030                 :            : 
    5031                 :            :         /* Setup the receive address. */
    5032                 :          0 :         e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
    5033                 :            : 
    5034                 :            :         /* Zero out the Multicast HASH table */
    5035                 :          0 :         DEBUGOUT("Zeroing the MTA\n");
    5036         [ #  # ]:          0 :         for (i = 0; i < mac->mta_reg_count; i++)
    5037                 :          0 :                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
    5038                 :            : 
    5039                 :            :         /* The 82578 Rx buffer will stall if wakeup is enabled in host and
    5040                 :            :          * the ME.  Disable wakeup by clearing the host wakeup bit.
    5041                 :            :          * Reset the phy after disabling host wakeup to reset the Rx buffer.
    5042                 :            :          */
    5043         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_82578) {
    5044                 :          0 :                 hw->phy.ops.read_reg(hw, BM_PORT_GEN_CFG, &i);
    5045                 :          0 :                 i &= ~BM_WUC_HOST_WU_BIT;
    5046                 :          0 :                 hw->phy.ops.write_reg(hw, BM_PORT_GEN_CFG, i);
    5047                 :          0 :                 ret_val = e1000_phy_hw_reset_ich8lan(hw);
    5048         [ #  # ]:          0 :                 if (ret_val)
    5049                 :            :                         return ret_val;
    5050                 :            :         }
    5051                 :            : 
    5052                 :            :         /* Setup link and flow control */
    5053                 :          0 :         ret_val = mac->ops.setup_link(hw);
    5054                 :            : 
    5055                 :            :         /* Set the transmit descriptor write-back policy for both queues */
    5056                 :          0 :         txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
    5057                 :            :         txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
    5058                 :            :                   E1000_TXDCTL_FULL_TX_DESC_WB);
    5059                 :          0 :         txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
    5060                 :            :                   E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
    5061                 :          0 :         E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
    5062                 :          0 :         txdctl = E1000_READ_REG(hw, E1000_TXDCTL(1));
    5063                 :            :         txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
    5064                 :            :                   E1000_TXDCTL_FULL_TX_DESC_WB);
    5065                 :          0 :         txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
    5066                 :            :                   E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
    5067                 :          0 :         E1000_WRITE_REG(hw, E1000_TXDCTL(1), txdctl);
    5068                 :            : 
    5069                 :            :         /* ICH8 has opposite polarity of no_snoop bits.
    5070                 :            :          * By default, we should use snoop behavior.
    5071                 :            :          */
    5072         [ #  # ]:          0 :         if (mac->type == e1000_ich8lan)
    5073                 :            :                 snoop = PCIE_ICH8_SNOOP_ALL;
    5074                 :            :         else
    5075                 :            :                 snoop = (u32) ~(PCIE_NO_SNOOP_ALL);
    5076                 :          0 :         e1000_set_pcie_no_snoop_generic(hw, snoop);
    5077                 :            : 
    5078                 :          0 :         ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
    5079                 :          0 :         ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
    5080                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
    5081                 :            : 
    5082                 :            :         /* Clear all of the statistics registers (clear on read).  It is
    5083                 :            :          * important that we do this after we have tried to establish link
    5084                 :            :          * because the symbol error count will increment wildly if there
    5085                 :            :          * is no link.
    5086                 :            :          */
    5087                 :          0 :         e1000_clear_hw_cntrs_ich8lan(hw);
    5088                 :            : 
    5089                 :          0 :         return ret_val;
    5090                 :            : }
    5091                 :            : 
    5092                 :            : /**
    5093                 :            :  *  e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
    5094                 :            :  *  @hw: pointer to the HW structure
    5095                 :            :  *
    5096                 :            :  *  Sets/Clears required hardware bits necessary for correctly setting up the
    5097                 :            :  *  hardware for transmit and receive.
    5098                 :            :  **/
    5099                 :          0 : STATIC void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
    5100                 :            : {
    5101                 :            :         u32 reg;
    5102                 :            : 
    5103                 :          0 :         DEBUGFUNC("e1000_initialize_hw_bits_ich8lan");
    5104                 :            : 
    5105                 :            :         /* Extended Device Control */
    5106                 :          0 :         reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
    5107                 :          0 :         reg |= (1 << 22);
    5108                 :            :         /* Enable PHY low-power state when MAC is at D3 w/o WoL */
    5109         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pchlan)
    5110                 :          0 :                 reg |= E1000_CTRL_EXT_PHYPDEN;
    5111                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
    5112                 :            : 
    5113                 :            :         /* Transmit Descriptor Control 0 */
    5114                 :          0 :         reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
    5115                 :          0 :         reg |= (1 << 22);
    5116                 :          0 :         E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
    5117                 :            : 
    5118                 :            :         /* Transmit Descriptor Control 1 */
    5119                 :          0 :         reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
    5120                 :          0 :         reg |= (1 << 22);
    5121                 :          0 :         E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
    5122                 :            : 
    5123                 :            :         /* Transmit Arbitration Control 0 */
    5124                 :          0 :         reg = E1000_READ_REG(hw, E1000_TARC(0));
    5125         [ #  # ]:          0 :         if (hw->mac.type == e1000_ich8lan)
    5126                 :          0 :                 reg |= (1 << 28) | (1 << 29);
    5127                 :          0 :         reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
    5128                 :          0 :         E1000_WRITE_REG(hw, E1000_TARC(0), reg);
    5129                 :            : 
    5130                 :            :         /* Transmit Arbitration Control 1 */
    5131                 :          0 :         reg = E1000_READ_REG(hw, E1000_TARC(1));
    5132         [ #  # ]:          0 :         if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
    5133                 :          0 :                 reg &= ~(1 << 28);
    5134                 :            :         else
    5135                 :          0 :                 reg |= (1 << 28);
    5136                 :          0 :         reg |= (1 << 24) | (1 << 26) | (1 << 30);
    5137                 :          0 :         E1000_WRITE_REG(hw, E1000_TARC(1), reg);
    5138                 :            : 
    5139                 :            :         /* Device Status */
    5140         [ #  # ]:          0 :         if (hw->mac.type == e1000_ich8lan) {
    5141                 :          0 :                 reg = E1000_READ_REG(hw, E1000_STATUS);
    5142                 :          0 :                 reg &= ~(1U << 31);
    5143                 :          0 :                 E1000_WRITE_REG(hw, E1000_STATUS, reg);
    5144                 :            :         }
    5145                 :            : 
    5146                 :            :         /* work-around descriptor data corruption issue during nfs v2 udp
    5147                 :            :          * traffic, just disable the nfs filtering capability
    5148                 :            :          */
    5149                 :          0 :         reg = E1000_READ_REG(hw, E1000_RFCTL);
    5150                 :          0 :         reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
    5151                 :            : 
    5152                 :            :         /* Disable IPv6 extension header parsing because some malformed
    5153                 :            :          * IPv6 headers can hang the Rx.
    5154                 :            :          */
    5155         [ #  # ]:          0 :         if (hw->mac.type == e1000_ich8lan)
    5156                 :          0 :                 reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
    5157                 :          0 :         E1000_WRITE_REG(hw, E1000_RFCTL, reg);
    5158                 :            : 
    5159                 :            :         /* Enable ECC on Lynxpoint */
    5160         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pch_lpt) {
    5161                 :          0 :                 reg = E1000_READ_REG(hw, E1000_PBECCSTS);
    5162                 :          0 :                 reg |= E1000_PBECCSTS_ECC_ENABLE;
    5163                 :          0 :                 E1000_WRITE_REG(hw, E1000_PBECCSTS, reg);
    5164                 :            : 
    5165                 :          0 :                 reg = E1000_READ_REG(hw, E1000_CTRL);
    5166                 :          0 :                 reg |= E1000_CTRL_MEHE;
    5167                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL, reg);
    5168                 :            :         }
    5169                 :            : 
    5170                 :          0 :         return;
    5171                 :            : }
    5172                 :            : 
    5173                 :            : /**
    5174                 :            :  *  e1000_setup_link_ich8lan - Setup flow control and link settings
    5175                 :            :  *  @hw: pointer to the HW structure
    5176                 :            :  *
    5177                 :            :  *  Determines which flow control settings to use, then configures flow
    5178                 :            :  *  control.  Calls the appropriate media-specific link configuration
    5179                 :            :  *  function.  Assuming the adapter has a valid link partner, a valid link
    5180                 :            :  *  should be established.  Assumes the hardware has previously been reset
    5181                 :            :  *  and the transmitter and receiver are not enabled.
    5182                 :            :  **/
    5183                 :          0 : STATIC s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
    5184                 :            : {
    5185                 :            :         s32 ret_val;
    5186                 :            : 
    5187                 :          0 :         DEBUGFUNC("e1000_setup_link_ich8lan");
    5188                 :            : 
    5189                 :            :         /* ICH parts do not have a word in the NVM to determine
    5190                 :            :          * the default flow control setting, so we explicitly
    5191                 :            :          * set it to full.
    5192                 :            :          */
    5193         [ #  # ]:          0 :         if (hw->fc.requested_mode == e1000_fc_default)
    5194                 :          0 :                 hw->fc.requested_mode = e1000_fc_full;
    5195                 :            : 
    5196                 :            :         /* Save off the requested flow control mode for use later.  Depending
    5197                 :            :          * on the link partner's capabilities, we may or may not use this mode.
    5198                 :            :          */
    5199                 :          0 :         hw->fc.current_mode = hw->fc.requested_mode;
    5200                 :            : 
    5201                 :          0 :         DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
    5202                 :            :                 hw->fc.current_mode);
    5203                 :            : 
    5204         [ #  # ]:          0 :         if (!hw->phy.ops.check_reset_block(hw)) {
    5205                 :            :                 /* Continue to configure the copper link. */
    5206                 :          0 :                 ret_val = hw->mac.ops.setup_physical_interface(hw);
    5207         [ #  # ]:          0 :                 if (ret_val)
    5208                 :            :                         return ret_val;
    5209                 :            :         }
    5210                 :            : 
    5211                 :          0 :         E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
    5212         [ #  # ]:          0 :         if ((hw->phy.type == e1000_phy_82578) ||
    5213         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_82579) ||
    5214         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_i217) ||
    5215                 :            :             (hw->phy.type == e1000_phy_82577)) {
    5216                 :          0 :                 E1000_WRITE_REG(hw, E1000_FCRTV_PCH, hw->fc.refresh_time);
    5217                 :            : 
    5218                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw,
    5219                 :            :                                              PHY_REG(BM_PORT_CTRL_PAGE, 27),
    5220                 :          0 :                                              hw->fc.pause_time);
    5221         [ #  # ]:          0 :                 if (ret_val)
    5222                 :            :                         return ret_val;
    5223                 :            :         }
    5224                 :            : 
    5225                 :          0 :         return e1000_set_fc_watermarks_generic(hw);
    5226                 :            : }
    5227                 :            : 
    5228                 :            : /**
    5229                 :            :  *  e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
    5230                 :            :  *  @hw: pointer to the HW structure
    5231                 :            :  *
    5232                 :            :  *  Configures the kumeran interface to the PHY to wait the appropriate time
    5233                 :            :  *  when polling the PHY, then call the generic setup_copper_link to finish
    5234                 :            :  *  configuring the copper link.
    5235                 :            :  **/
    5236                 :          0 : STATIC s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
    5237                 :            : {
    5238                 :            :         u32 ctrl;
    5239                 :            :         s32 ret_val;
    5240                 :            :         u16 reg_data;
    5241                 :            : 
    5242                 :          0 :         DEBUGFUNC("e1000_setup_copper_link_ich8lan");
    5243                 :            : 
    5244                 :          0 :         ctrl = E1000_READ_REG(hw, E1000_CTRL);
    5245                 :            :         ctrl |= E1000_CTRL_SLU;
    5246                 :          0 :         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
    5247                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
    5248                 :            : 
    5249                 :            :         /* Set the mac to wait the maximum time between each iteration
    5250                 :            :          * and increase the max iterations when polling the phy;
    5251                 :            :          * this fixes erroneous timeouts at 10Mbps.
    5252                 :            :          */
    5253                 :          0 :         ret_val = e1000_write_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_TIMEOUTS,
    5254                 :            :                                                0xFFFF);
    5255         [ #  # ]:          0 :         if (ret_val)
    5256                 :            :                 return ret_val;
    5257                 :          0 :         ret_val = e1000_read_kmrn_reg_generic(hw,
    5258                 :            :                                               E1000_KMRNCTRLSTA_INBAND_PARAM,
    5259                 :            :                                               &reg_data);
    5260         [ #  # ]:          0 :         if (ret_val)
    5261                 :            :                 return ret_val;
    5262                 :          0 :         reg_data |= 0x3F;
    5263                 :          0 :         ret_val = e1000_write_kmrn_reg_generic(hw,
    5264                 :            :                                                E1000_KMRNCTRLSTA_INBAND_PARAM,
    5265                 :            :                                                reg_data);
    5266         [ #  # ]:          0 :         if (ret_val)
    5267                 :            :                 return ret_val;
    5268                 :            : 
    5269   [ #  #  #  #  :          0 :         switch (hw->phy.type) {
                      # ]
    5270                 :          0 :         case e1000_phy_igp_3:
    5271                 :          0 :                 ret_val = e1000_copper_link_setup_igp(hw);
    5272         [ #  # ]:          0 :                 if (ret_val)
    5273                 :            :                         return ret_val;
    5274                 :            :                 break;
    5275                 :          0 :         case e1000_phy_bm:
    5276                 :            :         case e1000_phy_82578:
    5277                 :          0 :                 ret_val = e1000_copper_link_setup_m88(hw);
    5278         [ #  # ]:          0 :                 if (ret_val)
    5279                 :            :                         return ret_val;
    5280                 :            :                 break;
    5281                 :          0 :         case e1000_phy_82577:
    5282                 :            :         case e1000_phy_82579:
    5283                 :          0 :                 ret_val = e1000_copper_link_setup_82577(hw);
    5284         [ #  # ]:          0 :                 if (ret_val)
    5285                 :            :                         return ret_val;
    5286                 :            :                 break;
    5287                 :          0 :         case e1000_phy_ife:
    5288                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, IFE_PHY_MDIX_CONTROL,
    5289                 :            :                                                &reg_data);
    5290         [ #  # ]:          0 :                 if (ret_val)
    5291                 :            :                         return ret_val;
    5292                 :            : 
    5293                 :          0 :                 reg_data &= ~IFE_PMC_AUTO_MDIX;
    5294                 :            : 
    5295      [ #  #  # ]:          0 :                 switch (hw->phy.mdix) {
    5296                 :          0 :                 case 1:
    5297                 :          0 :                         reg_data &= ~IFE_PMC_FORCE_MDIX;
    5298                 :          0 :                         break;
    5299                 :          0 :                 case 2:
    5300                 :          0 :                         reg_data |= IFE_PMC_FORCE_MDIX;
    5301                 :          0 :                         break;
    5302                 :          0 :                 case 0:
    5303                 :            :                 default:
    5304                 :          0 :                         reg_data |= IFE_PMC_AUTO_MDIX;
    5305                 :          0 :                         break;
    5306                 :            :                 }
    5307                 :          0 :                 ret_val = hw->phy.ops.write_reg(hw, IFE_PHY_MDIX_CONTROL,
    5308                 :            :                                                 reg_data);
    5309         [ #  # ]:          0 :                 if (ret_val)
    5310                 :            :                         return ret_val;
    5311                 :            :                 break;
    5312                 :            :         default:
    5313                 :            :                 break;
    5314                 :            :         }
    5315                 :            : 
    5316                 :          0 :         return e1000_setup_copper_link_generic(hw);
    5317                 :            : }
    5318                 :            : 
    5319                 :            : /**
    5320                 :            :  *  e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
    5321                 :            :  *  @hw: pointer to the HW structure
    5322                 :            :  *
    5323                 :            :  *  Calls the PHY specific link setup function and then calls the
    5324                 :            :  *  generic setup_copper_link to finish configuring the link for
    5325                 :            :  *  Lynxpoint PCH devices
    5326                 :            :  **/
    5327                 :          0 : STATIC s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
    5328                 :            : {
    5329                 :            :         u32 ctrl;
    5330                 :            :         s32 ret_val;
    5331                 :            : 
    5332                 :          0 :         DEBUGFUNC("e1000_setup_copper_link_pch_lpt");
    5333                 :            : 
    5334                 :          0 :         ctrl = E1000_READ_REG(hw, E1000_CTRL);
    5335                 :            :         ctrl |= E1000_CTRL_SLU;
    5336                 :          0 :         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
    5337                 :          0 :         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
    5338                 :            : 
    5339                 :          0 :         ret_val = e1000_copper_link_setup_82577(hw);
    5340         [ #  # ]:          0 :         if (ret_val)
    5341                 :            :                 return ret_val;
    5342                 :            : 
    5343                 :          0 :         return e1000_setup_copper_link_generic(hw);
    5344                 :            : }
    5345                 :            : 
    5346                 :            : /**
    5347                 :            :  *  e1000_get_link_up_info_ich8lan - Get current link speed and duplex
    5348                 :            :  *  @hw: pointer to the HW structure
    5349                 :            :  *  @speed: pointer to store current link speed
    5350                 :            :  *  @duplex: pointer to store the current link duplex
    5351                 :            :  *
    5352                 :            :  *  Calls the generic get_speed_and_duplex to retrieve the current link
    5353                 :            :  *  information and then calls the Kumeran lock loss workaround for links at
    5354                 :            :  *  gigabit speeds.
    5355                 :            :  **/
    5356                 :          0 : STATIC s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
    5357                 :            :                                           u16 *duplex)
    5358                 :            : {
    5359                 :            :         s32 ret_val;
    5360                 :            : 
    5361                 :          0 :         DEBUGFUNC("e1000_get_link_up_info_ich8lan");
    5362                 :            : 
    5363                 :          0 :         ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed, duplex);
    5364         [ #  # ]:          0 :         if (ret_val)
    5365                 :            :                 return ret_val;
    5366                 :            : 
    5367         [ #  # ]:          0 :         if ((hw->mac.type == e1000_ich8lan) &&
    5368         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_igp_3) &&
    5369         [ #  # ]:          0 :             (*speed == SPEED_1000)) {
    5370                 :          0 :                 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
    5371                 :            :         }
    5372                 :            : 
    5373                 :            :         return ret_val;
    5374                 :            : }
    5375                 :            : 
    5376                 :            : /**
    5377                 :            :  *  e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
    5378                 :            :  *  @hw: pointer to the HW structure
    5379                 :            :  *
    5380                 :            :  *  Work-around for 82566 Kumeran PCS lock loss:
    5381                 :            :  *  On link status change (i.e. PCI reset, speed change) and link is up and
    5382                 :            :  *  speed is gigabit-
    5383                 :            :  *    0) if workaround is optionally disabled do nothing
    5384                 :            :  *    1) wait 1ms for Kumeran link to come up
    5385                 :            :  *    2) check Kumeran Diagnostic register PCS lock loss bit
    5386                 :            :  *    3) if not set the link is locked (all is good), otherwise...
    5387                 :            :  *    4) reset the PHY
    5388                 :            :  *    5) repeat up to 10 times
    5389                 :            :  *  Note: this is only called for IGP3 copper when speed is 1gb.
    5390                 :            :  **/
    5391                 :          0 : STATIC s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
    5392                 :            : {
    5393                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    5394                 :            :         u32 phy_ctrl;
    5395                 :            :         s32 ret_val;
    5396                 :            :         u16 i, data;
    5397                 :            :         bool link;
    5398                 :            : 
    5399                 :          0 :         DEBUGFUNC("e1000_kmrn_lock_loss_workaround_ich8lan");
    5400                 :            : 
    5401         [ #  # ]:          0 :         if (!dev_spec->kmrn_lock_loss_workaround_enabled)
    5402                 :            :                 return E1000_SUCCESS;
    5403                 :            : 
    5404                 :            :         /* Make sure link is up before proceeding.  If not just return.
    5405                 :            :          * Attempting this while link is negotiating fouled up link
    5406                 :            :          * stability
    5407                 :            :          */
    5408                 :          0 :         ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
    5409         [ #  # ]:          0 :         if (!link)
    5410                 :            :                 return E1000_SUCCESS;
    5411                 :            : 
    5412         [ #  # ]:          0 :         for (i = 0; i < 10; i++) {
    5413                 :            :                 /* read once to clear */
    5414                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
    5415         [ #  # ]:          0 :                 if (ret_val)
    5416                 :          0 :                         return ret_val;
    5417                 :            :                 /* and again to get new status */
    5418                 :          0 :                 ret_val = hw->phy.ops.read_reg(hw, IGP3_KMRN_DIAG, &data);
    5419         [ #  # ]:          0 :                 if (ret_val)
    5420                 :          0 :                         return ret_val;
    5421                 :            : 
    5422                 :            :                 /* check for PCS lock */
    5423         [ #  # ]:          0 :                 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
    5424                 :            :                         return E1000_SUCCESS;
    5425                 :            : 
    5426                 :            :                 /* Issue PHY reset */
    5427                 :          0 :                 hw->phy.ops.reset(hw);
    5428                 :          0 :                 msec_delay_irq(5);
    5429                 :            :         }
    5430                 :            :         /* Disable GigE link negotiation */
    5431                 :          0 :         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
    5432                 :          0 :         phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
    5433                 :            :                      E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
    5434                 :          0 :         E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    5435                 :            : 
    5436                 :            :         /* Call gig speed drop workaround on Gig disable before accessing
    5437                 :            :          * any PHY registers
    5438                 :            :          */
    5439                 :          0 :         e1000_gig_downshift_workaround_ich8lan(hw);
    5440                 :            : 
    5441                 :            :         /* unable to acquire PCS lock */
    5442                 :          0 :         return -E1000_ERR_PHY;
    5443                 :            : }
    5444                 :            : 
    5445                 :            : /**
    5446                 :            :  *  e1000_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
    5447                 :            :  *  @hw: pointer to the HW structure
    5448                 :            :  *  @state: boolean value used to set the current Kumeran workaround state
    5449                 :            :  *
    5450                 :            :  *  If ICH8, set the current Kumeran workaround state (enabled - true
    5451                 :            :  *  /disabled - false).
    5452                 :            :  **/
    5453                 :          0 : void e1000_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
    5454                 :            :                                                  bool state)
    5455                 :            : {
    5456                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    5457                 :            : 
    5458                 :          0 :         DEBUGFUNC("e1000_set_kmrn_lock_loss_workaround_ich8lan");
    5459                 :            : 
    5460         [ #  # ]:          0 :         if (hw->mac.type != e1000_ich8lan) {
    5461                 :          0 :                 DEBUGOUT("Workaround applies to ICH8 only.\n");
    5462                 :          0 :                 return;
    5463                 :            :         }
    5464                 :            : 
    5465                 :          0 :         dev_spec->kmrn_lock_loss_workaround_enabled = state;
    5466                 :            : 
    5467                 :          0 :         return;
    5468                 :            : }
    5469                 :            : 
    5470                 :            : /**
    5471                 :            :  *  e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
    5472                 :            :  *  @hw: pointer to the HW structure
    5473                 :            :  *
    5474                 :            :  *  Workaround for 82566 power-down on D3 entry:
    5475                 :            :  *    1) disable gigabit link
    5476                 :            :  *    2) write VR power-down enable
    5477                 :            :  *    3) read it back
    5478                 :            :  *  Continue if successful, else issue LCD reset and repeat
    5479                 :            :  **/
    5480                 :          0 : void e1000_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
    5481                 :            : {
    5482                 :            :         u32 reg;
    5483                 :            :         u16 data;
    5484                 :            :         u8  retry = 0;
    5485                 :            : 
    5486                 :          0 :         DEBUGFUNC("e1000_igp3_phy_powerdown_workaround_ich8lan");
    5487                 :            : 
    5488         [ #  # ]:          0 :         if (hw->phy.type != e1000_phy_igp_3)
    5489                 :          0 :                 return;
    5490                 :            : 
    5491                 :            :         /* Try the workaround twice (if needed) */
    5492                 :            :         do {
    5493                 :            :                 /* Disable link */
    5494                 :          0 :                 reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
    5495                 :          0 :                 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
    5496                 :            :                         E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
    5497                 :          0 :                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, reg);
    5498                 :            : 
    5499                 :            :                 /* Call gig speed drop workaround on Gig disable before
    5500                 :            :                  * accessing any PHY registers
    5501                 :            :                  */
    5502         [ #  # ]:          0 :                 if (hw->mac.type == e1000_ich8lan)
    5503                 :          0 :                         e1000_gig_downshift_workaround_ich8lan(hw);
    5504                 :            : 
    5505                 :            :                 /* Write VR power-down enable */
    5506                 :          0 :                 hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
    5507                 :          0 :                 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
    5508                 :          0 :                 hw->phy.ops.write_reg(hw, IGP3_VR_CTRL,
    5509                 :            :                                       data | IGP3_VR_CTRL_MODE_SHUTDOWN);
    5510                 :            : 
    5511                 :            :                 /* Read it back and test */
    5512                 :          0 :                 hw->phy.ops.read_reg(hw, IGP3_VR_CTRL, &data);
    5513                 :          0 :                 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
    5514   [ #  #  #  # ]:          0 :                 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
    5515                 :            :                         break;
    5516                 :            : 
    5517                 :            :                 /* Issue PHY reset and repeat at most one more time */
    5518                 :          0 :                 reg = E1000_READ_REG(hw, E1000_CTRL);
    5519                 :          0 :                 E1000_WRITE_REG(hw, E1000_CTRL, reg | E1000_CTRL_PHY_RST);
    5520                 :            :                 retry++;
    5521                 :            :         } while (retry);
    5522                 :            : }
    5523                 :            : 
    5524                 :            : /**
    5525                 :            :  *  e1000_gig_downshift_workaround_ich8lan - WoL from S5 stops working
    5526                 :            :  *  @hw: pointer to the HW structure
    5527                 :            :  *
    5528                 :            :  *  Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
    5529                 :            :  *  LPLU, Gig disable, MDIC PHY reset):
    5530                 :            :  *    1) Set Kumeran Near-end loopback
    5531                 :            :  *    2) Clear Kumeran Near-end loopback
    5532                 :            :  *  Should only be called for ICH8[m] devices with any 1G Phy.
    5533                 :            :  **/
    5534                 :          0 : void e1000_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
    5535                 :            : {
    5536                 :            :         s32 ret_val;
    5537                 :          0 :         u16 reg_data = 0;
    5538                 :            : 
    5539                 :          0 :         DEBUGFUNC("e1000_gig_downshift_workaround_ich8lan");
    5540                 :            : 
    5541         [ #  # ]:          0 :         if ((hw->mac.type != e1000_ich8lan) ||
    5542         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_ife))
    5543                 :          0 :                 return;
    5544                 :            : 
    5545                 :          0 :         ret_val = e1000_read_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
    5546                 :            :                                               &reg_data);
    5547         [ #  # ]:          0 :         if (ret_val)
    5548                 :            :                 return;
    5549                 :          0 :         reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
    5550                 :          0 :         ret_val = e1000_write_kmrn_reg_generic(hw,
    5551                 :            :                                                E1000_KMRNCTRLSTA_DIAG_OFFSET,
    5552                 :            :                                                reg_data);
    5553         [ #  # ]:          0 :         if (ret_val)
    5554                 :            :                 return;
    5555                 :          0 :         reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
    5556                 :          0 :         e1000_write_kmrn_reg_generic(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
    5557                 :            :                                      reg_data);
    5558                 :            : }
    5559                 :            : 
    5560                 :            : /**
    5561                 :            :  *  e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
    5562                 :            :  *  @hw: pointer to the HW structure
    5563                 :            :  *
    5564                 :            :  *  During S0 to Sx transition, it is possible the link remains at gig
    5565                 :            :  *  instead of negotiating to a lower speed.  Before going to Sx, set
    5566                 :            :  *  'Gig Disable' to force link speed negotiation to a lower speed based on
    5567                 :            :  *  the LPLU setting in the NVM or custom setting.  For PCH and newer parts,
    5568                 :            :  *  the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
    5569                 :            :  *  needs to be written.
    5570                 :            :  *  Parts that support (and are linked to a partner which support) EEE in
    5571                 :            :  *  100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
    5572                 :            :  *  than 10Mbps w/o EEE.
    5573                 :            :  **/
    5574                 :          0 : void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
    5575                 :            : {
    5576                 :            :         struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
    5577                 :            :         u32 phy_ctrl;
    5578                 :            :         s32 ret_val;
    5579                 :            : 
    5580                 :          0 :         DEBUGFUNC("e1000_suspend_workarounds_ich8lan");
    5581                 :            : 
    5582                 :          0 :         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
    5583                 :          0 :         phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
    5584                 :            : 
    5585         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_i217) {
    5586                 :          0 :                 u16 phy_reg, device_id = hw->device_id;
    5587                 :            : 
    5588                 :          0 :                 if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
    5589                 :          0 :                     (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
    5590   [ #  #  #  # ]:          0 :                     (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
    5591                 :          0 :                     (device_id == E1000_DEV_ID_PCH_I218_V3) ||
    5592         [ #  # ]:          0 :                     (hw->mac.type >= e1000_pch_spt)) {
    5593                 :          0 :                         u32 fextnvm6 = E1000_READ_REG(hw, E1000_FEXTNVM6);
    5594                 :            : 
    5595                 :          0 :                         E1000_WRITE_REG(hw, E1000_FEXTNVM6,
    5596                 :            :                                         fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
    5597                 :            :                 }
    5598                 :            : 
    5599                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    5600         [ #  # ]:          0 :                 if (ret_val)
    5601                 :          0 :                         goto out;
    5602                 :            : 
    5603         [ #  # ]:          0 :                 if (!dev_spec->eee_disable) {
    5604                 :            :                         u16 eee_advert;
    5605                 :            : 
    5606                 :            :                         ret_val =
    5607                 :          0 :                             e1000_read_emi_reg_locked(hw,
    5608                 :            :                                                       I217_EEE_ADVERTISEMENT,
    5609                 :            :                                                       &eee_advert);
    5610         [ #  # ]:          0 :                         if (ret_val)
    5611                 :          0 :                                 goto release;
    5612                 :            : 
    5613                 :            :                         /* Disable LPLU if both link partners support 100BaseT
    5614                 :            :                          * EEE and 100Full is advertised on both ends of the
    5615                 :            :                          * link, and enable Auto Enable LPI since there will
    5616                 :            :                          * be no driver to enable LPI while in Sx.
    5617                 :            :                          */
    5618         [ #  # ]:          0 :                         if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
    5619         [ #  # ]:          0 :                             (dev_spec->eee_lp_ability &
    5620                 :          0 :                              I82579_EEE_100_SUPPORTED) &&
    5621         [ #  # ]:          0 :                             (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)) {
    5622                 :          0 :                                 phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
    5623                 :            :                                               E1000_PHY_CTRL_NOND0A_LPLU);
    5624                 :            : 
    5625                 :            :                                 /* Set Auto Enable LPI after link up */
    5626                 :          0 :                                 hw->phy.ops.read_reg_locked(hw,
    5627                 :            :                                                             I217_LPI_GPIO_CTRL,
    5628                 :            :                                                             &phy_reg);
    5629                 :          0 :                                 phy_reg |= I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
    5630                 :          0 :                                 hw->phy.ops.write_reg_locked(hw,
    5631                 :            :                                                              I217_LPI_GPIO_CTRL,
    5632                 :            :                                                              phy_reg);
    5633                 :            :                         }
    5634                 :            :                 }
    5635                 :            : 
    5636                 :            :                 /* For i217 Intel Rapid Start Technology support,
    5637                 :            :                  * when the system is going into Sx and no manageability engine
    5638                 :            :                  * is present, the driver must configure proxy to reset only on
    5639                 :            :                  * power good.  LPI (Low Power Idle) state must also reset only
    5640                 :            :                  * on power good, as well as the MTA (Multicast table array).
    5641                 :            :                  * The SMBus release must also be disabled on LCD reset.
    5642                 :            :                  */
    5643         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_FWSM) &
    5644                 :            :                       E1000_ICH_FWSM_FW_VALID)) {
    5645                 :            :                         /* Enable proxy to reset only on power good. */
    5646                 :          0 :                         hw->phy.ops.read_reg_locked(hw, I217_PROXY_CTRL,
    5647                 :            :                                                     &phy_reg);
    5648                 :          0 :                         phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
    5649                 :          0 :                         hw->phy.ops.write_reg_locked(hw, I217_PROXY_CTRL,
    5650                 :            :                                                      phy_reg);
    5651                 :            : 
    5652                 :            :                         /* Set bit enable LPI (EEE) to reset only on
    5653                 :            :                          * power good.
    5654                 :            :                         */
    5655                 :          0 :                         hw->phy.ops.read_reg_locked(hw, I217_SxCTRL, &phy_reg);
    5656                 :          0 :                         phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
    5657                 :          0 :                         hw->phy.ops.write_reg_locked(hw, I217_SxCTRL, phy_reg);
    5658                 :            : 
    5659                 :            :                         /* Disable the SMB release on LCD reset. */
    5660                 :          0 :                         hw->phy.ops.read_reg_locked(hw, I217_MEMPWR, &phy_reg);
    5661                 :          0 :                         phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
    5662                 :          0 :                         hw->phy.ops.write_reg_locked(hw, I217_MEMPWR, phy_reg);
    5663                 :            :                 }
    5664                 :            : 
    5665                 :            :                 /* Enable MTA to reset for Intel Rapid Start Technology
    5666                 :            :                  * Support
    5667                 :            :                  */
    5668                 :          0 :                 hw->phy.ops.read_reg_locked(hw, I217_CGFREG, &phy_reg);
    5669                 :          0 :                 phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
    5670                 :          0 :                 hw->phy.ops.write_reg_locked(hw, I217_CGFREG, phy_reg);
    5671                 :            : 
    5672                 :          0 : release:
    5673                 :          0 :                 hw->phy.ops.release(hw);
    5674                 :            :         }
    5675                 :          0 : out:
    5676                 :          0 :         E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
    5677                 :            : 
    5678         [ #  # ]:          0 :         if (hw->mac.type == e1000_ich8lan)
    5679                 :          0 :                 e1000_gig_downshift_workaround_ich8lan(hw);
    5680                 :            : 
    5681         [ #  # ]:          0 :         if (hw->mac.type >= e1000_pchlan) {
    5682                 :          0 :                 e1000_oem_bits_config_ich8lan(hw, false);
    5683                 :            : 
    5684                 :            :                 /* Reset PHY to activate OEM bits on 82577/8 */
    5685         [ #  # ]:          0 :                 if (hw->mac.type == e1000_pchlan)
    5686                 :          0 :                         e1000_phy_hw_reset_generic(hw);
    5687                 :            : 
    5688                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    5689         [ #  # ]:          0 :                 if (ret_val)
    5690                 :            :                         return;
    5691                 :          0 :                 e1000_write_smbus_addr(hw);
    5692                 :          0 :                 hw->phy.ops.release(hw);
    5693                 :            :         }
    5694                 :            : 
    5695                 :            :         return;
    5696                 :            : }
    5697                 :            : 
    5698                 :            : /**
    5699                 :            :  *  e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
    5700                 :            :  *  @hw: pointer to the HW structure
    5701                 :            :  *
    5702                 :            :  *  During Sx to S0 transitions on non-managed devices or managed devices
    5703                 :            :  *  on which PHY resets are not blocked, if the PHY registers cannot be
    5704                 :            :  *  accessed properly by the s/w toggle the LANPHYPC value to power cycle
    5705                 :            :  *  the PHY.
    5706                 :            :  *  On i217, setup Intel Rapid Start Technology.
    5707                 :            :  **/
    5708                 :          0 : u32 e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
    5709                 :            : {
    5710                 :            :         s32 ret_val;
    5711                 :            : 
    5712                 :          0 :         DEBUGFUNC("e1000_resume_workarounds_pchlan");
    5713         [ #  # ]:          0 :         if (hw->mac.type < e1000_pch2lan)
    5714                 :            :                 return E1000_SUCCESS;
    5715                 :            : 
    5716                 :          0 :         ret_val = e1000_init_phy_workarounds_pchlan(hw);
    5717         [ #  # ]:          0 :         if (ret_val) {
    5718                 :          0 :                 DEBUGOUT1("Failed to init PHY flow ret_val=%d\n", ret_val);
    5719                 :          0 :                 return ret_val;
    5720                 :            :         }
    5721                 :            : 
    5722                 :            :         /* For i217 Intel Rapid Start Technology support when the system
    5723                 :            :          * is transitioning from Sx and no manageability engine is present
    5724                 :            :          * configure SMBus to restore on reset, disable proxy, and enable
    5725                 :            :          * the reset on MTA (Multicast table array).
    5726                 :            :          */
    5727         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_i217) {
    5728                 :            :                 u16 phy_reg;
    5729                 :            : 
    5730                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    5731         [ #  # ]:          0 :                 if (ret_val) {
    5732                 :          0 :                         DEBUGOUT("Failed to setup iRST\n");
    5733                 :          0 :                         return ret_val;
    5734                 :            :                 }
    5735                 :            : 
    5736                 :            :                 /* Clear Auto Enable LPI after link up */
    5737                 :          0 :                 hw->phy.ops.read_reg_locked(hw, I217_LPI_GPIO_CTRL, &phy_reg);
    5738                 :          0 :                 phy_reg &= ~I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
    5739                 :          0 :                 hw->phy.ops.write_reg_locked(hw, I217_LPI_GPIO_CTRL, phy_reg);
    5740                 :            : 
    5741         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_FWSM) &
    5742                 :            :                     E1000_ICH_FWSM_FW_VALID)) {
    5743                 :            :                         /* Restore clear on SMB if no manageability engine
    5744                 :            :                          * is present
    5745                 :            :                          */
    5746                 :          0 :                         ret_val = hw->phy.ops.read_reg_locked(hw, I217_MEMPWR,
    5747                 :            :                                                               &phy_reg);
    5748         [ #  # ]:          0 :                         if (ret_val)
    5749                 :          0 :                                 goto release;
    5750                 :          0 :                         phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
    5751                 :          0 :                         hw->phy.ops.write_reg_locked(hw, I217_MEMPWR, phy_reg);
    5752                 :            : 
    5753                 :            :                         /* Disable Proxy */
    5754                 :          0 :                         hw->phy.ops.write_reg_locked(hw, I217_PROXY_CTRL, 0);
    5755                 :            :                 }
    5756                 :            :                 /* Enable reset on MTA */
    5757                 :          0 :                 ret_val = hw->phy.ops.read_reg_locked(hw, I217_CGFREG,
    5758                 :            :                                                       &phy_reg);
    5759         [ #  # ]:          0 :                 if (ret_val)
    5760                 :          0 :                         goto release;
    5761                 :          0 :                 phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
    5762                 :          0 :                 hw->phy.ops.write_reg_locked(hw, I217_CGFREG, phy_reg);
    5763                 :          0 : release:
    5764         [ #  # ]:          0 :                 if (ret_val)
    5765                 :          0 :                         DEBUGOUT1("Error %d in resume workarounds\n", ret_val);
    5766                 :          0 :                 hw->phy.ops.release(hw);
    5767                 :          0 :                 return ret_val;
    5768                 :            :         }
    5769                 :            :         return E1000_SUCCESS;
    5770                 :            : }
    5771                 :            : 
    5772                 :            : /**
    5773                 :            :  *  e1000_cleanup_led_ich8lan - Restore the default LED operation
    5774                 :            :  *  @hw: pointer to the HW structure
    5775                 :            :  *
    5776                 :            :  *  Return the LED back to the default configuration.
    5777                 :            :  **/
    5778                 :          0 : STATIC s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
    5779                 :            : {
    5780                 :          0 :         DEBUGFUNC("e1000_cleanup_led_ich8lan");
    5781                 :            : 
    5782         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_ife)
    5783                 :          0 :                 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
    5784                 :            :                                              0);
    5785                 :            : 
    5786                 :          0 :         E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
    5787                 :          0 :         return E1000_SUCCESS;
    5788                 :            : }
    5789                 :            : 
    5790                 :            : /**
    5791                 :            :  *  e1000_led_on_ich8lan - Turn LEDs on
    5792                 :            :  *  @hw: pointer to the HW structure
    5793                 :            :  *
    5794                 :            :  *  Turn on the LEDs.
    5795                 :            :  **/
    5796                 :          0 : STATIC s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
    5797                 :            : {
    5798                 :          0 :         DEBUGFUNC("e1000_led_on_ich8lan");
    5799                 :            : 
    5800         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_ife)
    5801                 :          0 :                 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
    5802                 :            :                                 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
    5803                 :            : 
    5804                 :          0 :         E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
    5805                 :          0 :         return E1000_SUCCESS;
    5806                 :            : }
    5807                 :            : 
    5808                 :            : /**
    5809                 :            :  *  e1000_led_off_ich8lan - Turn LEDs off
    5810                 :            :  *  @hw: pointer to the HW structure
    5811                 :            :  *
    5812                 :            :  *  Turn off the LEDs.
    5813                 :            :  **/
    5814                 :          0 : STATIC s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
    5815                 :            : {
    5816                 :          0 :         DEBUGFUNC("e1000_led_off_ich8lan");
    5817                 :            : 
    5818         [ #  # ]:          0 :         if (hw->phy.type == e1000_phy_ife)
    5819                 :          0 :                 return hw->phy.ops.write_reg(hw, IFE_PHY_SPECIAL_CONTROL_LED,
    5820                 :            :                                (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
    5821                 :            : 
    5822                 :          0 :         E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
    5823                 :          0 :         return E1000_SUCCESS;
    5824                 :            : }
    5825                 :            : 
    5826                 :            : /**
    5827                 :            :  *  e1000_setup_led_pchlan - Configures SW controllable LED
    5828                 :            :  *  @hw: pointer to the HW structure
    5829                 :            :  *
    5830                 :            :  *  This prepares the SW controllable LED for use.
    5831                 :            :  **/
    5832                 :          0 : STATIC s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
    5833                 :            : {
    5834                 :          0 :         DEBUGFUNC("e1000_setup_led_pchlan");
    5835                 :            : 
    5836                 :          0 :         return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
    5837                 :          0 :                                      (u16)hw->mac.ledctl_mode1);
    5838                 :            : }
    5839                 :            : 
    5840                 :            : /**
    5841                 :            :  *  e1000_cleanup_led_pchlan - Restore the default LED operation
    5842                 :            :  *  @hw: pointer to the HW structure
    5843                 :            :  *
    5844                 :            :  *  Return the LED back to the default configuration.
    5845                 :            :  **/
    5846                 :          0 : STATIC s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
    5847                 :            : {
    5848                 :          0 :         DEBUGFUNC("e1000_cleanup_led_pchlan");
    5849                 :            : 
    5850                 :          0 :         return hw->phy.ops.write_reg(hw, HV_LED_CONFIG,
    5851                 :          0 :                                      (u16)hw->mac.ledctl_default);
    5852                 :            : }
    5853                 :            : 
    5854                 :            : /**
    5855                 :            :  *  e1000_led_on_pchlan - Turn LEDs on
    5856                 :            :  *  @hw: pointer to the HW structure
    5857                 :            :  *
    5858                 :            :  *  Turn on the LEDs.
    5859                 :            :  **/
    5860                 :          0 : STATIC s32 e1000_led_on_pchlan(struct e1000_hw *hw)
    5861                 :            : {
    5862                 :          0 :         u16 data = (u16)hw->mac.ledctl_mode2;
    5863                 :            :         u32 i, led;
    5864                 :            : 
    5865                 :          0 :         DEBUGFUNC("e1000_led_on_pchlan");
    5866                 :            : 
    5867                 :            :         /* If no link, then turn LED on by setting the invert bit
    5868                 :            :          * for each LED that's mode is "link_up" in ledctl_mode2.
    5869                 :            :          */
    5870         [ #  # ]:          0 :         if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
    5871         [ #  # ]:          0 :                 for (i = 0; i < 3; i++) {
    5872                 :          0 :                         led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
    5873         [ #  # ]:          0 :                         if ((led & E1000_PHY_LED0_MODE_MASK) !=
    5874                 :            :                             E1000_LEDCTL_MODE_LINK_UP)
    5875                 :          0 :                                 continue;
    5876         [ #  # ]:          0 :                         if (led & E1000_PHY_LED0_IVRT)
    5877                 :          0 :                                 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
    5878                 :            :                         else
    5879                 :          0 :                                 data |= (E1000_PHY_LED0_IVRT << (i * 5));
    5880                 :            :                 }
    5881                 :            :         }
    5882                 :            : 
    5883                 :          0 :         return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
    5884                 :            : }
    5885                 :            : 
    5886                 :            : /**
    5887                 :            :  *  e1000_led_off_pchlan - Turn LEDs off
    5888                 :            :  *  @hw: pointer to the HW structure
    5889                 :            :  *
    5890                 :            :  *  Turn off the LEDs.
    5891                 :            :  **/
    5892                 :          0 : STATIC s32 e1000_led_off_pchlan(struct e1000_hw *hw)
    5893                 :            : {
    5894                 :          0 :         u16 data = (u16)hw->mac.ledctl_mode1;
    5895                 :            :         u32 i, led;
    5896                 :            : 
    5897                 :          0 :         DEBUGFUNC("e1000_led_off_pchlan");
    5898                 :            : 
    5899                 :            :         /* If no link, then turn LED off by clearing the invert bit
    5900                 :            :          * for each LED that's mode is "link_up" in ledctl_mode1.
    5901                 :            :          */
    5902         [ #  # ]:          0 :         if (!(E1000_READ_REG(hw, E1000_STATUS) & E1000_STATUS_LU)) {
    5903         [ #  # ]:          0 :                 for (i = 0; i < 3; i++) {
    5904                 :          0 :                         led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
    5905         [ #  # ]:          0 :                         if ((led & E1000_PHY_LED0_MODE_MASK) !=
    5906                 :            :                             E1000_LEDCTL_MODE_LINK_UP)
    5907                 :          0 :                                 continue;
    5908         [ #  # ]:          0 :                         if (led & E1000_PHY_LED0_IVRT)
    5909                 :          0 :                                 data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
    5910                 :            :                         else
    5911                 :          0 :                                 data |= (E1000_PHY_LED0_IVRT << (i * 5));
    5912                 :            :                 }
    5913                 :            :         }
    5914                 :            : 
    5915                 :          0 :         return hw->phy.ops.write_reg(hw, HV_LED_CONFIG, data);
    5916                 :            : }
    5917                 :            : 
    5918                 :            : /**
    5919                 :            :  *  e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
    5920                 :            :  *  @hw: pointer to the HW structure
    5921                 :            :  *
    5922                 :            :  *  Read appropriate register for the config done bit for completion status
    5923                 :            :  *  and configure the PHY through s/w for EEPROM-less parts.
    5924                 :            :  *
    5925                 :            :  *  NOTE: some silicon which is EEPROM-less will fail trying to read the
    5926                 :            :  *  config done bit, so only an error is logged and continues.  If we were
    5927                 :            :  *  to return with error, EEPROM-less silicon would not be able to be reset
    5928                 :            :  *  or change link.
    5929                 :            :  **/
    5930                 :          0 : STATIC s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
    5931                 :            : {
    5932                 :            :         s32 ret_val = E1000_SUCCESS;
    5933                 :          0 :         u32 bank = 0;
    5934                 :            :         u32 status;
    5935                 :            : 
    5936                 :          0 :         DEBUGFUNC("e1000_get_cfg_done_ich8lan");
    5937                 :            : 
    5938                 :          0 :         e1000_get_cfg_done_generic(hw);
    5939                 :            : 
    5940                 :            :         /* Wait for indication from h/w that it has completed basic config */
    5941         [ #  # ]:          0 :         if (hw->mac.type >= e1000_ich10lan) {
    5942                 :          0 :                 e1000_lan_init_done_ich8lan(hw);
    5943                 :            :         } else {
    5944                 :          0 :                 ret_val = e1000_get_auto_rd_done_generic(hw);
    5945         [ #  # ]:          0 :                 if (ret_val) {
    5946                 :            :                         /* When auto config read does not complete, do not
    5947                 :            :                          * return with an error. This can happen in situations
    5948                 :            :                          * where there is no eeprom and prevents getting link.
    5949                 :            :                          */
    5950                 :          0 :                         DEBUGOUT("Auto Read Done did not complete\n");
    5951                 :            :                         ret_val = E1000_SUCCESS;
    5952                 :            :                 }
    5953                 :            :         }
    5954                 :            : 
    5955                 :            :         /* Clear PHY Reset Asserted bit */
    5956                 :          0 :         status = E1000_READ_REG(hw, E1000_STATUS);
    5957         [ #  # ]:          0 :         if (status & E1000_STATUS_PHYRA)
    5958                 :          0 :                 E1000_WRITE_REG(hw, E1000_STATUS, status & ~E1000_STATUS_PHYRA);
    5959                 :            :         else
    5960                 :          0 :                 DEBUGOUT("PHY Reset Asserted not set - needs delay\n");
    5961                 :            : 
    5962                 :            :         /* If EEPROM is not marked present, init the IGP 3 PHY manually */
    5963         [ #  # ]:          0 :         if (hw->mac.type <= e1000_ich9lan) {
    5964         [ #  # ]:          0 :                 if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) &&
    5965         [ #  # ]:          0 :                     (hw->phy.type == e1000_phy_igp_3)) {
    5966                 :          0 :                         e1000_phy_init_script_igp3(hw);
    5967                 :            :                 }
    5968                 :            :         } else {
    5969         [ #  # ]:          0 :                 if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
    5970                 :            :                         /* Maybe we should do a basic PHY config */
    5971                 :          0 :                         DEBUGOUT("EEPROM not present\n");
    5972                 :            :                         ret_val = -E1000_ERR_CONFIG;
    5973                 :            :                 }
    5974                 :            :         }
    5975                 :            : 
    5976                 :          0 :         return ret_val;
    5977                 :            : }
    5978                 :            : 
    5979                 :            : /**
    5980                 :            :  * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
    5981                 :            :  * @hw: pointer to the HW structure
    5982                 :            :  *
    5983                 :            :  * In the case of a PHY power down to save power, or to turn off link during a
    5984                 :            :  * driver unload, or wake on lan is not enabled, remove the link.
    5985                 :            :  **/
    5986                 :          0 : STATIC void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
    5987                 :            : {
    5988                 :            :         /* If the management interface is not enabled, then power down */
    5989   [ #  #  #  # ]:          0 :         if (!(hw->mac.ops.check_mng_mode(hw) ||
    5990                 :          0 :               hw->phy.ops.check_reset_block(hw)))
    5991                 :          0 :                 e1000_power_down_phy_copper(hw);
    5992                 :            : 
    5993                 :          0 :         return;
    5994                 :            : }
    5995                 :            : 
    5996                 :            : /**
    5997                 :            :  *  e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
    5998                 :            :  *  @hw: pointer to the HW structure
    5999                 :            :  *
    6000                 :            :  *  Clears hardware counters specific to the silicon family and calls
    6001                 :            :  *  clear_hw_cntrs_generic to clear all general purpose counters.
    6002                 :            :  **/
    6003                 :          0 : STATIC void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
    6004                 :            : {
    6005                 :            :         u16 phy_data;
    6006                 :            :         s32 ret_val;
    6007                 :            : 
    6008                 :          0 :         DEBUGFUNC("e1000_clear_hw_cntrs_ich8lan");
    6009                 :            : 
    6010                 :          0 :         e1000_clear_hw_cntrs_base_generic(hw);
    6011                 :            : 
    6012                 :          0 :         E1000_READ_REG(hw, E1000_ALGNERRC);
    6013                 :          0 :         E1000_READ_REG(hw, E1000_RXERRC);
    6014                 :          0 :         E1000_READ_REG(hw, E1000_TNCRS);
    6015                 :          0 :         E1000_READ_REG(hw, E1000_CEXTERR);
    6016                 :          0 :         E1000_READ_REG(hw, E1000_TSCTC);
    6017                 :          0 :         E1000_READ_REG(hw, E1000_TSCTFC);
    6018                 :            : 
    6019                 :          0 :         E1000_READ_REG(hw, E1000_MGTPRC);
    6020                 :          0 :         E1000_READ_REG(hw, E1000_MGTPDC);
    6021                 :          0 :         E1000_READ_REG(hw, E1000_MGTPTC);
    6022                 :            : 
    6023                 :          0 :         E1000_READ_REG(hw, E1000_IAC);
    6024                 :          0 :         E1000_READ_REG(hw, E1000_ICRXOC);
    6025                 :            : 
    6026                 :            :         /* Clear PHY statistics registers */
    6027         [ #  # ]:          0 :         if ((hw->phy.type == e1000_phy_82578) ||
    6028         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_82579) ||
    6029         [ #  # ]:          0 :             (hw->phy.type == e1000_phy_i217) ||
    6030                 :            :             (hw->phy.type == e1000_phy_82577)) {
    6031                 :          0 :                 ret_val = hw->phy.ops.acquire(hw);
    6032         [ #  # ]:          0 :                 if (ret_val)
    6033                 :          0 :                         return;
    6034                 :          0 :                 ret_val = hw->phy.ops.set_page(hw,
    6035                 :            :                                                HV_STATS_PAGE << IGP_PAGE_SHIFT);
    6036         [ #  # ]:          0 :                 if (ret_val)
    6037                 :          0 :                         goto release;
    6038                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
    6039                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
    6040                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
    6041                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
    6042                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
    6043                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
    6044                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
    6045                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
    6046                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
    6047                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
    6048                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
    6049                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
    6050                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
    6051                 :          0 :                 hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
    6052                 :          0 : release:
    6053                 :          0 :                 hw->phy.ops.release(hw);
    6054                 :            :         }
    6055                 :            : }
    6056                 :            : 
    6057                 :            : /**
    6058                 :            :  *  e1000_configure_k0s_lpt - Configure K0s power state
    6059                 :            :  *  @hw: pointer to the HW structure
    6060                 :            :  *  @entry_latency: Tx idle period for entering K0s - valid values are 0 to 3.
    6061                 :            :  *      0 corresponds to 128ns, each value over 0 doubles the duration.
    6062                 :            :  *  @min_time: Minimum Tx idle period allowed  - valid values are 0 to 4.
    6063                 :            :  *      0 corresponds to 128ns, each value over 0 doubles the duration.
    6064                 :            :  *
    6065                 :            :  *  Configure the K1 power state based on the provided parameter.
    6066                 :            :  *  Assumes semaphore already acquired.
    6067                 :            :  *
    6068                 :            :  *  Success returns 0, Failure returns:
    6069                 :            :  *      -E1000_ERR_PHY (-2) in case of access error
    6070                 :            :  *      -E1000_ERR_PARAM (-4) in case of parameters error
    6071                 :            :  **/
    6072                 :          0 : s32 e1000_configure_k0s_lpt(struct e1000_hw *hw, u8 entry_latency, u8 min_time)
    6073                 :            : {
    6074                 :            :         s32 ret_val;
    6075                 :          0 :         u16 kmrn_reg = 0;
    6076                 :            : 
    6077                 :          0 :         DEBUGFUNC("e1000_configure_k0s_lpt");
    6078                 :            : 
    6079         [ #  # ]:          0 :         if (entry_latency > 3 || min_time > 4)
    6080                 :            :                 return -E1000_ERR_PARAM;
    6081                 :            : 
    6082                 :          0 :         ret_val = e1000_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K0S_CTRL,
    6083                 :            :                                              &kmrn_reg);
    6084         [ #  # ]:          0 :         if (ret_val)
    6085                 :            :                 return ret_val;
    6086                 :            : 
    6087                 :            :         /* for now don't touch the latency */
    6088                 :          0 :         kmrn_reg &= ~(E1000_KMRNCTRLSTA_K0S_CTRL_MIN_TIME_MASK);
    6089                 :          0 :         kmrn_reg |= ((min_time << E1000_KMRNCTRLSTA_K0S_CTRL_MIN_TIME_SHIFT));
    6090                 :            : 
    6091                 :          0 :         ret_val = e1000_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K0S_CTRL,
    6092                 :            :                                               kmrn_reg);
    6093         [ #  # ]:          0 :         if (ret_val)
    6094                 :          0 :                 return ret_val;
    6095                 :            : 
    6096                 :            :         return E1000_SUCCESS;
    6097                 :            : }

Generated by: LCOV version 1.14