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