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