| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
|  | 2 |  | 
|  | 3 | Intel PRO/1000 Linux driver | 
| Bruce Allan | 451152d | 2010-06-16 13:28:11 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2010 Intel Corporation. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [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 | Linux NICS <linux.nics@intel.com> | 
|  | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | 
|  | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | 
|  | 26 |  | 
|  | 27 | *******************************************************************************/ | 
|  | 28 |  | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 29 | #include "e1000.h" | 
|  | 30 |  | 
|  | 31 | enum e1000_mng_mode { | 
|  | 32 | e1000_mng_mode_none = 0, | 
|  | 33 | e1000_mng_mode_asf, | 
|  | 34 | e1000_mng_mode_pt, | 
|  | 35 | e1000_mng_mode_ipmi, | 
|  | 36 | e1000_mng_mode_host_if_only | 
|  | 37 | }; | 
|  | 38 |  | 
|  | 39 | #define E1000_FACTPS_MNGCG		0x20000000 | 
|  | 40 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 41 | /* Intel(R) Active Management Technology signature */ | 
|  | 42 | #define E1000_IAMT_SIGNATURE		0x544D4149 | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | /** | 
|  | 45 | *  e1000e_get_bus_info_pcie - Get PCIe bus information | 
|  | 46 | *  @hw: pointer to the HW structure | 
|  | 47 | * | 
|  | 48 | *  Determines and stores the system bus information for a particular | 
|  | 49 | *  network interface.  The following bus information is determined and stored: | 
|  | 50 | *  bus speed, bus width, type (PCIe), and PCIe function. | 
|  | 51 | **/ | 
|  | 52 | s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw) | 
|  | 53 | { | 
| Bruce Allan | f4d2dd4 | 2010-01-13 02:05:18 +0000 | [diff] [blame] | 54 | struct e1000_mac_info *mac = &hw->mac; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 55 | struct e1000_bus_info *bus = &hw->bus; | 
|  | 56 | struct e1000_adapter *adapter = hw->adapter; | 
| Bruce Allan | f4d2dd4 | 2010-01-13 02:05:18 +0000 | [diff] [blame] | 57 | u16 pcie_link_status, cap_offset; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 58 |  | 
|  | 59 | cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP); | 
|  | 60 | if (!cap_offset) { | 
|  | 61 | bus->width = e1000_bus_width_unknown; | 
|  | 62 | } else { | 
|  | 63 | pci_read_config_word(adapter->pdev, | 
|  | 64 | cap_offset + PCIE_LINK_STATUS, | 
|  | 65 | &pcie_link_status); | 
|  | 66 | bus->width = (enum e1000_bus_width)((pcie_link_status & | 
|  | 67 | PCIE_LINK_WIDTH_MASK) >> | 
|  | 68 | PCIE_LINK_WIDTH_SHIFT); | 
|  | 69 | } | 
|  | 70 |  | 
| Bruce Allan | f4d2dd4 | 2010-01-13 02:05:18 +0000 | [diff] [blame] | 71 | mac->ops.set_lan_id(hw); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 72 |  | 
|  | 73 | return 0; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | /** | 
| Bruce Allan | f4d2dd4 | 2010-01-13 02:05:18 +0000 | [diff] [blame] | 77 | *  e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices | 
|  | 78 | * | 
|  | 79 | *  @hw: pointer to the HW structure | 
|  | 80 | * | 
|  | 81 | *  Determines the LAN function id by reading memory-mapped registers | 
|  | 82 | *  and swaps the port value if requested. | 
|  | 83 | **/ | 
|  | 84 | void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw) | 
|  | 85 | { | 
|  | 86 | struct e1000_bus_info *bus = &hw->bus; | 
|  | 87 | u32 reg; | 
|  | 88 |  | 
|  | 89 | /* | 
|  | 90 | * The status register reports the correct function number | 
|  | 91 | * for the device regardless of function swap state. | 
|  | 92 | */ | 
|  | 93 | reg = er32(STATUS); | 
|  | 94 | bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT; | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | /** | 
|  | 98 | *  e1000_set_lan_id_single_port - Set LAN id for a single port device | 
|  | 99 | *  @hw: pointer to the HW structure | 
|  | 100 | * | 
|  | 101 | *  Sets the LAN function id to zero for a single port device. | 
|  | 102 | **/ | 
|  | 103 | void e1000_set_lan_id_single_port(struct e1000_hw *hw) | 
|  | 104 | { | 
|  | 105 | struct e1000_bus_info *bus = &hw->bus; | 
|  | 106 |  | 
|  | 107 | bus->func = 0; | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | /** | 
| Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 111 | *  e1000_clear_vfta_generic - Clear VLAN filter table | 
|  | 112 | *  @hw: pointer to the HW structure | 
|  | 113 | * | 
|  | 114 | *  Clears the register array which contains the VLAN filter table by | 
|  | 115 | *  setting all the values to 0. | 
|  | 116 | **/ | 
|  | 117 | void e1000_clear_vfta_generic(struct e1000_hw *hw) | 
|  | 118 | { | 
|  | 119 | u32 offset; | 
|  | 120 |  | 
|  | 121 | for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { | 
|  | 122 | E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0); | 
|  | 123 | e1e_flush(); | 
|  | 124 | } | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | /** | 
|  | 128 | *  e1000_write_vfta_generic - Write value to VLAN filter table | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 129 | *  @hw: pointer to the HW structure | 
|  | 130 | *  @offset: register offset in VLAN filter table | 
|  | 131 | *  @value: register value written to VLAN filter table | 
|  | 132 | * | 
|  | 133 | *  Writes value at the given offset in the register array which stores | 
|  | 134 | *  the VLAN filter table. | 
|  | 135 | **/ | 
| Bruce Allan | caaddaf | 2009-12-01 15:46:43 +0000 | [diff] [blame] | 136 | void e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 137 | { | 
|  | 138 | E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value); | 
|  | 139 | e1e_flush(); | 
|  | 140 | } | 
|  | 141 |  | 
|  | 142 | /** | 
|  | 143 | *  e1000e_init_rx_addrs - Initialize receive address's | 
|  | 144 | *  @hw: pointer to the HW structure | 
|  | 145 | *  @rar_count: receive address registers | 
|  | 146 | * | 
|  | 147 | *  Setups the receive address registers by setting the base receive address | 
|  | 148 | *  register to the devices MAC address and clearing all the other receive | 
|  | 149 | *  address registers to 0. | 
|  | 150 | **/ | 
|  | 151 | void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count) | 
|  | 152 | { | 
|  | 153 | u32 i; | 
| Bruce Allan | b7a9216 | 2010-01-07 16:32:13 +0000 | [diff] [blame] | 154 | u8 mac_addr[ETH_ALEN] = {0}; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 155 |  | 
|  | 156 | /* Setup the receive address */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 157 | e_dbg("Programming MAC Address into RAR[0]\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 158 |  | 
|  | 159 | e1000e_rar_set(hw, hw->mac.addr, 0); | 
|  | 160 |  | 
|  | 161 | /* Zero out the other (rar_entry_count - 1) receive addresses */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 162 | e_dbg("Clearing RAR[1-%u]\n", rar_count-1); | 
| Bruce Allan | b7a9216 | 2010-01-07 16:32:13 +0000 | [diff] [blame] | 163 | for (i = 1; i < rar_count; i++) | 
|  | 164 | e1000e_rar_set(hw, mac_addr, i); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 165 | } | 
|  | 166 |  | 
|  | 167 | /** | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 168 | *  e1000_check_alt_mac_addr_generic - Check for alternate MAC addr | 
|  | 169 | *  @hw: pointer to the HW structure | 
|  | 170 | * | 
|  | 171 | *  Checks the nvm for an alternate MAC address.  An alternate MAC address | 
|  | 172 | *  can be setup by pre-boot software and must be treated like a permanent | 
|  | 173 | *  address and must override the actual permanent MAC address. If an | 
|  | 174 | *  alternate MAC address is found it is programmed into RAR0, replacing | 
|  | 175 | *  the permanent address that was installed into RAR0 by the Si on reset. | 
|  | 176 | *  This function will return SUCCESS unless it encounters an error while | 
|  | 177 | *  reading the EEPROM. | 
|  | 178 | **/ | 
|  | 179 | s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw) | 
|  | 180 | { | 
|  | 181 | u32 i; | 
|  | 182 | s32 ret_val = 0; | 
|  | 183 | u16 offset, nvm_alt_mac_addr_offset, nvm_data; | 
|  | 184 | u8 alt_mac_addr[ETH_ALEN]; | 
|  | 185 |  | 
|  | 186 | ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1, | 
|  | 187 | &nvm_alt_mac_addr_offset); | 
|  | 188 | if (ret_val) { | 
|  | 189 | e_dbg("NVM Read Error\n"); | 
|  | 190 | goto out; | 
|  | 191 | } | 
|  | 192 |  | 
|  | 193 | if (nvm_alt_mac_addr_offset == 0xFFFF) { | 
|  | 194 | /* There is no Alternate MAC Address */ | 
|  | 195 | goto out; | 
|  | 196 | } | 
|  | 197 |  | 
|  | 198 | if (hw->bus.func == E1000_FUNC_1) | 
|  | 199 | nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1; | 
|  | 200 | for (i = 0; i < ETH_ALEN; i += 2) { | 
|  | 201 | offset = nvm_alt_mac_addr_offset + (i >> 1); | 
|  | 202 | ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data); | 
|  | 203 | if (ret_val) { | 
|  | 204 | e_dbg("NVM Read Error\n"); | 
|  | 205 | goto out; | 
|  | 206 | } | 
|  | 207 |  | 
|  | 208 | alt_mac_addr[i] = (u8)(nvm_data & 0xFF); | 
|  | 209 | alt_mac_addr[i + 1] = (u8)(nvm_data >> 8); | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | /* if multicast bit is set, the alternate address will not be used */ | 
|  | 213 | if (alt_mac_addr[0] & 0x01) { | 
|  | 214 | e_dbg("Ignoring Alternate Mac Address with MC bit set\n"); | 
|  | 215 | goto out; | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | /* | 
|  | 219 | * We have a valid alternate MAC address, and we want to treat it the | 
|  | 220 | * same as the normal permanent MAC address stored by the HW into the | 
|  | 221 | * RAR. Do this by mapping this address into RAR0. | 
|  | 222 | */ | 
|  | 223 | e1000e_rar_set(hw, alt_mac_addr, 0); | 
|  | 224 |  | 
|  | 225 | out: | 
|  | 226 | return ret_val; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | /** | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 230 | *  e1000e_rar_set - Set receive address register | 
|  | 231 | *  @hw: pointer to the HW structure | 
|  | 232 | *  @addr: pointer to the receive address | 
|  | 233 | *  @index: receive address array register | 
|  | 234 | * | 
|  | 235 | *  Sets the receive address array register at index to the address passed | 
|  | 236 | *  in by addr. | 
|  | 237 | **/ | 
|  | 238 | void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) | 
|  | 239 | { | 
|  | 240 | u32 rar_low, rar_high; | 
|  | 241 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 242 | /* | 
|  | 243 | * HW expects these in little endian so we reverse the byte order | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 244 | * from network order (big endian) to little endian | 
|  | 245 | */ | 
|  | 246 | rar_low = ((u32) addr[0] | | 
|  | 247 | ((u32) addr[1] << 8) | | 
|  | 248 | ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); | 
|  | 249 |  | 
|  | 250 | rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); | 
|  | 251 |  | 
| Bruce Allan | b7a9216 | 2010-01-07 16:32:13 +0000 | [diff] [blame] | 252 | /* If MAC address zero, no need to set the AV bit */ | 
|  | 253 | if (rar_low || rar_high) | 
|  | 254 | rar_high |= E1000_RAH_AV; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 255 |  | 
| Bruce Allan | b7a9216 | 2010-01-07 16:32:13 +0000 | [diff] [blame] | 256 | /* | 
|  | 257 | * Some bridges will combine consecutive 32-bit writes into | 
|  | 258 | * a single burst write, which will malfunction on some parts. | 
|  | 259 | * The flushes avoid this. | 
|  | 260 | */ | 
|  | 261 | ew32(RAL(index), rar_low); | 
|  | 262 | e1e_flush(); | 
|  | 263 | ew32(RAH(index), rar_high); | 
|  | 264 | e1e_flush(); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 265 | } | 
|  | 266 |  | 
|  | 267 | /** | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 268 | *  e1000_hash_mc_addr - Generate a multicast hash value | 
|  | 269 | *  @hw: pointer to the HW structure | 
|  | 270 | *  @mc_addr: pointer to a multicast address | 
|  | 271 | * | 
|  | 272 | *  Generates a multicast address hash value which is used to determine | 
|  | 273 | *  the multicast filter table array address and new table value.  See | 
|  | 274 | *  e1000_mta_set_generic() | 
|  | 275 | **/ | 
|  | 276 | static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) | 
|  | 277 | { | 
|  | 278 | u32 hash_value, hash_mask; | 
|  | 279 | u8 bit_shift = 0; | 
|  | 280 |  | 
|  | 281 | /* Register count multiplied by bits per register */ | 
|  | 282 | hash_mask = (hw->mac.mta_reg_count * 32) - 1; | 
|  | 283 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 284 | /* | 
|  | 285 | * For a mc_filter_type of 0, bit_shift is the number of left-shifts | 
|  | 286 | * where 0xFF would still fall within the hash mask. | 
|  | 287 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 288 | while (hash_mask >> bit_shift != 0xFF) | 
|  | 289 | bit_shift++; | 
|  | 290 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 291 | /* | 
|  | 292 | * The portion of the address that is used for the hash table | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 293 | * is determined by the mc_filter_type setting. | 
|  | 294 | * The algorithm is such that there is a total of 8 bits of shifting. | 
|  | 295 | * The bit_shift for a mc_filter_type of 0 represents the number of | 
|  | 296 | * left-shifts where the MSB of mc_addr[5] would still fall within | 
|  | 297 | * the hash_mask.  Case 0 does this exactly.  Since there are a total | 
|  | 298 | * of 8 bits of shifting, then mc_addr[4] will shift right the | 
|  | 299 | * remaining number of bits. Thus 8 - bit_shift.  The rest of the | 
|  | 300 | * cases are a variation of this algorithm...essentially raising the | 
|  | 301 | * number of bits to shift mc_addr[5] left, while still keeping the | 
|  | 302 | * 8-bit shifting total. | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 303 | * | 
|  | 304 | * For example, given the following Destination MAC Address and an | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 305 | * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask), | 
|  | 306 | * we can see that the bit_shift for case 0 is 4.  These are the hash | 
|  | 307 | * values resulting from each mc_filter_type... | 
|  | 308 | * [0] [1] [2] [3] [4] [5] | 
|  | 309 | * 01  AA  00  12  34  56 | 
|  | 310 | * LSB		 MSB | 
|  | 311 | * | 
|  | 312 | * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 | 
|  | 313 | * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 | 
|  | 314 | * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163 | 
|  | 315 | * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634 | 
|  | 316 | */ | 
|  | 317 | switch (hw->mac.mc_filter_type) { | 
|  | 318 | default: | 
|  | 319 | case 0: | 
|  | 320 | break; | 
|  | 321 | case 1: | 
|  | 322 | bit_shift += 1; | 
|  | 323 | break; | 
|  | 324 | case 2: | 
|  | 325 | bit_shift += 2; | 
|  | 326 | break; | 
|  | 327 | case 3: | 
|  | 328 | bit_shift += 4; | 
|  | 329 | break; | 
|  | 330 | } | 
|  | 331 |  | 
|  | 332 | hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | | 
|  | 333 | (((u16) mc_addr[5]) << bit_shift))); | 
|  | 334 |  | 
|  | 335 | return hash_value; | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | /** | 
| Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 339 | *  e1000e_update_mc_addr_list_generic - Update Multicast addresses | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 340 | *  @hw: pointer to the HW structure | 
|  | 341 | *  @mc_addr_list: array of multicast addresses to program | 
|  | 342 | *  @mc_addr_count: number of multicast addresses to program | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 343 | * | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 344 | *  Updates entire Multicast Table Array. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 345 | *  The caller must have a packed mc_addr_list of multicast addresses. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 346 | **/ | 
| Jeff Kirsher | e2de3eb | 2008-03-28 09:15:11 -0700 | [diff] [blame] | 347 | void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw, | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 348 | u8 *mc_addr_list, u32 mc_addr_count) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 349 | { | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 350 | u32 hash_value, hash_bit, hash_reg; | 
|  | 351 | int i; | 
| Jesse Brandeburg | a72d2b2 | 2009-03-25 22:05:21 +0000 | [diff] [blame] | 352 |  | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 353 | /* clear mta_shadow */ | 
|  | 354 | memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 355 |  | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 356 | /* update mta_shadow from mc_addr_list */ | 
|  | 357 | for (i = 0; (u32) i < mc_addr_count; i++) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 358 | hash_value = e1000_hash_mc_addr(hw, mc_addr_list); | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 359 |  | 
| Jesse Brandeburg | a72d2b2 | 2009-03-25 22:05:21 +0000 | [diff] [blame] | 360 | hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); | 
|  | 361 | hash_bit = hash_value & 0x1F; | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 362 |  | 
|  | 363 | hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit); | 
|  | 364 | mc_addr_list += (ETH_ALEN); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 365 | } | 
| Jesse Brandeburg | a72d2b2 | 2009-03-25 22:05:21 +0000 | [diff] [blame] | 366 |  | 
| Bruce Allan | ab8932f | 2010-01-13 02:05:38 +0000 | [diff] [blame] | 367 | /* replace the entire MTA table */ | 
|  | 368 | for (i = hw->mac.mta_reg_count - 1; i >= 0; i--) | 
|  | 369 | E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]); | 
| Jesse Brandeburg | a72d2b2 | 2009-03-25 22:05:21 +0000 | [diff] [blame] | 370 | e1e_flush(); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 371 | } | 
|  | 372 |  | 
|  | 373 | /** | 
|  | 374 | *  e1000e_clear_hw_cntrs_base - Clear base hardware counters | 
|  | 375 | *  @hw: pointer to the HW structure | 
|  | 376 | * | 
|  | 377 | *  Clears the base hardware counters by reading the counter registers. | 
|  | 378 | **/ | 
|  | 379 | void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw) | 
|  | 380 | { | 
| Bruce Allan | 99673d9 | 2009-11-20 23:27:21 +0000 | [diff] [blame] | 381 | er32(CRCERRS); | 
|  | 382 | er32(SYMERRS); | 
|  | 383 | er32(MPC); | 
|  | 384 | er32(SCC); | 
|  | 385 | er32(ECOL); | 
|  | 386 | er32(MCC); | 
|  | 387 | er32(LATECOL); | 
|  | 388 | er32(COLC); | 
|  | 389 | er32(DC); | 
|  | 390 | er32(SEC); | 
|  | 391 | er32(RLEC); | 
|  | 392 | er32(XONRXC); | 
|  | 393 | er32(XONTXC); | 
|  | 394 | er32(XOFFRXC); | 
|  | 395 | er32(XOFFTXC); | 
|  | 396 | er32(FCRUC); | 
|  | 397 | er32(GPRC); | 
|  | 398 | er32(BPRC); | 
|  | 399 | er32(MPRC); | 
|  | 400 | er32(GPTC); | 
|  | 401 | er32(GORCL); | 
|  | 402 | er32(GORCH); | 
|  | 403 | er32(GOTCL); | 
|  | 404 | er32(GOTCH); | 
|  | 405 | er32(RNBC); | 
|  | 406 | er32(RUC); | 
|  | 407 | er32(RFC); | 
|  | 408 | er32(ROC); | 
|  | 409 | er32(RJC); | 
|  | 410 | er32(TORL); | 
|  | 411 | er32(TORH); | 
|  | 412 | er32(TOTL); | 
|  | 413 | er32(TOTH); | 
|  | 414 | er32(TPR); | 
|  | 415 | er32(TPT); | 
|  | 416 | er32(MPTC); | 
|  | 417 | er32(BPTC); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 418 | } | 
|  | 419 |  | 
|  | 420 | /** | 
|  | 421 | *  e1000e_check_for_copper_link - Check for link (Copper) | 
|  | 422 | *  @hw: pointer to the HW structure | 
|  | 423 | * | 
|  | 424 | *  Checks to see of the link status of the hardware has changed.  If a | 
|  | 425 | *  change in link status has been detected, then we read the PHY registers | 
|  | 426 | *  to get the current speed/duplex if link exists. | 
|  | 427 | **/ | 
|  | 428 | s32 e1000e_check_for_copper_link(struct e1000_hw *hw) | 
|  | 429 | { | 
|  | 430 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 431 | s32 ret_val; | 
|  | 432 | bool link; | 
|  | 433 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 434 | /* | 
|  | 435 | * We only want to go out to the PHY registers to see if Auto-Neg | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 436 | * has completed and/or if our link status has changed.  The | 
|  | 437 | * get_link_status flag is set upon receiving a Link Status | 
|  | 438 | * Change or Rx Sequence Error interrupt. | 
|  | 439 | */ | 
|  | 440 | if (!mac->get_link_status) | 
|  | 441 | return 0; | 
|  | 442 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 443 | /* | 
|  | 444 | * First we want to see if the MII Status Register reports | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 445 | * link.  If so, then we want to get the current speed/duplex | 
|  | 446 | * of the PHY. | 
|  | 447 | */ | 
|  | 448 | ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link); | 
|  | 449 | if (ret_val) | 
|  | 450 | return ret_val; | 
|  | 451 |  | 
|  | 452 | if (!link) | 
|  | 453 | return ret_val; /* No link detected */ | 
|  | 454 |  | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 455 | mac->get_link_status = false; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 456 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 457 | /* | 
|  | 458 | * Check if there was DownShift, must be checked | 
|  | 459 | * immediately after link-up | 
|  | 460 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 461 | e1000e_check_downshift(hw); | 
|  | 462 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 463 | /* | 
|  | 464 | * If we are forcing speed/duplex, then we simply return since | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 465 | * we have already determined whether we have link or not. | 
|  | 466 | */ | 
|  | 467 | if (!mac->autoneg) { | 
|  | 468 | ret_val = -E1000_ERR_CONFIG; | 
|  | 469 | return ret_val; | 
|  | 470 | } | 
|  | 471 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 472 | /* | 
|  | 473 | * Auto-Neg is enabled.  Auto Speed Detection takes care | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 474 | * of MAC speed/duplex configuration.  So we only need to | 
|  | 475 | * configure Collision Distance in the MAC. | 
|  | 476 | */ | 
|  | 477 | e1000e_config_collision_dist(hw); | 
|  | 478 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 479 | /* | 
|  | 480 | * Configure Flow Control now that Auto-Neg has completed. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 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 = e1000e_config_fc_after_link_up(hw); | 
|  | 486 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 487 | e_dbg("Error configuring flow control\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 488 | } | 
|  | 489 |  | 
|  | 490 | return ret_val; | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 | /** | 
|  | 494 | *  e1000e_check_for_fiber_link - Check for link (Fiber) | 
|  | 495 | *  @hw: pointer to the HW structure | 
|  | 496 | * | 
|  | 497 | *  Checks for link up on the hardware.  If link is not up and we have | 
|  | 498 | *  a signal, then we need to force link up. | 
|  | 499 | **/ | 
|  | 500 | s32 e1000e_check_for_fiber_link(struct e1000_hw *hw) | 
|  | 501 | { | 
|  | 502 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 503 | u32 rxcw; | 
|  | 504 | u32 ctrl; | 
|  | 505 | u32 status; | 
|  | 506 | s32 ret_val; | 
|  | 507 |  | 
|  | 508 | ctrl = er32(CTRL); | 
|  | 509 | status = er32(STATUS); | 
|  | 510 | rxcw = er32(RXCW); | 
|  | 511 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 512 | /* | 
|  | 513 | * If we don't have link (auto-negotiation failed or link partner | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 514 | * cannot auto-negotiate), the cable is plugged in (we have signal), | 
|  | 515 | * and our link partner is not trying to auto-negotiate with us (we | 
|  | 516 | * are receiving idles or data), we need to force link up. We also | 
|  | 517 | * need to give auto-negotiation time to complete, in case the cable | 
|  | 518 | * was just plugged in. The autoneg_failed flag does this. | 
|  | 519 | */ | 
|  | 520 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | 
|  | 521 | if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) && | 
|  | 522 | (!(rxcw & E1000_RXCW_C))) { | 
|  | 523 | if (mac->autoneg_failed == 0) { | 
|  | 524 | mac->autoneg_failed = 1; | 
|  | 525 | return 0; | 
|  | 526 | } | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 527 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 528 |  | 
|  | 529 | /* Disable auto-negotiation in the TXCW register */ | 
|  | 530 | ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE)); | 
|  | 531 |  | 
|  | 532 | /* Force link-up and also force full-duplex. */ | 
|  | 533 | ctrl = er32(CTRL); | 
|  | 534 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | 
|  | 535 | ew32(CTRL, ctrl); | 
|  | 536 |  | 
|  | 537 | /* Configure Flow Control after forcing link up. */ | 
|  | 538 | ret_val = e1000e_config_fc_after_link_up(hw); | 
|  | 539 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 540 | e_dbg("Error configuring flow control\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 541 | return ret_val; | 
|  | 542 | } | 
|  | 543 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 544 | /* | 
|  | 545 | * If we are forcing link and we are receiving /C/ ordered | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 546 | * sets, re-enable auto-negotiation in the TXCW register | 
|  | 547 | * and disable forced link in the Device Control register | 
|  | 548 | * in an attempt to auto-negotiate with our link partner. | 
|  | 549 | */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 550 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 551 | ew32(TXCW, mac->txcw); | 
|  | 552 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | 
|  | 553 |  | 
| Alex Chiang | 612e244 | 2009-02-05 23:55:45 -0800 | [diff] [blame] | 554 | mac->serdes_has_link = true; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 555 | } | 
|  | 556 |  | 
|  | 557 | return 0; | 
|  | 558 | } | 
|  | 559 |  | 
|  | 560 | /** | 
|  | 561 | *  e1000e_check_for_serdes_link - Check for link (Serdes) | 
|  | 562 | *  @hw: pointer to the HW structure | 
|  | 563 | * | 
|  | 564 | *  Checks for link up on the hardware.  If link is not up and we have | 
|  | 565 | *  a signal, then we need to force link up. | 
|  | 566 | **/ | 
|  | 567 | s32 e1000e_check_for_serdes_link(struct e1000_hw *hw) | 
|  | 568 | { | 
|  | 569 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 570 | u32 rxcw; | 
|  | 571 | u32 ctrl; | 
|  | 572 | u32 status; | 
|  | 573 | s32 ret_val; | 
|  | 574 |  | 
|  | 575 | ctrl = er32(CTRL); | 
|  | 576 | status = er32(STATUS); | 
|  | 577 | rxcw = er32(RXCW); | 
|  | 578 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 579 | /* | 
|  | 580 | * If we don't have link (auto-negotiation failed or link partner | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 581 | * cannot auto-negotiate), and our link partner is not trying to | 
|  | 582 | * auto-negotiate with us (we are receiving idles or data), | 
|  | 583 | * we need to force link up. We also need to give auto-negotiation | 
|  | 584 | * time to complete. | 
|  | 585 | */ | 
|  | 586 | /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ | 
|  | 587 | if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { | 
|  | 588 | if (mac->autoneg_failed == 0) { | 
|  | 589 | mac->autoneg_failed = 1; | 
|  | 590 | return 0; | 
|  | 591 | } | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 592 | e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 593 |  | 
|  | 594 | /* Disable auto-negotiation in the TXCW register */ | 
|  | 595 | ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE)); | 
|  | 596 |  | 
|  | 597 | /* Force link-up and also force full-duplex. */ | 
|  | 598 | ctrl = er32(CTRL); | 
|  | 599 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); | 
|  | 600 | ew32(CTRL, ctrl); | 
|  | 601 |  | 
|  | 602 | /* Configure Flow Control after forcing link up. */ | 
|  | 603 | ret_val = e1000e_config_fc_after_link_up(hw); | 
|  | 604 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 605 | e_dbg("Error configuring flow control\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 606 | return ret_val; | 
|  | 607 | } | 
|  | 608 | } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 609 | /* | 
|  | 610 | * If we are forcing link and we are receiving /C/ ordered | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 611 | * sets, re-enable auto-negotiation in the TXCW register | 
|  | 612 | * and disable forced link in the Device Control register | 
|  | 613 | * in an attempt to auto-negotiate with our link partner. | 
|  | 614 | */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 615 | e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 616 | ew32(TXCW, mac->txcw); | 
|  | 617 | ew32(CTRL, (ctrl & ~E1000_CTRL_SLU)); | 
|  | 618 |  | 
| Alex Chiang | 612e244 | 2009-02-05 23:55:45 -0800 | [diff] [blame] | 619 | mac->serdes_has_link = true; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 620 | } else if (!(E1000_TXCW_ANE & er32(TXCW))) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 621 | /* | 
|  | 622 | * If we force link for non-auto-negotiation switch, check | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 623 | * link status based on MAC synchronization for internal | 
|  | 624 | * serdes media type. | 
|  | 625 | */ | 
|  | 626 | /* SYNCH bit and IV bit are sticky. */ | 
|  | 627 | udelay(10); | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 628 | rxcw = er32(RXCW); | 
|  | 629 | if (rxcw & E1000_RXCW_SYNCH) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 630 | if (!(rxcw & E1000_RXCW_IV)) { | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 631 | mac->serdes_has_link = true; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 632 | e_dbg("SERDES: Link up - forced.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 633 | } | 
|  | 634 | } else { | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 635 | mac->serdes_has_link = false; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 636 | e_dbg("SERDES: Link down - force failed.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 637 | } | 
|  | 638 | } | 
|  | 639 |  | 
|  | 640 | if (E1000_TXCW_ANE & er32(TXCW)) { | 
|  | 641 | status = er32(STATUS); | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 642 | if (status & E1000_STATUS_LU) { | 
|  | 643 | /* SYNCH bit and IV bit are sticky, so reread rxcw.  */ | 
|  | 644 | udelay(10); | 
|  | 645 | rxcw = er32(RXCW); | 
|  | 646 | if (rxcw & E1000_RXCW_SYNCH) { | 
|  | 647 | if (!(rxcw & E1000_RXCW_IV)) { | 
|  | 648 | mac->serdes_has_link = true; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 649 | e_dbg("SERDES: Link up - autoneg " | 
| Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 650 | "completed successfully.\n"); | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 651 | } else { | 
|  | 652 | mac->serdes_has_link = false; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 653 | e_dbg("SERDES: Link down - invalid" | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 654 | "codewords detected in autoneg.\n"); | 
|  | 655 | } | 
|  | 656 | } else { | 
|  | 657 | mac->serdes_has_link = false; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 658 | e_dbg("SERDES: Link down - no sync.\n"); | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 659 | } | 
|  | 660 | } else { | 
|  | 661 | mac->serdes_has_link = false; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 662 | e_dbg("SERDES: Link down - autoneg failed\n"); | 
| Bruce Allan | 63dcf3d | 2008-11-21 16:50:34 -0800 | [diff] [blame] | 663 | } | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 664 | } | 
|  | 665 |  | 
|  | 666 | return 0; | 
|  | 667 | } | 
|  | 668 |  | 
|  | 669 | /** | 
|  | 670 | *  e1000_set_default_fc_generic - Set flow control default values | 
|  | 671 | *  @hw: pointer to the HW structure | 
|  | 672 | * | 
|  | 673 | *  Read the EEPROM for the default values for flow control and store the | 
|  | 674 | *  values. | 
|  | 675 | **/ | 
|  | 676 | static s32 e1000_set_default_fc_generic(struct e1000_hw *hw) | 
|  | 677 | { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 678 | s32 ret_val; | 
|  | 679 | u16 nvm_data; | 
|  | 680 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 681 | /* | 
|  | 682 | * Read and store word 0x0F of the EEPROM. This word contains bits | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 683 | * that determine the hardware's default PAUSE (flow control) mode, | 
|  | 684 | * a bit that determines whether the HW defaults to enabling or | 
|  | 685 | * disabling auto-negotiation, and the direction of the | 
|  | 686 | * SW defined pins. If there is no SW over-ride of the flow | 
|  | 687 | * control setting, then the variable hw->fc will | 
|  | 688 | * be initialized based on a value in the EEPROM. | 
|  | 689 | */ | 
|  | 690 | ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data); | 
|  | 691 |  | 
|  | 692 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 693 | e_dbg("NVM Read Error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 694 | return ret_val; | 
|  | 695 | } | 
|  | 696 |  | 
|  | 697 | if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 698 | hw->fc.requested_mode = e1000_fc_none; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 699 | else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == | 
|  | 700 | NVM_WORD0F_ASM_DIR) | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 701 | hw->fc.requested_mode = e1000_fc_tx_pause; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 702 | else | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 703 | hw->fc.requested_mode = e1000_fc_full; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 704 |  | 
|  | 705 | return 0; | 
|  | 706 | } | 
|  | 707 |  | 
|  | 708 | /** | 
|  | 709 | *  e1000e_setup_link - Setup flow control and link settings | 
|  | 710 | *  @hw: pointer to the HW structure | 
|  | 711 | * | 
|  | 712 | *  Determines which flow control settings to use, then configures flow | 
|  | 713 | *  control.  Calls the appropriate media-specific link configuration | 
|  | 714 | *  function.  Assuming the adapter has a valid link partner, a valid link | 
|  | 715 | *  should be established.  Assumes the hardware has previously been reset | 
|  | 716 | *  and the transmitter and receiver are not enabled. | 
|  | 717 | **/ | 
|  | 718 | s32 e1000e_setup_link(struct e1000_hw *hw) | 
|  | 719 | { | 
|  | 720 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 721 | s32 ret_val; | 
|  | 722 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 723 | /* | 
|  | 724 | * In the case of the phy reset being blocked, we already have a link. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 725 | * We do not need to set it up again. | 
|  | 726 | */ | 
|  | 727 | if (e1000_check_reset_block(hw)) | 
|  | 728 | return 0; | 
|  | 729 |  | 
| Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 730 | /* | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 731 | * If requested flow control is set to default, set flow control | 
|  | 732 | * based on the EEPROM flow control settings. | 
| Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 733 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 734 | if (hw->fc.requested_mode == e1000_fc_default) { | 
| Auke Kok | 309af40 | 2007-10-05 15:22:02 -0700 | [diff] [blame] | 735 | ret_val = e1000_set_default_fc_generic(hw); | 
|  | 736 | if (ret_val) | 
|  | 737 | return ret_val; | 
|  | 738 | } | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 739 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 740 | /* | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 741 | * Save off the requested flow control mode for use later.  Depending | 
|  | 742 | * on the link partner's capabilities, we may or may not use this mode. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 743 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 744 | hw->fc.current_mode = hw->fc.requested_mode; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 745 |  | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 746 | e_dbg("After fix-ups FlowControl is now = %x\n", | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 747 | hw->fc.current_mode); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 748 |  | 
|  | 749 | /* Call the necessary media_type subroutine to configure the link. */ | 
|  | 750 | ret_val = mac->ops.setup_physical_interface(hw); | 
|  | 751 | if (ret_val) | 
|  | 752 | return ret_val; | 
|  | 753 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 754 | /* | 
|  | 755 | * Initialize the flow control address, type, and PAUSE timer | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 756 | * registers to their default values.  This is done even if flow | 
|  | 757 | * control is disabled, because it does not hurt anything to | 
|  | 758 | * initialize these registers. | 
|  | 759 | */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 760 | e_dbg("Initializing the Flow Control address, type and timer regs\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 761 | ew32(FCT, FLOW_CONTROL_TYPE); | 
|  | 762 | ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH); | 
|  | 763 | ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW); | 
|  | 764 |  | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 765 | ew32(FCTTV, hw->fc.pause_time); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 766 |  | 
|  | 767 | return e1000e_set_fc_watermarks(hw); | 
|  | 768 | } | 
|  | 769 |  | 
|  | 770 | /** | 
|  | 771 | *  e1000_commit_fc_settings_generic - Configure flow control | 
|  | 772 | *  @hw: pointer to the HW structure | 
|  | 773 | * | 
|  | 774 | *  Write the flow control settings to the Transmit Config Word Register (TXCW) | 
|  | 775 | *  base on the flow control settings in e1000_mac_info. | 
|  | 776 | **/ | 
|  | 777 | static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw) | 
|  | 778 | { | 
|  | 779 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 780 | u32 txcw; | 
|  | 781 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 782 | /* | 
|  | 783 | * Check for a software override of the flow control settings, and | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 784 | * setup the device accordingly.  If auto-negotiation is enabled, then | 
|  | 785 | * software will have to set the "PAUSE" bits to the correct value in | 
|  | 786 | * the Transmit Config Word Register (TXCW) and re-start auto- | 
|  | 787 | * negotiation.  However, if auto-negotiation is disabled, then | 
|  | 788 | * software will have to manually configure the two flow control enable | 
|  | 789 | * bits in the CTRL register. | 
|  | 790 | * | 
|  | 791 | * The possible values of the "fc" parameter are: | 
|  | 792 | *      0:  Flow control is completely disabled | 
|  | 793 | *      1:  Rx flow control is enabled (we can receive pause frames, | 
|  | 794 | *	  but not send pause frames). | 
|  | 795 | *      2:  Tx flow control is enabled (we can send pause frames but we | 
|  | 796 | *	  do not support receiving pause frames). | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 797 | *      3:  Both Rx and Tx flow control (symmetric) are enabled. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 798 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 799 | switch (hw->fc.current_mode) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 800 | case e1000_fc_none: | 
|  | 801 | /* Flow control completely disabled by a software over-ride. */ | 
|  | 802 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); | 
|  | 803 | break; | 
|  | 804 | case e1000_fc_rx_pause: | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 805 | /* | 
|  | 806 | * Rx Flow control is enabled and Tx Flow control is disabled | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 807 | * by a software over-ride. Since there really isn't a way to | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 808 | * advertise that we are capable of Rx Pause ONLY, we will | 
|  | 809 | * advertise that we support both symmetric and asymmetric Rx | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 810 | * PAUSE.  Later, we will disable the adapter's ability to send | 
|  | 811 | * PAUSE frames. | 
|  | 812 | */ | 
|  | 813 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 814 | break; | 
|  | 815 | case e1000_fc_tx_pause: | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 816 | /* | 
|  | 817 | * Tx Flow control is enabled, and Rx Flow control is disabled, | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 818 | * by a software over-ride. | 
|  | 819 | */ | 
|  | 820 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); | 
|  | 821 | break; | 
|  | 822 | case e1000_fc_full: | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 823 | /* | 
|  | 824 | * Flow control (both Rx and Tx) is enabled by a software | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 825 | * over-ride. | 
|  | 826 | */ | 
|  | 827 | txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); | 
|  | 828 | break; | 
|  | 829 | default: | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 830 | e_dbg("Flow control param set incorrectly\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 831 | return -E1000_ERR_CONFIG; | 
|  | 832 | break; | 
|  | 833 | } | 
|  | 834 |  | 
|  | 835 | ew32(TXCW, txcw); | 
|  | 836 | mac->txcw = txcw; | 
|  | 837 |  | 
|  | 838 | return 0; | 
|  | 839 | } | 
|  | 840 |  | 
|  | 841 | /** | 
|  | 842 | *  e1000_poll_fiber_serdes_link_generic - Poll for link up | 
|  | 843 | *  @hw: pointer to the HW structure | 
|  | 844 | * | 
|  | 845 | *  Polls for link up by reading the status register, if link fails to come | 
|  | 846 | *  up with auto-negotiation, then the link is forced if a signal is detected. | 
|  | 847 | **/ | 
|  | 848 | static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw) | 
|  | 849 | { | 
|  | 850 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 851 | u32 i, status; | 
|  | 852 | s32 ret_val; | 
|  | 853 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 854 | /* | 
|  | 855 | * If we have a signal (the cable is plugged in, or assumed true for | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 856 | * serdes media) then poll for a "Link-Up" indication in the Device | 
|  | 857 | * Status Register.  Time-out if a link isn't seen in 500 milliseconds | 
|  | 858 | * seconds (Auto-negotiation should complete in less than 500 | 
|  | 859 | * milliseconds even if the other end is doing it in SW). | 
|  | 860 | */ | 
|  | 861 | for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) { | 
|  | 862 | msleep(10); | 
|  | 863 | status = er32(STATUS); | 
|  | 864 | if (status & E1000_STATUS_LU) | 
|  | 865 | break; | 
|  | 866 | } | 
|  | 867 | if (i == FIBER_LINK_UP_LIMIT) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 868 | e_dbg("Never got a valid link from auto-neg!!!\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 869 | mac->autoneg_failed = 1; | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 870 | /* | 
|  | 871 | * AutoNeg failed to achieve a link, so we'll call | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 872 | * mac->check_for_link. This routine will force the | 
|  | 873 | * link up if we detect a signal. This will allow us to | 
|  | 874 | * communicate with non-autonegotiating link partners. | 
|  | 875 | */ | 
|  | 876 | ret_val = mac->ops.check_for_link(hw); | 
|  | 877 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 878 | e_dbg("Error while checking for link\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 879 | return ret_val; | 
|  | 880 | } | 
|  | 881 | mac->autoneg_failed = 0; | 
|  | 882 | } else { | 
|  | 883 | mac->autoneg_failed = 0; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 884 | e_dbg("Valid Link Found\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 885 | } | 
|  | 886 |  | 
|  | 887 | return 0; | 
|  | 888 | } | 
|  | 889 |  | 
|  | 890 | /** | 
|  | 891 | *  e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes | 
|  | 892 | *  @hw: pointer to the HW structure | 
|  | 893 | * | 
|  | 894 | *  Configures collision distance and flow control for fiber and serdes | 
|  | 895 | *  links.  Upon successful setup, poll for link. | 
|  | 896 | **/ | 
|  | 897 | s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw) | 
|  | 898 | { | 
|  | 899 | u32 ctrl; | 
|  | 900 | s32 ret_val; | 
|  | 901 |  | 
|  | 902 | ctrl = er32(CTRL); | 
|  | 903 |  | 
|  | 904 | /* Take the link out of reset */ | 
|  | 905 | ctrl &= ~E1000_CTRL_LRST; | 
|  | 906 |  | 
|  | 907 | e1000e_config_collision_dist(hw); | 
|  | 908 |  | 
|  | 909 | ret_val = e1000_commit_fc_settings_generic(hw); | 
|  | 910 | if (ret_val) | 
|  | 911 | return ret_val; | 
|  | 912 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 913 | /* | 
|  | 914 | * Since auto-negotiation is enabled, take the link out of reset (the | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 915 | * link will be in reset, because we previously reset the chip). This | 
|  | 916 | * will restart auto-negotiation.  If auto-negotiation is successful | 
|  | 917 | * then the link-up status bit will be set and the flow control enable | 
|  | 918 | * bits (RFCE and TFCE) will be set according to their negotiated value. | 
|  | 919 | */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 920 | e_dbg("Auto-negotiation enabled\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 921 |  | 
|  | 922 | ew32(CTRL, ctrl); | 
|  | 923 | e1e_flush(); | 
|  | 924 | msleep(1); | 
|  | 925 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 926 | /* | 
|  | 927 | * For these adapters, the SW definable pin 1 is set when the optics | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 928 | * detect a signal.  If we have a signal, then poll for a "Link-Up" | 
|  | 929 | * indication. | 
|  | 930 | */ | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 931 | if (hw->phy.media_type == e1000_media_type_internal_serdes || | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 932 | (er32(CTRL) & E1000_CTRL_SWDPIN1)) { | 
|  | 933 | ret_val = e1000_poll_fiber_serdes_link_generic(hw); | 
|  | 934 | } else { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 935 | e_dbg("No signal detected\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 936 | } | 
|  | 937 |  | 
|  | 938 | return 0; | 
|  | 939 | } | 
|  | 940 |  | 
|  | 941 | /** | 
|  | 942 | *  e1000e_config_collision_dist - Configure collision distance | 
|  | 943 | *  @hw: pointer to the HW structure | 
|  | 944 | * | 
|  | 945 | *  Configures the collision distance to the default value and is used | 
|  | 946 | *  during link setup. Currently no func pointer exists and all | 
|  | 947 | *  implementations are handled in the generic version of this function. | 
|  | 948 | **/ | 
|  | 949 | void e1000e_config_collision_dist(struct e1000_hw *hw) | 
|  | 950 | { | 
|  | 951 | u32 tctl; | 
|  | 952 |  | 
|  | 953 | tctl = er32(TCTL); | 
|  | 954 |  | 
|  | 955 | tctl &= ~E1000_TCTL_COLD; | 
|  | 956 | tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT; | 
|  | 957 |  | 
|  | 958 | ew32(TCTL, tctl); | 
|  | 959 | e1e_flush(); | 
|  | 960 | } | 
|  | 961 |  | 
|  | 962 | /** | 
|  | 963 | *  e1000e_set_fc_watermarks - Set flow control high/low watermarks | 
|  | 964 | *  @hw: pointer to the HW structure | 
|  | 965 | * | 
|  | 966 | *  Sets the flow control high/low threshold (watermark) registers.  If | 
|  | 967 | *  flow control XON frame transmission is enabled, then set XON frame | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 968 | *  transmission as well. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 969 | **/ | 
|  | 970 | s32 e1000e_set_fc_watermarks(struct e1000_hw *hw) | 
|  | 971 | { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 972 | u32 fcrtl = 0, fcrth = 0; | 
|  | 973 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 974 | /* | 
|  | 975 | * Set the flow control receive threshold registers.  Normally, | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 976 | * these registers will be set to a default threshold that may be | 
|  | 977 | * adjusted later by the driver's runtime code.  However, if the | 
|  | 978 | * ability to transmit pause frames is not enabled, then these | 
|  | 979 | * registers will be set to 0. | 
|  | 980 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 981 | if (hw->fc.current_mode & e1000_fc_tx_pause) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 982 | /* | 
|  | 983 | * We need to set up the Receive Threshold high and low water | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 984 | * marks as well as (optionally) enabling the transmission of | 
|  | 985 | * XON frames. | 
|  | 986 | */ | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 987 | fcrtl = hw->fc.low_water; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 988 | fcrtl |= E1000_FCRTL_XONE; | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 989 | fcrth = hw->fc.high_water; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 990 | } | 
|  | 991 | ew32(FCRTL, fcrtl); | 
|  | 992 | ew32(FCRTH, fcrth); | 
|  | 993 |  | 
|  | 994 | return 0; | 
|  | 995 | } | 
|  | 996 |  | 
|  | 997 | /** | 
|  | 998 | *  e1000e_force_mac_fc - Force the MAC's flow control settings | 
|  | 999 | *  @hw: pointer to the HW structure | 
|  | 1000 | * | 
|  | 1001 | *  Force the MAC's flow control settings.  Sets the TFCE and RFCE bits in the | 
|  | 1002 | *  device control register to reflect the adapter settings.  TFCE and RFCE | 
|  | 1003 | *  need to be explicitly set by software when a copper PHY is used because | 
|  | 1004 | *  autonegotiation is managed by the PHY rather than the MAC.  Software must | 
|  | 1005 | *  also configure these bits when link is forced on a fiber connection. | 
|  | 1006 | **/ | 
|  | 1007 | s32 e1000e_force_mac_fc(struct e1000_hw *hw) | 
|  | 1008 | { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1009 | u32 ctrl; | 
|  | 1010 |  | 
|  | 1011 | ctrl = er32(CTRL); | 
|  | 1012 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1013 | /* | 
|  | 1014 | * Because we didn't get link via the internal auto-negotiation | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1015 | * mechanism (we either forced link or we got link via PHY | 
|  | 1016 | * auto-neg), we have to manually enable/disable transmit an | 
|  | 1017 | * receive flow control. | 
|  | 1018 | * | 
|  | 1019 | * The "Case" statement below enables/disable flow control | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1020 | * according to the "hw->fc.current_mode" parameter. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1021 | * | 
|  | 1022 | * The possible values of the "fc" parameter are: | 
|  | 1023 | *      0:  Flow control is completely disabled | 
|  | 1024 | *      1:  Rx flow control is enabled (we can receive pause | 
|  | 1025 | *	  frames but not send pause frames). | 
|  | 1026 | *      2:  Tx flow control is enabled (we can send pause frames | 
|  | 1027 | *	  frames but we do not receive pause frames). | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1028 | *      3:  Both Rx and Tx flow control (symmetric) is enabled. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1029 | *  other:  No other values should be possible at this point. | 
|  | 1030 | */ | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1031 | e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1032 |  | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1033 | switch (hw->fc.current_mode) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1034 | case e1000_fc_none: | 
|  | 1035 | ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); | 
|  | 1036 | break; | 
|  | 1037 | case e1000_fc_rx_pause: | 
|  | 1038 | ctrl &= (~E1000_CTRL_TFCE); | 
|  | 1039 | ctrl |= E1000_CTRL_RFCE; | 
|  | 1040 | break; | 
|  | 1041 | case e1000_fc_tx_pause: | 
|  | 1042 | ctrl &= (~E1000_CTRL_RFCE); | 
|  | 1043 | ctrl |= E1000_CTRL_TFCE; | 
|  | 1044 | break; | 
|  | 1045 | case e1000_fc_full: | 
|  | 1046 | ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); | 
|  | 1047 | break; | 
|  | 1048 | default: | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1049 | e_dbg("Flow control param set incorrectly\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1050 | return -E1000_ERR_CONFIG; | 
|  | 1051 | } | 
|  | 1052 |  | 
|  | 1053 | ew32(CTRL, ctrl); | 
|  | 1054 |  | 
|  | 1055 | return 0; | 
|  | 1056 | } | 
|  | 1057 |  | 
|  | 1058 | /** | 
|  | 1059 | *  e1000e_config_fc_after_link_up - Configures flow control after link | 
|  | 1060 | *  @hw: pointer to the HW structure | 
|  | 1061 | * | 
|  | 1062 | *  Checks the status of auto-negotiation after link up to ensure that the | 
|  | 1063 | *  speed and duplex were not forced.  If the link needed to be forced, then | 
|  | 1064 | *  flow control needs to be forced also.  If auto-negotiation is enabled | 
|  | 1065 | *  and did not fail, then we configure flow control based on our link | 
|  | 1066 | *  partner. | 
|  | 1067 | **/ | 
|  | 1068 | s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw) | 
|  | 1069 | { | 
|  | 1070 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 1071 | s32 ret_val = 0; | 
|  | 1072 | u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg; | 
|  | 1073 | u16 speed, duplex; | 
|  | 1074 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1075 | /* | 
|  | 1076 | * Check for the case where we have fiber media and auto-neg failed | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1077 | * so we had to force link.  In this case, we need to force the | 
|  | 1078 | * configuration of the MAC to match the "fc" parameter. | 
|  | 1079 | */ | 
|  | 1080 | if (mac->autoneg_failed) { | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1081 | if (hw->phy.media_type == e1000_media_type_fiber || | 
|  | 1082 | hw->phy.media_type == e1000_media_type_internal_serdes) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1083 | ret_val = e1000e_force_mac_fc(hw); | 
|  | 1084 | } else { | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1085 | if (hw->phy.media_type == e1000_media_type_copper) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1086 | ret_val = e1000e_force_mac_fc(hw); | 
|  | 1087 | } | 
|  | 1088 |  | 
|  | 1089 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1090 | e_dbg("Error forcing flow control settings\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1091 | return ret_val; | 
|  | 1092 | } | 
|  | 1093 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1094 | /* | 
|  | 1095 | * Check for the case where we have copper media and auto-neg is | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1096 | * enabled.  In this case, we need to check and see if Auto-Neg | 
|  | 1097 | * has completed, and if so, how the PHY and link partner has | 
|  | 1098 | * flow control configured. | 
|  | 1099 | */ | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1100 | if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1101 | /* | 
|  | 1102 | * Read the MII Status Register and check to see if AutoNeg | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1103 | * has completed.  We read this twice because this reg has | 
|  | 1104 | * some "sticky" (latched) bits. | 
|  | 1105 | */ | 
|  | 1106 | ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1107 | if (ret_val) | 
|  | 1108 | return ret_val; | 
|  | 1109 | ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg); | 
|  | 1110 | if (ret_val) | 
|  | 1111 | return ret_val; | 
|  | 1112 |  | 
|  | 1113 | if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1114 | e_dbg("Copper PHY and Auto Neg " | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1115 | "has not completed.\n"); | 
|  | 1116 | return ret_val; | 
|  | 1117 | } | 
|  | 1118 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1119 | /* | 
|  | 1120 | * The AutoNeg process has completed, so we now need to | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1121 | * read both the Auto Negotiation Advertisement | 
|  | 1122 | * Register (Address 4) and the Auto_Negotiation Base | 
|  | 1123 | * Page Ability Register (Address 5) to determine how | 
|  | 1124 | * flow control was negotiated. | 
|  | 1125 | */ | 
|  | 1126 | ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg); | 
|  | 1127 | if (ret_val) | 
|  | 1128 | return ret_val; | 
|  | 1129 | ret_val = e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg); | 
|  | 1130 | if (ret_val) | 
|  | 1131 | return ret_val; | 
|  | 1132 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1133 | /* | 
|  | 1134 | * Two bits in the Auto Negotiation Advertisement Register | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1135 | * (Address 4) and two bits in the Auto Negotiation Base | 
|  | 1136 | * Page Ability Register (Address 5) determine flow control | 
|  | 1137 | * for both the PHY and the link partner.  The following | 
|  | 1138 | * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, | 
|  | 1139 | * 1999, describes these PAUSE resolution bits and how flow | 
|  | 1140 | * control is determined based upon these settings. | 
|  | 1141 | * NOTE:  DC = Don't Care | 
|  | 1142 | * | 
|  | 1143 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 1144 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution | 
|  | 1145 | *-------|---------|-------|---------|-------------------- | 
|  | 1146 | *   0   |    0    |  DC   |   DC    | e1000_fc_none | 
|  | 1147 | *   0   |    1    |   0   |   DC    | e1000_fc_none | 
|  | 1148 | *   0   |    1    |   1   |    0    | e1000_fc_none | 
|  | 1149 | *   0   |    1    |   1   |    1    | e1000_fc_tx_pause | 
|  | 1150 | *   1   |    0    |   0   |   DC    | e1000_fc_none | 
|  | 1151 | *   1   |   DC    |   1   |   DC    | e1000_fc_full | 
|  | 1152 | *   1   |    1    |   0   |    0    | e1000_fc_none | 
|  | 1153 | *   1   |    1    |   0   |    1    | e1000_fc_rx_pause | 
|  | 1154 | * | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1155 | * Are both PAUSE bits set to 1?  If so, this implies | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1156 | * Symmetric Flow Control is enabled at both ends.  The | 
|  | 1157 | * ASM_DIR bits are irrelevant per the spec. | 
|  | 1158 | * | 
|  | 1159 | * For Symmetric Flow Control: | 
|  | 1160 | * | 
|  | 1161 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 1162 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 1163 | *-------|---------|-------|---------|-------------------- | 
|  | 1164 | *   1   |   DC    |   1   |   DC    | E1000_fc_full | 
|  | 1165 | * | 
|  | 1166 | */ | 
|  | 1167 | if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 1168 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1169 | /* | 
|  | 1170 | * Now we need to check if the user selected Rx ONLY | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1171 | * of pause frames.  In this case, we had to advertise | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1172 | * FULL flow control because we could not advertise Rx | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1173 | * ONLY. Hence, we must now check to see if we need to | 
|  | 1174 | * turn OFF  the TRANSMISSION of PAUSE frames. | 
|  | 1175 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1176 | if (hw->fc.requested_mode == e1000_fc_full) { | 
|  | 1177 | hw->fc.current_mode = e1000_fc_full; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1178 | e_dbg("Flow Control = FULL.\r\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1179 | } else { | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1180 | hw->fc.current_mode = e1000_fc_rx_pause; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1181 | e_dbg("Flow Control = " | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1182 | "RX PAUSE frames only.\r\n"); | 
|  | 1183 | } | 
|  | 1184 | } | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1185 | /* | 
|  | 1186 | * For receiving PAUSE frames ONLY. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1187 | * | 
|  | 1188 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 1189 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 1190 | *-------|---------|-------|---------|-------------------- | 
|  | 1191 | *   0   |    1    |   1   |    1    | e1000_fc_tx_pause | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1192 | */ | 
|  | 1193 | else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 1194 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 1195 | (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 1196 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1197 | hw->fc.current_mode = e1000_fc_tx_pause; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1198 | e_dbg("Flow Control = Tx PAUSE frames only.\r\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1199 | } | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1200 | /* | 
|  | 1201 | * For transmitting PAUSE frames ONLY. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1202 | * | 
|  | 1203 | *   LOCAL DEVICE  |   LINK PARTNER | 
|  | 1204 | * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result | 
|  | 1205 | *-------|---------|-------|---------|-------------------- | 
|  | 1206 | *   1   |    1    |   0   |    1    | e1000_fc_rx_pause | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | */ | 
|  | 1208 | else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && | 
|  | 1209 | (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && | 
|  | 1210 | !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && | 
|  | 1211 | (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1212 | hw->fc.current_mode = e1000_fc_rx_pause; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1213 | e_dbg("Flow Control = Rx PAUSE frames only.\r\n"); | 
| Jesse Brandeburg | de92d84 | 2008-02-21 15:11:02 -0800 | [diff] [blame] | 1214 | } else { | 
|  | 1215 | /* | 
|  | 1216 | * Per the IEEE spec, at this point flow control | 
|  | 1217 | * should be disabled. | 
|  | 1218 | */ | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1219 | hw->fc.current_mode = e1000_fc_none; | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1220 | e_dbg("Flow Control = NONE.\r\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1221 | } | 
|  | 1222 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1223 | /* | 
|  | 1224 | * Now we need to do one last check...  If we auto- | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1225 | * negotiated to HALF DUPLEX, flow control should not be | 
|  | 1226 | * enabled per IEEE 802.3 spec. | 
|  | 1227 | */ | 
|  | 1228 | ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex); | 
|  | 1229 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1230 | e_dbg("Error getting link speed and duplex\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1231 | return ret_val; | 
|  | 1232 | } | 
|  | 1233 |  | 
|  | 1234 | if (duplex == HALF_DUPLEX) | 
| Bruce Allan | 5c48ef3e2 | 2008-11-21 16:57:36 -0800 | [diff] [blame] | 1235 | hw->fc.current_mode = e1000_fc_none; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1236 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1237 | /* | 
|  | 1238 | * Now we call a subroutine to actually force the MAC | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1239 | * controller to use the correct flow control settings. | 
|  | 1240 | */ | 
|  | 1241 | ret_val = e1000e_force_mac_fc(hw); | 
|  | 1242 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1243 | e_dbg("Error forcing flow control settings\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1244 | return ret_val; | 
|  | 1245 | } | 
|  | 1246 | } | 
|  | 1247 |  | 
|  | 1248 | return 0; | 
|  | 1249 | } | 
|  | 1250 |  | 
|  | 1251 | /** | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1252 | *  e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1253 | *  @hw: pointer to the HW structure | 
|  | 1254 | *  @speed: stores the current speed | 
|  | 1255 | *  @duplex: stores the current duplex | 
|  | 1256 | * | 
|  | 1257 | *  Read the status register for the current speed/duplex and store the current | 
|  | 1258 | *  speed and duplex for copper connections. | 
|  | 1259 | **/ | 
|  | 1260 | s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex) | 
|  | 1261 | { | 
|  | 1262 | u32 status; | 
|  | 1263 |  | 
|  | 1264 | status = er32(STATUS); | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1265 | if (status & E1000_STATUS_SPEED_1000) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1266 | *speed = SPEED_1000; | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1267 | else if (status & E1000_STATUS_SPEED_100) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1268 | *speed = SPEED_100; | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1269 | else | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1270 | *speed = SPEED_10; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1271 |  | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1272 | if (status & E1000_STATUS_FD) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1273 | *duplex = FULL_DUPLEX; | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1274 | else | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1275 | *duplex = HALF_DUPLEX; | 
| Joe Perches | 2c73e1f | 2010-03-26 20:16:59 +0000 | [diff] [blame] | 1276 |  | 
|  | 1277 | e_dbg("%u Mbps, %s Duplex\n", | 
|  | 1278 | *speed == SPEED_1000 ? 1000 : *speed == SPEED_100 ? 100 : 10, | 
|  | 1279 | *duplex == FULL_DUPLEX ? "Full" : "Half"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1280 |  | 
|  | 1281 | return 0; | 
|  | 1282 | } | 
|  | 1283 |  | 
|  | 1284 | /** | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1285 | *  e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1286 | *  @hw: pointer to the HW structure | 
|  | 1287 | *  @speed: stores the current speed | 
|  | 1288 | *  @duplex: stores the current duplex | 
|  | 1289 | * | 
|  | 1290 | *  Sets the speed and duplex to gigabit full duplex (the only possible option) | 
|  | 1291 | *  for fiber/serdes links. | 
|  | 1292 | **/ | 
|  | 1293 | s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex) | 
|  | 1294 | { | 
|  | 1295 | *speed = SPEED_1000; | 
|  | 1296 | *duplex = FULL_DUPLEX; | 
|  | 1297 |  | 
|  | 1298 | return 0; | 
|  | 1299 | } | 
|  | 1300 |  | 
|  | 1301 | /** | 
|  | 1302 | *  e1000e_get_hw_semaphore - Acquire hardware semaphore | 
|  | 1303 | *  @hw: pointer to the HW structure | 
|  | 1304 | * | 
|  | 1305 | *  Acquire the HW semaphore to access the PHY or NVM | 
|  | 1306 | **/ | 
|  | 1307 | s32 e1000e_get_hw_semaphore(struct e1000_hw *hw) | 
|  | 1308 | { | 
|  | 1309 | u32 swsm; | 
|  | 1310 | s32 timeout = hw->nvm.word_size + 1; | 
|  | 1311 | s32 i = 0; | 
|  | 1312 |  | 
|  | 1313 | /* Get the SW semaphore */ | 
|  | 1314 | while (i < timeout) { | 
|  | 1315 | swsm = er32(SWSM); | 
|  | 1316 | if (!(swsm & E1000_SWSM_SMBI)) | 
|  | 1317 | break; | 
|  | 1318 |  | 
|  | 1319 | udelay(50); | 
|  | 1320 | i++; | 
|  | 1321 | } | 
|  | 1322 |  | 
|  | 1323 | if (i == timeout) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1324 | e_dbg("Driver can't access device - SMBI bit is set.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1325 | return -E1000_ERR_NVM; | 
|  | 1326 | } | 
|  | 1327 |  | 
|  | 1328 | /* Get the FW semaphore. */ | 
|  | 1329 | for (i = 0; i < timeout; i++) { | 
|  | 1330 | swsm = er32(SWSM); | 
|  | 1331 | ew32(SWSM, swsm | E1000_SWSM_SWESMBI); | 
|  | 1332 |  | 
|  | 1333 | /* Semaphore acquired if bit latched */ | 
|  | 1334 | if (er32(SWSM) & E1000_SWSM_SWESMBI) | 
|  | 1335 | break; | 
|  | 1336 |  | 
|  | 1337 | udelay(50); | 
|  | 1338 | } | 
|  | 1339 |  | 
|  | 1340 | if (i == timeout) { | 
|  | 1341 | /* Release semaphores */ | 
|  | 1342 | e1000e_put_hw_semaphore(hw); | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1343 | e_dbg("Driver can't access the NVM\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1344 | return -E1000_ERR_NVM; | 
|  | 1345 | } | 
|  | 1346 |  | 
|  | 1347 | return 0; | 
|  | 1348 | } | 
|  | 1349 |  | 
|  | 1350 | /** | 
|  | 1351 | *  e1000e_put_hw_semaphore - Release hardware semaphore | 
|  | 1352 | *  @hw: pointer to the HW structure | 
|  | 1353 | * | 
|  | 1354 | *  Release hardware semaphore used to access the PHY or NVM | 
|  | 1355 | **/ | 
|  | 1356 | void e1000e_put_hw_semaphore(struct e1000_hw *hw) | 
|  | 1357 | { | 
|  | 1358 | u32 swsm; | 
|  | 1359 |  | 
|  | 1360 | swsm = er32(SWSM); | 
|  | 1361 | swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); | 
|  | 1362 | ew32(SWSM, swsm); | 
|  | 1363 | } | 
|  | 1364 |  | 
|  | 1365 | /** | 
|  | 1366 | *  e1000e_get_auto_rd_done - Check for auto read completion | 
|  | 1367 | *  @hw: pointer to the HW structure | 
|  | 1368 | * | 
|  | 1369 | *  Check EEPROM for Auto Read done bit. | 
|  | 1370 | **/ | 
|  | 1371 | s32 e1000e_get_auto_rd_done(struct e1000_hw *hw) | 
|  | 1372 | { | 
|  | 1373 | s32 i = 0; | 
|  | 1374 |  | 
|  | 1375 | while (i < AUTO_READ_DONE_TIMEOUT) { | 
|  | 1376 | if (er32(EECD) & E1000_EECD_AUTO_RD) | 
|  | 1377 | break; | 
|  | 1378 | msleep(1); | 
|  | 1379 | i++; | 
|  | 1380 | } | 
|  | 1381 |  | 
|  | 1382 | if (i == AUTO_READ_DONE_TIMEOUT) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1383 | e_dbg("Auto read by HW from NVM has not completed.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1384 | return -E1000_ERR_RESET; | 
|  | 1385 | } | 
|  | 1386 |  | 
|  | 1387 | return 0; | 
|  | 1388 | } | 
|  | 1389 |  | 
|  | 1390 | /** | 
|  | 1391 | *  e1000e_valid_led_default - Verify a valid default LED config | 
|  | 1392 | *  @hw: pointer to the HW structure | 
|  | 1393 | *  @data: pointer to the NVM (EEPROM) | 
|  | 1394 | * | 
|  | 1395 | *  Read the EEPROM for the current default LED configuration.  If the | 
|  | 1396 | *  LED configuration is not valid, set to a valid LED configuration. | 
|  | 1397 | **/ | 
|  | 1398 | s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data) | 
|  | 1399 | { | 
|  | 1400 | s32 ret_val; | 
|  | 1401 |  | 
|  | 1402 | ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data); | 
|  | 1403 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1404 | e_dbg("NVM Read Error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1405 | return ret_val; | 
|  | 1406 | } | 
|  | 1407 |  | 
|  | 1408 | if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) | 
|  | 1409 | *data = ID_LED_DEFAULT; | 
|  | 1410 |  | 
|  | 1411 | return 0; | 
|  | 1412 | } | 
|  | 1413 |  | 
|  | 1414 | /** | 
|  | 1415 | *  e1000e_id_led_init - | 
|  | 1416 | *  @hw: pointer to the HW structure | 
|  | 1417 | * | 
|  | 1418 | **/ | 
|  | 1419 | s32 e1000e_id_led_init(struct e1000_hw *hw) | 
|  | 1420 | { | 
|  | 1421 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 1422 | s32 ret_val; | 
|  | 1423 | const u32 ledctl_mask = 0x000000FF; | 
|  | 1424 | const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; | 
|  | 1425 | const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; | 
|  | 1426 | u16 data, i, temp; | 
|  | 1427 | const u16 led_mask = 0x0F; | 
|  | 1428 |  | 
|  | 1429 | ret_val = hw->nvm.ops.valid_led_default(hw, &data); | 
|  | 1430 | if (ret_val) | 
|  | 1431 | return ret_val; | 
|  | 1432 |  | 
|  | 1433 | mac->ledctl_default = er32(LEDCTL); | 
|  | 1434 | mac->ledctl_mode1 = mac->ledctl_default; | 
|  | 1435 | mac->ledctl_mode2 = mac->ledctl_default; | 
|  | 1436 |  | 
|  | 1437 | for (i = 0; i < 4; i++) { | 
|  | 1438 | temp = (data >> (i << 2)) & led_mask; | 
|  | 1439 | switch (temp) { | 
|  | 1440 | case ID_LED_ON1_DEF2: | 
|  | 1441 | case ID_LED_ON1_ON2: | 
|  | 1442 | case ID_LED_ON1_OFF2: | 
|  | 1443 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 1444 | mac->ledctl_mode1 |= ledctl_on << (i << 3); | 
|  | 1445 | break; | 
|  | 1446 | case ID_LED_OFF1_DEF2: | 
|  | 1447 | case ID_LED_OFF1_ON2: | 
|  | 1448 | case ID_LED_OFF1_OFF2: | 
|  | 1449 | mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); | 
|  | 1450 | mac->ledctl_mode1 |= ledctl_off << (i << 3); | 
|  | 1451 | break; | 
|  | 1452 | default: | 
|  | 1453 | /* Do nothing */ | 
|  | 1454 | break; | 
|  | 1455 | } | 
|  | 1456 | switch (temp) { | 
|  | 1457 | case ID_LED_DEF1_ON2: | 
|  | 1458 | case ID_LED_ON1_ON2: | 
|  | 1459 | case ID_LED_OFF1_ON2: | 
|  | 1460 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 1461 | mac->ledctl_mode2 |= ledctl_on << (i << 3); | 
|  | 1462 | break; | 
|  | 1463 | case ID_LED_DEF1_OFF2: | 
|  | 1464 | case ID_LED_ON1_OFF2: | 
|  | 1465 | case ID_LED_OFF1_OFF2: | 
|  | 1466 | mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); | 
|  | 1467 | mac->ledctl_mode2 |= ledctl_off << (i << 3); | 
|  | 1468 | break; | 
|  | 1469 | default: | 
|  | 1470 | /* Do nothing */ | 
|  | 1471 | break; | 
|  | 1472 | } | 
|  | 1473 | } | 
|  | 1474 |  | 
|  | 1475 | return 0; | 
|  | 1476 | } | 
|  | 1477 |  | 
|  | 1478 | /** | 
| Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 1479 | *  e1000e_setup_led_generic - Configures SW controllable LED | 
|  | 1480 | *  @hw: pointer to the HW structure | 
|  | 1481 | * | 
|  | 1482 | *  This prepares the SW controllable LED for use and saves the current state | 
|  | 1483 | *  of the LED so it can be later restored. | 
|  | 1484 | **/ | 
|  | 1485 | s32 e1000e_setup_led_generic(struct e1000_hw *hw) | 
|  | 1486 | { | 
|  | 1487 | u32 ledctl; | 
|  | 1488 |  | 
|  | 1489 | if (hw->mac.ops.setup_led != e1000e_setup_led_generic) { | 
|  | 1490 | return -E1000_ERR_CONFIG; | 
|  | 1491 | } | 
|  | 1492 |  | 
|  | 1493 | if (hw->phy.media_type == e1000_media_type_fiber) { | 
|  | 1494 | ledctl = er32(LEDCTL); | 
|  | 1495 | hw->mac.ledctl_default = ledctl; | 
|  | 1496 | /* Turn off LED0 */ | 
|  | 1497 | ledctl &= ~(E1000_LEDCTL_LED0_IVRT | | 
|  | 1498 | E1000_LEDCTL_LED0_BLINK | | 
|  | 1499 | E1000_LEDCTL_LED0_MODE_MASK); | 
|  | 1500 | ledctl |= (E1000_LEDCTL_MODE_LED_OFF << | 
|  | 1501 | E1000_LEDCTL_LED0_MODE_SHIFT); | 
|  | 1502 | ew32(LEDCTL, ledctl); | 
|  | 1503 | } else if (hw->phy.media_type == e1000_media_type_copper) { | 
|  | 1504 | ew32(LEDCTL, hw->mac.ledctl_mode1); | 
|  | 1505 | } | 
|  | 1506 |  | 
|  | 1507 | return 0; | 
|  | 1508 | } | 
|  | 1509 |  | 
|  | 1510 | /** | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1511 | *  e1000e_cleanup_led_generic - Set LED config to default operation | 
|  | 1512 | *  @hw: pointer to the HW structure | 
|  | 1513 | * | 
|  | 1514 | *  Remove the current LED configuration and set the LED configuration | 
|  | 1515 | *  to the default value, saved from the EEPROM. | 
|  | 1516 | **/ | 
|  | 1517 | s32 e1000e_cleanup_led_generic(struct e1000_hw *hw) | 
|  | 1518 | { | 
|  | 1519 | ew32(LEDCTL, hw->mac.ledctl_default); | 
|  | 1520 | return 0; | 
|  | 1521 | } | 
|  | 1522 |  | 
|  | 1523 | /** | 
|  | 1524 | *  e1000e_blink_led - Blink LED | 
|  | 1525 | *  @hw: pointer to the HW structure | 
|  | 1526 | * | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1527 | *  Blink the LEDs which are set to be on. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1528 | **/ | 
|  | 1529 | s32 e1000e_blink_led(struct e1000_hw *hw) | 
|  | 1530 | { | 
|  | 1531 | u32 ledctl_blink = 0; | 
|  | 1532 | u32 i; | 
|  | 1533 |  | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1534 | if (hw->phy.media_type == e1000_media_type_fiber) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1535 | /* always blink LED0 for PCI-E fiber */ | 
|  | 1536 | ledctl_blink = E1000_LEDCTL_LED0_BLINK | | 
|  | 1537 | (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); | 
|  | 1538 | } else { | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1539 | /* | 
|  | 1540 | * set the blink bit for each LED that's "on" (0x0E) | 
|  | 1541 | * in ledctl_mode2 | 
|  | 1542 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1543 | ledctl_blink = hw->mac.ledctl_mode2; | 
|  | 1544 | for (i = 0; i < 4; i++) | 
|  | 1545 | if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) == | 
|  | 1546 | E1000_LEDCTL_MODE_LED_ON) | 
|  | 1547 | ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << | 
|  | 1548 | (i * 8)); | 
|  | 1549 | } | 
|  | 1550 |  | 
|  | 1551 | ew32(LEDCTL, ledctl_blink); | 
|  | 1552 |  | 
|  | 1553 | return 0; | 
|  | 1554 | } | 
|  | 1555 |  | 
|  | 1556 | /** | 
|  | 1557 | *  e1000e_led_on_generic - Turn LED on | 
|  | 1558 | *  @hw: pointer to the HW structure | 
|  | 1559 | * | 
|  | 1560 | *  Turn LED on. | 
|  | 1561 | **/ | 
|  | 1562 | s32 e1000e_led_on_generic(struct e1000_hw *hw) | 
|  | 1563 | { | 
|  | 1564 | u32 ctrl; | 
|  | 1565 |  | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1566 | switch (hw->phy.media_type) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1567 | case e1000_media_type_fiber: | 
|  | 1568 | ctrl = er32(CTRL); | 
|  | 1569 | ctrl &= ~E1000_CTRL_SWDPIN0; | 
|  | 1570 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 1571 | ew32(CTRL, ctrl); | 
|  | 1572 | break; | 
|  | 1573 | case e1000_media_type_copper: | 
|  | 1574 | ew32(LEDCTL, hw->mac.ledctl_mode2); | 
|  | 1575 | break; | 
|  | 1576 | default: | 
|  | 1577 | break; | 
|  | 1578 | } | 
|  | 1579 |  | 
|  | 1580 | return 0; | 
|  | 1581 | } | 
|  | 1582 |  | 
|  | 1583 | /** | 
|  | 1584 | *  e1000e_led_off_generic - Turn LED off | 
|  | 1585 | *  @hw: pointer to the HW structure | 
|  | 1586 | * | 
|  | 1587 | *  Turn LED off. | 
|  | 1588 | **/ | 
|  | 1589 | s32 e1000e_led_off_generic(struct e1000_hw *hw) | 
|  | 1590 | { | 
|  | 1591 | u32 ctrl; | 
|  | 1592 |  | 
| Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1593 | switch (hw->phy.media_type) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1594 | case e1000_media_type_fiber: | 
|  | 1595 | ctrl = er32(CTRL); | 
|  | 1596 | ctrl |= E1000_CTRL_SWDPIN0; | 
|  | 1597 | ctrl |= E1000_CTRL_SWDPIO0; | 
|  | 1598 | ew32(CTRL, ctrl); | 
|  | 1599 | break; | 
|  | 1600 | case e1000_media_type_copper: | 
|  | 1601 | ew32(LEDCTL, hw->mac.ledctl_mode1); | 
|  | 1602 | break; | 
|  | 1603 | default: | 
|  | 1604 | break; | 
|  | 1605 | } | 
|  | 1606 |  | 
|  | 1607 | return 0; | 
|  | 1608 | } | 
|  | 1609 |  | 
|  | 1610 | /** | 
|  | 1611 | *  e1000e_set_pcie_no_snoop - Set PCI-express capabilities | 
|  | 1612 | *  @hw: pointer to the HW structure | 
|  | 1613 | *  @no_snoop: bitmap of snoop events | 
|  | 1614 | * | 
|  | 1615 | *  Set the PCI-express register to snoop for events enabled in 'no_snoop'. | 
|  | 1616 | **/ | 
|  | 1617 | void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop) | 
|  | 1618 | { | 
|  | 1619 | u32 gcr; | 
|  | 1620 |  | 
|  | 1621 | if (no_snoop) { | 
|  | 1622 | gcr = er32(GCR); | 
|  | 1623 | gcr &= ~(PCIE_NO_SNOOP_ALL); | 
|  | 1624 | gcr |= no_snoop; | 
|  | 1625 | ew32(GCR, gcr); | 
|  | 1626 | } | 
|  | 1627 | } | 
|  | 1628 |  | 
|  | 1629 | /** | 
|  | 1630 | *  e1000e_disable_pcie_master - Disables PCI-express master access | 
|  | 1631 | *  @hw: pointer to the HW structure | 
|  | 1632 | * | 
|  | 1633 | *  Returns 0 if successful, else returns -10 | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 1634 | *  (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1635 | *  the master requests to be disabled. | 
|  | 1636 | * | 
|  | 1637 | *  Disables PCI-Express master access and verifies there are no pending | 
|  | 1638 | *  requests. | 
|  | 1639 | **/ | 
|  | 1640 | s32 e1000e_disable_pcie_master(struct e1000_hw *hw) | 
|  | 1641 | { | 
|  | 1642 | u32 ctrl; | 
|  | 1643 | s32 timeout = MASTER_DISABLE_TIMEOUT; | 
|  | 1644 |  | 
|  | 1645 | ctrl = er32(CTRL); | 
|  | 1646 | ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; | 
|  | 1647 | ew32(CTRL, ctrl); | 
|  | 1648 |  | 
|  | 1649 | while (timeout) { | 
|  | 1650 | if (!(er32(STATUS) & | 
|  | 1651 | E1000_STATUS_GIO_MASTER_ENABLE)) | 
|  | 1652 | break; | 
|  | 1653 | udelay(100); | 
|  | 1654 | timeout--; | 
|  | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | if (!timeout) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1658 | e_dbg("Master requests are pending.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1659 | return -E1000_ERR_MASTER_REQUESTS_PENDING; | 
|  | 1660 | } | 
|  | 1661 |  | 
|  | 1662 | return 0; | 
|  | 1663 | } | 
|  | 1664 |  | 
|  | 1665 | /** | 
|  | 1666 | *  e1000e_reset_adaptive - Reset Adaptive Interframe Spacing | 
|  | 1667 | *  @hw: pointer to the HW structure | 
|  | 1668 | * | 
|  | 1669 | *  Reset the Adaptive Interframe Spacing throttle to default values. | 
|  | 1670 | **/ | 
|  | 1671 | void e1000e_reset_adaptive(struct e1000_hw *hw) | 
|  | 1672 | { | 
|  | 1673 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 1674 |  | 
| Bruce Allan | f464ba8 | 2010-01-07 16:31:35 +0000 | [diff] [blame] | 1675 | if (!mac->adaptive_ifs) { | 
|  | 1676 | e_dbg("Not in Adaptive IFS mode!\n"); | 
|  | 1677 | goto out; | 
|  | 1678 | } | 
|  | 1679 |  | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1680 | mac->current_ifs_val = 0; | 
|  | 1681 | mac->ifs_min_val = IFS_MIN; | 
|  | 1682 | mac->ifs_max_val = IFS_MAX; | 
|  | 1683 | mac->ifs_step_size = IFS_STEP; | 
|  | 1684 | mac->ifs_ratio = IFS_RATIO; | 
|  | 1685 |  | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 1686 | mac->in_ifs_mode = false; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1687 | ew32(AIT, 0); | 
| Bruce Allan | f464ba8 | 2010-01-07 16:31:35 +0000 | [diff] [blame] | 1688 | out: | 
|  | 1689 | return; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1690 | } | 
|  | 1691 |  | 
|  | 1692 | /** | 
|  | 1693 | *  e1000e_update_adaptive - Update Adaptive Interframe Spacing | 
|  | 1694 | *  @hw: pointer to the HW structure | 
|  | 1695 | * | 
|  | 1696 | *  Update the Adaptive Interframe Spacing Throttle value based on the | 
|  | 1697 | *  time between transmitted packets and time between collisions. | 
|  | 1698 | **/ | 
|  | 1699 | void e1000e_update_adaptive(struct e1000_hw *hw) | 
|  | 1700 | { | 
|  | 1701 | struct e1000_mac_info *mac = &hw->mac; | 
|  | 1702 |  | 
| Bruce Allan | f464ba8 | 2010-01-07 16:31:35 +0000 | [diff] [blame] | 1703 | if (!mac->adaptive_ifs) { | 
|  | 1704 | e_dbg("Not in Adaptive IFS mode!\n"); | 
|  | 1705 | goto out; | 
|  | 1706 | } | 
|  | 1707 |  | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1708 | if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) { | 
|  | 1709 | if (mac->tx_packet_delta > MIN_NUM_XMITS) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 1710 | mac->in_ifs_mode = true; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1711 | if (mac->current_ifs_val < mac->ifs_max_val) { | 
|  | 1712 | if (!mac->current_ifs_val) | 
|  | 1713 | mac->current_ifs_val = mac->ifs_min_val; | 
|  | 1714 | else | 
|  | 1715 | mac->current_ifs_val += | 
|  | 1716 | mac->ifs_step_size; | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1717 | ew32(AIT, mac->current_ifs_val); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1718 | } | 
|  | 1719 | } | 
|  | 1720 | } else { | 
|  | 1721 | if (mac->in_ifs_mode && | 
|  | 1722 | (mac->tx_packet_delta <= MIN_NUM_XMITS)) { | 
|  | 1723 | mac->current_ifs_val = 0; | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 1724 | mac->in_ifs_mode = false; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1725 | ew32(AIT, 0); | 
|  | 1726 | } | 
|  | 1727 | } | 
| Bruce Allan | f464ba8 | 2010-01-07 16:31:35 +0000 | [diff] [blame] | 1728 | out: | 
|  | 1729 | return; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1730 | } | 
|  | 1731 |  | 
|  | 1732 | /** | 
|  | 1733 | *  e1000_raise_eec_clk - Raise EEPROM clock | 
|  | 1734 | *  @hw: pointer to the HW structure | 
|  | 1735 | *  @eecd: pointer to the EEPROM | 
|  | 1736 | * | 
|  | 1737 | *  Enable/Raise the EEPROM clock bit. | 
|  | 1738 | **/ | 
|  | 1739 | static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) | 
|  | 1740 | { | 
|  | 1741 | *eecd = *eecd | E1000_EECD_SK; | 
|  | 1742 | ew32(EECD, *eecd); | 
|  | 1743 | e1e_flush(); | 
|  | 1744 | udelay(hw->nvm.delay_usec); | 
|  | 1745 | } | 
|  | 1746 |  | 
|  | 1747 | /** | 
|  | 1748 | *  e1000_lower_eec_clk - Lower EEPROM clock | 
|  | 1749 | *  @hw: pointer to the HW structure | 
|  | 1750 | *  @eecd: pointer to the EEPROM | 
|  | 1751 | * | 
|  | 1752 | *  Clear/Lower the EEPROM clock bit. | 
|  | 1753 | **/ | 
|  | 1754 | static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) | 
|  | 1755 | { | 
|  | 1756 | *eecd = *eecd & ~E1000_EECD_SK; | 
|  | 1757 | ew32(EECD, *eecd); | 
|  | 1758 | e1e_flush(); | 
|  | 1759 | udelay(hw->nvm.delay_usec); | 
|  | 1760 | } | 
|  | 1761 |  | 
|  | 1762 | /** | 
|  | 1763 | *  e1000_shift_out_eec_bits - Shift data bits our to the EEPROM | 
|  | 1764 | *  @hw: pointer to the HW structure | 
|  | 1765 | *  @data: data to send to the EEPROM | 
|  | 1766 | *  @count: number of bits to shift out | 
|  | 1767 | * | 
|  | 1768 | *  We need to shift 'count' bits out to the EEPROM.  So, the value in the | 
|  | 1769 | *  "data" parameter will be shifted out to the EEPROM one bit at a time. | 
|  | 1770 | *  In order to do this, "data" must be broken down into bits. | 
|  | 1771 | **/ | 
|  | 1772 | static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) | 
|  | 1773 | { | 
|  | 1774 | struct e1000_nvm_info *nvm = &hw->nvm; | 
|  | 1775 | u32 eecd = er32(EECD); | 
|  | 1776 | u32 mask; | 
|  | 1777 |  | 
|  | 1778 | mask = 0x01 << (count - 1); | 
|  | 1779 | if (nvm->type == e1000_nvm_eeprom_spi) | 
|  | 1780 | eecd |= E1000_EECD_DO; | 
|  | 1781 |  | 
|  | 1782 | do { | 
|  | 1783 | eecd &= ~E1000_EECD_DI; | 
|  | 1784 |  | 
|  | 1785 | if (data & mask) | 
|  | 1786 | eecd |= E1000_EECD_DI; | 
|  | 1787 |  | 
|  | 1788 | ew32(EECD, eecd); | 
|  | 1789 | e1e_flush(); | 
|  | 1790 |  | 
|  | 1791 | udelay(nvm->delay_usec); | 
|  | 1792 |  | 
|  | 1793 | e1000_raise_eec_clk(hw, &eecd); | 
|  | 1794 | e1000_lower_eec_clk(hw, &eecd); | 
|  | 1795 |  | 
|  | 1796 | mask >>= 1; | 
|  | 1797 | } while (mask); | 
|  | 1798 |  | 
|  | 1799 | eecd &= ~E1000_EECD_DI; | 
|  | 1800 | ew32(EECD, eecd); | 
|  | 1801 | } | 
|  | 1802 |  | 
|  | 1803 | /** | 
|  | 1804 | *  e1000_shift_in_eec_bits - Shift data bits in from the EEPROM | 
|  | 1805 | *  @hw: pointer to the HW structure | 
|  | 1806 | *  @count: number of bits to shift in | 
|  | 1807 | * | 
|  | 1808 | *  In order to read a register from the EEPROM, we need to shift 'count' bits | 
|  | 1809 | *  in from the EEPROM.  Bits are "shifted in" by raising the clock input to | 
|  | 1810 | *  the EEPROM (setting the SK bit), and then reading the value of the data out | 
|  | 1811 | *  "DO" bit.  During this "shifting in" process the data in "DI" bit should | 
|  | 1812 | *  always be clear. | 
|  | 1813 | **/ | 
|  | 1814 | static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) | 
|  | 1815 | { | 
|  | 1816 | u32 eecd; | 
|  | 1817 | u32 i; | 
|  | 1818 | u16 data; | 
|  | 1819 |  | 
|  | 1820 | eecd = er32(EECD); | 
|  | 1821 |  | 
|  | 1822 | eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); | 
|  | 1823 | data = 0; | 
|  | 1824 |  | 
|  | 1825 | for (i = 0; i < count; i++) { | 
|  | 1826 | data <<= 1; | 
|  | 1827 | e1000_raise_eec_clk(hw, &eecd); | 
|  | 1828 |  | 
|  | 1829 | eecd = er32(EECD); | 
|  | 1830 |  | 
|  | 1831 | eecd &= ~E1000_EECD_DI; | 
|  | 1832 | if (eecd & E1000_EECD_DO) | 
|  | 1833 | data |= 1; | 
|  | 1834 |  | 
|  | 1835 | e1000_lower_eec_clk(hw, &eecd); | 
|  | 1836 | } | 
|  | 1837 |  | 
|  | 1838 | return data; | 
|  | 1839 | } | 
|  | 1840 |  | 
|  | 1841 | /** | 
|  | 1842 | *  e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion | 
|  | 1843 | *  @hw: pointer to the HW structure | 
|  | 1844 | *  @ee_reg: EEPROM flag for polling | 
|  | 1845 | * | 
|  | 1846 | *  Polls the EEPROM status bit for either read or write completion based | 
|  | 1847 | *  upon the value of 'ee_reg'. | 
|  | 1848 | **/ | 
|  | 1849 | s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) | 
|  | 1850 | { | 
|  | 1851 | u32 attempts = 100000; | 
|  | 1852 | u32 i, reg = 0; | 
|  | 1853 |  | 
|  | 1854 | for (i = 0; i < attempts; i++) { | 
|  | 1855 | if (ee_reg == E1000_NVM_POLL_READ) | 
|  | 1856 | reg = er32(EERD); | 
|  | 1857 | else | 
|  | 1858 | reg = er32(EEWR); | 
|  | 1859 |  | 
|  | 1860 | if (reg & E1000_NVM_RW_REG_DONE) | 
|  | 1861 | return 0; | 
|  | 1862 |  | 
|  | 1863 | udelay(5); | 
|  | 1864 | } | 
|  | 1865 |  | 
|  | 1866 | return -E1000_ERR_NVM; | 
|  | 1867 | } | 
|  | 1868 |  | 
|  | 1869 | /** | 
|  | 1870 | *  e1000e_acquire_nvm - Generic request for access to EEPROM | 
|  | 1871 | *  @hw: pointer to the HW structure | 
|  | 1872 | * | 
|  | 1873 | *  Set the EEPROM access request bit and wait for EEPROM access grant bit. | 
|  | 1874 | *  Return successful if access grant bit set, else clear the request for | 
|  | 1875 | *  EEPROM access and return -E1000_ERR_NVM (-1). | 
|  | 1876 | **/ | 
|  | 1877 | s32 e1000e_acquire_nvm(struct e1000_hw *hw) | 
|  | 1878 | { | 
|  | 1879 | u32 eecd = er32(EECD); | 
|  | 1880 | s32 timeout = E1000_NVM_GRANT_ATTEMPTS; | 
|  | 1881 |  | 
|  | 1882 | ew32(EECD, eecd | E1000_EECD_REQ); | 
|  | 1883 | eecd = er32(EECD); | 
|  | 1884 |  | 
|  | 1885 | while (timeout) { | 
|  | 1886 | if (eecd & E1000_EECD_GNT) | 
|  | 1887 | break; | 
|  | 1888 | udelay(5); | 
|  | 1889 | eecd = er32(EECD); | 
|  | 1890 | timeout--; | 
|  | 1891 | } | 
|  | 1892 |  | 
|  | 1893 | if (!timeout) { | 
|  | 1894 | eecd &= ~E1000_EECD_REQ; | 
|  | 1895 | ew32(EECD, eecd); | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 1896 | e_dbg("Could not acquire NVM grant\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1897 | return -E1000_ERR_NVM; | 
|  | 1898 | } | 
|  | 1899 |  | 
|  | 1900 | return 0; | 
|  | 1901 | } | 
|  | 1902 |  | 
|  | 1903 | /** | 
|  | 1904 | *  e1000_standby_nvm - Return EEPROM to standby state | 
|  | 1905 | *  @hw: pointer to the HW structure | 
|  | 1906 | * | 
|  | 1907 | *  Return the EEPROM to a standby state. | 
|  | 1908 | **/ | 
|  | 1909 | static void e1000_standby_nvm(struct e1000_hw *hw) | 
|  | 1910 | { | 
|  | 1911 | struct e1000_nvm_info *nvm = &hw->nvm; | 
|  | 1912 | u32 eecd = er32(EECD); | 
|  | 1913 |  | 
|  | 1914 | if (nvm->type == e1000_nvm_eeprom_spi) { | 
|  | 1915 | /* Toggle CS to flush commands */ | 
|  | 1916 | eecd |= E1000_EECD_CS; | 
|  | 1917 | ew32(EECD, eecd); | 
|  | 1918 | e1e_flush(); | 
|  | 1919 | udelay(nvm->delay_usec); | 
|  | 1920 | eecd &= ~E1000_EECD_CS; | 
|  | 1921 | ew32(EECD, eecd); | 
|  | 1922 | e1e_flush(); | 
|  | 1923 | udelay(nvm->delay_usec); | 
|  | 1924 | } | 
|  | 1925 | } | 
|  | 1926 |  | 
|  | 1927 | /** | 
|  | 1928 | *  e1000_stop_nvm - Terminate EEPROM command | 
|  | 1929 | *  @hw: pointer to the HW structure | 
|  | 1930 | * | 
|  | 1931 | *  Terminates the current command by inverting the EEPROM's chip select pin. | 
|  | 1932 | **/ | 
|  | 1933 | static void e1000_stop_nvm(struct e1000_hw *hw) | 
|  | 1934 | { | 
|  | 1935 | u32 eecd; | 
|  | 1936 |  | 
|  | 1937 | eecd = er32(EECD); | 
|  | 1938 | if (hw->nvm.type == e1000_nvm_eeprom_spi) { | 
|  | 1939 | /* Pull CS high */ | 
|  | 1940 | eecd |= E1000_EECD_CS; | 
|  | 1941 | e1000_lower_eec_clk(hw, &eecd); | 
|  | 1942 | } | 
|  | 1943 | } | 
|  | 1944 |  | 
|  | 1945 | /** | 
|  | 1946 | *  e1000e_release_nvm - Release exclusive access to EEPROM | 
|  | 1947 | *  @hw: pointer to the HW structure | 
|  | 1948 | * | 
|  | 1949 | *  Stop any current commands to the EEPROM and clear the EEPROM request bit. | 
|  | 1950 | **/ | 
|  | 1951 | void e1000e_release_nvm(struct e1000_hw *hw) | 
|  | 1952 | { | 
|  | 1953 | u32 eecd; | 
|  | 1954 |  | 
|  | 1955 | e1000_stop_nvm(hw); | 
|  | 1956 |  | 
|  | 1957 | eecd = er32(EECD); | 
|  | 1958 | eecd &= ~E1000_EECD_REQ; | 
|  | 1959 | ew32(EECD, eecd); | 
|  | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | /** | 
|  | 1963 | *  e1000_ready_nvm_eeprom - Prepares EEPROM for read/write | 
|  | 1964 | *  @hw: pointer to the HW structure | 
|  | 1965 | * | 
|  | 1966 | *  Setups the EEPROM for reading and writing. | 
|  | 1967 | **/ | 
|  | 1968 | static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw) | 
|  | 1969 | { | 
|  | 1970 | struct e1000_nvm_info *nvm = &hw->nvm; | 
|  | 1971 | u32 eecd = er32(EECD); | 
|  | 1972 | u16 timeout = 0; | 
|  | 1973 | u8 spi_stat_reg; | 
|  | 1974 |  | 
|  | 1975 | if (nvm->type == e1000_nvm_eeprom_spi) { | 
|  | 1976 | /* Clear SK and CS */ | 
|  | 1977 | eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); | 
|  | 1978 | ew32(EECD, eecd); | 
|  | 1979 | udelay(1); | 
|  | 1980 | timeout = NVM_MAX_RETRY_SPI; | 
|  | 1981 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1982 | /* | 
|  | 1983 | * Read "Status Register" repeatedly until the LSB is cleared. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1984 | * The EEPROM will signal that the command has been completed | 
|  | 1985 | * by clearing bit 0 of the internal status register.  If it's | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1986 | * not cleared within 'timeout', then error out. | 
|  | 1987 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1988 | while (timeout) { | 
|  | 1989 | e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, | 
|  | 1990 | hw->nvm.opcode_bits); | 
|  | 1991 | spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); | 
|  | 1992 | if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) | 
|  | 1993 | break; | 
|  | 1994 |  | 
|  | 1995 | udelay(5); | 
|  | 1996 | e1000_standby_nvm(hw); | 
|  | 1997 | timeout--; | 
|  | 1998 | } | 
|  | 1999 |  | 
|  | 2000 | if (!timeout) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2001 | e_dbg("SPI NVM Status error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2002 | return -E1000_ERR_NVM; | 
|  | 2003 | } | 
|  | 2004 | } | 
|  | 2005 |  | 
|  | 2006 | return 0; | 
|  | 2007 | } | 
|  | 2008 |  | 
|  | 2009 | /** | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2010 | *  e1000e_read_nvm_eerd - Reads EEPROM using EERD register | 
|  | 2011 | *  @hw: pointer to the HW structure | 
|  | 2012 | *  @offset: offset of word in the EEPROM to read | 
|  | 2013 | *  @words: number of words to read | 
|  | 2014 | *  @data: word read from the EEPROM | 
|  | 2015 | * | 
|  | 2016 | *  Reads a 16 bit word from the EEPROM using the EERD register. | 
|  | 2017 | **/ | 
|  | 2018 | s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | 
|  | 2019 | { | 
|  | 2020 | struct e1000_nvm_info *nvm = &hw->nvm; | 
|  | 2021 | u32 i, eerd = 0; | 
|  | 2022 | s32 ret_val = 0; | 
|  | 2023 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2024 | /* | 
|  | 2025 | * A check for invalid values:  offset too large, too many words, | 
|  | 2026 | * too many words for the offset, and not enough words. | 
|  | 2027 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2028 | if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || | 
|  | 2029 | (words == 0)) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2030 | e_dbg("nvm parameter(s) out of bounds\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2031 | return -E1000_ERR_NVM; | 
|  | 2032 | } | 
|  | 2033 |  | 
|  | 2034 | for (i = 0; i < words; i++) { | 
|  | 2035 | eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) + | 
|  | 2036 | E1000_NVM_RW_REG_START; | 
|  | 2037 |  | 
|  | 2038 | ew32(EERD, eerd); | 
|  | 2039 | ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); | 
|  | 2040 | if (ret_val) | 
|  | 2041 | break; | 
|  | 2042 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2043 | data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2044 | } | 
|  | 2045 |  | 
|  | 2046 | return ret_val; | 
|  | 2047 | } | 
|  | 2048 |  | 
|  | 2049 | /** | 
|  | 2050 | *  e1000e_write_nvm_spi - Write to EEPROM using SPI | 
|  | 2051 | *  @hw: pointer to the HW structure | 
|  | 2052 | *  @offset: offset within the EEPROM to be written to | 
|  | 2053 | *  @words: number of words to write | 
|  | 2054 | *  @data: 16 bit word(s) to be written to the EEPROM | 
|  | 2055 | * | 
|  | 2056 | *  Writes data to EEPROM at offset using SPI interface. | 
|  | 2057 | * | 
|  | 2058 | *  If e1000e_update_nvm_checksum is not called after this function , the | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2059 | *  EEPROM will most likely contain an invalid checksum. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2060 | **/ | 
|  | 2061 | s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) | 
|  | 2062 | { | 
|  | 2063 | struct e1000_nvm_info *nvm = &hw->nvm; | 
|  | 2064 | s32 ret_val; | 
|  | 2065 | u16 widx = 0; | 
|  | 2066 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2067 | /* | 
|  | 2068 | * A check for invalid values:  offset too large, too many words, | 
|  | 2069 | * and not enough words. | 
|  | 2070 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2071 | if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || | 
|  | 2072 | (words == 0)) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2073 | e_dbg("nvm parameter(s) out of bounds\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2074 | return -E1000_ERR_NVM; | 
|  | 2075 | } | 
|  | 2076 |  | 
| Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 2077 | ret_val = nvm->ops.acquire(hw); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2078 | if (ret_val) | 
|  | 2079 | return ret_val; | 
|  | 2080 |  | 
|  | 2081 | msleep(10); | 
|  | 2082 |  | 
|  | 2083 | while (widx < words) { | 
|  | 2084 | u8 write_opcode = NVM_WRITE_OPCODE_SPI; | 
|  | 2085 |  | 
|  | 2086 | ret_val = e1000_ready_nvm_eeprom(hw); | 
|  | 2087 | if (ret_val) { | 
| Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 2088 | nvm->ops.release(hw); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2089 | return ret_val; | 
|  | 2090 | } | 
|  | 2091 |  | 
|  | 2092 | e1000_standby_nvm(hw); | 
|  | 2093 |  | 
|  | 2094 | /* Send the WRITE ENABLE command (8 bit opcode) */ | 
|  | 2095 | e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, | 
|  | 2096 | nvm->opcode_bits); | 
|  | 2097 |  | 
|  | 2098 | e1000_standby_nvm(hw); | 
|  | 2099 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2100 | /* | 
|  | 2101 | * Some SPI eeproms use the 8th address bit embedded in the | 
|  | 2102 | * opcode | 
|  | 2103 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2104 | if ((nvm->address_bits == 8) && (offset >= 128)) | 
|  | 2105 | write_opcode |= NVM_A8_OPCODE_SPI; | 
|  | 2106 |  | 
|  | 2107 | /* Send the Write command (8-bit opcode + addr) */ | 
|  | 2108 | e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); | 
|  | 2109 | e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), | 
|  | 2110 | nvm->address_bits); | 
|  | 2111 |  | 
|  | 2112 | /* Loop to allow for up to whole page write of eeprom */ | 
|  | 2113 | while (widx < words) { | 
|  | 2114 | u16 word_out = data[widx]; | 
|  | 2115 | word_out = (word_out >> 8) | (word_out << 8); | 
|  | 2116 | e1000_shift_out_eec_bits(hw, word_out, 16); | 
|  | 2117 | widx++; | 
|  | 2118 |  | 
|  | 2119 | if ((((offset + widx) * 2) % nvm->page_size) == 0) { | 
|  | 2120 | e1000_standby_nvm(hw); | 
|  | 2121 | break; | 
|  | 2122 | } | 
|  | 2123 | } | 
|  | 2124 | } | 
|  | 2125 |  | 
|  | 2126 | msleep(10); | 
| Bruce Allan | 94d8186 | 2009-11-20 23:25:26 +0000 | [diff] [blame] | 2127 | nvm->ops.release(hw); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2128 | return 0; | 
|  | 2129 | } | 
|  | 2130 |  | 
|  | 2131 | /** | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2132 | *  e1000_read_mac_addr_generic - Read device MAC address | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2133 | *  @hw: pointer to the HW structure | 
|  | 2134 | * | 
|  | 2135 | *  Reads the device MAC address from the EEPROM and stores the value. | 
|  | 2136 | *  Since devices with two ports use the same EEPROM, we increment the | 
|  | 2137 | *  last bit in the MAC address for the second port. | 
|  | 2138 | **/ | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2139 | s32 e1000_read_mac_addr_generic(struct e1000_hw *hw) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2140 | { | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2141 | u32 rar_high; | 
|  | 2142 | u32 rar_low; | 
|  | 2143 | u16 i; | 
| Bill Hayes | 93ca161 | 2007-10-31 15:21:52 -0700 | [diff] [blame] | 2144 |  | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2145 | rar_high = er32(RAH(0)); | 
|  | 2146 | rar_low = er32(RAL(0)); | 
| Bill Hayes | 93ca161 | 2007-10-31 15:21:52 -0700 | [diff] [blame] | 2147 |  | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2148 | for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) | 
|  | 2149 | hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8)); | 
| Bill Hayes | 93ca161 | 2007-10-31 15:21:52 -0700 | [diff] [blame] | 2150 |  | 
| Bruce Allan | 608f8a0 | 2010-01-13 02:04:58 +0000 | [diff] [blame] | 2151 | for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) | 
|  | 2152 | hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8)); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2153 |  | 
|  | 2154 | for (i = 0; i < ETH_ALEN; i++) | 
|  | 2155 | hw->mac.addr[i] = hw->mac.perm_addr[i]; | 
|  | 2156 |  | 
|  | 2157 | return 0; | 
|  | 2158 | } | 
|  | 2159 |  | 
|  | 2160 | /** | 
|  | 2161 | *  e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum | 
|  | 2162 | *  @hw: pointer to the HW structure | 
|  | 2163 | * | 
|  | 2164 | *  Calculates the EEPROM checksum by reading/adding each word of the EEPROM | 
|  | 2165 | *  and then verifies that the sum of the EEPROM is equal to 0xBABA. | 
|  | 2166 | **/ | 
|  | 2167 | s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw) | 
|  | 2168 | { | 
|  | 2169 | s32 ret_val; | 
|  | 2170 | u16 checksum = 0; | 
|  | 2171 | u16 i, nvm_data; | 
|  | 2172 |  | 
|  | 2173 | for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { | 
|  | 2174 | ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); | 
|  | 2175 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2176 | e_dbg("NVM Read Error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2177 | return ret_val; | 
|  | 2178 | } | 
|  | 2179 | checksum += nvm_data; | 
|  | 2180 | } | 
|  | 2181 |  | 
|  | 2182 | if (checksum != (u16) NVM_SUM) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2183 | e_dbg("NVM Checksum Invalid\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2184 | return -E1000_ERR_NVM; | 
|  | 2185 | } | 
|  | 2186 |  | 
|  | 2187 | return 0; | 
|  | 2188 | } | 
|  | 2189 |  | 
|  | 2190 | /** | 
|  | 2191 | *  e1000e_update_nvm_checksum_generic - Update EEPROM checksum | 
|  | 2192 | *  @hw: pointer to the HW structure | 
|  | 2193 | * | 
|  | 2194 | *  Updates the EEPROM checksum by reading/adding each word of the EEPROM | 
|  | 2195 | *  up to the checksum.  Then calculates the EEPROM checksum and writes the | 
|  | 2196 | *  value to the EEPROM. | 
|  | 2197 | **/ | 
|  | 2198 | s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw) | 
|  | 2199 | { | 
|  | 2200 | s32 ret_val; | 
|  | 2201 | u16 checksum = 0; | 
|  | 2202 | u16 i, nvm_data; | 
|  | 2203 |  | 
|  | 2204 | for (i = 0; i < NVM_CHECKSUM_REG; i++) { | 
|  | 2205 | ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); | 
|  | 2206 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2207 | e_dbg("NVM Read Error while updating checksum.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2208 | return ret_val; | 
|  | 2209 | } | 
|  | 2210 | checksum += nvm_data; | 
|  | 2211 | } | 
|  | 2212 | checksum = (u16) NVM_SUM - checksum; | 
|  | 2213 | ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum); | 
|  | 2214 | if (ret_val) | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2215 | e_dbg("NVM Write Error while updating checksum.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2216 |  | 
|  | 2217 | return ret_val; | 
|  | 2218 | } | 
|  | 2219 |  | 
|  | 2220 | /** | 
|  | 2221 | *  e1000e_reload_nvm - Reloads EEPROM | 
|  | 2222 | *  @hw: pointer to the HW structure | 
|  | 2223 | * | 
|  | 2224 | *  Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the | 
|  | 2225 | *  extended control register. | 
|  | 2226 | **/ | 
|  | 2227 | void e1000e_reload_nvm(struct e1000_hw *hw) | 
|  | 2228 | { | 
|  | 2229 | u32 ctrl_ext; | 
|  | 2230 |  | 
|  | 2231 | udelay(10); | 
|  | 2232 | ctrl_ext = er32(CTRL_EXT); | 
|  | 2233 | ctrl_ext |= E1000_CTRL_EXT_EE_RST; | 
|  | 2234 | ew32(CTRL_EXT, ctrl_ext); | 
|  | 2235 | e1e_flush(); | 
|  | 2236 | } | 
|  | 2237 |  | 
|  | 2238 | /** | 
|  | 2239 | *  e1000_calculate_checksum - Calculate checksum for buffer | 
|  | 2240 | *  @buffer: pointer to EEPROM | 
|  | 2241 | *  @length: size of EEPROM to calculate a checksum for | 
|  | 2242 | * | 
|  | 2243 | *  Calculates the checksum for some buffer on a specified length.  The | 
|  | 2244 | *  checksum calculated is returned. | 
|  | 2245 | **/ | 
|  | 2246 | static u8 e1000_calculate_checksum(u8 *buffer, u32 length) | 
|  | 2247 | { | 
|  | 2248 | u32 i; | 
|  | 2249 | u8  sum = 0; | 
|  | 2250 |  | 
|  | 2251 | if (!buffer) | 
|  | 2252 | return 0; | 
|  | 2253 |  | 
|  | 2254 | for (i = 0; i < length; i++) | 
|  | 2255 | sum += buffer[i]; | 
|  | 2256 |  | 
|  | 2257 | return (u8) (0 - sum); | 
|  | 2258 | } | 
|  | 2259 |  | 
|  | 2260 | /** | 
|  | 2261 | *  e1000_mng_enable_host_if - Checks host interface is enabled | 
|  | 2262 | *  @hw: pointer to the HW structure | 
|  | 2263 | * | 
|  | 2264 | *  Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND | 
|  | 2265 | * | 
| Auke Kok | 489815c | 2008-02-21 15:11:07 -0800 | [diff] [blame] | 2266 | *  This function checks whether the HOST IF is enabled for command operation | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2267 | *  and also checks whether the previous command is completed.  It busy waits | 
|  | 2268 | *  in case of previous command is not completed. | 
|  | 2269 | **/ | 
|  | 2270 | static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) | 
|  | 2271 | { | 
|  | 2272 | u32 hicr; | 
|  | 2273 | u8 i; | 
|  | 2274 |  | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2275 | if (!(hw->mac.arc_subsystem_valid)) { | 
|  | 2276 | e_dbg("ARC subsystem not valid.\n"); | 
|  | 2277 | return -E1000_ERR_HOST_INTERFACE_COMMAND; | 
|  | 2278 | } | 
|  | 2279 |  | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2280 | /* Check that the host interface is enabled. */ | 
|  | 2281 | hicr = er32(HICR); | 
|  | 2282 | if ((hicr & E1000_HICR_EN) == 0) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2283 | e_dbg("E1000_HOST_EN bit disabled.\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2284 | return -E1000_ERR_HOST_INTERFACE_COMMAND; | 
|  | 2285 | } | 
|  | 2286 | /* check the previous command is completed */ | 
|  | 2287 | for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { | 
|  | 2288 | hicr = er32(HICR); | 
|  | 2289 | if (!(hicr & E1000_HICR_C)) | 
|  | 2290 | break; | 
|  | 2291 | mdelay(1); | 
|  | 2292 | } | 
|  | 2293 |  | 
|  | 2294 | if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2295 | e_dbg("Previous command timeout failed .\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2296 | return -E1000_ERR_HOST_INTERFACE_COMMAND; | 
|  | 2297 | } | 
|  | 2298 |  | 
|  | 2299 | return 0; | 
|  | 2300 | } | 
|  | 2301 |  | 
|  | 2302 | /** | 
| Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2303 | *  e1000e_check_mng_mode_generic - check management mode | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2304 | *  @hw: pointer to the HW structure | 
|  | 2305 | * | 
|  | 2306 | *  Reads the firmware semaphore register and returns true (>0) if | 
|  | 2307 | *  manageability is enabled, else false (0). | 
|  | 2308 | **/ | 
| Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2309 | bool e1000e_check_mng_mode_generic(struct e1000_hw *hw) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2310 | { | 
|  | 2311 | u32 fwsm = er32(FWSM); | 
|  | 2312 |  | 
| Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 2313 | return (fwsm & E1000_FWSM_MODE_MASK) == | 
|  | 2314 | (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2315 | } | 
|  | 2316 |  | 
|  | 2317 | /** | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2318 | *  e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2319 | *  @hw: pointer to the HW structure | 
|  | 2320 | * | 
|  | 2321 | *  Enables packet filtering on transmit packets if manageability is enabled | 
|  | 2322 | *  and host interface is enabled. | 
|  | 2323 | **/ | 
|  | 2324 | bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw) | 
|  | 2325 | { | 
|  | 2326 | struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie; | 
|  | 2327 | u32 *buffer = (u32 *)&hw->mng_cookie; | 
|  | 2328 | u32 offset; | 
|  | 2329 | s32 ret_val, hdr_csum, csum; | 
|  | 2330 | u8 i, len; | 
|  | 2331 |  | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2332 | hw->mac.tx_pkt_filtering = true; | 
|  | 2333 |  | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2334 | /* No manageability, no filtering */ | 
|  | 2335 | if (!e1000e_check_mng_mode(hw)) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2336 | hw->mac.tx_pkt_filtering = false; | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2337 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2338 | } | 
|  | 2339 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2340 | /* | 
|  | 2341 | * If we can't read from the host interface for whatever | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2342 | * reason, disable filtering. | 
|  | 2343 | */ | 
|  | 2344 | ret_val = e1000_mng_enable_host_if(hw); | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2345 | if (ret_val) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2346 | hw->mac.tx_pkt_filtering = false; | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2347 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2348 | } | 
|  | 2349 |  | 
|  | 2350 | /* Read in the header.  Length and offset are in dwords. */ | 
|  | 2351 | len    = E1000_MNG_DHCP_COOKIE_LENGTH >> 2; | 
|  | 2352 | offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2; | 
|  | 2353 | for (i = 0; i < len; i++) | 
|  | 2354 | *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i); | 
|  | 2355 | hdr_csum = hdr->checksum; | 
|  | 2356 | hdr->checksum = 0; | 
|  | 2357 | csum = e1000_calculate_checksum((u8 *)hdr, | 
|  | 2358 | E1000_MNG_DHCP_COOKIE_LENGTH); | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2359 | /* | 
|  | 2360 | * If either the checksums or signature don't match, then | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2361 | * the cookie area isn't considered valid, in which case we | 
|  | 2362 | * take the safe route of assuming Tx filtering is enabled. | 
|  | 2363 | */ | 
|  | 2364 | if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2365 | hw->mac.tx_pkt_filtering = true; | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2366 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2367 | } | 
|  | 2368 |  | 
|  | 2369 | /* Cookie area is valid, make the final check for filtering. */ | 
|  | 2370 | if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2371 | hw->mac.tx_pkt_filtering = false; | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2372 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2373 | } | 
|  | 2374 |  | 
| Bruce Allan | ca777f9 | 2010-01-07 16:31:54 +0000 | [diff] [blame] | 2375 | out: | 
|  | 2376 | return hw->mac.tx_pkt_filtering; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2377 | } | 
|  | 2378 |  | 
|  | 2379 | /** | 
|  | 2380 | *  e1000_mng_write_cmd_header - Writes manageability command header | 
|  | 2381 | *  @hw: pointer to the HW structure | 
|  | 2382 | *  @hdr: pointer to the host interface command header | 
|  | 2383 | * | 
|  | 2384 | *  Writes the command header after does the checksum calculation. | 
|  | 2385 | **/ | 
|  | 2386 | static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, | 
|  | 2387 | struct e1000_host_mng_command_header *hdr) | 
|  | 2388 | { | 
|  | 2389 | u16 i, length = sizeof(struct e1000_host_mng_command_header); | 
|  | 2390 |  | 
|  | 2391 | /* Write the whole command header structure with new checksum. */ | 
|  | 2392 |  | 
|  | 2393 | hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length); | 
|  | 2394 |  | 
|  | 2395 | length >>= 2; | 
|  | 2396 | /* Write the relevant command block into the ram area. */ | 
|  | 2397 | for (i = 0; i < length; i++) { | 
|  | 2398 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, | 
|  | 2399 | *((u32 *) hdr + i)); | 
|  | 2400 | e1e_flush(); | 
|  | 2401 | } | 
|  | 2402 |  | 
|  | 2403 | return 0; | 
|  | 2404 | } | 
|  | 2405 |  | 
|  | 2406 | /** | 
| Bruce Allan | 5ff5b66 | 2009-12-01 15:51:11 +0000 | [diff] [blame] | 2407 | *  e1000_mng_host_if_write - Write to the manageability host interface | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2408 | *  @hw: pointer to the HW structure | 
|  | 2409 | *  @buffer: pointer to the host interface buffer | 
|  | 2410 | *  @length: size of the buffer | 
|  | 2411 | *  @offset: location in the buffer to write to | 
|  | 2412 | *  @sum: sum of the data (not checksum) | 
|  | 2413 | * | 
|  | 2414 | *  This function writes the buffer content at the offset given on the host if. | 
|  | 2415 | *  It also does alignment considerations to do the writes in most efficient | 
|  | 2416 | *  way.  Also fills up the sum of the buffer in *buffer parameter. | 
|  | 2417 | **/ | 
|  | 2418 | static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, | 
|  | 2419 | u16 length, u16 offset, u8 *sum) | 
|  | 2420 | { | 
|  | 2421 | u8 *tmp; | 
|  | 2422 | u8 *bufptr = buffer; | 
|  | 2423 | u32 data = 0; | 
|  | 2424 | u16 remaining, i, j, prev_bytes; | 
|  | 2425 |  | 
|  | 2426 | /* sum = only sum of the data and it is not checksum */ | 
|  | 2427 |  | 
|  | 2428 | if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) | 
|  | 2429 | return -E1000_ERR_PARAM; | 
|  | 2430 |  | 
|  | 2431 | tmp = (u8 *)&data; | 
|  | 2432 | prev_bytes = offset & 0x3; | 
|  | 2433 | offset >>= 2; | 
|  | 2434 |  | 
|  | 2435 | if (prev_bytes) { | 
|  | 2436 | data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset); | 
|  | 2437 | for (j = prev_bytes; j < sizeof(u32); j++) { | 
|  | 2438 | *(tmp + j) = *bufptr++; | 
|  | 2439 | *sum += *(tmp + j); | 
|  | 2440 | } | 
|  | 2441 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data); | 
|  | 2442 | length -= j - prev_bytes; | 
|  | 2443 | offset++; | 
|  | 2444 | } | 
|  | 2445 |  | 
|  | 2446 | remaining = length & 0x3; | 
|  | 2447 | length -= remaining; | 
|  | 2448 |  | 
|  | 2449 | /* Calculate length in DWORDs */ | 
|  | 2450 | length >>= 2; | 
|  | 2451 |  | 
| Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 2452 | /* | 
|  | 2453 | * The device driver writes the relevant command block into the | 
|  | 2454 | * ram area. | 
|  | 2455 | */ | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2456 | for (i = 0; i < length; i++) { | 
|  | 2457 | for (j = 0; j < sizeof(u32); j++) { | 
|  | 2458 | *(tmp + j) = *bufptr++; | 
|  | 2459 | *sum += *(tmp + j); | 
|  | 2460 | } | 
|  | 2461 |  | 
|  | 2462 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); | 
|  | 2463 | } | 
|  | 2464 | if (remaining) { | 
|  | 2465 | for (j = 0; j < sizeof(u32); j++) { | 
|  | 2466 | if (j < remaining) | 
|  | 2467 | *(tmp + j) = *bufptr++; | 
|  | 2468 | else | 
|  | 2469 | *(tmp + j) = 0; | 
|  | 2470 |  | 
|  | 2471 | *sum += *(tmp + j); | 
|  | 2472 | } | 
|  | 2473 | E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); | 
|  | 2474 | } | 
|  | 2475 |  | 
|  | 2476 | return 0; | 
|  | 2477 | } | 
|  | 2478 |  | 
|  | 2479 | /** | 
|  | 2480 | *  e1000e_mng_write_dhcp_info - Writes DHCP info to host interface | 
|  | 2481 | *  @hw: pointer to the HW structure | 
|  | 2482 | *  @buffer: pointer to the host interface | 
|  | 2483 | *  @length: size of the buffer | 
|  | 2484 | * | 
|  | 2485 | *  Writes the DHCP information to the host interface. | 
|  | 2486 | **/ | 
|  | 2487 | s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) | 
|  | 2488 | { | 
|  | 2489 | struct e1000_host_mng_command_header hdr; | 
|  | 2490 | s32 ret_val; | 
|  | 2491 | u32 hicr; | 
|  | 2492 |  | 
|  | 2493 | hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; | 
|  | 2494 | hdr.command_length = length; | 
|  | 2495 | hdr.reserved1 = 0; | 
|  | 2496 | hdr.reserved2 = 0; | 
|  | 2497 | hdr.checksum = 0; | 
|  | 2498 |  | 
|  | 2499 | /* Enable the host interface */ | 
|  | 2500 | ret_val = e1000_mng_enable_host_if(hw); | 
|  | 2501 | if (ret_val) | 
|  | 2502 | return ret_val; | 
|  | 2503 |  | 
|  | 2504 | /* Populate the host interface with the contents of "buffer". */ | 
|  | 2505 | ret_val = e1000_mng_host_if_write(hw, buffer, length, | 
|  | 2506 | sizeof(hdr), &(hdr.checksum)); | 
|  | 2507 | if (ret_val) | 
|  | 2508 | return ret_val; | 
|  | 2509 |  | 
|  | 2510 | /* Write the manageability command header */ | 
|  | 2511 | ret_val = e1000_mng_write_cmd_header(hw, &hdr); | 
|  | 2512 | if (ret_val) | 
|  | 2513 | return ret_val; | 
|  | 2514 |  | 
|  | 2515 | /* Tell the ARC a new command is pending. */ | 
|  | 2516 | hicr = er32(HICR); | 
|  | 2517 | ew32(HICR, hicr | E1000_HICR_C); | 
|  | 2518 |  | 
|  | 2519 | return 0; | 
|  | 2520 | } | 
|  | 2521 |  | 
|  | 2522 | /** | 
| Bruce Allan | 757c530 | 2010-05-10 15:00:50 +0000 | [diff] [blame] | 2523 | *  e1000e_enable_mng_pass_thru - Check if management passthrough is needed | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2524 | *  @hw: pointer to the HW structure | 
|  | 2525 | * | 
| Bruce Allan | 757c530 | 2010-05-10 15:00:50 +0000 | [diff] [blame] | 2526 | *  Verifies the hardware needs to leave interface enabled so that frames can | 
|  | 2527 | *  be directed to and from the management interface. | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2528 | **/ | 
|  | 2529 | bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw) | 
|  | 2530 | { | 
|  | 2531 | u32 manc; | 
|  | 2532 | u32 fwsm, factps; | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2533 | bool ret_val = false; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2534 |  | 
|  | 2535 | manc = er32(MANC); | 
|  | 2536 |  | 
| Bruce Allan | 757c530 | 2010-05-10 15:00:50 +0000 | [diff] [blame] | 2537 | if (!(manc & E1000_MANC_RCV_TCO_EN)) | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2538 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2539 |  | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2540 | if (hw->mac.has_fwsm) { | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2541 | fwsm = er32(FWSM); | 
|  | 2542 | factps = er32(FACTPS); | 
|  | 2543 |  | 
|  | 2544 | if (!(factps & E1000_FACTPS_MNGCG) && | 
|  | 2545 | ((fwsm & E1000_FWSM_MODE_MASK) == | 
|  | 2546 | (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2547 | ret_val = true; | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2548 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2549 | } | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2550 | } else if ((hw->mac.type == e1000_82574) || | 
|  | 2551 | (hw->mac.type == e1000_82583)) { | 
|  | 2552 | u16 data; | 
|  | 2553 |  | 
|  | 2554 | factps = er32(FACTPS); | 
|  | 2555 | e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data); | 
|  | 2556 |  | 
|  | 2557 | if (!(factps & E1000_FACTPS_MNGCG) && | 
|  | 2558 | ((data & E1000_NVM_INIT_CTRL2_MNGM) == | 
|  | 2559 | (e1000_mng_mode_pt << 13))) { | 
|  | 2560 | ret_val = true; | 
|  | 2561 | goto out; | 
|  | 2562 | } | 
|  | 2563 | } else if ((manc & E1000_MANC_SMBUS_EN) && | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2564 | !(manc & E1000_MANC_ASF_EN)) { | 
| Bruce Allan | 564ea9b | 2009-11-20 23:26:44 +0000 | [diff] [blame] | 2565 | ret_val = true; | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2566 | goto out; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2567 | } | 
|  | 2568 |  | 
| Bruce Allan | a65a4a0 | 2010-05-10 15:01:51 +0000 | [diff] [blame] | 2569 | out: | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2570 | return ret_val; | 
|  | 2571 | } | 
|  | 2572 |  | 
| Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 2573 | s32 e1000e_read_pba_num(struct e1000_hw *hw, u32 *pba_num) | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2574 | { | 
|  | 2575 | s32 ret_val; | 
|  | 2576 | u16 nvm_data; | 
|  | 2577 |  | 
|  | 2578 | ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); | 
|  | 2579 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2580 | e_dbg("NVM Read Error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2581 | return ret_val; | 
|  | 2582 | } | 
| Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 2583 | *pba_num = (u32)(nvm_data << 16); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2584 |  | 
|  | 2585 | ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &nvm_data); | 
|  | 2586 | if (ret_val) { | 
| Bruce Allan | 3bb99fe | 2009-11-20 23:25:07 +0000 | [diff] [blame] | 2587 | e_dbg("NVM Read Error\n"); | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2588 | return ret_val; | 
|  | 2589 | } | 
| Jeff Kirsher | 69e3fd8 | 2008-04-02 13:48:18 -0700 | [diff] [blame] | 2590 | *pba_num |= nvm_data; | 
| Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2591 |  | 
|  | 2592 | return 0; | 
|  | 2593 | } |