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