1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 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 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 FILE_LICENCE ( GPL2_OR_LATER
);
33 static u32
e1000e_hash_mc_addr_generic(struct e1000_hw
*hw
, u8
*mc_addr
);
34 static s32
e1000e_set_default_fc_generic(struct e1000_hw
*hw
);
35 static s32
e1000e_commit_fc_settings_generic(struct e1000_hw
*hw
);
36 static s32
e1000e_poll_fiber_serdes_link_generic(struct e1000_hw
*hw
);
37 static s32
e1000e_validate_mdi_setting_generic(struct e1000_hw
*hw
);
38 static void e1000e_set_lan_id_multi_port_pcie(struct e1000_hw
*hw
);
41 * e1000e_init_mac_ops_generic - Initialize MAC function pointers
42 * @hw: pointer to the HW structure
44 * Setups up the function pointers to no-op functions
46 void e1000e_init_mac_ops_generic(struct e1000_hw
*hw
)
48 struct e1000_mac_info
*mac
= &hw
->mac
;
50 mac
->ops
.set_lan_id
= e1000e_set_lan_id_multi_port_pcie
;
51 mac
->ops
.read_mac_addr
= e1000e_read_mac_addr_generic
;
52 mac
->ops
.config_collision_dist
= e1000e_config_collision_dist
;
54 mac
->ops
.wait_autoneg
= e1000e_wait_autoneg
;
57 mac
->ops
.mng_host_if_write
= e1000e_mng_host_if_write_generic
;
58 mac
->ops
.mng_write_cmd_header
= e1000e_mng_write_cmd_header_generic
;
59 mac
->ops
.mng_enable_host_if
= e1000e_mng_enable_host_if_generic
;
62 mac
->ops
.rar_set
= e1000e_rar_set
;
63 mac
->ops
.validate_mdi_setting
= e1000e_validate_mdi_setting_generic
;
67 * e1000e_get_bus_info_pcie - Get PCIe bus information
68 * @hw: pointer to the HW structure
70 * Determines and stores the system bus information for a particular
71 * network interface. The following bus information is determined and stored:
72 * bus speed, bus width, type (PCIe), and PCIe function.
74 s32
e1000e_get_bus_info_pcie(struct e1000_hw
*hw
)
76 struct e1000_mac_info
*mac
= &hw
->mac
;
77 struct e1000_bus_info
*bus
= &hw
->bus
;
82 bus
->type
= e1000_bus_type_pci_express
;
83 bus
->speed
= e1000_bus_speed_2500
;
85 ret_val
= e1000e_read_pcie_cap_reg(hw
,
89 bus
->width
= e1000_bus_width_unknown
;
91 bus
->width
= (enum e1000_bus_width
)((pcie_link_status
&
92 PCIE_LINK_WIDTH_MASK
) >>
93 PCIE_LINK_WIDTH_SHIFT
);
95 mac
->ops
.set_lan_id(hw
);
101 * e1000e_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
103 * @hw: pointer to the HW structure
105 * Determines the LAN function id by reading memory-mapped registers
106 * and swaps the port value if requested.
108 static void e1000e_set_lan_id_multi_port_pcie(struct e1000_hw
*hw
)
110 struct e1000_bus_info
*bus
= &hw
->bus
;
114 * The status register reports the correct function number
115 * for the device regardless of function swap state.
118 bus
->func
= (reg
& E1000_STATUS_FUNC_MASK
) >> E1000_STATUS_FUNC_SHIFT
;
122 * e1000e_set_lan_id_single_port - Set LAN id for a single port device
123 * @hw: pointer to the HW structure
125 * Sets the LAN function id to zero for a single port device.
127 void e1000e_set_lan_id_single_port(struct e1000_hw
*hw
)
129 struct e1000_bus_info
*bus
= &hw
->bus
;
135 * e1000e_clear_vfta_generic - Clear VLAN filter table
136 * @hw: pointer to the HW structure
138 * Clears the register array which contains the VLAN filter table by
139 * setting all the values to 0.
141 void e1000e_clear_vfta_generic(struct e1000_hw
*hw
)
145 for (offset
= 0; offset
< E1000_VLAN_FILTER_TBL_SIZE
; offset
++) {
146 E1000_WRITE_REG_ARRAY(hw
, E1000_VFTA
, offset
, 0);
152 * e1000e_write_vfta_generic - Write value to VLAN filter table
153 * @hw: pointer to the HW structure
154 * @offset: register offset in VLAN filter table
155 * @value: register value written to VLAN filter table
157 * Writes value at the given offset in the register array which stores
158 * the VLAN filter table.
160 void e1000e_write_vfta_generic(struct e1000_hw
*hw
, u32 offset
, u32 value
)
162 E1000_WRITE_REG_ARRAY(hw
, E1000_VFTA
, offset
, value
);
167 * e1000e_init_rx_addrs - Initialize receive address's
168 * @hw: pointer to the HW structure
169 * @rar_count: receive address registers
171 * Setups the receive address registers by setting the base receive address
172 * register to the devices MAC address and clearing all the other receive
173 * address registers to 0.
175 void e1000e_init_rx_addrs(struct e1000_hw
*hw
, u16 rar_count
)
178 u8 mac_addr
[ETH_ADDR_LEN
] = {0};
180 /* Setup the receive address */
181 e_dbg("Programming MAC Address into RAR[0]\n");
183 hw
->mac
.ops
.rar_set(hw
, hw
->mac
.addr
, 0);
185 /* Zero out the other (rar_entry_count - 1) receive addresses */
186 e_dbg("Clearing RAR[1-%u]\n", rar_count
-1);
187 for (i
= 1; i
< rar_count
; i
++)
188 hw
->mac
.ops
.rar_set(hw
, mac_addr
, i
);
192 * e1000e_check_alt_mac_addr_generic - Check for alternate MAC addr
193 * @hw: pointer to the HW structure
195 * Checks the nvm for an alternate MAC address. An alternate MAC address
196 * can be setup by pre-boot software and must be treated like a permanent
197 * address and must override the actual permanent MAC address. If an
198 * alternate MAC address is found it is programmed into RAR0, replacing
199 * the permanent address that was installed into RAR0 by the Si on reset.
200 * This function will return SUCCESS unless it encounters an error while
201 * reading the EEPROM.
203 s32
e1000e_check_alt_mac_addr_generic(struct e1000_hw
*hw
)
206 s32 ret_val
= E1000_SUCCESS
;
207 u16 offset
, nvm_alt_mac_addr_offset
, nvm_data
;
208 u8 alt_mac_addr
[ETH_ADDR_LEN
];
210 ret_val
= e1000e_read_nvm(hw
, NVM_ALT_MAC_ADDR_PTR
, 1,
211 &nvm_alt_mac_addr_offset
);
213 e_dbg("NVM Read Error\n");
217 if (nvm_alt_mac_addr_offset
== 0xFFFF) {
218 /* There is no Alternate MAC Address */
222 if (hw
->bus
.func
== E1000_FUNC_1
)
223 nvm_alt_mac_addr_offset
+= E1000_ALT_MAC_ADDRESS_OFFSET_LAN1
;
224 for (i
= 0; i
< ETH_ADDR_LEN
; i
+= 2) {
225 offset
= nvm_alt_mac_addr_offset
+ (i
>> 1);
226 ret_val
= e1000e_read_nvm(hw
, offset
, 1, &nvm_data
);
228 e_dbg("NVM Read Error\n");
232 alt_mac_addr
[i
] = (u8
)(nvm_data
& 0xFF);
233 alt_mac_addr
[i
+ 1] = (u8
)(nvm_data
>> 8);
236 /* if multicast bit is set, the alternate address will not be used */
237 if (alt_mac_addr
[0] & 0x01) {
238 e_dbg("Ignoring Alternate Mac Address with MC bit set\n");
243 * We have a valid alternate MAC address, and we want to treat it the
244 * same as the normal permanent MAC address stored by the HW into the
245 * RAR. Do this by mapping this address into RAR0.
247 hw
->mac
.ops
.rar_set(hw
, alt_mac_addr
, 0);
254 * e1000e_rar_set - Set receive address register
255 * @hw: pointer to the HW structure
256 * @addr: pointer to the receive address
257 * @index: receive address array register
259 * Sets the receive address array register at index to the address passed
262 void e1000e_rar_set(struct e1000_hw
*hw
, u8
*addr
, u32 index
)
264 u32 rar_low
, rar_high
;
267 * HW expects these in little endian so we reverse the byte order
268 * from network order (big endian) to little endian
270 rar_low
= ((u32
) addr
[0] |
271 ((u32
) addr
[1] << 8) |
272 ((u32
) addr
[2] << 16) | ((u32
) addr
[3] << 24));
274 rar_high
= ((u32
) addr
[4] | ((u32
) addr
[5] << 8));
276 /* If MAC address zero, no need to set the AV bit */
277 if (rar_low
|| rar_high
)
278 rar_high
|= E1000_RAH_AV
;
281 * Some bridges will combine consecutive 32-bit writes into
282 * a single burst write, which will malfunction on some parts.
283 * The flushes avoid this.
285 ew32(RAL(index
), rar_low
);
287 ew32(RAH(index
), rar_high
);
292 * e1000e_mta_set_generic - Set multicast filter table address
293 * @hw: pointer to the HW structure
294 * @hash_value: determines the MTA register and bit to set
296 * The multicast table address is a register array of 32-bit registers.
297 * The hash_value is used to determine what register the bit is in, the
298 * current value is read, the new bit is OR'd in and the new value is
299 * written back into the register.
301 void e1000e_mta_set_generic(struct e1000_hw
*hw
, u32 hash_value
)
303 u32 hash_bit
, hash_reg
, mta
;
306 * The MTA is a register array of 32-bit registers. It is
307 * treated like an array of (32*mta_reg_count) bits. We want to
308 * set bit BitArray[hash_value]. So we figure out what register
309 * the bit is in, read it, OR in the new bit, then write
310 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
311 * mask to bits 31:5 of the hash value which gives us the
312 * register we're modifying. The hash bit within that register
313 * is determined by the lower 5 bits of the hash value.
315 hash_reg
= (hash_value
>> 5) & (hw
->mac
.mta_reg_count
- 1);
316 hash_bit
= hash_value
& 0x1F;
318 mta
= E1000_READ_REG_ARRAY(hw
, E1000_MTA
, hash_reg
);
320 mta
|= (1 << hash_bit
);
322 E1000_WRITE_REG_ARRAY(hw
, E1000_MTA
, hash_reg
, mta
);
327 * e1000e_update_mc_addr_list_generic - Update Multicast addresses
328 * @hw: pointer to the HW structure
329 * @mc_addr_list: array of multicast addresses to program
330 * @mc_addr_count: number of multicast addresses to program
332 * Updates entire Multicast Table Array.
333 * The caller must have a packed mc_addr_list of multicast addresses.
335 void e1000e_update_mc_addr_list_generic(struct e1000_hw
*hw
,
336 u8
*mc_addr_list
, u32 mc_addr_count
)
338 u32 hash_value
, hash_bit
, hash_reg
;
341 /* clear mta_shadow */
342 memset(&hw
->mac
.mta_shadow
, 0, sizeof(hw
->mac
.mta_shadow
));
344 /* update mta_shadow from mc_addr_list */
345 for (i
= 0; (u32
) i
< mc_addr_count
; i
++) {
346 hash_value
= e1000e_hash_mc_addr_generic(hw
, mc_addr_list
);
348 hash_reg
= (hash_value
>> 5) & (hw
->mac
.mta_reg_count
- 1);
349 hash_bit
= hash_value
& 0x1F;
351 hw
->mac
.mta_shadow
[hash_reg
] |= (1 << hash_bit
);
352 mc_addr_list
+= (ETH_ADDR_LEN
);
355 /* replace the entire MTA table */
356 for (i
= hw
->mac
.mta_reg_count
- 1; i
>= 0; i
--)
357 E1000_WRITE_REG_ARRAY(hw
, E1000_MTA
, i
, hw
->mac
.mta_shadow
[i
]);
362 * e1000e_hash_mc_addr_generic - Generate a multicast hash value
363 * @hw: pointer to the HW structure
364 * @mc_addr: pointer to a multicast address
366 * Generates a multicast address hash value which is used to determine
367 * the multicast filter table array address and new table value. See
368 * e1000e_mta_set_generic()
370 static u32
e1000e_hash_mc_addr_generic(struct e1000_hw
*hw
, u8
*mc_addr
)
372 u32 hash_value
, hash_mask
;
375 /* Register count multiplied by bits per register */
376 hash_mask
= (hw
->mac
.mta_reg_count
* 32) - 1;
379 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
380 * where 0xFF would still fall within the hash mask.
382 while (hash_mask
>> bit_shift
!= 0xFF)
386 * The portion of the address that is used for the hash table
387 * is determined by the mc_filter_type setting.
388 * The algorithm is such that there is a total of 8 bits of shifting.
389 * The bit_shift for a mc_filter_type of 0 represents the number of
390 * left-shifts where the MSB of mc_addr[5] would still fall within
391 * the hash_mask. Case 0 does this exactly. Since there are a total
392 * of 8 bits of shifting, then mc_addr[4] will shift right the
393 * remaining number of bits. Thus 8 - bit_shift. The rest of the
394 * cases are a variation of this algorithm...essentially raising the
395 * number of bits to shift mc_addr[5] left, while still keeping the
396 * 8-bit shifting total.
398 * For example, given the following Destination MAC Address and an
399 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
400 * we can see that the bit_shift for case 0 is 4. These are the hash
401 * values resulting from each mc_filter_type...
402 * [0] [1] [2] [3] [4] [5]
406 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
407 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
408 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
409 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
411 switch (hw
->mac
.mc_filter_type
) {
426 hash_value
= hash_mask
& (((mc_addr
[4] >> (8 - bit_shift
)) |
427 (((u16
) mc_addr
[5]) << bit_shift
)));
433 * e1000e_clear_hw_cntrs_base - Clear base hardware counters
434 * @hw: pointer to the HW structure
436 * Clears the base hardware counters by reading the counter registers.
438 void e1000e_clear_hw_cntrs_base(struct e1000_hw
*hw __unused
)
482 * e1000e_check_for_copper_link - Check for link (Copper)
483 * @hw: pointer to the HW structure
485 * Checks to see of the link status of the hardware has changed. If a
486 * change in link status has been detected, then we read the PHY registers
487 * to get the current speed/duplex if link exists.
489 s32
e1000e_check_for_copper_link(struct e1000_hw
*hw
)
491 struct e1000_mac_info
*mac
= &hw
->mac
;
496 * We only want to go out to the PHY registers to see if Auto-Neg
497 * has completed and/or if our link status has changed. The
498 * get_link_status flag is set upon receiving a Link Status
499 * Change or Rx Sequence Error interrupt.
501 if (!mac
->get_link_status
) {
502 ret_val
= E1000_SUCCESS
;
507 * First we want to see if the MII Status Register reports
508 * link. If so, then we want to get the current speed/duplex
511 ret_val
= e1000e_phy_has_link_generic(hw
, 1, 0, &link
);
516 goto out
; /* No link detected */
518 mac
->get_link_status
= false;
521 * Check if there was DownShift, must be checked
522 * immediately after link-up
524 e1000e_check_downshift(hw
);
527 * If we are forcing speed/duplex, then we simply return since
528 * we have already determined whether we have link or not.
531 ret_val
= -E1000_ERR_CONFIG
;
536 * Auto-Neg is enabled. Auto Speed Detection takes care
537 * of MAC speed/duplex configuration. So we only need to
538 * configure Collision Distance in the MAC.
540 e1000e_config_collision_dist(hw
);
543 * Configure Flow Control now that Auto-Neg has completed.
544 * First, we need to restore the desired flow control
545 * settings because we may have had to re-autoneg with a
546 * different link partner.
548 ret_val
= e1000e_config_fc_after_link_up(hw
);
550 e_dbg("Error configuring flow control\n");
557 * e1000e_check_for_fiber_link - Check for link (Fiber)
558 * @hw: pointer to the HW structure
560 * Checks for link up on the hardware. If link is not up and we have
561 * a signal, then we need to force link up.
563 s32
e1000e_check_for_fiber_link(struct e1000_hw
*hw
)
565 struct e1000_mac_info
*mac
= &hw
->mac
;
569 s32 ret_val
= E1000_SUCCESS
;
572 status
= er32(STATUS
);
576 * If we don't have link (auto-negotiation failed or link partner
577 * cannot auto-negotiate), the cable is plugged in (we have signal),
578 * and our link partner is not trying to auto-negotiate with us (we
579 * are receiving idles or data), we need to force link up. We also
580 * need to give auto-negotiation time to complete, in case the cable
581 * was just plugged in. The autoneg_failed flag does this.
583 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
584 if ((ctrl
& E1000_CTRL_SWDPIN1
) && (!(status
& E1000_STATUS_LU
)) &&
585 (!(rxcw
& E1000_RXCW_C
))) {
586 if (mac
->autoneg_failed
== 0) {
587 mac
->autoneg_failed
= 1;
590 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
592 /* Disable auto-negotiation in the TXCW register */
593 ew32(TXCW
, (mac
->txcw
& ~E1000_TXCW_ANE
));
595 /* Force link-up and also force full-duplex. */
597 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FD
);
600 /* Configure Flow Control after forcing link up. */
601 ret_val
= e1000e_config_fc_after_link_up(hw
);
603 e_dbg("Error configuring flow control\n");
606 } else if ((ctrl
& E1000_CTRL_SLU
) && (rxcw
& E1000_RXCW_C
)) {
608 * If we are forcing link and we are receiving /C/ ordered
609 * sets, re-enable auto-negotiation in the TXCW register
610 * and disable forced link in the Device Control register
611 * in an attempt to auto-negotiate with our link partner.
613 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
614 ew32(TXCW
, mac
->txcw
);
615 ew32(CTRL
, (ctrl
& ~E1000_CTRL_SLU
));
617 mac
->serdes_has_link
= true;
625 * e1000e_check_for_serdes_link - Check for link (Serdes)
626 * @hw: pointer to the HW structure
628 * Checks for link up on the hardware. If link is not up and we have
629 * a signal, then we need to force link up.
631 s32
e1000e_check_for_serdes_link(struct e1000_hw
*hw
)
633 struct e1000_mac_info
*mac
= &hw
->mac
;
637 s32 ret_val
= E1000_SUCCESS
;
640 status
= er32(STATUS
);
644 * If we don't have link (auto-negotiation failed or link partner
645 * cannot auto-negotiate), and our link partner is not trying to
646 * auto-negotiate with us (we are receiving idles or data),
647 * we need to force link up. We also need to give auto-negotiation
650 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
651 if ((!(status
& E1000_STATUS_LU
)) && (!(rxcw
& E1000_RXCW_C
))) {
652 if (mac
->autoneg_failed
== 0) {
653 mac
->autoneg_failed
= 1;
656 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
658 /* Disable auto-negotiation in the TXCW register */
659 ew32(TXCW
, (mac
->txcw
& ~E1000_TXCW_ANE
));
661 /* Force link-up and also force full-duplex. */
663 ctrl
|= (E1000_CTRL_SLU
| E1000_CTRL_FD
);
666 /* Configure Flow Control after forcing link up. */
667 ret_val
= e1000e_config_fc_after_link_up(hw
);
669 e_dbg("Error configuring flow control\n");
672 } else if ((ctrl
& E1000_CTRL_SLU
) && (rxcw
& E1000_RXCW_C
)) {
674 * If we are forcing link and we are receiving /C/ ordered
675 * sets, re-enable auto-negotiation in the TXCW register
676 * and disable forced link in the Device Control register
677 * in an attempt to auto-negotiate with our link partner.
679 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
680 ew32(TXCW
, mac
->txcw
);
681 ew32(CTRL
, (ctrl
& ~E1000_CTRL_SLU
));
683 mac
->serdes_has_link
= true;
684 } else if (!(E1000_TXCW_ANE
& er32(TXCW
))) {
686 * If we force link for non-auto-negotiation switch, check
687 * link status based on MAC synchronization for internal
690 /* SYNCH bit and IV bit are sticky. */
693 if (rxcw
& E1000_RXCW_SYNCH
) {
694 if (!(rxcw
& E1000_RXCW_IV
)) {
695 mac
->serdes_has_link
= true;
696 e_dbg("SERDES: Link up - forced.\n");
699 mac
->serdes_has_link
= false;
700 e_dbg("SERDES: Link down - force failed.\n");
704 if (E1000_TXCW_ANE
& er32(TXCW
)) {
705 status
= er32(STATUS
);
706 if (status
& E1000_STATUS_LU
) {
707 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
710 if (rxcw
& E1000_RXCW_SYNCH
) {
711 if (!(rxcw
& E1000_RXCW_IV
)) {
712 mac
->serdes_has_link
= true;
713 e_dbg("SERDES: Link up - autoneg "
714 "completed sucessfully.\n");
716 mac
->serdes_has_link
= false;
717 e_dbg("SERDES: Link down - invalid"
718 "codewords detected in autoneg.\n");
721 mac
->serdes_has_link
= false;
722 e_dbg("SERDES: Link down - no sync.\n");
725 mac
->serdes_has_link
= false;
726 e_dbg("SERDES: Link down - autoneg failed\n");
735 * e1000e_setup_link - Setup flow control and link settings
736 * @hw: pointer to the HW structure
738 * Determines which flow control settings to use, then configures flow
739 * control. Calls the appropriate media-specific link configuration
740 * function. Assuming the adapter has a valid link partner, a valid link
741 * should be established. Assumes the hardware has previously been reset
742 * and the transmitter and receiver are not enabled.
744 s32
e1000e_setup_link(struct e1000_hw
*hw
)
746 s32 ret_val
= E1000_SUCCESS
;
749 * In the case of the phy reset being blocked, we already have a link.
750 * We do not need to set it up again.
752 if (hw
->phy
.ops
.check_reset_block
)
753 if (e1000e_check_reset_block(hw
))
757 * If requested flow control is set to default, set flow control
758 * based on the EEPROM flow control settings.
760 if (hw
->fc
.requested_mode
== e1000_fc_default
) {
761 ret_val
= e1000e_set_default_fc_generic(hw
);
767 * Save off the requested flow control mode for use later. Depending
768 * on the link partner's capabilities, we may or may not use this mode.
770 hw
->fc
.current_mode
= hw
->fc
.requested_mode
;
772 e_dbg("After fix-ups FlowControl is now = %x\n",
773 hw
->fc
.current_mode
);
775 /* Call the necessary media_type subroutine to configure the link. */
776 ret_val
= hw
->mac
.ops
.setup_physical_interface(hw
);
781 * Initialize the flow control address, type, and PAUSE timer
782 * registers to their default values. This is done even if flow
783 * control is disabled, because it does not hurt anything to
784 * initialize these registers.
786 e_dbg("Initializing the Flow Control address, type and timer regs\n");
787 ew32(FCT
, FLOW_CONTROL_TYPE
);
788 ew32(FCAH
, FLOW_CONTROL_ADDRESS_HIGH
);
789 ew32(FCAL
, FLOW_CONTROL_ADDRESS_LOW
);
791 ew32(FCTTV
, hw
->fc
.pause_time
);
793 ret_val
= e1000e_set_fc_watermarks(hw
);
800 * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
801 * @hw: pointer to the HW structure
803 * Configures collision distance and flow control for fiber and serdes
804 * links. Upon successful setup, poll for link.
806 s32
e1000e_setup_fiber_serdes_link(struct e1000_hw
*hw
)
809 s32 ret_val
= E1000_SUCCESS
;
813 /* Take the link out of reset */
814 ctrl
&= ~E1000_CTRL_LRST
;
816 e1000e_config_collision_dist(hw
);
818 ret_val
= e1000e_commit_fc_settings_generic(hw
);
823 * Since auto-negotiation is enabled, take the link out of reset (the
824 * link will be in reset, because we previously reset the chip). This
825 * will restart auto-negotiation. If auto-negotiation is successful
826 * then the link-up status bit will be set and the flow control enable
827 * bits (RFCE and TFCE) will be set according to their negotiated value.
829 e_dbg("Auto-negotiation enabled\n");
836 * For these adapters, the SW definable pin 1 is set when the optics
837 * detect a signal. If we have a signal, then poll for a "Link-Up"
840 if (hw
->phy
.media_type
== e1000_media_type_internal_serdes
||
841 (er32(CTRL
) & E1000_CTRL_SWDPIN1
)) {
842 ret_val
= e1000e_poll_fiber_serdes_link_generic(hw
);
844 e_dbg("No signal detected\n");
852 * e1000e_config_collision_dist - Configure collision distance
853 * @hw: pointer to the HW structure
855 * Configures the collision distance to the default value and is used
856 * during link setup. Currently no func pointer exists and all
857 * implementations are handled in the generic version of this function.
859 void e1000e_config_collision_dist(struct e1000_hw
*hw
)
865 tctl
&= ~E1000_TCTL_COLD
;
866 tctl
|= E1000_COLLISION_DISTANCE
<< E1000_COLD_SHIFT
;
873 * e1000e_poll_fiber_serdes_link_generic - Poll for link up
874 * @hw: pointer to the HW structure
876 * Polls for link up by reading the status register, if link fails to come
877 * up with auto-negotiation, then the link is forced if a signal is detected.
879 static s32
e1000e_poll_fiber_serdes_link_generic(struct e1000_hw
*hw
)
881 struct e1000_mac_info
*mac
= &hw
->mac
;
883 s32 ret_val
= E1000_SUCCESS
;
886 * If we have a signal (the cable is plugged in, or assumed true for
887 * serdes media) then poll for a "Link-Up" indication in the Device
888 * Status Register. Time-out if a link isn't seen in 500 milliseconds
889 * seconds (Auto-negotiation should complete in less than 500
890 * milliseconds even if the other end is doing it in SW).
892 for (i
= 0; i
< FIBER_LINK_UP_LIMIT
; i
++) {
894 status
= er32(STATUS
);
895 if (status
& E1000_STATUS_LU
)
898 if (i
== FIBER_LINK_UP_LIMIT
) {
899 e_dbg("Never got a valid link from auto-neg!!!\n");
900 mac
->autoneg_failed
= 1;
902 * AutoNeg failed to achieve a link, so we'll call
903 * mac->check_for_link. This routine will force the
904 * link up if we detect a signal. This will allow us to
905 * communicate with non-autonegotiating link partners.
907 ret_val
= hw
->mac
.ops
.check_for_link(hw
);
909 e_dbg("Error while checking for link\n");
912 mac
->autoneg_failed
= 0;
914 mac
->autoneg_failed
= 0;
915 e_dbg("Valid Link Found\n");
923 * e1000e_commit_fc_settings_generic - Configure flow control
924 * @hw: pointer to the HW structure
926 * Write the flow control settings to the Transmit Config Word Register (TXCW)
927 * base on the flow control settings in e1000_mac_info.
929 static s32
e1000e_commit_fc_settings_generic(struct e1000_hw
*hw
)
931 struct e1000_mac_info
*mac
= &hw
->mac
;
933 s32 ret_val
= E1000_SUCCESS
;
936 * Check for a software override of the flow control settings, and
937 * setup the device accordingly. If auto-negotiation is enabled, then
938 * software will have to set the "PAUSE" bits to the correct value in
939 * the Transmit Config Word Register (TXCW) and re-start auto-
940 * negotiation. However, if auto-negotiation is disabled, then
941 * software will have to manually configure the two flow control enable
942 * bits in the CTRL register.
944 * The possible values of the "fc" parameter are:
945 * 0: Flow control is completely disabled
946 * 1: Rx flow control is enabled (we can receive pause frames,
947 * but not send pause frames).
948 * 2: Tx flow control is enabled (we can send pause frames but we
949 * do not support receiving pause frames).
950 * 3: Both Rx and Tx flow control (symmetric) are enabled.
952 switch (hw
->fc
.current_mode
) {
954 /* Flow control completely disabled by a software over-ride. */
955 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
);
957 case e1000_fc_rx_pause
:
959 * Rx Flow control is enabled and Tx Flow control is disabled
960 * by a software over-ride. Since there really isn't a way to
961 * advertise that we are capable of Rx Pause ONLY, we will
962 * advertise that we support both symmetric and asymmetric RX
963 * PAUSE. Later, we will disable the adapter's ability to send
966 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
968 case e1000_fc_tx_pause
:
970 * Tx Flow control is enabled, and Rx Flow control is disabled,
971 * by a software over-ride.
973 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_ASM_DIR
);
977 * Flow control (both Rx and Tx) is enabled by a software
980 txcw
= (E1000_TXCW_ANE
| E1000_TXCW_FD
| E1000_TXCW_PAUSE_MASK
);
983 e_dbg("Flow control param set incorrectly\n");
984 ret_val
= -E1000_ERR_CONFIG
;
997 * e1000e_set_fc_watermarks - Set flow control high/low watermarks
998 * @hw: pointer to the HW structure
1000 * Sets the flow control high/low threshold (watermark) registers. If
1001 * flow control XON frame transmission is enabled, then set XON frame
1002 * transmission as well.
1004 s32
e1000e_set_fc_watermarks(struct e1000_hw
*hw
)
1006 s32 ret_val
= E1000_SUCCESS
;
1007 u32 fcrtl
= 0, fcrth
= 0;
1010 * Set the flow control receive threshold registers. Normally,
1011 * these registers will be set to a default threshold that may be
1012 * adjusted later by the driver's runtime code. However, if the
1013 * ability to transmit pause frames is not enabled, then these
1014 * registers will be set to 0.
1016 if (hw
->fc
.current_mode
& e1000_fc_tx_pause
) {
1018 * We need to set up the Receive Threshold high and low water
1019 * marks as well as (optionally) enabling the transmission of
1022 fcrtl
= hw
->fc
.low_water
;
1023 if (hw
->fc
.send_xon
)
1024 fcrtl
|= E1000_FCRTL_XONE
;
1026 fcrth
= hw
->fc
.high_water
;
1035 * e1000e_set_default_fc_generic - Set flow control default values
1036 * @hw: pointer to the HW structure
1038 * Read the EEPROM for the default values for flow control and store the
1041 static s32
e1000e_set_default_fc_generic(struct e1000_hw
*hw
)
1043 s32 ret_val
= E1000_SUCCESS
;
1047 * Read and store word 0x0F of the EEPROM. This word contains bits
1048 * that determine the hardware's default PAUSE (flow control) mode,
1049 * a bit that determines whether the HW defaults to enabling or
1050 * disabling auto-negotiation, and the direction of the
1051 * SW defined pins. If there is no SW over-ride of the flow
1052 * control setting, then the variable hw->fc will
1053 * be initialized based on a value in the EEPROM.
1055 ret_val
= e1000e_read_nvm(hw
, NVM_INIT_CONTROL2_REG
, 1, &nvm_data
);
1058 e_dbg("NVM Read Error\n");
1062 if ((nvm_data
& NVM_WORD0F_PAUSE_MASK
) == 0)
1063 hw
->fc
.requested_mode
= e1000_fc_none
;
1064 else if ((nvm_data
& NVM_WORD0F_PAUSE_MASK
) ==
1066 hw
->fc
.requested_mode
= e1000_fc_tx_pause
;
1068 hw
->fc
.requested_mode
= e1000_fc_full
;
1075 * e1000e_force_mac_fc - Force the MAC's flow control settings
1076 * @hw: pointer to the HW structure
1078 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
1079 * device control register to reflect the adapter settings. TFCE and RFCE
1080 * need to be explicitly set by software when a copper PHY is used because
1081 * autonegotiation is managed by the PHY rather than the MAC. Software must
1082 * also configure these bits when link is forced on a fiber connection.
1084 s32
e1000e_force_mac_fc(struct e1000_hw
*hw
)
1087 s32 ret_val
= E1000_SUCCESS
;
1092 * Because we didn't get link via the internal auto-negotiation
1093 * mechanism (we either forced link or we got link via PHY
1094 * auto-neg), we have to manually enable/disable transmit an
1095 * receive flow control.
1097 * The "Case" statement below enables/disable flow control
1098 * according to the "hw->fc.current_mode" parameter.
1100 * The possible values of the "fc" parameter are:
1101 * 0: Flow control is completely disabled
1102 * 1: Rx flow control is enabled (we can receive pause
1103 * frames but not send pause frames).
1104 * 2: Tx flow control is enabled (we can send pause frames
1105 * frames but we do not receive pause frames).
1106 * 3: Both Rx and Tx flow control (symmetric) is enabled.
1107 * other: No other values should be possible at this point.
1109 e_dbg("hw->fc.current_mode = %u\n", hw
->fc
.current_mode
);
1111 switch (hw
->fc
.current_mode
) {
1113 ctrl
&= (~(E1000_CTRL_TFCE
| E1000_CTRL_RFCE
));
1115 case e1000_fc_rx_pause
:
1116 ctrl
&= (~E1000_CTRL_TFCE
);
1117 ctrl
|= E1000_CTRL_RFCE
;
1119 case e1000_fc_tx_pause
:
1120 ctrl
&= (~E1000_CTRL_RFCE
);
1121 ctrl
|= E1000_CTRL_TFCE
;
1124 ctrl
|= (E1000_CTRL_TFCE
| E1000_CTRL_RFCE
);
1127 e_dbg("Flow control param set incorrectly\n");
1128 ret_val
= -E1000_ERR_CONFIG
;
1139 * e1000e_config_fc_after_link_up - Configures flow control after link
1140 * @hw: pointer to the HW structure
1142 * Checks the status of auto-negotiation after link up to ensure that the
1143 * speed and duplex were not forced. If the link needed to be forced, then
1144 * flow control needs to be forced also. If auto-negotiation is enabled
1145 * and did not fail, then we configure flow control based on our link
1148 s32
e1000e_config_fc_after_link_up(struct e1000_hw
*hw
)
1150 struct e1000_mac_info
*mac
= &hw
->mac
;
1151 s32 ret_val
= E1000_SUCCESS
;
1152 u16 mii_status_reg
, mii_nway_adv_reg
, mii_nway_lp_ability_reg
;
1156 * Check for the case where we have fiber media and auto-neg failed
1157 * so we had to force link. In this case, we need to force the
1158 * configuration of the MAC to match the "fc" parameter.
1160 if (mac
->autoneg_failed
) {
1161 if (hw
->phy
.media_type
== e1000_media_type_fiber
||
1162 hw
->phy
.media_type
== e1000_media_type_internal_serdes
)
1163 ret_val
= e1000e_force_mac_fc(hw
);
1165 if (hw
->phy
.media_type
== e1000_media_type_copper
)
1166 ret_val
= e1000e_force_mac_fc(hw
);
1170 e_dbg("Error forcing flow control settings\n");
1175 * Check for the case where we have copper media and auto-neg is
1176 * enabled. In this case, we need to check and see if Auto-Neg
1177 * has completed, and if so, how the PHY and link partner has
1178 * flow control configured.
1180 if ((hw
->phy
.media_type
== e1000_media_type_copper
) && mac
->autoneg
) {
1182 * Read the MII Status Register and check to see if AutoNeg
1183 * has completed. We read this twice because this reg has
1184 * some "sticky" (latched) bits.
1186 ret_val
= e1e_rphy(hw
, PHY_STATUS
, &mii_status_reg
);
1189 ret_val
= e1e_rphy(hw
, PHY_STATUS
, &mii_status_reg
);
1193 if (!(mii_status_reg
& MII_SR_AUTONEG_COMPLETE
)) {
1194 e_dbg("Copper PHY and Auto Neg "
1195 "has not completed.\n");
1200 * The AutoNeg process has completed, so we now need to
1201 * read both the Auto Negotiation Advertisement
1202 * Register (Address 4) and the Auto_Negotiation Base
1203 * Page Ability Register (Address 5) to determine how
1204 * flow control was negotiated.
1206 ret_val
= e1e_rphy(hw
, PHY_AUTONEG_ADV
,
1210 ret_val
= e1e_rphy(hw
, PHY_LP_ABILITY
,
1211 &mii_nway_lp_ability_reg
);
1216 * Two bits in the Auto Negotiation Advertisement Register
1217 * (Address 4) and two bits in the Auto Negotiation Base
1218 * Page Ability Register (Address 5) determine flow control
1219 * for both the PHY and the link partner. The following
1220 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1221 * 1999, describes these PAUSE resolution bits and how flow
1222 * control is determined based upon these settings.
1223 * NOTE: DC = Don't Care
1225 * LOCAL DEVICE | LINK PARTNER
1226 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1227 *-------|---------|-------|---------|--------------------
1228 * 0 | 0 | DC | DC | e1000_fc_none
1229 * 0 | 1 | 0 | DC | e1000_fc_none
1230 * 0 | 1 | 1 | 0 | e1000_fc_none
1231 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1232 * 1 | 0 | 0 | DC | e1000_fc_none
1233 * 1 | DC | 1 | DC | e1000_fc_full
1234 * 1 | 1 | 0 | 0 | e1000_fc_none
1235 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1237 * Are both PAUSE bits set to 1? If so, this implies
1238 * Symmetric Flow Control is enabled at both ends. The
1239 * ASM_DIR bits are irrelevant per the spec.
1241 * For Symmetric Flow Control:
1243 * LOCAL DEVICE | LINK PARTNER
1244 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1245 *-------|---------|-------|---------|--------------------
1246 * 1 | DC | 1 | DC | E1000_fc_full
1249 if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1250 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
)) {
1252 * Now we need to check if the user selected Rx ONLY
1253 * of pause frames. In this case, we had to advertise
1254 * FULL flow control because we could not advertise RX
1255 * ONLY. Hence, we must now check to see if we need to
1256 * turn OFF the TRANSMISSION of PAUSE frames.
1258 if (hw
->fc
.requested_mode
== e1000_fc_full
) {
1259 hw
->fc
.current_mode
= e1000_fc_full
;
1260 e_dbg("Flow Control = FULL.\r\n");
1262 hw
->fc
.current_mode
= e1000_fc_rx_pause
;
1263 e_dbg("Flow Control = "
1264 "RX PAUSE frames only.\r\n");
1268 * For receiving PAUSE frames ONLY.
1270 * LOCAL DEVICE | LINK PARTNER
1271 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1272 *-------|---------|-------|---------|--------------------
1273 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1275 else if (!(mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1276 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1277 (mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1278 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
1279 hw
->fc
.current_mode
= e1000_fc_tx_pause
;
1280 e_dbg("Flow Control = TX PAUSE frames only.\r\n");
1283 * For transmitting PAUSE frames ONLY.
1285 * LOCAL DEVICE | LINK PARTNER
1286 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1287 *-------|---------|-------|---------|--------------------
1288 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1290 else if ((mii_nway_adv_reg
& NWAY_AR_PAUSE
) &&
1291 (mii_nway_adv_reg
& NWAY_AR_ASM_DIR
) &&
1292 !(mii_nway_lp_ability_reg
& NWAY_LPAR_PAUSE
) &&
1293 (mii_nway_lp_ability_reg
& NWAY_LPAR_ASM_DIR
)) {
1294 hw
->fc
.current_mode
= e1000_fc_rx_pause
;
1295 e_dbg("Flow Control = RX PAUSE frames only.\r\n");
1298 * Per the IEEE spec, at this point flow control
1299 * should be disabled.
1301 hw
->fc
.current_mode
= e1000_fc_none
;
1302 e_dbg("Flow Control = NONE.\r\n");
1306 * Now we need to do one last check... If we auto-
1307 * negotiated to HALF DUPLEX, flow control should not be
1308 * enabled per IEEE 802.3 spec.
1310 ret_val
= mac
->ops
.get_link_up_info(hw
, &speed
, &duplex
);
1312 e_dbg("Error getting link speed and duplex\n");
1316 if (duplex
== HALF_DUPLEX
)
1317 hw
->fc
.current_mode
= e1000_fc_none
;
1320 * Now we call a subroutine to actually force the MAC
1321 * controller to use the correct flow control settings.
1323 ret_val
= e1000e_force_mac_fc(hw
);
1325 e_dbg("Error forcing flow control settings\n");
1335 * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
1336 * @hw: pointer to the HW structure
1337 * @speed: stores the current speed
1338 * @duplex: stores the current duplex
1340 * Read the status register for the current speed/duplex and store the current
1341 * speed and duplex for copper connections.
1343 s32
e1000e_get_speed_and_duplex_copper(struct e1000_hw
*hw
, u16
*speed
,
1348 status
= er32(STATUS
);
1349 if (status
& E1000_STATUS_SPEED_1000
) {
1350 *speed
= SPEED_1000
;
1351 e_dbg("1000 Mbs, ");
1352 } else if (status
& E1000_STATUS_SPEED_100
) {
1360 if (status
& E1000_STATUS_FD
) {
1361 *duplex
= FULL_DUPLEX
;
1362 e_dbg("Full Duplex\n");
1364 *duplex
= HALF_DUPLEX
;
1365 e_dbg("Half Duplex\n");
1368 return E1000_SUCCESS
;
1372 * e1000e_get_speed_and_duplex_fiber_generic - Retrieve current speed/duplex
1373 * @hw: pointer to the HW structure
1374 * @speed: stores the current speed
1375 * @duplex: stores the current duplex
1377 * Sets the speed and duplex to gigabit full duplex (the only possible option)
1378 * for fiber/serdes links.
1380 s32
e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw
*hw __unused
,
1381 u16
*speed
, u16
*duplex
)
1383 *speed
= SPEED_1000
;
1384 *duplex
= FULL_DUPLEX
;
1386 return E1000_SUCCESS
;
1390 * e1000e_get_hw_semaphore - Acquire hardware semaphore
1391 * @hw: pointer to the HW structure
1393 * Acquire the HW semaphore to access the PHY or NVM
1395 s32
e1000e_get_hw_semaphore(struct e1000_hw
*hw
)
1398 s32 ret_val
= E1000_SUCCESS
;
1399 s32 timeout
= hw
->nvm
.word_size
+ 1;
1402 /* Get the SW semaphore */
1403 while (i
< timeout
) {
1405 if (!(swsm
& E1000_SWSM_SMBI
))
1413 e_dbg("Driver can't access device - SMBI bit is set.\n");
1414 ret_val
= -E1000_ERR_NVM
;
1418 /* Get the FW semaphore. */
1419 for (i
= 0; i
< timeout
; i
++) {
1421 ew32(SWSM
, swsm
| E1000_SWSM_SWESMBI
);
1423 /* Semaphore acquired if bit latched */
1424 if (er32(SWSM
) & E1000_SWSM_SWESMBI
)
1431 /* Release semaphores */
1432 e1000e_put_hw_semaphore(hw
);
1433 e_dbg("Driver can't access the NVM\n");
1434 ret_val
= -E1000_ERR_NVM
;
1443 * e1000e_put_hw_semaphore - Release hardware semaphore
1444 * @hw: pointer to the HW structure
1446 * Release hardware semaphore used to access the PHY or NVM
1448 void e1000e_put_hw_semaphore(struct e1000_hw
*hw
)
1453 swsm
&= ~(E1000_SWSM_SMBI
| E1000_SWSM_SWESMBI
);
1457 * e1000e_get_auto_rd_done - Check for auto read completion
1458 * @hw: pointer to the HW structure
1460 * Check EEPROM for Auto Read done bit.
1462 s32
e1000e_get_auto_rd_done(struct e1000_hw
*hw
)
1465 s32 ret_val
= E1000_SUCCESS
;
1467 while (i
< AUTO_READ_DONE_TIMEOUT
) {
1468 if (er32(EECD
) & E1000_EECD_AUTO_RD
)
1474 if (i
== AUTO_READ_DONE_TIMEOUT
) {
1475 e_dbg("Auto read by HW from NVM has not completed.\n");
1476 ret_val
= -E1000_ERR_RESET
;
1485 * e1000e_valid_led_default - Verify a valid default LED config
1486 * @hw: pointer to the HW structure
1487 * @data: pointer to the NVM (EEPROM)
1489 * Read the EEPROM for the current default LED configuration. If the
1490 * LED configuration is not valid, set to a valid LED configuration.
1492 s32
e1000e_valid_led_default(struct e1000_hw
*hw
, u16
*data
)
1496 ret_val
= e1000e_read_nvm(hw
, NVM_ID_LED_SETTINGS
, 1, data
);
1498 e_dbg("NVM Read Error\n");
1502 if (*data
== ID_LED_RESERVED_0000
|| *data
== ID_LED_RESERVED_FFFF
)
1503 *data
= ID_LED_DEFAULT
;
1510 * e1000e_id_led_init -
1511 * @hw: pointer to the HW structure
1514 s32
e1000e_id_led_init(struct e1000_hw
*hw __unused
)
1517 struct e1000_mac_info
*mac
= &hw
->mac
;
1519 const u32 ledctl_mask
= 0x000000FF;
1520 const u32 ledctl_on
= E1000_LEDCTL_MODE_LED_ON
;
1521 const u32 ledctl_off
= E1000_LEDCTL_MODE_LED_OFF
;
1523 const u16 led_mask
= 0x0F;
1525 ret_val
= hw
->nvm
.ops
.valid_led_default(hw
, &data
);
1529 mac
->ledctl_default
= er32(LEDCTL
);
1530 mac
->ledctl_mode1
= mac
->ledctl_default
;
1531 mac
->ledctl_mode2
= mac
->ledctl_default
;
1533 for (i
= 0; i
< 4; i
++) {
1534 temp
= (data
>> (i
<< 2)) & led_mask
;
1536 case ID_LED_ON1_DEF2
:
1537 case ID_LED_ON1_ON2
:
1538 case ID_LED_ON1_OFF2
:
1539 mac
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
1540 mac
->ledctl_mode1
|= ledctl_on
<< (i
<< 3);
1542 case ID_LED_OFF1_DEF2
:
1543 case ID_LED_OFF1_ON2
:
1544 case ID_LED_OFF1_OFF2
:
1545 mac
->ledctl_mode1
&= ~(ledctl_mask
<< (i
<< 3));
1546 mac
->ledctl_mode1
|= ledctl_off
<< (i
<< 3);
1553 case ID_LED_DEF1_ON2
:
1554 case ID_LED_ON1_ON2
:
1555 case ID_LED_OFF1_ON2
:
1556 mac
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
1557 mac
->ledctl_mode2
|= ledctl_on
<< (i
<< 3);
1559 case ID_LED_DEF1_OFF2
:
1560 case ID_LED_ON1_OFF2
:
1561 case ID_LED_OFF1_OFF2
:
1562 mac
->ledctl_mode2
&= ~(ledctl_mask
<< (i
<< 3));
1563 mac
->ledctl_mode2
|= ledctl_off
<< (i
<< 3);
1574 return E1000_SUCCESS
;
1578 * e1000e_setup_led_generic - Configures SW controllable LED
1579 * @hw: pointer to the HW structure
1581 * This prepares the SW controllable LED for use and saves the current state
1582 * of the LED so it can be later restored.
1584 s32
e1000e_setup_led_generic(struct e1000_hw
*hw __unused
)
1588 s32 ret_val
= E1000_SUCCESS
;
1590 if (hw
->mac
.ops
.setup_led
!= e1000e_setup_led_generic
) {
1591 ret_val
= -E1000_ERR_CONFIG
;
1595 if (hw
->phy
.media_type
== e1000_media_type_fiber
) {
1596 ledctl
= er32(LEDCTL
);
1597 hw
->mac
.ledctl_default
= ledctl
;
1599 ledctl
&= ~(E1000_LEDCTL_LED0_IVRT
|
1600 E1000_LEDCTL_LED0_BLINK
|
1601 E1000_LEDCTL_LED0_MODE_MASK
);
1602 ledctl
|= (E1000_LEDCTL_MODE_LED_OFF
<<
1603 E1000_LEDCTL_LED0_MODE_SHIFT
);
1604 ew32(LEDCTL
, ledctl
);
1605 } else if (hw
->phy
.media_type
== e1000_media_type_copper
) {
1606 ew32(LEDCTL
, hw
->mac
.ledctl_mode1
);
1612 return E1000_SUCCESS
;
1616 * e1000e_cleanup_led_generic - Set LED config to default operation
1617 * @hw: pointer to the HW structure
1619 * Remove the current LED configuration and set the LED configuration
1620 * to the default value, saved from the EEPROM.
1622 s32
e1000e_cleanup_led_generic(struct e1000_hw
*hw __unused
)
1625 s32 ret_val
= E1000_SUCCESS
;
1627 if (hw
->mac
.ops
.cleanup_led
!= e1000e_cleanup_led_generic
) {
1628 ret_val
= -E1000_ERR_CONFIG
;
1632 ew32(LEDCTL
, hw
->mac
.ledctl_default
);
1637 return E1000_SUCCESS
;
1641 * e1000e_blink_led - Blink LED
1642 * @hw: pointer to the HW structure
1644 * Blink the LEDs which are set to be on.
1646 s32
e1000e_blink_led(struct e1000_hw
*hw __unused
)
1649 u32 ledctl_blink
= 0;
1652 if (hw
->phy
.media_type
== e1000_media_type_fiber
) {
1653 /* always blink LED0 for PCI-E fiber */
1654 ledctl_blink
= E1000_LEDCTL_LED0_BLINK
|
1655 (E1000_LEDCTL_MODE_LED_ON
<< E1000_LEDCTL_LED0_MODE_SHIFT
);
1658 * set the blink bit for each LED that's "on" (0x0E)
1661 ledctl_blink
= hw
->mac
.ledctl_mode2
;
1662 for (i
= 0; i
< 4; i
++)
1663 if (((hw
->mac
.ledctl_mode2
>> (i
* 8)) & 0xFF) ==
1664 E1000_LEDCTL_MODE_LED_ON
)
1665 ledctl_blink
|= (E1000_LEDCTL_LED0_BLINK
<<
1669 ew32(LEDCTL
, ledctl_blink
);
1671 return E1000_SUCCESS
;
1675 * e1000e_led_on_generic - Turn LED on
1676 * @hw: pointer to the HW structure
1680 s32
e1000e_led_on_generic(struct e1000_hw
*hw __unused
)
1685 switch (hw
->phy
.media_type
) {
1686 case e1000_media_type_fiber
:
1688 ctrl
&= ~E1000_CTRL_SWDPIN0
;
1689 ctrl
|= E1000_CTRL_SWDPIO0
;
1692 case e1000_media_type_copper
:
1693 ew32(LEDCTL
, hw
->mac
.ledctl_mode2
);
1699 return E1000_SUCCESS
;
1703 * e1000e_led_off_generic - Turn LED off
1704 * @hw: pointer to the HW structure
1708 s32
e1000e_led_off_generic(struct e1000_hw
*hw __unused
)
1713 switch (hw
->phy
.media_type
) {
1714 case e1000_media_type_fiber
:
1716 ctrl
|= E1000_CTRL_SWDPIN0
;
1717 ctrl
|= E1000_CTRL_SWDPIO0
;
1720 case e1000_media_type_copper
:
1721 ew32(LEDCTL
, hw
->mac
.ledctl_mode1
);
1727 return E1000_SUCCESS
;
1731 * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
1732 * @hw: pointer to the HW structure
1733 * @no_snoop: bitmap of snoop events
1735 * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
1737 void e1000e_set_pcie_no_snoop(struct e1000_hw
*hw
, u32 no_snoop
)
1741 if (hw
->bus
.type
!= e1000_bus_type_pci_express
)
1746 gcr
&= ~(PCIE_NO_SNOOP_ALL
);
1755 * e1000e_disable_pcie_master - Disables PCI-express master access
1756 * @hw: pointer to the HW structure
1758 * Returns 0 (E1000_SUCCESS) if successful, else returns -10
1759 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
1760 * the master requests to be disabled.
1762 * Disables PCI-Express master access and verifies there are no pending
1765 s32
e1000e_disable_pcie_master(struct e1000_hw
*hw
)
1768 s32 timeout
= MASTER_DISABLE_TIMEOUT
;
1769 s32 ret_val
= E1000_SUCCESS
;
1771 if (hw
->bus
.type
!= e1000_bus_type_pci_express
)
1775 ctrl
|= E1000_CTRL_GIO_MASTER_DISABLE
;
1779 if (!(er32(STATUS
) &
1780 E1000_STATUS_GIO_MASTER_ENABLE
))
1787 e_dbg("Master requests are pending.\n");
1788 ret_val
= -E1000_ERR_MASTER_REQUESTS_PENDING
;
1797 * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
1798 * @hw: pointer to the HW structure
1800 * Reset the Adaptive Interframe Spacing throttle to default values.
1802 void e1000e_reset_adaptive(struct e1000_hw
*hw
)
1804 struct e1000_mac_info
*mac
= &hw
->mac
;
1806 if (!mac
->adaptive_ifs
) {
1807 e_dbg("Not in Adaptive IFS mode!\n");
1811 mac
->current_ifs_val
= 0;
1812 mac
->ifs_min_val
= IFS_MIN
;
1813 mac
->ifs_max_val
= IFS_MAX
;
1814 mac
->ifs_step_size
= IFS_STEP
;
1815 mac
->ifs_ratio
= IFS_RATIO
;
1817 mac
->in_ifs_mode
= false;
1824 * e1000e_update_adaptive - Update Adaptive Interframe Spacing
1825 * @hw: pointer to the HW structure
1827 * Update the Adaptive Interframe Spacing Throttle value based on the
1828 * time between transmitted packets and time between collisions.
1830 void e1000e_update_adaptive(struct e1000_hw
*hw
)
1832 struct e1000_mac_info
*mac
= &hw
->mac
;
1834 if (!mac
->adaptive_ifs
) {
1835 e_dbg("Not in Adaptive IFS mode!\n");
1839 if ((mac
->collision_delta
* mac
->ifs_ratio
) > mac
->tx_packet_delta
) {
1840 if (mac
->tx_packet_delta
> MIN_NUM_XMITS
) {
1841 mac
->in_ifs_mode
= true;
1842 if (mac
->current_ifs_val
< mac
->ifs_max_val
) {
1843 if (!mac
->current_ifs_val
)
1844 mac
->current_ifs_val
= mac
->ifs_min_val
;
1846 mac
->current_ifs_val
+=
1848 ew32(AIT
, mac
->current_ifs_val
);
1852 if (mac
->in_ifs_mode
&&
1853 (mac
->tx_packet_delta
<= MIN_NUM_XMITS
)) {
1854 mac
->current_ifs_val
= 0;
1855 mac
->in_ifs_mode
= false;
1864 * e1000e_validate_mdi_setting_generic - Verify MDI/MDIx settings
1865 * @hw: pointer to the HW structure
1867 * Verify that when not using auto-negotiation that MDI/MDIx is correctly
1868 * set, which is forced to MDI mode only.
1870 static s32
e1000e_validate_mdi_setting_generic(struct e1000_hw
*hw
)
1872 s32 ret_val
= E1000_SUCCESS
;
1874 if (!hw
->mac
.autoneg
&& (hw
->phy
.mdix
== 0 || hw
->phy
.mdix
== 3)) {
1875 e_dbg("Invalid MDI setting detected\n");
1877 ret_val
= -E1000_ERR_CONFIG
;