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);
41 * igb_get_bus_info_pcie - Get PCIe bus information
42 * @hw: pointer to the HW structure
44 * Determines and stores the system bus information for a particular
45 * network interface. The following bus information is determined and stored:
46 * bus speed, bus width, type (PCIe), and PCIe function.
48 s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
50 struct e1000_bus_info *bus = &hw->bus;
55 bus->type = e1000_bus_type_pci_express;
56 bus->speed = e1000_bus_speed_2500;
58 ret_val = igb_read_pcie_cap_reg(hw,
62 bus->width = e1000_bus_width_unknown;
64 bus->width = (enum e1000_bus_width)((pcie_link_status &
65 PCIE_LINK_WIDTH_MASK) >>
66 PCIE_LINK_WIDTH_SHIFT);
68 reg = rd32(E1000_STATUS);
69 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
75 * igb_clear_vfta - Clear VLAN filter table
76 * @hw: pointer to the HW structure
78 * Clears the register array which contains the VLAN filter table by
79 * setting all the values to 0.
81 void igb_clear_vfta(struct e1000_hw *hw)
85 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
86 array_wr32(E1000_VFTA, offset, 0);
92 * igb_write_vfta - Write value to VLAN filter table
93 * @hw: pointer to the HW structure
94 * @offset: register offset in VLAN filter table
95 * @value: register value written to VLAN filter table
97 * Writes value at the given offset in the register array which stores
98 * the VLAN filter table.
100 static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
102 array_wr32(E1000_VFTA, offset, value);
107 * igb_init_rx_addrs - Initialize receive address's
108 * @hw: pointer to the HW structure
109 * @rar_count: receive address registers
111 * Setups the receive address registers by setting the base receive address
112 * register to the devices MAC address and clearing all the other receive
113 * address registers to 0.
115 void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
118 u8 mac_addr[ETH_ALEN] = {0};
120 /* Setup the receive address */
121 hw_dbg("Programming MAC Address into RAR[0]\n");
123 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
125 /* Zero out the other (rar_entry_count - 1) receive addresses */
126 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
127 for (i = 1; i < rar_count; i++)
128 hw->mac.ops.rar_set(hw, mac_addr, i);
132 * igb_vfta_set - enable or disable vlan in VLAN filter table
133 * @hw: pointer to the HW structure
134 * @vid: VLAN id to add or remove
135 * @add: if true add filter, if false remove
137 * Sets or clears a bit in the VLAN filter table array based on VLAN id
138 * and if we are adding or removing the filter
140 s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add)
142 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
143 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
144 u32 vfta = array_rd32(E1000_VFTA, index);
147 /* bit was set/cleared before we started */
148 if ((!!(vfta & mask)) == add) {
149 ret_val = -E1000_ERR_CONFIG;
157 igb_write_vfta(hw, index, vfta);
163 * igb_check_alt_mac_addr - Check for alternate MAC addr
164 * @hw: pointer to the HW structure
166 * Checks the nvm for an alternate MAC address. An alternate MAC address
167 * can be setup by pre-boot software and must be treated like a permanent
168 * address and must override the actual permanent MAC address. If an
169 * alternate MAC address is fopund it is saved in the hw struct and
170 * prgrammed into RAR0 and the cuntion returns success, otherwise the
171 * fucntion returns an error.
173 s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
177 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
178 u8 alt_mac_addr[ETH_ALEN];
180 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
181 &nvm_alt_mac_addr_offset);
183 hw_dbg("NVM Read Error\n");
187 if (nvm_alt_mac_addr_offset == 0xFFFF) {
188 /* There is no Alternate MAC Address */
192 if (hw->bus.func == E1000_FUNC_1)
193 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
194 for (i = 0; i < ETH_ALEN; i += 2) {
195 offset = nvm_alt_mac_addr_offset + (i >> 1);
196 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
198 hw_dbg("NVM Read Error\n");
202 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
203 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
206 /* if multicast bit is set, the alternate address will not be used */
207 if (alt_mac_addr[0] & 0x01) {
208 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
213 * We have a valid alternate MAC address, and we want to treat it the
214 * same as the normal permanent MAC address stored by the HW into the
215 * RAR. Do this by mapping this address into RAR0.
217 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
224 * igb_rar_set - Set receive address register
225 * @hw: pointer to the HW structure
226 * @addr: pointer to the receive address
227 * @index: receive address array register
229 * Sets the receive address array register at index to the address passed
232 void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
234 u32 rar_low, rar_high;
237 * HW expects these in little endian so we reverse the byte order
238 * from network order (big endian) to little endian
240 rar_low = ((u32) addr[0] |
241 ((u32) addr[1] << 8) |
242 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
244 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
246 /* If MAC address zero, no need to set the AV bit */
247 if (rar_low || rar_high)
248 rar_high |= E1000_RAH_AV;
250 wr32(E1000_RAL(index), rar_low);
251 wr32(E1000_RAH(index), rar_high);
255 * igb_mta_set - Set multicast filter table address
256 * @hw: pointer to the HW structure
257 * @hash_value: determines the MTA register and bit to set
259 * The multicast table address is a register array of 32-bit registers.
260 * The hash_value is used to determine what register the bit is in, the
261 * current value is read, the new bit is OR'd in and the new value is
262 * written back into the register.
264 void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
266 u32 hash_bit, hash_reg, mta;
269 * The MTA is a register array of 32-bit registers. It is
270 * treated like an array of (32*mta_reg_count) bits. We want to
271 * set bit BitArray[hash_value]. So we figure out what register
272 * the bit is in, read it, OR in the new bit, then write
273 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
274 * mask to bits 31:5 of the hash value which gives us the
275 * register we're modifying. The hash bit within that register
276 * is determined by the lower 5 bits of the hash value.
278 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
279 hash_bit = hash_value & 0x1F;
281 mta = array_rd32(E1000_MTA, hash_reg);
283 mta |= (1 << hash_bit);
285 array_wr32(E1000_MTA, hash_reg, mta);
290 * igb_hash_mc_addr - Generate a multicast hash value
291 * @hw: pointer to the HW structure
292 * @mc_addr: pointer to a multicast address
294 * Generates a multicast address hash value which is used to determine
295 * the multicast filter table array address and new table value. See
298 static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
300 u32 hash_value, hash_mask;
303 /* Register count multiplied by bits per register */
304 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
307 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
308 * where 0xFF would still fall within the hash mask.
310 while (hash_mask >> bit_shift != 0xFF)
314 * The portion of the address that is used for the hash table
315 * is determined by the mc_filter_type setting.
316 * The algorithm is such that there is a total of 8 bits of shifting.
317 * The bit_shift for a mc_filter_type of 0 represents the number of
318 * left-shifts where the MSB of mc_addr[5] would still fall within
319 * the hash_mask. Case 0 does this exactly. Since there are a total
320 * of 8 bits of shifting, then mc_addr[4] will shift right the
321 * remaining number of bits. Thus 8 - bit_shift. The rest of the
322 * cases are a variation of this algorithm...essentially raising the
323 * number of bits to shift mc_addr[5] left, while still keeping the
324 * 8-bit shifting total.
326 * For example, given the following Destination MAC Address and an
327 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
328 * we can see that the bit_shift for case 0 is 4. These are the hash
329 * values resulting from each mc_filter_type...
330 * [0] [1] [2] [3] [4] [5]
334 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
335 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
336 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
337 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
339 switch (hw->mac.mc_filter_type) {
354 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
355 (((u16) mc_addr[5]) << bit_shift)));
361 * igb_update_mc_addr_list - Update Multicast addresses
362 * @hw: pointer to the HW structure
363 * @mc_addr_list: array of multicast addresses to program
364 * @mc_addr_count: number of multicast addresses to program
366 * Updates entire Multicast Table Array.
367 * The caller must have a packed mc_addr_list of multicast addresses.
369 void igb_update_mc_addr_list(struct e1000_hw *hw,
370 u8 *mc_addr_list, u32 mc_addr_count)
372 u32 hash_value, hash_bit, hash_reg;
375 /* clear mta_shadow */
376 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
378 /* update mta_shadow from mc_addr_list */
379 for (i = 0; (u32) i < mc_addr_count; i++) {
380 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
382 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
383 hash_bit = hash_value & 0x1F;
385 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
386 mc_addr_list += (ETH_ALEN);
389 /* replace the entire MTA table */
390 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
391 array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
396 * igb_clear_hw_cntrs_base - Clear base hardware counters
397 * @hw: pointer to the HW structure
399 * Clears the base hardware counters by reading the counter registers.
401 void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
443 * igb_check_for_copper_link - Check for link (Copper)
444 * @hw: pointer to the HW structure
446 * Checks to see of the link status of the hardware has changed. If a
447 * change in link status has been detected, then we read the PHY registers
448 * to get the current speed/duplex if link exists.
450 s32 igb_check_for_copper_link(struct e1000_hw *hw)
452 struct e1000_mac_info *mac = &hw->mac;
457 * We only want to go out to the PHY registers to see if Auto-Neg
458 * has completed and/or if our link status has changed. The
459 * get_link_status flag is set upon receiving a Link Status
460 * Change or Rx Sequence Error interrupt.
462 if (!mac->get_link_status) {
468 * First we want to see if the MII Status Register reports
469 * link. If so, then we want to get the current speed/duplex
472 ret_val = igb_phy_has_link(hw, 1, 0, &link);
477 goto out; /* No link detected */
479 mac->get_link_status = false;
482 * Check if there was DownShift, must be checked
483 * immediately after link-up
485 igb_check_downshift(hw);
488 * If we are forcing speed/duplex, then we simply return since
489 * we have already determined whether we have link or not.
492 ret_val = -E1000_ERR_CONFIG;
497 * Auto-Neg is enabled. Auto Speed Detection takes care
498 * of MAC speed/duplex configuration. So we only need to
499 * configure Collision Distance in the MAC.
501 igb_config_collision_dist(hw);
504 * Configure Flow Control now that Auto-Neg has completed.
505 * First, we need to restore the desired flow control
506 * settings because we may have had to re-autoneg with a
507 * different link partner.
509 ret_val = igb_config_fc_after_link_up(hw);
511 hw_dbg("Error configuring flow control\n");
518 * igb_setup_link - Setup flow control and link settings
519 * @hw: pointer to the HW structure
521 * Determines which flow control settings to use, then configures flow
522 * control. Calls the appropriate media-specific link configuration
523 * function. Assuming the adapter has a valid link partner, a valid link
524 * should be established. Assumes the hardware has previously been reset
525 * and the transmitter and receiver are not enabled.
527 s32 igb_setup_link(struct e1000_hw *hw)
532 * In the case of the phy reset being blocked, we already have a link.
533 * We do not need to set it up again.
535 if (igb_check_reset_block(hw))
539 * If requested flow control is set to default, set flow control
540 * based on the EEPROM flow control settings.
542 if (hw->fc.requested_mode == e1000_fc_default) {
543 ret_val = igb_set_default_fc(hw);
549 * We want to save off the original Flow Control configuration just
550 * in case we get disconnected and then reconnected into a different
551 * hub or switch with different Flow Control capabilities.
553 hw->fc.current_mode = hw->fc.requested_mode;
555 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
557 /* Call the necessary media_type subroutine to configure the link. */
558 ret_val = hw->mac.ops.setup_physical_interface(hw);
563 * Initialize the flow control address, type, and PAUSE timer
564 * registers to their default values. This is done even if flow
565 * control is disabled, because it does not hurt anything to
566 * initialize these registers.
568 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
569 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
570 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
571 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
573 wr32(E1000_FCTTV, hw->fc.pause_time);
575 ret_val = igb_set_fc_watermarks(hw);
582 * igb_config_collision_dist - Configure collision distance
583 * @hw: pointer to the HW structure
585 * Configures the collision distance to the default value and is used
586 * during link setup. Currently no func pointer exists and all
587 * implementations are handled in the generic version of this function.
589 void igb_config_collision_dist(struct e1000_hw *hw)
593 tctl = rd32(E1000_TCTL);
595 tctl &= ~E1000_TCTL_COLD;
596 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
598 wr32(E1000_TCTL, tctl);
603 * igb_set_fc_watermarks - Set flow control high/low watermarks
604 * @hw: pointer to the HW structure
606 * Sets the flow control high/low threshold (watermark) registers. If
607 * flow control XON frame transmission is enabled, then set XON frame
608 * tansmission as well.
610 static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
613 u32 fcrtl = 0, fcrth = 0;
616 * Set the flow control receive threshold registers. Normally,
617 * these registers will be set to a default threshold that may be
618 * adjusted later by the driver's runtime code. However, if the
619 * ability to transmit pause frames is not enabled, then these
620 * registers will be set to 0.
622 if (hw->fc.current_mode & e1000_fc_tx_pause) {
624 * We need to set up the Receive Threshold high and low water
625 * marks as well as (optionally) enabling the transmission of
628 fcrtl = hw->fc.low_water;
630 fcrtl |= E1000_FCRTL_XONE;
632 fcrth = hw->fc.high_water;
634 wr32(E1000_FCRTL, fcrtl);
635 wr32(E1000_FCRTH, fcrth);
641 * igb_set_default_fc - Set flow control default values
642 * @hw: pointer to the HW structure
644 * Read the EEPROM for the default values for flow control and store the
647 static s32 igb_set_default_fc(struct e1000_hw *hw)
653 * Read and store word 0x0F of the EEPROM. This word contains bits
654 * that determine the hardware's default PAUSE (flow control) mode,
655 * a bit that determines whether the HW defaults to enabling or
656 * disabling auto-negotiation, and the direction of the
657 * SW defined pins. If there is no SW over-ride of the flow
658 * control setting, then the variable hw->fc will
659 * be initialized based on a value in the EEPROM.
661 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
664 hw_dbg("NVM Read Error\n");
668 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
669 hw->fc.requested_mode = e1000_fc_none;
670 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
672 hw->fc.requested_mode = e1000_fc_tx_pause;
674 hw->fc.requested_mode = e1000_fc_full;
681 * igb_force_mac_fc - Force the MAC's flow control settings
682 * @hw: pointer to the HW structure
684 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
685 * device control register to reflect the adapter settings. TFCE and RFCE
686 * need to be explicitly set by software when a copper PHY is used because
687 * autonegotiation is managed by the PHY rather than the MAC. Software must
688 * also configure these bits when link is forced on a fiber connection.
690 s32 igb_force_mac_fc(struct e1000_hw *hw)
695 ctrl = rd32(E1000_CTRL);
698 * Because we didn't get link via the internal auto-negotiation
699 * mechanism (we either forced link or we got link via PHY
700 * auto-neg), we have to manually enable/disable transmit an
701 * receive flow control.
703 * The "Case" statement below enables/disable flow control
704 * according to the "hw->fc.current_mode" parameter.
706 * The possible values of the "fc" parameter are:
707 * 0: Flow control is completely disabled
708 * 1: Rx flow control is enabled (we can receive pause
709 * frames but not send pause frames).
710 * 2: Tx flow control is enabled (we can send pause frames
711 * frames but we do not receive pause frames).
712 * 3: Both Rx and TX flow control (symmetric) is enabled.
713 * other: No other values should be possible at this point.
715 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
717 switch (hw->fc.current_mode) {
719 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
721 case e1000_fc_rx_pause:
722 ctrl &= (~E1000_CTRL_TFCE);
723 ctrl |= E1000_CTRL_RFCE;
725 case e1000_fc_tx_pause:
726 ctrl &= (~E1000_CTRL_RFCE);
727 ctrl |= E1000_CTRL_TFCE;
730 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
733 hw_dbg("Flow control param set incorrectly\n");
734 ret_val = -E1000_ERR_CONFIG;
738 wr32(E1000_CTRL, ctrl);
745 * igb_config_fc_after_link_up - Configures flow control after link
746 * @hw: pointer to the HW structure
748 * Checks the status of auto-negotiation after link up to ensure that the
749 * speed and duplex were not forced. If the link needed to be forced, then
750 * flow control needs to be forced also. If auto-negotiation is enabled
751 * and did not fail, then we configure flow control based on our link
754 s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
756 struct e1000_mac_info *mac = &hw->mac;
758 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
762 * Check for the case where we have fiber media and auto-neg failed
763 * so we had to force link. In this case, we need to force the
764 * configuration of the MAC to match the "fc" parameter.
766 if (mac->autoneg_failed) {
767 if (hw->phy.media_type == e1000_media_type_internal_serdes)
768 ret_val = igb_force_mac_fc(hw);
770 if (hw->phy.media_type == e1000_media_type_copper)
771 ret_val = igb_force_mac_fc(hw);
775 hw_dbg("Error forcing flow control settings\n");
780 * Check for the case where we have copper media and auto-neg is
781 * enabled. In this case, we need to check and see if Auto-Neg
782 * has completed, and if so, how the PHY and link partner has
783 * flow control configured.
785 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
787 * Read the MII Status Register and check to see if AutoNeg
788 * has completed. We read this twice because this reg has
789 * some "sticky" (latched) bits.
791 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
795 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
800 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
801 hw_dbg("Copper PHY and Auto Neg "
802 "has not completed.\n");
807 * The AutoNeg process has completed, so we now need to
808 * read both the Auto Negotiation Advertisement
809 * Register (Address 4) and the Auto_Negotiation Base
810 * Page Ability Register (Address 5) to determine how
811 * flow control was negotiated.
813 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
817 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
818 &mii_nway_lp_ability_reg);
823 * Two bits in the Auto Negotiation Advertisement Register
824 * (Address 4) and two bits in the Auto Negotiation Base
825 * Page Ability Register (Address 5) determine flow control
826 * for both the PHY and the link partner. The following
827 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
828 * 1999, describes these PAUSE resolution bits and how flow
829 * control is determined based upon these settings.
830 * NOTE: DC = Don't Care
832 * LOCAL DEVICE | LINK PARTNER
833 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
834 *-------|---------|-------|---------|--------------------
835 * 0 | 0 | DC | DC | e1000_fc_none
836 * 0 | 1 | 0 | DC | e1000_fc_none
837 * 0 | 1 | 1 | 0 | e1000_fc_none
838 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
839 * 1 | 0 | 0 | DC | e1000_fc_none
840 * 1 | DC | 1 | DC | e1000_fc_full
841 * 1 | 1 | 0 | 0 | e1000_fc_none
842 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
844 * Are both PAUSE bits set to 1? If so, this implies
845 * Symmetric Flow Control is enabled at both ends. The
846 * ASM_DIR bits are irrelevant per the spec.
848 * For Symmetric Flow Control:
850 * LOCAL DEVICE | LINK PARTNER
851 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
852 *-------|---------|-------|---------|--------------------
853 * 1 | DC | 1 | DC | E1000_fc_full
856 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
857 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
859 * Now we need to check if the user selected RX ONLY
860 * of pause frames. In this case, we had to advertise
861 * FULL flow control because we could not advertise RX
862 * ONLY. Hence, we must now check to see if we need to
863 * turn OFF the TRANSMISSION of PAUSE frames.
865 if (hw->fc.requested_mode == e1000_fc_full) {
866 hw->fc.current_mode = e1000_fc_full;
867 hw_dbg("Flow Control = FULL.\r\n");
869 hw->fc.current_mode = e1000_fc_rx_pause;
870 hw_dbg("Flow Control = "
871 "RX PAUSE frames only.\r\n");
875 * For receiving PAUSE frames ONLY.
877 * LOCAL DEVICE | LINK PARTNER
878 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
879 *-------|---------|-------|---------|--------------------
880 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
882 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
883 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
884 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
885 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
886 hw->fc.current_mode = e1000_fc_tx_pause;
887 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
890 * For transmitting PAUSE frames ONLY.
892 * LOCAL DEVICE | LINK PARTNER
893 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
894 *-------|---------|-------|---------|--------------------
895 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
897 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
898 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
899 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
900 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
901 hw->fc.current_mode = e1000_fc_rx_pause;
902 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
905 * Per the IEEE spec, at this point flow control should be
906 * disabled. However, we want to consider that we could
907 * be connected to a legacy switch that doesn't advertise
908 * desired flow control, but can be forced on the link
909 * partner. So if we advertised no flow control, that is
910 * what we will resolve to. If we advertised some kind of
911 * receive capability (Rx Pause Only or Full Flow Control)
912 * and the link partner advertised none, we will configure
913 * ourselves to enable Rx Flow Control only. We can do
914 * this safely for two reasons: If the link partner really
915 * didn't want flow control enabled, and we enable Rx, no
916 * harm done since we won't be receiving any PAUSE frames
917 * anyway. If the intent on the link partner was to have
918 * flow control enabled, then by us enabling RX only, we
919 * can at least receive pause frames and process them.
920 * This is a good idea because in most cases, since we are
921 * predominantly a server NIC, more times than not we will
922 * be asked to delay transmission of packets than asking
923 * our link partner to pause transmission of frames.
925 else if ((hw->fc.requested_mode == e1000_fc_none ||
926 hw->fc.requested_mode == e1000_fc_tx_pause) ||
927 hw->fc.strict_ieee) {
928 hw->fc.current_mode = e1000_fc_none;
929 hw_dbg("Flow Control = NONE.\r\n");
931 hw->fc.current_mode = e1000_fc_rx_pause;
932 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
936 * Now we need to do one last check... If we auto-
937 * negotiated to HALF DUPLEX, flow control should not be
938 * enabled per IEEE 802.3 spec.
940 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
942 hw_dbg("Error getting link speed and duplex\n");
946 if (duplex == HALF_DUPLEX)
947 hw->fc.current_mode = e1000_fc_none;
950 * Now we call a subroutine to actually force the MAC
951 * controller to use the correct flow control settings.
953 ret_val = igb_force_mac_fc(hw);
955 hw_dbg("Error forcing flow control settings\n");
965 * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
966 * @hw: pointer to the HW structure
967 * @speed: stores the current speed
968 * @duplex: stores the current duplex
970 * Read the status register for the current speed/duplex and store the current
971 * speed and duplex for copper connections.
973 s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
978 status = rd32(E1000_STATUS);
979 if (status & E1000_STATUS_SPEED_1000) {
981 hw_dbg("1000 Mbs, ");
982 } else if (status & E1000_STATUS_SPEED_100) {
990 if (status & E1000_STATUS_FD) {
991 *duplex = FULL_DUPLEX;
992 hw_dbg("Full Duplex\n");
994 *duplex = HALF_DUPLEX;
995 hw_dbg("Half Duplex\n");
1002 * igb_get_hw_semaphore - Acquire hardware semaphore
1003 * @hw: pointer to the HW structure
1005 * Acquire the HW semaphore to access the PHY or NVM
1007 s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1011 s32 timeout = hw->nvm.word_size + 1;
1014 /* Get the SW semaphore */
1015 while (i < timeout) {
1016 swsm = rd32(E1000_SWSM);
1017 if (!(swsm & E1000_SWSM_SMBI))
1025 hw_dbg("Driver can't access device - SMBI bit is set.\n");
1026 ret_val = -E1000_ERR_NVM;
1030 /* Get the FW semaphore. */
1031 for (i = 0; i < timeout; i++) {
1032 swsm = rd32(E1000_SWSM);
1033 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1035 /* Semaphore acquired if bit latched */
1036 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1043 /* Release semaphores */
1044 igb_put_hw_semaphore(hw);
1045 hw_dbg("Driver can't access the NVM\n");
1046 ret_val = -E1000_ERR_NVM;
1055 * igb_put_hw_semaphore - Release hardware semaphore
1056 * @hw: pointer to the HW structure
1058 * Release hardware semaphore used to access the PHY or NVM
1060 void igb_put_hw_semaphore(struct e1000_hw *hw)
1064 swsm = rd32(E1000_SWSM);
1066 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1068 wr32(E1000_SWSM, swsm);
1072 * igb_get_auto_rd_done - Check for auto read completion
1073 * @hw: pointer to the HW structure
1075 * Check EEPROM for Auto Read done bit.
1077 s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1083 while (i < AUTO_READ_DONE_TIMEOUT) {
1084 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1090 if (i == AUTO_READ_DONE_TIMEOUT) {
1091 hw_dbg("Auto read by HW from NVM has not completed.\n");
1092 ret_val = -E1000_ERR_RESET;
1101 * igb_valid_led_default - Verify a valid default LED config
1102 * @hw: pointer to the HW structure
1103 * @data: pointer to the NVM (EEPROM)
1105 * Read the EEPROM for the current default LED configuration. If the
1106 * LED configuration is not valid, set to a valid LED configuration.
1108 static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1112 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
1114 hw_dbg("NVM Read Error\n");
1118 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1119 switch(hw->phy.media_type) {
1120 case e1000_media_type_internal_serdes:
1121 *data = ID_LED_DEFAULT_82575_SERDES;
1123 case e1000_media_type_copper:
1125 *data = ID_LED_DEFAULT;
1135 * @hw: pointer to the HW structure
1138 s32 igb_id_led_init(struct e1000_hw *hw)
1140 struct e1000_mac_info *mac = &hw->mac;
1142 const u32 ledctl_mask = 0x000000FF;
1143 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1144 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1146 const u16 led_mask = 0x0F;
1148 ret_val = igb_valid_led_default(hw, &data);
1152 mac->ledctl_default = rd32(E1000_LEDCTL);
1153 mac->ledctl_mode1 = mac->ledctl_default;
1154 mac->ledctl_mode2 = mac->ledctl_default;
1156 for (i = 0; i < 4; i++) {
1157 temp = (data >> (i << 2)) & led_mask;
1159 case ID_LED_ON1_DEF2:
1160 case ID_LED_ON1_ON2:
1161 case ID_LED_ON1_OFF2:
1162 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1163 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1165 case ID_LED_OFF1_DEF2:
1166 case ID_LED_OFF1_ON2:
1167 case ID_LED_OFF1_OFF2:
1168 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1169 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1176 case ID_LED_DEF1_ON2:
1177 case ID_LED_ON1_ON2:
1178 case ID_LED_OFF1_ON2:
1179 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1180 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1182 case ID_LED_DEF1_OFF2:
1183 case ID_LED_ON1_OFF2:
1184 case ID_LED_OFF1_OFF2:
1185 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1186 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1199 * igb_cleanup_led - Set LED config to default operation
1200 * @hw: pointer to the HW structure
1202 * Remove the current LED configuration and set the LED configuration
1203 * to the default value, saved from the EEPROM.
1205 s32 igb_cleanup_led(struct e1000_hw *hw)
1207 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1212 * igb_blink_led - Blink LED
1213 * @hw: pointer to the HW structure
1215 * Blink the led's which are set to be on.
1217 s32 igb_blink_led(struct e1000_hw *hw)
1219 u32 ledctl_blink = 0;
1223 * set the blink bit for each LED that's "on" (0x0E)
1226 ledctl_blink = hw->mac.ledctl_mode2;
1227 for (i = 0; i < 4; i++)
1228 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1229 E1000_LEDCTL_MODE_LED_ON)
1230 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1233 wr32(E1000_LEDCTL, ledctl_blink);
1239 * igb_led_off - Turn LED off
1240 * @hw: pointer to the HW structure
1244 s32 igb_led_off(struct e1000_hw *hw)
1246 switch (hw->phy.media_type) {
1247 case e1000_media_type_copper:
1248 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1258 * igb_disable_pcie_master - Disables PCI-express master access
1259 * @hw: pointer to the HW structure
1261 * Returns 0 (0) if successful, else returns -10
1262 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1263 * the master requests to be disabled.
1265 * Disables PCI-Express master access and verifies there are no pending
1268 s32 igb_disable_pcie_master(struct e1000_hw *hw)
1271 s32 timeout = MASTER_DISABLE_TIMEOUT;
1274 if (hw->bus.type != e1000_bus_type_pci_express)
1277 ctrl = rd32(E1000_CTRL);
1278 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1279 wr32(E1000_CTRL, ctrl);
1282 if (!(rd32(E1000_STATUS) &
1283 E1000_STATUS_GIO_MASTER_ENABLE))
1290 hw_dbg("Master requests are pending.\n");
1291 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1300 * igb_reset_adaptive - Reset Adaptive Interframe Spacing
1301 * @hw: pointer to the HW structure
1303 * Reset the Adaptive Interframe Spacing throttle to default values.
1305 void igb_reset_adaptive(struct e1000_hw *hw)
1307 struct e1000_mac_info *mac = &hw->mac;
1309 if (!mac->adaptive_ifs) {
1310 hw_dbg("Not in Adaptive IFS mode!\n");
1314 if (!mac->ifs_params_forced) {
1315 mac->current_ifs_val = 0;
1316 mac->ifs_min_val = IFS_MIN;
1317 mac->ifs_max_val = IFS_MAX;
1318 mac->ifs_step_size = IFS_STEP;
1319 mac->ifs_ratio = IFS_RATIO;
1322 mac->in_ifs_mode = false;
1329 * igb_update_adaptive - Update Adaptive Interframe Spacing
1330 * @hw: pointer to the HW structure
1332 * Update the Adaptive Interframe Spacing Throttle value based on the
1333 * time between transmitted packets and time between collisions.
1335 void igb_update_adaptive(struct e1000_hw *hw)
1337 struct e1000_mac_info *mac = &hw->mac;
1339 if (!mac->adaptive_ifs) {
1340 hw_dbg("Not in Adaptive IFS mode!\n");
1344 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1345 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
1346 mac->in_ifs_mode = true;
1347 if (mac->current_ifs_val < mac->ifs_max_val) {
1348 if (!mac->current_ifs_val)
1349 mac->current_ifs_val = mac->ifs_min_val;
1351 mac->current_ifs_val +=
1354 mac->current_ifs_val);
1358 if (mac->in_ifs_mode &&
1359 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1360 mac->current_ifs_val = 0;
1361 mac->in_ifs_mode = false;
1370 * igb_validate_mdi_setting - Verify MDI/MDIx settings
1371 * @hw: pointer to the HW structure
1373 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1374 * set, which is forced to MDI mode only.
1376 s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1380 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
1381 hw_dbg("Invalid MDI setting detected\n");
1383 ret_val = -E1000_ERR_CONFIG;
1392 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
1393 * @hw: pointer to the HW structure
1394 * @reg: 32bit register offset such as E1000_SCTL
1395 * @offset: register offset to write to
1396 * @data: data to write at register offset
1398 * Writes an address/data control type register. There are several of these
1399 * and they all have the format address << 8 | data and bit 31 is polled for
1402 s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1403 u32 offset, u8 data)
1405 u32 i, regvalue = 0;
1408 /* Set up the address and data */
1409 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1410 wr32(reg, regvalue);
1412 /* Poll the ready bit to see if the MDI read completed */
1413 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1415 regvalue = rd32(reg);
1416 if (regvalue & E1000_GEN_CTL_READY)
1419 if (!(regvalue & E1000_GEN_CTL_READY)) {
1420 hw_dbg("Reg %08x did not indicate ready\n", reg);
1421 ret_val = -E1000_ERR_PHY;
1430 * igb_enable_mng_pass_thru - Enable processing of ARP's
1431 * @hw: pointer to the HW structure
1433 * Verifies the hardware needs to allow ARPs to be processed by the host.
1435 bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1439 bool ret_val = false;
1441 if (!hw->mac.asf_firmware_present)
1444 manc = rd32(E1000_MANC);
1446 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
1447 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
1450 if (hw->mac.arc_subsystem_valid) {
1451 fwsm = rd32(E1000_FWSM);
1452 factps = rd32(E1000_FACTPS);
1454 if (!(factps & E1000_FACTPS_MNGCG) &&
1455 ((fwsm & E1000_FWSM_MODE_MASK) ==
1456 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1461 if ((manc & E1000_MANC_SMBUS_EN) &&
1462 !(manc & E1000_MANC_ASF_EN)) {