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