Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Carolyn Wyborny | 6e86132 | 2012-01-18 22:13:27 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2012 Intel Corporation. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | /* e1000_82575 |
| 29 | * e1000_82576 |
| 30 | */ |
| 31 | |
Joe Perches | 82bbcde | 2011-10-21 20:04:09 +0000 | [diff] [blame] | 32 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 33 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 34 | #include <linux/types.h> |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 35 | #include <linux/if_ether.h> |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 36 | |
| 37 | #include "e1000_mac.h" |
| 38 | #include "e1000_82575.h" |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 39 | #include "e1000_i210.h" |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 40 | |
| 41 | static s32 igb_get_invariants_82575(struct e1000_hw *); |
| 42 | static s32 igb_acquire_phy_82575(struct e1000_hw *); |
| 43 | static void igb_release_phy_82575(struct e1000_hw *); |
| 44 | static s32 igb_acquire_nvm_82575(struct e1000_hw *); |
| 45 | static void igb_release_nvm_82575(struct e1000_hw *); |
| 46 | static s32 igb_check_for_link_82575(struct e1000_hw *); |
| 47 | static s32 igb_get_cfg_done_82575(struct e1000_hw *); |
| 48 | static s32 igb_init_hw_82575(struct e1000_hw *); |
| 49 | static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *); |
| 50 | static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16 *); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 51 | static s32 igb_read_phy_reg_82580(struct e1000_hw *, u32, u16 *); |
| 52 | static s32 igb_write_phy_reg_82580(struct e1000_hw *, u32, u16); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 53 | static s32 igb_reset_hw_82575(struct e1000_hw *); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 54 | static s32 igb_reset_hw_82580(struct e1000_hw *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 55 | static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *, bool); |
Carolyn Wyborny | da02cde | 2012-03-04 03:26:26 +0000 | [diff] [blame] | 56 | static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *, bool); |
| 57 | static s32 igb_set_d3_lplu_state_82580(struct e1000_hw *, bool); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 58 | static s32 igb_setup_copper_link_82575(struct e1000_hw *); |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 59 | static s32 igb_setup_serdes_link_82575(struct e1000_hw *); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 60 | static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *, u32, u16); |
| 61 | static void igb_clear_hw_cntrs_82575(struct e1000_hw *); |
| 62 | static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *, u16); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 63 | static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *, u16 *, |
| 64 | u16 *); |
| 65 | static s32 igb_get_phy_id_82575(struct e1000_hw *); |
| 66 | static void igb_release_swfw_sync_82575(struct e1000_hw *, u16); |
| 67 | static bool igb_sgmii_active_82575(struct e1000_hw *); |
| 68 | static s32 igb_reset_init_script_82575(struct e1000_hw *); |
| 69 | static s32 igb_read_mac_addr_82575(struct e1000_hw *); |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 70 | static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw); |
Alexander Duyck | 99870a7 | 2010-08-03 11:50:08 +0000 | [diff] [blame] | 71 | static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw); |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 72 | static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw); |
| 73 | static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw); |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 74 | static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw); |
| 75 | static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 76 | static const u16 e1000_82580_rxpbs_table[] = |
| 77 | { 36, 72, 144, 1, 2, 4, 8, 16, |
| 78 | 35, 70, 140 }; |
| 79 | #define E1000_82580_RXPBS_TABLE_SIZE \ |
| 80 | (sizeof(e1000_82580_rxpbs_table)/sizeof(u16)) |
| 81 | |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 82 | /** |
| 83 | * igb_sgmii_uses_mdio_82575 - Determine if I2C pins are for external MDIO |
| 84 | * @hw: pointer to the HW structure |
| 85 | * |
| 86 | * Called to determine if the I2C pins are being used for I2C or as an |
| 87 | * external MDIO interface since the two options are mutually exclusive. |
| 88 | **/ |
| 89 | static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw) |
| 90 | { |
| 91 | u32 reg = 0; |
| 92 | bool ext_mdio = false; |
| 93 | |
| 94 | switch (hw->mac.type) { |
| 95 | case e1000_82575: |
| 96 | case e1000_82576: |
| 97 | reg = rd32(E1000_MDIC); |
| 98 | ext_mdio = !!(reg & E1000_MDIC_DEST); |
| 99 | break; |
| 100 | case e1000_82580: |
| 101 | case e1000_i350: |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 102 | case e1000_i210: |
| 103 | case e1000_i211: |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 104 | reg = rd32(E1000_MDICNFG); |
| 105 | ext_mdio = !!(reg & E1000_MDICNFG_EXT_MDIO); |
| 106 | break; |
| 107 | default: |
| 108 | break; |
| 109 | } |
| 110 | return ext_mdio; |
| 111 | } |
| 112 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 113 | static s32 igb_get_invariants_82575(struct e1000_hw *hw) |
| 114 | { |
| 115 | struct e1000_phy_info *phy = &hw->phy; |
| 116 | struct e1000_nvm_info *nvm = &hw->nvm; |
| 117 | struct e1000_mac_info *mac = &hw->mac; |
Alexander Duyck | c1889bf | 2009-02-06 23:16:45 +0000 | [diff] [blame] | 118 | struct e1000_dev_spec_82575 * dev_spec = &hw->dev_spec._82575; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 119 | u32 eecd; |
| 120 | s32 ret_val; |
| 121 | u16 size; |
| 122 | u32 ctrl_ext = 0; |
| 123 | |
| 124 | switch (hw->device_id) { |
| 125 | case E1000_DEV_ID_82575EB_COPPER: |
| 126 | case E1000_DEV_ID_82575EB_FIBER_SERDES: |
| 127 | case E1000_DEV_ID_82575GB_QUAD_COPPER: |
| 128 | mac->type = e1000_82575; |
| 129 | break; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 130 | case E1000_DEV_ID_82576: |
Alexander Duyck | 9eb2341 | 2009-03-13 20:42:15 +0000 | [diff] [blame] | 131 | case E1000_DEV_ID_82576_NS: |
Alexander Duyck | 747d49b | 2009-10-05 06:33:27 +0000 | [diff] [blame] | 132 | case E1000_DEV_ID_82576_NS_SERDES: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 133 | case E1000_DEV_ID_82576_FIBER: |
| 134 | case E1000_DEV_ID_82576_SERDES: |
Alexander Duyck | c8ea5ea | 2009-03-13 20:42:35 +0000 | [diff] [blame] | 135 | case E1000_DEV_ID_82576_QUAD_COPPER: |
Carolyn Wyborny | b894fa2 | 2010-03-19 06:07:48 +0000 | [diff] [blame] | 136 | case E1000_DEV_ID_82576_QUAD_COPPER_ET2: |
Alexander Duyck | 4703bf7 | 2009-07-23 18:09:48 +0000 | [diff] [blame] | 137 | case E1000_DEV_ID_82576_SERDES_QUAD: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 138 | mac->type = e1000_82576; |
| 139 | break; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 140 | case E1000_DEV_ID_82580_COPPER: |
| 141 | case E1000_DEV_ID_82580_FIBER: |
Carolyn Wyborny | 6493d24 | 2011-01-14 05:33:46 +0000 | [diff] [blame] | 142 | case E1000_DEV_ID_82580_QUAD_FIBER: |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 143 | case E1000_DEV_ID_82580_SERDES: |
| 144 | case E1000_DEV_ID_82580_SGMII: |
| 145 | case E1000_DEV_ID_82580_COPPER_DUAL: |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 146 | case E1000_DEV_ID_DH89XXCC_SGMII: |
| 147 | case E1000_DEV_ID_DH89XXCC_SERDES: |
Gasparakis, Joseph | 1b5dda3 | 2010-12-09 01:41:01 +0000 | [diff] [blame] | 148 | case E1000_DEV_ID_DH89XXCC_BACKPLANE: |
| 149 | case E1000_DEV_ID_DH89XXCC_SFP: |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 150 | mac->type = e1000_82580; |
| 151 | break; |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 152 | case E1000_DEV_ID_I350_COPPER: |
| 153 | case E1000_DEV_ID_I350_FIBER: |
| 154 | case E1000_DEV_ID_I350_SERDES: |
| 155 | case E1000_DEV_ID_I350_SGMII: |
| 156 | mac->type = e1000_i350; |
| 157 | break; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 158 | case E1000_DEV_ID_I210_COPPER: |
| 159 | case E1000_DEV_ID_I210_COPPER_OEM1: |
| 160 | case E1000_DEV_ID_I210_COPPER_IT: |
| 161 | case E1000_DEV_ID_I210_FIBER: |
| 162 | case E1000_DEV_ID_I210_SERDES: |
| 163 | case E1000_DEV_ID_I210_SGMII: |
| 164 | mac->type = e1000_i210; |
| 165 | break; |
| 166 | case E1000_DEV_ID_I211_COPPER: |
| 167 | mac->type = e1000_i211; |
| 168 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 169 | default: |
| 170 | return -E1000_ERR_MAC_INIT; |
| 171 | break; |
| 172 | } |
| 173 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 174 | /* Set media type */ |
| 175 | /* |
| 176 | * The 82575 uses bits 22:23 for link mode. The mode can be changed |
| 177 | * based on the EEPROM. We cannot rely upon device ID. There |
| 178 | * is no distinguishable difference between fiber and internal |
| 179 | * SerDes mode on the 82575. There can be an external PHY attached |
| 180 | * on the SGMII interface. For this, we'll set sgmii_active to true. |
| 181 | */ |
| 182 | phy->media_type = e1000_media_type_copper; |
| 183 | dev_spec->sgmii_active = false; |
| 184 | |
| 185 | ctrl_ext = rd32(E1000_CTRL_EXT); |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 186 | switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) { |
| 187 | case E1000_CTRL_EXT_LINK_MODE_SGMII: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 188 | dev_spec->sgmii_active = true; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 189 | break; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 190 | case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX: |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 191 | case E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES: |
| 192 | hw->phy.media_type = e1000_media_type_internal_serdes; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 193 | break; |
| 194 | default: |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 195 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 196 | } |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 197 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 198 | /* Set mta register count */ |
| 199 | mac->mta_reg_count = 128; |
| 200 | /* Set rar entry count */ |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 201 | switch (mac->type) { |
| 202 | case e1000_82576: |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 203 | mac->rar_entry_count = E1000_RAR_ENTRIES_82576; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 204 | break; |
| 205 | case e1000_82580: |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 206 | mac->rar_entry_count = E1000_RAR_ENTRIES_82580; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 207 | break; |
| 208 | case e1000_i350: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 209 | mac->rar_entry_count = E1000_RAR_ENTRIES_I350; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 210 | break; |
| 211 | default: |
| 212 | mac->rar_entry_count = E1000_RAR_ENTRIES_82575; |
| 213 | break; |
| 214 | } |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 215 | /* reset */ |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 216 | if (mac->type >= e1000_82580) |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 217 | mac->ops.reset_hw = igb_reset_hw_82580; |
| 218 | else |
| 219 | mac->ops.reset_hw = igb_reset_hw_82575; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 220 | |
| 221 | if (mac->type >= e1000_i210) { |
| 222 | mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_i210; |
| 223 | mac->ops.release_swfw_sync = igb_release_swfw_sync_i210; |
| 224 | } else { |
| 225 | mac->ops.acquire_swfw_sync = igb_acquire_swfw_sync_82575; |
| 226 | mac->ops.release_swfw_sync = igb_release_swfw_sync_82575; |
| 227 | } |
| 228 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 229 | /* Set if part includes ASF firmware */ |
| 230 | mac->asf_firmware_present = true; |
| 231 | /* Set if manageability features are enabled. */ |
| 232 | mac->arc_subsystem_valid = |
| 233 | (rd32(E1000_FWSM) & E1000_FWSM_MODE_MASK) |
| 234 | ? true : false; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 235 | /* enable EEE on i350 parts and later parts */ |
| 236 | if (mac->type >= e1000_i350) |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 237 | dev_spec->eee_disable = false; |
| 238 | else |
| 239 | dev_spec->eee_disable = true; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 240 | /* physical interface link setup */ |
| 241 | mac->ops.setup_physical_interface = |
| 242 | (hw->phy.media_type == e1000_media_type_copper) |
| 243 | ? igb_setup_copper_link_82575 |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 244 | : igb_setup_serdes_link_82575; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 245 | |
| 246 | /* NVM initialization */ |
| 247 | eecd = rd32(E1000_EECD); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 248 | size = (u16)((eecd & E1000_EECD_SIZE_EX_MASK) >> |
| 249 | E1000_EECD_SIZE_EX_SHIFT); |
| 250 | |
| 251 | /* |
| 252 | * Added to a constant, "size" becomes the left-shift value |
| 253 | * for setting word_size. |
| 254 | */ |
| 255 | size += NVM_WORD_SIZE_BASE_SHIFT; |
Jeff Kirsher | 5c3cad7 | 2008-06-27 10:59:33 -0700 | [diff] [blame] | 256 | |
Carolyn Wyborny | 925b11f | 2012-07-31 01:01:23 +0000 | [diff] [blame] | 257 | /* |
| 258 | * Check for invalid size |
| 259 | */ |
| 260 | if ((hw->mac.type == e1000_82576) && (size > 15)) { |
| 261 | pr_notice("The NVM size is not valid, defaulting to 32K\n"); |
| 262 | size = 15; |
| 263 | } |
| 264 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 265 | nvm->word_size = 1 << size; |
| 266 | if (hw->mac.type < e1000_i210) { |
| 267 | nvm->opcode_bits = 8; |
| 268 | nvm->delay_usec = 1; |
| 269 | switch (nvm->override) { |
| 270 | case e1000_nvm_override_spi_large: |
| 271 | nvm->page_size = 32; |
| 272 | nvm->address_bits = 16; |
| 273 | break; |
| 274 | case e1000_nvm_override_spi_small: |
| 275 | nvm->page_size = 8; |
| 276 | nvm->address_bits = 8; |
| 277 | break; |
| 278 | default: |
| 279 | nvm->page_size = eecd |
| 280 | & E1000_EECD_ADDR_BITS ? 32 : 8; |
| 281 | nvm->address_bits = eecd |
| 282 | & E1000_EECD_ADDR_BITS ? 16 : 8; |
| 283 | break; |
| 284 | } |
| 285 | if (nvm->word_size == (1 << 15)) |
| 286 | nvm->page_size = 128; |
| 287 | |
| 288 | nvm->type = e1000_nvm_eeprom_spi; |
| 289 | } else |
| 290 | nvm->type = e1000_nvm_flash_hw; |
| 291 | |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 292 | /* NVM Function Pointers */ |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 293 | switch (hw->mac.type) { |
| 294 | case e1000_82580: |
| 295 | nvm->ops.validate = igb_validate_nvm_checksum_82580; |
| 296 | nvm->ops.update = igb_update_nvm_checksum_82580; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 297 | nvm->ops.acquire = igb_acquire_nvm_82575; |
| 298 | nvm->ops.release = igb_release_nvm_82575; |
| 299 | if (nvm->word_size < (1 << 15)) |
| 300 | nvm->ops.read = igb_read_nvm_eerd; |
| 301 | else |
| 302 | nvm->ops.read = igb_read_nvm_spi; |
| 303 | nvm->ops.write = igb_write_nvm_spi; |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 304 | break; |
| 305 | case e1000_i350: |
| 306 | nvm->ops.validate = igb_validate_nvm_checksum_i350; |
| 307 | nvm->ops.update = igb_update_nvm_checksum_i350; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 308 | nvm->ops.acquire = igb_acquire_nvm_82575; |
| 309 | nvm->ops.release = igb_release_nvm_82575; |
| 310 | if (nvm->word_size < (1 << 15)) |
| 311 | nvm->ops.read = igb_read_nvm_eerd; |
| 312 | else |
| 313 | nvm->ops.read = igb_read_nvm_spi; |
| 314 | nvm->ops.write = igb_write_nvm_spi; |
| 315 | break; |
| 316 | case e1000_i210: |
| 317 | nvm->ops.validate = igb_validate_nvm_checksum_i210; |
| 318 | nvm->ops.update = igb_update_nvm_checksum_i210; |
| 319 | nvm->ops.acquire = igb_acquire_nvm_i210; |
| 320 | nvm->ops.release = igb_release_nvm_i210; |
| 321 | nvm->ops.read = igb_read_nvm_srrd_i210; |
Carolyn Wyborny | ede4126 | 2012-10-24 03:56:21 +0000 | [diff] [blame] | 322 | nvm->ops.write = igb_write_nvm_srwr_i210; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 323 | nvm->ops.valid_led_default = igb_valid_led_default_i210; |
| 324 | break; |
| 325 | case e1000_i211: |
| 326 | nvm->ops.acquire = igb_acquire_nvm_i210; |
| 327 | nvm->ops.release = igb_release_nvm_i210; |
| 328 | nvm->ops.read = igb_read_nvm_i211; |
| 329 | nvm->ops.valid_led_default = igb_valid_led_default_i210; |
| 330 | nvm->ops.validate = NULL; |
| 331 | nvm->ops.update = NULL; |
| 332 | nvm->ops.write = NULL; |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 333 | break; |
| 334 | default: |
| 335 | nvm->ops.validate = igb_validate_nvm_checksum; |
| 336 | nvm->ops.update = igb_update_nvm_checksum; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 337 | nvm->ops.acquire = igb_acquire_nvm_82575; |
| 338 | nvm->ops.release = igb_release_nvm_82575; |
| 339 | if (nvm->word_size < (1 << 15)) |
| 340 | nvm->ops.read = igb_read_nvm_eerd; |
| 341 | else |
| 342 | nvm->ops.read = igb_read_nvm_spi; |
| 343 | nvm->ops.write = igb_write_nvm_spi; |
| 344 | break; |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 345 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 346 | |
Carolyn Wyborny | 6b78bb1 | 2011-01-20 06:40:45 +0000 | [diff] [blame] | 347 | /* if part supports SR-IOV then initialize mailbox parameters */ |
| 348 | switch (mac->type) { |
| 349 | case e1000_82576: |
| 350 | case e1000_i350: |
Alexander Duyck | a0c9860 | 2009-07-23 18:10:43 +0000 | [diff] [blame] | 351 | igb_init_mbx_params_pf(hw); |
Carolyn Wyborny | 6b78bb1 | 2011-01-20 06:40:45 +0000 | [diff] [blame] | 352 | break; |
| 353 | default: |
| 354 | break; |
| 355 | } |
Alexander Duyck | a0c9860 | 2009-07-23 18:10:43 +0000 | [diff] [blame] | 356 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 357 | /* setup PHY parameters */ |
| 358 | if (phy->media_type != e1000_media_type_copper) { |
| 359 | phy->type = e1000_phy_none; |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT; |
| 364 | phy->reset_delay_us = 100; |
| 365 | |
Alexander Duyck | 99870a7 | 2010-08-03 11:50:08 +0000 | [diff] [blame] | 366 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 367 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 368 | /* PHY function pointers */ |
Alexander Duyck | 99870a7 | 2010-08-03 11:50:08 +0000 | [diff] [blame] | 369 | if (igb_sgmii_active_82575(hw)) { |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 370 | phy->ops.reset = igb_phy_hw_reset_sgmii_82575; |
Alexander Duyck | 99870a7 | 2010-08-03 11:50:08 +0000 | [diff] [blame] | 371 | ctrl_ext |= E1000_CTRL_I2C_ENA; |
| 372 | } else { |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 373 | phy->ops.reset = igb_phy_hw_reset; |
Alexander Duyck | 99870a7 | 2010-08-03 11:50:08 +0000 | [diff] [blame] | 374 | ctrl_ext &= ~E1000_CTRL_I2C_ENA; |
| 375 | } |
| 376 | |
| 377 | wr32(E1000_CTRL_EXT, ctrl_ext); |
| 378 | igb_reset_mdicnfg_82580(hw); |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 379 | |
| 380 | if (igb_sgmii_active_82575(hw) && !igb_sgmii_uses_mdio_82575(hw)) { |
| 381 | phy->ops.read_reg = igb_read_phy_reg_sgmii_82575; |
| 382 | phy->ops.write_reg = igb_write_phy_reg_sgmii_82575; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 383 | } else if ((hw->mac.type == e1000_82580) |
| 384 | || (hw->mac.type == e1000_i350)) { |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 385 | phy->ops.read_reg = igb_read_phy_reg_82580; |
| 386 | phy->ops.write_reg = igb_write_phy_reg_82580; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 387 | } else if (hw->phy.type >= e1000_phy_i210) { |
| 388 | phy->ops.read_reg = igb_read_phy_reg_gs40g; |
| 389 | phy->ops.write_reg = igb_write_phy_reg_gs40g; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 390 | } else { |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 391 | phy->ops.read_reg = igb_read_phy_reg_igp; |
| 392 | phy->ops.write_reg = igb_write_phy_reg_igp; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 393 | } |
| 394 | |
Alexander Duyck | 19e588e | 2009-07-07 13:01:55 +0000 | [diff] [blame] | 395 | /* set lan id */ |
| 396 | hw->bus.func = (rd32(E1000_STATUS) & E1000_STATUS_FUNC_MASK) >> |
| 397 | E1000_STATUS_FUNC_SHIFT; |
| 398 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 399 | /* Set phy->phy_addr and phy->id. */ |
| 400 | ret_val = igb_get_phy_id_82575(hw); |
| 401 | if (ret_val) |
| 402 | return ret_val; |
| 403 | |
| 404 | /* Verify phy id and set remaining function pointers */ |
| 405 | switch (phy->id) { |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 406 | case I347AT4_E_PHY_ID: |
| 407 | case M88E1112_E_PHY_ID: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 408 | case M88E1111_I_PHY_ID: |
| 409 | phy->type = e1000_phy_m88; |
| 410 | phy->ops.get_phy_info = igb_get_phy_info_m88; |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 411 | |
| 412 | if (phy->id == I347AT4_E_PHY_ID || |
| 413 | phy->id == M88E1112_E_PHY_ID) |
| 414 | phy->ops.get_cable_length = igb_get_cable_length_m88_gen2; |
| 415 | else |
| 416 | phy->ops.get_cable_length = igb_get_cable_length_m88; |
| 417 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 418 | if (phy->id == I210_I_PHY_ID) { |
| 419 | phy->ops.get_cable_length = |
| 420 | igb_get_cable_length_m88_gen2; |
| 421 | phy->ops.set_d0_lplu_state = |
| 422 | igb_set_d0_lplu_state_82580; |
| 423 | phy->ops.set_d3_lplu_state = |
| 424 | igb_set_d3_lplu_state_82580; |
| 425 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 426 | phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88; |
| 427 | break; |
| 428 | case IGP03E1000_E_PHY_ID: |
| 429 | phy->type = e1000_phy_igp_3; |
| 430 | phy->ops.get_phy_info = igb_get_phy_info_igp; |
| 431 | phy->ops.get_cable_length = igb_get_cable_length_igp_2; |
| 432 | phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_igp; |
| 433 | phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82575; |
| 434 | phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state; |
| 435 | break; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 436 | case I82580_I_PHY_ID: |
Alexander Duyck | d2ba2ed | 2010-03-22 14:08:06 +0000 | [diff] [blame] | 437 | case I350_I_PHY_ID: |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 438 | phy->type = e1000_phy_82580; |
| 439 | phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_82580; |
| 440 | phy->ops.get_cable_length = igb_get_cable_length_82580; |
| 441 | phy->ops.get_phy_info = igb_get_phy_info_82580; |
Carolyn Wyborny | da02cde | 2012-03-04 03:26:26 +0000 | [diff] [blame] | 442 | phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580; |
| 443 | phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 444 | break; |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 445 | case I210_I_PHY_ID: |
| 446 | phy->type = e1000_phy_i210; |
| 447 | phy->ops.get_phy_info = igb_get_phy_info_m88; |
| 448 | phy->ops.check_polarity = igb_check_polarity_m88; |
| 449 | phy->ops.get_cable_length = igb_get_cable_length_m88_gen2; |
| 450 | phy->ops.set_d0_lplu_state = igb_set_d0_lplu_state_82580; |
| 451 | phy->ops.set_d3_lplu_state = igb_set_d3_lplu_state_82580; |
| 452 | phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88; |
| 453 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 454 | default: |
| 455 | return -E1000_ERR_PHY; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 462 | * igb_acquire_phy_82575 - Acquire rights to access PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 463 | * @hw: pointer to the HW structure |
| 464 | * |
| 465 | * Acquire access rights to the correct PHY. This is a |
| 466 | * function pointer entry point called by the api module. |
| 467 | **/ |
| 468 | static s32 igb_acquire_phy_82575(struct e1000_hw *hw) |
| 469 | { |
Alexander Duyck | 008c342 | 2009-10-05 06:32:07 +0000 | [diff] [blame] | 470 | u16 mask = E1000_SWFW_PHY0_SM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 471 | |
Alexander Duyck | 008c342 | 2009-10-05 06:32:07 +0000 | [diff] [blame] | 472 | if (hw->bus.func == E1000_FUNC_1) |
| 473 | mask = E1000_SWFW_PHY1_SM; |
Nick Nunley | ede3ef0 | 2010-07-01 13:37:54 +0000 | [diff] [blame] | 474 | else if (hw->bus.func == E1000_FUNC_2) |
| 475 | mask = E1000_SWFW_PHY2_SM; |
| 476 | else if (hw->bus.func == E1000_FUNC_3) |
| 477 | mask = E1000_SWFW_PHY3_SM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 478 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 479 | return hw->mac.ops.acquire_swfw_sync(hw, mask); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 483 | * igb_release_phy_82575 - Release rights to access PHY |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 484 | * @hw: pointer to the HW structure |
| 485 | * |
| 486 | * A wrapper to release access rights to the correct PHY. This is a |
| 487 | * function pointer entry point called by the api module. |
| 488 | **/ |
| 489 | static void igb_release_phy_82575(struct e1000_hw *hw) |
| 490 | { |
Alexander Duyck | 008c342 | 2009-10-05 06:32:07 +0000 | [diff] [blame] | 491 | u16 mask = E1000_SWFW_PHY0_SM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 492 | |
Alexander Duyck | 008c342 | 2009-10-05 06:32:07 +0000 | [diff] [blame] | 493 | if (hw->bus.func == E1000_FUNC_1) |
| 494 | mask = E1000_SWFW_PHY1_SM; |
Nick Nunley | ede3ef0 | 2010-07-01 13:37:54 +0000 | [diff] [blame] | 495 | else if (hw->bus.func == E1000_FUNC_2) |
| 496 | mask = E1000_SWFW_PHY2_SM; |
| 497 | else if (hw->bus.func == E1000_FUNC_3) |
| 498 | mask = E1000_SWFW_PHY3_SM; |
Alexander Duyck | 008c342 | 2009-10-05 06:32:07 +0000 | [diff] [blame] | 499 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 500 | hw->mac.ops.release_swfw_sync(hw, mask); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 504 | * igb_read_phy_reg_sgmii_82575 - Read PHY register using sgmii |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 505 | * @hw: pointer to the HW structure |
| 506 | * @offset: register offset to be read |
| 507 | * @data: pointer to the read data |
| 508 | * |
| 509 | * Reads the PHY register at offset using the serial gigabit media independent |
| 510 | * interface and stores the retrieved information in data. |
| 511 | **/ |
| 512 | static s32 igb_read_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset, |
| 513 | u16 *data) |
| 514 | { |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 515 | s32 ret_val = -E1000_ERR_PARAM; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 516 | |
| 517 | if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 518 | hw_dbg("PHY Address %u is out of range\n", offset); |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 519 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 522 | ret_val = hw->phy.ops.acquire(hw); |
| 523 | if (ret_val) |
| 524 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 525 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 526 | ret_val = igb_read_phy_reg_i2c(hw, offset, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 527 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 528 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 529 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 530 | out: |
| 531 | return ret_val; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 535 | * igb_write_phy_reg_sgmii_82575 - Write PHY register using sgmii |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 536 | * @hw: pointer to the HW structure |
| 537 | * @offset: register offset to write to |
| 538 | * @data: data to write at register offset |
| 539 | * |
| 540 | * Writes the data to PHY register at the offset using the serial gigabit |
| 541 | * media independent interface. |
| 542 | **/ |
| 543 | static s32 igb_write_phy_reg_sgmii_82575(struct e1000_hw *hw, u32 offset, |
| 544 | u16 data) |
| 545 | { |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 546 | s32 ret_val = -E1000_ERR_PARAM; |
| 547 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 548 | |
| 549 | if (offset > E1000_MAX_SGMII_PHY_REG_ADDR) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 550 | hw_dbg("PHY Address %d is out of range\n", offset); |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 551 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 554 | ret_val = hw->phy.ops.acquire(hw); |
| 555 | if (ret_val) |
| 556 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 557 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 558 | ret_val = igb_write_phy_reg_i2c(hw, offset, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 559 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 560 | hw->phy.ops.release(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 561 | |
Alexander Duyck | bf6f7a9 | 2009-10-05 06:32:27 +0000 | [diff] [blame] | 562 | out: |
| 563 | return ret_val; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 567 | * igb_get_phy_id_82575 - Retrieve PHY addr and id |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 568 | * @hw: pointer to the HW structure |
| 569 | * |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 570 | * Retrieves the PHY address and ID for both PHY's which do and do not use |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 571 | * sgmi interface. |
| 572 | **/ |
| 573 | static s32 igb_get_phy_id_82575(struct e1000_hw *hw) |
| 574 | { |
| 575 | struct e1000_phy_info *phy = &hw->phy; |
| 576 | s32 ret_val = 0; |
| 577 | u16 phy_id; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 578 | u32 ctrl_ext; |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 579 | u32 mdic; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 580 | |
| 581 | /* |
| 582 | * For SGMII PHYs, we try the list of possible addresses until |
| 583 | * we find one that works. For non-SGMII PHYs |
| 584 | * (e.g. integrated copper PHYs), an address of 1 should |
| 585 | * work. The result of this function should mean phy->phy_addr |
| 586 | * and phy->id are set correctly. |
| 587 | */ |
| 588 | if (!(igb_sgmii_active_82575(hw))) { |
| 589 | phy->addr = 1; |
| 590 | ret_val = igb_get_phy_id(hw); |
| 591 | goto out; |
| 592 | } |
| 593 | |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 594 | if (igb_sgmii_uses_mdio_82575(hw)) { |
| 595 | switch (hw->mac.type) { |
| 596 | case e1000_82575: |
| 597 | case e1000_82576: |
| 598 | mdic = rd32(E1000_MDIC); |
| 599 | mdic &= E1000_MDIC_PHY_MASK; |
| 600 | phy->addr = mdic >> E1000_MDIC_PHY_SHIFT; |
| 601 | break; |
| 602 | case e1000_82580: |
| 603 | case e1000_i350: |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 604 | case e1000_i210: |
| 605 | case e1000_i211: |
Nick Nunley | 4085f74 | 2010-07-26 13:15:06 +0000 | [diff] [blame] | 606 | mdic = rd32(E1000_MDICNFG); |
| 607 | mdic &= E1000_MDICNFG_PHY_MASK; |
| 608 | phy->addr = mdic >> E1000_MDICNFG_PHY_SHIFT; |
| 609 | break; |
| 610 | default: |
| 611 | ret_val = -E1000_ERR_PHY; |
| 612 | goto out; |
| 613 | break; |
| 614 | } |
| 615 | ret_val = igb_get_phy_id(hw); |
| 616 | goto out; |
| 617 | } |
| 618 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 619 | /* Power on sgmii phy if it is disabled */ |
| 620 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 621 | wr32(E1000_CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_SDP3_DATA); |
| 622 | wrfl(); |
| 623 | msleep(300); |
| 624 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 625 | /* |
| 626 | * The address field in the I2CCMD register is 3 bits and 0 is invalid. |
| 627 | * Therefore, we need to test 1-7 |
| 628 | */ |
| 629 | for (phy->addr = 1; phy->addr < 8; phy->addr++) { |
| 630 | ret_val = igb_read_phy_reg_sgmii_82575(hw, PHY_ID1, &phy_id); |
| 631 | if (ret_val == 0) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 632 | hw_dbg("Vendor ID 0x%08X read at address %u\n", |
| 633 | phy_id, phy->addr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 634 | /* |
| 635 | * At the time of this writing, The M88 part is |
| 636 | * the only supported SGMII PHY product. |
| 637 | */ |
| 638 | if (phy_id == M88_VENDOR) |
| 639 | break; |
| 640 | } else { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 641 | hw_dbg("PHY address %u was unreadable\n", phy->addr); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
| 645 | /* A valid PHY type couldn't be found. */ |
| 646 | if (phy->addr == 8) { |
| 647 | phy->addr = 0; |
| 648 | ret_val = -E1000_ERR_PHY; |
| 649 | goto out; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 650 | } else { |
| 651 | ret_val = igb_get_phy_id(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 654 | /* restore previous sfp cage power state */ |
| 655 | wr32(E1000_CTRL_EXT, ctrl_ext); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 656 | |
| 657 | out: |
| 658 | return ret_val; |
| 659 | } |
| 660 | |
| 661 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 662 | * igb_phy_hw_reset_sgmii_82575 - Performs a PHY reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 663 | * @hw: pointer to the HW structure |
| 664 | * |
| 665 | * Resets the PHY using the serial gigabit media independent interface. |
| 666 | **/ |
| 667 | static s32 igb_phy_hw_reset_sgmii_82575(struct e1000_hw *hw) |
| 668 | { |
| 669 | s32 ret_val; |
| 670 | |
| 671 | /* |
| 672 | * This isn't a true "hard" reset, but is the only reset |
| 673 | * available to us at this time. |
| 674 | */ |
| 675 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 676 | hw_dbg("Soft resetting SGMII attached PHY...\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 677 | |
| 678 | /* |
| 679 | * SFP documentation requires the following to configure the SPF module |
| 680 | * to work on SGMII. No further documentation is given. |
| 681 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 682 | ret_val = hw->phy.ops.write_reg(hw, 0x1B, 0x8084); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 683 | if (ret_val) |
| 684 | goto out; |
| 685 | |
| 686 | ret_val = igb_phy_sw_reset(hw); |
| 687 | |
| 688 | out: |
| 689 | return ret_val; |
| 690 | } |
| 691 | |
| 692 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 693 | * igb_set_d0_lplu_state_82575 - Set Low Power Linkup D0 state |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 694 | * @hw: pointer to the HW structure |
| 695 | * @active: true to enable LPLU, false to disable |
| 696 | * |
| 697 | * Sets the LPLU D0 state according to the active flag. When |
| 698 | * activating LPLU this function also disables smart speed |
| 699 | * and vice versa. LPLU will not be activated unless the |
| 700 | * device autonegotiation advertisement meets standards of |
| 701 | * either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 702 | * This is a function pointer entry point only called by |
| 703 | * PHY setup routines. |
| 704 | **/ |
| 705 | static s32 igb_set_d0_lplu_state_82575(struct e1000_hw *hw, bool active) |
| 706 | { |
| 707 | struct e1000_phy_info *phy = &hw->phy; |
| 708 | s32 ret_val; |
| 709 | u16 data; |
| 710 | |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 711 | ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 712 | if (ret_val) |
| 713 | goto out; |
| 714 | |
| 715 | if (active) { |
| 716 | data |= IGP02E1000_PM_D0_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 717 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 718 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 719 | if (ret_val) |
| 720 | goto out; |
| 721 | |
| 722 | /* When LPLU is enabled, we should disable SmartSpeed */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 723 | ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 724 | &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 725 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 726 | ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 727 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 728 | if (ret_val) |
| 729 | goto out; |
| 730 | } else { |
| 731 | data &= ~IGP02E1000_PM_D0_LPLU; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 732 | ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 733 | data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 734 | /* |
| 735 | * LPLU and SmartSpeed are mutually exclusive. LPLU is used |
| 736 | * during Dx states where the power conservation is most |
| 737 | * important. During driver activity we should enable |
| 738 | * SmartSpeed, so performance is maintained. |
| 739 | */ |
| 740 | if (phy->smart_speed == e1000_smart_speed_on) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 741 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 742 | IGP01E1000_PHY_PORT_CONFIG, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 743 | if (ret_val) |
| 744 | goto out; |
| 745 | |
| 746 | data |= IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 747 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 748 | IGP01E1000_PHY_PORT_CONFIG, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 749 | if (ret_val) |
| 750 | goto out; |
| 751 | } else if (phy->smart_speed == e1000_smart_speed_off) { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 752 | ret_val = phy->ops.read_reg(hw, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 753 | IGP01E1000_PHY_PORT_CONFIG, &data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 754 | if (ret_val) |
| 755 | goto out; |
| 756 | |
| 757 | data &= ~IGP01E1000_PSCFR_SMART_SPEED; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 758 | ret_val = phy->ops.write_reg(hw, |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 759 | IGP01E1000_PHY_PORT_CONFIG, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 760 | if (ret_val) |
| 761 | goto out; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | out: |
| 766 | return ret_val; |
| 767 | } |
| 768 | |
| 769 | /** |
Carolyn Wyborny | da02cde | 2012-03-04 03:26:26 +0000 | [diff] [blame] | 770 | * igb_set_d0_lplu_state_82580 - Set Low Power Linkup D0 state |
| 771 | * @hw: pointer to the HW structure |
| 772 | * @active: true to enable LPLU, false to disable |
| 773 | * |
| 774 | * Sets the LPLU D0 state according to the active flag. When |
| 775 | * activating LPLU this function also disables smart speed |
| 776 | * and vice versa. LPLU will not be activated unless the |
| 777 | * device autonegotiation advertisement meets standards of |
| 778 | * either 10 or 10/100 or 10/100/1000 at all duplexes. |
| 779 | * This is a function pointer entry point only called by |
| 780 | * PHY setup routines. |
| 781 | **/ |
| 782 | static s32 igb_set_d0_lplu_state_82580(struct e1000_hw *hw, bool active) |
| 783 | { |
| 784 | struct e1000_phy_info *phy = &hw->phy; |
| 785 | s32 ret_val = 0; |
| 786 | u16 data; |
| 787 | |
| 788 | data = rd32(E1000_82580_PHY_POWER_MGMT); |
| 789 | |
| 790 | if (active) { |
| 791 | data |= E1000_82580_PM_D0_LPLU; |
| 792 | |
| 793 | /* When LPLU is enabled, we should disable SmartSpeed */ |
| 794 | data &= ~E1000_82580_PM_SPD; |
| 795 | } else { |
| 796 | data &= ~E1000_82580_PM_D0_LPLU; |
| 797 | |
| 798 | /* |
| 799 | * LPLU and SmartSpeed are mutually exclusive. LPLU is used |
| 800 | * during Dx states where the power conservation is most |
| 801 | * important. During driver activity we should enable |
| 802 | * SmartSpeed, so performance is maintained. |
| 803 | */ |
| 804 | if (phy->smart_speed == e1000_smart_speed_on) |
| 805 | data |= E1000_82580_PM_SPD; |
| 806 | else if (phy->smart_speed == e1000_smart_speed_off) |
| 807 | data &= ~E1000_82580_PM_SPD; } |
| 808 | |
| 809 | wr32(E1000_82580_PHY_POWER_MGMT, data); |
| 810 | return ret_val; |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * igb_set_d3_lplu_state_82580 - Sets low power link up state for D3 |
| 815 | * @hw: pointer to the HW structure |
| 816 | * @active: boolean used to enable/disable lplu |
| 817 | * |
| 818 | * Success returns 0, Failure returns 1 |
| 819 | * |
| 820 | * The low power link up (lplu) state is set to the power management level D3 |
| 821 | * and SmartSpeed is disabled when active is true, else clear lplu for D3 |
| 822 | * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU |
| 823 | * is used during Dx states where the power conservation is most important. |
| 824 | * During driver activity, SmartSpeed should be enabled so performance is |
| 825 | * maintained. |
| 826 | **/ |
| 827 | s32 igb_set_d3_lplu_state_82580(struct e1000_hw *hw, bool active) |
| 828 | { |
| 829 | struct e1000_phy_info *phy = &hw->phy; |
| 830 | s32 ret_val = 0; |
| 831 | u16 data; |
| 832 | |
| 833 | data = rd32(E1000_82580_PHY_POWER_MGMT); |
| 834 | |
| 835 | if (!active) { |
| 836 | data &= ~E1000_82580_PM_D3_LPLU; |
| 837 | /* |
| 838 | * LPLU and SmartSpeed are mutually exclusive. LPLU is used |
| 839 | * during Dx states where the power conservation is most |
| 840 | * important. During driver activity we should enable |
| 841 | * SmartSpeed, so performance is maintained. |
| 842 | */ |
| 843 | if (phy->smart_speed == e1000_smart_speed_on) |
| 844 | data |= E1000_82580_PM_SPD; |
| 845 | else if (phy->smart_speed == e1000_smart_speed_off) |
| 846 | data &= ~E1000_82580_PM_SPD; |
| 847 | } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) || |
| 848 | (phy->autoneg_advertised == E1000_ALL_NOT_GIG) || |
| 849 | (phy->autoneg_advertised == E1000_ALL_10_SPEED)) { |
| 850 | data |= E1000_82580_PM_D3_LPLU; |
| 851 | /* When LPLU is enabled, we should disable SmartSpeed */ |
| 852 | data &= ~E1000_82580_PM_SPD; |
| 853 | } |
| 854 | |
| 855 | wr32(E1000_82580_PHY_POWER_MGMT, data); |
| 856 | return ret_val; |
| 857 | } |
| 858 | |
| 859 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 860 | * igb_acquire_nvm_82575 - Request for access to EEPROM |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 861 | * @hw: pointer to the HW structure |
| 862 | * |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 863 | * Acquire the necessary semaphores for exclusive access to the EEPROM. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 864 | * Set the EEPROM access request bit and wait for EEPROM access grant bit. |
| 865 | * Return successful if access grant bit set, else clear the request for |
| 866 | * EEPROM access and return -E1000_ERR_NVM (-1). |
| 867 | **/ |
| 868 | static s32 igb_acquire_nvm_82575(struct e1000_hw *hw) |
| 869 | { |
| 870 | s32 ret_val; |
| 871 | |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 872 | ret_val = hw->mac.ops.acquire_swfw_sync(hw, E1000_SWFW_EEP_SM); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 873 | if (ret_val) |
| 874 | goto out; |
| 875 | |
| 876 | ret_val = igb_acquire_nvm(hw); |
| 877 | |
| 878 | if (ret_val) |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 879 | hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 880 | |
| 881 | out: |
| 882 | return ret_val; |
| 883 | } |
| 884 | |
| 885 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 886 | * igb_release_nvm_82575 - Release exclusive access to EEPROM |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 887 | * @hw: pointer to the HW structure |
| 888 | * |
| 889 | * Stop any current commands to the EEPROM and clear the EEPROM request bit, |
| 890 | * then release the semaphores acquired. |
| 891 | **/ |
| 892 | static void igb_release_nvm_82575(struct e1000_hw *hw) |
| 893 | { |
| 894 | igb_release_nvm(hw); |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 895 | hw->mac.ops.release_swfw_sync(hw, E1000_SWFW_EEP_SM); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 899 | * igb_acquire_swfw_sync_82575 - Acquire SW/FW semaphore |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 900 | * @hw: pointer to the HW structure |
| 901 | * @mask: specifies which semaphore to acquire |
| 902 | * |
| 903 | * Acquire the SW/FW semaphore to access the PHY or NVM. The mask |
| 904 | * will also specify which port we're acquiring the lock for. |
| 905 | **/ |
| 906 | static s32 igb_acquire_swfw_sync_82575(struct e1000_hw *hw, u16 mask) |
| 907 | { |
| 908 | u32 swfw_sync; |
| 909 | u32 swmask = mask; |
| 910 | u32 fwmask = mask << 16; |
| 911 | s32 ret_val = 0; |
| 912 | s32 i = 0, timeout = 200; /* FIXME: find real value to use here */ |
| 913 | |
| 914 | while (i < timeout) { |
| 915 | if (igb_get_hw_semaphore(hw)) { |
| 916 | ret_val = -E1000_ERR_SWFW_SYNC; |
| 917 | goto out; |
| 918 | } |
| 919 | |
| 920 | swfw_sync = rd32(E1000_SW_FW_SYNC); |
| 921 | if (!(swfw_sync & (fwmask | swmask))) |
| 922 | break; |
| 923 | |
| 924 | /* |
| 925 | * Firmware currently using resource (fwmask) |
| 926 | * or other software thread using resource (swmask) |
| 927 | */ |
| 928 | igb_put_hw_semaphore(hw); |
| 929 | mdelay(5); |
| 930 | i++; |
| 931 | } |
| 932 | |
| 933 | if (i == timeout) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 934 | hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 935 | ret_val = -E1000_ERR_SWFW_SYNC; |
| 936 | goto out; |
| 937 | } |
| 938 | |
| 939 | swfw_sync |= swmask; |
| 940 | wr32(E1000_SW_FW_SYNC, swfw_sync); |
| 941 | |
| 942 | igb_put_hw_semaphore(hw); |
| 943 | |
| 944 | out: |
| 945 | return ret_val; |
| 946 | } |
| 947 | |
| 948 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 949 | * igb_release_swfw_sync_82575 - Release SW/FW semaphore |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 950 | * @hw: pointer to the HW structure |
| 951 | * @mask: specifies which semaphore to acquire |
| 952 | * |
| 953 | * Release the SW/FW semaphore used to access the PHY or NVM. The mask |
| 954 | * will also specify which port we're releasing the lock for. |
| 955 | **/ |
| 956 | static void igb_release_swfw_sync_82575(struct e1000_hw *hw, u16 mask) |
| 957 | { |
| 958 | u32 swfw_sync; |
| 959 | |
| 960 | while (igb_get_hw_semaphore(hw) != 0); |
| 961 | /* Empty */ |
| 962 | |
| 963 | swfw_sync = rd32(E1000_SW_FW_SYNC); |
| 964 | swfw_sync &= ~mask; |
| 965 | wr32(E1000_SW_FW_SYNC, swfw_sync); |
| 966 | |
| 967 | igb_put_hw_semaphore(hw); |
| 968 | } |
| 969 | |
| 970 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 971 | * igb_get_cfg_done_82575 - Read config done bit |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 972 | * @hw: pointer to the HW structure |
| 973 | * |
| 974 | * Read the management control register for the config done bit for |
| 975 | * completion status. NOTE: silicon which is EEPROM-less will fail trying |
| 976 | * to read the config done bit, so an error is *ONLY* logged and returns |
| 977 | * 0. If we were to return with error, EEPROM-less silicon |
| 978 | * would not be able to be reset or change link. |
| 979 | **/ |
| 980 | static s32 igb_get_cfg_done_82575(struct e1000_hw *hw) |
| 981 | { |
| 982 | s32 timeout = PHY_CFG_TIMEOUT; |
| 983 | s32 ret_val = 0; |
| 984 | u32 mask = E1000_NVM_CFG_DONE_PORT_0; |
| 985 | |
| 986 | if (hw->bus.func == 1) |
| 987 | mask = E1000_NVM_CFG_DONE_PORT_1; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 988 | else if (hw->bus.func == E1000_FUNC_2) |
| 989 | mask = E1000_NVM_CFG_DONE_PORT_2; |
| 990 | else if (hw->bus.func == E1000_FUNC_3) |
| 991 | mask = E1000_NVM_CFG_DONE_PORT_3; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 992 | |
| 993 | while (timeout) { |
| 994 | if (rd32(E1000_EEMNGCTL) & mask) |
| 995 | break; |
| 996 | msleep(1); |
| 997 | timeout--; |
| 998 | } |
| 999 | if (!timeout) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1000 | hw_dbg("MNG configuration cycle has not completed.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1001 | |
| 1002 | /* If EEPROM is not marked present, init the PHY manually */ |
| 1003 | if (((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) && |
| 1004 | (hw->phy.type == e1000_phy_igp_3)) |
| 1005 | igb_phy_init_script_igp3(hw); |
| 1006 | |
| 1007 | return ret_val; |
| 1008 | } |
| 1009 | |
| 1010 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1011 | * igb_check_for_link_82575 - Check for link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1012 | * @hw: pointer to the HW structure |
| 1013 | * |
| 1014 | * If sgmii is enabled, then use the pcs register to determine link, otherwise |
| 1015 | * use the generic interface for determining link. |
| 1016 | **/ |
| 1017 | static s32 igb_check_for_link_82575(struct e1000_hw *hw) |
| 1018 | { |
| 1019 | s32 ret_val; |
| 1020 | u16 speed, duplex; |
| 1021 | |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1022 | if (hw->phy.media_type != e1000_media_type_copper) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1023 | ret_val = igb_get_pcs_speed_and_duplex_82575(hw, &speed, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1024 | &duplex); |
Alexander Duyck | 5d0932a | 2009-01-31 00:53:18 -0800 | [diff] [blame] | 1025 | /* |
| 1026 | * Use this flag to determine if link needs to be checked or |
| 1027 | * not. If we have link clear the flag so that we do not |
| 1028 | * continue to check for link. |
| 1029 | */ |
| 1030 | hw->mac.get_link_status = !hw->mac.serdes_has_link; |
| 1031 | } else { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1032 | ret_val = igb_check_for_copper_link(hw); |
Alexander Duyck | 5d0932a | 2009-01-31 00:53:18 -0800 | [diff] [blame] | 1033 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1034 | |
| 1035 | return ret_val; |
| 1036 | } |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1037 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1038 | /** |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1039 | * igb_power_up_serdes_link_82575 - Power up the serdes link after shutdown |
| 1040 | * @hw: pointer to the HW structure |
| 1041 | **/ |
| 1042 | void igb_power_up_serdes_link_82575(struct e1000_hw *hw) |
| 1043 | { |
| 1044 | u32 reg; |
| 1045 | |
| 1046 | |
| 1047 | if ((hw->phy.media_type != e1000_media_type_internal_serdes) && |
| 1048 | !igb_sgmii_active_82575(hw)) |
| 1049 | return; |
| 1050 | |
| 1051 | /* Enable PCS to turn on link */ |
| 1052 | reg = rd32(E1000_PCS_CFG0); |
| 1053 | reg |= E1000_PCS_CFG_PCS_EN; |
| 1054 | wr32(E1000_PCS_CFG0, reg); |
| 1055 | |
| 1056 | /* Power up the laser */ |
| 1057 | reg = rd32(E1000_CTRL_EXT); |
| 1058 | reg &= ~E1000_CTRL_EXT_SDP3_DATA; |
| 1059 | wr32(E1000_CTRL_EXT, reg); |
| 1060 | |
| 1061 | /* flush the write to verify completion */ |
| 1062 | wrfl(); |
| 1063 | msleep(1); |
| 1064 | } |
| 1065 | |
| 1066 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1067 | * igb_get_pcs_speed_and_duplex_82575 - Retrieve current speed/duplex |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1068 | * @hw: pointer to the HW structure |
| 1069 | * @speed: stores the current speed |
| 1070 | * @duplex: stores the current duplex |
| 1071 | * |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1072 | * Using the physical coding sub-layer (PCS), retrieve the current speed and |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1073 | * duplex, then store the values in the pointers provided. |
| 1074 | **/ |
| 1075 | static s32 igb_get_pcs_speed_and_duplex_82575(struct e1000_hw *hw, u16 *speed, |
| 1076 | u16 *duplex) |
| 1077 | { |
| 1078 | struct e1000_mac_info *mac = &hw->mac; |
| 1079 | u32 pcs; |
| 1080 | |
| 1081 | /* Set up defaults for the return values of this function */ |
| 1082 | mac->serdes_has_link = false; |
| 1083 | *speed = 0; |
| 1084 | *duplex = 0; |
| 1085 | |
| 1086 | /* |
| 1087 | * Read the PCS Status register for link state. For non-copper mode, |
| 1088 | * the status register is not accurate. The PCS status register is |
| 1089 | * used instead. |
| 1090 | */ |
| 1091 | pcs = rd32(E1000_PCS_LSTAT); |
| 1092 | |
| 1093 | /* |
| 1094 | * The link up bit determines when link is up on autoneg. The sync ok |
| 1095 | * gets set once both sides sync up and agree upon link. Stable link |
| 1096 | * can be determined by checking for both link up and link sync ok |
| 1097 | */ |
| 1098 | if ((pcs & E1000_PCS_LSTS_LINK_OK) && (pcs & E1000_PCS_LSTS_SYNK_OK)) { |
| 1099 | mac->serdes_has_link = true; |
| 1100 | |
| 1101 | /* Detect and store PCS speed */ |
| 1102 | if (pcs & E1000_PCS_LSTS_SPEED_1000) { |
| 1103 | *speed = SPEED_1000; |
| 1104 | } else if (pcs & E1000_PCS_LSTS_SPEED_100) { |
| 1105 | *speed = SPEED_100; |
| 1106 | } else { |
| 1107 | *speed = SPEED_10; |
| 1108 | } |
| 1109 | |
| 1110 | /* Detect and store PCS duplex */ |
| 1111 | if (pcs & E1000_PCS_LSTS_DUPLEX_FULL) { |
| 1112 | *duplex = FULL_DUPLEX; |
| 1113 | } else { |
| 1114 | *duplex = HALF_DUPLEX; |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | /** |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1122 | * igb_shutdown_serdes_link_82575 - Remove link during power down |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1123 | * @hw: pointer to the HW structure |
| 1124 | * |
| 1125 | * In the case of fiber serdes, shut down optics and PCS on driver unload |
| 1126 | * when management pass thru is not enabled. |
| 1127 | **/ |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1128 | void igb_shutdown_serdes_link_82575(struct e1000_hw *hw) |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1129 | { |
| 1130 | u32 reg; |
| 1131 | |
Nick Nunley | 53c992f | 2010-02-17 01:01:40 +0000 | [diff] [blame] | 1132 | if (hw->phy.media_type != e1000_media_type_internal_serdes && |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1133 | igb_sgmii_active_82575(hw)) |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1134 | return; |
| 1135 | |
Nick Nunley | 53c992f | 2010-02-17 01:01:40 +0000 | [diff] [blame] | 1136 | if (!igb_enable_mng_pass_thru(hw)) { |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1137 | /* Disable PCS to turn off link */ |
| 1138 | reg = rd32(E1000_PCS_CFG0); |
| 1139 | reg &= ~E1000_PCS_CFG_PCS_EN; |
| 1140 | wr32(E1000_PCS_CFG0, reg); |
| 1141 | |
| 1142 | /* shutdown the laser */ |
| 1143 | reg = rd32(E1000_CTRL_EXT); |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1144 | reg |= E1000_CTRL_EXT_SDP3_DATA; |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 1145 | wr32(E1000_CTRL_EXT, reg); |
| 1146 | |
| 1147 | /* flush the write to verify completion */ |
| 1148 | wrfl(); |
| 1149 | msleep(1); |
| 1150 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1154 | * igb_reset_hw_82575 - Reset hardware |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1155 | * @hw: pointer to the HW structure |
| 1156 | * |
| 1157 | * This resets the hardware into a known state. This is a |
| 1158 | * function pointer entry point called by the api module. |
| 1159 | **/ |
| 1160 | static s32 igb_reset_hw_82575(struct e1000_hw *hw) |
| 1161 | { |
| 1162 | u32 ctrl, icr; |
| 1163 | s32 ret_val; |
| 1164 | |
| 1165 | /* |
| 1166 | * Prevent the PCI-E bus from sticking if there is no TLP connection |
| 1167 | * on the last TLP read/write transaction when MAC is reset. |
| 1168 | */ |
| 1169 | ret_val = igb_disable_pcie_master(hw); |
| 1170 | if (ret_val) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1171 | hw_dbg("PCI-E Master disable polling has failed.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1172 | |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 1173 | /* set the completion timeout for interface */ |
| 1174 | ret_val = igb_set_pcie_completion_timeout(hw); |
| 1175 | if (ret_val) { |
| 1176 | hw_dbg("PCI-E Set completion timeout has failed.\n"); |
| 1177 | } |
| 1178 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1179 | hw_dbg("Masking off all interrupts\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1180 | wr32(E1000_IMC, 0xffffffff); |
| 1181 | |
| 1182 | wr32(E1000_RCTL, 0); |
| 1183 | wr32(E1000_TCTL, E1000_TCTL_PSP); |
| 1184 | wrfl(); |
| 1185 | |
| 1186 | msleep(10); |
| 1187 | |
| 1188 | ctrl = rd32(E1000_CTRL); |
| 1189 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1190 | hw_dbg("Issuing a global reset to MAC\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1191 | wr32(E1000_CTRL, ctrl | E1000_CTRL_RST); |
| 1192 | |
| 1193 | ret_val = igb_get_auto_rd_done(hw); |
| 1194 | if (ret_val) { |
| 1195 | /* |
| 1196 | * When auto config read does not complete, do not |
| 1197 | * return with an error. This can happen in situations |
| 1198 | * where there is no eeprom and prevents getting link. |
| 1199 | */ |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1200 | hw_dbg("Auto Read Done did not complete\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | /* If EEPROM is not present, run manual init scripts */ |
| 1204 | if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) |
| 1205 | igb_reset_init_script_82575(hw); |
| 1206 | |
| 1207 | /* Clear any pending interrupt events. */ |
| 1208 | wr32(E1000_IMC, 0xffffffff); |
| 1209 | icr = rd32(E1000_ICR); |
| 1210 | |
Alexander Duyck | 5ac1665 | 2009-07-23 18:09:12 +0000 | [diff] [blame] | 1211 | /* Install any alternate MAC address into RAR0 */ |
| 1212 | ret_val = igb_check_alt_mac_addr(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1213 | |
| 1214 | return ret_val; |
| 1215 | } |
| 1216 | |
| 1217 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1218 | * igb_init_hw_82575 - Initialize hardware |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1219 | * @hw: pointer to the HW structure |
| 1220 | * |
| 1221 | * This inits the hardware readying it for operation. |
| 1222 | **/ |
| 1223 | static s32 igb_init_hw_82575(struct e1000_hw *hw) |
| 1224 | { |
| 1225 | struct e1000_mac_info *mac = &hw->mac; |
| 1226 | s32 ret_val; |
| 1227 | u16 i, rar_count = mac->rar_entry_count; |
| 1228 | |
| 1229 | /* Initialize identification LED */ |
| 1230 | ret_val = igb_id_led_init(hw); |
| 1231 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1232 | hw_dbg("Error initializing identification LED\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1233 | /* This is not fatal and we should not stop init due to this */ |
| 1234 | } |
| 1235 | |
| 1236 | /* Disabling VLAN filtering */ |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1237 | hw_dbg("Initializing the IEEE VLAN\n"); |
Carolyn Wyborny | 1128c75 | 2011-10-14 00:13:49 +0000 | [diff] [blame] | 1238 | if (hw->mac.type == e1000_i350) |
| 1239 | igb_clear_vfta_i350(hw); |
| 1240 | else |
| 1241 | igb_clear_vfta(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1242 | |
| 1243 | /* Setup the receive address */ |
Alexander Duyck | 5ac1665 | 2009-07-23 18:09:12 +0000 | [diff] [blame] | 1244 | igb_init_rx_addrs(hw, rar_count); |
| 1245 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1246 | /* Zero out the Multicast HASH table */ |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1247 | hw_dbg("Zeroing the MTA\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1248 | for (i = 0; i < mac->mta_reg_count; i++) |
| 1249 | array_wr32(E1000_MTA, i, 0); |
| 1250 | |
Alexander Duyck | 68d480c | 2009-10-05 06:33:08 +0000 | [diff] [blame] | 1251 | /* Zero out the Unicast HASH table */ |
| 1252 | hw_dbg("Zeroing the UTA\n"); |
| 1253 | for (i = 0; i < mac->uta_reg_count; i++) |
| 1254 | array_wr32(E1000_UTA, i, 0); |
| 1255 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1256 | /* Setup link and flow control */ |
| 1257 | ret_val = igb_setup_link(hw); |
| 1258 | |
| 1259 | /* |
| 1260 | * Clear all of the statistics registers (clear on read). It is |
| 1261 | * important that we do this after we have tried to establish link |
| 1262 | * because the symbol error count will increment wildly if there |
| 1263 | * is no link. |
| 1264 | */ |
| 1265 | igb_clear_hw_cntrs_82575(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1266 | return ret_val; |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1270 | * igb_setup_copper_link_82575 - Configure copper link settings |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1271 | * @hw: pointer to the HW structure |
| 1272 | * |
| 1273 | * Configures the link for auto-neg or forced speed and duplex. Then we check |
| 1274 | * for link, once link is established calls to configure collision distance |
| 1275 | * and flow control are called. |
| 1276 | **/ |
| 1277 | static s32 igb_setup_copper_link_82575(struct e1000_hw *hw) |
| 1278 | { |
Alexander Duyck | 12645a1 | 2009-07-23 18:08:16 +0000 | [diff] [blame] | 1279 | u32 ctrl; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1280 | s32 ret_val; |
Carolyn Wyborny | 867eb39 | 2012-11-13 04:03:20 +0000 | [diff] [blame] | 1281 | u32 phpm_reg; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1282 | |
| 1283 | ctrl = rd32(E1000_CTRL); |
| 1284 | ctrl |= E1000_CTRL_SLU; |
| 1285 | ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX); |
| 1286 | wr32(E1000_CTRL, ctrl); |
| 1287 | |
Carolyn Wyborny | 867eb39 | 2012-11-13 04:03:20 +0000 | [diff] [blame] | 1288 | /* Clear Go Link Disconnect bit */ |
| 1289 | if (hw->mac.type >= e1000_82580) { |
| 1290 | phpm_reg = rd32(E1000_82580_PHY_POWER_MGMT); |
| 1291 | phpm_reg &= ~E1000_82580_PM_GO_LINKD; |
| 1292 | wr32(E1000_82580_PHY_POWER_MGMT, phpm_reg); |
| 1293 | } |
| 1294 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1295 | ret_val = igb_setup_serdes_link_82575(hw); |
| 1296 | if (ret_val) |
| 1297 | goto out; |
| 1298 | |
| 1299 | if (igb_sgmii_active_82575(hw) && !hw->phy.reset_disable) { |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1300 | /* allow time for SFP cage time to power up phy */ |
| 1301 | msleep(300); |
| 1302 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1303 | ret_val = hw->phy.ops.reset(hw); |
| 1304 | if (ret_val) { |
| 1305 | hw_dbg("Error resetting the PHY.\n"); |
| 1306 | goto out; |
| 1307 | } |
| 1308 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1309 | switch (hw->phy.type) { |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1310 | case e1000_phy_i210: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1311 | case e1000_phy_m88: |
Joseph Gasparakis | 308fb39 | 2010-09-22 17:56:44 +0000 | [diff] [blame] | 1312 | if (hw->phy.id == I347AT4_E_PHY_ID || |
| 1313 | hw->phy.id == M88E1112_E_PHY_ID) |
| 1314 | ret_val = igb_copper_link_setup_m88_gen2(hw); |
| 1315 | else |
| 1316 | ret_val = igb_copper_link_setup_m88(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1317 | break; |
| 1318 | case e1000_phy_igp_3: |
| 1319 | ret_val = igb_copper_link_setup_igp(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1320 | break; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1321 | case e1000_phy_82580: |
| 1322 | ret_val = igb_copper_link_setup_82580(hw); |
| 1323 | break; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1324 | default: |
| 1325 | ret_val = -E1000_ERR_PHY; |
| 1326 | break; |
| 1327 | } |
| 1328 | |
| 1329 | if (ret_val) |
| 1330 | goto out; |
| 1331 | |
Alexander Duyck | 81fadd8 | 2009-10-05 06:35:03 +0000 | [diff] [blame] | 1332 | ret_val = igb_setup_copper_link(hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1333 | out: |
| 1334 | return ret_val; |
| 1335 | } |
| 1336 | |
| 1337 | /** |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1338 | * igb_setup_serdes_link_82575 - Setup link for serdes |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1339 | * @hw: pointer to the HW structure |
| 1340 | * |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1341 | * Configure the physical coding sub-layer (PCS) link. The PCS link is |
| 1342 | * used on copper connections where the serialized gigabit media independent |
| 1343 | * interface (sgmii), or serdes fiber is being used. Configures the link |
| 1344 | * for auto-negotiation or forces speed/duplex. |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1345 | **/ |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1346 | static s32 igb_setup_serdes_link_82575(struct e1000_hw *hw) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1347 | { |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1348 | u32 ctrl_ext, ctrl_reg, reg; |
| 1349 | bool pcs_autoneg; |
Carolyn Wyborny | 2c670b5 | 2011-05-24 06:52:51 +0000 | [diff] [blame] | 1350 | s32 ret_val = E1000_SUCCESS; |
| 1351 | u16 data; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1352 | |
| 1353 | if ((hw->phy.media_type != e1000_media_type_internal_serdes) && |
| 1354 | !igb_sgmii_active_82575(hw)) |
Carolyn Wyborny | 2c670b5 | 2011-05-24 06:52:51 +0000 | [diff] [blame] | 1355 | return ret_val; |
| 1356 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1357 | |
| 1358 | /* |
| 1359 | * On the 82575, SerDes loopback mode persists until it is |
| 1360 | * explicitly turned off or a power cycle is performed. A read to |
| 1361 | * the register does not indicate its status. Therefore, we ensure |
| 1362 | * loopback mode is disabled during initialization. |
| 1363 | */ |
| 1364 | wr32(E1000_SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK); |
| 1365 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1366 | /* power on the sfp cage if present */ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1367 | ctrl_ext = rd32(E1000_CTRL_EXT); |
| 1368 | ctrl_ext &= ~E1000_CTRL_EXT_SDP3_DATA; |
| 1369 | wr32(E1000_CTRL_EXT, ctrl_ext); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1370 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1371 | ctrl_reg = rd32(E1000_CTRL); |
| 1372 | ctrl_reg |= E1000_CTRL_SLU; |
| 1373 | |
| 1374 | if (hw->mac.type == e1000_82575 || hw->mac.type == e1000_82576) { |
| 1375 | /* set both sw defined pins */ |
| 1376 | ctrl_reg |= E1000_CTRL_SWDPIN0 | E1000_CTRL_SWDPIN1; |
| 1377 | |
| 1378 | /* Set switch control to serdes energy detect */ |
| 1379 | reg = rd32(E1000_CONNSW); |
| 1380 | reg |= E1000_CONNSW_ENRGSRC; |
| 1381 | wr32(E1000_CONNSW, reg); |
Alexander Duyck | 921aa74 | 2009-01-21 14:42:28 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1384 | reg = rd32(E1000_PCS_LCTL); |
| 1385 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1386 | /* default pcs_autoneg to the same setting as mac autoneg */ |
| 1387 | pcs_autoneg = hw->mac.autoneg; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1388 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1389 | switch (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK) { |
| 1390 | case E1000_CTRL_EXT_LINK_MODE_SGMII: |
| 1391 | /* sgmii mode lets the phy handle forcing speed/duplex */ |
| 1392 | pcs_autoneg = true; |
| 1393 | /* autoneg time out should be disabled for SGMII mode */ |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1394 | reg &= ~(E1000_PCS_LCTL_AN_TIMEOUT); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | case E1000_CTRL_EXT_LINK_MODE_1000BASE_KX: |
| 1397 | /* disable PCS autoneg and support parallel detect only */ |
| 1398 | pcs_autoneg = false; |
| 1399 | default: |
Carolyn Wyborny | 2c670b5 | 2011-05-24 06:52:51 +0000 | [diff] [blame] | 1400 | if (hw->mac.type == e1000_82575 || |
| 1401 | hw->mac.type == e1000_82576) { |
| 1402 | ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &data); |
| 1403 | if (ret_val) { |
| 1404 | printk(KERN_DEBUG "NVM Read Error\n\n"); |
| 1405 | return ret_val; |
| 1406 | } |
| 1407 | |
| 1408 | if (data & E1000_EEPROM_PCS_AUTONEG_DISABLE_BIT) |
| 1409 | pcs_autoneg = false; |
| 1410 | } |
| 1411 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1412 | /* |
| 1413 | * non-SGMII modes only supports a speed of 1000/Full for the |
| 1414 | * link so it is best to just force the MAC and let the pcs |
| 1415 | * link either autoneg or be forced to 1000/Full |
| 1416 | */ |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1417 | ctrl_reg |= E1000_CTRL_SPD_1000 | E1000_CTRL_FRCSPD | |
| 1418 | E1000_CTRL_FD | E1000_CTRL_FRCDPX; |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1419 | |
| 1420 | /* set speed of 1000/Full if speed/duplex is forced */ |
| 1421 | reg |= E1000_PCS_LCTL_FSV_1000 | E1000_PCS_LCTL_FDV_FULL; |
| 1422 | break; |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | wr32(E1000_CTRL, ctrl_reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1426 | |
| 1427 | /* |
| 1428 | * New SerDes mode allows for forcing speed or autonegotiating speed |
| 1429 | * at 1gb. Autoneg should be default set by most drivers. This is the |
| 1430 | * mode that will be compatible with older link partners and switches. |
| 1431 | * However, both are supported by the hardware and some drivers/tools. |
| 1432 | */ |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1433 | reg &= ~(E1000_PCS_LCTL_AN_ENABLE | E1000_PCS_LCTL_FLV_LINK_UP | |
| 1434 | E1000_PCS_LCTL_FSD | E1000_PCS_LCTL_FORCE_LINK); |
| 1435 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1436 | /* |
| 1437 | * We force flow control to prevent the CTRL register values from being |
| 1438 | * overwritten by the autonegotiated flow control values |
| 1439 | */ |
| 1440 | reg |= E1000_PCS_LCTL_FORCE_FCTRL; |
| 1441 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1442 | if (pcs_autoneg) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1443 | /* Set PCS register for autoneg */ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1444 | reg |= E1000_PCS_LCTL_AN_ENABLE | /* Enable Autoneg */ |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1445 | E1000_PCS_LCTL_AN_RESTART; /* Restart autoneg */ |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1446 | hw_dbg("Configuring Autoneg:PCS_LCTL=0x%08X\n", reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1447 | } else { |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1448 | /* Set PCS register for forced link */ |
Alexander Duyck | d68caec | 2009-12-23 13:20:47 +0000 | [diff] [blame] | 1449 | reg |= E1000_PCS_LCTL_FSD; /* Force Speed */ |
Alexander Duyck | 70d92f8 | 2009-10-05 06:31:47 +0000 | [diff] [blame] | 1450 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1451 | hw_dbg("Configuring Forced Link:PCS_LCTL=0x%08X\n", reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1452 | } |
Alexander Duyck | 726c09e | 2008-08-04 14:59:56 -0700 | [diff] [blame] | 1453 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1454 | wr32(E1000_PCS_LCTL, reg); |
| 1455 | |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1456 | if (!igb_sgmii_active_82575(hw)) |
| 1457 | igb_force_mac_fc(hw); |
| 1458 | |
Carolyn Wyborny | 2c670b5 | 2011-05-24 06:52:51 +0000 | [diff] [blame] | 1459 | return ret_val; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1463 | * igb_sgmii_active_82575 - Return sgmii state |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1464 | * @hw: pointer to the HW structure |
| 1465 | * |
| 1466 | * 82575 silicon has a serialized gigabit media independent interface (sgmii) |
| 1467 | * which can be enabled for use in the embedded applications. Simply |
| 1468 | * return the current state of the sgmii interface. |
| 1469 | **/ |
| 1470 | static bool igb_sgmii_active_82575(struct e1000_hw *hw) |
| 1471 | { |
Alexander Duyck | c1889bf | 2009-02-06 23:16:45 +0000 | [diff] [blame] | 1472 | struct e1000_dev_spec_82575 *dev_spec = &hw->dev_spec._82575; |
Alexander Duyck | c1889bf | 2009-02-06 23:16:45 +0000 | [diff] [blame] | 1473 | return dev_spec->sgmii_active; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1477 | * igb_reset_init_script_82575 - Inits HW defaults after reset |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1478 | * @hw: pointer to the HW structure |
| 1479 | * |
| 1480 | * Inits recommended HW defaults after a reset when there is no EEPROM |
| 1481 | * detected. This is only for the 82575. |
| 1482 | **/ |
| 1483 | static s32 igb_reset_init_script_82575(struct e1000_hw *hw) |
| 1484 | { |
| 1485 | if (hw->mac.type == e1000_82575) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1486 | hw_dbg("Running reset init script for 82575\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1487 | /* SerDes configuration via SERDESCTRL */ |
| 1488 | igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x00, 0x0C); |
| 1489 | igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x01, 0x78); |
| 1490 | igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x1B, 0x23); |
| 1491 | igb_write_8bit_ctrl_reg(hw, E1000_SCTL, 0x23, 0x15); |
| 1492 | |
| 1493 | /* CCM configuration via CCMCTL register */ |
| 1494 | igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x14, 0x00); |
| 1495 | igb_write_8bit_ctrl_reg(hw, E1000_CCMCTL, 0x10, 0x00); |
| 1496 | |
| 1497 | /* PCIe lanes configuration */ |
| 1498 | igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x00, 0xEC); |
| 1499 | igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x61, 0xDF); |
| 1500 | igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x34, 0x05); |
| 1501 | igb_write_8bit_ctrl_reg(hw, E1000_GIOCTL, 0x2F, 0x81); |
| 1502 | |
| 1503 | /* PCIe PLL Configuration */ |
| 1504 | igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x02, 0x47); |
| 1505 | igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x14, 0x00); |
| 1506 | igb_write_8bit_ctrl_reg(hw, E1000_SCCTL, 0x10, 0x00); |
| 1507 | } |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1513 | * igb_read_mac_addr_82575 - Read device MAC address |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1514 | * @hw: pointer to the HW structure |
| 1515 | **/ |
| 1516 | static s32 igb_read_mac_addr_82575(struct e1000_hw *hw) |
| 1517 | { |
| 1518 | s32 ret_val = 0; |
| 1519 | |
Alexander Duyck | 2289663 | 2009-10-05 06:34:25 +0000 | [diff] [blame] | 1520 | /* |
| 1521 | * If there's an alternate MAC address place it in RAR0 |
| 1522 | * so that it will override the Si installed default perm |
| 1523 | * address. |
| 1524 | */ |
| 1525 | ret_val = igb_check_alt_mac_addr(hw); |
| 1526 | if (ret_val) |
| 1527 | goto out; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1528 | |
Alexander Duyck | 2289663 | 2009-10-05 06:34:25 +0000 | [diff] [blame] | 1529 | ret_val = igb_read_mac_addr(hw); |
| 1530 | |
| 1531 | out: |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1532 | return ret_val; |
| 1533 | } |
| 1534 | |
| 1535 | /** |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1536 | * igb_power_down_phy_copper_82575 - Remove link during PHY power down |
| 1537 | * @hw: pointer to the HW structure |
| 1538 | * |
| 1539 | * In the case of a PHY power down to save power, or to turn off link during a |
| 1540 | * driver unload, or wake on lan is not enabled, remove the link. |
| 1541 | **/ |
| 1542 | void igb_power_down_phy_copper_82575(struct e1000_hw *hw) |
| 1543 | { |
| 1544 | /* If the management interface is not enabled, then power down */ |
| 1545 | if (!(igb_enable_mng_pass_thru(hw) || igb_check_reset_block(hw))) |
| 1546 | igb_power_down_phy_copper(hw); |
Nick Nunley | 88a268c | 2010-02-17 01:01:59 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1550 | * igb_clear_hw_cntrs_82575 - Clear device specific hardware counters |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1551 | * @hw: pointer to the HW structure |
| 1552 | * |
| 1553 | * Clears the hardware counters by reading the counter registers. |
| 1554 | **/ |
| 1555 | static void igb_clear_hw_cntrs_82575(struct e1000_hw *hw) |
| 1556 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1557 | igb_clear_hw_cntrs_base(hw); |
| 1558 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1559 | rd32(E1000_PRC64); |
| 1560 | rd32(E1000_PRC127); |
| 1561 | rd32(E1000_PRC255); |
| 1562 | rd32(E1000_PRC511); |
| 1563 | rd32(E1000_PRC1023); |
| 1564 | rd32(E1000_PRC1522); |
| 1565 | rd32(E1000_PTC64); |
| 1566 | rd32(E1000_PTC127); |
| 1567 | rd32(E1000_PTC255); |
| 1568 | rd32(E1000_PTC511); |
| 1569 | rd32(E1000_PTC1023); |
| 1570 | rd32(E1000_PTC1522); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1571 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1572 | rd32(E1000_ALGNERRC); |
| 1573 | rd32(E1000_RXERRC); |
| 1574 | rd32(E1000_TNCRS); |
| 1575 | rd32(E1000_CEXTERR); |
| 1576 | rd32(E1000_TSCTC); |
| 1577 | rd32(E1000_TSCTFC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1578 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1579 | rd32(E1000_MGTPRC); |
| 1580 | rd32(E1000_MGTPDC); |
| 1581 | rd32(E1000_MGTPTC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1582 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1583 | rd32(E1000_IAC); |
| 1584 | rd32(E1000_ICRXOC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1585 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1586 | rd32(E1000_ICRXPTC); |
| 1587 | rd32(E1000_ICRXATC); |
| 1588 | rd32(E1000_ICTXPTC); |
| 1589 | rd32(E1000_ICTXATC); |
| 1590 | rd32(E1000_ICTXQEC); |
| 1591 | rd32(E1000_ICTXQMTC); |
| 1592 | rd32(E1000_ICRXDMTC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1593 | |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1594 | rd32(E1000_CBTMPC); |
| 1595 | rd32(E1000_HTDPMC); |
| 1596 | rd32(E1000_CBRMPC); |
| 1597 | rd32(E1000_RPTHC); |
| 1598 | rd32(E1000_HGPTC); |
| 1599 | rd32(E1000_HTCBDPC); |
| 1600 | rd32(E1000_HGORCL); |
| 1601 | rd32(E1000_HGORCH); |
| 1602 | rd32(E1000_HGOTCL); |
| 1603 | rd32(E1000_HGOTCH); |
| 1604 | rd32(E1000_LENERRS); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1605 | |
| 1606 | /* This register should not be read in copper configurations */ |
Alexander Duyck | 2fb02a2 | 2009-09-14 08:22:54 +0000 | [diff] [blame] | 1607 | if (hw->phy.media_type == e1000_media_type_internal_serdes || |
| 1608 | igb_sgmii_active_82575(hw)) |
Alexander Duyck | cc9073b | 2009-10-05 06:31:25 +0000 | [diff] [blame] | 1609 | rd32(E1000_SCVPC); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1610 | } |
| 1611 | |
Alexander Duyck | 662d720 | 2008-06-27 11:00:29 -0700 | [diff] [blame] | 1612 | /** |
| 1613 | * igb_rx_fifo_flush_82575 - Clean rx fifo after RX enable |
| 1614 | * @hw: pointer to the HW structure |
| 1615 | * |
| 1616 | * After rx enable if managability is enabled then there is likely some |
| 1617 | * bad data at the start of the fifo and possibly in the DMA fifo. This |
| 1618 | * function clears the fifos and flushes any packets that came in as rx was |
| 1619 | * being enabled. |
| 1620 | **/ |
| 1621 | void igb_rx_fifo_flush_82575(struct e1000_hw *hw) |
| 1622 | { |
| 1623 | u32 rctl, rlpml, rxdctl[4], rfctl, temp_rctl, rx_enabled; |
| 1624 | int i, ms_wait; |
| 1625 | |
| 1626 | if (hw->mac.type != e1000_82575 || |
| 1627 | !(rd32(E1000_MANC) & E1000_MANC_RCV_TCO_EN)) |
| 1628 | return; |
| 1629 | |
| 1630 | /* Disable all RX queues */ |
| 1631 | for (i = 0; i < 4; i++) { |
| 1632 | rxdctl[i] = rd32(E1000_RXDCTL(i)); |
| 1633 | wr32(E1000_RXDCTL(i), |
| 1634 | rxdctl[i] & ~E1000_RXDCTL_QUEUE_ENABLE); |
| 1635 | } |
| 1636 | /* Poll all queues to verify they have shut down */ |
| 1637 | for (ms_wait = 0; ms_wait < 10; ms_wait++) { |
| 1638 | msleep(1); |
| 1639 | rx_enabled = 0; |
| 1640 | for (i = 0; i < 4; i++) |
| 1641 | rx_enabled |= rd32(E1000_RXDCTL(i)); |
| 1642 | if (!(rx_enabled & E1000_RXDCTL_QUEUE_ENABLE)) |
| 1643 | break; |
| 1644 | } |
| 1645 | |
| 1646 | if (ms_wait == 10) |
| 1647 | hw_dbg("Queue disable timed out after 10ms\n"); |
| 1648 | |
| 1649 | /* Clear RLPML, RCTL.SBP, RFCTL.LEF, and set RCTL.LPE so that all |
| 1650 | * incoming packets are rejected. Set enable and wait 2ms so that |
| 1651 | * any packet that was coming in as RCTL.EN was set is flushed |
| 1652 | */ |
| 1653 | rfctl = rd32(E1000_RFCTL); |
| 1654 | wr32(E1000_RFCTL, rfctl & ~E1000_RFCTL_LEF); |
| 1655 | |
| 1656 | rlpml = rd32(E1000_RLPML); |
| 1657 | wr32(E1000_RLPML, 0); |
| 1658 | |
| 1659 | rctl = rd32(E1000_RCTL); |
| 1660 | temp_rctl = rctl & ~(E1000_RCTL_EN | E1000_RCTL_SBP); |
| 1661 | temp_rctl |= E1000_RCTL_LPE; |
| 1662 | |
| 1663 | wr32(E1000_RCTL, temp_rctl); |
| 1664 | wr32(E1000_RCTL, temp_rctl | E1000_RCTL_EN); |
| 1665 | wrfl(); |
| 1666 | msleep(2); |
| 1667 | |
| 1668 | /* Enable RX queues that were previously enabled and restore our |
| 1669 | * previous state |
| 1670 | */ |
| 1671 | for (i = 0; i < 4; i++) |
| 1672 | wr32(E1000_RXDCTL(i), rxdctl[i]); |
| 1673 | wr32(E1000_RCTL, rctl); |
| 1674 | wrfl(); |
| 1675 | |
| 1676 | wr32(E1000_RLPML, rlpml); |
| 1677 | wr32(E1000_RFCTL, rfctl); |
| 1678 | |
| 1679 | /* Flush receive errors generated by workaround */ |
| 1680 | rd32(E1000_ROC); |
| 1681 | rd32(E1000_RNBC); |
| 1682 | rd32(E1000_MPC); |
| 1683 | } |
| 1684 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1685 | /** |
Alexander Duyck | 009bc06 | 2009-07-23 18:08:35 +0000 | [diff] [blame] | 1686 | * igb_set_pcie_completion_timeout - set pci-e completion timeout |
| 1687 | * @hw: pointer to the HW structure |
| 1688 | * |
| 1689 | * The defaults for 82575 and 82576 should be in the range of 50us to 50ms, |
| 1690 | * however the hardware default for these parts is 500us to 1ms which is less |
| 1691 | * than the 10ms recommended by the pci-e spec. To address this we need to |
| 1692 | * increase the value to either 10ms to 200ms for capability version 1 config, |
| 1693 | * or 16ms to 55ms for version 2. |
| 1694 | **/ |
| 1695 | static s32 igb_set_pcie_completion_timeout(struct e1000_hw *hw) |
| 1696 | { |
| 1697 | u32 gcr = rd32(E1000_GCR); |
| 1698 | s32 ret_val = 0; |
| 1699 | u16 pcie_devctl2; |
| 1700 | |
| 1701 | /* only take action if timeout value is defaulted to 0 */ |
| 1702 | if (gcr & E1000_GCR_CMPL_TMOUT_MASK) |
| 1703 | goto out; |
| 1704 | |
| 1705 | /* |
| 1706 | * if capababilities version is type 1 we can write the |
| 1707 | * timeout of 10ms to 200ms through the GCR register |
| 1708 | */ |
| 1709 | if (!(gcr & E1000_GCR_CAP_VER2)) { |
| 1710 | gcr |= E1000_GCR_CMPL_TMOUT_10ms; |
| 1711 | goto out; |
| 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * for version 2 capabilities we need to write the config space |
| 1716 | * directly in order to set the completion timeout value for |
| 1717 | * 16ms to 55ms |
| 1718 | */ |
| 1719 | ret_val = igb_read_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2, |
| 1720 | &pcie_devctl2); |
| 1721 | if (ret_val) |
| 1722 | goto out; |
| 1723 | |
| 1724 | pcie_devctl2 |= PCIE_DEVICE_CONTROL2_16ms; |
| 1725 | |
| 1726 | ret_val = igb_write_pcie_cap_reg(hw, PCIE_DEVICE_CONTROL2, |
| 1727 | &pcie_devctl2); |
| 1728 | out: |
| 1729 | /* disable completion timeout resend */ |
| 1730 | gcr &= ~E1000_GCR_CMPL_TMOUT_RESEND; |
| 1731 | |
| 1732 | wr32(E1000_GCR, gcr); |
| 1733 | return ret_val; |
| 1734 | } |
| 1735 | |
| 1736 | /** |
Greg Rose | 1380046 | 2010-11-06 02:08:26 +0000 | [diff] [blame] | 1737 | * igb_vmdq_set_anti_spoofing_pf - enable or disable anti-spoofing |
| 1738 | * @hw: pointer to the hardware struct |
| 1739 | * @enable: state to enter, either enabled or disabled |
| 1740 | * @pf: Physical Function pool - do not set anti-spoofing for the PF |
| 1741 | * |
| 1742 | * enables/disables L2 switch anti-spoofing functionality. |
| 1743 | **/ |
| 1744 | void igb_vmdq_set_anti_spoofing_pf(struct e1000_hw *hw, bool enable, int pf) |
| 1745 | { |
| 1746 | u32 dtxswc; |
| 1747 | |
| 1748 | switch (hw->mac.type) { |
| 1749 | case e1000_82576: |
| 1750 | case e1000_i350: |
| 1751 | dtxswc = rd32(E1000_DTXSWC); |
| 1752 | if (enable) { |
| 1753 | dtxswc |= (E1000_DTXSWC_MAC_SPOOF_MASK | |
| 1754 | E1000_DTXSWC_VLAN_SPOOF_MASK); |
| 1755 | /* The PF can spoof - it has to in order to |
| 1756 | * support emulation mode NICs */ |
| 1757 | dtxswc ^= (1 << pf | 1 << (pf + MAX_NUM_VFS)); |
| 1758 | } else { |
| 1759 | dtxswc &= ~(E1000_DTXSWC_MAC_SPOOF_MASK | |
| 1760 | E1000_DTXSWC_VLAN_SPOOF_MASK); |
| 1761 | } |
| 1762 | wr32(E1000_DTXSWC, dtxswc); |
| 1763 | break; |
| 1764 | default: |
| 1765 | break; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | /** |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1770 | * igb_vmdq_set_loopback_pf - enable or disable vmdq loopback |
| 1771 | * @hw: pointer to the hardware struct |
| 1772 | * @enable: state to enter, either enabled or disabled |
| 1773 | * |
| 1774 | * enables/disables L2 switch loopback functionality. |
| 1775 | **/ |
| 1776 | void igb_vmdq_set_loopback_pf(struct e1000_hw *hw, bool enable) |
| 1777 | { |
Akeem G. Abodunrin | ca2e3e7 | 2011-09-08 20:39:48 +0000 | [diff] [blame] | 1778 | u32 dtxswc; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1779 | |
Akeem G. Abodunrin | ca2e3e7 | 2011-09-08 20:39:48 +0000 | [diff] [blame] | 1780 | switch (hw->mac.type) { |
| 1781 | case e1000_82576: |
| 1782 | dtxswc = rd32(E1000_DTXSWC); |
| 1783 | if (enable) |
| 1784 | dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN; |
| 1785 | else |
| 1786 | dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN; |
| 1787 | wr32(E1000_DTXSWC, dtxswc); |
| 1788 | break; |
| 1789 | case e1000_i350: |
| 1790 | dtxswc = rd32(E1000_TXSWC); |
| 1791 | if (enable) |
| 1792 | dtxswc |= E1000_DTXSWC_VMDQ_LOOPBACK_EN; |
| 1793 | else |
| 1794 | dtxswc &= ~E1000_DTXSWC_VMDQ_LOOPBACK_EN; |
| 1795 | wr32(E1000_TXSWC, dtxswc); |
| 1796 | break; |
| 1797 | default: |
| 1798 | /* Currently no other hardware supports loopback */ |
| 1799 | break; |
| 1800 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1801 | |
Akeem G. Abodunrin | ca2e3e7 | 2011-09-08 20:39:48 +0000 | [diff] [blame] | 1802 | |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * igb_vmdq_set_replication_pf - enable or disable vmdq replication |
| 1807 | * @hw: pointer to the hardware struct |
| 1808 | * @enable: state to enter, either enabled or disabled |
| 1809 | * |
| 1810 | * enables/disables replication of packets across multiple pools. |
| 1811 | **/ |
| 1812 | void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable) |
| 1813 | { |
| 1814 | u32 vt_ctl = rd32(E1000_VT_CTL); |
| 1815 | |
| 1816 | if (enable) |
| 1817 | vt_ctl |= E1000_VT_CTL_VM_REPL_EN; |
| 1818 | else |
| 1819 | vt_ctl &= ~E1000_VT_CTL_VM_REPL_EN; |
| 1820 | |
| 1821 | wr32(E1000_VT_CTL, vt_ctl); |
| 1822 | } |
| 1823 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1824 | /** |
| 1825 | * igb_read_phy_reg_82580 - Read 82580 MDI control register |
| 1826 | * @hw: pointer to the HW structure |
| 1827 | * @offset: register offset to be read |
| 1828 | * @data: pointer to the read data |
| 1829 | * |
| 1830 | * Reads the MDI control register in the PHY at offset and stores the |
| 1831 | * information read to data. |
| 1832 | **/ |
| 1833 | static s32 igb_read_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 *data) |
| 1834 | { |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1835 | s32 ret_val; |
| 1836 | |
| 1837 | |
| 1838 | ret_val = hw->phy.ops.acquire(hw); |
| 1839 | if (ret_val) |
| 1840 | goto out; |
| 1841 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1842 | ret_val = igb_read_phy_reg_mdic(hw, offset, data); |
| 1843 | |
| 1844 | hw->phy.ops.release(hw); |
| 1845 | |
| 1846 | out: |
| 1847 | return ret_val; |
| 1848 | } |
| 1849 | |
| 1850 | /** |
| 1851 | * igb_write_phy_reg_82580 - Write 82580 MDI control register |
| 1852 | * @hw: pointer to the HW structure |
| 1853 | * @offset: register offset to write to |
| 1854 | * @data: data to write to register at offset |
| 1855 | * |
| 1856 | * Writes data to MDI control register in the PHY at offset. |
| 1857 | **/ |
| 1858 | static s32 igb_write_phy_reg_82580(struct e1000_hw *hw, u32 offset, u16 data) |
| 1859 | { |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1860 | s32 ret_val; |
| 1861 | |
| 1862 | |
| 1863 | ret_val = hw->phy.ops.acquire(hw); |
| 1864 | if (ret_val) |
| 1865 | goto out; |
| 1866 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1867 | ret_val = igb_write_phy_reg_mdic(hw, offset, data); |
| 1868 | |
| 1869 | hw->phy.ops.release(hw); |
| 1870 | |
| 1871 | out: |
| 1872 | return ret_val; |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Nick Nunley | 08451e2 | 2010-07-26 13:15:29 +0000 | [diff] [blame] | 1876 | * igb_reset_mdicnfg_82580 - Reset MDICNFG destination and com_mdio bits |
| 1877 | * @hw: pointer to the HW structure |
| 1878 | * |
| 1879 | * This resets the the MDICNFG.Destination and MDICNFG.Com_MDIO bits based on |
| 1880 | * the values found in the EEPROM. This addresses an issue in which these |
| 1881 | * bits are not restored from EEPROM after reset. |
| 1882 | **/ |
| 1883 | static s32 igb_reset_mdicnfg_82580(struct e1000_hw *hw) |
| 1884 | { |
| 1885 | s32 ret_val = 0; |
| 1886 | u32 mdicnfg; |
Gasparakis, Joseph | 1b5dda3 | 2010-12-09 01:41:01 +0000 | [diff] [blame] | 1887 | u16 nvm_data = 0; |
Nick Nunley | 08451e2 | 2010-07-26 13:15:29 +0000 | [diff] [blame] | 1888 | |
| 1889 | if (hw->mac.type != e1000_82580) |
| 1890 | goto out; |
| 1891 | if (!igb_sgmii_active_82575(hw)) |
| 1892 | goto out; |
| 1893 | |
| 1894 | ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A + |
| 1895 | NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1, |
| 1896 | &nvm_data); |
| 1897 | if (ret_val) { |
| 1898 | hw_dbg("NVM Read Error\n"); |
| 1899 | goto out; |
| 1900 | } |
| 1901 | |
| 1902 | mdicnfg = rd32(E1000_MDICNFG); |
| 1903 | if (nvm_data & NVM_WORD24_EXT_MDIO) |
| 1904 | mdicnfg |= E1000_MDICNFG_EXT_MDIO; |
| 1905 | if (nvm_data & NVM_WORD24_COM_MDIO) |
| 1906 | mdicnfg |= E1000_MDICNFG_COM_MDIO; |
| 1907 | wr32(E1000_MDICNFG, mdicnfg); |
| 1908 | out: |
| 1909 | return ret_val; |
| 1910 | } |
| 1911 | |
| 1912 | /** |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1913 | * igb_reset_hw_82580 - Reset hardware |
| 1914 | * @hw: pointer to the HW structure |
| 1915 | * |
| 1916 | * This resets function or entire device (all ports, etc.) |
| 1917 | * to a known state. |
| 1918 | **/ |
| 1919 | static s32 igb_reset_hw_82580(struct e1000_hw *hw) |
| 1920 | { |
| 1921 | s32 ret_val = 0; |
| 1922 | /* BH SW mailbox bit in SW_FW_SYNC */ |
| 1923 | u16 swmbsw_mask = E1000_SW_SYNCH_MB; |
| 1924 | u32 ctrl, icr; |
| 1925 | bool global_device_reset = hw->dev_spec._82575.global_device_reset; |
| 1926 | |
| 1927 | |
| 1928 | hw->dev_spec._82575.global_device_reset = false; |
| 1929 | |
| 1930 | /* Get current control state. */ |
| 1931 | ctrl = rd32(E1000_CTRL); |
| 1932 | |
| 1933 | /* |
| 1934 | * Prevent the PCI-E bus from sticking if there is no TLP connection |
| 1935 | * on the last TLP read/write transaction when MAC is reset. |
| 1936 | */ |
| 1937 | ret_val = igb_disable_pcie_master(hw); |
| 1938 | if (ret_val) |
| 1939 | hw_dbg("PCI-E Master disable polling has failed.\n"); |
| 1940 | |
| 1941 | hw_dbg("Masking off all interrupts\n"); |
| 1942 | wr32(E1000_IMC, 0xffffffff); |
| 1943 | wr32(E1000_RCTL, 0); |
| 1944 | wr32(E1000_TCTL, E1000_TCTL_PSP); |
| 1945 | wrfl(); |
| 1946 | |
| 1947 | msleep(10); |
| 1948 | |
| 1949 | /* Determine whether or not a global dev reset is requested */ |
| 1950 | if (global_device_reset && |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1951 | hw->mac.ops.acquire_swfw_sync(hw, swmbsw_mask)) |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1952 | global_device_reset = false; |
| 1953 | |
| 1954 | if (global_device_reset && |
| 1955 | !(rd32(E1000_STATUS) & E1000_STAT_DEV_RST_SET)) |
| 1956 | ctrl |= E1000_CTRL_DEV_RST; |
| 1957 | else |
| 1958 | ctrl |= E1000_CTRL_RST; |
| 1959 | |
| 1960 | wr32(E1000_CTRL, ctrl); |
Carolyn Wyborny | 064b433 | 2011-06-25 13:18:12 +0000 | [diff] [blame] | 1961 | wrfl(); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1962 | |
| 1963 | /* Add delay to insure DEV_RST has time to complete */ |
| 1964 | if (global_device_reset) |
| 1965 | msleep(5); |
| 1966 | |
| 1967 | ret_val = igb_get_auto_rd_done(hw); |
| 1968 | if (ret_val) { |
| 1969 | /* |
| 1970 | * When auto config read does not complete, do not |
| 1971 | * return with an error. This can happen in situations |
| 1972 | * where there is no eeprom and prevents getting link. |
| 1973 | */ |
| 1974 | hw_dbg("Auto Read Done did not complete\n"); |
| 1975 | } |
| 1976 | |
| 1977 | /* If EEPROM is not present, run manual init scripts */ |
| 1978 | if ((rd32(E1000_EECD) & E1000_EECD_PRES) == 0) |
| 1979 | igb_reset_init_script_82575(hw); |
| 1980 | |
| 1981 | /* clear global device reset status bit */ |
| 1982 | wr32(E1000_STATUS, E1000_STAT_DEV_RST_SET); |
| 1983 | |
| 1984 | /* Clear any pending interrupt events. */ |
| 1985 | wr32(E1000_IMC, 0xffffffff); |
| 1986 | icr = rd32(E1000_ICR); |
| 1987 | |
Nick Nunley | 08451e2 | 2010-07-26 13:15:29 +0000 | [diff] [blame] | 1988 | ret_val = igb_reset_mdicnfg_82580(hw); |
| 1989 | if (ret_val) |
| 1990 | hw_dbg("Could not reset MDICNFG based on EEPROM\n"); |
| 1991 | |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1992 | /* Install any alternate MAC address into RAR0 */ |
| 1993 | ret_val = igb_check_alt_mac_addr(hw); |
| 1994 | |
| 1995 | /* Release semaphore */ |
| 1996 | if (global_device_reset) |
Carolyn Wyborny | f96a8a0 | 2012-04-06 23:25:19 +0000 | [diff] [blame] | 1997 | hw->mac.ops.release_swfw_sync(hw, swmbsw_mask); |
Alexander Duyck | bb2ac47 | 2009-11-19 12:42:01 +0000 | [diff] [blame] | 1998 | |
| 1999 | return ret_val; |
| 2000 | } |
| 2001 | |
| 2002 | /** |
| 2003 | * igb_rxpbs_adjust_82580 - adjust RXPBS value to reflect actual RX PBA size |
| 2004 | * @data: data received by reading RXPBS register |
| 2005 | * |
| 2006 | * The 82580 uses a table based approach for packet buffer allocation sizes. |
| 2007 | * This function converts the retrieved value into the correct table value |
| 2008 | * 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 |
| 2009 | * 0x0 36 72 144 1 2 4 8 16 |
| 2010 | * 0x8 35 70 140 rsv rsv rsv rsv rsv |
| 2011 | */ |
| 2012 | u16 igb_rxpbs_adjust_82580(u32 data) |
| 2013 | { |
| 2014 | u16 ret_val = 0; |
| 2015 | |
| 2016 | if (data < E1000_82580_RXPBS_TABLE_SIZE) |
| 2017 | ret_val = e1000_82580_rxpbs_table[data]; |
| 2018 | |
| 2019 | return ret_val; |
| 2020 | } |
| 2021 | |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2022 | /** |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2023 | * igb_validate_nvm_checksum_with_offset - Validate EEPROM |
| 2024 | * checksum |
| 2025 | * @hw: pointer to the HW structure |
| 2026 | * @offset: offset in words of the checksum protected region |
| 2027 | * |
| 2028 | * Calculates the EEPROM checksum by reading/adding each word of the EEPROM |
| 2029 | * and then verifies that the sum of the EEPROM is equal to 0xBABA. |
| 2030 | **/ |
Emil Tantilov | bed45a6 | 2011-08-30 06:35:04 +0000 | [diff] [blame] | 2031 | static s32 igb_validate_nvm_checksum_with_offset(struct e1000_hw *hw, |
| 2032 | u16 offset) |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2033 | { |
| 2034 | s32 ret_val = 0; |
| 2035 | u16 checksum = 0; |
| 2036 | u16 i, nvm_data; |
| 2037 | |
| 2038 | for (i = offset; i < ((NVM_CHECKSUM_REG + offset) + 1); i++) { |
| 2039 | ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); |
| 2040 | if (ret_val) { |
| 2041 | hw_dbg("NVM Read Error\n"); |
| 2042 | goto out; |
| 2043 | } |
| 2044 | checksum += nvm_data; |
| 2045 | } |
| 2046 | |
| 2047 | if (checksum != (u16) NVM_SUM) { |
| 2048 | hw_dbg("NVM Checksum Invalid\n"); |
| 2049 | ret_val = -E1000_ERR_NVM; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | |
| 2053 | out: |
| 2054 | return ret_val; |
| 2055 | } |
| 2056 | |
| 2057 | /** |
| 2058 | * igb_update_nvm_checksum_with_offset - Update EEPROM |
| 2059 | * checksum |
| 2060 | * @hw: pointer to the HW structure |
| 2061 | * @offset: offset in words of the checksum protected region |
| 2062 | * |
| 2063 | * Updates the EEPROM checksum by reading/adding each word of the EEPROM |
| 2064 | * up to the checksum. Then calculates the EEPROM checksum and writes the |
| 2065 | * value to the EEPROM. |
| 2066 | **/ |
Emil Tantilov | bed45a6 | 2011-08-30 06:35:04 +0000 | [diff] [blame] | 2067 | static s32 igb_update_nvm_checksum_with_offset(struct e1000_hw *hw, u16 offset) |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2068 | { |
| 2069 | s32 ret_val; |
| 2070 | u16 checksum = 0; |
| 2071 | u16 i, nvm_data; |
| 2072 | |
| 2073 | for (i = offset; i < (NVM_CHECKSUM_REG + offset); i++) { |
| 2074 | ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); |
| 2075 | if (ret_val) { |
| 2076 | hw_dbg("NVM Read Error while updating checksum.\n"); |
| 2077 | goto out; |
| 2078 | } |
| 2079 | checksum += nvm_data; |
| 2080 | } |
| 2081 | checksum = (u16) NVM_SUM - checksum; |
| 2082 | ret_val = hw->nvm.ops.write(hw, (NVM_CHECKSUM_REG + offset), 1, |
| 2083 | &checksum); |
| 2084 | if (ret_val) |
| 2085 | hw_dbg("NVM Write Error while updating checksum.\n"); |
| 2086 | |
| 2087 | out: |
| 2088 | return ret_val; |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * igb_validate_nvm_checksum_82580 - Validate EEPROM checksum |
| 2093 | * @hw: pointer to the HW structure |
| 2094 | * |
| 2095 | * Calculates the EEPROM section checksum by reading/adding each word of |
| 2096 | * the EEPROM and then verifies that the sum of the EEPROM is |
| 2097 | * equal to 0xBABA. |
| 2098 | **/ |
| 2099 | static s32 igb_validate_nvm_checksum_82580(struct e1000_hw *hw) |
| 2100 | { |
| 2101 | s32 ret_val = 0; |
| 2102 | u16 eeprom_regions_count = 1; |
| 2103 | u16 j, nvm_data; |
| 2104 | u16 nvm_offset; |
| 2105 | |
| 2106 | ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data); |
| 2107 | if (ret_val) { |
| 2108 | hw_dbg("NVM Read Error\n"); |
| 2109 | goto out; |
| 2110 | } |
| 2111 | |
| 2112 | if (nvm_data & NVM_COMPATIBILITY_BIT_MASK) { |
Stefan Assmann | 34a0326 | 2011-04-05 04:27:05 +0000 | [diff] [blame] | 2113 | /* if checksums compatibility bit is set validate checksums |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2114 | * for all 4 ports. */ |
| 2115 | eeprom_regions_count = 4; |
| 2116 | } |
| 2117 | |
| 2118 | for (j = 0; j < eeprom_regions_count; j++) { |
| 2119 | nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j); |
| 2120 | ret_val = igb_validate_nvm_checksum_with_offset(hw, |
| 2121 | nvm_offset); |
| 2122 | if (ret_val != 0) |
| 2123 | goto out; |
| 2124 | } |
| 2125 | |
| 2126 | out: |
| 2127 | return ret_val; |
| 2128 | } |
| 2129 | |
| 2130 | /** |
| 2131 | * igb_update_nvm_checksum_82580 - Update EEPROM checksum |
| 2132 | * @hw: pointer to the HW structure |
| 2133 | * |
| 2134 | * Updates the EEPROM section checksums for all 4 ports by reading/adding |
| 2135 | * each word of the EEPROM up to the checksum. Then calculates the EEPROM |
| 2136 | * checksum and writes the value to the EEPROM. |
| 2137 | **/ |
| 2138 | static s32 igb_update_nvm_checksum_82580(struct e1000_hw *hw) |
| 2139 | { |
| 2140 | s32 ret_val; |
| 2141 | u16 j, nvm_data; |
| 2142 | u16 nvm_offset; |
| 2143 | |
| 2144 | ret_val = hw->nvm.ops.read(hw, NVM_COMPATIBILITY_REG_3, 1, &nvm_data); |
| 2145 | if (ret_val) { |
| 2146 | hw_dbg("NVM Read Error while updating checksum" |
| 2147 | " compatibility bit.\n"); |
| 2148 | goto out; |
| 2149 | } |
| 2150 | |
| 2151 | if ((nvm_data & NVM_COMPATIBILITY_BIT_MASK) == 0) { |
| 2152 | /* set compatibility bit to validate checksums appropriately */ |
| 2153 | nvm_data = nvm_data | NVM_COMPATIBILITY_BIT_MASK; |
| 2154 | ret_val = hw->nvm.ops.write(hw, NVM_COMPATIBILITY_REG_3, 1, |
| 2155 | &nvm_data); |
| 2156 | if (ret_val) { |
| 2157 | hw_dbg("NVM Write Error while updating checksum" |
| 2158 | " compatibility bit.\n"); |
| 2159 | goto out; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | for (j = 0; j < 4; j++) { |
| 2164 | nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j); |
| 2165 | ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset); |
| 2166 | if (ret_val) |
| 2167 | goto out; |
| 2168 | } |
| 2169 | |
| 2170 | out: |
| 2171 | return ret_val; |
| 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * igb_validate_nvm_checksum_i350 - Validate EEPROM checksum |
| 2176 | * @hw: pointer to the HW structure |
| 2177 | * |
| 2178 | * Calculates the EEPROM section checksum by reading/adding each word of |
| 2179 | * the EEPROM and then verifies that the sum of the EEPROM is |
| 2180 | * equal to 0xBABA. |
| 2181 | **/ |
| 2182 | static s32 igb_validate_nvm_checksum_i350(struct e1000_hw *hw) |
| 2183 | { |
| 2184 | s32 ret_val = 0; |
| 2185 | u16 j; |
| 2186 | u16 nvm_offset; |
| 2187 | |
| 2188 | for (j = 0; j < 4; j++) { |
| 2189 | nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j); |
| 2190 | ret_val = igb_validate_nvm_checksum_with_offset(hw, |
| 2191 | nvm_offset); |
| 2192 | if (ret_val != 0) |
| 2193 | goto out; |
| 2194 | } |
| 2195 | |
| 2196 | out: |
| 2197 | return ret_val; |
| 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * igb_update_nvm_checksum_i350 - Update EEPROM checksum |
| 2202 | * @hw: pointer to the HW structure |
| 2203 | * |
| 2204 | * Updates the EEPROM section checksums for all 4 ports by reading/adding |
| 2205 | * each word of the EEPROM up to the checksum. Then calculates the EEPROM |
| 2206 | * checksum and writes the value to the EEPROM. |
| 2207 | **/ |
| 2208 | static s32 igb_update_nvm_checksum_i350(struct e1000_hw *hw) |
| 2209 | { |
| 2210 | s32 ret_val = 0; |
| 2211 | u16 j; |
| 2212 | u16 nvm_offset; |
| 2213 | |
| 2214 | for (j = 0; j < 4; j++) { |
| 2215 | nvm_offset = NVM_82580_LAN_FUNC_OFFSET(j); |
| 2216 | ret_val = igb_update_nvm_checksum_with_offset(hw, nvm_offset); |
| 2217 | if (ret_val != 0) |
| 2218 | goto out; |
| 2219 | } |
| 2220 | |
| 2221 | out: |
| 2222 | return ret_val; |
| 2223 | } |
Stefan Assmann | 34a0326 | 2011-04-05 04:27:05 +0000 | [diff] [blame] | 2224 | |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2225 | /** |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2226 | * igb_set_eee_i350 - Enable/disable EEE support |
| 2227 | * @hw: pointer to the HW structure |
| 2228 | * |
| 2229 | * Enable/disable EEE based on setting in dev_spec structure. |
| 2230 | * |
| 2231 | **/ |
| 2232 | s32 igb_set_eee_i350(struct e1000_hw *hw) |
| 2233 | { |
| 2234 | s32 ret_val = 0; |
Akeem G. Abodunrin | e546111 | 2012-09-06 01:28:31 +0000 | [diff] [blame] | 2235 | u32 ipcnfg, eeer; |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2236 | |
Akeem G. Abodunrin | e546111 | 2012-09-06 01:28:31 +0000 | [diff] [blame] | 2237 | if ((hw->mac.type < e1000_i350) || |
| 2238 | (hw->phy.media_type != e1000_media_type_copper)) |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2239 | goto out; |
| 2240 | ipcnfg = rd32(E1000_IPCNFG); |
| 2241 | eeer = rd32(E1000_EEER); |
| 2242 | |
| 2243 | /* enable or disable per user setting */ |
| 2244 | if (!(hw->dev_spec._82575.eee_disable)) { |
Carolyn Wyborny | 40b2012 | 2012-10-19 05:31:43 +0000 | [diff] [blame] | 2245 | u32 eee_su = rd32(E1000_EEE_SU); |
| 2246 | |
| 2247 | ipcnfg |= (E1000_IPCNFG_EEE_1G_AN | E1000_IPCNFG_EEE_100M_AN); |
| 2248 | eeer |= (E1000_EEER_TX_LPI_EN | E1000_EEER_RX_LPI_EN | |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2249 | E1000_EEER_LPI_FC); |
| 2250 | |
Carolyn Wyborny | 40b2012 | 2012-10-19 05:31:43 +0000 | [diff] [blame] | 2251 | /* This bit should not be set in normal operation. */ |
| 2252 | if (eee_su & E1000_EEE_SU_LPI_CLK_STP) |
| 2253 | hw_dbg("LPI Clock Stop Bit should not be set!\n"); |
| 2254 | |
Akeem G. Abodunrin | e546111 | 2012-09-06 01:28:31 +0000 | [diff] [blame] | 2255 | |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2256 | } else { |
| 2257 | ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN | |
| 2258 | E1000_IPCNFG_EEE_100M_AN); |
| 2259 | eeer &= ~(E1000_EEER_TX_LPI_EN | |
| 2260 | E1000_EEER_RX_LPI_EN | |
| 2261 | E1000_EEER_LPI_FC); |
| 2262 | } |
| 2263 | wr32(E1000_IPCNFG, ipcnfg); |
| 2264 | wr32(E1000_EEER, eeer); |
Akeem G. Abodunrin | e546111 | 2012-09-06 01:28:31 +0000 | [diff] [blame] | 2265 | rd32(E1000_IPCNFG); |
| 2266 | rd32(E1000_EEER); |
Carolyn Wyborny | 09b068d | 2011-03-11 20:42:13 -0800 | [diff] [blame] | 2267 | out: |
| 2268 | |
| 2269 | return ret_val; |
| 2270 | } |
Carolyn Wyborny | 4322e56 | 2011-03-11 20:43:18 -0800 | [diff] [blame] | 2271 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2272 | static struct e1000_mac_operations e1000_mac_ops_82575 = { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2273 | .init_hw = igb_init_hw_82575, |
| 2274 | .check_for_link = igb_check_for_link_82575, |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 2275 | .rar_set = igb_rar_set, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2276 | .read_mac_addr = igb_read_mac_addr_82575, |
| 2277 | .get_speed_and_duplex = igb_get_speed_and_duplex_copper, |
| 2278 | }; |
| 2279 | |
| 2280 | static struct e1000_phy_operations e1000_phy_ops_82575 = { |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2281 | .acquire = igb_acquire_phy_82575, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2282 | .get_cfg_done = igb_get_cfg_done_82575, |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 2283 | .release = igb_release_phy_82575, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2284 | }; |
| 2285 | |
| 2286 | static struct e1000_nvm_operations e1000_nvm_ops_82575 = { |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 2287 | .acquire = igb_acquire_nvm_82575, |
| 2288 | .read = igb_read_nvm_eerd, |
| 2289 | .release = igb_release_nvm_82575, |
| 2290 | .write = igb_write_nvm_spi, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | const struct e1000_info e1000_82575_info = { |
| 2294 | .get_invariants = igb_get_invariants_82575, |
| 2295 | .mac_ops = &e1000_mac_ops_82575, |
| 2296 | .phy_ops = &e1000_phy_ops_82575, |
| 2297 | .nvm_ops = &e1000_nvm_ops_82575, |
| 2298 | }; |
| 2299 | |