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