Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) Gigabit Ethernet Linux driver |
Alexander Duyck | 86d5d38 | 2009-02-06 23:23:12 +0000 | [diff] [blame] | 4 | Copyright(c) 2007-2009 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 | #include <linux/if_ether.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | |
| 33 | #include "e1000_mac.h" |
| 34 | |
| 35 | #include "igb.h" |
| 36 | |
| 37 | static s32 igb_set_default_fc(struct e1000_hw *hw); |
| 38 | static s32 igb_set_fc_watermarks(struct e1000_hw *hw); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 39 | |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 40 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 41 | * igb_get_bus_info_pcie - Get PCIe bus information |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 42 | * @hw: pointer to the HW structure |
| 43 | * |
| 44 | * Determines and stores the system bus information for a particular |
| 45 | * network interface. The following bus information is determined and stored: |
| 46 | * bus speed, bus width, type (PCIe), and PCIe function. |
| 47 | **/ |
| 48 | s32 igb_get_bus_info_pcie(struct e1000_hw *hw) |
| 49 | { |
| 50 | struct e1000_bus_info *bus = &hw->bus; |
| 51 | s32 ret_val; |
Alexander Duyck | 5e8427e | 2008-12-10 01:09:53 -0800 | [diff] [blame] | 52 | u32 reg; |
| 53 | u16 pcie_link_status; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 54 | |
| 55 | bus->type = e1000_bus_type_pci_express; |
| 56 | bus->speed = e1000_bus_speed_2500; |
| 57 | |
| 58 | ret_val = igb_read_pcie_cap_reg(hw, |
| 59 | PCIE_LINK_STATUS, |
| 60 | &pcie_link_status); |
| 61 | if (ret_val) |
| 62 | bus->width = e1000_bus_width_unknown; |
| 63 | else |
| 64 | bus->width = (enum e1000_bus_width)((pcie_link_status & |
| 65 | PCIE_LINK_WIDTH_MASK) >> |
| 66 | PCIE_LINK_WIDTH_SHIFT); |
| 67 | |
Alexander Duyck | 5e8427e | 2008-12-10 01:09:53 -0800 | [diff] [blame] | 68 | reg = rd32(E1000_STATUS); |
| 69 | bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT; |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 75 | * igb_clear_vfta - Clear VLAN filter table |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 76 | * @hw: pointer to the HW structure |
| 77 | * |
| 78 | * Clears the register array which contains the VLAN filter table by |
| 79 | * setting all the values to 0. |
| 80 | **/ |
| 81 | void igb_clear_vfta(struct e1000_hw *hw) |
| 82 | { |
| 83 | u32 offset; |
| 84 | |
| 85 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { |
| 86 | array_wr32(E1000_VFTA, offset, 0); |
| 87 | wrfl(); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 92 | * igb_write_vfta - Write value to VLAN filter table |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 93 | * @hw: pointer to the HW structure |
| 94 | * @offset: register offset in VLAN filter table |
| 95 | * @value: register value written to VLAN filter table |
| 96 | * |
| 97 | * Writes value at the given offset in the register array which stores |
| 98 | * the VLAN filter table. |
| 99 | **/ |
Alexander Duyck | ff6f63d | 2009-04-09 22:49:02 +0000 | [diff] [blame] | 100 | static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 101 | { |
| 102 | array_wr32(E1000_VFTA, offset, value); |
| 103 | wrfl(); |
| 104 | } |
| 105 | |
| 106 | /** |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 107 | * igb_vfta_set - enable or disable vlan in VLAN filter table |
| 108 | * @hw: pointer to the HW structure |
| 109 | * @vid: VLAN id to add or remove |
| 110 | * @add: if true add filter, if false remove |
| 111 | * |
| 112 | * Sets or clears a bit in the VLAN filter table array based on VLAN id |
| 113 | * and if we are adding or removing the filter |
| 114 | **/ |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 115 | s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add) |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 116 | { |
| 117 | u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK; |
Alexander Duyck | 75f4f38 | 2009-03-13 20:41:55 +0000 | [diff] [blame] | 118 | u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK); |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 119 | u32 vfta = array_rd32(E1000_VFTA, index); |
| 120 | s32 ret_val = 0; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 121 | |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 122 | /* bit was set/cleared before we started */ |
| 123 | if ((!!(vfta & mask)) == add) { |
| 124 | ret_val = -E1000_ERR_CONFIG; |
| 125 | } else { |
| 126 | if (add) |
| 127 | vfta |= mask; |
| 128 | else |
| 129 | vfta &= ~mask; |
| 130 | } |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 131 | |
| 132 | igb_write_vfta(hw, index, vfta); |
Alexander Duyck | cad6d05 | 2009-03-13 20:41:37 +0000 | [diff] [blame] | 133 | |
| 134 | return ret_val; |
Alexander Duyck | 4ae196d | 2009-02-19 20:40:07 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 138 | * igb_check_alt_mac_addr - Check for alternate MAC addr |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 139 | * @hw: pointer to the HW structure |
| 140 | * |
| 141 | * Checks the nvm for an alternate MAC address. An alternate MAC address |
| 142 | * can be setup by pre-boot software and must be treated like a permanent |
| 143 | * address and must override the actual permanent MAC address. If an |
| 144 | * alternate MAC address is fopund it is saved in the hw struct and |
| 145 | * prgrammed into RAR0 and the cuntion returns success, otherwise the |
| 146 | * fucntion returns an error. |
| 147 | **/ |
| 148 | s32 igb_check_alt_mac_addr(struct e1000_hw *hw) |
| 149 | { |
| 150 | u32 i; |
| 151 | s32 ret_val = 0; |
| 152 | u16 offset, nvm_alt_mac_addr_offset, nvm_data; |
| 153 | u8 alt_mac_addr[ETH_ALEN]; |
| 154 | |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 155 | ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 156 | &nvm_alt_mac_addr_offset); |
| 157 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 158 | hw_dbg("NVM Read Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 159 | goto out; |
| 160 | } |
| 161 | |
| 162 | if (nvm_alt_mac_addr_offset == 0xFFFF) { |
| 163 | ret_val = -(E1000_NOT_IMPLEMENTED); |
| 164 | goto out; |
| 165 | } |
| 166 | |
| 167 | if (hw->bus.func == E1000_FUNC_1) |
| 168 | nvm_alt_mac_addr_offset += ETH_ALEN/sizeof(u16); |
| 169 | |
| 170 | for (i = 0; i < ETH_ALEN; i += 2) { |
| 171 | offset = nvm_alt_mac_addr_offset + (i >> 1); |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 172 | ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 173 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 174 | hw_dbg("NVM Read Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 175 | goto out; |
| 176 | } |
| 177 | |
| 178 | alt_mac_addr[i] = (u8)(nvm_data & 0xFF); |
| 179 | alt_mac_addr[i + 1] = (u8)(nvm_data >> 8); |
| 180 | } |
| 181 | |
| 182 | /* if multicast bit is set, the alternate address will not be used */ |
| 183 | if (alt_mac_addr[0] & 0x01) { |
| 184 | ret_val = -(E1000_NOT_IMPLEMENTED); |
| 185 | goto out; |
| 186 | } |
| 187 | |
| 188 | for (i = 0; i < ETH_ALEN; i++) |
| 189 | hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i]; |
| 190 | |
| 191 | hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0); |
| 192 | |
| 193 | out: |
| 194 | return ret_val; |
| 195 | } |
| 196 | |
| 197 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 198 | * igb_rar_set - Set receive address register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 199 | * @hw: pointer to the HW structure |
| 200 | * @addr: pointer to the receive address |
| 201 | * @index: receive address array register |
| 202 | * |
| 203 | * Sets the receive address array register at index to the address passed |
| 204 | * in by addr. |
| 205 | **/ |
| 206 | void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) |
| 207 | { |
| 208 | u32 rar_low, rar_high; |
| 209 | |
| 210 | /* |
| 211 | * HW expects these in little endian so we reverse the byte order |
| 212 | * from network order (big endian) to little endian |
| 213 | */ |
| 214 | rar_low = ((u32) addr[0] | |
| 215 | ((u32) addr[1] << 8) | |
| 216 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); |
| 217 | |
| 218 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); |
| 219 | |
Alexander Duyck | 8675737 | 2009-02-06 23:21:51 +0000 | [diff] [blame] | 220 | /* If MAC address zero, no need to set the AV bit */ |
| 221 | if (rar_low || rar_high) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 222 | rar_high |= E1000_RAH_AV; |
| 223 | |
Alexander Duyck | 5e8427e | 2008-12-10 01:09:53 -0800 | [diff] [blame] | 224 | wr32(E1000_RAL(index), rar_low); |
| 225 | wr32(E1000_RAH(index), rar_high); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 229 | * igb_mta_set - Set multicast filter table address |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 230 | * @hw: pointer to the HW structure |
| 231 | * @hash_value: determines the MTA register and bit to set |
| 232 | * |
| 233 | * The multicast table address is a register array of 32-bit registers. |
| 234 | * The hash_value is used to determine what register the bit is in, the |
| 235 | * current value is read, the new bit is OR'd in and the new value is |
| 236 | * written back into the register. |
| 237 | **/ |
Alexander Duyck | 549bdd8 | 2008-08-04 15:00:06 -0700 | [diff] [blame] | 238 | void igb_mta_set(struct e1000_hw *hw, u32 hash_value) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 239 | { |
| 240 | u32 hash_bit, hash_reg, mta; |
| 241 | |
| 242 | /* |
| 243 | * The MTA is a register array of 32-bit registers. It is |
| 244 | * treated like an array of (32*mta_reg_count) bits. We want to |
| 245 | * set bit BitArray[hash_value]. So we figure out what register |
| 246 | * the bit is in, read it, OR in the new bit, then write |
| 247 | * back the new value. The (hw->mac.mta_reg_count - 1) serves as a |
| 248 | * mask to bits 31:5 of the hash value which gives us the |
| 249 | * register we're modifying. The hash bit within that register |
| 250 | * is determined by the lower 5 bits of the hash value. |
| 251 | */ |
| 252 | hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); |
| 253 | hash_bit = hash_value & 0x1F; |
| 254 | |
| 255 | mta = array_rd32(E1000_MTA, hash_reg); |
| 256 | |
| 257 | mta |= (1 << hash_bit); |
| 258 | |
| 259 | array_wr32(E1000_MTA, hash_reg, mta); |
| 260 | wrfl(); |
| 261 | } |
| 262 | |
| 263 | /** |
Alexander Duyck | 28fc06f | 2009-07-23 18:08:54 +0000 | [diff] [blame^] | 264 | * igb_update_mc_addr_list - Update Multicast addresses |
| 265 | * @hw: pointer to the HW structure |
| 266 | * @mc_addr_list: array of multicast addresses to program |
| 267 | * @mc_addr_count: number of multicast addresses to program |
| 268 | * |
| 269 | * Updates entire Multicast Table Array. |
| 270 | * The caller must have a packed mc_addr_list of multicast addresses. |
| 271 | **/ |
| 272 | void igb_update_mc_addr_list(struct e1000_hw *hw, |
| 273 | u8 *mc_addr_list, u32 mc_addr_count) |
| 274 | { |
| 275 | u32 hash_value, hash_bit, hash_reg; |
| 276 | int i; |
| 277 | |
| 278 | /* clear mta_shadow */ |
| 279 | memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); |
| 280 | |
| 281 | /* update mta_shadow from mc_addr_list */ |
| 282 | for (i = 0; (u32) i < mc_addr_count; i++) { |
| 283 | hash_value = igb_hash_mc_addr(hw, mc_addr_list); |
| 284 | |
| 285 | hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); |
| 286 | hash_bit = hash_value & 0x1F; |
| 287 | |
| 288 | hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit); |
| 289 | mc_addr_list += (ETH_ALEN); |
| 290 | } |
| 291 | |
| 292 | /* replace the entire MTA table */ |
| 293 | for (i = hw->mac.mta_reg_count - 1; i >= 0; i--) |
| 294 | array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]); |
| 295 | wrfl(); |
| 296 | } |
| 297 | |
| 298 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 299 | * igb_hash_mc_addr - Generate a multicast hash value |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 300 | * @hw: pointer to the HW structure |
| 301 | * @mc_addr: pointer to a multicast address |
| 302 | * |
| 303 | * Generates a multicast address hash value which is used to determine |
| 304 | * the multicast filter table array address and new table value. See |
| 305 | * igb_mta_set() |
| 306 | **/ |
Alexander Duyck | 2d064c0 | 2008-07-08 15:10:12 -0700 | [diff] [blame] | 307 | u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 308 | { |
| 309 | u32 hash_value, hash_mask; |
| 310 | u8 bit_shift = 0; |
| 311 | |
| 312 | /* Register count multiplied by bits per register */ |
| 313 | hash_mask = (hw->mac.mta_reg_count * 32) - 1; |
| 314 | |
| 315 | /* |
| 316 | * For a mc_filter_type of 0, bit_shift is the number of left-shifts |
| 317 | * where 0xFF would still fall within the hash mask. |
| 318 | */ |
| 319 | while (hash_mask >> bit_shift != 0xFF) |
| 320 | bit_shift++; |
| 321 | |
| 322 | /* |
| 323 | * The portion of the address that is used for the hash table |
| 324 | * is determined by the mc_filter_type setting. |
| 325 | * The algorithm is such that there is a total of 8 bits of shifting. |
| 326 | * The bit_shift for a mc_filter_type of 0 represents the number of |
| 327 | * left-shifts where the MSB of mc_addr[5] would still fall within |
| 328 | * the hash_mask. Case 0 does this exactly. Since there are a total |
| 329 | * of 8 bits of shifting, then mc_addr[4] will shift right the |
| 330 | * remaining number of bits. Thus 8 - bit_shift. The rest of the |
| 331 | * cases are a variation of this algorithm...essentially raising the |
| 332 | * number of bits to shift mc_addr[5] left, while still keeping the |
| 333 | * 8-bit shifting total. |
| 334 | * |
| 335 | * For example, given the following Destination MAC Address and an |
| 336 | * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask), |
| 337 | * we can see that the bit_shift for case 0 is 4. These are the hash |
| 338 | * values resulting from each mc_filter_type... |
| 339 | * [0] [1] [2] [3] [4] [5] |
| 340 | * 01 AA 00 12 34 56 |
| 341 | * LSB MSB |
| 342 | * |
| 343 | * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 |
| 344 | * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 |
| 345 | * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163 |
| 346 | * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634 |
| 347 | */ |
| 348 | switch (hw->mac.mc_filter_type) { |
| 349 | default: |
| 350 | case 0: |
| 351 | break; |
| 352 | case 1: |
| 353 | bit_shift += 1; |
| 354 | break; |
| 355 | case 2: |
| 356 | bit_shift += 2; |
| 357 | break; |
| 358 | case 3: |
| 359 | bit_shift += 4; |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | |
| 364 | (((u16) mc_addr[5]) << bit_shift))); |
| 365 | |
| 366 | return hash_value; |
| 367 | } |
| 368 | |
| 369 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 370 | * igb_clear_hw_cntrs_base - Clear base hardware counters |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 371 | * @hw: pointer to the HW structure |
| 372 | * |
| 373 | * Clears the base hardware counters by reading the counter registers. |
| 374 | **/ |
| 375 | void igb_clear_hw_cntrs_base(struct e1000_hw *hw) |
| 376 | { |
| 377 | u32 temp; |
| 378 | |
| 379 | temp = rd32(E1000_CRCERRS); |
| 380 | temp = rd32(E1000_SYMERRS); |
| 381 | temp = rd32(E1000_MPC); |
| 382 | temp = rd32(E1000_SCC); |
| 383 | temp = rd32(E1000_ECOL); |
| 384 | temp = rd32(E1000_MCC); |
| 385 | temp = rd32(E1000_LATECOL); |
| 386 | temp = rd32(E1000_COLC); |
| 387 | temp = rd32(E1000_DC); |
| 388 | temp = rd32(E1000_SEC); |
| 389 | temp = rd32(E1000_RLEC); |
| 390 | temp = rd32(E1000_XONRXC); |
| 391 | temp = rd32(E1000_XONTXC); |
| 392 | temp = rd32(E1000_XOFFRXC); |
| 393 | temp = rd32(E1000_XOFFTXC); |
| 394 | temp = rd32(E1000_FCRUC); |
| 395 | temp = rd32(E1000_GPRC); |
| 396 | temp = rd32(E1000_BPRC); |
| 397 | temp = rd32(E1000_MPRC); |
| 398 | temp = rd32(E1000_GPTC); |
| 399 | temp = rd32(E1000_GORCL); |
| 400 | temp = rd32(E1000_GORCH); |
| 401 | temp = rd32(E1000_GOTCL); |
| 402 | temp = rd32(E1000_GOTCH); |
| 403 | temp = rd32(E1000_RNBC); |
| 404 | temp = rd32(E1000_RUC); |
| 405 | temp = rd32(E1000_RFC); |
| 406 | temp = rd32(E1000_ROC); |
| 407 | temp = rd32(E1000_RJC); |
| 408 | temp = rd32(E1000_TORL); |
| 409 | temp = rd32(E1000_TORH); |
| 410 | temp = rd32(E1000_TOTL); |
| 411 | temp = rd32(E1000_TOTH); |
| 412 | temp = rd32(E1000_TPR); |
| 413 | temp = rd32(E1000_TPT); |
| 414 | temp = rd32(E1000_MPTC); |
| 415 | temp = rd32(E1000_BPTC); |
| 416 | } |
| 417 | |
| 418 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 419 | * igb_check_for_copper_link - Check for link (Copper) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 420 | * @hw: pointer to the HW structure |
| 421 | * |
| 422 | * Checks to see of the link status of the hardware has changed. If a |
| 423 | * change in link status has been detected, then we read the PHY registers |
| 424 | * to get the current speed/duplex if link exists. |
| 425 | **/ |
| 426 | s32 igb_check_for_copper_link(struct e1000_hw *hw) |
| 427 | { |
| 428 | struct e1000_mac_info *mac = &hw->mac; |
| 429 | s32 ret_val; |
| 430 | bool link; |
| 431 | |
| 432 | /* |
| 433 | * We only want to go out to the PHY registers to see if Auto-Neg |
| 434 | * has completed and/or if our link status has changed. The |
| 435 | * get_link_status flag is set upon receiving a Link Status |
| 436 | * Change or Rx Sequence Error interrupt. |
| 437 | */ |
| 438 | if (!mac->get_link_status) { |
| 439 | ret_val = 0; |
| 440 | goto out; |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * First we want to see if the MII Status Register reports |
| 445 | * link. If so, then we want to get the current speed/duplex |
| 446 | * of the PHY. |
| 447 | */ |
| 448 | ret_val = igb_phy_has_link(hw, 1, 0, &link); |
| 449 | if (ret_val) |
| 450 | goto out; |
| 451 | |
| 452 | if (!link) |
| 453 | goto out; /* No link detected */ |
| 454 | |
| 455 | mac->get_link_status = false; |
| 456 | |
| 457 | /* |
| 458 | * Check if there was DownShift, must be checked |
| 459 | * immediately after link-up |
| 460 | */ |
| 461 | igb_check_downshift(hw); |
| 462 | |
| 463 | /* |
| 464 | * If we are forcing speed/duplex, then we simply return since |
| 465 | * we have already determined whether we have link or not. |
| 466 | */ |
| 467 | if (!mac->autoneg) { |
| 468 | ret_val = -E1000_ERR_CONFIG; |
| 469 | goto out; |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * Auto-Neg is enabled. Auto Speed Detection takes care |
| 474 | * of MAC speed/duplex configuration. So we only need to |
| 475 | * configure Collision Distance in the MAC. |
| 476 | */ |
| 477 | igb_config_collision_dist(hw); |
| 478 | |
| 479 | /* |
| 480 | * Configure Flow Control now that Auto-Neg has completed. |
| 481 | * First, we need to restore the desired flow control |
| 482 | * settings because we may have had to re-autoneg with a |
| 483 | * different link partner. |
| 484 | */ |
| 485 | ret_val = igb_config_fc_after_link_up(hw); |
| 486 | if (ret_val) |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 487 | hw_dbg("Error configuring flow control\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 488 | |
| 489 | out: |
| 490 | return ret_val; |
| 491 | } |
| 492 | |
| 493 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 494 | * igb_setup_link - Setup flow control and link settings |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 495 | * @hw: pointer to the HW structure |
| 496 | * |
| 497 | * Determines which flow control settings to use, then configures flow |
| 498 | * control. Calls the appropriate media-specific link configuration |
| 499 | * function. Assuming the adapter has a valid link partner, a valid link |
| 500 | * should be established. Assumes the hardware has previously been reset |
| 501 | * and the transmitter and receiver are not enabled. |
| 502 | **/ |
| 503 | s32 igb_setup_link(struct e1000_hw *hw) |
| 504 | { |
| 505 | s32 ret_val = 0; |
| 506 | |
| 507 | /* |
| 508 | * In the case of the phy reset being blocked, we already have a link. |
| 509 | * We do not need to set it up again. |
| 510 | */ |
| 511 | if (igb_check_reset_block(hw)) |
| 512 | goto out; |
| 513 | |
| 514 | ret_val = igb_set_default_fc(hw); |
| 515 | if (ret_val) |
| 516 | goto out; |
| 517 | |
| 518 | /* |
| 519 | * We want to save off the original Flow Control configuration just |
| 520 | * in case we get disconnected and then reconnected into a different |
| 521 | * hub or switch with different Flow Control capabilities. |
| 522 | */ |
| 523 | hw->fc.original_type = hw->fc.type; |
| 524 | |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 525 | hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.type); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 526 | |
| 527 | /* Call the necessary media_type subroutine to configure the link. */ |
| 528 | ret_val = hw->mac.ops.setup_physical_interface(hw); |
| 529 | if (ret_val) |
| 530 | goto out; |
| 531 | |
| 532 | /* |
| 533 | * Initialize the flow control address, type, and PAUSE timer |
| 534 | * registers to their default values. This is done even if flow |
| 535 | * control is disabled, because it does not hurt anything to |
| 536 | * initialize these registers. |
| 537 | */ |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 538 | hw_dbg("Initializing the Flow Control address, type and timer regs\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 539 | wr32(E1000_FCT, FLOW_CONTROL_TYPE); |
| 540 | wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH); |
| 541 | wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW); |
| 542 | |
| 543 | wr32(E1000_FCTTV, hw->fc.pause_time); |
| 544 | |
| 545 | ret_val = igb_set_fc_watermarks(hw); |
| 546 | |
| 547 | out: |
| 548 | return ret_val; |
| 549 | } |
| 550 | |
| 551 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 552 | * igb_config_collision_dist - Configure collision distance |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 553 | * @hw: pointer to the HW structure |
| 554 | * |
| 555 | * Configures the collision distance to the default value and is used |
| 556 | * during link setup. Currently no func pointer exists and all |
| 557 | * implementations are handled in the generic version of this function. |
| 558 | **/ |
| 559 | void igb_config_collision_dist(struct e1000_hw *hw) |
| 560 | { |
| 561 | u32 tctl; |
| 562 | |
| 563 | tctl = rd32(E1000_TCTL); |
| 564 | |
| 565 | tctl &= ~E1000_TCTL_COLD; |
| 566 | tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT; |
| 567 | |
| 568 | wr32(E1000_TCTL, tctl); |
| 569 | wrfl(); |
| 570 | } |
| 571 | |
| 572 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 573 | * igb_set_fc_watermarks - Set flow control high/low watermarks |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 574 | * @hw: pointer to the HW structure |
| 575 | * |
| 576 | * Sets the flow control high/low threshold (watermark) registers. If |
| 577 | * flow control XON frame transmission is enabled, then set XON frame |
| 578 | * tansmission as well. |
| 579 | **/ |
| 580 | static s32 igb_set_fc_watermarks(struct e1000_hw *hw) |
| 581 | { |
| 582 | s32 ret_val = 0; |
| 583 | u32 fcrtl = 0, fcrth = 0; |
| 584 | |
| 585 | /* |
| 586 | * Set the flow control receive threshold registers. Normally, |
| 587 | * these registers will be set to a default threshold that may be |
| 588 | * adjusted later by the driver's runtime code. However, if the |
| 589 | * ability to transmit pause frames is not enabled, then these |
| 590 | * registers will be set to 0. |
| 591 | */ |
| 592 | if (hw->fc.type & e1000_fc_tx_pause) { |
| 593 | /* |
| 594 | * We need to set up the Receive Threshold high and low water |
| 595 | * marks as well as (optionally) enabling the transmission of |
| 596 | * XON frames. |
| 597 | */ |
| 598 | fcrtl = hw->fc.low_water; |
| 599 | if (hw->fc.send_xon) |
| 600 | fcrtl |= E1000_FCRTL_XONE; |
| 601 | |
| 602 | fcrth = hw->fc.high_water; |
| 603 | } |
| 604 | wr32(E1000_FCRTL, fcrtl); |
| 605 | wr32(E1000_FCRTH, fcrth); |
| 606 | |
| 607 | return ret_val; |
| 608 | } |
| 609 | |
| 610 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 611 | * igb_set_default_fc - Set flow control default values |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 612 | * @hw: pointer to the HW structure |
| 613 | * |
| 614 | * Read the EEPROM for the default values for flow control and store the |
| 615 | * values. |
| 616 | **/ |
| 617 | static s32 igb_set_default_fc(struct e1000_hw *hw) |
| 618 | { |
| 619 | s32 ret_val = 0; |
| 620 | u16 nvm_data; |
| 621 | |
| 622 | /* |
| 623 | * Read and store word 0x0F of the EEPROM. This word contains bits |
| 624 | * that determine the hardware's default PAUSE (flow control) mode, |
| 625 | * a bit that determines whether the HW defaults to enabling or |
| 626 | * disabling auto-negotiation, and the direction of the |
| 627 | * SW defined pins. If there is no SW over-ride of the flow |
| 628 | * control setting, then the variable hw->fc will |
| 629 | * be initialized based on a value in the EEPROM. |
| 630 | */ |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 631 | ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 632 | |
| 633 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 634 | hw_dbg("NVM Read Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 635 | goto out; |
| 636 | } |
| 637 | |
| 638 | if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) |
| 639 | hw->fc.type = e1000_fc_none; |
| 640 | else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == |
| 641 | NVM_WORD0F_ASM_DIR) |
| 642 | hw->fc.type = e1000_fc_tx_pause; |
| 643 | else |
| 644 | hw->fc.type = e1000_fc_full; |
| 645 | |
| 646 | out: |
| 647 | return ret_val; |
| 648 | } |
| 649 | |
| 650 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 651 | * igb_force_mac_fc - Force the MAC's flow control settings |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 652 | * @hw: pointer to the HW structure |
| 653 | * |
| 654 | * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the |
| 655 | * device control register to reflect the adapter settings. TFCE and RFCE |
| 656 | * need to be explicitly set by software when a copper PHY is used because |
| 657 | * autonegotiation is managed by the PHY rather than the MAC. Software must |
| 658 | * also configure these bits when link is forced on a fiber connection. |
| 659 | **/ |
| 660 | s32 igb_force_mac_fc(struct e1000_hw *hw) |
| 661 | { |
| 662 | u32 ctrl; |
| 663 | s32 ret_val = 0; |
| 664 | |
| 665 | ctrl = rd32(E1000_CTRL); |
| 666 | |
| 667 | /* |
| 668 | * Because we didn't get link via the internal auto-negotiation |
| 669 | * mechanism (we either forced link or we got link via PHY |
| 670 | * auto-neg), we have to manually enable/disable transmit an |
| 671 | * receive flow control. |
| 672 | * |
| 673 | * The "Case" statement below enables/disable flow control |
| 674 | * according to the "hw->fc.type" parameter. |
| 675 | * |
| 676 | * The possible values of the "fc" parameter are: |
| 677 | * 0: Flow control is completely disabled |
| 678 | * 1: Rx flow control is enabled (we can receive pause |
| 679 | * frames but not send pause frames). |
| 680 | * 2: Tx flow control is enabled (we can send pause frames |
| 681 | * frames but we do not receive pause frames). |
| 682 | * 3: Both Rx and TX flow control (symmetric) is enabled. |
| 683 | * other: No other values should be possible at this point. |
| 684 | */ |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 685 | hw_dbg("hw->fc.type = %u\n", hw->fc.type); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 686 | |
| 687 | switch (hw->fc.type) { |
| 688 | case e1000_fc_none: |
| 689 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); |
| 690 | break; |
| 691 | case e1000_fc_rx_pause: |
| 692 | ctrl &= (~E1000_CTRL_TFCE); |
| 693 | ctrl |= E1000_CTRL_RFCE; |
| 694 | break; |
| 695 | case e1000_fc_tx_pause: |
| 696 | ctrl &= (~E1000_CTRL_RFCE); |
| 697 | ctrl |= E1000_CTRL_TFCE; |
| 698 | break; |
| 699 | case e1000_fc_full: |
| 700 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); |
| 701 | break; |
| 702 | default: |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 703 | hw_dbg("Flow control param set incorrectly\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 704 | ret_val = -E1000_ERR_CONFIG; |
| 705 | goto out; |
| 706 | } |
| 707 | |
| 708 | wr32(E1000_CTRL, ctrl); |
| 709 | |
| 710 | out: |
| 711 | return ret_val; |
| 712 | } |
| 713 | |
| 714 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 715 | * igb_config_fc_after_link_up - Configures flow control after link |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 716 | * @hw: pointer to the HW structure |
| 717 | * |
| 718 | * Checks the status of auto-negotiation after link up to ensure that the |
| 719 | * speed and duplex were not forced. If the link needed to be forced, then |
| 720 | * flow control needs to be forced also. If auto-negotiation is enabled |
| 721 | * and did not fail, then we configure flow control based on our link |
| 722 | * partner. |
| 723 | **/ |
| 724 | s32 igb_config_fc_after_link_up(struct e1000_hw *hw) |
| 725 | { |
| 726 | struct e1000_mac_info *mac = &hw->mac; |
| 727 | s32 ret_val = 0; |
| 728 | u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg; |
| 729 | u16 speed, duplex; |
| 730 | |
| 731 | /* |
| 732 | * Check for the case where we have fiber media and auto-neg failed |
| 733 | * so we had to force link. In this case, we need to force the |
| 734 | * configuration of the MAC to match the "fc" parameter. |
| 735 | */ |
| 736 | if (mac->autoneg_failed) { |
Alexander Duyck | dcc3ae9 | 2009-07-23 18:07:20 +0000 | [diff] [blame] | 737 | if (hw->phy.media_type == e1000_media_type_internal_serdes) |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 738 | ret_val = igb_force_mac_fc(hw); |
| 739 | } else { |
| 740 | if (hw->phy.media_type == e1000_media_type_copper) |
| 741 | ret_val = igb_force_mac_fc(hw); |
| 742 | } |
| 743 | |
| 744 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 745 | hw_dbg("Error forcing flow control settings\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 746 | goto out; |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Check for the case where we have copper media and auto-neg is |
| 751 | * enabled. In this case, we need to check and see if Auto-Neg |
| 752 | * has completed, and if so, how the PHY and link partner has |
| 753 | * flow control configured. |
| 754 | */ |
| 755 | if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) { |
| 756 | /* |
| 757 | * Read the MII Status Register and check to see if AutoNeg |
| 758 | * has completed. We read this twice because this reg has |
| 759 | * some "sticky" (latched) bits. |
| 760 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 761 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 762 | &mii_status_reg); |
| 763 | if (ret_val) |
| 764 | goto out; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 765 | ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 766 | &mii_status_reg); |
| 767 | if (ret_val) |
| 768 | goto out; |
| 769 | |
| 770 | if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 771 | hw_dbg("Copper PHY and Auto Neg " |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 772 | "has not completed.\n"); |
| 773 | goto out; |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * The AutoNeg process has completed, so we now need to |
| 778 | * read both the Auto Negotiation Advertisement |
| 779 | * Register (Address 4) and the Auto_Negotiation Base |
| 780 | * Page Ability Register (Address 5) to determine how |
| 781 | * flow control was negotiated. |
| 782 | */ |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 783 | ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 784 | &mii_nway_adv_reg); |
| 785 | if (ret_val) |
| 786 | goto out; |
Alexander Duyck | a8d2a0c | 2009-02-06 23:17:26 +0000 | [diff] [blame] | 787 | ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY, |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 788 | &mii_nway_lp_ability_reg); |
| 789 | if (ret_val) |
| 790 | goto out; |
| 791 | |
| 792 | /* |
| 793 | * Two bits in the Auto Negotiation Advertisement Register |
| 794 | * (Address 4) and two bits in the Auto Negotiation Base |
| 795 | * Page Ability Register (Address 5) determine flow control |
| 796 | * for both the PHY and the link partner. The following |
| 797 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, |
| 798 | * 1999, describes these PAUSE resolution bits and how flow |
| 799 | * control is determined based upon these settings. |
| 800 | * NOTE: DC = Don't Care |
| 801 | * |
| 802 | * LOCAL DEVICE | LINK PARTNER |
| 803 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution |
| 804 | *-------|---------|-------|---------|-------------------- |
| 805 | * 0 | 0 | DC | DC | e1000_fc_none |
| 806 | * 0 | 1 | 0 | DC | e1000_fc_none |
| 807 | * 0 | 1 | 1 | 0 | e1000_fc_none |
| 808 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
| 809 | * 1 | 0 | 0 | DC | e1000_fc_none |
| 810 | * 1 | DC | 1 | DC | e1000_fc_full |
| 811 | * 1 | 1 | 0 | 0 | e1000_fc_none |
| 812 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
| 813 | * |
| 814 | * Are both PAUSE bits set to 1? If so, this implies |
| 815 | * Symmetric Flow Control is enabled at both ends. The |
| 816 | * ASM_DIR bits are irrelevant per the spec. |
| 817 | * |
| 818 | * For Symmetric Flow Control: |
| 819 | * |
| 820 | * LOCAL DEVICE | LINK PARTNER |
| 821 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 822 | *-------|---------|-------|---------|-------------------- |
| 823 | * 1 | DC | 1 | DC | E1000_fc_full |
| 824 | * |
| 825 | */ |
| 826 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 827 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { |
| 828 | /* |
| 829 | * Now we need to check if the user selected RX ONLY |
| 830 | * of pause frames. In this case, we had to advertise |
| 831 | * FULL flow control because we could not advertise RX |
| 832 | * ONLY. Hence, we must now check to see if we need to |
| 833 | * turn OFF the TRANSMISSION of PAUSE frames. |
| 834 | */ |
| 835 | if (hw->fc.original_type == e1000_fc_full) { |
| 836 | hw->fc.type = e1000_fc_full; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 837 | hw_dbg("Flow Control = FULL.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 838 | } else { |
| 839 | hw->fc.type = e1000_fc_rx_pause; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 840 | hw_dbg("Flow Control = " |
| 841 | "RX PAUSE frames only.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | /* |
| 845 | * For receiving PAUSE frames ONLY. |
| 846 | * |
| 847 | * LOCAL DEVICE | LINK PARTNER |
| 848 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 849 | *-------|---------|-------|---------|-------------------- |
| 850 | * 0 | 1 | 1 | 1 | e1000_fc_tx_pause |
| 851 | */ |
| 852 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 853 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 854 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 855 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
| 856 | hw->fc.type = e1000_fc_tx_pause; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 857 | hw_dbg("Flow Control = TX PAUSE frames only.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 858 | } |
| 859 | /* |
| 860 | * For transmitting PAUSE frames ONLY. |
| 861 | * |
| 862 | * LOCAL DEVICE | LINK PARTNER |
| 863 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result |
| 864 | *-------|---------|-------|---------|-------------------- |
| 865 | * 1 | 1 | 0 | 1 | e1000_fc_rx_pause |
| 866 | */ |
| 867 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && |
| 868 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && |
| 869 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && |
| 870 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { |
| 871 | hw->fc.type = e1000_fc_rx_pause; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 872 | hw_dbg("Flow Control = RX PAUSE frames only.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 873 | } |
| 874 | /* |
| 875 | * Per the IEEE spec, at this point flow control should be |
| 876 | * disabled. However, we want to consider that we could |
| 877 | * be connected to a legacy switch that doesn't advertise |
| 878 | * desired flow control, but can be forced on the link |
| 879 | * partner. So if we advertised no flow control, that is |
| 880 | * what we will resolve to. If we advertised some kind of |
| 881 | * receive capability (Rx Pause Only or Full Flow Control) |
| 882 | * and the link partner advertised none, we will configure |
| 883 | * ourselves to enable Rx Flow Control only. We can do |
| 884 | * this safely for two reasons: If the link partner really |
| 885 | * didn't want flow control enabled, and we enable Rx, no |
| 886 | * harm done since we won't be receiving any PAUSE frames |
| 887 | * anyway. If the intent on the link partner was to have |
| 888 | * flow control enabled, then by us enabling RX only, we |
| 889 | * can at least receive pause frames and process them. |
| 890 | * This is a good idea because in most cases, since we are |
| 891 | * predominantly a server NIC, more times than not we will |
| 892 | * be asked to delay transmission of packets than asking |
| 893 | * our link partner to pause transmission of frames. |
| 894 | */ |
| 895 | else if ((hw->fc.original_type == e1000_fc_none || |
| 896 | hw->fc.original_type == e1000_fc_tx_pause) || |
| 897 | hw->fc.strict_ieee) { |
| 898 | hw->fc.type = e1000_fc_none; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 899 | hw_dbg("Flow Control = NONE.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 900 | } else { |
| 901 | hw->fc.type = e1000_fc_rx_pause; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 902 | hw_dbg("Flow Control = RX PAUSE frames only.\r\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /* |
| 906 | * Now we need to do one last check... If we auto- |
| 907 | * negotiated to HALF DUPLEX, flow control should not be |
| 908 | * enabled per IEEE 802.3 spec. |
| 909 | */ |
| 910 | ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex); |
| 911 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 912 | hw_dbg("Error getting link speed and duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 913 | goto out; |
| 914 | } |
| 915 | |
| 916 | if (duplex == HALF_DUPLEX) |
| 917 | hw->fc.type = e1000_fc_none; |
| 918 | |
| 919 | /* |
| 920 | * Now we call a subroutine to actually force the MAC |
| 921 | * controller to use the correct flow control settings. |
| 922 | */ |
| 923 | ret_val = igb_force_mac_fc(hw); |
| 924 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 925 | hw_dbg("Error forcing flow control settings\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 926 | goto out; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | out: |
| 931 | return ret_val; |
| 932 | } |
| 933 | |
| 934 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 935 | * igb_get_speed_and_duplex_copper - Retreive current speed/duplex |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 936 | * @hw: pointer to the HW structure |
| 937 | * @speed: stores the current speed |
| 938 | * @duplex: stores the current duplex |
| 939 | * |
| 940 | * Read the status register for the current speed/duplex and store the current |
| 941 | * speed and duplex for copper connections. |
| 942 | **/ |
| 943 | s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, |
| 944 | u16 *duplex) |
| 945 | { |
| 946 | u32 status; |
| 947 | |
| 948 | status = rd32(E1000_STATUS); |
| 949 | if (status & E1000_STATUS_SPEED_1000) { |
| 950 | *speed = SPEED_1000; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 951 | hw_dbg("1000 Mbs, "); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 952 | } else if (status & E1000_STATUS_SPEED_100) { |
| 953 | *speed = SPEED_100; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 954 | hw_dbg("100 Mbs, "); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 955 | } else { |
| 956 | *speed = SPEED_10; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 957 | hw_dbg("10 Mbs, "); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | if (status & E1000_STATUS_FD) { |
| 961 | *duplex = FULL_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 962 | hw_dbg("Full Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 963 | } else { |
| 964 | *duplex = HALF_DUPLEX; |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 965 | hw_dbg("Half Duplex\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 972 | * igb_get_hw_semaphore - Acquire hardware semaphore |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 973 | * @hw: pointer to the HW structure |
| 974 | * |
| 975 | * Acquire the HW semaphore to access the PHY or NVM |
| 976 | **/ |
| 977 | s32 igb_get_hw_semaphore(struct e1000_hw *hw) |
| 978 | { |
| 979 | u32 swsm; |
| 980 | s32 ret_val = 0; |
| 981 | s32 timeout = hw->nvm.word_size + 1; |
| 982 | s32 i = 0; |
| 983 | |
| 984 | /* Get the SW semaphore */ |
| 985 | while (i < timeout) { |
| 986 | swsm = rd32(E1000_SWSM); |
| 987 | if (!(swsm & E1000_SWSM_SMBI)) |
| 988 | break; |
| 989 | |
| 990 | udelay(50); |
| 991 | i++; |
| 992 | } |
| 993 | |
| 994 | if (i == timeout) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 995 | hw_dbg("Driver can't access device - SMBI bit is set.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 996 | ret_val = -E1000_ERR_NVM; |
| 997 | goto out; |
| 998 | } |
| 999 | |
| 1000 | /* Get the FW semaphore. */ |
| 1001 | for (i = 0; i < timeout; i++) { |
| 1002 | swsm = rd32(E1000_SWSM); |
| 1003 | wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI); |
| 1004 | |
| 1005 | /* Semaphore acquired if bit latched */ |
| 1006 | if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI) |
| 1007 | break; |
| 1008 | |
| 1009 | udelay(50); |
| 1010 | } |
| 1011 | |
| 1012 | if (i == timeout) { |
| 1013 | /* Release semaphores */ |
| 1014 | igb_put_hw_semaphore(hw); |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1015 | hw_dbg("Driver can't access the NVM\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1016 | ret_val = -E1000_ERR_NVM; |
| 1017 | goto out; |
| 1018 | } |
| 1019 | |
| 1020 | out: |
| 1021 | return ret_val; |
| 1022 | } |
| 1023 | |
| 1024 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1025 | * igb_put_hw_semaphore - Release hardware semaphore |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1026 | * @hw: pointer to the HW structure |
| 1027 | * |
| 1028 | * Release hardware semaphore used to access the PHY or NVM |
| 1029 | **/ |
| 1030 | void igb_put_hw_semaphore(struct e1000_hw *hw) |
| 1031 | { |
| 1032 | u32 swsm; |
| 1033 | |
| 1034 | swsm = rd32(E1000_SWSM); |
| 1035 | |
| 1036 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); |
| 1037 | |
| 1038 | wr32(E1000_SWSM, swsm); |
| 1039 | } |
| 1040 | |
| 1041 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1042 | * igb_get_auto_rd_done - Check for auto read completion |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1043 | * @hw: pointer to the HW structure |
| 1044 | * |
| 1045 | * Check EEPROM for Auto Read done bit. |
| 1046 | **/ |
| 1047 | s32 igb_get_auto_rd_done(struct e1000_hw *hw) |
| 1048 | { |
| 1049 | s32 i = 0; |
| 1050 | s32 ret_val = 0; |
| 1051 | |
| 1052 | |
| 1053 | while (i < AUTO_READ_DONE_TIMEOUT) { |
| 1054 | if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD) |
| 1055 | break; |
| 1056 | msleep(1); |
| 1057 | i++; |
| 1058 | } |
| 1059 | |
| 1060 | if (i == AUTO_READ_DONE_TIMEOUT) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1061 | hw_dbg("Auto read by HW from NVM has not completed.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1062 | ret_val = -E1000_ERR_RESET; |
| 1063 | goto out; |
| 1064 | } |
| 1065 | |
| 1066 | out: |
| 1067 | return ret_val; |
| 1068 | } |
| 1069 | |
| 1070 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1071 | * igb_valid_led_default - Verify a valid default LED config |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1072 | * @hw: pointer to the HW structure |
| 1073 | * @data: pointer to the NVM (EEPROM) |
| 1074 | * |
| 1075 | * Read the EEPROM for the current default LED configuration. If the |
| 1076 | * LED configuration is not valid, set to a valid LED configuration. |
| 1077 | **/ |
| 1078 | static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data) |
| 1079 | { |
| 1080 | s32 ret_val; |
| 1081 | |
Alexander Duyck | 312c75a | 2009-02-06 23:17:47 +0000 | [diff] [blame] | 1082 | ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1083 | if (ret_val) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1084 | hw_dbg("NVM Read Error\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1085 | goto out; |
| 1086 | } |
| 1087 | |
Alexander Duyck | 099e1cb | 2009-07-23 18:07:40 +0000 | [diff] [blame] | 1088 | if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) { |
| 1089 | switch(hw->phy.media_type) { |
| 1090 | case e1000_media_type_internal_serdes: |
| 1091 | *data = ID_LED_DEFAULT_82575_SERDES; |
| 1092 | break; |
| 1093 | case e1000_media_type_copper: |
| 1094 | default: |
| 1095 | *data = ID_LED_DEFAULT; |
| 1096 | break; |
| 1097 | } |
| 1098 | } |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1099 | out: |
| 1100 | return ret_val; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1104 | * igb_id_led_init - |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1105 | * @hw: pointer to the HW structure |
| 1106 | * |
| 1107 | **/ |
| 1108 | s32 igb_id_led_init(struct e1000_hw *hw) |
| 1109 | { |
| 1110 | struct e1000_mac_info *mac = &hw->mac; |
| 1111 | s32 ret_val; |
| 1112 | const u32 ledctl_mask = 0x000000FF; |
| 1113 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; |
| 1114 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; |
| 1115 | u16 data, i, temp; |
| 1116 | const u16 led_mask = 0x0F; |
| 1117 | |
| 1118 | ret_val = igb_valid_led_default(hw, &data); |
| 1119 | if (ret_val) |
| 1120 | goto out; |
| 1121 | |
| 1122 | mac->ledctl_default = rd32(E1000_LEDCTL); |
| 1123 | mac->ledctl_mode1 = mac->ledctl_default; |
| 1124 | mac->ledctl_mode2 = mac->ledctl_default; |
| 1125 | |
| 1126 | for (i = 0; i < 4; i++) { |
| 1127 | temp = (data >> (i << 2)) & led_mask; |
| 1128 | switch (temp) { |
| 1129 | case ID_LED_ON1_DEF2: |
| 1130 | case ID_LED_ON1_ON2: |
| 1131 | case ID_LED_ON1_OFF2: |
| 1132 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 1133 | mac->ledctl_mode1 |= ledctl_on << (i << 3); |
| 1134 | break; |
| 1135 | case ID_LED_OFF1_DEF2: |
| 1136 | case ID_LED_OFF1_ON2: |
| 1137 | case ID_LED_OFF1_OFF2: |
| 1138 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); |
| 1139 | mac->ledctl_mode1 |= ledctl_off << (i << 3); |
| 1140 | break; |
| 1141 | default: |
| 1142 | /* Do nothing */ |
| 1143 | break; |
| 1144 | } |
| 1145 | switch (temp) { |
| 1146 | case ID_LED_DEF1_ON2: |
| 1147 | case ID_LED_ON1_ON2: |
| 1148 | case ID_LED_OFF1_ON2: |
| 1149 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 1150 | mac->ledctl_mode2 |= ledctl_on << (i << 3); |
| 1151 | break; |
| 1152 | case ID_LED_DEF1_OFF2: |
| 1153 | case ID_LED_ON1_OFF2: |
| 1154 | case ID_LED_OFF1_OFF2: |
| 1155 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); |
| 1156 | mac->ledctl_mode2 |= ledctl_off << (i << 3); |
| 1157 | break; |
| 1158 | default: |
| 1159 | /* Do nothing */ |
| 1160 | break; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | out: |
| 1165 | return ret_val; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1169 | * igb_cleanup_led - Set LED config to default operation |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1170 | * @hw: pointer to the HW structure |
| 1171 | * |
| 1172 | * Remove the current LED configuration and set the LED configuration |
| 1173 | * to the default value, saved from the EEPROM. |
| 1174 | **/ |
| 1175 | s32 igb_cleanup_led(struct e1000_hw *hw) |
| 1176 | { |
| 1177 | wr32(E1000_LEDCTL, hw->mac.ledctl_default); |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1182 | * igb_blink_led - Blink LED |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1183 | * @hw: pointer to the HW structure |
| 1184 | * |
| 1185 | * Blink the led's which are set to be on. |
| 1186 | **/ |
| 1187 | s32 igb_blink_led(struct e1000_hw *hw) |
| 1188 | { |
| 1189 | u32 ledctl_blink = 0; |
| 1190 | u32 i; |
| 1191 | |
Alexander Duyck | dcc3ae9 | 2009-07-23 18:07:20 +0000 | [diff] [blame] | 1192 | /* |
| 1193 | * set the blink bit for each LED that's "on" (0x0E) |
| 1194 | * in ledctl_mode2 |
| 1195 | */ |
| 1196 | ledctl_blink = hw->mac.ledctl_mode2; |
| 1197 | for (i = 0; i < 4; i++) |
| 1198 | if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) == |
| 1199 | E1000_LEDCTL_MODE_LED_ON) |
| 1200 | ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << |
| 1201 | (i * 8)); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1202 | |
| 1203 | wr32(E1000_LEDCTL, ledctl_blink); |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1209 | * igb_led_off - Turn LED off |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1210 | * @hw: pointer to the HW structure |
| 1211 | * |
| 1212 | * Turn LED off. |
| 1213 | **/ |
| 1214 | s32 igb_led_off(struct e1000_hw *hw) |
| 1215 | { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1216 | switch (hw->phy.media_type) { |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1217 | case e1000_media_type_copper: |
| 1218 | wr32(E1000_LEDCTL, hw->mac.ledctl_mode1); |
| 1219 | break; |
| 1220 | default: |
| 1221 | break; |
| 1222 | } |
| 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1228 | * igb_disable_pcie_master - Disables PCI-express master access |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1229 | * @hw: pointer to the HW structure |
| 1230 | * |
| 1231 | * Returns 0 (0) if successful, else returns -10 |
| 1232 | * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued |
| 1233 | * the master requests to be disabled. |
| 1234 | * |
| 1235 | * Disables PCI-Express master access and verifies there are no pending |
| 1236 | * requests. |
| 1237 | **/ |
| 1238 | s32 igb_disable_pcie_master(struct e1000_hw *hw) |
| 1239 | { |
| 1240 | u32 ctrl; |
| 1241 | s32 timeout = MASTER_DISABLE_TIMEOUT; |
| 1242 | s32 ret_val = 0; |
| 1243 | |
| 1244 | if (hw->bus.type != e1000_bus_type_pci_express) |
| 1245 | goto out; |
| 1246 | |
| 1247 | ctrl = rd32(E1000_CTRL); |
| 1248 | ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; |
| 1249 | wr32(E1000_CTRL, ctrl); |
| 1250 | |
| 1251 | while (timeout) { |
| 1252 | if (!(rd32(E1000_STATUS) & |
| 1253 | E1000_STATUS_GIO_MASTER_ENABLE)) |
| 1254 | break; |
| 1255 | udelay(100); |
| 1256 | timeout--; |
| 1257 | } |
| 1258 | |
| 1259 | if (!timeout) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1260 | hw_dbg("Master requests are pending.\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1261 | ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING; |
| 1262 | goto out; |
| 1263 | } |
| 1264 | |
| 1265 | out: |
| 1266 | return ret_val; |
| 1267 | } |
| 1268 | |
| 1269 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1270 | * igb_reset_adaptive - Reset Adaptive Interframe Spacing |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1271 | * @hw: pointer to the HW structure |
| 1272 | * |
| 1273 | * Reset the Adaptive Interframe Spacing throttle to default values. |
| 1274 | **/ |
| 1275 | void igb_reset_adaptive(struct e1000_hw *hw) |
| 1276 | { |
| 1277 | struct e1000_mac_info *mac = &hw->mac; |
| 1278 | |
| 1279 | if (!mac->adaptive_ifs) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1280 | hw_dbg("Not in Adaptive IFS mode!\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1281 | goto out; |
| 1282 | } |
| 1283 | |
| 1284 | if (!mac->ifs_params_forced) { |
| 1285 | mac->current_ifs_val = 0; |
| 1286 | mac->ifs_min_val = IFS_MIN; |
| 1287 | mac->ifs_max_val = IFS_MAX; |
| 1288 | mac->ifs_step_size = IFS_STEP; |
| 1289 | mac->ifs_ratio = IFS_RATIO; |
| 1290 | } |
| 1291 | |
| 1292 | mac->in_ifs_mode = false; |
| 1293 | wr32(E1000_AIT, 0); |
| 1294 | out: |
| 1295 | return; |
| 1296 | } |
| 1297 | |
| 1298 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1299 | * igb_update_adaptive - Update Adaptive Interframe Spacing |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1300 | * @hw: pointer to the HW structure |
| 1301 | * |
| 1302 | * Update the Adaptive Interframe Spacing Throttle value based on the |
| 1303 | * time between transmitted packets and time between collisions. |
| 1304 | **/ |
| 1305 | void igb_update_adaptive(struct e1000_hw *hw) |
| 1306 | { |
| 1307 | struct e1000_mac_info *mac = &hw->mac; |
| 1308 | |
| 1309 | if (!mac->adaptive_ifs) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1310 | hw_dbg("Not in Adaptive IFS mode!\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1311 | goto out; |
| 1312 | } |
| 1313 | |
| 1314 | if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) { |
| 1315 | if (mac->tx_packet_delta > MIN_NUM_XMITS) { |
| 1316 | mac->in_ifs_mode = true; |
| 1317 | if (mac->current_ifs_val < mac->ifs_max_val) { |
| 1318 | if (!mac->current_ifs_val) |
| 1319 | mac->current_ifs_val = mac->ifs_min_val; |
| 1320 | else |
| 1321 | mac->current_ifs_val += |
| 1322 | mac->ifs_step_size; |
| 1323 | wr32(E1000_AIT, |
| 1324 | mac->current_ifs_val); |
| 1325 | } |
| 1326 | } |
| 1327 | } else { |
| 1328 | if (mac->in_ifs_mode && |
| 1329 | (mac->tx_packet_delta <= MIN_NUM_XMITS)) { |
| 1330 | mac->current_ifs_val = 0; |
| 1331 | mac->in_ifs_mode = false; |
| 1332 | wr32(E1000_AIT, 0); |
| 1333 | } |
| 1334 | } |
| 1335 | out: |
| 1336 | return; |
| 1337 | } |
| 1338 | |
| 1339 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1340 | * igb_validate_mdi_setting - Verify MDI/MDIx settings |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1341 | * @hw: pointer to the HW structure |
| 1342 | * |
| 1343 | * Verify that when not using auto-negotitation that MDI/MDIx is correctly |
| 1344 | * set, which is forced to MDI mode only. |
| 1345 | **/ |
| 1346 | s32 igb_validate_mdi_setting(struct e1000_hw *hw) |
| 1347 | { |
| 1348 | s32 ret_val = 0; |
| 1349 | |
| 1350 | if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1351 | hw_dbg("Invalid MDI setting detected\n"); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1352 | hw->phy.mdix = 1; |
| 1353 | ret_val = -E1000_ERR_CONFIG; |
| 1354 | goto out; |
| 1355 | } |
| 1356 | |
| 1357 | out: |
| 1358 | return ret_val; |
| 1359 | } |
| 1360 | |
| 1361 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1362 | * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1363 | * @hw: pointer to the HW structure |
| 1364 | * @reg: 32bit register offset such as E1000_SCTL |
| 1365 | * @offset: register offset to write to |
| 1366 | * @data: data to write at register offset |
| 1367 | * |
| 1368 | * Writes an address/data control type register. There are several of these |
| 1369 | * and they all have the format address << 8 | data and bit 31 is polled for |
| 1370 | * completion. |
| 1371 | **/ |
| 1372 | s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg, |
| 1373 | u32 offset, u8 data) |
| 1374 | { |
| 1375 | u32 i, regvalue = 0; |
| 1376 | s32 ret_val = 0; |
| 1377 | |
| 1378 | /* Set up the address and data */ |
| 1379 | regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT); |
| 1380 | wr32(reg, regvalue); |
| 1381 | |
| 1382 | /* Poll the ready bit to see if the MDI read completed */ |
| 1383 | for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) { |
| 1384 | udelay(5); |
| 1385 | regvalue = rd32(reg); |
| 1386 | if (regvalue & E1000_GEN_CTL_READY) |
| 1387 | break; |
| 1388 | } |
| 1389 | if (!(regvalue & E1000_GEN_CTL_READY)) { |
Auke Kok | 652fff3 | 2008-06-27 11:00:18 -0700 | [diff] [blame] | 1390 | hw_dbg("Reg %08x did not indicate ready\n", reg); |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1391 | ret_val = -E1000_ERR_PHY; |
| 1392 | goto out; |
| 1393 | } |
| 1394 | |
| 1395 | out: |
| 1396 | return ret_val; |
| 1397 | } |
| 1398 | |
| 1399 | /** |
Jeff Kirsher | 733596b | 2008-06-27 10:59:59 -0700 | [diff] [blame] | 1400 | * igb_enable_mng_pass_thru - Enable processing of ARP's |
Auke Kok | 9d5c824 | 2008-01-24 02:22:38 -0800 | [diff] [blame] | 1401 | * @hw: pointer to the HW structure |
| 1402 | * |
| 1403 | * Verifies the hardware needs to allow ARPs to be processed by the host. |
| 1404 | **/ |
| 1405 | bool igb_enable_mng_pass_thru(struct e1000_hw *hw) |
| 1406 | { |
| 1407 | u32 manc; |
| 1408 | u32 fwsm, factps; |
| 1409 | bool ret_val = false; |
| 1410 | |
| 1411 | if (!hw->mac.asf_firmware_present) |
| 1412 | goto out; |
| 1413 | |
| 1414 | manc = rd32(E1000_MANC); |
| 1415 | |
| 1416 | if (!(manc & E1000_MANC_RCV_TCO_EN) || |
| 1417 | !(manc & E1000_MANC_EN_MAC_ADDR_FILTER)) |
| 1418 | goto out; |
| 1419 | |
| 1420 | if (hw->mac.arc_subsystem_valid) { |
| 1421 | fwsm = rd32(E1000_FWSM); |
| 1422 | factps = rd32(E1000_FACTPS); |
| 1423 | |
| 1424 | if (!(factps & E1000_FACTPS_MNGCG) && |
| 1425 | ((fwsm & E1000_FWSM_MODE_MASK) == |
| 1426 | (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { |
| 1427 | ret_val = true; |
| 1428 | goto out; |
| 1429 | } |
| 1430 | } else { |
| 1431 | if ((manc & E1000_MANC_SMBUS_EN) && |
| 1432 | !(manc & E1000_MANC_ASF_EN)) { |
| 1433 | ret_val = true; |
| 1434 | goto out; |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | out: |
| 1439 | return ret_val; |
| 1440 | } |