1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2009 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
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".
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"
37 static s32 igb_set_default_fc(struct e1000_hw *hw);
38 static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
40 static s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
42 struct igb_adapter *adapter = hw->back;
45 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
47 return -E1000_ERR_CONFIG;
49 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
55 * igb_get_bus_info_pcie - Get PCIe bus information
56 * @hw: pointer to the HW structure
58 * Determines and stores the system bus information for a particular
59 * network interface. The following bus information is determined and stored:
60 * bus speed, bus width, type (PCIe), and PCIe function.
62 s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
64 struct e1000_bus_info *bus = &hw->bus;
69 bus->type = e1000_bus_type_pci_express;
70 bus->speed = e1000_bus_speed_2500;
72 ret_val = igb_read_pcie_cap_reg(hw,
76 bus->width = e1000_bus_width_unknown;
78 bus->width = (enum e1000_bus_width)((pcie_link_status &
79 PCIE_LINK_WIDTH_MASK) >>
80 PCIE_LINK_WIDTH_SHIFT);
82 reg = rd32(E1000_STATUS);
83 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
89 * igb_clear_vfta - Clear VLAN filter table
90 * @hw: pointer to the HW structure
92 * Clears the register array which contains the VLAN filter table by
93 * setting all the values to 0.
95 void igb_clear_vfta(struct e1000_hw *hw)
99 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
100 array_wr32(E1000_VFTA, offset, 0);
106 * igb_write_vfta - Write value to VLAN filter table
107 * @hw: pointer to the HW structure
108 * @offset: register offset in VLAN filter table
109 * @value: register value written to VLAN filter table
111 * Writes value at the given offset in the register array which stores
112 * the VLAN filter table.
114 void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
116 array_wr32(E1000_VFTA, offset, value);
121 * igb_check_alt_mac_addr - Check for alternate MAC addr
122 * @hw: pointer to the HW structure
124 * Checks the nvm for an alternate MAC address. An alternate MAC address
125 * can be setup by pre-boot software and must be treated like a permanent
126 * address and must override the actual permanent MAC address. If an
127 * alternate MAC address is fopund it is saved in the hw struct and
128 * prgrammed into RAR0 and the cuntion returns success, otherwise the
129 * fucntion returns an error.
131 s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
135 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
136 u8 alt_mac_addr[ETH_ALEN];
138 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
139 &nvm_alt_mac_addr_offset);
141 hw_dbg("NVM Read Error\n");
145 if (nvm_alt_mac_addr_offset == 0xFFFF) {
146 ret_val = -(E1000_NOT_IMPLEMENTED);
150 if (hw->bus.func == E1000_FUNC_1)
151 nvm_alt_mac_addr_offset += ETH_ALEN/sizeof(u16);
153 for (i = 0; i < ETH_ALEN; i += 2) {
154 offset = nvm_alt_mac_addr_offset + (i >> 1);
155 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
157 hw_dbg("NVM Read Error\n");
161 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
162 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
165 /* if multicast bit is set, the alternate address will not be used */
166 if (alt_mac_addr[0] & 0x01) {
167 ret_val = -(E1000_NOT_IMPLEMENTED);
171 for (i = 0; i < ETH_ALEN; i++)
172 hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i];
174 hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0);
181 * igb_rar_set - Set receive address register
182 * @hw: pointer to the HW structure
183 * @addr: pointer to the receive address
184 * @index: receive address array register
186 * Sets the receive address array register at index to the address passed
189 void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
191 u32 rar_low, rar_high;
194 * HW expects these in little endian so we reverse the byte order
195 * from network order (big endian) to little endian
197 rar_low = ((u32) addr[0] |
198 ((u32) addr[1] << 8) |
199 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
201 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
203 /* If MAC address zero, no need to set the AV bit */
204 if (rar_low || rar_high)
205 rar_high |= E1000_RAH_AV;
207 wr32(E1000_RAL(index), rar_low);
208 wr32(E1000_RAH(index), rar_high);
212 * igb_mta_set - Set multicast filter table address
213 * @hw: pointer to the HW structure
214 * @hash_value: determines the MTA register and bit to set
216 * The multicast table address is a register array of 32-bit registers.
217 * The hash_value is used to determine what register the bit is in, the
218 * current value is read, the new bit is OR'd in and the new value is
219 * written back into the register.
221 void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
223 u32 hash_bit, hash_reg, mta;
226 * The MTA is a register array of 32-bit registers. It is
227 * treated like an array of (32*mta_reg_count) bits. We want to
228 * set bit BitArray[hash_value]. So we figure out what register
229 * the bit is in, read it, OR in the new bit, then write
230 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
231 * mask to bits 31:5 of the hash value which gives us the
232 * register we're modifying. The hash bit within that register
233 * is determined by the lower 5 bits of the hash value.
235 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
236 hash_bit = hash_value & 0x1F;
238 mta = array_rd32(E1000_MTA, hash_reg);
240 mta |= (1 << hash_bit);
242 array_wr32(E1000_MTA, hash_reg, mta);
247 * igb_hash_mc_addr - Generate a multicast hash value
248 * @hw: pointer to the HW structure
249 * @mc_addr: pointer to a multicast address
251 * Generates a multicast address hash value which is used to determine
252 * the multicast filter table array address and new table value. See
255 u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
257 u32 hash_value, hash_mask;
260 /* Register count multiplied by bits per register */
261 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
264 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
265 * where 0xFF would still fall within the hash mask.
267 while (hash_mask >> bit_shift != 0xFF)
271 * The portion of the address that is used for the hash table
272 * is determined by the mc_filter_type setting.
273 * The algorithm is such that there is a total of 8 bits of shifting.
274 * The bit_shift for a mc_filter_type of 0 represents the number of
275 * left-shifts where the MSB of mc_addr[5] would still fall within
276 * the hash_mask. Case 0 does this exactly. Since there are a total
277 * of 8 bits of shifting, then mc_addr[4] will shift right the
278 * remaining number of bits. Thus 8 - bit_shift. The rest of the
279 * cases are a variation of this algorithm...essentially raising the
280 * number of bits to shift mc_addr[5] left, while still keeping the
281 * 8-bit shifting total.
283 * For example, given the following Destination MAC Address and an
284 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
285 * we can see that the bit_shift for case 0 is 4. These are the hash
286 * values resulting from each mc_filter_type...
287 * [0] [1] [2] [3] [4] [5]
291 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
292 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
293 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
294 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
296 switch (hw->mac.mc_filter_type) {
311 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
312 (((u16) mc_addr[5]) << bit_shift)));
318 * igb_clear_hw_cntrs_base - Clear base hardware counters
319 * @hw: pointer to the HW structure
321 * Clears the base hardware counters by reading the counter registers.
323 void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
327 temp = rd32(E1000_CRCERRS);
328 temp = rd32(E1000_SYMERRS);
329 temp = rd32(E1000_MPC);
330 temp = rd32(E1000_SCC);
331 temp = rd32(E1000_ECOL);
332 temp = rd32(E1000_MCC);
333 temp = rd32(E1000_LATECOL);
334 temp = rd32(E1000_COLC);
335 temp = rd32(E1000_DC);
336 temp = rd32(E1000_SEC);
337 temp = rd32(E1000_RLEC);
338 temp = rd32(E1000_XONRXC);
339 temp = rd32(E1000_XONTXC);
340 temp = rd32(E1000_XOFFRXC);
341 temp = rd32(E1000_XOFFTXC);
342 temp = rd32(E1000_FCRUC);
343 temp = rd32(E1000_GPRC);
344 temp = rd32(E1000_BPRC);
345 temp = rd32(E1000_MPRC);
346 temp = rd32(E1000_GPTC);
347 temp = rd32(E1000_GORCL);
348 temp = rd32(E1000_GORCH);
349 temp = rd32(E1000_GOTCL);
350 temp = rd32(E1000_GOTCH);
351 temp = rd32(E1000_RNBC);
352 temp = rd32(E1000_RUC);
353 temp = rd32(E1000_RFC);
354 temp = rd32(E1000_ROC);
355 temp = rd32(E1000_RJC);
356 temp = rd32(E1000_TORL);
357 temp = rd32(E1000_TORH);
358 temp = rd32(E1000_TOTL);
359 temp = rd32(E1000_TOTH);
360 temp = rd32(E1000_TPR);
361 temp = rd32(E1000_TPT);
362 temp = rd32(E1000_MPTC);
363 temp = rd32(E1000_BPTC);
367 * igb_check_for_copper_link - Check for link (Copper)
368 * @hw: pointer to the HW structure
370 * Checks to see of the link status of the hardware has changed. If a
371 * change in link status has been detected, then we read the PHY registers
372 * to get the current speed/duplex if link exists.
374 s32 igb_check_for_copper_link(struct e1000_hw *hw)
376 struct e1000_mac_info *mac = &hw->mac;
381 * We only want to go out to the PHY registers to see if Auto-Neg
382 * has completed and/or if our link status has changed. The
383 * get_link_status flag is set upon receiving a Link Status
384 * Change or Rx Sequence Error interrupt.
386 if (!mac->get_link_status) {
392 * First we want to see if the MII Status Register reports
393 * link. If so, then we want to get the current speed/duplex
396 ret_val = igb_phy_has_link(hw, 1, 0, &link);
401 goto out; /* No link detected */
403 mac->get_link_status = false;
406 * Check if there was DownShift, must be checked
407 * immediately after link-up
409 igb_check_downshift(hw);
412 * If we are forcing speed/duplex, then we simply return since
413 * we have already determined whether we have link or not.
416 ret_val = -E1000_ERR_CONFIG;
421 * Auto-Neg is enabled. Auto Speed Detection takes care
422 * of MAC speed/duplex configuration. So we only need to
423 * configure Collision Distance in the MAC.
425 igb_config_collision_dist(hw);
428 * Configure Flow Control now that Auto-Neg has completed.
429 * First, we need to restore the desired flow control
430 * settings because we may have had to re-autoneg with a
431 * different link partner.
433 ret_val = igb_config_fc_after_link_up(hw);
435 hw_dbg("Error configuring flow control\n");
442 * igb_setup_link - Setup flow control and link settings
443 * @hw: pointer to the HW structure
445 * Determines which flow control settings to use, then configures flow
446 * control. Calls the appropriate media-specific link configuration
447 * function. Assuming the adapter has a valid link partner, a valid link
448 * should be established. Assumes the hardware has previously been reset
449 * and the transmitter and receiver are not enabled.
451 s32 igb_setup_link(struct e1000_hw *hw)
456 * In the case of the phy reset being blocked, we already have a link.
457 * We do not need to set it up again.
459 if (igb_check_reset_block(hw))
462 ret_val = igb_set_default_fc(hw);
467 * We want to save off the original Flow Control configuration just
468 * in case we get disconnected and then reconnected into a different
469 * hub or switch with different Flow Control capabilities.
471 hw->fc.original_type = hw->fc.type;
473 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.type);
475 /* Call the necessary media_type subroutine to configure the link. */
476 ret_val = hw->mac.ops.setup_physical_interface(hw);
481 * Initialize the flow control address, type, and PAUSE timer
482 * registers to their default values. This is done even if flow
483 * control is disabled, because it does not hurt anything to
484 * initialize these registers.
486 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
487 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
488 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
489 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
491 wr32(E1000_FCTTV, hw->fc.pause_time);
493 ret_val = igb_set_fc_watermarks(hw);
500 * igb_config_collision_dist - Configure collision distance
501 * @hw: pointer to the HW structure
503 * Configures the collision distance to the default value and is used
504 * during link setup. Currently no func pointer exists and all
505 * implementations are handled in the generic version of this function.
507 void igb_config_collision_dist(struct e1000_hw *hw)
511 tctl = rd32(E1000_TCTL);
513 tctl &= ~E1000_TCTL_COLD;
514 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
516 wr32(E1000_TCTL, tctl);
521 * igb_set_fc_watermarks - Set flow control high/low watermarks
522 * @hw: pointer to the HW structure
524 * Sets the flow control high/low threshold (watermark) registers. If
525 * flow control XON frame transmission is enabled, then set XON frame
526 * tansmission as well.
528 static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
531 u32 fcrtl = 0, fcrth = 0;
534 * Set the flow control receive threshold registers. Normally,
535 * these registers will be set to a default threshold that may be
536 * adjusted later by the driver's runtime code. However, if the
537 * ability to transmit pause frames is not enabled, then these
538 * registers will be set to 0.
540 if (hw->fc.type & e1000_fc_tx_pause) {
542 * We need to set up the Receive Threshold high and low water
543 * marks as well as (optionally) enabling the transmission of
546 fcrtl = hw->fc.low_water;
548 fcrtl |= E1000_FCRTL_XONE;
550 fcrth = hw->fc.high_water;
552 wr32(E1000_FCRTL, fcrtl);
553 wr32(E1000_FCRTH, fcrth);
559 * igb_set_default_fc - Set flow control default values
560 * @hw: pointer to the HW structure
562 * Read the EEPROM for the default values for flow control and store the
565 static s32 igb_set_default_fc(struct e1000_hw *hw)
571 * Read and store word 0x0F of the EEPROM. This word contains bits
572 * that determine the hardware's default PAUSE (flow control) mode,
573 * a bit that determines whether the HW defaults to enabling or
574 * disabling auto-negotiation, and the direction of the
575 * SW defined pins. If there is no SW over-ride of the flow
576 * control setting, then the variable hw->fc will
577 * be initialized based on a value in the EEPROM.
579 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
582 hw_dbg("NVM Read Error\n");
586 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
587 hw->fc.type = e1000_fc_none;
588 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
590 hw->fc.type = e1000_fc_tx_pause;
592 hw->fc.type = e1000_fc_full;
599 * igb_force_mac_fc - Force the MAC's flow control settings
600 * @hw: pointer to the HW structure
602 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
603 * device control register to reflect the adapter settings. TFCE and RFCE
604 * need to be explicitly set by software when a copper PHY is used because
605 * autonegotiation is managed by the PHY rather than the MAC. Software must
606 * also configure these bits when link is forced on a fiber connection.
608 s32 igb_force_mac_fc(struct e1000_hw *hw)
613 ctrl = rd32(E1000_CTRL);
616 * Because we didn't get link via the internal auto-negotiation
617 * mechanism (we either forced link or we got link via PHY
618 * auto-neg), we have to manually enable/disable transmit an
619 * receive flow control.
621 * The "Case" statement below enables/disable flow control
622 * according to the "hw->fc.type" parameter.
624 * The possible values of the "fc" parameter are:
625 * 0: Flow control is completely disabled
626 * 1: Rx flow control is enabled (we can receive pause
627 * frames but not send pause frames).
628 * 2: Tx flow control is enabled (we can send pause frames
629 * frames but we do not receive pause frames).
630 * 3: Both Rx and TX flow control (symmetric) is enabled.
631 * other: No other values should be possible at this point.
633 hw_dbg("hw->fc.type = %u\n", hw->fc.type);
635 switch (hw->fc.type) {
637 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
639 case e1000_fc_rx_pause:
640 ctrl &= (~E1000_CTRL_TFCE);
641 ctrl |= E1000_CTRL_RFCE;
643 case e1000_fc_tx_pause:
644 ctrl &= (~E1000_CTRL_RFCE);
645 ctrl |= E1000_CTRL_TFCE;
648 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
651 hw_dbg("Flow control param set incorrectly\n");
652 ret_val = -E1000_ERR_CONFIG;
656 wr32(E1000_CTRL, ctrl);
663 * igb_config_fc_after_link_up - Configures flow control after link
664 * @hw: pointer to the HW structure
666 * Checks the status of auto-negotiation after link up to ensure that the
667 * speed and duplex were not forced. If the link needed to be forced, then
668 * flow control needs to be forced also. If auto-negotiation is enabled
669 * and did not fail, then we configure flow control based on our link
672 s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
674 struct e1000_mac_info *mac = &hw->mac;
676 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
680 * Check for the case where we have fiber media and auto-neg failed
681 * so we had to force link. In this case, we need to force the
682 * configuration of the MAC to match the "fc" parameter.
684 if (mac->autoneg_failed) {
685 if (hw->phy.media_type == e1000_media_type_fiber ||
686 hw->phy.media_type == e1000_media_type_internal_serdes)
687 ret_val = igb_force_mac_fc(hw);
689 if (hw->phy.media_type == e1000_media_type_copper)
690 ret_val = igb_force_mac_fc(hw);
694 hw_dbg("Error forcing flow control settings\n");
699 * Check for the case where we have copper media and auto-neg is
700 * enabled. In this case, we need to check and see if Auto-Neg
701 * has completed, and if so, how the PHY and link partner has
702 * flow control configured.
704 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
706 * Read the MII Status Register and check to see if AutoNeg
707 * has completed. We read this twice because this reg has
708 * some "sticky" (latched) bits.
710 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
714 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
719 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
720 hw_dbg("Copper PHY and Auto Neg "
721 "has not completed.\n");
726 * The AutoNeg process has completed, so we now need to
727 * read both the Auto Negotiation Advertisement
728 * Register (Address 4) and the Auto_Negotiation Base
729 * Page Ability Register (Address 5) to determine how
730 * flow control was negotiated.
732 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
736 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
737 &mii_nway_lp_ability_reg);
742 * Two bits in the Auto Negotiation Advertisement Register
743 * (Address 4) and two bits in the Auto Negotiation Base
744 * Page Ability Register (Address 5) determine flow control
745 * for both the PHY and the link partner. The following
746 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
747 * 1999, describes these PAUSE resolution bits and how flow
748 * control is determined based upon these settings.
749 * NOTE: DC = Don't Care
751 * LOCAL DEVICE | LINK PARTNER
752 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
753 *-------|---------|-------|---------|--------------------
754 * 0 | 0 | DC | DC | e1000_fc_none
755 * 0 | 1 | 0 | DC | e1000_fc_none
756 * 0 | 1 | 1 | 0 | e1000_fc_none
757 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
758 * 1 | 0 | 0 | DC | e1000_fc_none
759 * 1 | DC | 1 | DC | e1000_fc_full
760 * 1 | 1 | 0 | 0 | e1000_fc_none
761 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
763 * Are both PAUSE bits set to 1? If so, this implies
764 * Symmetric Flow Control is enabled at both ends. The
765 * ASM_DIR bits are irrelevant per the spec.
767 * For Symmetric Flow Control:
769 * LOCAL DEVICE | LINK PARTNER
770 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
771 *-------|---------|-------|---------|--------------------
772 * 1 | DC | 1 | DC | E1000_fc_full
775 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
776 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
778 * Now we need to check if the user selected RX ONLY
779 * of pause frames. In this case, we had to advertise
780 * FULL flow control because we could not advertise RX
781 * ONLY. Hence, we must now check to see if we need to
782 * turn OFF the TRANSMISSION of PAUSE frames.
784 if (hw->fc.original_type == e1000_fc_full) {
785 hw->fc.type = e1000_fc_full;
786 hw_dbg("Flow Control = FULL.\r\n");
788 hw->fc.type = e1000_fc_rx_pause;
789 hw_dbg("Flow Control = "
790 "RX PAUSE frames only.\r\n");
794 * For receiving PAUSE frames ONLY.
796 * LOCAL DEVICE | LINK PARTNER
797 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
798 *-------|---------|-------|---------|--------------------
799 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
801 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
802 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
803 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
804 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
805 hw->fc.type = e1000_fc_tx_pause;
806 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
809 * For transmitting PAUSE frames ONLY.
811 * LOCAL DEVICE | LINK PARTNER
812 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
813 *-------|---------|-------|---------|--------------------
814 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
816 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
817 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
818 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
819 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
820 hw->fc.type = e1000_fc_rx_pause;
821 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
824 * Per the IEEE spec, at this point flow control should be
825 * disabled. However, we want to consider that we could
826 * be connected to a legacy switch that doesn't advertise
827 * desired flow control, but can be forced on the link
828 * partner. So if we advertised no flow control, that is
829 * what we will resolve to. If we advertised some kind of
830 * receive capability (Rx Pause Only or Full Flow Control)
831 * and the link partner advertised none, we will configure
832 * ourselves to enable Rx Flow Control only. We can do
833 * this safely for two reasons: If the link partner really
834 * didn't want flow control enabled, and we enable Rx, no
835 * harm done since we won't be receiving any PAUSE frames
836 * anyway. If the intent on the link partner was to have
837 * flow control enabled, then by us enabling RX only, we
838 * can at least receive pause frames and process them.
839 * This is a good idea because in most cases, since we are
840 * predominantly a server NIC, more times than not we will
841 * be asked to delay transmission of packets than asking
842 * our link partner to pause transmission of frames.
844 else if ((hw->fc.original_type == e1000_fc_none ||
845 hw->fc.original_type == e1000_fc_tx_pause) ||
846 hw->fc.strict_ieee) {
847 hw->fc.type = e1000_fc_none;
848 hw_dbg("Flow Control = NONE.\r\n");
850 hw->fc.type = e1000_fc_rx_pause;
851 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
855 * Now we need to do one last check... If we auto-
856 * negotiated to HALF DUPLEX, flow control should not be
857 * enabled per IEEE 802.3 spec.
859 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
861 hw_dbg("Error getting link speed and duplex\n");
865 if (duplex == HALF_DUPLEX)
866 hw->fc.type = e1000_fc_none;
869 * Now we call a subroutine to actually force the MAC
870 * controller to use the correct flow control settings.
872 ret_val = igb_force_mac_fc(hw);
874 hw_dbg("Error forcing flow control settings\n");
884 * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
885 * @hw: pointer to the HW structure
886 * @speed: stores the current speed
887 * @duplex: stores the current duplex
889 * Read the status register for the current speed/duplex and store the current
890 * speed and duplex for copper connections.
892 s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
897 status = rd32(E1000_STATUS);
898 if (status & E1000_STATUS_SPEED_1000) {
900 hw_dbg("1000 Mbs, ");
901 } else if (status & E1000_STATUS_SPEED_100) {
909 if (status & E1000_STATUS_FD) {
910 *duplex = FULL_DUPLEX;
911 hw_dbg("Full Duplex\n");
913 *duplex = HALF_DUPLEX;
914 hw_dbg("Half Duplex\n");
921 * igb_get_hw_semaphore - Acquire hardware semaphore
922 * @hw: pointer to the HW structure
924 * Acquire the HW semaphore to access the PHY or NVM
926 s32 igb_get_hw_semaphore(struct e1000_hw *hw)
930 s32 timeout = hw->nvm.word_size + 1;
933 /* Get the SW semaphore */
934 while (i < timeout) {
935 swsm = rd32(E1000_SWSM);
936 if (!(swsm & E1000_SWSM_SMBI))
944 hw_dbg("Driver can't access device - SMBI bit is set.\n");
945 ret_val = -E1000_ERR_NVM;
949 /* Get the FW semaphore. */
950 for (i = 0; i < timeout; i++) {
951 swsm = rd32(E1000_SWSM);
952 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
954 /* Semaphore acquired if bit latched */
955 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
962 /* Release semaphores */
963 igb_put_hw_semaphore(hw);
964 hw_dbg("Driver can't access the NVM\n");
965 ret_val = -E1000_ERR_NVM;
974 * igb_put_hw_semaphore - Release hardware semaphore
975 * @hw: pointer to the HW structure
977 * Release hardware semaphore used to access the PHY or NVM
979 void igb_put_hw_semaphore(struct e1000_hw *hw)
983 swsm = rd32(E1000_SWSM);
985 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
987 wr32(E1000_SWSM, swsm);
991 * igb_get_auto_rd_done - Check for auto read completion
992 * @hw: pointer to the HW structure
994 * Check EEPROM for Auto Read done bit.
996 s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1002 while (i < AUTO_READ_DONE_TIMEOUT) {
1003 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1009 if (i == AUTO_READ_DONE_TIMEOUT) {
1010 hw_dbg("Auto read by HW from NVM has not completed.\n");
1011 ret_val = -E1000_ERR_RESET;
1020 * igb_valid_led_default - Verify a valid default LED config
1021 * @hw: pointer to the HW structure
1022 * @data: pointer to the NVM (EEPROM)
1024 * Read the EEPROM for the current default LED configuration. If the
1025 * LED configuration is not valid, set to a valid LED configuration.
1027 static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1031 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1033 hw_dbg("NVM Read Error\n");
1037 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
1038 *data = ID_LED_DEFAULT;
1046 * @hw: pointer to the HW structure
1049 s32 igb_id_led_init(struct e1000_hw *hw)
1051 struct e1000_mac_info *mac = &hw->mac;
1053 const u32 ledctl_mask = 0x000000FF;
1054 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1055 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1057 const u16 led_mask = 0x0F;
1059 ret_val = igb_valid_led_default(hw, &data);
1063 mac->ledctl_default = rd32(E1000_LEDCTL);
1064 mac->ledctl_mode1 = mac->ledctl_default;
1065 mac->ledctl_mode2 = mac->ledctl_default;
1067 for (i = 0; i < 4; i++) {
1068 temp = (data >> (i << 2)) & led_mask;
1070 case ID_LED_ON1_DEF2:
1071 case ID_LED_ON1_ON2:
1072 case ID_LED_ON1_OFF2:
1073 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1074 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1076 case ID_LED_OFF1_DEF2:
1077 case ID_LED_OFF1_ON2:
1078 case ID_LED_OFF1_OFF2:
1079 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1080 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1087 case ID_LED_DEF1_ON2:
1088 case ID_LED_ON1_ON2:
1089 case ID_LED_OFF1_ON2:
1090 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1091 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1093 case ID_LED_DEF1_OFF2:
1094 case ID_LED_ON1_OFF2:
1095 case ID_LED_OFF1_OFF2:
1096 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1097 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1110 * igb_cleanup_led - Set LED config to default operation
1111 * @hw: pointer to the HW structure
1113 * Remove the current LED configuration and set the LED configuration
1114 * to the default value, saved from the EEPROM.
1116 s32 igb_cleanup_led(struct e1000_hw *hw)
1118 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1123 * igb_blink_led - Blink LED
1124 * @hw: pointer to the HW structure
1126 * Blink the led's which are set to be on.
1128 s32 igb_blink_led(struct e1000_hw *hw)
1130 u32 ledctl_blink = 0;
1133 if (hw->phy.media_type == e1000_media_type_fiber) {
1134 /* always blink LED0 for PCI-E fiber */
1135 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1136 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1139 * set the blink bit for each LED that's "on" (0x0E)
1142 ledctl_blink = hw->mac.ledctl_mode2;
1143 for (i = 0; i < 4; i++)
1144 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1145 E1000_LEDCTL_MODE_LED_ON)
1146 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1150 wr32(E1000_LEDCTL, ledctl_blink);
1156 * igb_led_off - Turn LED off
1157 * @hw: pointer to the HW structure
1161 s32 igb_led_off(struct e1000_hw *hw)
1165 switch (hw->phy.media_type) {
1166 case e1000_media_type_fiber:
1167 ctrl = rd32(E1000_CTRL);
1168 ctrl |= E1000_CTRL_SWDPIN0;
1169 ctrl |= E1000_CTRL_SWDPIO0;
1170 wr32(E1000_CTRL, ctrl);
1172 case e1000_media_type_copper:
1173 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1183 * igb_disable_pcie_master - Disables PCI-express master access
1184 * @hw: pointer to the HW structure
1186 * Returns 0 (0) if successful, else returns -10
1187 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1188 * the master requests to be disabled.
1190 * Disables PCI-Express master access and verifies there are no pending
1193 s32 igb_disable_pcie_master(struct e1000_hw *hw)
1196 s32 timeout = MASTER_DISABLE_TIMEOUT;
1199 if (hw->bus.type != e1000_bus_type_pci_express)
1202 ctrl = rd32(E1000_CTRL);
1203 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1204 wr32(E1000_CTRL, ctrl);
1207 if (!(rd32(E1000_STATUS) &
1208 E1000_STATUS_GIO_MASTER_ENABLE))
1215 hw_dbg("Master requests are pending.\n");
1216 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1225 * igb_reset_adaptive - Reset Adaptive Interframe Spacing
1226 * @hw: pointer to the HW structure
1228 * Reset the Adaptive Interframe Spacing throttle to default values.
1230 void igb_reset_adaptive(struct e1000_hw *hw)
1232 struct e1000_mac_info *mac = &hw->mac;
1234 if (!mac->adaptive_ifs) {
1235 hw_dbg("Not in Adaptive IFS mode!\n");
1239 if (!mac->ifs_params_forced) {
1240 mac->current_ifs_val = 0;
1241 mac->ifs_min_val = IFS_MIN;
1242 mac->ifs_max_val = IFS_MAX;
1243 mac->ifs_step_size = IFS_STEP;
1244 mac->ifs_ratio = IFS_RATIO;
1247 mac->in_ifs_mode = false;
1254 * igb_update_adaptive - Update Adaptive Interframe Spacing
1255 * @hw: pointer to the HW structure
1257 * Update the Adaptive Interframe Spacing Throttle value based on the
1258 * time between transmitted packets and time between collisions.
1260 void igb_update_adaptive(struct e1000_hw *hw)
1262 struct e1000_mac_info *mac = &hw->mac;
1264 if (!mac->adaptive_ifs) {
1265 hw_dbg("Not in Adaptive IFS mode!\n");
1269 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1270 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
1271 mac->in_ifs_mode = true;
1272 if (mac->current_ifs_val < mac->ifs_max_val) {
1273 if (!mac->current_ifs_val)
1274 mac->current_ifs_val = mac->ifs_min_val;
1276 mac->current_ifs_val +=
1279 mac->current_ifs_val);
1283 if (mac->in_ifs_mode &&
1284 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1285 mac->current_ifs_val = 0;
1286 mac->in_ifs_mode = false;
1295 * igb_validate_mdi_setting - Verify MDI/MDIx settings
1296 * @hw: pointer to the HW structure
1298 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1299 * set, which is forced to MDI mode only.
1301 s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1305 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
1306 hw_dbg("Invalid MDI setting detected\n");
1308 ret_val = -E1000_ERR_CONFIG;
1317 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
1318 * @hw: pointer to the HW structure
1319 * @reg: 32bit register offset such as E1000_SCTL
1320 * @offset: register offset to write to
1321 * @data: data to write at register offset
1323 * Writes an address/data control type register. There are several of these
1324 * and they all have the format address << 8 | data and bit 31 is polled for
1327 s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1328 u32 offset, u8 data)
1330 u32 i, regvalue = 0;
1333 /* Set up the address and data */
1334 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1335 wr32(reg, regvalue);
1337 /* Poll the ready bit to see if the MDI read completed */
1338 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1340 regvalue = rd32(reg);
1341 if (regvalue & E1000_GEN_CTL_READY)
1344 if (!(regvalue & E1000_GEN_CTL_READY)) {
1345 hw_dbg("Reg %08x did not indicate ready\n", reg);
1346 ret_val = -E1000_ERR_PHY;
1355 * igb_enable_mng_pass_thru - Enable processing of ARP's
1356 * @hw: pointer to the HW structure
1358 * Verifies the hardware needs to allow ARPs to be processed by the host.
1360 bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1364 bool ret_val = false;
1366 if (!hw->mac.asf_firmware_present)
1369 manc = rd32(E1000_MANC);
1371 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
1372 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
1375 if (hw->mac.arc_subsystem_valid) {
1376 fwsm = rd32(E1000_FWSM);
1377 factps = rd32(E1000_FACTPS);
1379 if (!(factps & E1000_FACTPS_MNGCG) &&
1380 ((fwsm & E1000_FWSM_MODE_MASK) ==
1381 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1386 if ((manc & E1000_MANC_SMBUS_EN) &&
1387 !(manc & E1000_MANC_ASF_EN)) {