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
;
57 ret_val
= igb_read_pcie_cap_reg(hw
,
61 bus
->width
= e1000_bus_width_unknown
;
62 bus
->speed
= e1000_bus_speed_unknown
;
64 switch (pcie_link_status
& PCI_EXP_LNKSTA_CLS
) {
65 case PCI_EXP_LNKSTA_CLS_2_5GB
:
66 bus
->speed
= e1000_bus_speed_2500
;
68 case PCI_EXP_LNKSTA_CLS_5_0GB
:
69 bus
->speed
= e1000_bus_speed_5000
;
72 bus
->speed
= e1000_bus_speed_unknown
;
76 bus
->width
= (enum e1000_bus_width
)((pcie_link_status
&
77 PCI_EXP_LNKSTA_NLW
) >>
78 PCI_EXP_LNKSTA_NLW_SHIFT
);
81 reg
= rd32(E1000_STATUS
);
82 bus
->func
= (reg
& E1000_STATUS_FUNC_MASK
) >> E1000_STATUS_FUNC_SHIFT
;
88 * igb_clear_vfta - Clear VLAN filter table
89 * @hw: pointer to the HW structure
91 * Clears the register array which contains the VLAN filter table by
92 * setting all the values to 0.
94 void igb_clear_vfta(struct e1000_hw
*hw
)
98 for (offset
= 0; offset
< E1000_VLAN_FILTER_TBL_SIZE
; offset
++) {
99 array_wr32(E1000_VFTA
, offset
, 0);
105 * igb_write_vfta - Write value to VLAN filter table
106 * @hw: pointer to the HW structure
107 * @offset: register offset in VLAN filter table
108 * @value: register value written to VLAN filter table
110 * Writes value at the given offset in the register array which stores
111 * the VLAN filter table.
113 static void igb_write_vfta(struct e1000_hw
*hw
, u32 offset
, u32 value
)
115 array_wr32(E1000_VFTA
, offset
, value
);
120 * igb_init_rx_addrs - Initialize receive address's
121 * @hw: pointer to the HW structure
122 * @rar_count: receive address registers
124 * Setups the receive address registers by setting the base receive address
125 * register to the devices MAC address and clearing all the other receive
126 * address registers to 0.
128 void igb_init_rx_addrs(struct e1000_hw
*hw
, u16 rar_count
)
131 u8 mac_addr
[ETH_ALEN
] = {0};
133 /* Setup the receive address */
134 hw_dbg("Programming MAC Address into RAR[0]\n");
136 hw
->mac
.ops
.rar_set(hw
, hw
->mac
.addr
, 0);
138 /* Zero out the other (rar_entry_count - 1) receive addresses */
139 hw_dbg("Clearing RAR[1-%u]\n", rar_count
-1);
140 for (i
= 1; i
< rar_count
; i
++)
141 hw
->mac
.ops
.rar_set(hw
, mac_addr
, i
);
145 * igb_vfta_set - enable or disable vlan in VLAN filter table
146 * @hw: pointer to the HW structure
147 * @vid: VLAN id to add or remove
148 * @add: if true add filter, if false remove
150 * Sets or clears a bit in the VLAN filter table array based on VLAN id
151 * and if we are adding or removing the filter
153 s32
igb_vfta_set(struct e1000_hw
*hw
, u32 vid
, bool add
)
155 u32 index
= (vid
>> E1000_VFTA_ENTRY_SHIFT
) & E1000_VFTA_ENTRY_MASK
;
156 u32 mask
= 1 << (vid
& E1000_VFTA_ENTRY_BIT_SHIFT_MASK
);
157 u32 vfta
= array_rd32(E1000_VFTA
, index
);
160 /* bit was set/cleared before we started */
161 if ((!!(vfta
& mask
)) == add
) {
162 ret_val
= -E1000_ERR_CONFIG
;
170 igb_write_vfta(hw
, index
, vfta
);
176 * igb_check_alt_mac_addr - Check for alternate MAC addr
177 * @hw: pointer to the HW structure
179 * Checks the nvm for an alternate MAC address. An alternate MAC address
180 * can be setup by pre-boot software and must be treated like a permanent
181 * address and must override the actual permanent MAC address. If an
182 * alternate MAC address is fopund it is saved in the hw struct and
183 * prgrammed into RAR0 and the cuntion returns success, otherwise the
184 * function returns an error.
186 s32
igb_check_alt_mac_addr(struct e1000_hw
*hw
)
190 u16 offset
, nvm_alt_mac_addr_offset
, nvm_data
;
191 u8 alt_mac_addr
[ETH_ALEN
];
193 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_ALT_MAC_ADDR_PTR
, 1,
194 &nvm_alt_mac_addr_offset
);
196 hw_dbg("NVM Read Error\n");
200 if (nvm_alt_mac_addr_offset
== 0xFFFF) {
201 /* There is no Alternate MAC Address */
205 if (hw
->bus
.func
== E1000_FUNC_1
)
206 nvm_alt_mac_addr_offset
+= E1000_ALT_MAC_ADDRESS_OFFSET_LAN1
;
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(hw
, offset
, 1, &nvm_data
);
211 hw_dbg("NVM Read Error\n");
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 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
226 * We have a valid alternate MAC address, and we want to treat it the
227 * same as the normal permanent MAC address stored by the HW into the
228 * RAR. Do this by mapping this address into RAR0.
230 hw
->mac
.ops
.rar_set(hw
, alt_mac_addr
, 0);
237 * igb_rar_set - Set receive address register
238 * @hw: pointer to the HW structure
239 * @addr: pointer to the receive address
240 * @index: receive address array register
242 * Sets the receive address array register at index to the address passed
245 void igb_rar_set(struct e1000_hw
*hw
, u8
*addr
, u32 index
)
247 u32 rar_low
, rar_high
;
250 * HW expects these in little endian so we reverse the byte order
251 * from network order (big endian) to little endian
253 rar_low
= ((u32
) addr
[0] |
254 ((u32
) addr
[1] << 8) |
255 ((u32
) addr
[2] << 16) | ((u32
) addr
[3] << 24));
257 rar_high
= ((u32
) addr
[4] | ((u32
) addr
[5] << 8));
259 /* If MAC address zero, no need to set the AV bit */
260 if (rar_low
|| rar_high
)
261 rar_high
|= E1000_RAH_AV
;
264 * Some bridges will combine consecutive 32-bit writes into
265 * a single burst write, which will malfunction on some parts.
266 * The flushes avoid this.
268 wr32(E1000_RAL(index
), rar_low
);
270 wr32(E1000_RAH(index
), rar_high
);
275 * igb_mta_set - Set multicast filter table address
276 * @hw: pointer to the HW structure
277 * @hash_value: determines the MTA register and bit to set
279 * The multicast table address is a register array of 32-bit registers.
280 * The hash_value is used to determine what register the bit is in, the
281 * current value is read, the new bit is OR'd in and the new value is
282 * written back into the register.
284 void igb_mta_set(struct e1000_hw
*hw
, u32 hash_value
)
286 u32 hash_bit
, hash_reg
, mta
;
289 * The MTA is a register array of 32-bit registers. It is
290 * treated like an array of (32*mta_reg_count) bits. We want to
291 * set bit BitArray[hash_value]. So we figure out what register
292 * the bit is in, read it, OR in the new bit, then write
293 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
294 * mask to bits 31:5 of the hash value which gives us the
295 * register we're modifying. The hash bit within that register
296 * is determined by the lower 5 bits of the hash value.
298 hash_reg
= (hash_value
>> 5) & (hw
->mac
.mta_reg_count
- 1);
299 hash_bit
= hash_value
& 0x1F;
301 mta
= array_rd32(E1000_MTA
, hash_reg
);
303 mta
|= (1 << hash_bit
);
305 array_wr32(E1000_MTA
, hash_reg
, mta
);
310 * igb_hash_mc_addr - Generate a multicast hash value
311 * @hw: pointer to the HW structure
312 * @mc_addr: pointer to a multicast address
314 * Generates a multicast address hash value which is used to determine
315 * the multicast filter table array address and new table value. See
318 static u32
igb_hash_mc_addr(struct e1000_hw
*hw
, u8
*mc_addr
)
320 u32 hash_value
, hash_mask
;
323 /* Register count multiplied by bits per register */
324 hash_mask
= (hw
->mac
.mta_reg_count
* 32) - 1;
327 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
328 * where 0xFF would still fall within the hash mask.
330 while (hash_mask
>> bit_shift
!= 0xFF)
334 * The portion of the address that is used for the hash table
335 * is determined by the mc_filter_type setting.
336 * The algorithm is such that there is a total of 8 bits of shifting.
337 * The bit_shift for a mc_filter_type of 0 represents the number of
338 * left-shifts where the MSB of mc_addr[5] would still fall within
339 * the hash_mask. Case 0 does this exactly. Since there are a total
340 * of 8 bits of shifting, then mc_addr[4] will shift right the
341 * remaining number of bits. Thus 8 - bit_shift. The rest of the
342 * cases are a variation of this algorithm...essentially raising the
343 * number of bits to shift mc_addr[5] left, while still keeping the
344 * 8-bit shifting total.
346 * For example, given the following Destination MAC Address and an
347 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
348 * we can see that the bit_shift for case 0 is 4. These are the hash
349 * values resulting from each mc_filter_type...
350 * [0] [1] [2] [3] [4] [5]
354 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
355 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
356 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
357 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
359 switch (hw
->mac
.mc_filter_type
) {
374 hash_value
= hash_mask
& (((mc_addr
[4] >> (8 - bit_shift
)) |
375 (((u16
) mc_addr
[5]) << bit_shift
)));
381 * igb_update_mc_addr_list - Update Multicast addresses
382 * @hw: pointer to the HW structure
383 * @mc_addr_list: array of multicast addresses to program
384 * @mc_addr_count: number of multicast addresses to program
386 * Updates entire Multicast Table Array.
387 * The caller must have a packed mc_addr_list of multicast addresses.
389 void igb_update_mc_addr_list(struct e1000_hw
*hw
,
390 u8
*mc_addr_list
, u32 mc_addr_count
)
392 u32 hash_value
, hash_bit
, hash_reg
;
395 /* clear mta_shadow */
396 memset(&hw
->mac
.mta_shadow
, 0, sizeof(hw
->mac
.mta_shadow
));
398 /* update mta_shadow from mc_addr_list */
399 for (i
= 0; (u32
) i
< mc_addr_count
; i
++) {
400 hash_value
= igb_hash_mc_addr(hw
, mc_addr_list
);
402 hash_reg
= (hash_value
>> 5) & (hw
->mac
.mta_reg_count
- 1);
403 hash_bit
= hash_value
& 0x1F;
405 hw
->mac
.mta_shadow
[hash_reg
] |= (1 << hash_bit
);
406 mc_addr_list
+= (ETH_ALEN
);
409 /* replace the entire MTA table */
410 for (i
= hw
->mac
.mta_reg_count
- 1; i
>= 0; i
--)
411 array_wr32(E1000_MTA
, i
, hw
->mac
.mta_shadow
[i
]);
416 * igb_clear_hw_cntrs_base - Clear base hardware counters
417 * @hw: pointer to the HW structure
419 * Clears the base hardware counters by reading the counter registers.
421 void igb_clear_hw_cntrs_base(struct e1000_hw
*hw
)
463 * igb_check_for_copper_link - Check for link (Copper)
464 * @hw: pointer to the HW structure
466 * Checks to see of the link status of the hardware has changed. If a
467 * change in link status has been detected, then we read the PHY registers
468 * to get the current speed/duplex if link exists.
470 s32
igb_check_for_copper_link(struct e1000_hw
*hw
)
472 struct e1000_mac_info
*mac
= &hw
->mac
;
477 * We only want to go out to the PHY registers to see if Auto-Neg
478 * has completed and/or if our link status has changed. The
479 * get_link_status flag is set upon receiving a Link Status
480 * Change or Rx Sequence Error interrupt.
482 if (!mac
->get_link_status
) {
488 * First we want to see if the MII Status Register reports
489 * link. If so, then we want to get the current speed/duplex
492 ret_val
= igb_phy_has_link(hw
, 1, 0, &link
);
497 goto out
; /* No link detected */
499 mac
->get_link_status
= false;
502 * Check if there was DownShift, must be checked
503 * immediately after link-up
505 igb_check_downshift(hw
);
508 * If we are forcing speed/duplex, then we simply return since
509 * we have already determined whether we have link or not.
512 ret_val
= -E1000_ERR_CONFIG
;
517 * Auto-Neg is enabled. Auto Speed Detection takes care
518 * of MAC speed/duplex configuration. So we only need to
519 * configure Collision Distance in the MAC.
521 igb_config_collision_dist(hw
);
524 * Configure Flow Control now that Auto-Neg has completed.
525 * First, we need to restore the desired flow control
526 * settings because we may have had to re-autoneg with a
527 * different link partner.
529 ret_val
= igb_config_fc_after_link_up(hw
);
531 hw_dbg("Error configuring flow control\n");
538 * igb_setup_link - Setup flow control and link settings
539 * @hw: pointer to the HW structure
541 * Determines which flow control settings to use, then configures flow
542 * control. Calls the appropriate media-specific link configuration
543 * function. Assuming the adapter has a valid link partner, a valid link
544 * should be established. Assumes the hardware has previously been reset
545 * and the transmitter and receiver are not enabled.
547 s32
igb_setup_link(struct e1000_hw
*hw
)
552 * In the case of the phy reset being blocked, we already have a link.
553 * We do not need to set it up again.
555 if (igb_check_reset_block(hw
))
559 * If requested flow control is set to default, set flow control
560 * based on the EEPROM flow control settings.
562 if (hw
->fc
.requested_mode
== e1000_fc_default
) {
563 ret_val
= igb_set_default_fc(hw
);
569 * We want to save off the original Flow Control configuration just
570 * in case we get disconnected and then reconnected into a different
571 * hub or switch with different Flow Control capabilities.
573 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
575 hw_dbg("After fix-ups FlowControl is now = %x\n", hw
->fc
.current_mode
);
577 /* Call the necessary media_type subroutine to configure the link. */
578 ret_val
= hw
->mac
.ops
.setup_physical_interface(hw
);
583 * Initialize the flow control address, type, and PAUSE timer
584 * registers to their default values. This is done even if flow
585 * control is disabled, because it does not hurt anything to
586 * initialize these registers.
588 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
589 wr32(E1000_FCT
, FLOW_CONTROL_TYPE
);
590 wr32(E1000_FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
591 wr32(E1000_FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
593 wr32(E1000_FCTTV
, hw
->fc
.pause_time
);
595 ret_val
= igb_set_fc_watermarks(hw
);
602 * igb_config_collision_dist - Configure collision distance
603 * @hw: pointer to the HW structure
605 * Configures the collision distance to the default value and is used
606 * during link setup. Currently no func pointer exists and all
607 * implementations are handled in the generic version of this function.
609 void igb_config_collision_dist(struct e1000_hw
*hw
)
613 tctl
= rd32(E1000_TCTL
);
615 tctl
&= ~E1000_TCTL_COLD
;
616 tctl
|= E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
;
618 wr32(E1000_TCTL
, tctl
);
623 * igb_set_fc_watermarks - Set flow control high/low watermarks
624 * @hw: pointer to the HW structure
626 * Sets the flow control high/low threshold (watermark) registers. If
627 * flow control XON frame transmission is enabled, then set XON frame
628 * tansmission as well.
630 static s32
igb_set_fc_watermarks(struct e1000_hw
*hw
)
633 u32 fcrtl
= 0, fcrth
= 0;
636 * Set the flow control receive threshold registers. Normally,
637 * these registers will be set to a default threshold that may be
638 * adjusted later by the driver's runtime code. However, if the
639 * ability to transmit pause frames is not enabled, then these
640 * registers will be set to 0.
642 if (hw
->fc
.current_mode
& e1000_fc_tx_pause
) {
644 * We need to set up the Receive Threshold high and low water
645 * marks as well as (optionally) enabling the transmission of
648 fcrtl
= hw
->fc
.low_water
;
650 fcrtl
|= E1000_FCRTL_XONE
;
652 fcrth
= hw
->fc
.high_water
;
654 wr32(E1000_FCRTL
, fcrtl
);
655 wr32(E1000_FCRTH
, fcrth
);
661 * igb_set_default_fc - Set flow control default values
662 * @hw: pointer to the HW structure
664 * Read the EEPROM for the default values for flow control and store the
667 static s32
igb_set_default_fc(struct e1000_hw
*hw
)
673 * Read and store word 0x0F of the EEPROM. This word contains bits
674 * that determine the hardware's default PAUSE (flow control) mode,
675 * a bit that determines whether the HW defaults to enabling or
676 * disabling auto-negotiation, and the direction of the
677 * SW defined pins. If there is no SW over-ride of the flow
678 * control setting, then the variable hw->fc will
679 * be initialized based on a value in the EEPROM.
681 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_INIT_CONTROL2_REG
, 1, &nvm_data
);
684 hw_dbg("NVM Read Error\n");
688 if ((nvm_data
& NVM_WORD0F_PAUSE_MASK
) == 0)
689 hw
->fc
.requested_mode
= e1000_fc_none
;
690 else if ((nvm_data
& NVM_WORD0F_PAUSE_MASK
) ==
692 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
694 hw
->fc
.requested_mode
= e1000_fc_full
;
701 * igb_force_mac_fc - Force the MAC's flow control settings
702 * @hw: pointer to the HW structure
704 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
705 * device control register to reflect the adapter settings. TFCE and RFCE
706 * need to be explicitly set by software when a copper PHY is used because
707 * autonegotiation is managed by the PHY rather than the MAC. Software must
708 * also configure these bits when link is forced on a fiber connection.
710 s32
igb_force_mac_fc(struct e1000_hw
*hw
)
715 ctrl
= rd32(E1000_CTRL
);
718 * Because we didn't get link via the internal auto-negotiation
719 * mechanism (we either forced link or we got link via PHY
720 * auto-neg), we have to manually enable/disable transmit an
721 * receive flow control.
723 * The "Case" statement below enables/disable flow control
724 * according to the "hw->fc.current_mode" parameter.
726 * The possible values of the "fc" parameter are:
727 * 0: Flow control is completely disabled
728 * 1: Rx flow control is enabled (we can receive pause
729 * frames but not send pause frames).
730 * 2: Tx flow control is enabled (we can send pause frames
731 * frames but we do not receive pause frames).
732 * 3: Both Rx and TX flow control (symmetric) is enabled.
733 * other: No other values should be possible at this point.
735 hw_dbg("hw->fc.current_mode = %u\n", hw
->fc
.current_mode
);
737 switch (hw
->fc
.current_mode
) {
739 ctrl
&= (~(E1000_CTRL_TFCE
| E1000_CTRL_RFCE
));
741 case e1000_fc_rx_pause
:
742 ctrl
&= (~E1000_CTRL_TFCE
);
743 ctrl
|= E1000_CTRL_RFCE
;
745 case e1000_fc_tx_pause
:
746 ctrl
&= (~E1000_CTRL_RFCE
);
747 ctrl
|= E1000_CTRL_TFCE
;
750 ctrl
|= (E1000_CTRL_TFCE
| E1000_CTRL_RFCE
);
753 hw_dbg("Flow control param set incorrectly\n");
754 ret_val
= -E1000_ERR_CONFIG
;
758 wr32(E1000_CTRL
, ctrl
);
765 * igb_config_fc_after_link_up - Configures flow control after link
766 * @hw: pointer to the HW structure
768 * Checks the status of auto-negotiation after link up to ensure that the
769 * speed and duplex were not forced. If the link needed to be forced, then
770 * flow control needs to be forced also. If auto-negotiation is enabled
771 * and did not fail, then we configure flow control based on our link
774 s32
igb_config_fc_after_link_up(struct e1000_hw
*hw
)
776 struct e1000_mac_info
*mac
= &hw
->mac
;
778 u16 mii_status_reg
, mii_nway_adv_reg
, mii_nway_lp_ability_reg
;
782 * Check for the case where we have fiber media and auto-neg failed
783 * so we had to force link. In this case, we need to force the
784 * configuration of the MAC to match the "fc" parameter.
786 if (mac
->autoneg_failed
) {
787 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
)
788 ret_val
= igb_force_mac_fc(hw
);
790 if (hw
->phy
.media_type
== e1000_media_type_copper
)
791 ret_val
= igb_force_mac_fc(hw
);
795 hw_dbg("Error forcing flow control settings\n");
800 * Check for the case where we have copper media and auto-neg is
801 * enabled. In this case, we need to check and see if Auto-Neg
802 * has completed, and if so, how the PHY and link partner has
803 * flow control configured.
805 if ((hw
->phy
.media_type
== e1000_media_type_copper
) && mac
->autoneg
) {
807 * Read the MII Status Register and check to see if AutoNeg
808 * has completed. We read this twice because this reg has
809 * some "sticky" (latched) bits.
811 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
,
815 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_STATUS
,
820 if (!(mii_status_reg
& MII_SR_AUTONEG_COMPLETE
)) {
821 hw_dbg("Copper PHY and Auto Neg "
822 "has not completed.\n");
827 * The AutoNeg process has completed, so we now need to
828 * read both the Auto Negotiation Advertisement
829 * Register (Address 4) and the Auto_Negotiation Base
830 * Page Ability Register (Address 5) to determine how
831 * flow control was negotiated.
833 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_AUTONEG_ADV
,
837 ret_val
= hw
->phy
.ops
.read_reg(hw
, PHY_LP_ABILITY
,
838 &mii_nway_lp_ability_reg
);
843 * Two bits in the Auto Negotiation Advertisement Register
844 * (Address 4) and two bits in the Auto Negotiation Base
845 * Page Ability Register (Address 5) determine flow control
846 * for both the PHY and the link partner. The following
847 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
848 * 1999, describes these PAUSE resolution bits and how flow
849 * control is determined based upon these settings.
850 * NOTE: DC = Don't Care
852 * LOCAL DEVICE | LINK PARTNER
853 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
854 *-------|---------|-------|---------|--------------------
855 * 0 | 0 | DC | DC | e1000_fc_none
856 * 0 | 1 | 0 | DC | e1000_fc_none
857 * 0 | 1 | 1 | 0 | e1000_fc_none
858 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
859 * 1 | 0 | 0 | DC | e1000_fc_none
860 * 1 | DC | 1 | DC | e1000_fc_full
861 * 1 | 1 | 0 | 0 | e1000_fc_none
862 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
864 * Are both PAUSE bits set to 1? If so, this implies
865 * Symmetric Flow Control is enabled at both ends. The
866 * ASM_DIR bits are irrelevant per the spec.
868 * For Symmetric Flow Control:
870 * LOCAL DEVICE | LINK PARTNER
871 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
872 *-------|---------|-------|---------|--------------------
873 * 1 | DC | 1 | DC | E1000_fc_full
876 if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
877 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
)) {
879 * Now we need to check if the user selected RX ONLY
880 * of pause frames. In this case, we had to advertise
881 * FULL flow control because we could not advertise RX
882 * ONLY. Hence, we must now check to see if we need to
883 * turn OFF the TRANSMISSION of PAUSE frames.
885 if (hw
->fc
.requested_mode
== e1000_fc_full
) {
886 hw
->fc
.current_mode
= e1000_fc_full
;
887 hw_dbg("Flow Control = FULL.\r\n");
889 hw
->fc
.current_mode
= e1000_fc_rx_pause
;
890 hw_dbg("Flow Control = "
891 "RX PAUSE frames only.\r\n");
895 * For receiving PAUSE frames ONLY.
897 * LOCAL DEVICE | LINK PARTNER
898 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
899 *-------|---------|-------|---------|--------------------
900 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
902 else if (!(mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
903 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
904 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
905 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
906 hw
->fc
.current_mode
= e1000_fc_tx_pause
;
907 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
910 * For transmitting PAUSE frames ONLY.
912 * LOCAL DEVICE | LINK PARTNER
913 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
914 *-------|---------|-------|---------|--------------------
915 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
917 else if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
918 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
919 !(mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
920 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
921 hw
->fc
.current_mode
= e1000_fc_rx_pause
;
922 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
925 * Per the IEEE spec, at this point flow control should be
926 * disabled. However, we want to consider that we could
927 * be connected to a legacy switch that doesn't advertise
928 * desired flow control, but can be forced on the link
929 * partner. So if we advertised no flow control, that is
930 * what we will resolve to. If we advertised some kind of
931 * receive capability (Rx Pause Only or Full Flow Control)
932 * and the link partner advertised none, we will configure
933 * ourselves to enable Rx Flow Control only. We can do
934 * this safely for two reasons: If the link partner really
935 * didn't want flow control enabled, and we enable Rx, no
936 * harm done since we won't be receiving any PAUSE frames
937 * anyway. If the intent on the link partner was to have
938 * flow control enabled, then by us enabling RX only, we
939 * can at least receive pause frames and process them.
940 * This is a good idea because in most cases, since we are
941 * predominantly a server NIC, more times than not we will
942 * be asked to delay transmission of packets than asking
943 * our link partner to pause transmission of frames.
945 else if ((hw
->fc
.requested_mode
== e1000_fc_none
||
946 hw
->fc
.requested_mode
== e1000_fc_tx_pause
) ||
947 hw
->fc
.strict_ieee
) {
948 hw
->fc
.current_mode
= e1000_fc_none
;
949 hw_dbg("Flow Control = NONE.\r\n");
951 hw
->fc
.current_mode
= e1000_fc_rx_pause
;
952 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
956 * Now we need to do one last check... If we auto-
957 * negotiated to HALF DUPLEX, flow control should not be
958 * enabled per IEEE 802.3 spec.
960 ret_val
= hw
->mac
.ops
.get_speed_and_duplex(hw
, &speed
, &duplex
);
962 hw_dbg("Error getting link speed and duplex\n");
966 if (duplex
== HALF_DUPLEX
)
967 hw
->fc
.current_mode
= e1000_fc_none
;
970 * Now we call a subroutine to actually force the MAC
971 * controller to use the correct flow control settings.
973 ret_val
= igb_force_mac_fc(hw
);
975 hw_dbg("Error forcing flow control settings\n");
985 * igb_get_speed_and_duplex_copper - Retrieve current speed/duplex
986 * @hw: pointer to the HW structure
987 * @speed: stores the current speed
988 * @duplex: stores the current duplex
990 * Read the status register for the current speed/duplex and store the current
991 * speed and duplex for copper connections.
993 s32
igb_get_speed_and_duplex_copper(struct e1000_hw
*hw
, u16
*speed
,
998 status
= rd32(E1000_STATUS
);
999 if (status
& E1000_STATUS_SPEED_1000
) {
1000 *speed
= SPEED_1000
;
1001 hw_dbg("1000 Mbs, ");
1002 } else if (status
& E1000_STATUS_SPEED_100
) {
1004 hw_dbg("100 Mbs, ");
1010 if (status
& E1000_STATUS_FD
) {
1011 *duplex
= FULL_DUPLEX
;
1012 hw_dbg("Full Duplex\n");
1014 *duplex
= HALF_DUPLEX
;
1015 hw_dbg("Half Duplex\n");
1022 * igb_get_hw_semaphore - Acquire hardware semaphore
1023 * @hw: pointer to the HW structure
1025 * Acquire the HW semaphore to access the PHY or NVM
1027 s32
igb_get_hw_semaphore(struct e1000_hw
*hw
)
1031 s32 timeout
= hw
->nvm
.word_size
+ 1;
1034 /* Get the SW semaphore */
1035 while (i
< timeout
) {
1036 swsm
= rd32(E1000_SWSM
);
1037 if (!(swsm
& E1000_SWSM_SMBI
))
1045 hw_dbg("Driver can't access device - SMBI bit is set.\n");
1046 ret_val
= -E1000_ERR_NVM
;
1050 /* Get the FW semaphore. */
1051 for (i
= 0; i
< timeout
; i
++) {
1052 swsm
= rd32(E1000_SWSM
);
1053 wr32(E1000_SWSM
, swsm
| E1000_SWSM_SWESMBI
);
1055 /* Semaphore acquired if bit latched */
1056 if (rd32(E1000_SWSM
) & E1000_SWSM_SWESMBI
)
1063 /* Release semaphores */
1064 igb_put_hw_semaphore(hw
);
1065 hw_dbg("Driver can't access the NVM\n");
1066 ret_val
= -E1000_ERR_NVM
;
1075 * igb_put_hw_semaphore - Release hardware semaphore
1076 * @hw: pointer to the HW structure
1078 * Release hardware semaphore used to access the PHY or NVM
1080 void igb_put_hw_semaphore(struct e1000_hw
*hw
)
1084 swsm
= rd32(E1000_SWSM
);
1086 swsm
&= ~(E1000_SWSM_SMBI
| E1000_SWSM_SWESMBI
);
1088 wr32(E1000_SWSM
, swsm
);
1092 * igb_get_auto_rd_done - Check for auto read completion
1093 * @hw: pointer to the HW structure
1095 * Check EEPROM for Auto Read done bit.
1097 s32
igb_get_auto_rd_done(struct e1000_hw
*hw
)
1103 while (i
< AUTO_READ_DONE_TIMEOUT
) {
1104 if (rd32(E1000_EECD
) & E1000_EECD_AUTO_RD
)
1110 if (i
== AUTO_READ_DONE_TIMEOUT
) {
1111 hw_dbg("Auto read by HW from NVM has not completed.\n");
1112 ret_val
= -E1000_ERR_RESET
;
1121 * igb_valid_led_default - Verify a valid default LED config
1122 * @hw: pointer to the HW structure
1123 * @data: pointer to the NVM (EEPROM)
1125 * Read the EEPROM for the current default LED configuration. If the
1126 * LED configuration is not valid, set to a valid LED configuration.
1128 static s32
igb_valid_led_default(struct e1000_hw
*hw
, u16
*data
)
1132 ret_val
= hw
->nvm
.ops
.read(hw
, NVM_ID_LED_SETTINGS
, 1, data
);
1134 hw_dbg("NVM Read Error\n");
1138 if (*data
== ID_LED_RESERVED_0000
|| *data
== ID_LED_RESERVED_FFFF
) {
1139 switch(hw
->phy
.media_type
) {
1140 case e1000_media_type_internal_serdes
:
1141 *data
= ID_LED_DEFAULT_82575_SERDES
;
1143 case e1000_media_type_copper
:
1145 *data
= ID_LED_DEFAULT
;
1155 * @hw: pointer to the HW structure
1158 s32
igb_id_led_init(struct e1000_hw
*hw
)
1160 struct e1000_mac_info
*mac
= &hw
->mac
;
1162 const u32 ledctl_mask
= 0x000000FF;
1163 const u32 ledctl_on
= E1000_LEDCTL_MODE_LED_ON
;
1164 const u32 ledctl_off
= E1000_LEDCTL_MODE_LED_OFF
;
1166 const u16 led_mask
= 0x0F;
1168 ret_val
= igb_valid_led_default(hw
, &data
);
1172 mac
->ledctl_default
= rd32(E1000_LEDCTL
);
1173 mac
->ledctl_mode1
= mac
->ledctl_default
;
1174 mac
->ledctl_mode2
= mac
->ledctl_default
;
1176 for (i
= 0; i
< 4; i
++) {
1177 temp
= (data
>> (i
<< 2)) & led_mask
;
1179 case ID_LED_ON1_DEF2
:
1180 case ID_LED_ON1_ON2
:
1181 case ID_LED_ON1_OFF2
:
1182 mac
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
1183 mac
->ledctl_mode1
|= ledctl_on
<< (i
<< 3);
1185 case ID_LED_OFF1_DEF2
:
1186 case ID_LED_OFF1_ON2
:
1187 case ID_LED_OFF1_OFF2
:
1188 mac
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
1189 mac
->ledctl_mode1
|= ledctl_off
<< (i
<< 3);
1196 case ID_LED_DEF1_ON2
:
1197 case ID_LED_ON1_ON2
:
1198 case ID_LED_OFF1_ON2
:
1199 mac
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
1200 mac
->ledctl_mode2
|= ledctl_on
<< (i
<< 3);
1202 case ID_LED_DEF1_OFF2
:
1203 case ID_LED_ON1_OFF2
:
1204 case ID_LED_OFF1_OFF2
:
1205 mac
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
1206 mac
->ledctl_mode2
|= ledctl_off
<< (i
<< 3);
1219 * igb_cleanup_led - Set LED config to default operation
1220 * @hw: pointer to the HW structure
1222 * Remove the current LED configuration and set the LED configuration
1223 * to the default value, saved from the EEPROM.
1225 s32
igb_cleanup_led(struct e1000_hw
*hw
)
1227 wr32(E1000_LEDCTL
, hw
->mac
.ledctl_default
);
1232 * igb_blink_led - Blink LED
1233 * @hw: pointer to the HW structure
1235 * Blink the led's which are set to be on.
1237 s32
igb_blink_led(struct e1000_hw
*hw
)
1239 u32 ledctl_blink
= 0;
1243 * set the blink bit for each LED that's "on" (0x0E)
1246 ledctl_blink
= hw
->mac
.ledctl_mode2
;
1247 for (i
= 0; i
< 4; i
++)
1248 if (((hw
->mac
.ledctl_mode2
>> (i
* 8)) & 0xFF) ==
1249 E1000_LEDCTL_MODE_LED_ON
)
1250 ledctl_blink
|= (E1000_LEDCTL_LED0_BLINK
<<
1253 wr32(E1000_LEDCTL
, ledctl_blink
);
1259 * igb_led_off - Turn LED off
1260 * @hw: pointer to the HW structure
1264 s32
igb_led_off(struct e1000_hw
*hw
)
1266 switch (hw
->phy
.media_type
) {
1267 case e1000_media_type_copper
:
1268 wr32(E1000_LEDCTL
, hw
->mac
.ledctl_mode1
);
1278 * igb_disable_pcie_master - Disables PCI-express master access
1279 * @hw: pointer to the HW structure
1281 * Returns 0 (0) if successful, else returns -10
1282 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1283 * the master requests to be disabled.
1285 * Disables PCI-Express master access and verifies there are no pending
1288 s32
igb_disable_pcie_master(struct e1000_hw
*hw
)
1291 s32 timeout
= MASTER_DISABLE_TIMEOUT
;
1294 if (hw
->bus
.type
!= e1000_bus_type_pci_express
)
1297 ctrl
= rd32(E1000_CTRL
);
1298 ctrl
|= E1000_CTRL_GIO_MASTER_DISABLE
;
1299 wr32(E1000_CTRL
, ctrl
);
1302 if (!(rd32(E1000_STATUS
) &
1303 E1000_STATUS_GIO_MASTER_ENABLE
))
1310 hw_dbg("Master requests are pending.\n");
1311 ret_val
= -E1000_ERR_MASTER_REQUESTS_PENDING
;
1320 * igb_validate_mdi_setting - Verify MDI/MDIx settings
1321 * @hw: pointer to the HW structure
1323 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1324 * set, which is forced to MDI mode only.
1326 s32
igb_validate_mdi_setting(struct e1000_hw
*hw
)
1330 if (!hw
->mac
.autoneg
&& (hw
->phy
.mdix
== 0 || hw
->phy
.mdix
== 3)) {
1331 hw_dbg("Invalid MDI setting detected\n");
1333 ret_val
= -E1000_ERR_CONFIG
;
1342 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
1343 * @hw: pointer to the HW structure
1344 * @reg: 32bit register offset such as E1000_SCTL
1345 * @offset: register offset to write to
1346 * @data: data to write at register offset
1348 * Writes an address/data control type register. There are several of these
1349 * and they all have the format address << 8 | data and bit 31 is polled for
1352 s32
igb_write_8bit_ctrl_reg(struct e1000_hw
*hw
, u32 reg
,
1353 u32 offset
, u8 data
)
1355 u32 i
, regvalue
= 0;
1358 /* Set up the address and data */
1359 regvalue
= ((u32
)data
) | (offset
<< E1000_GEN_CTL_ADDRESS_SHIFT
);
1360 wr32(reg
, regvalue
);
1362 /* Poll the ready bit to see if the MDI read completed */
1363 for (i
= 0; i
< E1000_GEN_POLL_TIMEOUT
; i
++) {
1365 regvalue
= rd32(reg
);
1366 if (regvalue
& E1000_GEN_CTL_READY
)
1369 if (!(regvalue
& E1000_GEN_CTL_READY
)) {
1370 hw_dbg("Reg %08x did not indicate ready\n", reg
);
1371 ret_val
= -E1000_ERR_PHY
;
1380 * igb_enable_mng_pass_thru - Enable processing of ARP's
1381 * @hw: pointer to the HW structure
1383 * Verifies the hardware needs to leave interface enabled so that frames can
1384 * be directed to and from the management interface.
1386 bool igb_enable_mng_pass_thru(struct e1000_hw
*hw
)
1390 bool ret_val
= false;
1392 if (!hw
->mac
.asf_firmware_present
)
1395 manc
= rd32(E1000_MANC
);
1397 if (!(manc
& E1000_MANC_RCV_TCO_EN
))
1400 if (hw
->mac
.arc_subsystem_valid
) {
1401 fwsm
= rd32(E1000_FWSM
);
1402 factps
= rd32(E1000_FACTPS
);
1404 if (!(factps
& E1000_FACTPS_MNGCG
) &&
1405 ((fwsm
& E1000_FWSM_MODE_MASK
) ==
1406 (e1000_mng_mode_pt
<< E1000_FWSM_MODE_SHIFT
))) {
1411 if ((manc
& E1000_MANC_SMBUS_EN
) &&
1412 !(manc
& E1000_MANC_ASF_EN
)) {