atm: [fore200e] use MODULE_FIRMWARE() and other suggested cleanups
[linux-2.6/cjktty.git] / drivers / net / igb / e1000_mac.c
blob20408aa1f916a7ce379b402c41ccd47a7ffb6567
1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
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.
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.
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
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
26 *******************************************************************************/
28 #include <linux/if_ether.h>
29 #include <linux/delay.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
33 #include "e1000_mac.h"
35 #include "igb.h"
37 static s32 igb_set_default_fc(struct e1000_hw *hw);
38 static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
40 /**
41 * igb_remove_device - Free device specific structure
42 * @hw: pointer to the HW structure
44 * If a device specific structure was allocated, this function will
45 * free it.
46 **/
47 void igb_remove_device(struct e1000_hw *hw)
49 /* Freeing the dev_spec member of e1000_hw structure */
50 kfree(hw->dev_spec);
53 static void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
55 struct igb_adapter *adapter = hw->back;
57 pci_read_config_word(adapter->pdev, reg, value);
60 static s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
62 struct igb_adapter *adapter = hw->back;
63 u16 cap_offset;
65 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
66 if (!cap_offset)
67 return -E1000_ERR_CONFIG;
69 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
71 return 0;
74 /**
75 * igb_get_bus_info_pcie - Get PCIe bus information
76 * @hw: pointer to the HW structure
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)
84 struct e1000_bus_info *bus = &hw->bus;
85 s32 ret_val;
86 u32 status;
87 u16 pcie_link_status, pci_header_type;
89 bus->type = e1000_bus_type_pci_express;
90 bus->speed = e1000_bus_speed_2500;
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);
102 igb_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
103 if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
104 status = rd32(E1000_STATUS);
105 bus->func = (status & E1000_STATUS_FUNC_MASK)
106 >> E1000_STATUS_FUNC_SHIFT;
107 } else {
108 bus->func = 0;
111 return 0;
115 * igb_clear_vfta - Clear VLAN filter table
116 * @hw: pointer to the HW structure
118 * Clears the register array which contains the VLAN filter table by
119 * setting all the values to 0.
121 void igb_clear_vfta(struct e1000_hw *hw)
123 u32 offset;
125 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
126 array_wr32(E1000_VFTA, offset, 0);
127 wrfl();
132 * igb_write_vfta - Write value to VLAN filter table
133 * @hw: pointer to the HW structure
134 * @offset: register offset in VLAN filter table
135 * @value: register value written to VLAN filter table
137 * Writes value at the given offset in the register array which stores
138 * the VLAN filter table.
140 void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
142 array_wr32(E1000_VFTA, offset, value);
143 wrfl();
147 * igb_init_rx_addrs - Initialize receive address's
148 * @hw: pointer to the HW structure
149 * @rar_count: receive address registers
151 * Setups the receive address registers by setting the base receive address
152 * register to the devices MAC address and clearing all the other receive
153 * address registers to 0.
155 void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
157 u32 i;
159 /* Setup the receive address */
160 hw_dbg("Programming MAC Address into RAR[0]\n");
162 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
164 /* Zero out the other (rar_entry_count - 1) receive addresses */
165 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
166 for (i = 1; i < rar_count; i++) {
167 array_wr32(E1000_RA, (i << 1), 0);
168 wrfl();
169 array_wr32(E1000_RA, ((i << 1) + 1), 0);
170 wrfl();
175 * igb_check_alt_mac_addr - Check for alternate MAC addr
176 * @hw: pointer to the HW structure
178 * Checks the nvm for an alternate MAC address. An alternate MAC address
179 * can be setup by pre-boot software and must be treated like a permanent
180 * address and must override the actual permanent MAC address. If an
181 * alternate MAC address is fopund it is saved in the hw struct and
182 * prgrammed into RAR0 and the cuntion returns success, otherwise the
183 * fucntion returns an error.
185 s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
187 u32 i;
188 s32 ret_val = 0;
189 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
190 u8 alt_mac_addr[ETH_ALEN];
192 ret_val = hw->nvm.ops.read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
193 &nvm_alt_mac_addr_offset);
194 if (ret_val) {
195 hw_dbg("NVM Read Error\n");
196 goto out;
199 if (nvm_alt_mac_addr_offset == 0xFFFF) {
200 ret_val = -(E1000_NOT_IMPLEMENTED);
201 goto out;
204 if (hw->bus.func == E1000_FUNC_1)
205 nvm_alt_mac_addr_offset += ETH_ALEN/sizeof(u16);
207 for (i = 0; i < ETH_ALEN; i += 2) {
208 offset = nvm_alt_mac_addr_offset + (i >> 1);
209 ret_val = hw->nvm.ops.read_nvm(hw, offset, 1, &nvm_data);
210 if (ret_val) {
211 hw_dbg("NVM Read Error\n");
212 goto out;
215 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
216 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
219 /* if multicast bit is set, the alternate address will not be used */
220 if (alt_mac_addr[0] & 0x01) {
221 ret_val = -(E1000_NOT_IMPLEMENTED);
222 goto out;
225 for (i = 0; i < ETH_ALEN; i++)
226 hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i];
228 hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0);
230 out:
231 return ret_val;
235 * igb_rar_set - Set receive address register
236 * @hw: pointer to the HW structure
237 * @addr: pointer to the receive address
238 * @index: receive address array register
240 * Sets the receive address array register at index to the address passed
241 * in by addr.
243 void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
245 u32 rar_low, rar_high;
248 * HW expects these in little endian so we reverse the byte order
249 * from network order (big endian) to little endian
251 rar_low = ((u32) addr[0] |
252 ((u32) addr[1] << 8) |
253 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
255 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
257 if (!hw->mac.disable_av)
258 rar_high |= E1000_RAH_AV;
260 array_wr32(E1000_RA, (index << 1), rar_low);
261 array_wr32(E1000_RA, ((index << 1) + 1), rar_high);
265 * igb_mta_set - Set multicast filter table address
266 * @hw: pointer to the HW structure
267 * @hash_value: determines the MTA register and bit to set
269 * The multicast table address is a register array of 32-bit registers.
270 * The hash_value is used to determine what register the bit is in, the
271 * current value is read, the new bit is OR'd in and the new value is
272 * written back into the register.
274 static void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
276 u32 hash_bit, hash_reg, mta;
279 * The MTA is a register array of 32-bit registers. It is
280 * treated like an array of (32*mta_reg_count) bits. We want to
281 * set bit BitArray[hash_value]. So we figure out what register
282 * the bit is in, read it, OR in the new bit, then write
283 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
284 * mask to bits 31:5 of the hash value which gives us the
285 * register we're modifying. The hash bit within that register
286 * is determined by the lower 5 bits of the hash value.
288 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
289 hash_bit = hash_value & 0x1F;
291 mta = array_rd32(E1000_MTA, hash_reg);
293 mta |= (1 << hash_bit);
295 array_wr32(E1000_MTA, hash_reg, mta);
296 wrfl();
300 * igb_update_mc_addr_list - Update Multicast addresses
301 * @hw: pointer to the HW structure
302 * @mc_addr_list: array of multicast addresses to program
303 * @mc_addr_count: number of multicast addresses to program
304 * @rar_used_count: the first RAR register free to program
305 * @rar_count: total number of supported Receive Address Registers
307 * Updates the Receive Address Registers and Multicast Table Array.
308 * The caller must have a packed mc_addr_list of multicast addresses.
309 * The parameter rar_count will usually be hw->mac.rar_entry_count
310 * unless there are workarounds that change this.
312 void igb_update_mc_addr_list(struct e1000_hw *hw,
313 u8 *mc_addr_list, u32 mc_addr_count,
314 u32 rar_used_count, u32 rar_count)
316 u32 hash_value;
317 u32 i;
320 * Load the first set of multicast addresses into the exact
321 * filters (RAR). If there are not enough to fill the RAR
322 * array, clear the filters.
324 for (i = rar_used_count; i < rar_count; i++) {
325 if (mc_addr_count) {
326 hw->mac.ops.rar_set(hw, mc_addr_list, i);
327 mc_addr_count--;
328 mc_addr_list += ETH_ALEN;
329 } else {
330 array_wr32(E1000_RA, i << 1, 0);
331 wrfl();
332 array_wr32(E1000_RA, (i << 1) + 1, 0);
333 wrfl();
337 /* Clear the old settings from the MTA */
338 hw_dbg("Clearing MTA\n");
339 for (i = 0; i < hw->mac.mta_reg_count; i++) {
340 array_wr32(E1000_MTA, i, 0);
341 wrfl();
344 /* Load any remaining multicast addresses into the hash table. */
345 for (; mc_addr_count > 0; mc_addr_count--) {
346 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
347 hw_dbg("Hash value = 0x%03X\n", hash_value);
348 igb_mta_set(hw, hash_value);
349 mc_addr_list += ETH_ALEN;
354 * igb_hash_mc_addr - Generate a multicast hash value
355 * @hw: pointer to the HW structure
356 * @mc_addr: pointer to a multicast address
358 * Generates a multicast address hash value which is used to determine
359 * the multicast filter table array address and new table value. See
360 * igb_mta_set()
362 u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
364 u32 hash_value, hash_mask;
365 u8 bit_shift = 0;
367 /* Register count multiplied by bits per register */
368 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
371 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
372 * where 0xFF would still fall within the hash mask.
374 while (hash_mask >> bit_shift != 0xFF)
375 bit_shift++;
378 * The portion of the address that is used for the hash table
379 * is determined by the mc_filter_type setting.
380 * The algorithm is such that there is a total of 8 bits of shifting.
381 * The bit_shift for a mc_filter_type of 0 represents the number of
382 * left-shifts where the MSB of mc_addr[5] would still fall within
383 * the hash_mask. Case 0 does this exactly. Since there are a total
384 * of 8 bits of shifting, then mc_addr[4] will shift right the
385 * remaining number of bits. Thus 8 - bit_shift. The rest of the
386 * cases are a variation of this algorithm...essentially raising the
387 * number of bits to shift mc_addr[5] left, while still keeping the
388 * 8-bit shifting total.
390 * For example, given the following Destination MAC Address and an
391 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
392 * we can see that the bit_shift for case 0 is 4. These are the hash
393 * values resulting from each mc_filter_type...
394 * [0] [1] [2] [3] [4] [5]
395 * 01 AA 00 12 34 56
396 * LSB MSB
398 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
399 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
400 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
401 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
403 switch (hw->mac.mc_filter_type) {
404 default:
405 case 0:
406 break;
407 case 1:
408 bit_shift += 1;
409 break;
410 case 2:
411 bit_shift += 2;
412 break;
413 case 3:
414 bit_shift += 4;
415 break;
418 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
419 (((u16) mc_addr[5]) << bit_shift)));
421 return hash_value;
425 * igb_clear_hw_cntrs_base - Clear base hardware counters
426 * @hw: pointer to the HW structure
428 * Clears the base hardware counters by reading the counter registers.
430 void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
432 u32 temp;
434 temp = rd32(E1000_CRCERRS);
435 temp = rd32(E1000_SYMERRS);
436 temp = rd32(E1000_MPC);
437 temp = rd32(E1000_SCC);
438 temp = rd32(E1000_ECOL);
439 temp = rd32(E1000_MCC);
440 temp = rd32(E1000_LATECOL);
441 temp = rd32(E1000_COLC);
442 temp = rd32(E1000_DC);
443 temp = rd32(E1000_SEC);
444 temp = rd32(E1000_RLEC);
445 temp = rd32(E1000_XONRXC);
446 temp = rd32(E1000_XONTXC);
447 temp = rd32(E1000_XOFFRXC);
448 temp = rd32(E1000_XOFFTXC);
449 temp = rd32(E1000_FCRUC);
450 temp = rd32(E1000_GPRC);
451 temp = rd32(E1000_BPRC);
452 temp = rd32(E1000_MPRC);
453 temp = rd32(E1000_GPTC);
454 temp = rd32(E1000_GORCL);
455 temp = rd32(E1000_GORCH);
456 temp = rd32(E1000_GOTCL);
457 temp = rd32(E1000_GOTCH);
458 temp = rd32(E1000_RNBC);
459 temp = rd32(E1000_RUC);
460 temp = rd32(E1000_RFC);
461 temp = rd32(E1000_ROC);
462 temp = rd32(E1000_RJC);
463 temp = rd32(E1000_TORL);
464 temp = rd32(E1000_TORH);
465 temp = rd32(E1000_TOTL);
466 temp = rd32(E1000_TOTH);
467 temp = rd32(E1000_TPR);
468 temp = rd32(E1000_TPT);
469 temp = rd32(E1000_MPTC);
470 temp = rd32(E1000_BPTC);
474 * igb_check_for_copper_link - Check for link (Copper)
475 * @hw: pointer to the HW structure
477 * Checks to see of the link status of the hardware has changed. If a
478 * change in link status has been detected, then we read the PHY registers
479 * to get the current speed/duplex if link exists.
481 s32 igb_check_for_copper_link(struct e1000_hw *hw)
483 struct e1000_mac_info *mac = &hw->mac;
484 s32 ret_val;
485 bool link;
488 * We only want to go out to the PHY registers to see if Auto-Neg
489 * has completed and/or if our link status has changed. The
490 * get_link_status flag is set upon receiving a Link Status
491 * Change or Rx Sequence Error interrupt.
493 if (!mac->get_link_status) {
494 ret_val = 0;
495 goto out;
499 * First we want to see if the MII Status Register reports
500 * link. If so, then we want to get the current speed/duplex
501 * of the PHY.
503 ret_val = igb_phy_has_link(hw, 1, 0, &link);
504 if (ret_val)
505 goto out;
507 if (!link)
508 goto out; /* No link detected */
510 mac->get_link_status = false;
513 * Check if there was DownShift, must be checked
514 * immediately after link-up
516 igb_check_downshift(hw);
519 * If we are forcing speed/duplex, then we simply return since
520 * we have already determined whether we have link or not.
522 if (!mac->autoneg) {
523 ret_val = -E1000_ERR_CONFIG;
524 goto out;
528 * Auto-Neg is enabled. Auto Speed Detection takes care
529 * of MAC speed/duplex configuration. So we only need to
530 * configure Collision Distance in the MAC.
532 igb_config_collision_dist(hw);
535 * Configure Flow Control now that Auto-Neg has completed.
536 * First, we need to restore the desired flow control
537 * settings because we may have had to re-autoneg with a
538 * different link partner.
540 ret_val = igb_config_fc_after_link_up(hw);
541 if (ret_val)
542 hw_dbg("Error configuring flow control\n");
544 out:
545 return ret_val;
549 * igb_setup_link - Setup flow control and link settings
550 * @hw: pointer to the HW structure
552 * Determines which flow control settings to use, then configures flow
553 * control. Calls the appropriate media-specific link configuration
554 * function. Assuming the adapter has a valid link partner, a valid link
555 * should be established. Assumes the hardware has previously been reset
556 * and the transmitter and receiver are not enabled.
558 s32 igb_setup_link(struct e1000_hw *hw)
560 s32 ret_val = 0;
563 * In the case of the phy reset being blocked, we already have a link.
564 * We do not need to set it up again.
566 if (igb_check_reset_block(hw))
567 goto out;
569 ret_val = igb_set_default_fc(hw);
570 if (ret_val)
571 goto out;
574 * We want to save off the original Flow Control configuration just
575 * in case we get disconnected and then reconnected into a different
576 * hub or switch with different Flow Control capabilities.
578 hw->fc.original_type = hw->fc.type;
580 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.type);
582 /* Call the necessary media_type subroutine to configure the link. */
583 ret_val = hw->mac.ops.setup_physical_interface(hw);
584 if (ret_val)
585 goto out;
588 * Initialize the flow control address, type, and PAUSE timer
589 * registers to their default values. This is done even if flow
590 * control is disabled, because it does not hurt anything to
591 * initialize these registers.
593 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
594 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
595 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
596 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
598 wr32(E1000_FCTTV, hw->fc.pause_time);
600 ret_val = igb_set_fc_watermarks(hw);
602 out:
603 return ret_val;
607 * igb_config_collision_dist - Configure collision distance
608 * @hw: pointer to the HW structure
610 * Configures the collision distance to the default value and is used
611 * during link setup. Currently no func pointer exists and all
612 * implementations are handled in the generic version of this function.
614 void igb_config_collision_dist(struct e1000_hw *hw)
616 u32 tctl;
618 tctl = rd32(E1000_TCTL);
620 tctl &= ~E1000_TCTL_COLD;
621 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
623 wr32(E1000_TCTL, tctl);
624 wrfl();
628 * igb_set_fc_watermarks - Set flow control high/low watermarks
629 * @hw: pointer to the HW structure
631 * Sets the flow control high/low threshold (watermark) registers. If
632 * flow control XON frame transmission is enabled, then set XON frame
633 * tansmission as well.
635 static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
637 s32 ret_val = 0;
638 u32 fcrtl = 0, fcrth = 0;
641 * Set the flow control receive threshold registers. Normally,
642 * these registers will be set to a default threshold that may be
643 * adjusted later by the driver's runtime code. However, if the
644 * ability to transmit pause frames is not enabled, then these
645 * registers will be set to 0.
647 if (hw->fc.type & e1000_fc_tx_pause) {
649 * We need to set up the Receive Threshold high and low water
650 * marks as well as (optionally) enabling the transmission of
651 * XON frames.
653 fcrtl = hw->fc.low_water;
654 if (hw->fc.send_xon)
655 fcrtl |= E1000_FCRTL_XONE;
657 fcrth = hw->fc.high_water;
659 wr32(E1000_FCRTL, fcrtl);
660 wr32(E1000_FCRTH, fcrth);
662 return ret_val;
666 * igb_set_default_fc - Set flow control default values
667 * @hw: pointer to the HW structure
669 * Read the EEPROM for the default values for flow control and store the
670 * values.
672 static s32 igb_set_default_fc(struct e1000_hw *hw)
674 s32 ret_val = 0;
675 u16 nvm_data;
678 * Read and store word 0x0F of the EEPROM. This word contains bits
679 * that determine the hardware's default PAUSE (flow control) mode,
680 * a bit that determines whether the HW defaults to enabling or
681 * disabling auto-negotiation, and the direction of the
682 * SW defined pins. If there is no SW over-ride of the flow
683 * control setting, then the variable hw->fc will
684 * be initialized based on a value in the EEPROM.
686 ret_val = hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL2_REG, 1,
687 &nvm_data);
689 if (ret_val) {
690 hw_dbg("NVM Read Error\n");
691 goto out;
694 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
695 hw->fc.type = e1000_fc_none;
696 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
697 NVM_WORD0F_ASM_DIR)
698 hw->fc.type = e1000_fc_tx_pause;
699 else
700 hw->fc.type = e1000_fc_full;
702 out:
703 return ret_val;
707 * igb_force_mac_fc - Force the MAC's flow control settings
708 * @hw: pointer to the HW structure
710 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
711 * device control register to reflect the adapter settings. TFCE and RFCE
712 * need to be explicitly set by software when a copper PHY is used because
713 * autonegotiation is managed by the PHY rather than the MAC. Software must
714 * also configure these bits when link is forced on a fiber connection.
716 s32 igb_force_mac_fc(struct e1000_hw *hw)
718 u32 ctrl;
719 s32 ret_val = 0;
721 ctrl = rd32(E1000_CTRL);
724 * Because we didn't get link via the internal auto-negotiation
725 * mechanism (we either forced link or we got link via PHY
726 * auto-neg), we have to manually enable/disable transmit an
727 * receive flow control.
729 * The "Case" statement below enables/disable flow control
730 * according to the "hw->fc.type" parameter.
732 * The possible values of the "fc" parameter are:
733 * 0: Flow control is completely disabled
734 * 1: Rx flow control is enabled (we can receive pause
735 * frames but not send pause frames).
736 * 2: Tx flow control is enabled (we can send pause frames
737 * frames but we do not receive pause frames).
738 * 3: Both Rx and TX flow control (symmetric) is enabled.
739 * other: No other values should be possible at this point.
741 hw_dbg("hw->fc.type = %u\n", hw->fc.type);
743 switch (hw->fc.type) {
744 case e1000_fc_none:
745 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
746 break;
747 case e1000_fc_rx_pause:
748 ctrl &= (~E1000_CTRL_TFCE);
749 ctrl |= E1000_CTRL_RFCE;
750 break;
751 case e1000_fc_tx_pause:
752 ctrl &= (~E1000_CTRL_RFCE);
753 ctrl |= E1000_CTRL_TFCE;
754 break;
755 case e1000_fc_full:
756 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
757 break;
758 default:
759 hw_dbg("Flow control param set incorrectly\n");
760 ret_val = -E1000_ERR_CONFIG;
761 goto out;
764 wr32(E1000_CTRL, ctrl);
766 out:
767 return ret_val;
771 * igb_config_fc_after_link_up - Configures flow control after link
772 * @hw: pointer to the HW structure
774 * Checks the status of auto-negotiation after link up to ensure that the
775 * speed and duplex were not forced. If the link needed to be forced, then
776 * flow control needs to be forced also. If auto-negotiation is enabled
777 * and did not fail, then we configure flow control based on our link
778 * partner.
780 s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
782 struct e1000_mac_info *mac = &hw->mac;
783 s32 ret_val = 0;
784 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
785 u16 speed, duplex;
788 * Check for the case where we have fiber media and auto-neg failed
789 * so we had to force link. In this case, we need to force the
790 * configuration of the MAC to match the "fc" parameter.
792 if (mac->autoneg_failed) {
793 if (hw->phy.media_type == e1000_media_type_fiber ||
794 hw->phy.media_type == e1000_media_type_internal_serdes)
795 ret_val = igb_force_mac_fc(hw);
796 } else {
797 if (hw->phy.media_type == e1000_media_type_copper)
798 ret_val = igb_force_mac_fc(hw);
801 if (ret_val) {
802 hw_dbg("Error forcing flow control settings\n");
803 goto out;
807 * Check for the case where we have copper media and auto-neg is
808 * enabled. In this case, we need to check and see if Auto-Neg
809 * has completed, and if so, how the PHY and link partner has
810 * flow control configured.
812 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
814 * Read the MII Status Register and check to see if AutoNeg
815 * has completed. We read this twice because this reg has
816 * some "sticky" (latched) bits.
818 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
819 &mii_status_reg);
820 if (ret_val)
821 goto out;
822 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
823 &mii_status_reg);
824 if (ret_val)
825 goto out;
827 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
828 hw_dbg("Copper PHY and Auto Neg "
829 "has not completed.\n");
830 goto out;
834 * The AutoNeg process has completed, so we now need to
835 * read both the Auto Negotiation Advertisement
836 * Register (Address 4) and the Auto_Negotiation Base
837 * Page Ability Register (Address 5) to determine how
838 * flow control was negotiated.
840 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_AUTONEG_ADV,
841 &mii_nway_adv_reg);
842 if (ret_val)
843 goto out;
844 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_LP_ABILITY,
845 &mii_nway_lp_ability_reg);
846 if (ret_val)
847 goto out;
850 * Two bits in the Auto Negotiation Advertisement Register
851 * (Address 4) and two bits in the Auto Negotiation Base
852 * Page Ability Register (Address 5) determine flow control
853 * for both the PHY and the link partner. The following
854 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
855 * 1999, describes these PAUSE resolution bits and how flow
856 * control is determined based upon these settings.
857 * NOTE: DC = Don't Care
859 * LOCAL DEVICE | LINK PARTNER
860 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
861 *-------|---------|-------|---------|--------------------
862 * 0 | 0 | DC | DC | e1000_fc_none
863 * 0 | 1 | 0 | DC | e1000_fc_none
864 * 0 | 1 | 1 | 0 | e1000_fc_none
865 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
866 * 1 | 0 | 0 | DC | e1000_fc_none
867 * 1 | DC | 1 | DC | e1000_fc_full
868 * 1 | 1 | 0 | 0 | e1000_fc_none
869 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
871 * Are both PAUSE bits set to 1? If so, this implies
872 * Symmetric Flow Control is enabled at both ends. The
873 * ASM_DIR bits are irrelevant per the spec.
875 * For Symmetric Flow Control:
877 * LOCAL DEVICE | LINK PARTNER
878 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
879 *-------|---------|-------|---------|--------------------
880 * 1 | DC | 1 | DC | E1000_fc_full
883 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
884 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
886 * Now we need to check if the user selected RX ONLY
887 * of pause frames. In this case, we had to advertise
888 * FULL flow control because we could not advertise RX
889 * ONLY. Hence, we must now check to see if we need to
890 * turn OFF the TRANSMISSION of PAUSE frames.
892 if (hw->fc.original_type == e1000_fc_full) {
893 hw->fc.type = e1000_fc_full;
894 hw_dbg("Flow Control = FULL.\r\n");
895 } else {
896 hw->fc.type = e1000_fc_rx_pause;
897 hw_dbg("Flow Control = "
898 "RX PAUSE frames only.\r\n");
902 * For receiving PAUSE frames ONLY.
904 * LOCAL DEVICE | LINK PARTNER
905 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
906 *-------|---------|-------|---------|--------------------
907 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
909 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
910 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
911 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
912 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
913 hw->fc.type = e1000_fc_tx_pause;
914 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
917 * For transmitting PAUSE frames ONLY.
919 * LOCAL DEVICE | LINK PARTNER
920 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
921 *-------|---------|-------|---------|--------------------
922 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
924 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
925 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
926 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
927 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
928 hw->fc.type = e1000_fc_rx_pause;
929 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
932 * Per the IEEE spec, at this point flow control should be
933 * disabled. However, we want to consider that we could
934 * be connected to a legacy switch that doesn't advertise
935 * desired flow control, but can be forced on the link
936 * partner. So if we advertised no flow control, that is
937 * what we will resolve to. If we advertised some kind of
938 * receive capability (Rx Pause Only or Full Flow Control)
939 * and the link partner advertised none, we will configure
940 * ourselves to enable Rx Flow Control only. We can do
941 * this safely for two reasons: If the link partner really
942 * didn't want flow control enabled, and we enable Rx, no
943 * harm done since we won't be receiving any PAUSE frames
944 * anyway. If the intent on the link partner was to have
945 * flow control enabled, then by us enabling RX only, we
946 * can at least receive pause frames and process them.
947 * This is a good idea because in most cases, since we are
948 * predominantly a server NIC, more times than not we will
949 * be asked to delay transmission of packets than asking
950 * our link partner to pause transmission of frames.
952 else if ((hw->fc.original_type == e1000_fc_none ||
953 hw->fc.original_type == e1000_fc_tx_pause) ||
954 hw->fc.strict_ieee) {
955 hw->fc.type = e1000_fc_none;
956 hw_dbg("Flow Control = NONE.\r\n");
957 } else {
958 hw->fc.type = e1000_fc_rx_pause;
959 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
963 * Now we need to do one last check... If we auto-
964 * negotiated to HALF DUPLEX, flow control should not be
965 * enabled per IEEE 802.3 spec.
967 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
968 if (ret_val) {
969 hw_dbg("Error getting link speed and duplex\n");
970 goto out;
973 if (duplex == HALF_DUPLEX)
974 hw->fc.type = e1000_fc_none;
977 * Now we call a subroutine to actually force the MAC
978 * controller to use the correct flow control settings.
980 ret_val = igb_force_mac_fc(hw);
981 if (ret_val) {
982 hw_dbg("Error forcing flow control settings\n");
983 goto out;
987 out:
988 return ret_val;
992 * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
993 * @hw: pointer to the HW structure
994 * @speed: stores the current speed
995 * @duplex: stores the current duplex
997 * Read the status register for the current speed/duplex and store the current
998 * speed and duplex for copper connections.
1000 s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
1001 u16 *duplex)
1003 u32 status;
1005 status = rd32(E1000_STATUS);
1006 if (status & E1000_STATUS_SPEED_1000) {
1007 *speed = SPEED_1000;
1008 hw_dbg("1000 Mbs, ");
1009 } else if (status & E1000_STATUS_SPEED_100) {
1010 *speed = SPEED_100;
1011 hw_dbg("100 Mbs, ");
1012 } else {
1013 *speed = SPEED_10;
1014 hw_dbg("10 Mbs, ");
1017 if (status & E1000_STATUS_FD) {
1018 *duplex = FULL_DUPLEX;
1019 hw_dbg("Full Duplex\n");
1020 } else {
1021 *duplex = HALF_DUPLEX;
1022 hw_dbg("Half Duplex\n");
1025 return 0;
1029 * igb_get_hw_semaphore - Acquire hardware semaphore
1030 * @hw: pointer to the HW structure
1032 * Acquire the HW semaphore to access the PHY or NVM
1034 s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1036 u32 swsm;
1037 s32 ret_val = 0;
1038 s32 timeout = hw->nvm.word_size + 1;
1039 s32 i = 0;
1041 /* Get the SW semaphore */
1042 while (i < timeout) {
1043 swsm = rd32(E1000_SWSM);
1044 if (!(swsm & E1000_SWSM_SMBI))
1045 break;
1047 udelay(50);
1048 i++;
1051 if (i == timeout) {
1052 hw_dbg("Driver can't access device - SMBI bit is set.\n");
1053 ret_val = -E1000_ERR_NVM;
1054 goto out;
1057 /* Get the FW semaphore. */
1058 for (i = 0; i < timeout; i++) {
1059 swsm = rd32(E1000_SWSM);
1060 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1062 /* Semaphore acquired if bit latched */
1063 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1064 break;
1066 udelay(50);
1069 if (i == timeout) {
1070 /* Release semaphores */
1071 igb_put_hw_semaphore(hw);
1072 hw_dbg("Driver can't access the NVM\n");
1073 ret_val = -E1000_ERR_NVM;
1074 goto out;
1077 out:
1078 return ret_val;
1082 * igb_put_hw_semaphore - Release hardware semaphore
1083 * @hw: pointer to the HW structure
1085 * Release hardware semaphore used to access the PHY or NVM
1087 void igb_put_hw_semaphore(struct e1000_hw *hw)
1089 u32 swsm;
1091 swsm = rd32(E1000_SWSM);
1093 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1095 wr32(E1000_SWSM, swsm);
1099 * igb_get_auto_rd_done - Check for auto read completion
1100 * @hw: pointer to the HW structure
1102 * Check EEPROM for Auto Read done bit.
1104 s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1106 s32 i = 0;
1107 s32 ret_val = 0;
1110 while (i < AUTO_READ_DONE_TIMEOUT) {
1111 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1112 break;
1113 msleep(1);
1114 i++;
1117 if (i == AUTO_READ_DONE_TIMEOUT) {
1118 hw_dbg("Auto read by HW from NVM has not completed.\n");
1119 ret_val = -E1000_ERR_RESET;
1120 goto out;
1123 out:
1124 return ret_val;
1128 * igb_valid_led_default - Verify a valid default LED config
1129 * @hw: pointer to the HW structure
1130 * @data: pointer to the NVM (EEPROM)
1132 * Read the EEPROM for the current default LED configuration. If the
1133 * LED configuration is not valid, set to a valid LED configuration.
1135 static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1137 s32 ret_val;
1139 ret_val = hw->nvm.ops.read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1140 if (ret_val) {
1141 hw_dbg("NVM Read Error\n");
1142 goto out;
1145 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
1146 *data = ID_LED_DEFAULT;
1148 out:
1149 return ret_val;
1153 * igb_id_led_init -
1154 * @hw: pointer to the HW structure
1157 s32 igb_id_led_init(struct e1000_hw *hw)
1159 struct e1000_mac_info *mac = &hw->mac;
1160 s32 ret_val;
1161 const u32 ledctl_mask = 0x000000FF;
1162 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1163 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1164 u16 data, i, temp;
1165 const u16 led_mask = 0x0F;
1167 ret_val = igb_valid_led_default(hw, &data);
1168 if (ret_val)
1169 goto out;
1171 mac->ledctl_default = rd32(E1000_LEDCTL);
1172 mac->ledctl_mode1 = mac->ledctl_default;
1173 mac->ledctl_mode2 = mac->ledctl_default;
1175 for (i = 0; i < 4; i++) {
1176 temp = (data >> (i << 2)) & led_mask;
1177 switch (temp) {
1178 case ID_LED_ON1_DEF2:
1179 case ID_LED_ON1_ON2:
1180 case ID_LED_ON1_OFF2:
1181 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1182 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1183 break;
1184 case ID_LED_OFF1_DEF2:
1185 case ID_LED_OFF1_ON2:
1186 case ID_LED_OFF1_OFF2:
1187 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1188 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1189 break;
1190 default:
1191 /* Do nothing */
1192 break;
1194 switch (temp) {
1195 case ID_LED_DEF1_ON2:
1196 case ID_LED_ON1_ON2:
1197 case ID_LED_OFF1_ON2:
1198 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1199 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1200 break;
1201 case ID_LED_DEF1_OFF2:
1202 case ID_LED_ON1_OFF2:
1203 case ID_LED_OFF1_OFF2:
1204 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1205 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1206 break;
1207 default:
1208 /* Do nothing */
1209 break;
1213 out:
1214 return ret_val;
1218 * igb_cleanup_led - Set LED config to default operation
1219 * @hw: pointer to the HW structure
1221 * Remove the current LED configuration and set the LED configuration
1222 * to the default value, saved from the EEPROM.
1224 s32 igb_cleanup_led(struct e1000_hw *hw)
1226 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1227 return 0;
1231 * igb_blink_led - Blink LED
1232 * @hw: pointer to the HW structure
1234 * Blink the led's which are set to be on.
1236 s32 igb_blink_led(struct e1000_hw *hw)
1238 u32 ledctl_blink = 0;
1239 u32 i;
1241 if (hw->phy.media_type == e1000_media_type_fiber) {
1242 /* always blink LED0 for PCI-E fiber */
1243 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1244 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1245 } else {
1247 * set the blink bit for each LED that's "on" (0x0E)
1248 * in ledctl_mode2
1250 ledctl_blink = hw->mac.ledctl_mode2;
1251 for (i = 0; i < 4; i++)
1252 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1253 E1000_LEDCTL_MODE_LED_ON)
1254 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1255 (i * 8));
1258 wr32(E1000_LEDCTL, ledctl_blink);
1260 return 0;
1264 * igb_led_off - Turn LED off
1265 * @hw: pointer to the HW structure
1267 * Turn LED off.
1269 s32 igb_led_off(struct e1000_hw *hw)
1271 u32 ctrl;
1273 switch (hw->phy.media_type) {
1274 case e1000_media_type_fiber:
1275 ctrl = rd32(E1000_CTRL);
1276 ctrl |= E1000_CTRL_SWDPIN0;
1277 ctrl |= E1000_CTRL_SWDPIO0;
1278 wr32(E1000_CTRL, ctrl);
1279 break;
1280 case e1000_media_type_copper:
1281 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1282 break;
1283 default:
1284 break;
1287 return 0;
1291 * igb_disable_pcie_master - Disables PCI-express master access
1292 * @hw: pointer to the HW structure
1294 * Returns 0 (0) if successful, else returns -10
1295 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1296 * the master requests to be disabled.
1298 * Disables PCI-Express master access and verifies there are no pending
1299 * requests.
1301 s32 igb_disable_pcie_master(struct e1000_hw *hw)
1303 u32 ctrl;
1304 s32 timeout = MASTER_DISABLE_TIMEOUT;
1305 s32 ret_val = 0;
1307 if (hw->bus.type != e1000_bus_type_pci_express)
1308 goto out;
1310 ctrl = rd32(E1000_CTRL);
1311 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1312 wr32(E1000_CTRL, ctrl);
1314 while (timeout) {
1315 if (!(rd32(E1000_STATUS) &
1316 E1000_STATUS_GIO_MASTER_ENABLE))
1317 break;
1318 udelay(100);
1319 timeout--;
1322 if (!timeout) {
1323 hw_dbg("Master requests are pending.\n");
1324 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1325 goto out;
1328 out:
1329 return ret_val;
1333 * igb_reset_adaptive - Reset Adaptive Interframe Spacing
1334 * @hw: pointer to the HW structure
1336 * Reset the Adaptive Interframe Spacing throttle to default values.
1338 void igb_reset_adaptive(struct e1000_hw *hw)
1340 struct e1000_mac_info *mac = &hw->mac;
1342 if (!mac->adaptive_ifs) {
1343 hw_dbg("Not in Adaptive IFS mode!\n");
1344 goto out;
1347 if (!mac->ifs_params_forced) {
1348 mac->current_ifs_val = 0;
1349 mac->ifs_min_val = IFS_MIN;
1350 mac->ifs_max_val = IFS_MAX;
1351 mac->ifs_step_size = IFS_STEP;
1352 mac->ifs_ratio = IFS_RATIO;
1355 mac->in_ifs_mode = false;
1356 wr32(E1000_AIT, 0);
1357 out:
1358 return;
1362 * igb_update_adaptive - Update Adaptive Interframe Spacing
1363 * @hw: pointer to the HW structure
1365 * Update the Adaptive Interframe Spacing Throttle value based on the
1366 * time between transmitted packets and time between collisions.
1368 void igb_update_adaptive(struct e1000_hw *hw)
1370 struct e1000_mac_info *mac = &hw->mac;
1372 if (!mac->adaptive_ifs) {
1373 hw_dbg("Not in Adaptive IFS mode!\n");
1374 goto out;
1377 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1378 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
1379 mac->in_ifs_mode = true;
1380 if (mac->current_ifs_val < mac->ifs_max_val) {
1381 if (!mac->current_ifs_val)
1382 mac->current_ifs_val = mac->ifs_min_val;
1383 else
1384 mac->current_ifs_val +=
1385 mac->ifs_step_size;
1386 wr32(E1000_AIT,
1387 mac->current_ifs_val);
1390 } else {
1391 if (mac->in_ifs_mode &&
1392 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1393 mac->current_ifs_val = 0;
1394 mac->in_ifs_mode = false;
1395 wr32(E1000_AIT, 0);
1398 out:
1399 return;
1403 * igb_validate_mdi_setting - Verify MDI/MDIx settings
1404 * @hw: pointer to the HW structure
1406 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1407 * set, which is forced to MDI mode only.
1409 s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1411 s32 ret_val = 0;
1413 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
1414 hw_dbg("Invalid MDI setting detected\n");
1415 hw->phy.mdix = 1;
1416 ret_val = -E1000_ERR_CONFIG;
1417 goto out;
1420 out:
1421 return ret_val;
1425 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
1426 * @hw: pointer to the HW structure
1427 * @reg: 32bit register offset such as E1000_SCTL
1428 * @offset: register offset to write to
1429 * @data: data to write at register offset
1431 * Writes an address/data control type register. There are several of these
1432 * and they all have the format address << 8 | data and bit 31 is polled for
1433 * completion.
1435 s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1436 u32 offset, u8 data)
1438 u32 i, regvalue = 0;
1439 s32 ret_val = 0;
1441 /* Set up the address and data */
1442 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1443 wr32(reg, regvalue);
1445 /* Poll the ready bit to see if the MDI read completed */
1446 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1447 udelay(5);
1448 regvalue = rd32(reg);
1449 if (regvalue & E1000_GEN_CTL_READY)
1450 break;
1452 if (!(regvalue & E1000_GEN_CTL_READY)) {
1453 hw_dbg("Reg %08x did not indicate ready\n", reg);
1454 ret_val = -E1000_ERR_PHY;
1455 goto out;
1458 out:
1459 return ret_val;
1463 * igb_enable_mng_pass_thru - Enable processing of ARP's
1464 * @hw: pointer to the HW structure
1466 * Verifies the hardware needs to allow ARPs to be processed by the host.
1468 bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1470 u32 manc;
1471 u32 fwsm, factps;
1472 bool ret_val = false;
1474 if (!hw->mac.asf_firmware_present)
1475 goto out;
1477 manc = rd32(E1000_MANC);
1479 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
1480 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
1481 goto out;
1483 if (hw->mac.arc_subsystem_valid) {
1484 fwsm = rd32(E1000_FWSM);
1485 factps = rd32(E1000_FACTPS);
1487 if (!(factps & E1000_FACTPS_MNGCG) &&
1488 ((fwsm & E1000_FWSM_MODE_MASK) ==
1489 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1490 ret_val = true;
1491 goto out;
1493 } else {
1494 if ((manc & E1000_MANC_SMBUS_EN) &&
1495 !(manc & E1000_MANC_ASF_EN)) {
1496 ret_val = true;
1497 goto out;
1501 out:
1502 return ret_val;