1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 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
30 * Shared functions for accessing and configuring the MAC
35 static s32 e1000_check_downshift(struct e1000_hw *hw);
36 static s32 e1000_check_polarity(struct e1000_hw *hw,
37 e1000_rev_polarity *polarity);
38 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
39 static void e1000_clear_vfta(struct e1000_hw *hw);
40 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
42 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
43 static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
44 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
45 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
47 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
48 static s32 e1000_id_led_init(struct e1000_hw *hw);
49 static void e1000_init_rx_addrs(struct e1000_hw *hw);
50 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
51 struct e1000_phy_info *phy_info);
52 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
53 struct e1000_phy_info *phy_info);
54 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
55 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
56 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
57 static s32 e1000_set_phy_type(struct e1000_hw *hw);
58 static void e1000_phy_init_script(struct e1000_hw *hw);
59 static s32 e1000_setup_copper_link(struct e1000_hw *hw);
60 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
61 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
62 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
63 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
64 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
65 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
66 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
67 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
68 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
69 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
70 u16 words, u16 *data);
71 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
72 u16 words, u16 *data);
73 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
74 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
75 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
76 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
77 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
79 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
81 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
82 static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
83 static void e1000_release_eeprom(struct e1000_hw *hw);
84 static void e1000_standby_eeprom(struct e1000_hw *hw);
85 static s32 e1000_set_vco_speed(struct e1000_hw *hw);
86 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
87 static s32 e1000_set_phy_mode(struct e1000_hw *hw);
88 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
90 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
93 /* IGP cable length table */
95 u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
96 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
97 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
98 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
99 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
100 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
101 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
103 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
105 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
109 static DEFINE_SPINLOCK(e1000_eeprom_lock);
110 static DEFINE_SPINLOCK(e1000_phy_lock);
113 * e1000_set_phy_type - Set the phy type member in the hw struct.
114 * @hw: Struct containing variables accessed by shared code
116 static s32 e1000_set_phy_type(struct e1000_hw *hw)
118 e_dbg("e1000_set_phy_type");
120 if (hw->mac_type == e1000_undefined)
121 return -E1000_ERR_PHY_TYPE;
123 switch (hw->phy_id) {
124 case M88E1000_E_PHY_ID:
125 case M88E1000_I_PHY_ID:
126 case M88E1011_I_PHY_ID:
127 case M88E1111_I_PHY_ID:
128 case M88E1118_E_PHY_ID:
129 hw->phy_type = e1000_phy_m88;
131 case IGP01E1000_I_PHY_ID:
132 if (hw->mac_type == e1000_82541 ||
133 hw->mac_type == e1000_82541_rev_2 ||
134 hw->mac_type == e1000_82547 ||
135 hw->mac_type == e1000_82547_rev_2)
136 hw->phy_type = e1000_phy_igp;
138 case RTL8211B_PHY_ID:
139 hw->phy_type = e1000_phy_8211;
141 case RTL8201N_PHY_ID:
142 hw->phy_type = e1000_phy_8201;
145 /* Should never have loaded on this device */
146 hw->phy_type = e1000_phy_undefined;
147 return -E1000_ERR_PHY_TYPE;
150 return E1000_SUCCESS;
154 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
155 * @hw: Struct containing variables accessed by shared code
157 static void e1000_phy_init_script(struct e1000_hw *hw)
162 e_dbg("e1000_phy_init_script");
164 if (hw->phy_init_script) {
167 /* Save off the current value of register 0x2F5B to be restored
168 * at the end of this routine.
170 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
172 /* Disabled the PHY transmitter */
173 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
176 e1000_write_phy_reg(hw, 0x0000, 0x0140);
179 switch (hw->mac_type) {
182 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
183 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
184 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
185 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
186 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
187 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
188 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
189 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
190 e1000_write_phy_reg(hw, 0x2010, 0x0008);
193 case e1000_82541_rev_2:
194 case e1000_82547_rev_2:
195 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
201 e1000_write_phy_reg(hw, 0x0000, 0x3300);
204 /* Now enable the transmitter */
205 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
207 if (hw->mac_type == e1000_82547) {
208 u16 fused, fine, coarse;
210 /* Move to analog registers page */
211 e1000_read_phy_reg(hw,
212 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
215 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
216 e1000_read_phy_reg(hw,
217 IGP01E1000_ANALOG_FUSE_STATUS,
220 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
222 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
225 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
227 IGP01E1000_ANALOG_FUSE_COARSE_10;
228 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
230 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
231 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
234 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
235 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
237 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
239 e1000_write_phy_reg(hw,
240 IGP01E1000_ANALOG_FUSE_CONTROL,
242 e1000_write_phy_reg(hw,
243 IGP01E1000_ANALOG_FUSE_BYPASS,
244 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
251 * e1000_set_mac_type - Set the mac type member in the hw struct.
252 * @hw: Struct containing variables accessed by shared code
254 s32 e1000_set_mac_type(struct e1000_hw *hw)
256 e_dbg("e1000_set_mac_type");
258 switch (hw->device_id) {
259 case E1000_DEV_ID_82542:
260 switch (hw->revision_id) {
261 case E1000_82542_2_0_REV_ID:
262 hw->mac_type = e1000_82542_rev2_0;
264 case E1000_82542_2_1_REV_ID:
265 hw->mac_type = e1000_82542_rev2_1;
268 /* Invalid 82542 revision ID */
269 return -E1000_ERR_MAC_TYPE;
272 case E1000_DEV_ID_82543GC_FIBER:
273 case E1000_DEV_ID_82543GC_COPPER:
274 hw->mac_type = e1000_82543;
276 case E1000_DEV_ID_82544EI_COPPER:
277 case E1000_DEV_ID_82544EI_FIBER:
278 case E1000_DEV_ID_82544GC_COPPER:
279 case E1000_DEV_ID_82544GC_LOM:
280 hw->mac_type = e1000_82544;
282 case E1000_DEV_ID_82540EM:
283 case E1000_DEV_ID_82540EM_LOM:
284 case E1000_DEV_ID_82540EP:
285 case E1000_DEV_ID_82540EP_LOM:
286 case E1000_DEV_ID_82540EP_LP:
287 hw->mac_type = e1000_82540;
289 case E1000_DEV_ID_82545EM_COPPER:
290 case E1000_DEV_ID_82545EM_FIBER:
291 hw->mac_type = e1000_82545;
293 case E1000_DEV_ID_82545GM_COPPER:
294 case E1000_DEV_ID_82545GM_FIBER:
295 case E1000_DEV_ID_82545GM_SERDES:
296 hw->mac_type = e1000_82545_rev_3;
298 case E1000_DEV_ID_82546EB_COPPER:
299 case E1000_DEV_ID_82546EB_FIBER:
300 case E1000_DEV_ID_82546EB_QUAD_COPPER:
301 hw->mac_type = e1000_82546;
303 case E1000_DEV_ID_82546GB_COPPER:
304 case E1000_DEV_ID_82546GB_FIBER:
305 case E1000_DEV_ID_82546GB_SERDES:
306 case E1000_DEV_ID_82546GB_PCIE:
307 case E1000_DEV_ID_82546GB_QUAD_COPPER:
308 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
309 hw->mac_type = e1000_82546_rev_3;
311 case E1000_DEV_ID_82541EI:
312 case E1000_DEV_ID_82541EI_MOBILE:
313 case E1000_DEV_ID_82541ER_LOM:
314 hw->mac_type = e1000_82541;
316 case E1000_DEV_ID_82541ER:
317 case E1000_DEV_ID_82541GI:
318 case E1000_DEV_ID_82541GI_LF:
319 case E1000_DEV_ID_82541GI_MOBILE:
320 hw->mac_type = e1000_82541_rev_2;
322 case E1000_DEV_ID_82547EI:
323 case E1000_DEV_ID_82547EI_MOBILE:
324 hw->mac_type = e1000_82547;
326 case E1000_DEV_ID_82547GI:
327 hw->mac_type = e1000_82547_rev_2;
329 case E1000_DEV_ID_INTEL_CE4100_GBE:
330 hw->mac_type = e1000_ce4100;
333 /* Should never have loaded on this device */
334 return -E1000_ERR_MAC_TYPE;
337 switch (hw->mac_type) {
340 case e1000_82541_rev_2:
341 case e1000_82547_rev_2:
342 hw->asf_firmware_present = true;
348 /* The 82543 chip does not count tx_carrier_errors properly in
351 if (hw->mac_type == e1000_82543)
352 hw->bad_tx_carr_stats_fd = true;
354 if (hw->mac_type > e1000_82544)
355 hw->has_smbus = true;
357 return E1000_SUCCESS;
361 * e1000_set_media_type - Set media type and TBI compatibility.
362 * @hw: Struct containing variables accessed by shared code
364 void e1000_set_media_type(struct e1000_hw *hw)
368 e_dbg("e1000_set_media_type");
370 if (hw->mac_type != e1000_82543) {
371 /* tbi_compatibility is only valid on 82543 */
372 hw->tbi_compatibility_en = false;
375 switch (hw->device_id) {
376 case E1000_DEV_ID_82545GM_SERDES:
377 case E1000_DEV_ID_82546GB_SERDES:
378 hw->media_type = e1000_media_type_internal_serdes;
381 switch (hw->mac_type) {
382 case e1000_82542_rev2_0:
383 case e1000_82542_rev2_1:
384 hw->media_type = e1000_media_type_fiber;
387 hw->media_type = e1000_media_type_copper;
390 status = er32(STATUS);
391 if (status & E1000_STATUS_TBIMODE) {
392 hw->media_type = e1000_media_type_fiber;
393 /* tbi_compatibility not valid on fiber */
394 hw->tbi_compatibility_en = false;
396 hw->media_type = e1000_media_type_copper;
404 * e1000_reset_hw - reset the hardware completely
405 * @hw: Struct containing variables accessed by shared code
407 * Reset the transmit and receive units; mask and clear all interrupts.
409 s32 e1000_reset_hw(struct e1000_hw *hw)
418 e_dbg("e1000_reset_hw");
420 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
421 if (hw->mac_type == e1000_82542_rev2_0) {
422 e_dbg("Disabling MWI on 82542 rev 2.0\n");
423 e1000_pci_clear_mwi(hw);
426 /* Clear interrupt mask to stop board from generating interrupts */
427 e_dbg("Masking off all interrupts\n");
428 ew32(IMC, 0xffffffff);
430 /* Disable the Transmit and Receive units. Then delay to allow
431 * any pending transactions to complete before we hit the MAC with
435 ew32(TCTL, E1000_TCTL_PSP);
438 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
439 hw->tbi_compatibility_on = false;
441 /* Delay to allow any outstanding PCI transactions to complete before
442 * resetting the device
448 /* Must reset the PHY before resetting the MAC */
449 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
450 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
455 /* Issue a global reset to the MAC. This will reset the chip's
456 * transmit, receive, DMA, and link units. It will not effect
457 * the current PCI configuration. The global reset bit is self-
458 * clearing, and should clear within a microsecond.
460 e_dbg("Issuing a global reset to MAC\n");
462 switch (hw->mac_type) {
468 case e1000_82541_rev_2:
469 /* These controllers can't ack the 64-bit write when issuing the
470 * reset, so use IO-mapping as a workaround to issue the reset
472 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
474 case e1000_82545_rev_3:
475 case e1000_82546_rev_3:
476 /* Reset is performed on a shadow of the control register */
477 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
481 ew32(CTRL, (ctrl | E1000_CTRL_RST));
485 /* After MAC reset, force reload of EEPROM to restore power-on settings
486 * to device. Later controllers reload the EEPROM automatically, so
487 * just wait for reload to complete.
489 switch (hw->mac_type) {
490 case e1000_82542_rev2_0:
491 case e1000_82542_rev2_1:
494 /* Wait for reset to complete */
496 ctrl_ext = er32(CTRL_EXT);
497 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
498 ew32(CTRL_EXT, ctrl_ext);
500 /* Wait for EEPROM reload */
504 case e1000_82541_rev_2:
506 case e1000_82547_rev_2:
507 /* Wait for EEPROM reload */
511 /* Auto read done will delay 5ms or poll based on mac type */
512 ret_val = e1000_get_auto_rd_done(hw);
518 /* Disable HW ARPs on ASF enabled adapters */
519 if (hw->mac_type >= e1000_82540) {
521 manc &= ~(E1000_MANC_ARP_EN);
525 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
526 e1000_phy_init_script(hw);
528 /* Configure activity LED after PHY reset */
529 led_ctrl = er32(LEDCTL);
530 led_ctrl &= IGP_ACTIVITY_LED_MASK;
531 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
532 ew32(LEDCTL, led_ctrl);
535 /* Clear interrupt mask to stop board from generating interrupts */
536 e_dbg("Masking off all interrupts\n");
537 ew32(IMC, 0xffffffff);
539 /* Clear any pending interrupt events. */
542 /* If MWI was previously enabled, reenable it. */
543 if (hw->mac_type == e1000_82542_rev2_0) {
544 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
545 e1000_pci_set_mwi(hw);
548 return E1000_SUCCESS;
552 * e1000_init_hw - Performs basic configuration of the adapter.
553 * @hw: Struct containing variables accessed by shared code
555 * Assumes that the controller has previously been reset and is in a
556 * post-reset uninitialized state. Initializes the receive address registers,
557 * multicast table, and VLAN filter table. Calls routines to setup link
558 * configuration and flow control settings. Clears all on-chip counters. Leaves
559 * the transmit and receive units disabled and uninitialized.
561 s32 e1000_init_hw(struct e1000_hw *hw)
569 e_dbg("e1000_init_hw");
571 /* Initialize Identification LED */
572 ret_val = e1000_id_led_init(hw);
574 e_dbg("Error Initializing Identification LED\n");
578 /* Set the media type and TBI compatibility */
579 e1000_set_media_type(hw);
581 /* Disabling VLAN filtering. */
582 e_dbg("Initializing the IEEE VLAN\n");
583 if (hw->mac_type < e1000_82545_rev_3)
585 e1000_clear_vfta(hw);
587 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
588 if (hw->mac_type == e1000_82542_rev2_0) {
589 e_dbg("Disabling MWI on 82542 rev 2.0\n");
590 e1000_pci_clear_mwi(hw);
591 ew32(RCTL, E1000_RCTL_RST);
596 /* Setup the receive address. This involves initializing all of the
597 * Receive Address Registers (RARs 0 - 15).
599 e1000_init_rx_addrs(hw);
601 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
602 if (hw->mac_type == e1000_82542_rev2_0) {
606 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
607 e1000_pci_set_mwi(hw);
610 /* Zero out the Multicast HASH table */
611 e_dbg("Zeroing the MTA\n");
612 mta_size = E1000_MC_TBL_SIZE;
613 for (i = 0; i < mta_size; i++) {
614 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
615 /* use write flush to prevent Memory Write Block (MWB) from
616 * occurring when accessing our register space
621 /* Set the PCI priority bit correctly in the CTRL register. This
622 * determines if the adapter gives priority to receives, or if it
623 * gives equal priority to transmits and receives. Valid only on
624 * 82542 and 82543 silicon.
626 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
628 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
631 switch (hw->mac_type) {
632 case e1000_82545_rev_3:
633 case e1000_82546_rev_3:
636 /* Workaround for PCI-X problem when BIOS sets MMRBC
639 if (hw->bus_type == e1000_bus_type_pcix
640 && e1000_pcix_get_mmrbc(hw) > 2048)
641 e1000_pcix_set_mmrbc(hw, 2048);
645 /* Call a subroutine to configure the link and setup flow control. */
646 ret_val = e1000_setup_link(hw);
648 /* Set the transmit descriptor write-back policy */
649 if (hw->mac_type > e1000_82544) {
652 (ctrl & ~E1000_TXDCTL_WTHRESH) |
653 E1000_TXDCTL_FULL_TX_DESC_WB;
657 /* Clear all of the statistics registers (clear on read). It is
658 * important that we do this after we have tried to establish link
659 * because the symbol error count will increment wildly if there
662 e1000_clear_hw_cntrs(hw);
664 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
665 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
666 ctrl_ext = er32(CTRL_EXT);
667 /* Relaxed ordering must be disabled to avoid a parity
668 * error crash in a PCI slot.
670 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
671 ew32(CTRL_EXT, ctrl_ext);
678 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
679 * @hw: Struct containing variables accessed by shared code.
681 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
686 e_dbg("e1000_adjust_serdes_amplitude");
688 if (hw->media_type != e1000_media_type_internal_serdes)
689 return E1000_SUCCESS;
691 switch (hw->mac_type) {
692 case e1000_82545_rev_3:
693 case e1000_82546_rev_3:
696 return E1000_SUCCESS;
699 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
705 if (eeprom_data != EEPROM_RESERVED_WORD) {
706 /* Adjust SERDES output amplitude only. */
707 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
709 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
714 return E1000_SUCCESS;
718 * e1000_setup_link - Configures flow control and link settings.
719 * @hw: Struct containing variables accessed by shared code
721 * Determines which flow control settings to use. Calls the appropriate media-
722 * specific link configuration function. Configures the flow control settings.
723 * Assuming the adapter has a valid link partner, a valid link should be
724 * established. Assumes the hardware has previously been reset and the
725 * transmitter and receiver are not enabled.
727 s32 e1000_setup_link(struct e1000_hw *hw)
733 e_dbg("e1000_setup_link");
735 /* Read and store word 0x0F of the EEPROM. This word contains bits
736 * that determine the hardware's default PAUSE (flow control) mode,
737 * a bit that determines whether the HW defaults to enabling or
738 * disabling auto-negotiation, and the direction of the
739 * SW defined pins. If there is no SW over-ride of the flow
740 * control setting, then the variable hw->fc will
741 * be initialized based on a value in the EEPROM.
743 if (hw->fc == E1000_FC_DEFAULT) {
744 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
747 e_dbg("EEPROM Read Error\n");
748 return -E1000_ERR_EEPROM;
750 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
751 hw->fc = E1000_FC_NONE;
752 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
753 EEPROM_WORD0F_ASM_DIR)
754 hw->fc = E1000_FC_TX_PAUSE;
756 hw->fc = E1000_FC_FULL;
759 /* We want to save off the original Flow Control configuration just
760 * in case we get disconnected and then reconnected into a different
761 * hub or switch with different Flow Control capabilities.
763 if (hw->mac_type == e1000_82542_rev2_0)
764 hw->fc &= (~E1000_FC_TX_PAUSE);
766 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
767 hw->fc &= (~E1000_FC_RX_PAUSE);
769 hw->original_fc = hw->fc;
771 e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
773 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
774 * polarity value for the SW controlled pins, and setup the
775 * Extended Device Control reg with that info.
776 * This is needed because one of the SW controlled pins is used for
777 * signal detection. So this should be done before e1000_setup_pcs_link()
778 * or e1000_phy_setup() is called.
780 if (hw->mac_type == e1000_82543) {
781 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
784 e_dbg("EEPROM Read Error\n");
785 return -E1000_ERR_EEPROM;
787 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
789 ew32(CTRL_EXT, ctrl_ext);
792 /* Call the necessary subroutine to configure the link. */
793 ret_val = (hw->media_type == e1000_media_type_copper) ?
794 e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
796 /* Initialize the flow control address, type, and PAUSE timer
797 * registers to their default values. This is done even if flow
798 * control is disabled, because it does not hurt anything to
799 * initialize these registers.
801 e_dbg("Initializing the Flow Control address, type and timer regs\n");
803 ew32(FCT, FLOW_CONTROL_TYPE);
804 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
805 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
807 ew32(FCTTV, hw->fc_pause_time);
809 /* Set the flow control receive threshold registers. Normally,
810 * these registers will be set to a default threshold that may be
811 * adjusted later by the driver's runtime code. However, if the
812 * ability to transmit pause frames in not enabled, then these
813 * registers will be set to 0.
815 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
819 /* We need to set up the Receive Threshold high and low water
820 * marks as well as (optionally) enabling the transmission of
823 if (hw->fc_send_xon) {
824 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
825 ew32(FCRTH, hw->fc_high_water);
827 ew32(FCRTL, hw->fc_low_water);
828 ew32(FCRTH, hw->fc_high_water);
835 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
836 * @hw: Struct containing variables accessed by shared code
838 * Manipulates Physical Coding Sublayer functions in order to configure
839 * link. Assumes the hardware has been previously reset and the transmitter
840 * and receiver are not enabled.
842 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
851 e_dbg("e1000_setup_fiber_serdes_link");
853 /* On adapters with a MAC newer than 82544, SWDP 1 will be
854 * set when the optics detect a signal. On older adapters, it will be
855 * cleared when there is a signal. This applies to fiber media only.
856 * If we're on serdes media, adjust the output amplitude to value
860 if (hw->media_type == e1000_media_type_fiber)
861 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
863 ret_val = e1000_adjust_serdes_amplitude(hw);
867 /* Take the link out of reset */
868 ctrl &= ~(E1000_CTRL_LRST);
870 /* Adjust VCO speed to improve BER performance */
871 ret_val = e1000_set_vco_speed(hw);
875 e1000_config_collision_dist(hw);
877 /* Check for a software override of the flow control settings, and setup
878 * the device accordingly. If auto-negotiation is enabled, then
879 * software will have to set the "PAUSE" bits to the correct value in
880 * the Tranmsit Config Word Register (TXCW) and re-start
881 * auto-negotiation. However, if auto-negotiation is disabled, then
882 * software will have to manually configure the two flow control enable
883 * bits in the CTRL register.
885 * The possible values of the "fc" parameter are:
886 * 0: Flow control is completely disabled
887 * 1: Rx flow control is enabled (we can receive pause frames, but
888 * not send pause frames).
889 * 2: Tx flow control is enabled (we can send pause frames but we do
890 * not support receiving pause frames).
891 * 3: Both Rx and TX flow control (symmetric) are enabled.
895 /* Flow ctrl is completely disabled by a software over-ride */
896 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
898 case E1000_FC_RX_PAUSE:
899 /* Rx Flow control is enabled and Tx Flow control is disabled by
900 * a software over-ride. Since there really isn't a way to
901 * advertise that we are capable of Rx Pause ONLY, we will
902 * advertise that we support both symmetric and asymmetric Rx
903 * PAUSE. Later, we will disable the adapter's ability to send
906 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
908 case E1000_FC_TX_PAUSE:
909 /* Tx Flow control is enabled, and Rx Flow control is disabled,
910 * by a software over-ride.
912 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
915 /* Flow control (both Rx and Tx) is enabled by a software
918 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
921 e_dbg("Flow control param set incorrectly\n");
922 return -E1000_ERR_CONFIG;
926 /* Since auto-negotiation is enabled, take the link out of reset (the
927 * link will be in reset, because we previously reset the chip). This
928 * will restart auto-negotiation. If auto-negotiation is successful
929 * then the link-up status bit will be set and the flow control enable
930 * bits (RFCE and TFCE) will be set according to their negotiated value.
932 e_dbg("Auto-negotiation enabled\n");
941 /* If we have a signal (the cable is plugged in) then poll for a
942 * "Link-Up" indication in the Device Status Register. Time-out if a
943 * link isn't seen in 500 milliseconds seconds (Auto-negotiation should
944 * complete in less than 500 milliseconds even if the other end is doing
945 * it in SW). For internal serdes, we just assume a signal is present,
948 if (hw->media_type == e1000_media_type_internal_serdes ||
949 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
950 e_dbg("Looking for Link\n");
951 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
953 status = er32(STATUS);
954 if (status & E1000_STATUS_LU)
957 if (i == (LINK_UP_TIMEOUT / 10)) {
958 e_dbg("Never got a valid link from auto-neg!!!\n");
959 hw->autoneg_failed = 1;
960 /* AutoNeg failed to achieve a link, so we'll call
961 * e1000_check_for_link. This routine will force the
962 * link up if we detect a signal. This will allow us to
963 * communicate with non-autonegotiating link partners.
965 ret_val = e1000_check_for_link(hw);
967 e_dbg("Error while checking for link\n");
970 hw->autoneg_failed = 0;
972 hw->autoneg_failed = 0;
973 e_dbg("Valid Link Found\n");
976 e_dbg("No Signal Detected\n");
978 return E1000_SUCCESS;
982 * e1000_copper_link_rtl_setup - Copper link setup for e1000_phy_rtl series.
983 * @hw: Struct containing variables accessed by shared code
985 * Commits changes to PHY configuration by calling e1000_phy_reset().
987 static s32 e1000_copper_link_rtl_setup(struct e1000_hw *hw)
991 /* SW reset the PHY so all changes take effect */
992 ret_val = e1000_phy_reset(hw);
994 e_dbg("Error Resetting the PHY\n");
998 return E1000_SUCCESS;
1001 static s32 gbe_dhg_phy_setup(struct e1000_hw *hw)
1006 switch (hw->phy_type) {
1007 case e1000_phy_8211:
1008 ret_val = e1000_copper_link_rtl_setup(hw);
1010 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1014 case e1000_phy_8201:
1016 ctrl_aux = er32(CTL_AUX);
1017 ctrl_aux |= E1000_CTL_AUX_RMII;
1018 ew32(CTL_AUX, ctrl_aux);
1019 E1000_WRITE_FLUSH();
1021 /* Disable the J/K bits required for receive */
1022 ctrl_aux = er32(CTL_AUX);
1025 ew32(CTL_AUX, ctrl_aux);
1026 E1000_WRITE_FLUSH();
1027 ret_val = e1000_copper_link_rtl_setup(hw);
1030 e_dbg("e1000_copper_link_rtl_setup failed!\n");
1035 e_dbg("Error Resetting the PHY\n");
1036 return E1000_ERR_PHY_TYPE;
1039 return E1000_SUCCESS;
1043 * e1000_copper_link_preconfig - early configuration for copper
1044 * @hw: Struct containing variables accessed by shared code
1046 * Make sure we have a valid PHY and change PHY mode before link setup.
1048 static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
1054 e_dbg("e1000_copper_link_preconfig");
1057 /* With 82543, we need to force speed and duplex on the MAC equal to
1058 * what the PHY speed and duplex configuration is. In addition, we need
1059 * to perform a hardware reset on the PHY to take it out of reset.
1061 if (hw->mac_type > e1000_82543) {
1062 ctrl |= E1000_CTRL_SLU;
1063 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1067 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1069 ret_val = e1000_phy_hw_reset(hw);
1074 /* Make sure we have a valid PHY */
1075 ret_val = e1000_detect_gig_phy(hw);
1077 e_dbg("Error, did not detect valid phy.\n");
1080 e_dbg("Phy ID = %x\n", hw->phy_id);
1082 /* Set PHY to class A mode (if necessary) */
1083 ret_val = e1000_set_phy_mode(hw);
1087 if ((hw->mac_type == e1000_82545_rev_3) ||
1088 (hw->mac_type == e1000_82546_rev_3)) {
1090 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1091 phy_data |= 0x00000008;
1093 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1096 if (hw->mac_type <= e1000_82543 ||
1097 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1098 hw->mac_type == e1000_82541_rev_2
1099 || hw->mac_type == e1000_82547_rev_2)
1100 hw->phy_reset_disable = false;
1102 return E1000_SUCCESS;
1106 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1107 * @hw: Struct containing variables accessed by shared code
1109 static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1115 e_dbg("e1000_copper_link_igp_setup");
1117 if (hw->phy_reset_disable)
1118 return E1000_SUCCESS;
1120 ret_val = e1000_phy_reset(hw);
1122 e_dbg("Error Resetting the PHY\n");
1126 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1128 /* Configure activity LED after PHY reset */
1129 led_ctrl = er32(LEDCTL);
1130 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1131 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1132 ew32(LEDCTL, led_ctrl);
1134 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1135 if (hw->phy_type == e1000_phy_igp) {
1136 /* disable lplu d3 during driver init */
1137 ret_val = e1000_set_d3_lplu_state(hw, false);
1139 e_dbg("Error Disabling LPLU D3\n");
1144 /* Configure mdi-mdix settings */
1145 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1149 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1150 hw->dsp_config_state = e1000_dsp_config_disabled;
1151 /* Force MDI for earlier revs of the IGP PHY */
1153 ~(IGP01E1000_PSCR_AUTO_MDIX |
1154 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1158 hw->dsp_config_state = e1000_dsp_config_enabled;
1159 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1163 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1166 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1170 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1174 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1178 /* set auto-master slave resolution settings */
1180 e1000_ms_type phy_ms_setting = hw->master_slave;
1182 if (hw->ffe_config_state == e1000_ffe_config_active)
1183 hw->ffe_config_state = e1000_ffe_config_enabled;
1185 if (hw->dsp_config_state == e1000_dsp_config_activated)
1186 hw->dsp_config_state = e1000_dsp_config_enabled;
1188 /* when autonegotiation advertisement is only 1000Mbps then we
1189 * should disable SmartSpeed and enable Auto MasterSlave
1190 * resolution as hardware default.
1192 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1193 /* Disable SmartSpeed */
1195 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1199 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1201 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1205 /* Set auto Master/Slave resolution process */
1207 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1210 phy_data &= ~CR_1000T_MS_ENABLE;
1212 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1217 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1221 /* load defaults for future use */
1222 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1223 ((phy_data & CR_1000T_MS_VALUE) ?
1224 e1000_ms_force_master :
1225 e1000_ms_force_slave) : e1000_ms_auto;
1227 switch (phy_ms_setting) {
1228 case e1000_ms_force_master:
1229 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1231 case e1000_ms_force_slave:
1232 phy_data |= CR_1000T_MS_ENABLE;
1233 phy_data &= ~(CR_1000T_MS_VALUE);
1236 phy_data &= ~CR_1000T_MS_ENABLE;
1240 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1245 return E1000_SUCCESS;
1249 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1250 * @hw: Struct containing variables accessed by shared code
1252 static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1257 e_dbg("e1000_copper_link_mgp_setup");
1259 if (hw->phy_reset_disable)
1260 return E1000_SUCCESS;
1262 /* Enable CRS on TX. This must be set for half-duplex operation. */
1263 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1267 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1270 * MDI/MDI-X = 0 (default)
1271 * 0 - Auto for all speeds
1274 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1276 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1280 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1283 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1286 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1290 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1295 * disable_polarity_correction = 0 (default)
1296 * Automatic Correction for Reversed Cable Polarity
1300 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1301 if (hw->disable_polarity_correction == 1)
1302 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1303 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1307 if (hw->phy_revision < M88E1011_I_REV_4) {
1308 /* Force TX_CLK in the Extended PHY Specific Control Register
1312 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1317 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1319 if ((hw->phy_revision == E1000_REVISION_2) &&
1320 (hw->phy_id == M88E1111_I_PHY_ID)) {
1321 /* Vidalia Phy, set the downshift counter to 5x */
1322 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1323 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1324 ret_val = e1000_write_phy_reg(hw,
1325 M88E1000_EXT_PHY_SPEC_CTRL,
1330 /* Configure Master and Slave downshift values */
1331 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1332 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1333 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1334 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1335 ret_val = e1000_write_phy_reg(hw,
1336 M88E1000_EXT_PHY_SPEC_CTRL,
1343 /* SW Reset the PHY so all changes take effect */
1344 ret_val = e1000_phy_reset(hw);
1346 e_dbg("Error Resetting the PHY\n");
1350 return E1000_SUCCESS;
1354 * e1000_copper_link_autoneg - setup auto-neg
1355 * @hw: Struct containing variables accessed by shared code
1357 * Setup auto-negotiation and flow control advertisements,
1358 * and then perform auto-negotiation.
1360 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1365 e_dbg("e1000_copper_link_autoneg");
1367 /* Perform some bounds checking on the hw->autoneg_advertised
1368 * parameter. If this variable is zero, then set it to the default.
1370 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1372 /* If autoneg_advertised is zero, we assume it was not defaulted
1373 * by the calling code so we set to advertise full capability.
1375 if (hw->autoneg_advertised == 0)
1376 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1378 /* IFE/RTL8201N PHY only supports 10/100 */
1379 if (hw->phy_type == e1000_phy_8201)
1380 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
1382 e_dbg("Reconfiguring auto-neg advertisement params\n");
1383 ret_val = e1000_phy_setup_autoneg(hw);
1385 e_dbg("Error Setting up Auto-Negotiation\n");
1388 e_dbg("Restarting Auto-Neg\n");
1390 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1391 * the Auto Neg Restart bit in the PHY control register.
1393 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1397 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1398 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1402 /* Does the user want to wait for Auto-Neg to complete here, or
1403 * check at a later time (for example, callback routine).
1405 if (hw->wait_autoneg_complete) {
1406 ret_val = e1000_wait_autoneg(hw);
1409 ("Error while waiting for autoneg to complete\n");
1414 hw->get_link_status = true;
1416 return E1000_SUCCESS;
1420 * e1000_copper_link_postconfig - post link setup
1421 * @hw: Struct containing variables accessed by shared code
1423 * Config the MAC and the PHY after link is up.
1424 * 1) Set up the MAC to the current PHY speed/duplex
1425 * if we are on 82543. If we
1426 * are on newer silicon, we only need to configure
1427 * collision distance in the Transmit Control Register.
1428 * 2) Set up flow control on the MAC to that established with
1430 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1432 static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
1435 e_dbg("e1000_copper_link_postconfig");
1437 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) {
1438 e1000_config_collision_dist(hw);
1440 ret_val = e1000_config_mac_to_phy(hw);
1442 e_dbg("Error configuring MAC to PHY settings\n");
1446 ret_val = e1000_config_fc_after_link_up(hw);
1448 e_dbg("Error Configuring Flow Control\n");
1452 /* Config DSP to improve Giga link quality */
1453 if (hw->phy_type == e1000_phy_igp) {
1454 ret_val = e1000_config_dsp_after_link_change(hw, true);
1456 e_dbg("Error Configuring DSP after link up\n");
1461 return E1000_SUCCESS;
1465 * e1000_setup_copper_link - phy/speed/duplex setting
1466 * @hw: Struct containing variables accessed by shared code
1468 * Detects which PHY is present and sets up the speed and duplex
1470 static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1476 e_dbg("e1000_setup_copper_link");
1478 /* Check if it is a valid PHY and set PHY mode if necessary. */
1479 ret_val = e1000_copper_link_preconfig(hw);
1483 if (hw->phy_type == e1000_phy_igp) {
1484 ret_val = e1000_copper_link_igp_setup(hw);
1487 } else if (hw->phy_type == e1000_phy_m88) {
1488 ret_val = e1000_copper_link_mgp_setup(hw);
1492 ret_val = gbe_dhg_phy_setup(hw);
1494 e_dbg("gbe_dhg_phy_setup failed!\n");
1500 /* Setup autoneg and flow control advertisement
1501 * and perform autonegotiation
1503 ret_val = e1000_copper_link_autoneg(hw);
1507 /* PHY will be set to 10H, 10F, 100H,or 100F
1508 * depending on value from forced_speed_duplex.
1510 e_dbg("Forcing speed and duplex\n");
1511 ret_val = e1000_phy_force_speed_duplex(hw);
1513 e_dbg("Error Forcing Speed and Duplex\n");
1518 /* Check link status. Wait up to 100 microseconds for link to become
1521 for (i = 0; i < 10; i++) {
1522 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1525 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1529 if (phy_data & MII_SR_LINK_STATUS) {
1530 /* Config the MAC and PHY after link is up */
1531 ret_val = e1000_copper_link_postconfig(hw);
1535 e_dbg("Valid link established!!!\n");
1536 return E1000_SUCCESS;
1541 e_dbg("Unable to establish link!!!\n");
1542 return E1000_SUCCESS;
1546 * e1000_phy_setup_autoneg - phy settings
1547 * @hw: Struct containing variables accessed by shared code
1549 * Configures PHY autoneg and flow control advertisement settings
1551 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1554 u16 mii_autoneg_adv_reg;
1555 u16 mii_1000t_ctrl_reg;
1557 e_dbg("e1000_phy_setup_autoneg");
1559 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1560 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1564 /* Read the MII 1000Base-T Control Register (Address 9). */
1565 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1568 else if (hw->phy_type == e1000_phy_8201)
1569 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1571 /* Need to parse both autoneg_advertised and fc and set up
1572 * the appropriate PHY registers. First we will parse for
1573 * autoneg_advertised software override. Since we can advertise
1574 * a plethora of combinations, we need to check each bit
1578 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1579 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1580 * the 1000Base-T Control Register (Address 9).
1582 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1583 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1585 e_dbg("autoneg_advertised %x\n", hw->autoneg_advertised);
1587 /* Do we want to advertise 10 Mb Half Duplex? */
1588 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1589 e_dbg("Advertise 10mb Half duplex\n");
1590 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1593 /* Do we want to advertise 10 Mb Full Duplex? */
1594 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1595 e_dbg("Advertise 10mb Full duplex\n");
1596 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1599 /* Do we want to advertise 100 Mb Half Duplex? */
1600 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1601 e_dbg("Advertise 100mb Half duplex\n");
1602 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1605 /* Do we want to advertise 100 Mb Full Duplex? */
1606 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1607 e_dbg("Advertise 100mb Full duplex\n");
1608 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1611 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1612 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1614 ("Advertise 1000mb Half duplex requested, request denied!\n");
1617 /* Do we want to advertise 1000 Mb Full Duplex? */
1618 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1619 e_dbg("Advertise 1000mb Full duplex\n");
1620 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1623 /* Check for a software override of the flow control settings, and
1624 * setup the PHY advertisement registers accordingly. If
1625 * auto-negotiation is enabled, then software will have to set the
1626 * "PAUSE" bits to the correct value in the Auto-Negotiation
1627 * Advertisement Register (PHY_AUTONEG_ADV) and re-start
1630 * The possible values of the "fc" parameter are:
1631 * 0: Flow control is completely disabled
1632 * 1: Rx flow control is enabled (we can receive pause frames
1633 * but not send pause frames).
1634 * 2: Tx flow control is enabled (we can send pause frames
1635 * but we do not support receiving pause frames).
1636 * 3: Both Rx and TX flow control (symmetric) are enabled.
1637 * other: No software override. The flow control configuration
1638 * in the EEPROM is used.
1641 case E1000_FC_NONE: /* 0 */
1642 /* Flow control (RX & TX) is completely disabled by a
1643 * software over-ride.
1645 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1647 case E1000_FC_RX_PAUSE: /* 1 */
1648 /* RX Flow control is enabled, and TX Flow control is
1649 * disabled, by a software over-ride.
1651 /* Since there really isn't a way to advertise that we are
1652 * capable of RX Pause ONLY, we will advertise that we
1653 * support both symmetric and asymmetric RX PAUSE. Later
1654 * (in e1000_config_fc_after_link_up) we will disable the
1655 * hw's ability to send PAUSE frames.
1657 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1659 case E1000_FC_TX_PAUSE: /* 2 */
1660 /* TX Flow control is enabled, and RX Flow control is
1661 * disabled, by a software over-ride.
1663 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1664 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1666 case E1000_FC_FULL: /* 3 */
1667 /* Flow control (both RX and TX) is enabled by a software
1670 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1673 e_dbg("Flow control param set incorrectly\n");
1674 return -E1000_ERR_CONFIG;
1677 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1681 e_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1683 if (hw->phy_type == e1000_phy_8201) {
1684 mii_1000t_ctrl_reg = 0;
1686 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
1687 mii_1000t_ctrl_reg);
1692 return E1000_SUCCESS;
1696 * e1000_phy_force_speed_duplex - force link settings
1697 * @hw: Struct containing variables accessed by shared code
1699 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1701 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1710 e_dbg("e1000_phy_force_speed_duplex");
1712 /* Turn off Flow control if we are forcing speed and duplex. */
1713 hw->fc = E1000_FC_NONE;
1715 e_dbg("hw->fc = %d\n", hw->fc);
1717 /* Read the Device Control Register. */
1720 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1721 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1722 ctrl &= ~(DEVICE_SPEED_MASK);
1724 /* Clear the Auto Speed Detect Enable bit. */
1725 ctrl &= ~E1000_CTRL_ASDE;
1727 /* Read the MII Control Register. */
1728 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1732 /* We need to disable autoneg in order to force link and duplex. */
1734 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1736 /* Are we forcing Full or Half Duplex? */
1737 if (hw->forced_speed_duplex == e1000_100_full ||
1738 hw->forced_speed_duplex == e1000_10_full) {
1739 /* We want to force full duplex so we SET the full duplex bits
1740 * in the Device and MII Control Registers.
1742 ctrl |= E1000_CTRL_FD;
1743 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1744 e_dbg("Full Duplex\n");
1746 /* We want to force half duplex so we CLEAR the full duplex bits
1747 * in the Device and MII Control Registers.
1749 ctrl &= ~E1000_CTRL_FD;
1750 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1751 e_dbg("Half Duplex\n");
1754 /* Are we forcing 100Mbps??? */
1755 if (hw->forced_speed_duplex == e1000_100_full ||
1756 hw->forced_speed_duplex == e1000_100_half) {
1757 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1758 ctrl |= E1000_CTRL_SPD_100;
1759 mii_ctrl_reg |= MII_CR_SPEED_100;
1760 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1761 e_dbg("Forcing 100mb ");
1763 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1764 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1765 mii_ctrl_reg |= MII_CR_SPEED_10;
1766 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1767 e_dbg("Forcing 10mb ");
1770 e1000_config_collision_dist(hw);
1772 /* Write the configured values back to the Device Control Reg. */
1775 if (hw->phy_type == e1000_phy_m88) {
1777 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1781 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires
1782 * MDI forced whenever speed are duplex are forced.
1784 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1786 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1790 e_dbg("M88E1000 PSCR: %x\n", phy_data);
1792 /* Need to reset the PHY or these changes will be ignored */
1793 mii_ctrl_reg |= MII_CR_RESET;
1795 /* Disable MDI-X support for 10/100 */
1797 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1798 * forced whenever speed or duplex are forced.
1801 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1805 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1806 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1809 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1814 /* Write back the modified PHY MII control register. */
1815 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1821 /* The wait_autoneg_complete flag may be a little misleading here.
1822 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1823 * But we do want to delay for a period while forcing only so we
1824 * don't generate false No Link messages. So we will wait here
1825 * only if the user has set wait_autoneg_complete to 1, which is
1828 if (hw->wait_autoneg_complete) {
1829 /* We will wait for autoneg to complete. */
1830 e_dbg("Waiting for forced speed/duplex link.\n");
1833 /* Wait for autoneg to complete or 4.5 seconds to expire */
1834 for (i = PHY_FORCE_TIME; i > 0; i--) {
1835 /* Read the MII Status Register and wait for Auto-Neg
1836 * Complete bit to be set.
1839 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1844 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1848 if (mii_status_reg & MII_SR_LINK_STATUS)
1852 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1853 /* We didn't get link. Reset the DSP and wait again
1856 ret_val = e1000_phy_reset_dsp(hw);
1858 e_dbg("Error Resetting PHY DSP\n");
1862 /* This loop will early-out if the link condition has been
1865 for (i = PHY_FORCE_TIME; i > 0; i--) {
1866 if (mii_status_reg & MII_SR_LINK_STATUS)
1869 /* Read the MII Status Register and wait for Auto-Neg
1870 * Complete bit to be set.
1873 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1878 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1884 if (hw->phy_type == e1000_phy_m88) {
1885 /* Because we reset the PHY above, we need to re-force TX_CLK in
1886 * the Extended PHY Specific Control Register to 25MHz clock.
1887 * This value defaults back to a 2.5MHz clock when the PHY is
1891 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1896 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1898 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1903 /* In addition, because of the s/w reset above, we need to
1904 * enable CRS on Tx. This must be set for both full and half
1908 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1912 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1914 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1918 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1920 && (hw->forced_speed_duplex == e1000_10_full
1921 || hw->forced_speed_duplex == e1000_10_half)) {
1922 ret_val = e1000_polarity_reversal_workaround(hw);
1927 return E1000_SUCCESS;
1931 * e1000_config_collision_dist - set collision distance register
1932 * @hw: Struct containing variables accessed by shared code
1934 * Sets the collision distance in the Transmit Control register.
1935 * Link should have been established previously. Reads the speed and duplex
1936 * information from the Device Status register.
1938 void e1000_config_collision_dist(struct e1000_hw *hw)
1940 u32 tctl, coll_dist;
1942 e_dbg("e1000_config_collision_dist");
1944 if (hw->mac_type < e1000_82543)
1945 coll_dist = E1000_COLLISION_DISTANCE_82542;
1947 coll_dist = E1000_COLLISION_DISTANCE;
1951 tctl &= ~E1000_TCTL_COLD;
1952 tctl |= coll_dist << E1000_COLD_SHIFT;
1955 E1000_WRITE_FLUSH();
1959 * e1000_config_mac_to_phy - sync phy and mac settings
1960 * @hw: Struct containing variables accessed by shared code
1961 * @mii_reg: data to write to the MII control register
1963 * Sets MAC speed and duplex settings to reflect the those in the PHY
1964 * The contents of the PHY register containing the needed information need to
1967 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
1973 e_dbg("e1000_config_mac_to_phy");
1975 /* 82544 or newer MAC, Auto Speed Detection takes care of
1976 * MAC speed/duplex configuration.
1978 if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100))
1979 return E1000_SUCCESS;
1981 /* Read the Device Control Register and set the bits to Force Speed
1985 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1986 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1988 switch (hw->phy_type) {
1989 case e1000_phy_8201:
1990 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1994 if (phy_data & RTL_PHY_CTRL_FD)
1995 ctrl |= E1000_CTRL_FD;
1997 ctrl &= ~E1000_CTRL_FD;
1999 if (phy_data & RTL_PHY_CTRL_SPD_100)
2000 ctrl |= E1000_CTRL_SPD_100;
2002 ctrl |= E1000_CTRL_SPD_10;
2004 e1000_config_collision_dist(hw);
2007 /* Set up duplex in the Device Control and Transmit Control
2008 * registers depending on negotiated values.
2010 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
2015 if (phy_data & M88E1000_PSSR_DPLX)
2016 ctrl |= E1000_CTRL_FD;
2018 ctrl &= ~E1000_CTRL_FD;
2020 e1000_config_collision_dist(hw);
2022 /* Set up speed in the Device Control register depending on
2023 * negotiated values.
2025 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
2026 ctrl |= E1000_CTRL_SPD_1000;
2027 else if ((phy_data & M88E1000_PSSR_SPEED) ==
2028 M88E1000_PSSR_100MBS)
2029 ctrl |= E1000_CTRL_SPD_100;
2032 /* Write the configured values back to the Device Control Reg. */
2034 return E1000_SUCCESS;
2038 * e1000_force_mac_fc - force flow control settings
2039 * @hw: Struct containing variables accessed by shared code
2041 * Forces the MAC's flow control settings.
2042 * Sets the TFCE and RFCE bits in the device control register to reflect
2043 * the adapter settings. TFCE and RFCE need to be explicitly set by
2044 * software when a Copper PHY is used because autonegotiation is managed
2045 * by the PHY rather than the MAC. Software must also configure these
2046 * bits when link is forced on a fiber connection.
2048 s32 e1000_force_mac_fc(struct e1000_hw *hw)
2052 e_dbg("e1000_force_mac_fc");
2054 /* Get the current configuration of the Device Control Register */
2057 /* Because we didn't get link via the internal auto-negotiation
2058 * mechanism (we either forced link or we got link via PHY
2059 * auto-neg), we have to manually enable/disable transmit an
2060 * receive flow control.
2062 * The "Case" statement below enables/disable flow control
2063 * according to the "hw->fc" parameter.
2065 * The possible values of the "fc" parameter are:
2066 * 0: Flow control is completely disabled
2067 * 1: Rx flow control is enabled (we can receive pause
2068 * frames but not send pause frames).
2069 * 2: Tx flow control is enabled (we can send pause frames
2070 * frames but we do not receive pause frames).
2071 * 3: Both Rx and TX flow control (symmetric) is enabled.
2072 * other: No other values should be possible at this point.
2077 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2079 case E1000_FC_RX_PAUSE:
2080 ctrl &= (~E1000_CTRL_TFCE);
2081 ctrl |= E1000_CTRL_RFCE;
2083 case E1000_FC_TX_PAUSE:
2084 ctrl &= (~E1000_CTRL_RFCE);
2085 ctrl |= E1000_CTRL_TFCE;
2088 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2091 e_dbg("Flow control param set incorrectly\n");
2092 return -E1000_ERR_CONFIG;
2095 /* Disable TX Flow Control for 82542 (rev 2.0) */
2096 if (hw->mac_type == e1000_82542_rev2_0)
2097 ctrl &= (~E1000_CTRL_TFCE);
2100 return E1000_SUCCESS;
2104 * e1000_config_fc_after_link_up - configure flow control after autoneg
2105 * @hw: Struct containing variables accessed by shared code
2107 * Configures flow control settings after link is established
2108 * Should be called immediately after a valid link has been established.
2109 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2110 * and autonegotiation is enabled, the MAC flow control settings will be set
2111 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2112 * and RFCE bits will be automatically set to the negotiated flow control mode.
2114 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2118 u16 mii_nway_adv_reg;
2119 u16 mii_nway_lp_ability_reg;
2123 e_dbg("e1000_config_fc_after_link_up");
2125 /* Check for the case where we have fiber media and auto-neg failed
2126 * so we had to force link. In this case, we need to force the
2127 * configuration of the MAC to match the "fc" parameter.
2129 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
2130 || ((hw->media_type == e1000_media_type_internal_serdes)
2131 && (hw->autoneg_failed))
2132 || ((hw->media_type == e1000_media_type_copper)
2133 && (!hw->autoneg))) {
2134 ret_val = e1000_force_mac_fc(hw);
2136 e_dbg("Error forcing flow control settings\n");
2141 /* Check for the case where we have copper media and auto-neg is
2142 * enabled. In this case, we need to check and see if Auto-Neg
2143 * has completed, and if so, how the PHY and link partner has
2144 * flow control configured.
2146 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2147 /* Read the MII Status Register and check to see if AutoNeg
2148 * has completed. We read this twice because this reg has
2149 * some "sticky" (latched) bits.
2151 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2154 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2158 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2159 /* The AutoNeg process has completed, so we now need to
2160 * read both the Auto Negotiation Advertisement Register
2161 * (Address 4) and the Auto_Negotiation Base Page
2162 * Ability Register (Address 5) to determine how flow
2163 * control was negotiated.
2165 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2169 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2170 &mii_nway_lp_ability_reg);
2174 /* Two bits in the Auto Negotiation Advertisement
2175 * Register (Address 4) and two bits in the Auto
2176 * Negotiation Base Page Ability Register (Address 5)
2177 * determine flow control for both the PHY and the link
2178 * partner. The following table, taken out of the IEEE
2179 * 802.3ab/D6.0 dated March 25, 1999, describes these
2180 * PAUSE resolution bits and how flow control is
2181 * determined based upon these settings.
2182 * NOTE: DC = Don't Care
2184 * LOCAL DEVICE | LINK PARTNER
2185 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2186 *-------|---------|-------|---------|------------------
2187 * 0 | 0 | DC | DC | E1000_FC_NONE
2188 * 0 | 1 | 0 | DC | E1000_FC_NONE
2189 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2190 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2191 * 1 | 0 | 0 | DC | E1000_FC_NONE
2192 * 1 | DC | 1 | DC | E1000_FC_FULL
2193 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2194 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2197 /* Are both PAUSE bits set to 1? If so, this implies
2198 * Symmetric Flow Control is enabled at both ends. The
2199 * ASM_DIR bits are irrelevant per the spec.
2201 * For Symmetric Flow Control:
2203 * LOCAL DEVICE | LINK PARTNER
2204 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2205 *-------|---------|-------|---------|------------------
2206 * 1 | DC | 1 | DC | E1000_FC_FULL
2209 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2210 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2211 /* Now we need to check if the user selected Rx
2212 * ONLY of pause frames. In this case, we had
2213 * to advertise FULL flow control because we
2214 * could not advertise Rx ONLY. Hence, we must
2215 * now check to see if we need to turn OFF the
2216 * TRANSMISSION of PAUSE frames.
2218 if (hw->original_fc == E1000_FC_FULL) {
2219 hw->fc = E1000_FC_FULL;
2220 e_dbg("Flow Control = FULL.\n");
2222 hw->fc = E1000_FC_RX_PAUSE;
2224 ("Flow Control = RX PAUSE frames only.\n");
2227 /* For receiving PAUSE frames ONLY.
2229 * LOCAL DEVICE | LINK PARTNER
2230 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2231 *-------|---------|-------|---------|------------------
2232 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2235 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2236 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2237 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2238 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2240 hw->fc = E1000_FC_TX_PAUSE;
2242 ("Flow Control = TX PAUSE frames only.\n");
2244 /* For transmitting PAUSE frames ONLY.
2246 * LOCAL DEVICE | LINK PARTNER
2247 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2248 *-------|---------|-------|---------|------------------
2249 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2252 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2253 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2254 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2255 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2257 hw->fc = E1000_FC_RX_PAUSE;
2259 ("Flow Control = RX PAUSE frames only.\n");
2261 /* Per the IEEE spec, at this point flow control should
2262 * be disabled. However, we want to consider that we
2263 * could be connected to a legacy switch that doesn't
2264 * advertise desired flow control, but can be forced on
2265 * the link partner. So if we advertised no flow
2266 * control, that is what we will resolve to. If we
2267 * advertised some kind of receive capability (Rx Pause
2268 * Only or Full Flow Control) and the link partner
2269 * advertised none, we will configure ourselves to
2270 * enable Rx Flow Control only. We can do this safely
2271 * for two reasons: If the link partner really
2272 * didn't want flow control enabled, and we enable Rx,
2273 * no harm done since we won't be receiving any PAUSE
2274 * frames anyway. If the intent on the link partner was
2275 * to have flow control enabled, then by us enabling Rx
2276 * only, we can at least receive pause frames and
2277 * process them. This is a good idea because in most
2278 * cases, since we are predominantly a server NIC, more
2279 * times than not we will be asked to delay transmission
2280 * of packets than asking our link partner to pause
2281 * transmission of frames.
2283 else if ((hw->original_fc == E1000_FC_NONE ||
2284 hw->original_fc == E1000_FC_TX_PAUSE) ||
2285 hw->fc_strict_ieee) {
2286 hw->fc = E1000_FC_NONE;
2287 e_dbg("Flow Control = NONE.\n");
2289 hw->fc = E1000_FC_RX_PAUSE;
2291 ("Flow Control = RX PAUSE frames only.\n");
2294 /* Now we need to do one last check... If we auto-
2295 * negotiated to HALF DUPLEX, flow control should not be
2296 * enabled per IEEE 802.3 spec.
2299 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2302 ("Error getting link speed and duplex\n");
2306 if (duplex == HALF_DUPLEX)
2307 hw->fc = E1000_FC_NONE;
2309 /* Now we call a subroutine to actually force the MAC
2310 * controller to use the correct flow control settings.
2312 ret_val = e1000_force_mac_fc(hw);
2315 ("Error forcing flow control settings\n");
2320 ("Copper PHY and Auto Neg has not completed.\n");
2323 return E1000_SUCCESS;
2327 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2328 * @hw: pointer to the HW structure
2330 * Checks for link up on the hardware. If link is not up and we have
2331 * a signal, then we need to force link up.
2333 static s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2338 s32 ret_val = E1000_SUCCESS;
2340 e_dbg("e1000_check_for_serdes_link_generic");
2343 status = er32(STATUS);
2346 /* If we don't have link (auto-negotiation failed or link partner
2347 * cannot auto-negotiate), and our link partner is not trying to
2348 * auto-negotiate with us (we are receiving idles or data),
2349 * we need to force link up. We also need to give auto-negotiation
2352 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2353 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2354 if (hw->autoneg_failed == 0) {
2355 hw->autoneg_failed = 1;
2358 e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
2360 /* Disable auto-negotiation in the TXCW register */
2361 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2363 /* Force link-up and also force full-duplex. */
2365 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2368 /* Configure Flow Control after forcing link up. */
2369 ret_val = e1000_config_fc_after_link_up(hw);
2371 e_dbg("Error configuring flow control\n");
2374 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2375 /* If we are forcing link and we are receiving /C/ ordered
2376 * sets, re-enable auto-negotiation in the TXCW register
2377 * and disable forced link in the Device Control register
2378 * in an attempt to auto-negotiate with our link partner.
2380 e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
2381 ew32(TXCW, hw->txcw);
2382 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2384 hw->serdes_has_link = true;
2385 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2386 /* If we force link for non-auto-negotiation switch, check
2387 * link status based on MAC synchronization for internal
2388 * serdes media type.
2390 /* SYNCH bit and IV bit are sticky. */
2393 if (rxcw & E1000_RXCW_SYNCH) {
2394 if (!(rxcw & E1000_RXCW_IV)) {
2395 hw->serdes_has_link = true;
2396 e_dbg("SERDES: Link up - forced.\n");
2399 hw->serdes_has_link = false;
2400 e_dbg("SERDES: Link down - force failed.\n");
2404 if (E1000_TXCW_ANE & er32(TXCW)) {
2405 status = er32(STATUS);
2406 if (status & E1000_STATUS_LU) {
2407 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2410 if (rxcw & E1000_RXCW_SYNCH) {
2411 if (!(rxcw & E1000_RXCW_IV)) {
2412 hw->serdes_has_link = true;
2413 e_dbg("SERDES: Link up - autoneg "
2414 "completed successfully.\n");
2416 hw->serdes_has_link = false;
2417 e_dbg("SERDES: Link down - invalid"
2418 "codewords detected in autoneg.\n");
2421 hw->serdes_has_link = false;
2422 e_dbg("SERDES: Link down - no sync.\n");
2425 hw->serdes_has_link = false;
2426 e_dbg("SERDES: Link down - autoneg failed\n");
2435 * e1000_check_for_link
2436 * @hw: Struct containing variables accessed by shared code
2438 * Checks to see if the link status of the hardware has changed.
2439 * Called by any function that needs to check the link status of the adapter.
2441 s32 e1000_check_for_link(struct e1000_hw *hw)
2452 e_dbg("e1000_check_for_link");
2455 status = er32(STATUS);
2457 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2458 * set when the optics detect a signal. On older adapters, it will be
2459 * cleared when there is a signal. This applies to fiber media only.
2461 if ((hw->media_type == e1000_media_type_fiber) ||
2462 (hw->media_type == e1000_media_type_internal_serdes)) {
2465 if (hw->media_type == e1000_media_type_fiber) {
2468 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2469 if (status & E1000_STATUS_LU)
2470 hw->get_link_status = false;
2474 /* If we have a copper PHY then we only want to go out to the PHY
2475 * registers to see if Auto-Neg has completed and/or if our link
2476 * status has changed. The get_link_status flag will be set if we
2477 * receive a Link Status Change interrupt or we have Rx Sequence
2480 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2481 /* First we want to see if the MII Status Register reports
2482 * link. If so, then we want to get the current speed/duplex
2484 * Read the register twice since the link bit is sticky.
2486 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2489 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2493 if (phy_data & MII_SR_LINK_STATUS) {
2494 hw->get_link_status = false;
2495 /* Check if there was DownShift, must be checked
2496 * immediately after link-up
2498 e1000_check_downshift(hw);
2500 /* If we are on 82544 or 82543 silicon and speed/duplex
2501 * are forced to 10H or 10F, then we will implement the
2502 * polarity reversal workaround. We disable interrupts
2503 * first, and upon returning, place the devices
2504 * interrupt state to its previous value except for the
2505 * link status change interrupt which will
2506 * happen due to the execution of this workaround.
2509 if ((hw->mac_type == e1000_82544
2510 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2511 && (hw->forced_speed_duplex == e1000_10_full
2512 || hw->forced_speed_duplex == e1000_10_half)) {
2513 ew32(IMC, 0xffffffff);
2515 e1000_polarity_reversal_workaround(hw);
2517 ew32(ICS, (icr & ~E1000_ICS_LSC));
2518 ew32(IMS, IMS_ENABLE_MASK);
2522 /* No link detected */
2523 e1000_config_dsp_after_link_change(hw, false);
2527 /* If we are forcing speed/duplex, then we simply return since
2528 * we have already determined whether we have link or not.
2531 return -E1000_ERR_CONFIG;
2533 /* optimize the dsp settings for the igp phy */
2534 e1000_config_dsp_after_link_change(hw, true);
2536 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2537 * have Si on board that is 82544 or newer, Auto
2538 * Speed Detection takes care of MAC speed/duplex
2539 * configuration. So we only need to configure Collision
2540 * Distance in the MAC. Otherwise, we need to force
2541 * speed/duplex on the MAC to the current PHY speed/duplex
2544 if ((hw->mac_type >= e1000_82544) &&
2545 (hw->mac_type != e1000_ce4100))
2546 e1000_config_collision_dist(hw);
2548 ret_val = e1000_config_mac_to_phy(hw);
2551 ("Error configuring MAC to PHY settings\n");
2556 /* Configure Flow Control now that Auto-Neg has completed.
2557 * First, we need to restore the desired flow control settings
2558 * because we may have had to re-autoneg with a different link
2561 ret_val = e1000_config_fc_after_link_up(hw);
2563 e_dbg("Error configuring flow control\n");
2567 /* At this point we know that we are on copper and we have
2568 * auto-negotiated link. These are conditions for checking the
2569 * link partner capability register. We use the link speed to
2570 * determine if TBI compatibility needs to be turned on or off.
2571 * If the link is not at gigabit speed, then TBI compatibility
2572 * is not needed. If we are at gigabit speed, we turn on TBI
2575 if (hw->tbi_compatibility_en) {
2578 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2581 ("Error getting link speed and duplex\n");
2584 if (speed != SPEED_1000) {
2585 /* If link speed is not set to gigabit speed, we
2586 * do not need to enable TBI compatibility.
2588 if (hw->tbi_compatibility_on) {
2589 /* If we previously were in the mode,
2593 rctl &= ~E1000_RCTL_SBP;
2595 hw->tbi_compatibility_on = false;
2598 /* If TBI compatibility is was previously off,
2599 * turn it on. For compatibility with a TBI link
2600 * partner, we will store bad packets. Some
2601 * frames have an additional byte on the end and
2602 * will look like CRC errors to to the hardware.
2604 if (!hw->tbi_compatibility_on) {
2605 hw->tbi_compatibility_on = true;
2607 rctl |= E1000_RCTL_SBP;
2614 if ((hw->media_type == e1000_media_type_fiber) ||
2615 (hw->media_type == e1000_media_type_internal_serdes))
2616 e1000_check_for_serdes_link_generic(hw);
2618 return E1000_SUCCESS;
2622 * e1000_get_speed_and_duplex
2623 * @hw: Struct containing variables accessed by shared code
2624 * @speed: Speed of the connection
2625 * @duplex: Duplex setting of the connection
2627 * Detects the current speed and duplex settings of the hardware.
2629 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
2635 e_dbg("e1000_get_speed_and_duplex");
2637 if (hw->mac_type >= e1000_82543) {
2638 status = er32(STATUS);
2639 if (status & E1000_STATUS_SPEED_1000) {
2640 *speed = SPEED_1000;
2641 e_dbg("1000 Mbs, ");
2642 } else if (status & E1000_STATUS_SPEED_100) {
2650 if (status & E1000_STATUS_FD) {
2651 *duplex = FULL_DUPLEX;
2652 e_dbg("Full Duplex\n");
2654 *duplex = HALF_DUPLEX;
2655 e_dbg(" Half Duplex\n");
2658 e_dbg("1000 Mbs, Full Duplex\n");
2659 *speed = SPEED_1000;
2660 *duplex = FULL_DUPLEX;
2663 /* IGP01 PHY may advertise full duplex operation after speed downgrade
2664 * even if it is operating at half duplex. Here we set the duplex
2665 * settings to match the duplex in the link partner's capabilities.
2667 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2668 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2672 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2673 *duplex = HALF_DUPLEX;
2676 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2679 if ((*speed == SPEED_100
2680 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2681 || (*speed == SPEED_10
2682 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2683 *duplex = HALF_DUPLEX;
2687 return E1000_SUCCESS;
2691 * e1000_wait_autoneg
2692 * @hw: Struct containing variables accessed by shared code
2694 * Blocks until autoneg completes or times out (~4.5 seconds)
2696 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
2702 e_dbg("e1000_wait_autoneg");
2703 e_dbg("Waiting for Auto-Neg to complete.\n");
2705 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2706 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2707 /* Read the MII Status Register and wait for Auto-Neg
2708 * Complete bit to be set.
2710 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2713 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2716 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2717 return E1000_SUCCESS;
2721 return E1000_SUCCESS;
2725 * e1000_raise_mdi_clk - Raises the Management Data Clock
2726 * @hw: Struct containing variables accessed by shared code
2727 * @ctrl: Device control register's current value
2729 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2731 /* Raise the clock input to the Management Data Clock (by setting the
2732 * MDC bit), and then delay 10 microseconds.
2734 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2735 E1000_WRITE_FLUSH();
2740 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2741 * @hw: Struct containing variables accessed by shared code
2742 * @ctrl: Device control register's current value
2744 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2746 /* Lower the clock input to the Management Data Clock (by clearing the
2747 * MDC bit), and then delay 10 microseconds.
2749 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2750 E1000_WRITE_FLUSH();
2755 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2756 * @hw: Struct containing variables accessed by shared code
2757 * @data: Data to send out to the PHY
2758 * @count: Number of bits to shift out
2760 * Bits are shifted out in MSB to LSB order.
2762 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
2767 /* We need to shift "count" number of bits out to the PHY. So, the value
2768 * in the "data" parameter will be shifted out to the PHY one bit at a
2769 * time. In order to do this, "data" must be broken down into bits.
2772 mask <<= (count - 1);
2776 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2777 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2780 /* A "1" is shifted out to the PHY by setting the MDIO bit to
2781 * "1" and then raising and lowering the Management Data Clock.
2782 * A "0" is shifted out to the PHY by setting the MDIO bit to
2783 * "0" and then raising and lowering the clock.
2786 ctrl |= E1000_CTRL_MDIO;
2788 ctrl &= ~E1000_CTRL_MDIO;
2791 E1000_WRITE_FLUSH();
2795 e1000_raise_mdi_clk(hw, &ctrl);
2796 e1000_lower_mdi_clk(hw, &ctrl);
2803 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2804 * @hw: Struct containing variables accessed by shared code
2806 * Bits are shifted in in MSB to LSB order.
2808 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2814 /* In order to read a register from the PHY, we need to shift in a total
2815 * of 18 bits from the PHY. The first two bit (turnaround) times are
2816 * used to avoid contention on the MDIO pin when a read operation is
2817 * performed. These two bits are ignored by us and thrown away. Bits are
2818 * "shifted in" by raising the input to the Management Data Clock
2819 * (setting the MDC bit), and then reading the value of the MDIO bit.
2823 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as
2826 ctrl &= ~E1000_CTRL_MDIO_DIR;
2827 ctrl &= ~E1000_CTRL_MDIO;
2830 E1000_WRITE_FLUSH();
2832 /* Raise and Lower the clock before reading in the data. This accounts
2833 * for the turnaround bits. The first clock occurred when we clocked out
2834 * the last bit of the Register Address.
2836 e1000_raise_mdi_clk(hw, &ctrl);
2837 e1000_lower_mdi_clk(hw, &ctrl);
2839 for (data = 0, i = 0; i < 16; i++) {
2841 e1000_raise_mdi_clk(hw, &ctrl);
2843 /* Check to see if we shifted in a "1". */
2844 if (ctrl & E1000_CTRL_MDIO)
2846 e1000_lower_mdi_clk(hw, &ctrl);
2849 e1000_raise_mdi_clk(hw, &ctrl);
2850 e1000_lower_mdi_clk(hw, &ctrl);
2857 * e1000_read_phy_reg - read a phy register
2858 * @hw: Struct containing variables accessed by shared code
2859 * @reg_addr: address of the PHY register to read
2861 * Reads the value from a PHY register, if the value is on a specific non zero
2862 * page, sets the page first.
2864 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
2867 unsigned long flags;
2869 e_dbg("e1000_read_phy_reg");
2871 spin_lock_irqsave(&e1000_phy_lock, flags);
2873 if ((hw->phy_type == e1000_phy_igp) &&
2874 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2875 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2878 spin_unlock_irqrestore(&e1000_phy_lock, flags);
2883 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2885 spin_unlock_irqrestore(&e1000_phy_lock, flags);
2890 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2895 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
2897 e_dbg("e1000_read_phy_reg_ex");
2899 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2900 e_dbg("PHY Address %d is out of range\n", reg_addr);
2901 return -E1000_ERR_PARAM;
2904 if (hw->mac_type > e1000_82543) {
2905 /* Set up Op-code, Phy Address, and register address in the MDI
2906 * Control register. The MAC will take care of interfacing with
2907 * the PHY to retrieve the desired data.
2909 if (hw->mac_type == e1000_ce4100) {
2910 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2911 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2912 (INTEL_CE_GBE_MDIC_OP_READ) |
2913 (INTEL_CE_GBE_MDIC_GO));
2915 writel(mdic, E1000_MDIO_CMD);
2917 /* Poll the ready bit to see if the MDI read
2920 for (i = 0; i < 64; i++) {
2922 mdic = readl(E1000_MDIO_CMD);
2923 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
2927 if (mdic & INTEL_CE_GBE_MDIC_GO) {
2928 e_dbg("MDI Read did not complete\n");
2929 return -E1000_ERR_PHY;
2932 mdic = readl(E1000_MDIO_STS);
2933 if (mdic & INTEL_CE_GBE_MDIC_READ_ERROR) {
2934 e_dbg("MDI Read Error\n");
2935 return -E1000_ERR_PHY;
2937 *phy_data = (u16) mdic;
2939 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2940 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2941 (E1000_MDIC_OP_READ));
2945 /* Poll the ready bit to see if the MDI read
2948 for (i = 0; i < 64; i++) {
2951 if (mdic & E1000_MDIC_READY)
2954 if (!(mdic & E1000_MDIC_READY)) {
2955 e_dbg("MDI Read did not complete\n");
2956 return -E1000_ERR_PHY;
2958 if (mdic & E1000_MDIC_ERROR) {
2959 e_dbg("MDI Error\n");
2960 return -E1000_ERR_PHY;
2962 *phy_data = (u16) mdic;
2965 /* We must first send a preamble through the MDIO pin to signal
2966 * the beginning of an MII instruction. This is done by sending
2967 * 32 consecutive "1" bits.
2969 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2971 /* Now combine the next few fields that are required for a read
2972 * operation. We use this method instead of calling the
2973 * e1000_shift_out_mdi_bits routine five different times. The
2974 * format of a MII read instruction consists of a shift out of
2975 * 14 bits and is defined as follows:
2976 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2977 * followed by a shift in of 18 bits. This first two bits
2978 * shifted in are TurnAround bits used to avoid contention on
2979 * the MDIO pin when a READ operation is performed. These two
2980 * bits are thrown away followed by a shift in of 16 bits which
2981 * contains the desired data.
2983 mdic = ((reg_addr) | (phy_addr << 5) |
2984 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2986 e1000_shift_out_mdi_bits(hw, mdic, 14);
2988 /* Now that we've shifted out the read command to the MII, we
2989 * need to "shift in" the 16-bit value (18 total bits) of the
2990 * requested PHY register address.
2992 *phy_data = e1000_shift_in_mdi_bits(hw);
2994 return E1000_SUCCESS;
2998 * e1000_write_phy_reg - write a phy register
3000 * @hw: Struct containing variables accessed by shared code
3001 * @reg_addr: address of the PHY register to write
3002 * @data: data to write to the PHY
3004 * Writes a value to a PHY register
3006 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
3009 unsigned long flags;
3011 e_dbg("e1000_write_phy_reg");
3013 spin_lock_irqsave(&e1000_phy_lock, flags);
3015 if ((hw->phy_type == e1000_phy_igp) &&
3016 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
3017 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
3020 spin_unlock_irqrestore(&e1000_phy_lock, flags);
3025 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
3027 spin_unlock_irqrestore(&e1000_phy_lock, flags);
3032 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
3037 const u32 phy_addr = (hw->mac_type == e1000_ce4100) ? hw->phy_addr : 1;
3039 e_dbg("e1000_write_phy_reg_ex");
3041 if (reg_addr > MAX_PHY_REG_ADDRESS) {
3042 e_dbg("PHY Address %d is out of range\n", reg_addr);
3043 return -E1000_ERR_PARAM;
3046 if (hw->mac_type > e1000_82543) {
3047 /* Set up Op-code, Phy Address, register address, and data
3048 * intended for the PHY register in the MDI Control register.
3049 * The MAC will take care of interfacing with the PHY to send
3052 if (hw->mac_type == e1000_ce4100) {
3053 mdic = (((u32) phy_data) |
3054 (reg_addr << E1000_MDIC_REG_SHIFT) |
3055 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3056 (INTEL_CE_GBE_MDIC_OP_WRITE) |
3057 (INTEL_CE_GBE_MDIC_GO));
3059 writel(mdic, E1000_MDIO_CMD);
3061 /* Poll the ready bit to see if the MDI read
3064 for (i = 0; i < 640; i++) {
3066 mdic = readl(E1000_MDIO_CMD);
3067 if (!(mdic & INTEL_CE_GBE_MDIC_GO))
3070 if (mdic & INTEL_CE_GBE_MDIC_GO) {
3071 e_dbg("MDI Write did not complete\n");
3072 return -E1000_ERR_PHY;
3075 mdic = (((u32) phy_data) |
3076 (reg_addr << E1000_MDIC_REG_SHIFT) |
3077 (phy_addr << E1000_MDIC_PHY_SHIFT) |
3078 (E1000_MDIC_OP_WRITE));
3082 /* Poll the ready bit to see if the MDI read
3085 for (i = 0; i < 641; i++) {
3088 if (mdic & E1000_MDIC_READY)
3091 if (!(mdic & E1000_MDIC_READY)) {
3092 e_dbg("MDI Write did not complete\n");
3093 return -E1000_ERR_PHY;
3097 /* We'll need to use the SW defined pins to shift the write
3098 * command out to the PHY. We first send a preamble to the PHY
3099 * to signal the beginning of the MII instruction. This is done
3100 * by sending 32 consecutive "1" bits.
3102 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
3104 /* Now combine the remaining required fields that will indicate
3105 * a write operation. We use this method instead of calling the
3106 * e1000_shift_out_mdi_bits routine for each field in the
3107 * command. The format of a MII write instruction is as follows:
3108 * <Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
3110 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
3111 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
3113 mdic |= (u32) phy_data;
3115 e1000_shift_out_mdi_bits(hw, mdic, 32);
3118 return E1000_SUCCESS;
3122 * e1000_phy_hw_reset - reset the phy, hardware style
3123 * @hw: Struct containing variables accessed by shared code
3125 * Returns the PHY to the power-on reset state
3127 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
3132 e_dbg("e1000_phy_hw_reset");
3134 e_dbg("Resetting Phy...\n");
3136 if (hw->mac_type > e1000_82543) {
3137 /* Read the device control register and assert the
3138 * E1000_CTRL_PHY_RST bit. Then, take it out of reset.
3139 * For e1000 hardware, we delay for 10ms between the assert
3143 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
3144 E1000_WRITE_FLUSH();
3149 E1000_WRITE_FLUSH();
3152 /* Read the Extended Device Control Register, assert the
3153 * PHY_RESET_DIR bit to put the PHY into reset. Then, take it
3156 ctrl_ext = er32(CTRL_EXT);
3157 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
3158 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
3159 ew32(CTRL_EXT, ctrl_ext);
3160 E1000_WRITE_FLUSH();
3162 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3163 ew32(CTRL_EXT, ctrl_ext);
3164 E1000_WRITE_FLUSH();
3168 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3169 /* Configure activity LED after PHY reset */
3170 led_ctrl = er32(LEDCTL);
3171 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3172 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3173 ew32(LEDCTL, led_ctrl);
3176 /* Wait for FW to finish PHY configuration. */
3177 return e1000_get_phy_cfg_done(hw);
3181 * e1000_phy_reset - reset the phy to commit settings
3182 * @hw: Struct containing variables accessed by shared code
3185 * Sets bit 15 of the MII Control register
3187 s32 e1000_phy_reset(struct e1000_hw *hw)
3192 e_dbg("e1000_phy_reset");
3194 switch (hw->phy_type) {
3196 ret_val = e1000_phy_hw_reset(hw);
3201 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3205 phy_data |= MII_CR_RESET;
3206 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3214 if (hw->phy_type == e1000_phy_igp)
3215 e1000_phy_init_script(hw);
3217 return E1000_SUCCESS;
3221 * e1000_detect_gig_phy - check the phy type
3222 * @hw: Struct containing variables accessed by shared code
3224 * Probes the expected PHY address for known PHY IDs
3226 static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
3228 s32 phy_init_status, ret_val;
3229 u16 phy_id_high, phy_id_low;
3232 e_dbg("e1000_detect_gig_phy");
3234 if (hw->phy_id != 0)
3235 return E1000_SUCCESS;
3237 /* Read the PHY ID Registers to identify which PHY is onboard. */
3238 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3242 hw->phy_id = (u32) (phy_id_high << 16);
3244 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3248 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3249 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
3251 switch (hw->mac_type) {
3253 if (hw->phy_id == M88E1000_E_PHY_ID)
3257 if (hw->phy_id == M88E1000_I_PHY_ID)
3262 case e1000_82545_rev_3:
3264 case e1000_82546_rev_3:
3265 if (hw->phy_id == M88E1011_I_PHY_ID)
3269 if ((hw->phy_id == RTL8211B_PHY_ID) ||
3270 (hw->phy_id == RTL8201N_PHY_ID) ||
3271 (hw->phy_id == M88E1118_E_PHY_ID))
3275 case e1000_82541_rev_2:
3277 case e1000_82547_rev_2:
3278 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3282 e_dbg("Invalid MAC type %d\n", hw->mac_type);
3283 return -E1000_ERR_CONFIG;
3285 phy_init_status = e1000_set_phy_type(hw);
3287 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3288 e_dbg("PHY ID 0x%X detected\n", hw->phy_id);
3289 return E1000_SUCCESS;
3291 e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id);
3292 return -E1000_ERR_PHY;
3296 * e1000_phy_reset_dsp - reset DSP
3297 * @hw: Struct containing variables accessed by shared code
3299 * Resets the PHY's DSP
3301 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
3304 e_dbg("e1000_phy_reset_dsp");
3307 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3310 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3313 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3316 ret_val = E1000_SUCCESS;
3323 * e1000_phy_igp_get_info - get igp specific registers
3324 * @hw: Struct containing variables accessed by shared code
3325 * @phy_info: PHY information structure
3327 * Get PHY information from various PHY registers for igp PHY only.
3329 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3330 struct e1000_phy_info *phy_info)
3333 u16 phy_data, min_length, max_length, average;
3334 e1000_rev_polarity polarity;
3336 e_dbg("e1000_phy_igp_get_info");
3338 /* The downshift status is checked only once, after link is established,
3339 * and it stored in the hw->speed_downgraded parameter.
3341 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3343 /* IGP01E1000 does not need to support it. */
3344 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3346 /* IGP01E1000 always correct polarity reversal */
3347 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3349 /* Check polarity status */
3350 ret_val = e1000_check_polarity(hw, &polarity);
3354 phy_info->cable_polarity = polarity;
3356 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3360 phy_info->mdix_mode =
3361 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3362 IGP01E1000_PSSR_MDIX_SHIFT);
3364 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3365 IGP01E1000_PSSR_SPEED_1000MBPS) {
3366 /* Local/Remote Receiver Information are only valid @ 1000
3369 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3373 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3374 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3375 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3376 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3377 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3378 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3380 /* Get cable length */
3381 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3385 /* Translate to old method */
3386 average = (max_length + min_length) / 2;
3388 if (average <= e1000_igp_cable_length_50)
3389 phy_info->cable_length = e1000_cable_length_50;
3390 else if (average <= e1000_igp_cable_length_80)
3391 phy_info->cable_length = e1000_cable_length_50_80;
3392 else if (average <= e1000_igp_cable_length_110)
3393 phy_info->cable_length = e1000_cable_length_80_110;
3394 else if (average <= e1000_igp_cable_length_140)
3395 phy_info->cable_length = e1000_cable_length_110_140;
3397 phy_info->cable_length = e1000_cable_length_140;
3400 return E1000_SUCCESS;
3404 * e1000_phy_m88_get_info - get m88 specific registers
3405 * @hw: Struct containing variables accessed by shared code
3406 * @phy_info: PHY information structure
3408 * Get PHY information from various PHY registers for m88 PHY only.
3410 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3411 struct e1000_phy_info *phy_info)
3415 e1000_rev_polarity polarity;
3417 e_dbg("e1000_phy_m88_get_info");
3419 /* The downshift status is checked only once, after link is established,
3420 * and it stored in the hw->speed_downgraded parameter.
3422 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3424 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3428 phy_info->extended_10bt_distance =
3429 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3430 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3431 e1000_10bt_ext_dist_enable_lower :
3432 e1000_10bt_ext_dist_enable_normal;
3434 phy_info->polarity_correction =
3435 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3436 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3437 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
3439 /* Check polarity status */
3440 ret_val = e1000_check_polarity(hw, &polarity);
3443 phy_info->cable_polarity = polarity;
3445 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3449 phy_info->mdix_mode =
3450 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3451 M88E1000_PSSR_MDIX_SHIFT);
3453 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3454 /* Cable Length Estimation and Local/Remote Receiver Information
3455 * are only valid at 1000 Mbps.
3457 phy_info->cable_length =
3458 (e1000_cable_length) ((phy_data &
3459 M88E1000_PSSR_CABLE_LENGTH) >>
3460 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3462 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3466 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3467 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3468 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3469 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3470 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3471 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3475 return E1000_SUCCESS;
3479 * e1000_phy_get_info - request phy info
3480 * @hw: Struct containing variables accessed by shared code
3481 * @phy_info: PHY information structure
3483 * Get PHY information from various PHY registers
3485 s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
3490 e_dbg("e1000_phy_get_info");
3492 phy_info->cable_length = e1000_cable_length_undefined;
3493 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3494 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3495 phy_info->downshift = e1000_downshift_undefined;
3496 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3497 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3498 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3499 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3501 if (hw->media_type != e1000_media_type_copper) {
3502 e_dbg("PHY info is only valid for copper media\n");
3503 return -E1000_ERR_CONFIG;
3506 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3510 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3514 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3515 e_dbg("PHY info is only valid if link is up\n");
3516 return -E1000_ERR_CONFIG;
3519 if (hw->phy_type == e1000_phy_igp)
3520 return e1000_phy_igp_get_info(hw, phy_info);
3521 else if ((hw->phy_type == e1000_phy_8211) ||
3522 (hw->phy_type == e1000_phy_8201))
3523 return E1000_SUCCESS;
3525 return e1000_phy_m88_get_info(hw, phy_info);
3528 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
3530 e_dbg("e1000_validate_mdi_settings");
3532 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3533 e_dbg("Invalid MDI setting detected\n");
3535 return -E1000_ERR_CONFIG;
3537 return E1000_SUCCESS;
3541 * e1000_init_eeprom_params - initialize sw eeprom vars
3542 * @hw: Struct containing variables accessed by shared code
3544 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3547 s32 e1000_init_eeprom_params(struct e1000_hw *hw)
3549 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3550 u32 eecd = er32(EECD);
3551 s32 ret_val = E1000_SUCCESS;
3554 e_dbg("e1000_init_eeprom_params");
3556 switch (hw->mac_type) {
3557 case e1000_82542_rev2_0:
3558 case e1000_82542_rev2_1:
3561 eeprom->type = e1000_eeprom_microwire;
3562 eeprom->word_size = 64;
3563 eeprom->opcode_bits = 3;
3564 eeprom->address_bits = 6;
3565 eeprom->delay_usec = 50;
3569 case e1000_82545_rev_3:
3571 case e1000_82546_rev_3:
3572 eeprom->type = e1000_eeprom_microwire;
3573 eeprom->opcode_bits = 3;
3574 eeprom->delay_usec = 50;
3575 if (eecd & E1000_EECD_SIZE) {
3576 eeprom->word_size = 256;
3577 eeprom->address_bits = 8;
3579 eeprom->word_size = 64;
3580 eeprom->address_bits = 6;
3584 case e1000_82541_rev_2:
3586 case e1000_82547_rev_2:
3587 if (eecd & E1000_EECD_TYPE) {
3588 eeprom->type = e1000_eeprom_spi;
3589 eeprom->opcode_bits = 8;
3590 eeprom->delay_usec = 1;
3591 if (eecd & E1000_EECD_ADDR_BITS) {
3592 eeprom->page_size = 32;
3593 eeprom->address_bits = 16;
3595 eeprom->page_size = 8;
3596 eeprom->address_bits = 8;
3599 eeprom->type = e1000_eeprom_microwire;
3600 eeprom->opcode_bits = 3;
3601 eeprom->delay_usec = 50;
3602 if (eecd & E1000_EECD_ADDR_BITS) {
3603 eeprom->word_size = 256;
3604 eeprom->address_bits = 8;
3606 eeprom->word_size = 64;
3607 eeprom->address_bits = 6;
3615 if (eeprom->type == e1000_eeprom_spi) {
3616 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes
3617 * 128B to 32KB (incremented by powers of 2).
3619 /* Set to default value for initial eeprom read. */
3620 eeprom->word_size = 64;
3621 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3625 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3626 /* 256B eeprom size was not supported in earlier hardware, so we
3627 * bump eeprom_size up one to ensure that "1" (which maps to
3628 * 256B) is never the result used in the shifting logic below.
3633 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3639 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3640 * @hw: Struct containing variables accessed by shared code
3641 * @eecd: EECD's current value
3643 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
3645 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3646 * wait <delay> microseconds.
3648 *eecd = *eecd | E1000_EECD_SK;
3650 E1000_WRITE_FLUSH();
3651 udelay(hw->eeprom.delay_usec);
3655 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3656 * @hw: Struct containing variables accessed by shared code
3657 * @eecd: EECD's current value
3659 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
3661 /* Lower the clock input to the EEPROM (by clearing the SK bit), and
3662 * then wait 50 microseconds.
3664 *eecd = *eecd & ~E1000_EECD_SK;
3666 E1000_WRITE_FLUSH();
3667 udelay(hw->eeprom.delay_usec);
3671 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3672 * @hw: Struct containing variables accessed by shared code
3673 * @data: data to send to the EEPROM
3674 * @count: number of bits to shift out
3676 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
3678 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3682 /* We need to shift "count" bits out to the EEPROM. So, value in the
3683 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3684 * In order to do this, "data" must be broken down into bits.
3686 mask = 0x01 << (count - 1);
3688 if (eeprom->type == e1000_eeprom_microwire) {
3689 eecd &= ~E1000_EECD_DO;
3690 } else if (eeprom->type == e1000_eeprom_spi) {
3691 eecd |= E1000_EECD_DO;
3694 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a
3695 * "1", and then raising and then lowering the clock (the SK bit
3696 * controls the clock input to the EEPROM). A "0" is shifted
3697 * out to the EEPROM by setting "DI" to "0" and then raising and
3698 * then lowering the clock.
3700 eecd &= ~E1000_EECD_DI;
3703 eecd |= E1000_EECD_DI;
3706 E1000_WRITE_FLUSH();
3708 udelay(eeprom->delay_usec);
3710 e1000_raise_ee_clk(hw, &eecd);
3711 e1000_lower_ee_clk(hw, &eecd);
3717 /* We leave the "DI" bit set to "0" when we leave this routine. */
3718 eecd &= ~E1000_EECD_DI;
3723 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3724 * @hw: Struct containing variables accessed by shared code
3725 * @count: number of bits to shift in
3727 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
3733 /* In order to read a register from the EEPROM, we need to shift 'count'
3734 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3735 * input to the EEPROM (setting the SK bit), and then reading the value
3736 * of the "DO" bit. During this "shifting in" process the "DI" bit
3737 * should always be clear.
3742 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3745 for (i = 0; i < count; i++) {
3747 e1000_raise_ee_clk(hw, &eecd);
3751 eecd &= ~(E1000_EECD_DI);
3752 if (eecd & E1000_EECD_DO)
3755 e1000_lower_ee_clk(hw, &eecd);
3762 * e1000_acquire_eeprom - Prepares EEPROM for access
3763 * @hw: Struct containing variables accessed by shared code
3765 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3766 * function should be called before issuing a command to the EEPROM.
3768 static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
3770 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3773 e_dbg("e1000_acquire_eeprom");
3777 /* Request EEPROM Access */
3778 if (hw->mac_type > e1000_82544) {
3779 eecd |= E1000_EECD_REQ;
3782 while ((!(eecd & E1000_EECD_GNT)) &&
3783 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3788 if (!(eecd & E1000_EECD_GNT)) {
3789 eecd &= ~E1000_EECD_REQ;
3791 e_dbg("Could not acquire EEPROM grant\n");
3792 return -E1000_ERR_EEPROM;
3796 /* Setup EEPROM for Read/Write */
3798 if (eeprom->type == e1000_eeprom_microwire) {
3799 /* Clear SK and DI */
3800 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3804 eecd |= E1000_EECD_CS;
3806 } else if (eeprom->type == e1000_eeprom_spi) {
3807 /* Clear SK and CS */
3808 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3810 E1000_WRITE_FLUSH();
3814 return E1000_SUCCESS;
3818 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3819 * @hw: Struct containing variables accessed by shared code
3821 static void e1000_standby_eeprom(struct e1000_hw *hw)
3823 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3828 if (eeprom->type == e1000_eeprom_microwire) {
3829 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3831 E1000_WRITE_FLUSH();
3832 udelay(eeprom->delay_usec);
3835 eecd |= E1000_EECD_SK;
3837 E1000_WRITE_FLUSH();
3838 udelay(eeprom->delay_usec);
3841 eecd |= E1000_EECD_CS;
3843 E1000_WRITE_FLUSH();
3844 udelay(eeprom->delay_usec);
3847 eecd &= ~E1000_EECD_SK;
3849 E1000_WRITE_FLUSH();
3850 udelay(eeprom->delay_usec);
3851 } else if (eeprom->type == e1000_eeprom_spi) {
3852 /* Toggle CS to flush commands */
3853 eecd |= E1000_EECD_CS;
3855 E1000_WRITE_FLUSH();
3856 udelay(eeprom->delay_usec);
3857 eecd &= ~E1000_EECD_CS;
3859 E1000_WRITE_FLUSH();
3860 udelay(eeprom->delay_usec);
3865 * e1000_release_eeprom - drop chip select
3866 * @hw: Struct containing variables accessed by shared code
3868 * Terminates a command by inverting the EEPROM's chip select pin
3870 static void e1000_release_eeprom(struct e1000_hw *hw)
3874 e_dbg("e1000_release_eeprom");
3878 if (hw->eeprom.type == e1000_eeprom_spi) {
3879 eecd |= E1000_EECD_CS; /* Pull CS high */
3880 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3883 E1000_WRITE_FLUSH();
3885 udelay(hw->eeprom.delay_usec);
3886 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3887 /* cleanup eeprom */
3889 /* CS on Microwire is active-high */
3890 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3894 /* Rising edge of clock */
3895 eecd |= E1000_EECD_SK;
3897 E1000_WRITE_FLUSH();
3898 udelay(hw->eeprom.delay_usec);
3900 /* Falling edge of clock */
3901 eecd &= ~E1000_EECD_SK;
3903 E1000_WRITE_FLUSH();
3904 udelay(hw->eeprom.delay_usec);
3907 /* Stop requesting EEPROM access */
3908 if (hw->mac_type > e1000_82544) {
3909 eecd &= ~E1000_EECD_REQ;
3915 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3916 * @hw: Struct containing variables accessed by shared code
3918 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3920 u16 retry_count = 0;
3923 e_dbg("e1000_spi_eeprom_ready");
3925 /* Read "Status Register" repeatedly until the LSB is cleared. The
3926 * EEPROM will signal that the command has been completed by clearing
3927 * bit 0 of the internal status register. If it's not cleared within
3928 * 5 milliseconds, then error out.
3932 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3933 hw->eeprom.opcode_bits);
3934 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3935 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3941 e1000_standby_eeprom(hw);
3942 } while (retry_count < EEPROM_MAX_RETRY_SPI);
3944 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3945 * only 0-5mSec on 5V devices)
3947 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3948 e_dbg("SPI EEPROM Status error\n");
3949 return -E1000_ERR_EEPROM;
3952 return E1000_SUCCESS;
3956 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3957 * @hw: Struct containing variables accessed by shared code
3958 * @offset: offset of word in the EEPROM to read
3959 * @data: word read from the EEPROM
3960 * @words: number of words to read
3962 s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3965 spin_lock(&e1000_eeprom_lock);
3966 ret = e1000_do_read_eeprom(hw, offset, words, data);
3967 spin_unlock(&e1000_eeprom_lock);
3971 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3974 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3977 e_dbg("e1000_read_eeprom");
3979 if (hw->mac_type == e1000_ce4100) {
3980 GBE_CONFIG_FLASH_READ(GBE_CONFIG_BASE_VIRT, offset, words,
3982 return E1000_SUCCESS;
3985 /* If eeprom is not yet detected, do so now */
3986 if (eeprom->word_size == 0)
3987 e1000_init_eeprom_params(hw);
3989 /* A check for invalid values: offset too large, too many words, and
3992 if ((offset >= eeprom->word_size)
3993 || (words > eeprom->word_size - offset) || (words == 0)) {
3994 e_dbg("\"words\" parameter out of bounds. Words = %d,"
3995 "size = %d\n", offset, eeprom->word_size);
3996 return -E1000_ERR_EEPROM;
3999 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
4000 * directly. In this case, we need to acquire the EEPROM so that
4001 * FW or other port software does not interrupt.
4003 /* Prepare the EEPROM for bit-bang reading */
4004 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4005 return -E1000_ERR_EEPROM;
4007 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
4008 * acquired the EEPROM at this point, so any returns should release it
4010 if (eeprom->type == e1000_eeprom_spi) {
4012 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
4014 if (e1000_spi_eeprom_ready(hw)) {
4015 e1000_release_eeprom(hw);
4016 return -E1000_ERR_EEPROM;
4019 e1000_standby_eeprom(hw);
4021 /* Some SPI eeproms use the 8th address bit embedded in the
4024 if ((eeprom->address_bits == 8) && (offset >= 128))
4025 read_opcode |= EEPROM_A8_OPCODE_SPI;
4027 /* Send the READ command (opcode + addr) */
4028 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
4029 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
4030 eeprom->address_bits);
4032 /* Read the data. The address of the eeprom internally
4033 * increments with each byte (spi) being read, saving on the
4034 * overhead of eeprom setup and tear-down. The address counter
4035 * will roll over if reading beyond the size of the eeprom, thus
4036 * allowing the entire memory to be read starting from any
4039 for (i = 0; i < words; i++) {
4040 word_in = e1000_shift_in_ee_bits(hw, 16);
4041 data[i] = (word_in >> 8) | (word_in << 8);
4043 } else if (eeprom->type == e1000_eeprom_microwire) {
4044 for (i = 0; i < words; i++) {
4045 /* Send the READ command (opcode + addr) */
4046 e1000_shift_out_ee_bits(hw,
4047 EEPROM_READ_OPCODE_MICROWIRE,
4048 eeprom->opcode_bits);
4049 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
4050 eeprom->address_bits);
4052 /* Read the data. For microwire, each word requires the
4053 * overhead of eeprom setup and tear-down.
4055 data[i] = e1000_shift_in_ee_bits(hw, 16);
4056 e1000_standby_eeprom(hw);
4060 /* End this read operation */
4061 e1000_release_eeprom(hw);
4063 return E1000_SUCCESS;
4067 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
4068 * @hw: Struct containing variables accessed by shared code
4070 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4071 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4074 s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4079 e_dbg("e1000_validate_eeprom_checksum");
4081 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4082 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4083 e_dbg("EEPROM Read Error\n");
4084 return -E1000_ERR_EEPROM;
4086 checksum += eeprom_data;
4089 #ifdef CONFIG_PARISC
4090 /* This is a signature and not a checksum on HP c8000 */
4091 if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6))
4092 return E1000_SUCCESS;
4095 if (checksum == (u16) EEPROM_SUM)
4096 return E1000_SUCCESS;
4098 e_dbg("EEPROM Checksum Invalid\n");
4099 return -E1000_ERR_EEPROM;
4104 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
4105 * @hw: Struct containing variables accessed by shared code
4107 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4108 * Writes the difference to word offset 63 of the EEPROM.
4110 s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4115 e_dbg("e1000_update_eeprom_checksum");
4117 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4118 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4119 e_dbg("EEPROM Read Error\n");
4120 return -E1000_ERR_EEPROM;
4122 checksum += eeprom_data;
4124 checksum = (u16) EEPROM_SUM - checksum;
4125 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4126 e_dbg("EEPROM Write Error\n");
4127 return -E1000_ERR_EEPROM;
4129 return E1000_SUCCESS;
4133 * e1000_write_eeprom - write words to the different EEPROM types.
4134 * @hw: Struct containing variables accessed by shared code
4135 * @offset: offset within the EEPROM to be written to
4136 * @words: number of words to write
4137 * @data: 16 bit word to be written to the EEPROM
4139 * If e1000_update_eeprom_checksum is not called after this function, the
4140 * EEPROM will most likely contain an invalid checksum.
4142 s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
4145 spin_lock(&e1000_eeprom_lock);
4146 ret = e1000_do_write_eeprom(hw, offset, words, data);
4147 spin_unlock(&e1000_eeprom_lock);
4151 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4154 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4157 e_dbg("e1000_write_eeprom");
4159 if (hw->mac_type == e1000_ce4100) {
4160 GBE_CONFIG_FLASH_WRITE(GBE_CONFIG_BASE_VIRT, offset, words,
4162 return E1000_SUCCESS;
4165 /* If eeprom is not yet detected, do so now */
4166 if (eeprom->word_size == 0)
4167 e1000_init_eeprom_params(hw);
4169 /* A check for invalid values: offset too large, too many words, and
4172 if ((offset >= eeprom->word_size)
4173 || (words > eeprom->word_size - offset) || (words == 0)) {
4174 e_dbg("\"words\" parameter out of bounds\n");
4175 return -E1000_ERR_EEPROM;
4178 /* Prepare the EEPROM for writing */
4179 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4180 return -E1000_ERR_EEPROM;
4182 if (eeprom->type == e1000_eeprom_microwire) {
4183 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4185 status = e1000_write_eeprom_spi(hw, offset, words, data);
4189 /* Done with writing */
4190 e1000_release_eeprom(hw);
4196 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4197 * @hw: Struct containing variables accessed by shared code
4198 * @offset: offset within the EEPROM to be written to
4199 * @words: number of words to write
4200 * @data: pointer to array of 8 bit words to be written to the EEPROM
4202 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4205 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4208 e_dbg("e1000_write_eeprom_spi");
4210 while (widx < words) {
4211 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
4213 if (e1000_spi_eeprom_ready(hw))
4214 return -E1000_ERR_EEPROM;
4216 e1000_standby_eeprom(hw);
4218 /* Send the WRITE ENABLE command (8 bit opcode ) */
4219 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4220 eeprom->opcode_bits);
4222 e1000_standby_eeprom(hw);
4224 /* Some SPI eeproms use the 8th address bit embedded in the
4227 if ((eeprom->address_bits == 8) && (offset >= 128))
4228 write_opcode |= EEPROM_A8_OPCODE_SPI;
4230 /* Send the Write command (8-bit opcode + addr) */
4231 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4233 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
4234 eeprom->address_bits);
4238 /* Loop to allow for up to whole page write (32 bytes) of
4241 while (widx < words) {
4242 u16 word_out = data[widx];
4243 word_out = (word_out >> 8) | (word_out << 8);
4244 e1000_shift_out_ee_bits(hw, word_out, 16);
4247 /* Some larger eeprom sizes are capable of a 32-byte
4248 * PAGE WRITE operation, while the smaller eeproms are
4249 * capable of an 8-byte PAGE WRITE operation. Break the
4250 * inner loop to pass new address
4252 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4253 e1000_standby_eeprom(hw);
4259 return E1000_SUCCESS;
4263 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4264 * @hw: Struct containing variables accessed by shared code
4265 * @offset: offset within the EEPROM to be written to
4266 * @words: number of words to write
4267 * @data: pointer to array of 8 bit words to be written to the EEPROM
4269 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4270 u16 words, u16 *data)
4272 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4274 u16 words_written = 0;
4277 e_dbg("e1000_write_eeprom_microwire");
4279 /* Send the write enable command to the EEPROM (3-bit opcode plus
4280 * 6/8-bit dummy address beginning with 11). It's less work to include
4281 * the 11 of the dummy address as part of the opcode than it is to shift
4282 * it over the correct number of bits for the address. This puts the
4283 * EEPROM into write/erase mode.
4285 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4286 (u16) (eeprom->opcode_bits + 2));
4288 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4290 /* Prepare the EEPROM */
4291 e1000_standby_eeprom(hw);
4293 while (words_written < words) {
4294 /* Send the Write command (3-bit opcode + addr) */
4295 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4296 eeprom->opcode_bits);
4298 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4299 eeprom->address_bits);
4302 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4304 /* Toggle the CS line. This in effect tells the EEPROM to
4305 * execute the previous command.
4307 e1000_standby_eeprom(hw);
4309 /* Read DO repeatedly until it is high (equal to '1'). The
4310 * EEPROM will signal that the command has been completed by
4311 * raising the DO signal. If DO does not go high in 10
4312 * milliseconds, then error out.
4314 for (i = 0; i < 200; i++) {
4316 if (eecd & E1000_EECD_DO)
4321 e_dbg("EEPROM Write did not complete\n");
4322 return -E1000_ERR_EEPROM;
4325 /* Recover from write */
4326 e1000_standby_eeprom(hw);
4331 /* Send the write disable command to the EEPROM (3-bit opcode plus
4332 * 6/8-bit dummy address beginning with 10). It's less work to include
4333 * the 10 of the dummy address as part of the opcode than it is to shift
4334 * it over the correct number of bits for the address. This takes the
4335 * EEPROM out of write/erase mode.
4337 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4338 (u16) (eeprom->opcode_bits + 2));
4340 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4342 return E1000_SUCCESS;
4346 * e1000_read_mac_addr - read the adapters MAC from eeprom
4347 * @hw: Struct containing variables accessed by shared code
4349 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4350 * second function of dual function devices
4352 s32 e1000_read_mac_addr(struct e1000_hw *hw)
4357 e_dbg("e1000_read_mac_addr");
4359 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4361 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4362 e_dbg("EEPROM Read Error\n");
4363 return -E1000_ERR_EEPROM;
4365 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4366 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4369 switch (hw->mac_type) {
4373 case e1000_82546_rev_3:
4374 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4375 hw->perm_mac_addr[5] ^= 0x01;
4379 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4380 hw->mac_addr[i] = hw->perm_mac_addr[i];
4381 return E1000_SUCCESS;
4385 * e1000_init_rx_addrs - Initializes receive address filters.
4386 * @hw: Struct containing variables accessed by shared code
4388 * Places the MAC address in receive address register 0 and clears the rest
4389 * of the receive address registers. Clears the multicast table. Assumes
4390 * the receiver is in reset when the routine is called.
4392 static void e1000_init_rx_addrs(struct e1000_hw *hw)
4397 e_dbg("e1000_init_rx_addrs");
4399 /* Setup the receive address. */
4400 e_dbg("Programming MAC Address into RAR[0]\n");
4402 e1000_rar_set(hw, hw->mac_addr, 0);
4404 rar_num = E1000_RAR_ENTRIES;
4406 /* Zero out the other 15 receive addresses. */
4407 e_dbg("Clearing RAR[1-15]\n");
4408 for (i = 1; i < rar_num; i++) {
4409 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4410 E1000_WRITE_FLUSH();
4411 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4412 E1000_WRITE_FLUSH();
4417 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4418 * @hw: Struct containing variables accessed by shared code
4419 * @mc_addr: the multicast address to hash
4421 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
4425 /* The portion of the address that is used for the hash table is
4426 * determined by the mc_filter_type setting.
4428 switch (hw->mc_filter_type) {
4429 /* [0] [1] [2] [3] [4] [5]
4434 /* [47:36] i.e. 0x563 for above example address */
4435 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4438 /* [46:35] i.e. 0xAC6 for above example address */
4439 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4442 /* [45:34] i.e. 0x5D8 for above example address */
4443 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4446 /* [43:32] i.e. 0x634 for above example address */
4447 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4451 hash_value &= 0xFFF;
4456 * e1000_rar_set - Puts an ethernet address into a receive address register.
4457 * @hw: Struct containing variables accessed by shared code
4458 * @addr: Address to put into receive address register
4459 * @index: Receive address register to write
4461 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
4463 u32 rar_low, rar_high;
4465 /* HW expects these in little endian so we reverse the byte order
4466 * from network order (big endian) to little endian
4468 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4469 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4470 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4472 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4476 * If there are any Rx frames queued up or otherwise present in the HW
4477 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4478 * hang. To work around this issue, we have to disable receives and
4479 * flush out all Rx frames before we enable RSS. To do so, we modify we
4480 * redirect all Rx traffic to manageability and then reset the HW.
4481 * This flushes away Rx frames, and (since the redirections to
4482 * manageability persists across resets) keeps new ones from coming in
4483 * while we work. Then, we clear the Address Valid AV bit for all MAC
4484 * addresses and undo the re-direction to manageability.
4485 * Now, frames are coming in again, but the MAC won't accept them, so
4486 * far so good. We now proceed to initialize RSS (if necessary) and
4487 * configure the Rx unit. Last, we re-enable the AV bits and continue
4490 switch (hw->mac_type) {
4492 /* Indicate to hardware the Address is Valid. */
4493 rar_high |= E1000_RAH_AV;
4497 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4498 E1000_WRITE_FLUSH();
4499 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4500 E1000_WRITE_FLUSH();
4504 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4505 * @hw: Struct containing variables accessed by shared code
4506 * @offset: Offset in VLAN filer table to write
4507 * @value: Value to write into VLAN filter table
4509 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
4513 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4514 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4515 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4516 E1000_WRITE_FLUSH();
4517 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4518 E1000_WRITE_FLUSH();
4520 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4521 E1000_WRITE_FLUSH();
4526 * e1000_clear_vfta - Clears the VLAN filer table
4527 * @hw: Struct containing variables accessed by shared code
4529 static void e1000_clear_vfta(struct e1000_hw *hw)
4533 u32 vfta_offset = 0;
4534 u32 vfta_bit_in_reg = 0;
4536 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4537 /* If the offset we want to clear is the same offset of the
4538 * manageability VLAN ID, then clear all bits except that of the
4539 * manageability unit
4541 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4542 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4543 E1000_WRITE_FLUSH();
4547 static s32 e1000_id_led_init(struct e1000_hw *hw)
4550 const u32 ledctl_mask = 0x000000FF;
4551 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4552 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4553 u16 eeprom_data, i, temp;
4554 const u16 led_mask = 0x0F;
4556 e_dbg("e1000_id_led_init");
4558 if (hw->mac_type < e1000_82540) {
4560 return E1000_SUCCESS;
4563 ledctl = er32(LEDCTL);
4564 hw->ledctl_default = ledctl;
4565 hw->ledctl_mode1 = hw->ledctl_default;
4566 hw->ledctl_mode2 = hw->ledctl_default;
4568 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4569 e_dbg("EEPROM Read Error\n");
4570 return -E1000_ERR_EEPROM;
4573 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4574 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4575 eeprom_data = ID_LED_DEFAULT;
4578 for (i = 0; i < 4; i++) {
4579 temp = (eeprom_data >> (i << 2)) & led_mask;
4581 case ID_LED_ON1_DEF2:
4582 case ID_LED_ON1_ON2:
4583 case ID_LED_ON1_OFF2:
4584 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4585 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4587 case ID_LED_OFF1_DEF2:
4588 case ID_LED_OFF1_ON2:
4589 case ID_LED_OFF1_OFF2:
4590 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4591 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4598 case ID_LED_DEF1_ON2:
4599 case ID_LED_ON1_ON2:
4600 case ID_LED_OFF1_ON2:
4601 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4602 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4604 case ID_LED_DEF1_OFF2:
4605 case ID_LED_ON1_OFF2:
4606 case ID_LED_OFF1_OFF2:
4607 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4608 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4615 return E1000_SUCCESS;
4620 * @hw: Struct containing variables accessed by shared code
4622 * Prepares SW controlable LED for use and saves the current state of the LED.
4624 s32 e1000_setup_led(struct e1000_hw *hw)
4627 s32 ret_val = E1000_SUCCESS;
4629 e_dbg("e1000_setup_led");
4631 switch (hw->mac_type) {
4632 case e1000_82542_rev2_0:
4633 case e1000_82542_rev2_1:
4636 /* No setup necessary */
4640 case e1000_82541_rev_2:
4641 case e1000_82547_rev_2:
4642 /* Turn off PHY Smart Power Down (if enabled) */
4643 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4644 &hw->phy_spd_default);
4647 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4648 (u16) (hw->phy_spd_default &
4649 ~IGP01E1000_GMII_SPD));
4654 if (hw->media_type == e1000_media_type_fiber) {
4655 ledctl = er32(LEDCTL);
4656 /* Save current LEDCTL settings */
4657 hw->ledctl_default = ledctl;
4659 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4660 E1000_LEDCTL_LED0_BLINK |
4661 E1000_LEDCTL_LED0_MODE_MASK);
4662 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4663 E1000_LEDCTL_LED0_MODE_SHIFT);
4664 ew32(LEDCTL, ledctl);
4665 } else if (hw->media_type == e1000_media_type_copper)
4666 ew32(LEDCTL, hw->ledctl_mode1);
4670 return E1000_SUCCESS;
4674 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4675 * @hw: Struct containing variables accessed by shared code
4677 s32 e1000_cleanup_led(struct e1000_hw *hw)
4679 s32 ret_val = E1000_SUCCESS;
4681 e_dbg("e1000_cleanup_led");
4683 switch (hw->mac_type) {
4684 case e1000_82542_rev2_0:
4685 case e1000_82542_rev2_1:
4688 /* No cleanup necessary */
4692 case e1000_82541_rev_2:
4693 case e1000_82547_rev_2:
4694 /* Turn on PHY Smart Power Down (if previously enabled) */
4695 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4696 hw->phy_spd_default);
4701 /* Restore LEDCTL settings */
4702 ew32(LEDCTL, hw->ledctl_default);
4706 return E1000_SUCCESS;
4710 * e1000_led_on - Turns on the software controllable LED
4711 * @hw: Struct containing variables accessed by shared code
4713 s32 e1000_led_on(struct e1000_hw *hw)
4715 u32 ctrl = er32(CTRL);
4717 e_dbg("e1000_led_on");
4719 switch (hw->mac_type) {
4720 case e1000_82542_rev2_0:
4721 case e1000_82542_rev2_1:
4723 /* Set SW Defineable Pin 0 to turn on the LED */
4724 ctrl |= E1000_CTRL_SWDPIN0;
4725 ctrl |= E1000_CTRL_SWDPIO0;
4728 if (hw->media_type == e1000_media_type_fiber) {
4729 /* Set SW Defineable Pin 0 to turn on the LED */
4730 ctrl |= E1000_CTRL_SWDPIN0;
4731 ctrl |= E1000_CTRL_SWDPIO0;
4733 /* Clear SW Defineable Pin 0 to turn on the LED */
4734 ctrl &= ~E1000_CTRL_SWDPIN0;
4735 ctrl |= E1000_CTRL_SWDPIO0;
4739 if (hw->media_type == e1000_media_type_fiber) {
4740 /* Clear SW Defineable Pin 0 to turn on the LED */
4741 ctrl &= ~E1000_CTRL_SWDPIN0;
4742 ctrl |= E1000_CTRL_SWDPIO0;
4743 } else if (hw->media_type == e1000_media_type_copper) {
4744 ew32(LEDCTL, hw->ledctl_mode2);
4745 return E1000_SUCCESS;
4752 return E1000_SUCCESS;
4756 * e1000_led_off - Turns off the software controllable LED
4757 * @hw: Struct containing variables accessed by shared code
4759 s32 e1000_led_off(struct e1000_hw *hw)
4761 u32 ctrl = er32(CTRL);
4763 e_dbg("e1000_led_off");
4765 switch (hw->mac_type) {
4766 case e1000_82542_rev2_0:
4767 case e1000_82542_rev2_1:
4769 /* Clear SW Defineable Pin 0 to turn off the LED */
4770 ctrl &= ~E1000_CTRL_SWDPIN0;
4771 ctrl |= E1000_CTRL_SWDPIO0;
4774 if (hw->media_type == e1000_media_type_fiber) {
4775 /* Clear SW Defineable Pin 0 to turn off the LED */
4776 ctrl &= ~E1000_CTRL_SWDPIN0;
4777 ctrl |= E1000_CTRL_SWDPIO0;
4779 /* Set SW Defineable Pin 0 to turn off the LED */
4780 ctrl |= E1000_CTRL_SWDPIN0;
4781 ctrl |= E1000_CTRL_SWDPIO0;
4785 if (hw->media_type == e1000_media_type_fiber) {
4786 /* Set SW Defineable Pin 0 to turn off the LED */
4787 ctrl |= E1000_CTRL_SWDPIN0;
4788 ctrl |= E1000_CTRL_SWDPIO0;
4789 } else if (hw->media_type == e1000_media_type_copper) {
4790 ew32(LEDCTL, hw->ledctl_mode1);
4791 return E1000_SUCCESS;
4798 return E1000_SUCCESS;
4802 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4803 * @hw: Struct containing variables accessed by shared code
4805 static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
4809 temp = er32(CRCERRS);
4810 temp = er32(SYMERRS);
4815 temp = er32(LATECOL);
4820 temp = er32(XONRXC);
4821 temp = er32(XONTXC);
4822 temp = er32(XOFFRXC);
4823 temp = er32(XOFFTXC);
4827 temp = er32(PRC127);
4828 temp = er32(PRC255);
4829 temp = er32(PRC511);
4830 temp = er32(PRC1023);
4831 temp = er32(PRC1522);
4854 temp = er32(PTC127);
4855 temp = er32(PTC255);
4856 temp = er32(PTC511);
4857 temp = er32(PTC1023);
4858 temp = er32(PTC1522);
4863 if (hw->mac_type < e1000_82543)
4866 temp = er32(ALGNERRC);
4867 temp = er32(RXERRC);
4869 temp = er32(CEXTERR);
4871 temp = er32(TSCTFC);
4873 if (hw->mac_type <= e1000_82544)
4876 temp = er32(MGTPRC);
4877 temp = er32(MGTPDC);
4878 temp = er32(MGTPTC);
4882 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4883 * @hw: Struct containing variables accessed by shared code
4885 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4886 * hw->ifs_params_forced to true. However, you must initialize hw->
4887 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4888 * before calling this function.
4890 void e1000_reset_adaptive(struct e1000_hw *hw)
4892 e_dbg("e1000_reset_adaptive");
4894 if (hw->adaptive_ifs) {
4895 if (!hw->ifs_params_forced) {
4896 hw->current_ifs_val = 0;
4897 hw->ifs_min_val = IFS_MIN;
4898 hw->ifs_max_val = IFS_MAX;
4899 hw->ifs_step_size = IFS_STEP;
4900 hw->ifs_ratio = IFS_RATIO;
4902 hw->in_ifs_mode = false;
4905 e_dbg("Not in Adaptive IFS mode!\n");
4910 * e1000_update_adaptive - update adaptive IFS
4911 * @hw: Struct containing variables accessed by shared code
4912 * @tx_packets: Number of transmits since last callback
4913 * @total_collisions: Number of collisions since last callback
4915 * Called during the callback/watchdog routine to update IFS value based on
4916 * the ratio of transmits to collisions.
4918 void e1000_update_adaptive(struct e1000_hw *hw)
4920 e_dbg("e1000_update_adaptive");
4922 if (hw->adaptive_ifs) {
4923 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4924 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4925 hw->in_ifs_mode = true;
4926 if (hw->current_ifs_val < hw->ifs_max_val) {
4927 if (hw->current_ifs_val == 0)
4928 hw->current_ifs_val =
4931 hw->current_ifs_val +=
4933 ew32(AIT, hw->current_ifs_val);
4938 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4939 hw->current_ifs_val = 0;
4940 hw->in_ifs_mode = false;
4945 e_dbg("Not in Adaptive IFS mode!\n");
4950 * e1000_tbi_adjust_stats
4951 * @hw: Struct containing variables accessed by shared code
4952 * @frame_len: The length of the frame in question
4953 * @mac_addr: The Ethernet destination address of the frame in question
4955 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4957 void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4958 u32 frame_len, u8 *mac_addr)
4962 /* First adjust the frame length. */
4964 /* We need to adjust the statistics counters, since the hardware
4965 * counters overcount this packet as a CRC error and undercount
4966 * the packet as a good packet
4968 /* This packet should not be counted as a CRC error. */
4970 /* This packet does count as a Good Packet Received. */
4973 /* Adjust the Good Octets received counters */
4974 carry_bit = 0x80000000 & stats->gorcl;
4975 stats->gorcl += frame_len;
4976 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4977 * Received Count) was one before the addition,
4978 * AND it is zero after, then we lost the carry out,
4979 * need to add one to Gorch (Good Octets Received Count High).
4980 * This could be simplified if all environments supported
4983 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4985 /* Is this a broadcast or multicast? Check broadcast first,
4986 * since the test for a multicast frame will test positive on
4987 * a broadcast frame.
4989 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4990 /* Broadcast packet */
4992 else if (*mac_addr & 0x01)
4993 /* Multicast packet */
4996 if (frame_len == hw->max_frame_size) {
4997 /* In this case, the hardware has overcounted the number of
5004 /* Adjust the bin counters when the extra byte put the frame in the
5005 * wrong bin. Remember that the frame_len was adjusted above.
5007 if (frame_len == 64) {
5010 } else if (frame_len == 127) {
5013 } else if (frame_len == 255) {
5016 } else if (frame_len == 511) {
5019 } else if (frame_len == 1023) {
5022 } else if (frame_len == 1522) {
5028 * e1000_get_bus_info
5029 * @hw: Struct containing variables accessed by shared code
5031 * Gets the current PCI bus type, speed, and width of the hardware
5033 void e1000_get_bus_info(struct e1000_hw *hw)
5037 switch (hw->mac_type) {
5038 case e1000_82542_rev2_0:
5039 case e1000_82542_rev2_1:
5040 hw->bus_type = e1000_bus_type_pci;
5041 hw->bus_speed = e1000_bus_speed_unknown;
5042 hw->bus_width = e1000_bus_width_unknown;
5045 status = er32(STATUS);
5046 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5047 e1000_bus_type_pcix : e1000_bus_type_pci;
5049 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5050 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5051 e1000_bus_speed_66 : e1000_bus_speed_120;
5052 } else if (hw->bus_type == e1000_bus_type_pci) {
5053 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5054 e1000_bus_speed_66 : e1000_bus_speed_33;
5056 switch (status & E1000_STATUS_PCIX_SPEED) {
5057 case E1000_STATUS_PCIX_SPEED_66:
5058 hw->bus_speed = e1000_bus_speed_66;
5060 case E1000_STATUS_PCIX_SPEED_100:
5061 hw->bus_speed = e1000_bus_speed_100;
5063 case E1000_STATUS_PCIX_SPEED_133:
5064 hw->bus_speed = e1000_bus_speed_133;
5067 hw->bus_speed = e1000_bus_speed_reserved;
5071 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5072 e1000_bus_width_64 : e1000_bus_width_32;
5078 * e1000_write_reg_io
5079 * @hw: Struct containing variables accessed by shared code
5080 * @offset: offset to write to
5081 * @value: value to write
5083 * Writes a value to one of the devices registers using port I/O (as opposed to
5084 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5086 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
5088 unsigned long io_addr = hw->io_base;
5089 unsigned long io_data = hw->io_base + 4;
5091 e1000_io_write(hw, io_addr, offset);
5092 e1000_io_write(hw, io_data, value);
5096 * e1000_get_cable_length - Estimates the cable length.
5097 * @hw: Struct containing variables accessed by shared code
5098 * @min_length: The estimated minimum length
5099 * @max_length: The estimated maximum length
5101 * returns: - E1000_ERR_XXX
5104 * This function always returns a ranged length (minimum & maximum).
5105 * So for M88 phy's, this function interprets the one value returned from the
5106 * register to the minimum and maximum range.
5107 * For IGP phy's, the function calculates the range by the AGC registers.
5109 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
5117 e_dbg("e1000_get_cable_length");
5119 *min_length = *max_length = 0;
5121 /* Use old method for Phy older than IGP */
5122 if (hw->phy_type == e1000_phy_m88) {
5124 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5128 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5129 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
5131 /* Convert the enum value to ranged values */
5132 switch (cable_length) {
5133 case e1000_cable_length_50:
5135 *max_length = e1000_igp_cable_length_50;
5137 case e1000_cable_length_50_80:
5138 *min_length = e1000_igp_cable_length_50;
5139 *max_length = e1000_igp_cable_length_80;
5141 case e1000_cable_length_80_110:
5142 *min_length = e1000_igp_cable_length_80;
5143 *max_length = e1000_igp_cable_length_110;
5145 case e1000_cable_length_110_140:
5146 *min_length = e1000_igp_cable_length_110;
5147 *max_length = e1000_igp_cable_length_140;
5149 case e1000_cable_length_140:
5150 *min_length = e1000_igp_cable_length_140;
5151 *max_length = e1000_igp_cable_length_170;
5154 return -E1000_ERR_PHY;
5157 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5159 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5160 static const u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5161 IGP01E1000_PHY_AGC_A,
5162 IGP01E1000_PHY_AGC_B,
5163 IGP01E1000_PHY_AGC_C,
5164 IGP01E1000_PHY_AGC_D
5166 /* Read the AGC registers for all channels */
5167 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5170 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5174 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5176 /* Value bound check. */
5177 if ((cur_agc_value >=
5178 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
5179 || (cur_agc_value == 0))
5180 return -E1000_ERR_PHY;
5182 agc_value += cur_agc_value;
5184 /* Update minimal AGC value. */
5185 if (min_agc_value > cur_agc_value)
5186 min_agc_value = cur_agc_value;
5189 /* Remove the minimal AGC result for length < 50m */
5191 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5192 agc_value -= min_agc_value;
5194 /* Get the average length of the remaining 3 channels */
5195 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5197 /* Get the average length of all the 4 channels. */
5198 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5201 /* Set the range of the calculated length. */
5202 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5203 IGP01E1000_AGC_RANGE) > 0) ?
5204 (e1000_igp_cable_length_table[agc_value] -
5205 IGP01E1000_AGC_RANGE) : 0;
5206 *max_length = e1000_igp_cable_length_table[agc_value] +
5207 IGP01E1000_AGC_RANGE;
5210 return E1000_SUCCESS;
5214 * e1000_check_polarity - Check the cable polarity
5215 * @hw: Struct containing variables accessed by shared code
5216 * @polarity: output parameter : 0 - Polarity is not reversed
5217 * 1 - Polarity is reversed.
5219 * returns: - E1000_ERR_XXX
5222 * For phy's older than IGP, this function simply reads the polarity bit in the
5223 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5224 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5225 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5226 * IGP01E1000_PHY_PCS_INIT_REG.
5228 static s32 e1000_check_polarity(struct e1000_hw *hw,
5229 e1000_rev_polarity *polarity)
5234 e_dbg("e1000_check_polarity");
5236 if (hw->phy_type == e1000_phy_m88) {
5237 /* return the Polarity bit in the Status register. */
5238 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5242 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5243 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5244 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5246 } else if (hw->phy_type == e1000_phy_igp) {
5247 /* Read the Status register to check the speed */
5248 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5253 /* If speed is 1000 Mbps, must read the
5254 * IGP01E1000_PHY_PCS_INIT_REG to find the polarity status
5256 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5257 IGP01E1000_PSSR_SPEED_1000MBPS) {
5259 /* Read the GIG initialization PCS register (0x00B4) */
5261 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5266 /* Check the polarity bits */
5267 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5268 e1000_rev_polarity_reversed :
5269 e1000_rev_polarity_normal;
5271 /* For 10 Mbps, read the polarity bit in the status
5272 * register. (for 100 Mbps this bit is always 0)
5275 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5276 e1000_rev_polarity_reversed :
5277 e1000_rev_polarity_normal;
5280 return E1000_SUCCESS;
5284 * e1000_check_downshift - Check if Downshift occurred
5285 * @hw: Struct containing variables accessed by shared code
5286 * @downshift: output parameter : 0 - No Downshift occurred.
5287 * 1 - Downshift occurred.
5289 * returns: - E1000_ERR_XXX
5292 * For phy's older than IGP, this function reads the Downshift bit in the Phy
5293 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5294 * Link Health register. In IGP this bit is latched high, so the driver must
5295 * read it immediately after link is established.
5297 static s32 e1000_check_downshift(struct e1000_hw *hw)
5302 e_dbg("e1000_check_downshift");
5304 if (hw->phy_type == e1000_phy_igp) {
5305 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5310 hw->speed_downgraded =
5311 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5312 } else if (hw->phy_type == e1000_phy_m88) {
5313 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5318 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5319 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5322 return E1000_SUCCESS;
5325 static const u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
5326 IGP01E1000_PHY_AGC_PARAM_A,
5327 IGP01E1000_PHY_AGC_PARAM_B,
5328 IGP01E1000_PHY_AGC_PARAM_C,
5329 IGP01E1000_PHY_AGC_PARAM_D
5332 static s32 e1000_1000Mb_check_cable_length(struct e1000_hw *hw)
5334 u16 min_length, max_length;
5338 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5342 if (hw->dsp_config_state != e1000_dsp_config_enabled)
5345 if (min_length >= e1000_igp_cable_length_50) {
5346 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5347 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5352 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5354 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5359 hw->dsp_config_state = e1000_dsp_config_activated;
5361 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5364 /* clear previous idle error counts */
5365 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
5369 for (i = 0; i < ffe_idle_err_timeout; i++) {
5371 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5376 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5377 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5378 hw->ffe_config_state = e1000_ffe_config_active;
5380 ret_val = e1000_write_phy_reg(hw,
5381 IGP01E1000_PHY_DSP_FFE,
5382 IGP01E1000_PHY_DSP_FFE_CM_CP);
5389 ffe_idle_err_timeout =
5390 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5398 * e1000_config_dsp_after_link_change
5399 * @hw: Struct containing variables accessed by shared code
5400 * @link_up: was link up at the time this was called
5402 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5403 * E1000_SUCCESS at any other case.
5405 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5406 * gigabit link is achieved to improve link quality.
5409 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
5412 u16 phy_data, phy_saved_data, speed, duplex, i;
5414 e_dbg("e1000_config_dsp_after_link_change");
5416 if (hw->phy_type != e1000_phy_igp)
5417 return E1000_SUCCESS;
5420 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5422 e_dbg("Error getting link speed and duplex\n");
5426 if (speed == SPEED_1000) {
5427 ret_val = e1000_1000Mb_check_cable_length(hw);
5432 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5433 /* Save off the current value of register 0x2F5B to be
5434 * restored at the end of the routines.
5437 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5442 /* Disable the PHY transmitter */
5443 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5450 ret_val = e1000_write_phy_reg(hw, 0x0000,
5451 IGP01E1000_IEEE_FORCE_GIGA);
5454 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5456 e1000_read_phy_reg(hw, dsp_reg_array[i],
5461 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5462 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5465 e1000_write_phy_reg(hw, dsp_reg_array[i],
5471 ret_val = e1000_write_phy_reg(hw, 0x0000,
5472 IGP01E1000_IEEE_RESTART_AUTONEG);
5478 /* Now enable the transmitter */
5480 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5485 hw->dsp_config_state = e1000_dsp_config_enabled;
5488 if (hw->ffe_config_state == e1000_ffe_config_active) {
5489 /* Save off the current value of register 0x2F5B to be
5490 * restored at the end of the routines.
5493 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5498 /* Disable the PHY transmitter */
5499 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5506 ret_val = e1000_write_phy_reg(hw, 0x0000,
5507 IGP01E1000_IEEE_FORCE_GIGA);
5511 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5512 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5516 ret_val = e1000_write_phy_reg(hw, 0x0000,
5517 IGP01E1000_IEEE_RESTART_AUTONEG);
5523 /* Now enable the transmitter */
5525 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5530 hw->ffe_config_state = e1000_ffe_config_enabled;
5533 return E1000_SUCCESS;
5537 * e1000_set_phy_mode - Set PHY to class A mode
5538 * @hw: Struct containing variables accessed by shared code
5540 * Assumes the following operations will follow to enable the new class mode.
5541 * 1. Do a PHY soft reset
5542 * 2. Restart auto-negotiation or force link.
5544 static s32 e1000_set_phy_mode(struct e1000_hw *hw)
5549 e_dbg("e1000_set_phy_mode");
5551 if ((hw->mac_type == e1000_82545_rev_3) &&
5552 (hw->media_type == e1000_media_type_copper)) {
5554 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5560 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5561 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5563 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5568 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5573 hw->phy_reset_disable = false;
5577 return E1000_SUCCESS;
5581 * e1000_set_d3_lplu_state - set d3 link power state
5582 * @hw: Struct containing variables accessed by shared code
5583 * @active: true to enable lplu false to disable lplu.
5585 * This function sets the lplu state according to the active flag. When
5586 * activating lplu this function also disables smart speed and vise versa.
5587 * lplu will not be activated unless the device autonegotiation advertisement
5588 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5590 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5591 * E1000_SUCCESS at any other case.
5593 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
5597 e_dbg("e1000_set_d3_lplu_state");
5599 if (hw->phy_type != e1000_phy_igp)
5600 return E1000_SUCCESS;
5602 /* During driver activity LPLU should not be used or it will attain link
5603 * from the lowest speeds starting from 10Mbps. The capability is used
5604 * for Dx transitions and states
5606 if (hw->mac_type == e1000_82541_rev_2
5607 || hw->mac_type == e1000_82547_rev_2) {
5609 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5615 if (hw->mac_type == e1000_82541_rev_2 ||
5616 hw->mac_type == e1000_82547_rev_2) {
5617 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5619 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5625 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
5626 * during Dx states where the power conservation is most
5627 * important. During driver activity we should enable
5628 * SmartSpeed, so performance is maintained.
5630 if (hw->smart_speed == e1000_smart_speed_on) {
5632 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5637 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5639 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5643 } else if (hw->smart_speed == e1000_smart_speed_off) {
5645 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5650 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5652 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5657 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5658 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5659 || (hw->autoneg_advertised ==
5660 AUTONEG_ADVERTISE_10_100_ALL)) {
5662 if (hw->mac_type == e1000_82541_rev_2 ||
5663 hw->mac_type == e1000_82547_rev_2) {
5664 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5666 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5672 /* When LPLU is enabled we should disable SmartSpeed */
5674 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5679 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5681 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5687 return E1000_SUCCESS;
5691 * e1000_set_vco_speed
5692 * @hw: Struct containing variables accessed by shared code
5694 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5696 static s32 e1000_set_vco_speed(struct e1000_hw *hw)
5699 u16 default_page = 0;
5702 e_dbg("e1000_set_vco_speed");
5704 switch (hw->mac_type) {
5705 case e1000_82545_rev_3:
5706 case e1000_82546_rev_3:
5709 return E1000_SUCCESS;
5712 /* Set PHY register 30, page 5, bit 8 to 0 */
5715 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5719 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5723 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5727 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5728 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5732 /* Set PHY register 30, page 4, bit 11 to 1 */
5734 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5738 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5742 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5743 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5748 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5752 return E1000_SUCCESS;
5757 * e1000_enable_mng_pass_thru - check for bmc pass through
5758 * @hw: Struct containing variables accessed by shared code
5760 * Verifies the hardware needs to allow ARPs to be processed by the host
5761 * returns: - true/false
5763 u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5767 if (hw->asf_firmware_present) {
5770 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5771 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5773 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5779 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5785 /* Polarity reversal workaround for forced 10F/10H links. */
5787 /* Disable the transmitter on the PHY */
5789 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5792 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5796 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5800 /* This loop will early-out if the NO link condition has been met. */
5801 for (i = PHY_FORCE_TIME; i > 0; i--) {
5802 /* Read the MII Status Register and wait for Link Status bit
5806 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5810 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5814 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5819 /* Recommended delay time after link has been lost */
5822 /* Now we will re-enable th transmitter on the PHY */
5824 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5828 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5832 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5836 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5840 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5844 /* This loop will early-out if the link condition has been met. */
5845 for (i = PHY_FORCE_TIME; i > 0; i--) {
5846 /* Read the MII Status Register and wait for Link Status bit
5850 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5854 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5858 if (mii_status_reg & MII_SR_LINK_STATUS)
5862 return E1000_SUCCESS;
5866 * e1000_get_auto_rd_done
5867 * @hw: Struct containing variables accessed by shared code
5869 * Check for EEPROM Auto Read bit done.
5870 * returns: - E1000_ERR_RESET if fail to reset MAC
5871 * E1000_SUCCESS at any other case.
5873 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
5875 e_dbg("e1000_get_auto_rd_done");
5877 return E1000_SUCCESS;
5881 * e1000_get_phy_cfg_done
5882 * @hw: Struct containing variables accessed by shared code
5884 * Checks if the PHY configuration is done
5885 * returns: - E1000_ERR_RESET if fail to reset MAC
5886 * E1000_SUCCESS at any other case.
5888 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
5890 e_dbg("e1000_get_phy_cfg_done");
5892 return E1000_SUCCESS;