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