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
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
36 static s32 e1000_check_downshift(struct e1000_hw *hw);
37 static s32 e1000_check_polarity(struct e1000_hw *hw,
38 e1000_rev_polarity *polarity);
39 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
40 static void e1000_clear_vfta(struct e1000_hw *hw);
41 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
43 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
44 static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
45 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
46 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
48 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
49 static s32 e1000_id_led_init(struct e1000_hw *hw);
50 static void e1000_init_rx_addrs(struct e1000_hw *hw);
51 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
52 struct e1000_phy_info *phy_info);
53 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
55 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
57 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
58 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
59 struct e1000_phy_info *phy_info);
60 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
61 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
62 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
63 static s32 e1000_set_phy_type(struct e1000_hw *hw);
64 static void e1000_phy_init_script(struct e1000_hw *hw);
65 static s32 e1000_setup_copper_link(struct e1000_hw *hw);
66 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
67 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
68 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
69 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
70 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
71 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
72 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data,
74 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
75 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
76 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
77 u16 words, u16 *data);
78 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
79 u16 words, u16 *data);
80 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
81 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
82 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
83 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
84 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
86 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr,
88 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
89 static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
90 static void e1000_release_eeprom(struct e1000_hw *hw);
91 static void e1000_standby_eeprom(struct e1000_hw *hw);
92 static s32 e1000_set_vco_speed(struct e1000_hw *hw);
93 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
94 static s32 e1000_set_phy_mode(struct e1000_hw *hw);
95 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
96 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
98 /* IGP cable length table */
100 u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
101 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
102 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
103 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
104 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
105 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
106 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
107 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
108 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
110 static DEFINE_SPINLOCK(e1000_eeprom_lock);
112 /******************************************************************************
113 * Set the phy type member in the hw struct.
115 * hw - Struct containing variables accessed by shared code
116 *****************************************************************************/
117 static s32 e1000_set_phy_type(struct e1000_hw *hw)
119 DEBUGFUNC("e1000_set_phy_type");
121 if (hw->mac_type == e1000_undefined)
122 return -E1000_ERR_PHY_TYPE;
124 switch (hw->phy_id) {
125 case M88E1000_E_PHY_ID:
126 case M88E1000_I_PHY_ID:
127 case M88E1011_I_PHY_ID:
128 case M88E1111_I_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;
140 /* Should never have loaded on this device */
141 hw->phy_type = e1000_phy_undefined;
142 return -E1000_ERR_PHY_TYPE;
145 return E1000_SUCCESS;
148 /******************************************************************************
149 * IGP phy init script - initializes the GbE PHY
151 * hw - Struct containing variables accessed by shared code
152 *****************************************************************************/
153 static void e1000_phy_init_script(struct e1000_hw *hw)
158 DEBUGFUNC("e1000_phy_init_script");
160 if (hw->phy_init_script) {
163 /* Save off the current value of register 0x2F5B to be restored at
164 * the end of this routine. */
165 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
167 /* Disabled the PHY transmitter */
168 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
172 e1000_write_phy_reg(hw,0x0000,0x0140);
176 switch (hw->mac_type) {
179 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
181 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
183 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
185 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
187 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
189 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
191 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
193 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
195 e1000_write_phy_reg(hw, 0x2010, 0x0008);
198 case e1000_82541_rev_2:
199 case e1000_82547_rev_2:
200 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
206 e1000_write_phy_reg(hw, 0x0000, 0x3300);
210 /* Now enable the transmitter */
211 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
213 if (hw->mac_type == e1000_82547) {
214 u16 fused, fine, coarse;
216 /* Move to analog registers page */
217 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
219 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
220 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
222 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
223 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
225 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
226 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
227 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
228 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
229 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
231 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
232 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
233 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
235 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
236 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
237 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
243 /******************************************************************************
244 * Set the mac type member in the hw struct.
246 * hw - Struct containing variables accessed by shared code
247 *****************************************************************************/
248 s32 e1000_set_mac_type(struct e1000_hw *hw)
250 DEBUGFUNC("e1000_set_mac_type");
252 switch (hw->device_id) {
253 case E1000_DEV_ID_82542:
254 switch (hw->revision_id) {
255 case E1000_82542_2_0_REV_ID:
256 hw->mac_type = e1000_82542_rev2_0;
258 case E1000_82542_2_1_REV_ID:
259 hw->mac_type = e1000_82542_rev2_1;
262 /* Invalid 82542 revision ID */
263 return -E1000_ERR_MAC_TYPE;
266 case E1000_DEV_ID_82543GC_FIBER:
267 case E1000_DEV_ID_82543GC_COPPER:
268 hw->mac_type = e1000_82543;
270 case E1000_DEV_ID_82544EI_COPPER:
271 case E1000_DEV_ID_82544EI_FIBER:
272 case E1000_DEV_ID_82544GC_COPPER:
273 case E1000_DEV_ID_82544GC_LOM:
274 hw->mac_type = e1000_82544;
276 case E1000_DEV_ID_82540EM:
277 case E1000_DEV_ID_82540EM_LOM:
278 case E1000_DEV_ID_82540EP:
279 case E1000_DEV_ID_82540EP_LOM:
280 case E1000_DEV_ID_82540EP_LP:
281 hw->mac_type = e1000_82540;
283 case E1000_DEV_ID_82545EM_COPPER:
284 case E1000_DEV_ID_82545EM_FIBER:
285 hw->mac_type = e1000_82545;
287 case E1000_DEV_ID_82545GM_COPPER:
288 case E1000_DEV_ID_82545GM_FIBER:
289 case E1000_DEV_ID_82545GM_SERDES:
290 hw->mac_type = e1000_82545_rev_3;
292 case E1000_DEV_ID_82546EB_COPPER:
293 case E1000_DEV_ID_82546EB_FIBER:
294 case E1000_DEV_ID_82546EB_QUAD_COPPER:
295 hw->mac_type = e1000_82546;
297 case E1000_DEV_ID_82546GB_COPPER:
298 case E1000_DEV_ID_82546GB_FIBER:
299 case E1000_DEV_ID_82546GB_SERDES:
300 case E1000_DEV_ID_82546GB_PCIE:
301 case E1000_DEV_ID_82546GB_QUAD_COPPER:
302 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
303 hw->mac_type = e1000_82546_rev_3;
305 case E1000_DEV_ID_82541EI:
306 case E1000_DEV_ID_82541EI_MOBILE:
307 case E1000_DEV_ID_82541ER_LOM:
308 hw->mac_type = e1000_82541;
310 case E1000_DEV_ID_82541ER:
311 case E1000_DEV_ID_82541GI:
312 case E1000_DEV_ID_82541GI_LF:
313 case E1000_DEV_ID_82541GI_MOBILE:
314 hw->mac_type = e1000_82541_rev_2;
316 case E1000_DEV_ID_82547EI:
317 case E1000_DEV_ID_82547EI_MOBILE:
318 hw->mac_type = e1000_82547;
320 case E1000_DEV_ID_82547GI:
321 hw->mac_type = e1000_82547_rev_2;
324 /* Should never have loaded on this device */
325 return -E1000_ERR_MAC_TYPE;
328 switch (hw->mac_type) {
331 case e1000_82541_rev_2:
332 case e1000_82547_rev_2:
333 hw->asf_firmware_present = true;
339 /* The 82543 chip does not count tx_carrier_errors properly in
342 if (hw->mac_type == e1000_82543)
343 hw->bad_tx_carr_stats_fd = true;
345 if (hw->mac_type > e1000_82544)
346 hw->has_smbus = true;
348 return E1000_SUCCESS;
351 /*****************************************************************************
352 * Set media type and TBI compatibility.
354 * hw - Struct containing variables accessed by shared code
355 * **************************************************************************/
356 void e1000_set_media_type(struct e1000_hw *hw)
360 DEBUGFUNC("e1000_set_media_type");
362 if (hw->mac_type != e1000_82543) {
363 /* tbi_compatibility is only valid on 82543 */
364 hw->tbi_compatibility_en = false;
367 switch (hw->device_id) {
368 case E1000_DEV_ID_82545GM_SERDES:
369 case E1000_DEV_ID_82546GB_SERDES:
370 hw->media_type = e1000_media_type_internal_serdes;
373 switch (hw->mac_type) {
374 case e1000_82542_rev2_0:
375 case e1000_82542_rev2_1:
376 hw->media_type = e1000_media_type_fiber;
379 status = er32(STATUS);
380 if (status & E1000_STATUS_TBIMODE) {
381 hw->media_type = e1000_media_type_fiber;
382 /* tbi_compatibility not valid on fiber */
383 hw->tbi_compatibility_en = false;
385 hw->media_type = e1000_media_type_copper;
392 /******************************************************************************
393 * Reset the transmit and receive units; mask and clear all interrupts.
395 * hw - Struct containing variables accessed by shared code
396 *****************************************************************************/
397 s32 e1000_reset_hw(struct e1000_hw *hw)
406 DEBUGFUNC("e1000_reset_hw");
408 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
409 if (hw->mac_type == e1000_82542_rev2_0) {
410 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
411 e1000_pci_clear_mwi(hw);
414 /* Clear interrupt mask to stop board from generating interrupts */
415 DEBUGOUT("Masking off all interrupts\n");
416 ew32(IMC, 0xffffffff);
418 /* Disable the Transmit and Receive units. Then delay to allow
419 * any pending transactions to complete before we hit the MAC with
423 ew32(TCTL, E1000_TCTL_PSP);
426 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
427 hw->tbi_compatibility_on = false;
429 /* Delay to allow any outstanding PCI transactions to complete before
430 * resetting the device
436 /* Must reset the PHY before resetting the MAC */
437 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
438 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
442 /* Issue a global reset to the MAC. This will reset the chip's
443 * transmit, receive, DMA, and link units. It will not effect
444 * the current PCI configuration. The global reset bit is self-
445 * clearing, and should clear within a microsecond.
447 DEBUGOUT("Issuing a global reset to MAC\n");
449 switch (hw->mac_type) {
455 case e1000_82541_rev_2:
456 /* These controllers can't ack the 64-bit write when issuing the
457 * reset, so use IO-mapping as a workaround to issue the reset */
458 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
460 case e1000_82545_rev_3:
461 case e1000_82546_rev_3:
462 /* Reset is performed on a shadow of the control register */
463 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
466 ew32(CTRL, (ctrl | E1000_CTRL_RST));
470 /* After MAC reset, force reload of EEPROM to restore power-on settings to
471 * device. Later controllers reload the EEPROM automatically, so just wait
472 * for reload to complete.
474 switch (hw->mac_type) {
475 case e1000_82542_rev2_0:
476 case e1000_82542_rev2_1:
479 /* Wait for reset to complete */
481 ctrl_ext = er32(CTRL_EXT);
482 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
483 ew32(CTRL_EXT, ctrl_ext);
485 /* Wait for EEPROM reload */
489 case e1000_82541_rev_2:
491 case e1000_82547_rev_2:
492 /* Wait for EEPROM reload */
496 /* Auto read done will delay 5ms or poll based on mac type */
497 ret_val = e1000_get_auto_rd_done(hw);
503 /* Disable HW ARPs on ASF enabled adapters */
504 if (hw->mac_type >= e1000_82540) {
506 manc &= ~(E1000_MANC_ARP_EN);
510 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
511 e1000_phy_init_script(hw);
513 /* Configure activity LED after PHY reset */
514 led_ctrl = er32(LEDCTL);
515 led_ctrl &= IGP_ACTIVITY_LED_MASK;
516 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
517 ew32(LEDCTL, led_ctrl);
520 /* Clear interrupt mask to stop board from generating interrupts */
521 DEBUGOUT("Masking off all interrupts\n");
522 ew32(IMC, 0xffffffff);
524 /* Clear any pending interrupt events. */
527 /* If MWI was previously enabled, reenable it. */
528 if (hw->mac_type == e1000_82542_rev2_0) {
529 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
530 e1000_pci_set_mwi(hw);
533 return E1000_SUCCESS;
536 /******************************************************************************
537 * Performs basic configuration of the adapter.
539 * hw - Struct containing variables accessed by shared code
541 * Assumes that the controller has previously been reset and is in a
542 * post-reset uninitialized state. Initializes the receive address registers,
543 * multicast table, and VLAN filter table. Calls routines to setup link
544 * configuration and flow control settings. Clears all on-chip counters. Leaves
545 * the transmit and receive units disabled and uninitialized.
546 *****************************************************************************/
547 s32 e1000_init_hw(struct e1000_hw *hw)
555 DEBUGFUNC("e1000_init_hw");
557 /* Initialize Identification LED */
558 ret_val = e1000_id_led_init(hw);
560 DEBUGOUT("Error Initializing Identification LED\n");
564 /* Set the media type and TBI compatibility */
565 e1000_set_media_type(hw);
567 /* Disabling VLAN filtering. */
568 DEBUGOUT("Initializing the IEEE VLAN\n");
569 if (hw->mac_type < e1000_82545_rev_3)
571 e1000_clear_vfta(hw);
573 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
574 if (hw->mac_type == e1000_82542_rev2_0) {
575 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
576 e1000_pci_clear_mwi(hw);
577 ew32(RCTL, E1000_RCTL_RST);
582 /* Setup the receive address. This involves initializing all of the Receive
583 * Address Registers (RARs 0 - 15).
585 e1000_init_rx_addrs(hw);
587 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
588 if (hw->mac_type == e1000_82542_rev2_0) {
592 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
593 e1000_pci_set_mwi(hw);
596 /* Zero out the Multicast HASH table */
597 DEBUGOUT("Zeroing the MTA\n");
598 mta_size = E1000_MC_TBL_SIZE;
599 for (i = 0; i < mta_size; i++) {
600 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
601 /* use write flush to prevent Memory Write Block (MWB) from
602 * occuring when accessing our register space */
606 /* Set the PCI priority bit correctly in the CTRL register. This
607 * determines if the adapter gives priority to receives, or if it
608 * gives equal priority to transmits and receives. Valid only on
609 * 82542 and 82543 silicon.
611 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
613 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
616 switch (hw->mac_type) {
617 case e1000_82545_rev_3:
618 case e1000_82546_rev_3:
621 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
622 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
623 e1000_pcix_set_mmrbc(hw, 2048);
627 /* Call a subroutine to configure the link and setup flow control. */
628 ret_val = e1000_setup_link(hw);
630 /* Set the transmit descriptor write-back policy */
631 if (hw->mac_type > e1000_82544) {
633 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
637 /* Clear all of the statistics registers (clear on read). It is
638 * important that we do this after we have tried to establish link
639 * because the symbol error count will increment wildly if there
642 e1000_clear_hw_cntrs(hw);
644 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
645 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
646 ctrl_ext = er32(CTRL_EXT);
647 /* Relaxed ordering must be disabled to avoid a parity
648 * error crash in a PCI slot. */
649 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
650 ew32(CTRL_EXT, ctrl_ext);
656 /******************************************************************************
657 * Adjust SERDES output amplitude based on EEPROM setting.
659 * hw - Struct containing variables accessed by shared code.
660 *****************************************************************************/
661 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
666 DEBUGFUNC("e1000_adjust_serdes_amplitude");
668 if (hw->media_type != e1000_media_type_internal_serdes)
669 return E1000_SUCCESS;
671 switch (hw->mac_type) {
672 case e1000_82545_rev_3:
673 case e1000_82546_rev_3:
676 return E1000_SUCCESS;
679 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
684 if (eeprom_data != EEPROM_RESERVED_WORD) {
685 /* Adjust SERDES output amplitude only. */
686 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
687 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
692 return E1000_SUCCESS;
695 /******************************************************************************
696 * Configures flow control and link settings.
698 * hw - Struct containing variables accessed by shared code
700 * Determines which flow control settings to use. Calls the apropriate media-
701 * specific link configuration function. Configures the flow control settings.
702 * Assuming the adapter has a valid link partner, a valid link should be
703 * established. Assumes the hardware has previously been reset and the
704 * transmitter and receiver are not enabled.
705 *****************************************************************************/
706 s32 e1000_setup_link(struct e1000_hw *hw)
712 DEBUGFUNC("e1000_setup_link");
714 /* Read and store word 0x0F of the EEPROM. This word contains bits
715 * that determine the hardware's default PAUSE (flow control) mode,
716 * a bit that determines whether the HW defaults to enabling or
717 * disabling auto-negotiation, and the direction of the
718 * SW defined pins. If there is no SW over-ride of the flow
719 * control setting, then the variable hw->fc will
720 * be initialized based on a value in the EEPROM.
722 if (hw->fc == E1000_FC_DEFAULT) {
723 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
726 DEBUGOUT("EEPROM Read Error\n");
727 return -E1000_ERR_EEPROM;
729 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
730 hw->fc = E1000_FC_NONE;
731 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
732 EEPROM_WORD0F_ASM_DIR)
733 hw->fc = E1000_FC_TX_PAUSE;
735 hw->fc = E1000_FC_FULL;
738 /* We want to save off the original Flow Control configuration just
739 * in case we get disconnected and then reconnected into a different
740 * hub or switch with different Flow Control capabilities.
742 if (hw->mac_type == e1000_82542_rev2_0)
743 hw->fc &= (~E1000_FC_TX_PAUSE);
745 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
746 hw->fc &= (~E1000_FC_RX_PAUSE);
748 hw->original_fc = hw->fc;
750 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
752 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
753 * polarity value for the SW controlled pins, and setup the
754 * Extended Device Control reg with that info.
755 * This is needed because one of the SW controlled pins is used for
756 * signal detection. So this should be done before e1000_setup_pcs_link()
757 * or e1000_phy_setup() is called.
759 if (hw->mac_type == e1000_82543) {
760 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
763 DEBUGOUT("EEPROM Read Error\n");
764 return -E1000_ERR_EEPROM;
766 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
768 ew32(CTRL_EXT, ctrl_ext);
771 /* Call the necessary subroutine to configure the link. */
772 ret_val = (hw->media_type == e1000_media_type_copper) ?
773 e1000_setup_copper_link(hw) :
774 e1000_setup_fiber_serdes_link(hw);
776 /* Initialize the flow control address, type, and PAUSE timer
777 * registers to their default values. This is done even if flow
778 * control is disabled, because it does not hurt anything to
779 * initialize these registers.
781 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
783 ew32(FCT, FLOW_CONTROL_TYPE);
784 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
785 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
787 ew32(FCTTV, hw->fc_pause_time);
789 /* Set the flow control receive threshold registers. Normally,
790 * these registers will be set to a default threshold that may be
791 * adjusted later by the driver's runtime code. However, if the
792 * ability to transmit pause frames in not enabled, then these
793 * registers will be set to 0.
795 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
799 /* We need to set up the Receive Threshold high and low water marks
800 * as well as (optionally) enabling the transmission of XON frames.
802 if (hw->fc_send_xon) {
803 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
804 ew32(FCRTH, hw->fc_high_water);
806 ew32(FCRTL, hw->fc_low_water);
807 ew32(FCRTH, hw->fc_high_water);
813 /******************************************************************************
814 * Sets up link for a fiber based or serdes based adapter
816 * hw - Struct containing variables accessed by shared code
818 * Manipulates Physical Coding Sublayer functions in order to configure
819 * link. Assumes the hardware has been previously reset and the transmitter
820 * and receiver are not enabled.
821 *****************************************************************************/
822 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
831 DEBUGFUNC("e1000_setup_fiber_serdes_link");
833 /* On adapters with a MAC newer than 82544, SWDP 1 will be
834 * set when the optics detect a signal. On older adapters, it will be
835 * cleared when there is a signal. This applies to fiber media only.
836 * If we're on serdes media, adjust the output amplitude to value
840 if (hw->media_type == e1000_media_type_fiber)
841 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
843 ret_val = e1000_adjust_serdes_amplitude(hw);
847 /* Take the link out of reset */
848 ctrl &= ~(E1000_CTRL_LRST);
850 /* Adjust VCO speed to improve BER performance */
851 ret_val = e1000_set_vco_speed(hw);
855 e1000_config_collision_dist(hw);
857 /* Check for a software override of the flow control settings, and setup
858 * the device accordingly. If auto-negotiation is enabled, then software
859 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
860 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
861 * auto-negotiation is disabled, then software will have to manually
862 * configure the two flow control enable bits in the CTRL register.
864 * The possible values of the "fc" parameter are:
865 * 0: Flow control is completely disabled
866 * 1: Rx flow control is enabled (we can receive pause frames, but
867 * not send pause frames).
868 * 2: Tx flow control is enabled (we can send pause frames but we do
869 * not support receiving pause frames).
870 * 3: Both Rx and TX flow control (symmetric) are enabled.
874 /* Flow control is completely disabled by a software over-ride. */
875 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
877 case E1000_FC_RX_PAUSE:
878 /* RX Flow control is enabled and TX Flow control is disabled by a
879 * software over-ride. Since there really isn't a way to advertise
880 * that we are capable of RX Pause ONLY, we will advertise that we
881 * support both symmetric and asymmetric RX PAUSE. Later, we will
882 * disable the adapter's ability to send PAUSE frames.
884 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
886 case E1000_FC_TX_PAUSE:
887 /* TX Flow control is enabled, and RX Flow control is disabled, by a
888 * software over-ride.
890 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
893 /* Flow control (both RX and TX) is enabled by a software over-ride. */
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
897 DEBUGOUT("Flow control param set incorrectly\n");
898 return -E1000_ERR_CONFIG;
902 /* Since auto-negotiation is enabled, take the link out of reset (the link
903 * will be in reset, because we previously reset the chip). This will
904 * restart auto-negotiation. If auto-neogtiation is successful then the
905 * link-up status bit will be set and the flow control enable bits (RFCE
906 * and TFCE) will be set according to their negotiated value.
908 DEBUGOUT("Auto-negotiation enabled\n");
917 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
918 * indication in the Device Status Register. Time-out if a link isn't
919 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
920 * less than 500 milliseconds even if the other end is doing it in SW).
921 * For internal serdes, we just assume a signal is present, then poll.
923 if (hw->media_type == e1000_media_type_internal_serdes ||
924 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
925 DEBUGOUT("Looking for Link\n");
926 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
928 status = er32(STATUS);
929 if (status & E1000_STATUS_LU) break;
931 if (i == (LINK_UP_TIMEOUT / 10)) {
932 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
933 hw->autoneg_failed = 1;
934 /* AutoNeg failed to achieve a link, so we'll call
935 * e1000_check_for_link. This routine will force the link up if
936 * we detect a signal. This will allow us to communicate with
937 * non-autonegotiating link partners.
939 ret_val = e1000_check_for_link(hw);
941 DEBUGOUT("Error while checking for link\n");
944 hw->autoneg_failed = 0;
946 hw->autoneg_failed = 0;
947 DEBUGOUT("Valid Link Found\n");
950 DEBUGOUT("No Signal Detected\n");
952 return E1000_SUCCESS;
955 /******************************************************************************
956 * Make sure we have a valid PHY and change PHY mode before link setup.
958 * hw - Struct containing variables accessed by shared code
959 ******************************************************************************/
960 static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
966 DEBUGFUNC("e1000_copper_link_preconfig");
969 /* With 82543, we need to force speed and duplex on the MAC equal to what
970 * the PHY speed and duplex configuration is. In addition, we need to
971 * perform a hardware reset on the PHY to take it out of reset.
973 if (hw->mac_type > e1000_82543) {
974 ctrl |= E1000_CTRL_SLU;
975 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
978 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
980 ret_val = e1000_phy_hw_reset(hw);
985 /* Make sure we have a valid PHY */
986 ret_val = e1000_detect_gig_phy(hw);
988 DEBUGOUT("Error, did not detect valid phy.\n");
991 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
993 /* Set PHY to class A mode (if necessary) */
994 ret_val = e1000_set_phy_mode(hw);
998 if ((hw->mac_type == e1000_82545_rev_3) ||
999 (hw->mac_type == e1000_82546_rev_3)) {
1000 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1001 phy_data |= 0x00000008;
1002 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1005 if (hw->mac_type <= e1000_82543 ||
1006 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1007 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1008 hw->phy_reset_disable = false;
1010 return E1000_SUCCESS;
1014 /********************************************************************
1015 * Copper link setup for e1000_phy_igp series.
1017 * hw - Struct containing variables accessed by shared code
1018 *********************************************************************/
1019 static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1025 DEBUGFUNC("e1000_copper_link_igp_setup");
1027 if (hw->phy_reset_disable)
1028 return E1000_SUCCESS;
1030 ret_val = e1000_phy_reset(hw);
1032 DEBUGOUT("Error Resetting the PHY\n");
1036 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1038 /* Configure activity LED after PHY reset */
1039 led_ctrl = er32(LEDCTL);
1040 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1041 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1042 ew32(LEDCTL, led_ctrl);
1044 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1045 if (hw->phy_type == e1000_phy_igp) {
1046 /* disable lplu d3 during driver init */
1047 ret_val = e1000_set_d3_lplu_state(hw, false);
1049 DEBUGOUT("Error Disabling LPLU D3\n");
1054 /* Configure mdi-mdix settings */
1055 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1059 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1060 hw->dsp_config_state = e1000_dsp_config_disabled;
1061 /* Force MDI for earlier revs of the IGP PHY */
1062 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1066 hw->dsp_config_state = e1000_dsp_config_enabled;
1067 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1071 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1074 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1078 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1082 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1086 /* set auto-master slave resolution settings */
1088 e1000_ms_type phy_ms_setting = hw->master_slave;
1090 if (hw->ffe_config_state == e1000_ffe_config_active)
1091 hw->ffe_config_state = e1000_ffe_config_enabled;
1093 if (hw->dsp_config_state == e1000_dsp_config_activated)
1094 hw->dsp_config_state = e1000_dsp_config_enabled;
1096 /* when autonegotiation advertisment is only 1000Mbps then we
1097 * should disable SmartSpeed and enable Auto MasterSlave
1098 * resolution as hardware default. */
1099 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1100 /* Disable SmartSpeed */
1101 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1105 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1106 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1110 /* Set auto Master/Slave resolution process */
1111 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1114 phy_data &= ~CR_1000T_MS_ENABLE;
1115 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1120 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1124 /* load defaults for future use */
1125 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1126 ((phy_data & CR_1000T_MS_VALUE) ?
1127 e1000_ms_force_master :
1128 e1000_ms_force_slave) :
1131 switch (phy_ms_setting) {
1132 case e1000_ms_force_master:
1133 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1135 case e1000_ms_force_slave:
1136 phy_data |= CR_1000T_MS_ENABLE;
1137 phy_data &= ~(CR_1000T_MS_VALUE);
1140 phy_data &= ~CR_1000T_MS_ENABLE;
1144 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1149 return E1000_SUCCESS;
1152 /********************************************************************
1153 * Copper link setup for e1000_phy_m88 series.
1155 * hw - Struct containing variables accessed by shared code
1156 *********************************************************************/
1157 static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1162 DEBUGFUNC("e1000_copper_link_mgp_setup");
1164 if (hw->phy_reset_disable)
1165 return E1000_SUCCESS;
1167 /* Enable CRS on TX. This must be set for half-duplex operation. */
1168 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1172 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1175 * MDI/MDI-X = 0 (default)
1176 * 0 - Auto for all speeds
1179 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1181 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1185 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1188 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1191 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1195 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1200 * disable_polarity_correction = 0 (default)
1201 * Automatic Correction for Reversed Cable Polarity
1205 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1206 if (hw->disable_polarity_correction == 1)
1207 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1208 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1212 if (hw->phy_revision < M88E1011_I_REV_4) {
1213 /* Force TX_CLK in the Extended PHY Specific Control Register
1216 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1220 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1222 if ((hw->phy_revision == E1000_REVISION_2) &&
1223 (hw->phy_id == M88E1111_I_PHY_ID)) {
1224 /* Vidalia Phy, set the downshift counter to 5x */
1225 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1226 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1227 ret_val = e1000_write_phy_reg(hw,
1228 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1232 /* Configure Master and Slave downshift values */
1233 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1234 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1235 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1236 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1237 ret_val = e1000_write_phy_reg(hw,
1238 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1244 /* SW Reset the PHY so all changes take effect */
1245 ret_val = e1000_phy_reset(hw);
1247 DEBUGOUT("Error Resetting the PHY\n");
1251 return E1000_SUCCESS;
1254 /********************************************************************
1255 * Setup auto-negotiation and flow control advertisements,
1256 * and then perform auto-negotiation.
1258 * hw - Struct containing variables accessed by shared code
1259 *********************************************************************/
1260 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1265 DEBUGFUNC("e1000_copper_link_autoneg");
1267 /* Perform some bounds checking on the hw->autoneg_advertised
1268 * parameter. If this variable is zero, then set it to the default.
1270 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1272 /* If autoneg_advertised is zero, we assume it was not defaulted
1273 * by the calling code so we set to advertise full capability.
1275 if (hw->autoneg_advertised == 0)
1276 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1278 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1279 ret_val = e1000_phy_setup_autoneg(hw);
1281 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1284 DEBUGOUT("Restarting Auto-Neg\n");
1286 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1287 * the Auto Neg Restart bit in the PHY control register.
1289 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1293 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1294 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1298 /* Does the user want to wait for Auto-Neg to complete here, or
1299 * check at a later time (for example, callback routine).
1301 if (hw->wait_autoneg_complete) {
1302 ret_val = e1000_wait_autoneg(hw);
1304 DEBUGOUT("Error while waiting for autoneg to complete\n");
1309 hw->get_link_status = true;
1311 return E1000_SUCCESS;
1314 /******************************************************************************
1315 * Config the MAC and the PHY after link is up.
1316 * 1) Set up the MAC to the current PHY speed/duplex
1317 * if we are on 82543. If we
1318 * are on newer silicon, we only need to configure
1319 * collision distance in the Transmit Control Register.
1320 * 2) Set up flow control on the MAC to that established with
1322 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1324 * hw - Struct containing variables accessed by shared code
1325 ******************************************************************************/
1326 static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
1329 DEBUGFUNC("e1000_copper_link_postconfig");
1331 if (hw->mac_type >= e1000_82544) {
1332 e1000_config_collision_dist(hw);
1334 ret_val = e1000_config_mac_to_phy(hw);
1336 DEBUGOUT("Error configuring MAC to PHY settings\n");
1340 ret_val = e1000_config_fc_after_link_up(hw);
1342 DEBUGOUT("Error Configuring Flow Control\n");
1346 /* Config DSP to improve Giga link quality */
1347 if (hw->phy_type == e1000_phy_igp) {
1348 ret_val = e1000_config_dsp_after_link_change(hw, true);
1350 DEBUGOUT("Error Configuring DSP after link up\n");
1355 return E1000_SUCCESS;
1358 /******************************************************************************
1359 * Detects which PHY is present and setup the speed and duplex
1361 * hw - Struct containing variables accessed by shared code
1362 ******************************************************************************/
1363 static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1369 DEBUGFUNC("e1000_setup_copper_link");
1371 /* Check if it is a valid PHY and set PHY mode if necessary. */
1372 ret_val = e1000_copper_link_preconfig(hw);
1376 if (hw->phy_type == e1000_phy_igp) {
1377 ret_val = e1000_copper_link_igp_setup(hw);
1380 } else if (hw->phy_type == e1000_phy_m88) {
1381 ret_val = e1000_copper_link_mgp_setup(hw);
1387 /* Setup autoneg and flow control advertisement
1388 * and perform autonegotiation */
1389 ret_val = e1000_copper_link_autoneg(hw);
1393 /* PHY will be set to 10H, 10F, 100H,or 100F
1394 * depending on value from forced_speed_duplex. */
1395 DEBUGOUT("Forcing speed and duplex\n");
1396 ret_val = e1000_phy_force_speed_duplex(hw);
1398 DEBUGOUT("Error Forcing Speed and Duplex\n");
1403 /* Check link status. Wait up to 100 microseconds for link to become
1406 for (i = 0; i < 10; i++) {
1407 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1410 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1414 if (phy_data & MII_SR_LINK_STATUS) {
1415 /* Config the MAC and PHY after link is up */
1416 ret_val = e1000_copper_link_postconfig(hw);
1420 DEBUGOUT("Valid link established!!!\n");
1421 return E1000_SUCCESS;
1426 DEBUGOUT("Unable to establish link!!!\n");
1427 return E1000_SUCCESS;
1430 /******************************************************************************
1431 * Configures PHY autoneg and flow control advertisement settings
1433 * hw - Struct containing variables accessed by shared code
1434 ******************************************************************************/
1435 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1438 u16 mii_autoneg_adv_reg;
1439 u16 mii_1000t_ctrl_reg;
1441 DEBUGFUNC("e1000_phy_setup_autoneg");
1443 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1444 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1448 /* Read the MII 1000Base-T Control Register (Address 9). */
1449 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1453 /* Need to parse both autoneg_advertised and fc and set up
1454 * the appropriate PHY registers. First we will parse for
1455 * autoneg_advertised software override. Since we can advertise
1456 * a plethora of combinations, we need to check each bit
1460 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1461 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1462 * the 1000Base-T Control Register (Address 9).
1464 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1465 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1467 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1469 /* Do we want to advertise 10 Mb Half Duplex? */
1470 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1471 DEBUGOUT("Advertise 10mb Half duplex\n");
1472 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1475 /* Do we want to advertise 10 Mb Full Duplex? */
1476 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1477 DEBUGOUT("Advertise 10mb Full duplex\n");
1478 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1481 /* Do we want to advertise 100 Mb Half Duplex? */
1482 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1483 DEBUGOUT("Advertise 100mb Half duplex\n");
1484 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1487 /* Do we want to advertise 100 Mb Full Duplex? */
1488 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1489 DEBUGOUT("Advertise 100mb Full duplex\n");
1490 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1493 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1494 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1495 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1498 /* Do we want to advertise 1000 Mb Full Duplex? */
1499 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1500 DEBUGOUT("Advertise 1000mb Full duplex\n");
1501 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1504 /* Check for a software override of the flow control settings, and
1505 * setup the PHY advertisement registers accordingly. If
1506 * auto-negotiation is enabled, then software will have to set the
1507 * "PAUSE" bits to the correct value in the Auto-Negotiation
1508 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1510 * The possible values of the "fc" parameter are:
1511 * 0: Flow control is completely disabled
1512 * 1: Rx flow control is enabled (we can receive pause frames
1513 * but not send pause frames).
1514 * 2: Tx flow control is enabled (we can send pause frames
1515 * but we do not support receiving pause frames).
1516 * 3: Both Rx and TX flow control (symmetric) are enabled.
1517 * other: No software override. The flow control configuration
1518 * in the EEPROM is used.
1521 case E1000_FC_NONE: /* 0 */
1522 /* Flow control (RX & TX) is completely disabled by a
1523 * software over-ride.
1525 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1527 case E1000_FC_RX_PAUSE: /* 1 */
1528 /* RX Flow control is enabled, and TX Flow control is
1529 * disabled, by a software over-ride.
1531 /* Since there really isn't a way to advertise that we are
1532 * capable of RX Pause ONLY, we will advertise that we
1533 * support both symmetric and asymmetric RX PAUSE. Later
1534 * (in e1000_config_fc_after_link_up) we will disable the
1535 *hw's ability to send PAUSE frames.
1537 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1539 case E1000_FC_TX_PAUSE: /* 2 */
1540 /* TX Flow control is enabled, and RX Flow control is
1541 * disabled, by a software over-ride.
1543 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1544 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1546 case E1000_FC_FULL: /* 3 */
1547 /* Flow control (both RX and TX) is enabled by a software
1550 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1553 DEBUGOUT("Flow control param set incorrectly\n");
1554 return -E1000_ERR_CONFIG;
1557 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1561 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1563 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1567 return E1000_SUCCESS;
1570 /******************************************************************************
1571 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1573 * hw - Struct containing variables accessed by shared code
1574 ******************************************************************************/
1575 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1584 DEBUGFUNC("e1000_phy_force_speed_duplex");
1586 /* Turn off Flow control if we are forcing speed and duplex. */
1587 hw->fc = E1000_FC_NONE;
1589 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1591 /* Read the Device Control Register. */
1594 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1595 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1596 ctrl &= ~(DEVICE_SPEED_MASK);
1598 /* Clear the Auto Speed Detect Enable bit. */
1599 ctrl &= ~E1000_CTRL_ASDE;
1601 /* Read the MII Control Register. */
1602 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1606 /* We need to disable autoneg in order to force link and duplex. */
1608 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1610 /* Are we forcing Full or Half Duplex? */
1611 if (hw->forced_speed_duplex == e1000_100_full ||
1612 hw->forced_speed_duplex == e1000_10_full) {
1613 /* We want to force full duplex so we SET the full duplex bits in the
1614 * Device and MII Control Registers.
1616 ctrl |= E1000_CTRL_FD;
1617 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1618 DEBUGOUT("Full Duplex\n");
1620 /* We want to force half duplex so we CLEAR the full duplex bits in
1621 * the Device and MII Control Registers.
1623 ctrl &= ~E1000_CTRL_FD;
1624 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1625 DEBUGOUT("Half Duplex\n");
1628 /* Are we forcing 100Mbps??? */
1629 if (hw->forced_speed_duplex == e1000_100_full ||
1630 hw->forced_speed_duplex == e1000_100_half) {
1631 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1632 ctrl |= E1000_CTRL_SPD_100;
1633 mii_ctrl_reg |= MII_CR_SPEED_100;
1634 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1635 DEBUGOUT("Forcing 100mb ");
1637 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1638 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1639 mii_ctrl_reg |= MII_CR_SPEED_10;
1640 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1641 DEBUGOUT("Forcing 10mb ");
1644 e1000_config_collision_dist(hw);
1646 /* Write the configured values back to the Device Control Reg. */
1649 if (hw->phy_type == e1000_phy_m88) {
1650 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1654 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1655 * forced whenever speed are duplex are forced.
1657 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1658 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1662 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1664 /* Need to reset the PHY or these changes will be ignored */
1665 mii_ctrl_reg |= MII_CR_RESET;
1668 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1669 * forced whenever speed or duplex are forced.
1671 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1675 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1676 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1678 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1683 /* Write back the modified PHY MII control register. */
1684 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1690 /* The wait_autoneg_complete flag may be a little misleading here.
1691 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1692 * But we do want to delay for a period while forcing only so we
1693 * don't generate false No Link messages. So we will wait here
1694 * only if the user has set wait_autoneg_complete to 1, which is
1697 if (hw->wait_autoneg_complete) {
1698 /* We will wait for autoneg to complete. */
1699 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1702 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1703 for (i = PHY_FORCE_TIME; i > 0; i--) {
1704 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1707 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1711 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1715 if (mii_status_reg & MII_SR_LINK_STATUS) break;
1719 (hw->phy_type == e1000_phy_m88)) {
1720 /* We didn't get link. Reset the DSP and wait again for link. */
1721 ret_val = e1000_phy_reset_dsp(hw);
1723 DEBUGOUT("Error Resetting PHY DSP\n");
1727 /* This loop will early-out if the link condition has been met. */
1728 for (i = PHY_FORCE_TIME; i > 0; i--) {
1729 if (mii_status_reg & MII_SR_LINK_STATUS) break;
1731 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1734 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1738 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1744 if (hw->phy_type == e1000_phy_m88) {
1745 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1746 * Extended PHY Specific Control Register to 25MHz clock. This value
1747 * defaults back to a 2.5MHz clock when the PHY is reset.
1749 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1753 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1754 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1758 /* In addition, because of the s/w reset above, we need to enable CRS on
1759 * TX. This must be set for both full and half duplex operation.
1761 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1765 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1766 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1770 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1771 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
1772 hw->forced_speed_duplex == e1000_10_half)) {
1773 ret_val = e1000_polarity_reversal_workaround(hw);
1778 return E1000_SUCCESS;
1781 /******************************************************************************
1782 * Sets the collision distance in the Transmit Control register
1784 * hw - Struct containing variables accessed by shared code
1786 * Link should have been established previously. Reads the speed and duplex
1787 * information from the Device Status register.
1788 ******************************************************************************/
1789 void e1000_config_collision_dist(struct e1000_hw *hw)
1791 u32 tctl, coll_dist;
1793 DEBUGFUNC("e1000_config_collision_dist");
1795 if (hw->mac_type < e1000_82543)
1796 coll_dist = E1000_COLLISION_DISTANCE_82542;
1798 coll_dist = E1000_COLLISION_DISTANCE;
1802 tctl &= ~E1000_TCTL_COLD;
1803 tctl |= coll_dist << E1000_COLD_SHIFT;
1806 E1000_WRITE_FLUSH();
1809 /******************************************************************************
1810 * Sets MAC speed and duplex settings to reflect the those in the PHY
1812 * hw - Struct containing variables accessed by shared code
1813 * mii_reg - data to write to the MII control register
1815 * The contents of the PHY register containing the needed information need to
1817 ******************************************************************************/
1818 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
1824 DEBUGFUNC("e1000_config_mac_to_phy");
1826 /* 82544 or newer MAC, Auto Speed Detection takes care of
1827 * MAC speed/duplex configuration.*/
1828 if (hw->mac_type >= e1000_82544)
1829 return E1000_SUCCESS;
1831 /* Read the Device Control Register and set the bits to Force Speed
1835 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1836 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1838 /* Set up duplex in the Device Control and Transmit Control
1839 * registers depending on negotiated values.
1841 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1845 if (phy_data & M88E1000_PSSR_DPLX)
1846 ctrl |= E1000_CTRL_FD;
1848 ctrl &= ~E1000_CTRL_FD;
1850 e1000_config_collision_dist(hw);
1852 /* Set up speed in the Device Control register depending on
1853 * negotiated values.
1855 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1856 ctrl |= E1000_CTRL_SPD_1000;
1857 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1858 ctrl |= E1000_CTRL_SPD_100;
1860 /* Write the configured values back to the Device Control Reg. */
1862 return E1000_SUCCESS;
1865 /******************************************************************************
1866 * Forces the MAC's flow control settings.
1868 * hw - Struct containing variables accessed by shared code
1870 * Sets the TFCE and RFCE bits in the device control register to reflect
1871 * the adapter settings. TFCE and RFCE need to be explicitly set by
1872 * software when a Copper PHY is used because autonegotiation is managed
1873 * by the PHY rather than the MAC. Software must also configure these
1874 * bits when link is forced on a fiber connection.
1875 *****************************************************************************/
1876 s32 e1000_force_mac_fc(struct e1000_hw *hw)
1880 DEBUGFUNC("e1000_force_mac_fc");
1882 /* Get the current configuration of the Device Control Register */
1885 /* Because we didn't get link via the internal auto-negotiation
1886 * mechanism (we either forced link or we got link via PHY
1887 * auto-neg), we have to manually enable/disable transmit an
1888 * receive flow control.
1890 * The "Case" statement below enables/disable flow control
1891 * according to the "hw->fc" parameter.
1893 * The possible values of the "fc" parameter are:
1894 * 0: Flow control is completely disabled
1895 * 1: Rx flow control is enabled (we can receive pause
1896 * frames but not send pause frames).
1897 * 2: Tx flow control is enabled (we can send pause frames
1898 * frames but we do not receive pause frames).
1899 * 3: Both Rx and TX flow control (symmetric) is enabled.
1900 * other: No other values should be possible at this point.
1905 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1907 case E1000_FC_RX_PAUSE:
1908 ctrl &= (~E1000_CTRL_TFCE);
1909 ctrl |= E1000_CTRL_RFCE;
1911 case E1000_FC_TX_PAUSE:
1912 ctrl &= (~E1000_CTRL_RFCE);
1913 ctrl |= E1000_CTRL_TFCE;
1916 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1919 DEBUGOUT("Flow control param set incorrectly\n");
1920 return -E1000_ERR_CONFIG;
1923 /* Disable TX Flow Control for 82542 (rev 2.0) */
1924 if (hw->mac_type == e1000_82542_rev2_0)
1925 ctrl &= (~E1000_CTRL_TFCE);
1928 return E1000_SUCCESS;
1931 /******************************************************************************
1932 * Configures flow control settings after link is established
1934 * hw - Struct containing variables accessed by shared code
1936 * Should be called immediately after a valid link has been established.
1937 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1938 * and autonegotiation is enabled, the MAC flow control settings will be set
1939 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1940 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1941 *****************************************************************************/
1942 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1946 u16 mii_nway_adv_reg;
1947 u16 mii_nway_lp_ability_reg;
1951 DEBUGFUNC("e1000_config_fc_after_link_up");
1953 /* Check for the case where we have fiber media and auto-neg failed
1954 * so we had to force link. In this case, we need to force the
1955 * configuration of the MAC to match the "fc" parameter.
1957 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1958 ((hw->media_type == e1000_media_type_internal_serdes) &&
1959 (hw->autoneg_failed)) ||
1960 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1961 ret_val = e1000_force_mac_fc(hw);
1963 DEBUGOUT("Error forcing flow control settings\n");
1968 /* Check for the case where we have copper media and auto-neg is
1969 * enabled. In this case, we need to check and see if Auto-Neg
1970 * has completed, and if so, how the PHY and link partner has
1971 * flow control configured.
1973 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1974 /* Read the MII Status Register and check to see if AutoNeg
1975 * has completed. We read this twice because this reg has
1976 * some "sticky" (latched) bits.
1978 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1981 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1985 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1986 /* The AutoNeg process has completed, so we now need to
1987 * read both the Auto Negotiation Advertisement Register
1988 * (Address 4) and the Auto_Negotiation Base Page Ability
1989 * Register (Address 5) to determine how flow control was
1992 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1996 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1997 &mii_nway_lp_ability_reg);
2001 /* Two bits in the Auto Negotiation Advertisement Register
2002 * (Address 4) and two bits in the Auto Negotiation Base
2003 * Page Ability Register (Address 5) determine flow control
2004 * for both the PHY and the link partner. The following
2005 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2006 * 1999, describes these PAUSE resolution bits and how flow
2007 * control is determined based upon these settings.
2008 * NOTE: DC = Don't Care
2010 * LOCAL DEVICE | LINK PARTNER
2011 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2012 *-------|---------|-------|---------|--------------------
2013 * 0 | 0 | DC | DC | E1000_FC_NONE
2014 * 0 | 1 | 0 | DC | E1000_FC_NONE
2015 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2016 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2017 * 1 | 0 | 0 | DC | E1000_FC_NONE
2018 * 1 | DC | 1 | DC | E1000_FC_FULL
2019 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2020 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2023 /* Are both PAUSE bits set to 1? If so, this implies
2024 * Symmetric Flow Control is enabled at both ends. The
2025 * ASM_DIR bits are irrelevant per the spec.
2027 * For Symmetric Flow Control:
2029 * LOCAL DEVICE | LINK PARTNER
2030 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2031 *-------|---------|-------|---------|--------------------
2032 * 1 | DC | 1 | DC | E1000_FC_FULL
2035 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2036 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2037 /* Now we need to check if the user selected RX ONLY
2038 * of pause frames. In this case, we had to advertise
2039 * FULL flow control because we could not advertise RX
2040 * ONLY. Hence, we must now check to see if we need to
2041 * turn OFF the TRANSMISSION of PAUSE frames.
2043 if (hw->original_fc == E1000_FC_FULL) {
2044 hw->fc = E1000_FC_FULL;
2045 DEBUGOUT("Flow Control = FULL.\n");
2047 hw->fc = E1000_FC_RX_PAUSE;
2048 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2051 /* For receiving PAUSE frames ONLY.
2053 * LOCAL DEVICE | LINK PARTNER
2054 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2055 *-------|---------|-------|---------|--------------------
2056 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2059 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2060 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2061 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2062 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2063 hw->fc = E1000_FC_TX_PAUSE;
2064 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2066 /* For transmitting PAUSE frames ONLY.
2068 * LOCAL DEVICE | LINK PARTNER
2069 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2070 *-------|---------|-------|---------|--------------------
2071 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2074 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2075 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2076 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2077 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2078 hw->fc = E1000_FC_RX_PAUSE;
2079 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2081 /* Per the IEEE spec, at this point flow control should be
2082 * disabled. However, we want to consider that we could
2083 * be connected to a legacy switch that doesn't advertise
2084 * desired flow control, but can be forced on the link
2085 * partner. So if we advertised no flow control, that is
2086 * what we will resolve to. If we advertised some kind of
2087 * receive capability (Rx Pause Only or Full Flow Control)
2088 * and the link partner advertised none, we will configure
2089 * ourselves to enable Rx Flow Control only. We can do
2090 * this safely for two reasons: If the link partner really
2091 * didn't want flow control enabled, and we enable Rx, no
2092 * harm done since we won't be receiving any PAUSE frames
2093 * anyway. If the intent on the link partner was to have
2094 * flow control enabled, then by us enabling RX only, we
2095 * can at least receive pause frames and process them.
2096 * This is a good idea because in most cases, since we are
2097 * predominantly a server NIC, more times than not we will
2098 * be asked to delay transmission of packets than asking
2099 * our link partner to pause transmission of frames.
2101 else if ((hw->original_fc == E1000_FC_NONE ||
2102 hw->original_fc == E1000_FC_TX_PAUSE) ||
2103 hw->fc_strict_ieee) {
2104 hw->fc = E1000_FC_NONE;
2105 DEBUGOUT("Flow Control = NONE.\n");
2107 hw->fc = E1000_FC_RX_PAUSE;
2108 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2111 /* Now we need to do one last check... If we auto-
2112 * negotiated to HALF DUPLEX, flow control should not be
2113 * enabled per IEEE 802.3 spec.
2115 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2117 DEBUGOUT("Error getting link speed and duplex\n");
2121 if (duplex == HALF_DUPLEX)
2122 hw->fc = E1000_FC_NONE;
2124 /* Now we call a subroutine to actually force the MAC
2125 * controller to use the correct flow control settings.
2127 ret_val = e1000_force_mac_fc(hw);
2129 DEBUGOUT("Error forcing flow control settings\n");
2133 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2136 return E1000_SUCCESS;
2140 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2141 * @hw: pointer to the HW structure
2143 * Checks for link up on the hardware. If link is not up and we have
2144 * a signal, then we need to force link up.
2146 s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2151 s32 ret_val = E1000_SUCCESS;
2153 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2156 status = er32(STATUS);
2160 * If we don't have link (auto-negotiation failed or link partner
2161 * cannot auto-negotiate), and our link partner is not trying to
2162 * auto-negotiate with us (we are receiving idles or data),
2163 * we need to force link up. We also need to give auto-negotiation
2166 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2167 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2168 if (hw->autoneg_failed == 0) {
2169 hw->autoneg_failed = 1;
2172 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2174 /* Disable auto-negotiation in the TXCW register */
2175 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2177 /* Force link-up and also force full-duplex. */
2179 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2182 /* Configure Flow Control after forcing link up. */
2183 ret_val = e1000_config_fc_after_link_up(hw);
2185 DEBUGOUT("Error configuring flow control\n");
2188 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2190 * If we are forcing link and we are receiving /C/ ordered
2191 * sets, re-enable auto-negotiation in the TXCW register
2192 * and disable forced link in the Device Control register
2193 * in an attempt to auto-negotiate with our link partner.
2195 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2196 ew32(TXCW, hw->txcw);
2197 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2199 hw->serdes_has_link = true;
2200 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2202 * If we force link for non-auto-negotiation switch, check
2203 * link status based on MAC synchronization for internal
2204 * serdes media type.
2206 /* SYNCH bit and IV bit are sticky. */
2209 if (rxcw & E1000_RXCW_SYNCH) {
2210 if (!(rxcw & E1000_RXCW_IV)) {
2211 hw->serdes_has_link = true;
2212 DEBUGOUT("SERDES: Link up - forced.\n");
2215 hw->serdes_has_link = false;
2216 DEBUGOUT("SERDES: Link down - force failed.\n");
2220 if (E1000_TXCW_ANE & er32(TXCW)) {
2221 status = er32(STATUS);
2222 if (status & E1000_STATUS_LU) {
2223 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2226 if (rxcw & E1000_RXCW_SYNCH) {
2227 if (!(rxcw & E1000_RXCW_IV)) {
2228 hw->serdes_has_link = true;
2229 DEBUGOUT("SERDES: Link up - autoneg "
2230 "completed sucessfully.\n");
2232 hw->serdes_has_link = false;
2233 DEBUGOUT("SERDES: Link down - invalid"
2234 "codewords detected in autoneg.\n");
2237 hw->serdes_has_link = false;
2238 DEBUGOUT("SERDES: Link down - no sync.\n");
2241 hw->serdes_has_link = false;
2242 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2249 /******************************************************************************
2250 * Checks to see if the link status of the hardware has changed.
2252 * hw - Struct containing variables accessed by shared code
2254 * Called by any function that needs to check the link status of the adapter.
2255 *****************************************************************************/
2256 s32 e1000_check_for_link(struct e1000_hw *hw)
2267 DEBUGFUNC("e1000_check_for_link");
2270 status = er32(STATUS);
2272 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2273 * set when the optics detect a signal. On older adapters, it will be
2274 * cleared when there is a signal. This applies to fiber media only.
2276 if ((hw->media_type == e1000_media_type_fiber) ||
2277 (hw->media_type == e1000_media_type_internal_serdes)) {
2280 if (hw->media_type == e1000_media_type_fiber) {
2281 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2282 if (status & E1000_STATUS_LU)
2283 hw->get_link_status = false;
2287 /* If we have a copper PHY then we only want to go out to the PHY
2288 * registers to see if Auto-Neg has completed and/or if our link
2289 * status has changed. The get_link_status flag will be set if we
2290 * receive a Link Status Change interrupt or we have Rx Sequence
2293 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2294 /* First we want to see if the MII Status Register reports
2295 * link. If so, then we want to get the current speed/duplex
2297 * Read the register twice since the link bit is sticky.
2299 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2302 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2306 if (phy_data & MII_SR_LINK_STATUS) {
2307 hw->get_link_status = false;
2308 /* Check if there was DownShift, must be checked immediately after
2310 e1000_check_downshift(hw);
2312 /* If we are on 82544 or 82543 silicon and speed/duplex
2313 * are forced to 10H or 10F, then we will implement the polarity
2314 * reversal workaround. We disable interrupts first, and upon
2315 * returning, place the devices interrupt state to its previous
2316 * value except for the link status change interrupt which will
2317 * happen due to the execution of this workaround.
2320 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2322 (hw->forced_speed_duplex == e1000_10_full ||
2323 hw->forced_speed_duplex == e1000_10_half)) {
2324 ew32(IMC, 0xffffffff);
2325 ret_val = e1000_polarity_reversal_workaround(hw);
2327 ew32(ICS, (icr & ~E1000_ICS_LSC));
2328 ew32(IMS, IMS_ENABLE_MASK);
2332 /* No link detected */
2333 e1000_config_dsp_after_link_change(hw, false);
2337 /* If we are forcing speed/duplex, then we simply return since
2338 * we have already determined whether we have link or not.
2340 if (!hw->autoneg) return -E1000_ERR_CONFIG;
2342 /* optimize the dsp settings for the igp phy */
2343 e1000_config_dsp_after_link_change(hw, true);
2345 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2346 * have Si on board that is 82544 or newer, Auto
2347 * Speed Detection takes care of MAC speed/duplex
2348 * configuration. So we only need to configure Collision
2349 * Distance in the MAC. Otherwise, we need to force
2350 * speed/duplex on the MAC to the current PHY speed/duplex
2353 if (hw->mac_type >= e1000_82544)
2354 e1000_config_collision_dist(hw);
2356 ret_val = e1000_config_mac_to_phy(hw);
2358 DEBUGOUT("Error configuring MAC to PHY settings\n");
2363 /* Configure Flow Control now that Auto-Neg has completed. First, we
2364 * need to restore the desired flow control settings because we may
2365 * have had to re-autoneg with a different link partner.
2367 ret_val = e1000_config_fc_after_link_up(hw);
2369 DEBUGOUT("Error configuring flow control\n");
2373 /* At this point we know that we are on copper and we have
2374 * auto-negotiated link. These are conditions for checking the link
2375 * partner capability register. We use the link speed to determine if
2376 * TBI compatibility needs to be turned on or off. If the link is not
2377 * at gigabit speed, then TBI compatibility is not needed. If we are
2378 * at gigabit speed, we turn on TBI compatibility.
2380 if (hw->tbi_compatibility_en) {
2382 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2384 DEBUGOUT("Error getting link speed and duplex\n");
2387 if (speed != SPEED_1000) {
2388 /* If link speed is not set to gigabit speed, we do not need
2389 * to enable TBI compatibility.
2391 if (hw->tbi_compatibility_on) {
2392 /* If we previously were in the mode, turn it off. */
2394 rctl &= ~E1000_RCTL_SBP;
2396 hw->tbi_compatibility_on = false;
2399 /* If TBI compatibility is was previously off, turn it on. For
2400 * compatibility with a TBI link partner, we will store bad
2401 * packets. Some frames have an additional byte on the end and
2402 * will look like CRC errors to the hardware.
2404 if (!hw->tbi_compatibility_on) {
2405 hw->tbi_compatibility_on = true;
2407 rctl |= E1000_RCTL_SBP;
2414 if ((hw->media_type == e1000_media_type_fiber) ||
2415 (hw->media_type == e1000_media_type_internal_serdes))
2416 e1000_check_for_serdes_link_generic(hw);
2418 return E1000_SUCCESS;
2421 /******************************************************************************
2422 * Detects the current speed and duplex settings of the hardware.
2424 * hw - Struct containing variables accessed by shared code
2425 * speed - Speed of the connection
2426 * duplex - Duplex setting of the connection
2427 *****************************************************************************/
2428 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
2434 DEBUGFUNC("e1000_get_speed_and_duplex");
2436 if (hw->mac_type >= e1000_82543) {
2437 status = er32(STATUS);
2438 if (status & E1000_STATUS_SPEED_1000) {
2439 *speed = SPEED_1000;
2440 DEBUGOUT("1000 Mbs, ");
2441 } else if (status & E1000_STATUS_SPEED_100) {
2443 DEBUGOUT("100 Mbs, ");
2446 DEBUGOUT("10 Mbs, ");
2449 if (status & E1000_STATUS_FD) {
2450 *duplex = FULL_DUPLEX;
2451 DEBUGOUT("Full Duplex\n");
2453 *duplex = HALF_DUPLEX;
2454 DEBUGOUT(" Half Duplex\n");
2457 DEBUGOUT("1000 Mbs, Full Duplex\n");
2458 *speed = SPEED_1000;
2459 *duplex = FULL_DUPLEX;
2462 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2463 * if it is operating at half duplex. Here we set the duplex settings to
2464 * match the duplex in the link partner's capabilities.
2466 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2467 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2471 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2472 *duplex = HALF_DUPLEX;
2474 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2477 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2478 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2479 *duplex = HALF_DUPLEX;
2483 return E1000_SUCCESS;
2486 /******************************************************************************
2487 * Blocks until autoneg completes or times out (~4.5 seconds)
2489 * hw - Struct containing variables accessed by shared code
2490 ******************************************************************************/
2491 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
2497 DEBUGFUNC("e1000_wait_autoneg");
2498 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2500 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2501 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2502 /* Read the MII Status Register and wait for Auto-Neg
2503 * Complete bit to be set.
2505 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2508 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2511 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2512 return E1000_SUCCESS;
2516 return E1000_SUCCESS;
2519 /******************************************************************************
2520 * Raises the Management Data Clock
2522 * hw - Struct containing variables accessed by shared code
2523 * ctrl - Device control register's current value
2524 ******************************************************************************/
2525 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2527 /* Raise the clock input to the Management Data Clock (by setting the MDC
2528 * bit), and then delay 10 microseconds.
2530 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2531 E1000_WRITE_FLUSH();
2535 /******************************************************************************
2536 * Lowers the Management Data Clock
2538 * hw - Struct containing variables accessed by shared code
2539 * ctrl - Device control register's current value
2540 ******************************************************************************/
2541 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2543 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2544 * bit), and then delay 10 microseconds.
2546 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2547 E1000_WRITE_FLUSH();
2551 /******************************************************************************
2552 * Shifts data bits out to the PHY
2554 * hw - Struct containing variables accessed by shared code
2555 * data - Data to send out to the PHY
2556 * count - Number of bits to shift out
2558 * Bits are shifted out in MSB to LSB order.
2559 ******************************************************************************/
2560 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
2565 /* We need to shift "count" number of bits out to the PHY. So, the value
2566 * in the "data" parameter will be shifted out to the PHY one bit at a
2567 * time. In order to do this, "data" must be broken down into bits.
2570 mask <<= (count - 1);
2574 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2575 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2578 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2579 * then raising and lowering the Management Data Clock. A "0" is
2580 * shifted out to the PHY by setting the MDIO bit to "0" and then
2581 * raising and lowering the clock.
2584 ctrl |= E1000_CTRL_MDIO;
2586 ctrl &= ~E1000_CTRL_MDIO;
2589 E1000_WRITE_FLUSH();
2593 e1000_raise_mdi_clk(hw, &ctrl);
2594 e1000_lower_mdi_clk(hw, &ctrl);
2600 /******************************************************************************
2601 * Shifts data bits in from the PHY
2603 * hw - Struct containing variables accessed by shared code
2605 * Bits are shifted in in MSB to LSB order.
2606 ******************************************************************************/
2607 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2613 /* In order to read a register from the PHY, we need to shift in a total
2614 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2615 * to avoid contention on the MDIO pin when a read operation is performed.
2616 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2617 * by raising the input to the Management Data Clock (setting the MDC bit),
2618 * and then reading the value of the MDIO bit.
2622 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2623 ctrl &= ~E1000_CTRL_MDIO_DIR;
2624 ctrl &= ~E1000_CTRL_MDIO;
2627 E1000_WRITE_FLUSH();
2629 /* Raise and Lower the clock before reading in the data. This accounts for
2630 * the turnaround bits. The first clock occurred when we clocked out the
2631 * last bit of the Register Address.
2633 e1000_raise_mdi_clk(hw, &ctrl);
2634 e1000_lower_mdi_clk(hw, &ctrl);
2636 for (data = 0, i = 0; i < 16; i++) {
2638 e1000_raise_mdi_clk(hw, &ctrl);
2640 /* Check to see if we shifted in a "1". */
2641 if (ctrl & E1000_CTRL_MDIO)
2643 e1000_lower_mdi_clk(hw, &ctrl);
2646 e1000_raise_mdi_clk(hw, &ctrl);
2647 e1000_lower_mdi_clk(hw, &ctrl);
2652 /*****************************************************************************
2653 * Reads the value from a PHY register, if the value is on a specific non zero
2654 * page, sets the page first.
2655 * hw - Struct containing variables accessed by shared code
2656 * reg_addr - address of the PHY register to read
2657 ******************************************************************************/
2658 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
2662 DEBUGFUNC("e1000_read_phy_reg");
2664 if ((hw->phy_type == e1000_phy_igp) &&
2665 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2666 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2672 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2677 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2682 const u32 phy_addr = 1;
2684 DEBUGFUNC("e1000_read_phy_reg_ex");
2686 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2687 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2688 return -E1000_ERR_PARAM;
2691 if (hw->mac_type > e1000_82543) {
2692 /* Set up Op-code, Phy Address, and register address in the MDI
2693 * Control register. The MAC will take care of interfacing with the
2694 * PHY to retrieve the desired data.
2696 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2697 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2698 (E1000_MDIC_OP_READ));
2702 /* Poll the ready bit to see if the MDI read completed */
2703 for (i = 0; i < 64; i++) {
2706 if (mdic & E1000_MDIC_READY) break;
2708 if (!(mdic & E1000_MDIC_READY)) {
2709 DEBUGOUT("MDI Read did not complete\n");
2710 return -E1000_ERR_PHY;
2712 if (mdic & E1000_MDIC_ERROR) {
2713 DEBUGOUT("MDI Error\n");
2714 return -E1000_ERR_PHY;
2716 *phy_data = (u16)mdic;
2718 /* We must first send a preamble through the MDIO pin to signal the
2719 * beginning of an MII instruction. This is done by sending 32
2720 * consecutive "1" bits.
2722 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2724 /* Now combine the next few fields that are required for a read
2725 * operation. We use this method instead of calling the
2726 * e1000_shift_out_mdi_bits routine five different times. The format of
2727 * a MII read instruction consists of a shift out of 14 bits and is
2728 * defined as follows:
2729 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2730 * followed by a shift in of 18 bits. This first two bits shifted in
2731 * are TurnAround bits used to avoid contention on the MDIO pin when a
2732 * READ operation is performed. These two bits are thrown away
2733 * followed by a shift in of 16 bits which contains the desired data.
2735 mdic = ((reg_addr) | (phy_addr << 5) |
2736 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2738 e1000_shift_out_mdi_bits(hw, mdic, 14);
2740 /* Now that we've shifted out the read command to the MII, we need to
2741 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2744 *phy_data = e1000_shift_in_mdi_bits(hw);
2746 return E1000_SUCCESS;
2749 /******************************************************************************
2750 * Writes a value to a PHY register
2752 * hw - Struct containing variables accessed by shared code
2753 * reg_addr - address of the PHY register to write
2754 * data - data to write to the PHY
2755 ******************************************************************************/
2756 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
2760 DEBUGFUNC("e1000_write_phy_reg");
2762 if ((hw->phy_type == e1000_phy_igp) &&
2763 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2764 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2770 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2776 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2781 const u32 phy_addr = 1;
2783 DEBUGFUNC("e1000_write_phy_reg_ex");
2785 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2786 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2787 return -E1000_ERR_PARAM;
2790 if (hw->mac_type > e1000_82543) {
2791 /* Set up Op-code, Phy Address, register address, and data intended
2792 * for the PHY register in the MDI Control register. The MAC will take
2793 * care of interfacing with the PHY to send the desired data.
2795 mdic = (((u32)phy_data) |
2796 (reg_addr << E1000_MDIC_REG_SHIFT) |
2797 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2798 (E1000_MDIC_OP_WRITE));
2802 /* Poll the ready bit to see if the MDI read completed */
2803 for (i = 0; i < 641; i++) {
2806 if (mdic & E1000_MDIC_READY) break;
2808 if (!(mdic & E1000_MDIC_READY)) {
2809 DEBUGOUT("MDI Write did not complete\n");
2810 return -E1000_ERR_PHY;
2813 /* We'll need to use the SW defined pins to shift the write command
2814 * out to the PHY. We first send a preamble to the PHY to signal the
2815 * beginning of the MII instruction. This is done by sending 32
2816 * consecutive "1" bits.
2818 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2820 /* Now combine the remaining required fields that will indicate a
2821 * write operation. We use this method instead of calling the
2822 * e1000_shift_out_mdi_bits routine for each field in the command. The
2823 * format of a MII write instruction is as follows:
2824 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2826 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2827 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2829 mdic |= (u32)phy_data;
2831 e1000_shift_out_mdi_bits(hw, mdic, 32);
2834 return E1000_SUCCESS;
2837 /******************************************************************************
2838 * Returns the PHY to the power-on reset state
2840 * hw - Struct containing variables accessed by shared code
2841 ******************************************************************************/
2842 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
2848 DEBUGFUNC("e1000_phy_hw_reset");
2850 DEBUGOUT("Resetting Phy...\n");
2852 if (hw->mac_type > e1000_82543) {
2853 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2854 * bit. Then, take it out of reset.
2855 * For e1000 hardware, we delay for 10ms between the assert
2859 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2860 E1000_WRITE_FLUSH();
2865 E1000_WRITE_FLUSH();
2867 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2868 * bit to put the PHY into reset. Then, take it out of reset.
2870 ctrl_ext = er32(CTRL_EXT);
2871 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2872 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2873 ew32(CTRL_EXT, ctrl_ext);
2874 E1000_WRITE_FLUSH();
2876 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2877 ew32(CTRL_EXT, ctrl_ext);
2878 E1000_WRITE_FLUSH();
2882 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2883 /* Configure activity LED after PHY reset */
2884 led_ctrl = er32(LEDCTL);
2885 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2886 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2887 ew32(LEDCTL, led_ctrl);
2890 /* Wait for FW to finish PHY configuration. */
2891 ret_val = e1000_get_phy_cfg_done(hw);
2892 if (ret_val != E1000_SUCCESS)
2898 /******************************************************************************
2901 * hw - Struct containing variables accessed by shared code
2903 * Sets bit 15 of the MII Control register
2904 ******************************************************************************/
2905 s32 e1000_phy_reset(struct e1000_hw *hw)
2910 DEBUGFUNC("e1000_phy_reset");
2912 switch (hw->phy_type) {
2914 ret_val = e1000_phy_hw_reset(hw);
2919 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2923 phy_data |= MII_CR_RESET;
2924 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2932 if (hw->phy_type == e1000_phy_igp)
2933 e1000_phy_init_script(hw);
2935 return E1000_SUCCESS;
2938 /******************************************************************************
2939 * Probes the expected PHY address for known PHY IDs
2941 * hw - Struct containing variables accessed by shared code
2942 ******************************************************************************/
2943 static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
2945 s32 phy_init_status, ret_val;
2946 u16 phy_id_high, phy_id_low;
2949 DEBUGFUNC("e1000_detect_gig_phy");
2951 if (hw->phy_id != 0)
2952 return E1000_SUCCESS;
2954 /* Read the PHY ID Registers to identify which PHY is onboard. */
2955 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2959 hw->phy_id = (u32)(phy_id_high << 16);
2961 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2965 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
2966 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
2968 switch (hw->mac_type) {
2970 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
2973 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
2977 case e1000_82545_rev_3:
2979 case e1000_82546_rev_3:
2980 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
2983 case e1000_82541_rev_2:
2985 case e1000_82547_rev_2:
2986 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
2989 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2990 return -E1000_ERR_CONFIG;
2992 phy_init_status = e1000_set_phy_type(hw);
2994 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2995 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2996 return E1000_SUCCESS;
2998 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2999 return -E1000_ERR_PHY;
3002 /******************************************************************************
3003 * Resets the PHY's DSP
3005 * hw - Struct containing variables accessed by shared code
3006 ******************************************************************************/
3007 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
3010 DEBUGFUNC("e1000_phy_reset_dsp");
3013 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3015 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3017 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3019 ret_val = E1000_SUCCESS;
3025 /******************************************************************************
3026 * Get PHY information from various PHY registers for igp PHY only.
3028 * hw - Struct containing variables accessed by shared code
3029 * phy_info - PHY information structure
3030 ******************************************************************************/
3031 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3032 struct e1000_phy_info *phy_info)
3035 u16 phy_data, min_length, max_length, average;
3036 e1000_rev_polarity polarity;
3038 DEBUGFUNC("e1000_phy_igp_get_info");
3040 /* The downshift status is checked only once, after link is established,
3041 * and it stored in the hw->speed_downgraded parameter. */
3042 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3044 /* IGP01E1000 does not need to support it. */
3045 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3047 /* IGP01E1000 always correct polarity reversal */
3048 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3050 /* Check polarity status */
3051 ret_val = e1000_check_polarity(hw, &polarity);
3055 phy_info->cable_polarity = polarity;
3057 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3061 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
3062 IGP01E1000_PSSR_MDIX_SHIFT);
3064 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3065 IGP01E1000_PSSR_SPEED_1000MBPS) {
3066 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3067 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3071 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3072 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3073 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3074 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3075 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3076 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3078 /* Get cable length */
3079 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3083 /* Translate to old method */
3084 average = (max_length + min_length) / 2;
3086 if (average <= e1000_igp_cable_length_50)
3087 phy_info->cable_length = e1000_cable_length_50;
3088 else if (average <= e1000_igp_cable_length_80)
3089 phy_info->cable_length = e1000_cable_length_50_80;
3090 else if (average <= e1000_igp_cable_length_110)
3091 phy_info->cable_length = e1000_cable_length_80_110;
3092 else if (average <= e1000_igp_cable_length_140)
3093 phy_info->cable_length = e1000_cable_length_110_140;
3095 phy_info->cable_length = e1000_cable_length_140;
3098 return E1000_SUCCESS;
3102 /******************************************************************************
3103 * Get PHY information from various PHY registers fot m88 PHY only.
3105 * hw - Struct containing variables accessed by shared code
3106 * phy_info - PHY information structure
3107 ******************************************************************************/
3108 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3109 struct e1000_phy_info *phy_info)
3113 e1000_rev_polarity polarity;
3115 DEBUGFUNC("e1000_phy_m88_get_info");
3117 /* The downshift status is checked only once, after link is established,
3118 * and it stored in the hw->speed_downgraded parameter. */
3119 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3121 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3125 phy_info->extended_10bt_distance =
3126 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3127 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3128 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
3130 phy_info->polarity_correction =
3131 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3132 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3133 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
3135 /* Check polarity status */
3136 ret_val = e1000_check_polarity(hw, &polarity);
3139 phy_info->cable_polarity = polarity;
3141 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3145 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
3146 M88E1000_PSSR_MDIX_SHIFT);
3148 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3149 /* Cable Length Estimation and Local/Remote Receiver Information
3150 * are only valid at 1000 Mbps.
3152 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3153 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3155 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3159 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3160 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3161 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3162 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3163 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3164 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3168 return E1000_SUCCESS;
3171 /******************************************************************************
3172 * Get PHY information from various PHY registers
3174 * hw - Struct containing variables accessed by shared code
3175 * phy_info - PHY information structure
3176 ******************************************************************************/
3177 s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
3182 DEBUGFUNC("e1000_phy_get_info");
3184 phy_info->cable_length = e1000_cable_length_undefined;
3185 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3186 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3187 phy_info->downshift = e1000_downshift_undefined;
3188 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3189 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3190 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3191 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3193 if (hw->media_type != e1000_media_type_copper) {
3194 DEBUGOUT("PHY info is only valid for copper media\n");
3195 return -E1000_ERR_CONFIG;
3198 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3202 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3206 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3207 DEBUGOUT("PHY info is only valid if link is up\n");
3208 return -E1000_ERR_CONFIG;
3211 if (hw->phy_type == e1000_phy_igp)
3212 return e1000_phy_igp_get_info(hw, phy_info);
3214 return e1000_phy_m88_get_info(hw, phy_info);
3217 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
3219 DEBUGFUNC("e1000_validate_mdi_settings");
3221 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3222 DEBUGOUT("Invalid MDI setting detected\n");
3224 return -E1000_ERR_CONFIG;
3226 return E1000_SUCCESS;
3230 /******************************************************************************
3231 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3234 * hw - Struct containing variables accessed by shared code
3235 *****************************************************************************/
3236 s32 e1000_init_eeprom_params(struct e1000_hw *hw)
3238 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3239 u32 eecd = er32(EECD);
3240 s32 ret_val = E1000_SUCCESS;
3243 DEBUGFUNC("e1000_init_eeprom_params");
3245 switch (hw->mac_type) {
3246 case e1000_82542_rev2_0:
3247 case e1000_82542_rev2_1:
3250 eeprom->type = e1000_eeprom_microwire;
3251 eeprom->word_size = 64;
3252 eeprom->opcode_bits = 3;
3253 eeprom->address_bits = 6;
3254 eeprom->delay_usec = 50;
3255 eeprom->use_eerd = false;
3256 eeprom->use_eewr = false;
3260 case e1000_82545_rev_3:
3262 case e1000_82546_rev_3:
3263 eeprom->type = e1000_eeprom_microwire;
3264 eeprom->opcode_bits = 3;
3265 eeprom->delay_usec = 50;
3266 if (eecd & E1000_EECD_SIZE) {
3267 eeprom->word_size = 256;
3268 eeprom->address_bits = 8;
3270 eeprom->word_size = 64;
3271 eeprom->address_bits = 6;
3273 eeprom->use_eerd = false;
3274 eeprom->use_eewr = false;
3277 case e1000_82541_rev_2:
3279 case e1000_82547_rev_2:
3280 if (eecd & E1000_EECD_TYPE) {
3281 eeprom->type = e1000_eeprom_spi;
3282 eeprom->opcode_bits = 8;
3283 eeprom->delay_usec = 1;
3284 if (eecd & E1000_EECD_ADDR_BITS) {
3285 eeprom->page_size = 32;
3286 eeprom->address_bits = 16;
3288 eeprom->page_size = 8;
3289 eeprom->address_bits = 8;
3292 eeprom->type = e1000_eeprom_microwire;
3293 eeprom->opcode_bits = 3;
3294 eeprom->delay_usec = 50;
3295 if (eecd & E1000_EECD_ADDR_BITS) {
3296 eeprom->word_size = 256;
3297 eeprom->address_bits = 8;
3299 eeprom->word_size = 64;
3300 eeprom->address_bits = 6;
3303 eeprom->use_eerd = false;
3304 eeprom->use_eewr = false;
3310 if (eeprom->type == e1000_eeprom_spi) {
3311 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3312 * 32KB (incremented by powers of 2).
3314 /* Set to default value for initial eeprom read. */
3315 eeprom->word_size = 64;
3316 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3319 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3320 /* 256B eeprom size was not supported in earlier hardware, so we
3321 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3322 * is never the result used in the shifting logic below. */
3326 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3331 /******************************************************************************
3332 * Raises the EEPROM's clock input.
3334 * hw - Struct containing variables accessed by shared code
3335 * eecd - EECD's current value
3336 *****************************************************************************/
3337 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
3339 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3340 * wait <delay> microseconds.
3342 *eecd = *eecd | E1000_EECD_SK;
3344 E1000_WRITE_FLUSH();
3345 udelay(hw->eeprom.delay_usec);
3348 /******************************************************************************
3349 * Lowers the EEPROM's clock input.
3351 * hw - Struct containing variables accessed by shared code
3352 * eecd - EECD's current value
3353 *****************************************************************************/
3354 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
3356 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3357 * wait 50 microseconds.
3359 *eecd = *eecd & ~E1000_EECD_SK;
3361 E1000_WRITE_FLUSH();
3362 udelay(hw->eeprom.delay_usec);
3365 /******************************************************************************
3366 * Shift data bits out to the EEPROM.
3368 * hw - Struct containing variables accessed by shared code
3369 * data - data to send to the EEPROM
3370 * count - number of bits to shift out
3371 *****************************************************************************/
3372 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
3374 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3378 /* We need to shift "count" bits out to the EEPROM. So, value in the
3379 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3380 * In order to do this, "data" must be broken down into bits.
3382 mask = 0x01 << (count - 1);
3384 if (eeprom->type == e1000_eeprom_microwire) {
3385 eecd &= ~E1000_EECD_DO;
3386 } else if (eeprom->type == e1000_eeprom_spi) {
3387 eecd |= E1000_EECD_DO;
3390 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3391 * and then raising and then lowering the clock (the SK bit controls
3392 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3393 * by setting "DI" to "0" and then raising and then lowering the clock.
3395 eecd &= ~E1000_EECD_DI;
3398 eecd |= E1000_EECD_DI;
3401 E1000_WRITE_FLUSH();
3403 udelay(eeprom->delay_usec);
3405 e1000_raise_ee_clk(hw, &eecd);
3406 e1000_lower_ee_clk(hw, &eecd);
3412 /* We leave the "DI" bit set to "0" when we leave this routine. */
3413 eecd &= ~E1000_EECD_DI;
3417 /******************************************************************************
3418 * Shift data bits in from the EEPROM
3420 * hw - Struct containing variables accessed by shared code
3421 *****************************************************************************/
3422 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
3428 /* In order to read a register from the EEPROM, we need to shift 'count'
3429 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3430 * input to the EEPROM (setting the SK bit), and then reading the value of
3431 * the "DO" bit. During this "shifting in" process the "DI" bit should
3437 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3440 for (i = 0; i < count; i++) {
3442 e1000_raise_ee_clk(hw, &eecd);
3446 eecd &= ~(E1000_EECD_DI);
3447 if (eecd & E1000_EECD_DO)
3450 e1000_lower_ee_clk(hw, &eecd);
3456 /******************************************************************************
3457 * Prepares EEPROM for access
3459 * hw - Struct containing variables accessed by shared code
3461 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3462 * function should be called before issuing a command to the EEPROM.
3463 *****************************************************************************/
3464 static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
3466 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3469 DEBUGFUNC("e1000_acquire_eeprom");
3473 /* Request EEPROM Access */
3474 if (hw->mac_type > e1000_82544) {
3475 eecd |= E1000_EECD_REQ;
3478 while ((!(eecd & E1000_EECD_GNT)) &&
3479 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3484 if (!(eecd & E1000_EECD_GNT)) {
3485 eecd &= ~E1000_EECD_REQ;
3487 DEBUGOUT("Could not acquire EEPROM grant\n");
3488 return -E1000_ERR_EEPROM;
3492 /* Setup EEPROM for Read/Write */
3494 if (eeprom->type == e1000_eeprom_microwire) {
3495 /* Clear SK and DI */
3496 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3500 eecd |= E1000_EECD_CS;
3502 } else if (eeprom->type == e1000_eeprom_spi) {
3503 /* Clear SK and CS */
3504 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3509 return E1000_SUCCESS;
3512 /******************************************************************************
3513 * Returns EEPROM to a "standby" state
3515 * hw - Struct containing variables accessed by shared code
3516 *****************************************************************************/
3517 static void e1000_standby_eeprom(struct e1000_hw *hw)
3519 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3524 if (eeprom->type == e1000_eeprom_microwire) {
3525 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3527 E1000_WRITE_FLUSH();
3528 udelay(eeprom->delay_usec);
3531 eecd |= E1000_EECD_SK;
3533 E1000_WRITE_FLUSH();
3534 udelay(eeprom->delay_usec);
3537 eecd |= E1000_EECD_CS;
3539 E1000_WRITE_FLUSH();
3540 udelay(eeprom->delay_usec);
3543 eecd &= ~E1000_EECD_SK;
3545 E1000_WRITE_FLUSH();
3546 udelay(eeprom->delay_usec);
3547 } else if (eeprom->type == e1000_eeprom_spi) {
3548 /* Toggle CS to flush commands */
3549 eecd |= E1000_EECD_CS;
3551 E1000_WRITE_FLUSH();
3552 udelay(eeprom->delay_usec);
3553 eecd &= ~E1000_EECD_CS;
3555 E1000_WRITE_FLUSH();
3556 udelay(eeprom->delay_usec);
3560 /******************************************************************************
3561 * Terminates a command by inverting the EEPROM's chip select pin
3563 * hw - Struct containing variables accessed by shared code
3564 *****************************************************************************/
3565 static void e1000_release_eeprom(struct e1000_hw *hw)
3569 DEBUGFUNC("e1000_release_eeprom");
3573 if (hw->eeprom.type == e1000_eeprom_spi) {
3574 eecd |= E1000_EECD_CS; /* Pull CS high */
3575 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3579 udelay(hw->eeprom.delay_usec);
3580 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3581 /* cleanup eeprom */
3583 /* CS on Microwire is active-high */
3584 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3588 /* Rising edge of clock */
3589 eecd |= E1000_EECD_SK;
3591 E1000_WRITE_FLUSH();
3592 udelay(hw->eeprom.delay_usec);
3594 /* Falling edge of clock */
3595 eecd &= ~E1000_EECD_SK;
3597 E1000_WRITE_FLUSH();
3598 udelay(hw->eeprom.delay_usec);
3601 /* Stop requesting EEPROM access */
3602 if (hw->mac_type > e1000_82544) {
3603 eecd &= ~E1000_EECD_REQ;
3608 /******************************************************************************
3609 * Reads a 16 bit word from the EEPROM.
3611 * hw - Struct containing variables accessed by shared code
3612 *****************************************************************************/
3613 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3615 u16 retry_count = 0;
3618 DEBUGFUNC("e1000_spi_eeprom_ready");
3620 /* Read "Status Register" repeatedly until the LSB is cleared. The
3621 * EEPROM will signal that the command has been completed by clearing
3622 * bit 0 of the internal status register. If it's not cleared within
3623 * 5 milliseconds, then error out.
3627 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3628 hw->eeprom.opcode_bits);
3629 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
3630 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3636 e1000_standby_eeprom(hw);
3637 } while (retry_count < EEPROM_MAX_RETRY_SPI);
3639 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3640 * only 0-5mSec on 5V devices)
3642 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3643 DEBUGOUT("SPI EEPROM Status error\n");
3644 return -E1000_ERR_EEPROM;
3647 return E1000_SUCCESS;
3650 /******************************************************************************
3651 * Reads a 16 bit word from the EEPROM.
3653 * hw - Struct containing variables accessed by shared code
3654 * offset - offset of word in the EEPROM to read
3655 * data - word read from the EEPROM
3656 * words - number of words to read
3657 *****************************************************************************/
3658 s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3661 spin_lock(&e1000_eeprom_lock);
3662 ret = e1000_do_read_eeprom(hw, offset, words, data);
3663 spin_unlock(&e1000_eeprom_lock);
3667 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3669 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3672 DEBUGFUNC("e1000_read_eeprom");
3674 /* If eeprom is not yet detected, do so now */
3675 if (eeprom->word_size == 0)
3676 e1000_init_eeprom_params(hw);
3678 /* A check for invalid values: offset too large, too many words, and not
3681 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3683 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
3684 return -E1000_ERR_EEPROM;
3687 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3688 * directly. In this case, we need to acquire the EEPROM so that
3689 * FW or other port software does not interrupt.
3691 if (!hw->eeprom.use_eerd) {
3692 /* Prepare the EEPROM for bit-bang reading */
3693 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3694 return -E1000_ERR_EEPROM;
3697 /* Eerd register EEPROM access requires no eeprom aquire/release */
3698 if (eeprom->use_eerd)
3699 return e1000_read_eeprom_eerd(hw, offset, words, data);
3701 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3702 * acquired the EEPROM at this point, so any returns should relase it */
3703 if (eeprom->type == e1000_eeprom_spi) {
3705 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
3707 if (e1000_spi_eeprom_ready(hw)) {
3708 e1000_release_eeprom(hw);
3709 return -E1000_ERR_EEPROM;
3712 e1000_standby_eeprom(hw);
3714 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3715 if ((eeprom->address_bits == 8) && (offset >= 128))
3716 read_opcode |= EEPROM_A8_OPCODE_SPI;
3718 /* Send the READ command (opcode + addr) */
3719 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3720 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
3722 /* Read the data. The address of the eeprom internally increments with
3723 * each byte (spi) being read, saving on the overhead of eeprom setup
3724 * and tear-down. The address counter will roll over if reading beyond
3725 * the size of the eeprom, thus allowing the entire memory to be read
3726 * starting from any offset. */
3727 for (i = 0; i < words; i++) {
3728 word_in = e1000_shift_in_ee_bits(hw, 16);
3729 data[i] = (word_in >> 8) | (word_in << 8);
3731 } else if (eeprom->type == e1000_eeprom_microwire) {
3732 for (i = 0; i < words; i++) {
3733 /* Send the READ command (opcode + addr) */
3734 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3735 eeprom->opcode_bits);
3736 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
3737 eeprom->address_bits);
3739 /* Read the data. For microwire, each word requires the overhead
3740 * of eeprom setup and tear-down. */
3741 data[i] = e1000_shift_in_ee_bits(hw, 16);
3742 e1000_standby_eeprom(hw);
3746 /* End this read operation */
3747 e1000_release_eeprom(hw);
3749 return E1000_SUCCESS;
3752 /******************************************************************************
3753 * Reads a 16 bit word from the EEPROM using the EERD register.
3755 * hw - Struct containing variables accessed by shared code
3756 * offset - offset of word in the EEPROM to read
3757 * data - word read from the EEPROM
3758 * words - number of words to read
3759 *****************************************************************************/
3760 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3766 for (i = 0; i < words; i++) {
3767 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3768 E1000_EEPROM_RW_REG_START;
3771 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3776 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
3783 /******************************************************************************
3784 * Writes a 16 bit word from the EEPROM using the EEWR register.
3786 * hw - Struct containing variables accessed by shared code
3787 * offset - offset of word in the EEPROM to read
3788 * data - word read from the EEPROM
3789 * words - number of words to read
3790 *****************************************************************************/
3791 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3794 u32 register_value = 0;
3799 for (i = 0; i < words; i++) {
3800 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3801 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3802 E1000_EEPROM_RW_REG_START;
3804 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3809 ew32(EEWR, register_value);
3811 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3821 /******************************************************************************
3822 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3824 * hw - Struct containing variables accessed by shared code
3825 *****************************************************************************/
3826 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
3828 u32 attempts = 100000;
3830 s32 done = E1000_ERR_EEPROM;
3832 for (i = 0; i < attempts; i++) {
3833 if (eerd == E1000_EEPROM_POLL_READ)
3838 if (reg & E1000_EEPROM_RW_REG_DONE) {
3839 done = E1000_SUCCESS;
3848 /******************************************************************************
3849 * Verifies that the EEPROM has a valid checksum
3851 * hw - Struct containing variables accessed by shared code
3853 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3854 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3856 *****************************************************************************/
3857 s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3862 DEBUGFUNC("e1000_validate_eeprom_checksum");
3864 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3865 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3866 DEBUGOUT("EEPROM Read Error\n");
3867 return -E1000_ERR_EEPROM;
3869 checksum += eeprom_data;
3872 if (checksum == (u16)EEPROM_SUM)
3873 return E1000_SUCCESS;
3875 DEBUGOUT("EEPROM Checksum Invalid\n");
3876 return -E1000_ERR_EEPROM;
3880 /******************************************************************************
3881 * Calculates the EEPROM checksum and writes it to the EEPROM
3883 * hw - Struct containing variables accessed by shared code
3885 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3886 * Writes the difference to word offset 63 of the EEPROM.
3887 *****************************************************************************/
3888 s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3893 DEBUGFUNC("e1000_update_eeprom_checksum");
3895 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3896 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3897 DEBUGOUT("EEPROM Read Error\n");
3898 return -E1000_ERR_EEPROM;
3900 checksum += eeprom_data;
3902 checksum = (u16)EEPROM_SUM - checksum;
3903 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3904 DEBUGOUT("EEPROM Write Error\n");
3905 return -E1000_ERR_EEPROM;
3907 return E1000_SUCCESS;
3910 /******************************************************************************
3911 * Parent function for writing words to the different EEPROM types.
3913 * hw - Struct containing variables accessed by shared code
3914 * offset - offset within the EEPROM to be written to
3915 * words - number of words to write
3916 * data - 16 bit word to be written to the EEPROM
3918 * If e1000_update_eeprom_checksum is not called after this function, the
3919 * EEPROM will most likely contain an invalid checksum.
3920 *****************************************************************************/
3921 s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3924 spin_lock(&e1000_eeprom_lock);
3925 ret = e1000_do_write_eeprom(hw, offset, words, data);
3926 spin_unlock(&e1000_eeprom_lock);
3931 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3933 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3936 DEBUGFUNC("e1000_write_eeprom");
3938 /* If eeprom is not yet detected, do so now */
3939 if (eeprom->word_size == 0)
3940 e1000_init_eeprom_params(hw);
3942 /* A check for invalid values: offset too large, too many words, and not
3945 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3947 DEBUGOUT("\"words\" parameter out of bounds\n");
3948 return -E1000_ERR_EEPROM;
3951 if (eeprom->use_eewr)
3952 return e1000_write_eeprom_eewr(hw, offset, words, data);
3954 /* Prepare the EEPROM for writing */
3955 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3956 return -E1000_ERR_EEPROM;
3958 if (eeprom->type == e1000_eeprom_microwire) {
3959 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3961 status = e1000_write_eeprom_spi(hw, offset, words, data);
3965 /* Done with writing */
3966 e1000_release_eeprom(hw);
3971 /******************************************************************************
3972 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3974 * hw - Struct containing variables accessed by shared code
3975 * offset - offset within the EEPROM to be written to
3976 * words - number of words to write
3977 * data - pointer to array of 8 bit words to be written to the EEPROM
3979 *****************************************************************************/
3980 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
3983 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3986 DEBUGFUNC("e1000_write_eeprom_spi");
3988 while (widx < words) {
3989 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
3991 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3993 e1000_standby_eeprom(hw);
3995 /* Send the WRITE ENABLE command (8 bit opcode ) */
3996 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3997 eeprom->opcode_bits);
3999 e1000_standby_eeprom(hw);
4001 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4002 if ((eeprom->address_bits == 8) && (offset >= 128))
4003 write_opcode |= EEPROM_A8_OPCODE_SPI;
4005 /* Send the Write command (8-bit opcode + addr) */
4006 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4008 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
4009 eeprom->address_bits);
4013 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4014 while (widx < words) {
4015 u16 word_out = data[widx];
4016 word_out = (word_out >> 8) | (word_out << 8);
4017 e1000_shift_out_ee_bits(hw, word_out, 16);
4020 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4021 * operation, while the smaller eeproms are capable of an 8-byte
4022 * PAGE WRITE operation. Break the inner loop to pass new address
4024 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
4025 e1000_standby_eeprom(hw);
4031 return E1000_SUCCESS;
4034 /******************************************************************************
4035 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4037 * hw - Struct containing variables accessed by shared code
4038 * offset - offset within the EEPROM to be written to
4039 * words - number of words to write
4040 * data - pointer to array of 16 bit words to be written to the EEPROM
4042 *****************************************************************************/
4043 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4044 u16 words, u16 *data)
4046 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4048 u16 words_written = 0;
4051 DEBUGFUNC("e1000_write_eeprom_microwire");
4053 /* Send the write enable command to the EEPROM (3-bit opcode plus
4054 * 6/8-bit dummy address beginning with 11). It's less work to include
4055 * the 11 of the dummy address as part of the opcode than it is to shift
4056 * it over the correct number of bits for the address. This puts the
4057 * EEPROM into write/erase mode.
4059 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4060 (u16)(eeprom->opcode_bits + 2));
4062 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
4064 /* Prepare the EEPROM */
4065 e1000_standby_eeprom(hw);
4067 while (words_written < words) {
4068 /* Send the Write command (3-bit opcode + addr) */
4069 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4070 eeprom->opcode_bits);
4072 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
4073 eeprom->address_bits);
4076 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4078 /* Toggle the CS line. This in effect tells the EEPROM to execute
4079 * the previous command.
4081 e1000_standby_eeprom(hw);
4083 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4084 * signal that the command has been completed by raising the DO signal.
4085 * If DO does not go high in 10 milliseconds, then error out.
4087 for (i = 0; i < 200; i++) {
4089 if (eecd & E1000_EECD_DO) break;
4093 DEBUGOUT("EEPROM Write did not complete\n");
4094 return -E1000_ERR_EEPROM;
4097 /* Recover from write */
4098 e1000_standby_eeprom(hw);
4103 /* Send the write disable command to the EEPROM (3-bit opcode plus
4104 * 6/8-bit dummy address beginning with 10). It's less work to include
4105 * the 10 of the dummy address as part of the opcode than it is to shift
4106 * it over the correct number of bits for the address. This takes the
4107 * EEPROM out of write/erase mode.
4109 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4110 (u16)(eeprom->opcode_bits + 2));
4112 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
4114 return E1000_SUCCESS;
4117 /******************************************************************************
4118 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4119 * second function of dual function devices
4121 * hw - Struct containing variables accessed by shared code
4122 *****************************************************************************/
4123 s32 e1000_read_mac_addr(struct e1000_hw *hw)
4128 DEBUGFUNC("e1000_read_mac_addr");
4130 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4132 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4133 DEBUGOUT("EEPROM Read Error\n");
4134 return -E1000_ERR_EEPROM;
4136 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4137 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
4140 switch (hw->mac_type) {
4144 case e1000_82546_rev_3:
4145 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4146 hw->perm_mac_addr[5] ^= 0x01;
4150 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4151 hw->mac_addr[i] = hw->perm_mac_addr[i];
4152 return E1000_SUCCESS;
4155 /******************************************************************************
4156 * Initializes receive address filters.
4158 * hw - Struct containing variables accessed by shared code
4160 * Places the MAC address in receive address register 0 and clears the rest
4161 * of the receive addresss registers. Clears the multicast table. Assumes
4162 * the receiver is in reset when the routine is called.
4163 *****************************************************************************/
4164 static void e1000_init_rx_addrs(struct e1000_hw *hw)
4169 DEBUGFUNC("e1000_init_rx_addrs");
4171 /* Setup the receive address. */
4172 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4174 e1000_rar_set(hw, hw->mac_addr, 0);
4176 rar_num = E1000_RAR_ENTRIES;
4178 /* Zero out the other 15 receive addresses. */
4179 DEBUGOUT("Clearing RAR[1-15]\n");
4180 for (i = 1; i < rar_num; i++) {
4181 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4182 E1000_WRITE_FLUSH();
4183 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4184 E1000_WRITE_FLUSH();
4188 /******************************************************************************
4189 * Hashes an address to determine its location in the multicast table
4191 * hw - Struct containing variables accessed by shared code
4192 * mc_addr - the multicast address to hash
4193 *****************************************************************************/
4194 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
4198 /* The portion of the address that is used for the hash table is
4199 * determined by the mc_filter_type setting.
4201 switch (hw->mc_filter_type) {
4202 /* [0] [1] [2] [3] [4] [5]
4207 /* [47:36] i.e. 0x563 for above example address */
4208 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
4211 /* [46:35] i.e. 0xAC6 for above example address */
4212 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
4215 /* [45:34] i.e. 0x5D8 for above example address */
4216 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
4219 /* [43:32] i.e. 0x634 for above example address */
4220 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
4224 hash_value &= 0xFFF;
4228 /******************************************************************************
4229 * Puts an ethernet address into a receive address register.
4231 * hw - Struct containing variables accessed by shared code
4232 * addr - Address to put into receive address register
4233 * index - Receive address register to write
4234 *****************************************************************************/
4235 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
4237 u32 rar_low, rar_high;
4239 /* HW expects these in little endian so we reverse the byte order
4240 * from network order (big endian) to little endian
4242 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4243 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4244 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
4246 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4250 * If there are any Rx frames queued up or otherwise present in the HW
4251 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4252 * hang. To work around this issue, we have to disable receives and
4253 * flush out all Rx frames before we enable RSS. To do so, we modify we
4254 * redirect all Rx traffic to manageability and then reset the HW.
4255 * This flushes away Rx frames, and (since the redirections to
4256 * manageability persists across resets) keeps new ones from coming in
4257 * while we work. Then, we clear the Address Valid AV bit for all MAC
4258 * addresses and undo the re-direction to manageability.
4259 * Now, frames are coming in again, but the MAC won't accept them, so
4260 * far so good. We now proceed to initialize RSS (if necessary) and
4261 * configure the Rx unit. Last, we re-enable the AV bits and continue
4264 switch (hw->mac_type) {
4266 /* Indicate to hardware the Address is Valid. */
4267 rar_high |= E1000_RAH_AV;
4271 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4272 E1000_WRITE_FLUSH();
4273 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4274 E1000_WRITE_FLUSH();
4277 /******************************************************************************
4278 * Writes a value to the specified offset in the VLAN filter table.
4280 * hw - Struct containing variables accessed by shared code
4281 * offset - Offset in VLAN filer table to write
4282 * value - Value to write into VLAN filter table
4283 *****************************************************************************/
4284 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
4288 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4289 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4290 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4291 E1000_WRITE_FLUSH();
4292 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4293 E1000_WRITE_FLUSH();
4295 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4296 E1000_WRITE_FLUSH();
4300 /******************************************************************************
4301 * Clears the VLAN filer table
4303 * hw - Struct containing variables accessed by shared code
4304 *****************************************************************************/
4305 static void e1000_clear_vfta(struct e1000_hw *hw)
4309 u32 vfta_offset = 0;
4310 u32 vfta_bit_in_reg = 0;
4312 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4313 /* If the offset we want to clear is the same offset of the
4314 * manageability VLAN ID, then clear all bits except that of the
4315 * manageability unit */
4316 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4317 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4318 E1000_WRITE_FLUSH();
4322 static s32 e1000_id_led_init(struct e1000_hw *hw)
4325 const u32 ledctl_mask = 0x000000FF;
4326 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4327 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4328 u16 eeprom_data, i, temp;
4329 const u16 led_mask = 0x0F;
4331 DEBUGFUNC("e1000_id_led_init");
4333 if (hw->mac_type < e1000_82540) {
4335 return E1000_SUCCESS;
4338 ledctl = er32(LEDCTL);
4339 hw->ledctl_default = ledctl;
4340 hw->ledctl_mode1 = hw->ledctl_default;
4341 hw->ledctl_mode2 = hw->ledctl_default;
4343 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4344 DEBUGOUT("EEPROM Read Error\n");
4345 return -E1000_ERR_EEPROM;
4348 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4349 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4350 eeprom_data = ID_LED_DEFAULT;
4353 for (i = 0; i < 4; i++) {
4354 temp = (eeprom_data >> (i << 2)) & led_mask;
4356 case ID_LED_ON1_DEF2:
4357 case ID_LED_ON1_ON2:
4358 case ID_LED_ON1_OFF2:
4359 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4360 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4362 case ID_LED_OFF1_DEF2:
4363 case ID_LED_OFF1_ON2:
4364 case ID_LED_OFF1_OFF2:
4365 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4366 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4373 case ID_LED_DEF1_ON2:
4374 case ID_LED_ON1_ON2:
4375 case ID_LED_OFF1_ON2:
4376 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4377 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4379 case ID_LED_DEF1_OFF2:
4380 case ID_LED_ON1_OFF2:
4381 case ID_LED_OFF1_OFF2:
4382 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4383 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4390 return E1000_SUCCESS;
4393 /******************************************************************************
4394 * Prepares SW controlable LED for use and saves the current state of the LED.
4396 * hw - Struct containing variables accessed by shared code
4397 *****************************************************************************/
4398 s32 e1000_setup_led(struct e1000_hw *hw)
4401 s32 ret_val = E1000_SUCCESS;
4403 DEBUGFUNC("e1000_setup_led");
4405 switch (hw->mac_type) {
4406 case e1000_82542_rev2_0:
4407 case e1000_82542_rev2_1:
4410 /* No setup necessary */
4414 case e1000_82541_rev_2:
4415 case e1000_82547_rev_2:
4416 /* Turn off PHY Smart Power Down (if enabled) */
4417 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4418 &hw->phy_spd_default);
4421 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4422 (u16)(hw->phy_spd_default &
4423 ~IGP01E1000_GMII_SPD));
4428 if (hw->media_type == e1000_media_type_fiber) {
4429 ledctl = er32(LEDCTL);
4430 /* Save current LEDCTL settings */
4431 hw->ledctl_default = ledctl;
4433 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4434 E1000_LEDCTL_LED0_BLINK |
4435 E1000_LEDCTL_LED0_MODE_MASK);
4436 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4437 E1000_LEDCTL_LED0_MODE_SHIFT);
4438 ew32(LEDCTL, ledctl);
4439 } else if (hw->media_type == e1000_media_type_copper)
4440 ew32(LEDCTL, hw->ledctl_mode1);
4444 return E1000_SUCCESS;
4447 /******************************************************************************
4448 * Restores the saved state of the SW controlable LED.
4450 * hw - Struct containing variables accessed by shared code
4451 *****************************************************************************/
4452 s32 e1000_cleanup_led(struct e1000_hw *hw)
4454 s32 ret_val = E1000_SUCCESS;
4456 DEBUGFUNC("e1000_cleanup_led");
4458 switch (hw->mac_type) {
4459 case e1000_82542_rev2_0:
4460 case e1000_82542_rev2_1:
4463 /* No cleanup necessary */
4467 case e1000_82541_rev_2:
4468 case e1000_82547_rev_2:
4469 /* Turn on PHY Smart Power Down (if previously enabled) */
4470 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4471 hw->phy_spd_default);
4476 /* Restore LEDCTL settings */
4477 ew32(LEDCTL, hw->ledctl_default);
4481 return E1000_SUCCESS;
4484 /******************************************************************************
4485 * Turns on the software controllable LED
4487 * hw - Struct containing variables accessed by shared code
4488 *****************************************************************************/
4489 s32 e1000_led_on(struct e1000_hw *hw)
4491 u32 ctrl = er32(CTRL);
4493 DEBUGFUNC("e1000_led_on");
4495 switch (hw->mac_type) {
4496 case e1000_82542_rev2_0:
4497 case e1000_82542_rev2_1:
4499 /* Set SW Defineable Pin 0 to turn on the LED */
4500 ctrl |= E1000_CTRL_SWDPIN0;
4501 ctrl |= E1000_CTRL_SWDPIO0;
4504 if (hw->media_type == e1000_media_type_fiber) {
4505 /* Set SW Defineable Pin 0 to turn on the LED */
4506 ctrl |= E1000_CTRL_SWDPIN0;
4507 ctrl |= E1000_CTRL_SWDPIO0;
4509 /* Clear SW Defineable Pin 0 to turn on the LED */
4510 ctrl &= ~E1000_CTRL_SWDPIN0;
4511 ctrl |= E1000_CTRL_SWDPIO0;
4515 if (hw->media_type == e1000_media_type_fiber) {
4516 /* Clear SW Defineable Pin 0 to turn on the LED */
4517 ctrl &= ~E1000_CTRL_SWDPIN0;
4518 ctrl |= E1000_CTRL_SWDPIO0;
4519 } else if (hw->media_type == e1000_media_type_copper) {
4520 ew32(LEDCTL, hw->ledctl_mode2);
4521 return E1000_SUCCESS;
4528 return E1000_SUCCESS;
4531 /******************************************************************************
4532 * Turns off the software controllable LED
4534 * hw - Struct containing variables accessed by shared code
4535 *****************************************************************************/
4536 s32 e1000_led_off(struct e1000_hw *hw)
4538 u32 ctrl = er32(CTRL);
4540 DEBUGFUNC("e1000_led_off");
4542 switch (hw->mac_type) {
4543 case e1000_82542_rev2_0:
4544 case e1000_82542_rev2_1:
4546 /* Clear SW Defineable Pin 0 to turn off the LED */
4547 ctrl &= ~E1000_CTRL_SWDPIN0;
4548 ctrl |= E1000_CTRL_SWDPIO0;
4551 if (hw->media_type == e1000_media_type_fiber) {
4552 /* Clear SW Defineable Pin 0 to turn off the LED */
4553 ctrl &= ~E1000_CTRL_SWDPIN0;
4554 ctrl |= E1000_CTRL_SWDPIO0;
4556 /* Set SW Defineable Pin 0 to turn off the LED */
4557 ctrl |= E1000_CTRL_SWDPIN0;
4558 ctrl |= E1000_CTRL_SWDPIO0;
4562 if (hw->media_type == e1000_media_type_fiber) {
4563 /* Set SW Defineable Pin 0 to turn off the LED */
4564 ctrl |= E1000_CTRL_SWDPIN0;
4565 ctrl |= E1000_CTRL_SWDPIO0;
4566 } else if (hw->media_type == e1000_media_type_copper) {
4567 ew32(LEDCTL, hw->ledctl_mode1);
4568 return E1000_SUCCESS;
4575 return E1000_SUCCESS;
4578 /******************************************************************************
4579 * Clears all hardware statistics counters.
4581 * hw - Struct containing variables accessed by shared code
4582 *****************************************************************************/
4583 static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
4587 temp = er32(CRCERRS);
4588 temp = er32(SYMERRS);
4593 temp = er32(LATECOL);
4598 temp = er32(XONRXC);
4599 temp = er32(XONTXC);
4600 temp = er32(XOFFRXC);
4601 temp = er32(XOFFTXC);
4605 temp = er32(PRC127);
4606 temp = er32(PRC255);
4607 temp = er32(PRC511);
4608 temp = er32(PRC1023);
4609 temp = er32(PRC1522);
4632 temp = er32(PTC127);
4633 temp = er32(PTC255);
4634 temp = er32(PTC511);
4635 temp = er32(PTC1023);
4636 temp = er32(PTC1522);
4641 if (hw->mac_type < e1000_82543) return;
4643 temp = er32(ALGNERRC);
4644 temp = er32(RXERRC);
4646 temp = er32(CEXTERR);
4648 temp = er32(TSCTFC);
4650 if (hw->mac_type <= e1000_82544) return;
4652 temp = er32(MGTPRC);
4653 temp = er32(MGTPDC);
4654 temp = er32(MGTPTC);
4657 /******************************************************************************
4658 * Resets Adaptive IFS to its default state.
4660 * hw - Struct containing variables accessed by shared code
4662 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4663 * hw->ifs_params_forced to true. However, you must initialize hw->
4664 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4665 * before calling this function.
4666 *****************************************************************************/
4667 void e1000_reset_adaptive(struct e1000_hw *hw)
4669 DEBUGFUNC("e1000_reset_adaptive");
4671 if (hw->adaptive_ifs) {
4672 if (!hw->ifs_params_forced) {
4673 hw->current_ifs_val = 0;
4674 hw->ifs_min_val = IFS_MIN;
4675 hw->ifs_max_val = IFS_MAX;
4676 hw->ifs_step_size = IFS_STEP;
4677 hw->ifs_ratio = IFS_RATIO;
4679 hw->in_ifs_mode = false;
4682 DEBUGOUT("Not in Adaptive IFS mode!\n");
4686 /******************************************************************************
4687 * Called during the callback/watchdog routine to update IFS value based on
4688 * the ratio of transmits to collisions.
4690 * hw - Struct containing variables accessed by shared code
4691 * tx_packets - Number of transmits since last callback
4692 * total_collisions - Number of collisions since last callback
4693 *****************************************************************************/
4694 void e1000_update_adaptive(struct e1000_hw *hw)
4696 DEBUGFUNC("e1000_update_adaptive");
4698 if (hw->adaptive_ifs) {
4699 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4700 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4701 hw->in_ifs_mode = true;
4702 if (hw->current_ifs_val < hw->ifs_max_val) {
4703 if (hw->current_ifs_val == 0)
4704 hw->current_ifs_val = hw->ifs_min_val;
4706 hw->current_ifs_val += hw->ifs_step_size;
4707 ew32(AIT, hw->current_ifs_val);
4711 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4712 hw->current_ifs_val = 0;
4713 hw->in_ifs_mode = false;
4718 DEBUGOUT("Not in Adaptive IFS mode!\n");
4722 /******************************************************************************
4723 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4725 * hw - Struct containing variables accessed by shared code
4726 * frame_len - The length of the frame in question
4727 * mac_addr - The Ethernet destination address of the frame in question
4728 *****************************************************************************/
4729 void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4730 u32 frame_len, u8 *mac_addr)
4734 /* First adjust the frame length. */
4736 /* We need to adjust the statistics counters, since the hardware
4737 * counters overcount this packet as a CRC error and undercount
4738 * the packet as a good packet
4740 /* This packet should not be counted as a CRC error. */
4742 /* This packet does count as a Good Packet Received. */
4745 /* Adjust the Good Octets received counters */
4746 carry_bit = 0x80000000 & stats->gorcl;
4747 stats->gorcl += frame_len;
4748 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4749 * Received Count) was one before the addition,
4750 * AND it is zero after, then we lost the carry out,
4751 * need to add one to Gorch (Good Octets Received Count High).
4752 * This could be simplified if all environments supported
4755 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4757 /* Is this a broadcast or multicast? Check broadcast first,
4758 * since the test for a multicast frame will test positive on
4759 * a broadcast frame.
4761 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
4762 /* Broadcast packet */
4764 else if (*mac_addr & 0x01)
4765 /* Multicast packet */
4768 if (frame_len == hw->max_frame_size) {
4769 /* In this case, the hardware has overcounted the number of
4776 /* Adjust the bin counters when the extra byte put the frame in the
4777 * wrong bin. Remember that the frame_len was adjusted above.
4779 if (frame_len == 64) {
4782 } else if (frame_len == 127) {
4785 } else if (frame_len == 255) {
4788 } else if (frame_len == 511) {
4791 } else if (frame_len == 1023) {
4794 } else if (frame_len == 1522) {
4799 /******************************************************************************
4800 * Gets the current PCI bus type, speed, and width of the hardware
4802 * hw - Struct containing variables accessed by shared code
4803 *****************************************************************************/
4804 void e1000_get_bus_info(struct e1000_hw *hw)
4808 switch (hw->mac_type) {
4809 case e1000_82542_rev2_0:
4810 case e1000_82542_rev2_1:
4811 hw->bus_type = e1000_bus_type_pci;
4812 hw->bus_speed = e1000_bus_speed_unknown;
4813 hw->bus_width = e1000_bus_width_unknown;
4816 status = er32(STATUS);
4817 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4818 e1000_bus_type_pcix : e1000_bus_type_pci;
4820 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4821 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4822 e1000_bus_speed_66 : e1000_bus_speed_120;
4823 } else if (hw->bus_type == e1000_bus_type_pci) {
4824 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4825 e1000_bus_speed_66 : e1000_bus_speed_33;
4827 switch (status & E1000_STATUS_PCIX_SPEED) {
4828 case E1000_STATUS_PCIX_SPEED_66:
4829 hw->bus_speed = e1000_bus_speed_66;
4831 case E1000_STATUS_PCIX_SPEED_100:
4832 hw->bus_speed = e1000_bus_speed_100;
4834 case E1000_STATUS_PCIX_SPEED_133:
4835 hw->bus_speed = e1000_bus_speed_133;
4838 hw->bus_speed = e1000_bus_speed_reserved;
4842 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4843 e1000_bus_width_64 : e1000_bus_width_32;
4848 /******************************************************************************
4849 * Writes a value to one of the devices registers using port I/O (as opposed to
4850 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4852 * hw - Struct containing variables accessed by shared code
4853 * offset - offset to write to
4854 * value - value to write
4855 *****************************************************************************/
4856 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
4858 unsigned long io_addr = hw->io_base;
4859 unsigned long io_data = hw->io_base + 4;
4861 e1000_io_write(hw, io_addr, offset);
4862 e1000_io_write(hw, io_data, value);
4865 /******************************************************************************
4866 * Estimates the cable length.
4868 * hw - Struct containing variables accessed by shared code
4869 * min_length - The estimated minimum length
4870 * max_length - The estimated maximum length
4872 * returns: - E1000_ERR_XXX
4875 * This function always returns a ranged length (minimum & maximum).
4876 * So for M88 phy's, this function interprets the one value returned from the
4877 * register to the minimum and maximum range.
4878 * For IGP phy's, the function calculates the range by the AGC registers.
4879 *****************************************************************************/
4880 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4888 DEBUGFUNC("e1000_get_cable_length");
4890 *min_length = *max_length = 0;
4892 /* Use old method for Phy older than IGP */
4893 if (hw->phy_type == e1000_phy_m88) {
4895 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4899 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4900 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4902 /* Convert the enum value to ranged values */
4903 switch (cable_length) {
4904 case e1000_cable_length_50:
4906 *max_length = e1000_igp_cable_length_50;
4908 case e1000_cable_length_50_80:
4909 *min_length = e1000_igp_cable_length_50;
4910 *max_length = e1000_igp_cable_length_80;
4912 case e1000_cable_length_80_110:
4913 *min_length = e1000_igp_cable_length_80;
4914 *max_length = e1000_igp_cable_length_110;
4916 case e1000_cable_length_110_140:
4917 *min_length = e1000_igp_cable_length_110;
4918 *max_length = e1000_igp_cable_length_140;
4920 case e1000_cable_length_140:
4921 *min_length = e1000_igp_cable_length_140;
4922 *max_length = e1000_igp_cable_length_170;
4925 return -E1000_ERR_PHY;
4928 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4930 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4931 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4932 {IGP01E1000_PHY_AGC_A,
4933 IGP01E1000_PHY_AGC_B,
4934 IGP01E1000_PHY_AGC_C,
4935 IGP01E1000_PHY_AGC_D};
4936 /* Read the AGC registers for all channels */
4937 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4939 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4943 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4945 /* Value bound check. */
4946 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4947 (cur_agc_value == 0))
4948 return -E1000_ERR_PHY;
4950 agc_value += cur_agc_value;
4952 /* Update minimal AGC value. */
4953 if (min_agc_value > cur_agc_value)
4954 min_agc_value = cur_agc_value;
4957 /* Remove the minimal AGC result for length < 50m */
4958 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4959 agc_value -= min_agc_value;
4961 /* Get the average length of the remaining 3 channels */
4962 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4964 /* Get the average length of all the 4 channels. */
4965 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4968 /* Set the range of the calculated length. */
4969 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4970 IGP01E1000_AGC_RANGE) > 0) ?
4971 (e1000_igp_cable_length_table[agc_value] -
4972 IGP01E1000_AGC_RANGE) : 0;
4973 *max_length = e1000_igp_cable_length_table[agc_value] +
4974 IGP01E1000_AGC_RANGE;
4977 return E1000_SUCCESS;
4980 /******************************************************************************
4981 * Check the cable polarity
4983 * hw - Struct containing variables accessed by shared code
4984 * polarity - output parameter : 0 - Polarity is not reversed
4985 * 1 - Polarity is reversed.
4987 * returns: - E1000_ERR_XXX
4990 * For phy's older than IGP, this function simply reads the polarity bit in the
4991 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4992 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4993 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4994 * IGP01E1000_PHY_PCS_INIT_REG.
4995 *****************************************************************************/
4996 static s32 e1000_check_polarity(struct e1000_hw *hw,
4997 e1000_rev_polarity *polarity)
5002 DEBUGFUNC("e1000_check_polarity");
5004 if (hw->phy_type == e1000_phy_m88) {
5005 /* return the Polarity bit in the Status register. */
5006 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5010 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5011 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5012 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5014 } else if (hw->phy_type == e1000_phy_igp) {
5015 /* Read the Status register to check the speed */
5016 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5021 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5022 * find the polarity status */
5023 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5024 IGP01E1000_PSSR_SPEED_1000MBPS) {
5026 /* Read the GIG initialization PCS register (0x00B4) */
5027 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5032 /* Check the polarity bits */
5033 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5034 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5036 /* For 10 Mbps, read the polarity bit in the status register. (for
5037 * 100 Mbps this bit is always 0) */
5038 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5039 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5042 return E1000_SUCCESS;
5045 /******************************************************************************
5046 * Check if Downshift occured
5048 * hw - Struct containing variables accessed by shared code
5049 * downshift - output parameter : 0 - No Downshift ocured.
5050 * 1 - Downshift ocured.
5052 * returns: - E1000_ERR_XXX
5055 * For phy's older than IGP, this function reads the Downshift bit in the Phy
5056 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5057 * Link Health register. In IGP this bit is latched high, so the driver must
5058 * read it immediately after link is established.
5059 *****************************************************************************/
5060 static s32 e1000_check_downshift(struct e1000_hw *hw)
5065 DEBUGFUNC("e1000_check_downshift");
5067 if (hw->phy_type == e1000_phy_igp) {
5068 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5073 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5074 } else if (hw->phy_type == e1000_phy_m88) {
5075 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5080 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5081 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5084 return E1000_SUCCESS;
5087 /*****************************************************************************
5089 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5090 * gigabit link is achieved to improve link quality.
5092 * hw: Struct containing variables accessed by shared code
5094 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5095 * E1000_SUCCESS at any other case.
5097 ****************************************************************************/
5099 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
5102 u16 phy_data, phy_saved_data, speed, duplex, i;
5103 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5104 {IGP01E1000_PHY_AGC_PARAM_A,
5105 IGP01E1000_PHY_AGC_PARAM_B,
5106 IGP01E1000_PHY_AGC_PARAM_C,
5107 IGP01E1000_PHY_AGC_PARAM_D};
5108 u16 min_length, max_length;
5110 DEBUGFUNC("e1000_config_dsp_after_link_change");
5112 if (hw->phy_type != e1000_phy_igp)
5113 return E1000_SUCCESS;
5116 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5118 DEBUGOUT("Error getting link speed and duplex\n");
5122 if (speed == SPEED_1000) {
5124 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5128 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
5129 min_length >= e1000_igp_cable_length_50) {
5131 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5132 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5137 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5139 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5144 hw->dsp_config_state = e1000_dsp_config_activated;
5147 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
5148 (min_length < e1000_igp_cable_length_50)) {
5150 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5153 /* clear previous idle error counts */
5154 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5159 for (i = 0; i < ffe_idle_err_timeout; i++) {
5161 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5166 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5167 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5168 hw->ffe_config_state = e1000_ffe_config_active;
5170 ret_val = e1000_write_phy_reg(hw,
5171 IGP01E1000_PHY_DSP_FFE,
5172 IGP01E1000_PHY_DSP_FFE_CM_CP);
5179 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5184 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5185 /* Save off the current value of register 0x2F5B to be restored at
5186 * the end of the routines. */
5187 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5192 /* Disable the PHY transmitter */
5193 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5200 ret_val = e1000_write_phy_reg(hw, 0x0000,
5201 IGP01E1000_IEEE_FORCE_GIGA);
5204 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5205 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5209 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5210 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5212 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5217 ret_val = e1000_write_phy_reg(hw, 0x0000,
5218 IGP01E1000_IEEE_RESTART_AUTONEG);
5224 /* Now enable the transmitter */
5225 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5230 hw->dsp_config_state = e1000_dsp_config_enabled;
5233 if (hw->ffe_config_state == e1000_ffe_config_active) {
5234 /* Save off the current value of register 0x2F5B to be restored at
5235 * the end of the routines. */
5236 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5241 /* Disable the PHY transmitter */
5242 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5249 ret_val = e1000_write_phy_reg(hw, 0x0000,
5250 IGP01E1000_IEEE_FORCE_GIGA);
5253 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5254 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5258 ret_val = e1000_write_phy_reg(hw, 0x0000,
5259 IGP01E1000_IEEE_RESTART_AUTONEG);
5265 /* Now enable the transmitter */
5266 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5271 hw->ffe_config_state = e1000_ffe_config_enabled;
5274 return E1000_SUCCESS;
5277 /*****************************************************************************
5278 * Set PHY to class A mode
5279 * Assumes the following operations will follow to enable the new class mode.
5280 * 1. Do a PHY soft reset
5281 * 2. Restart auto-negotiation or force link.
5283 * hw - Struct containing variables accessed by shared code
5284 ****************************************************************************/
5285 static s32 e1000_set_phy_mode(struct e1000_hw *hw)
5290 DEBUGFUNC("e1000_set_phy_mode");
5292 if ((hw->mac_type == e1000_82545_rev_3) &&
5293 (hw->media_type == e1000_media_type_copper)) {
5294 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5299 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5300 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5301 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5304 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5308 hw->phy_reset_disable = false;
5312 return E1000_SUCCESS;
5315 /*****************************************************************************
5317 * This function sets the lplu state according to the active flag. When
5318 * activating lplu this function also disables smart speed and vise versa.
5319 * lplu will not be activated unless the device autonegotiation advertisment
5320 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5321 * hw: Struct containing variables accessed by shared code
5322 * active - true to enable lplu false to disable lplu.
5324 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5325 * E1000_SUCCESS at any other case.
5327 ****************************************************************************/
5329 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
5333 DEBUGFUNC("e1000_set_d3_lplu_state");
5335 if (hw->phy_type != e1000_phy_igp)
5336 return E1000_SUCCESS;
5338 /* During driver activity LPLU should not be used or it will attain link
5339 * from the lowest speeds starting from 10Mbps. The capability is used for
5340 * Dx transitions and states */
5341 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
5342 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5346 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5352 if (hw->mac_type == e1000_82541_rev_2 ||
5353 hw->mac_type == e1000_82547_rev_2) {
5354 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5355 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5359 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5360 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5366 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5367 * Dx states where the power conservation is most important. During
5368 * driver activity we should enable SmartSpeed, so performance is
5370 if (hw->smart_speed == e1000_smart_speed_on) {
5371 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5376 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5377 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5381 } else if (hw->smart_speed == e1000_smart_speed_off) {
5382 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5387 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5388 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5394 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5395 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5396 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5398 if (hw->mac_type == e1000_82541_rev_2 ||
5399 hw->mac_type == e1000_82547_rev_2) {
5400 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5401 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5405 phy_data |= IGP02E1000_PM_D3_LPLU;
5406 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5412 /* When LPLU is enabled we should disable SmartSpeed */
5413 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5417 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5418 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5423 return E1000_SUCCESS;
5426 /******************************************************************************
5427 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5429 * hw - Struct containing variables accessed by shared code
5430 *****************************************************************************/
5431 static s32 e1000_set_vco_speed(struct e1000_hw *hw)
5434 u16 default_page = 0;
5437 DEBUGFUNC("e1000_set_vco_speed");
5439 switch (hw->mac_type) {
5440 case e1000_82545_rev_3:
5441 case e1000_82546_rev_3:
5444 return E1000_SUCCESS;
5447 /* Set PHY register 30, page 5, bit 8 to 0 */
5449 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5453 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5457 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5461 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5462 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5466 /* Set PHY register 30, page 4, bit 11 to 1 */
5468 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5472 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5476 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5477 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5481 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5485 return E1000_SUCCESS;
5489 /******************************************************************************
5490 * Verifies the hardware needs to allow ARPs to be processed by the host
5492 * hw - Struct containing variables accessed by shared code
5494 * returns: - true/false
5496 *****************************************************************************/
5497 u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5501 if (hw->asf_firmware_present) {
5504 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5505 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5507 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5513 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5519 /* Polarity reversal workaround for forced 10F/10H links. */
5521 /* Disable the transmitter on the PHY */
5523 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5526 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5530 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5534 /* This loop will early-out if the NO link condition has been met. */
5535 for (i = PHY_FORCE_TIME; i > 0; i--) {
5536 /* Read the MII Status Register and wait for Link Status bit
5540 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5544 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5548 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
5552 /* Recommended delay time after link has been lost */
5555 /* Now we will re-enable th transmitter on the PHY */
5557 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5561 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5565 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5569 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5573 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5577 /* This loop will early-out if the link condition has been met. */
5578 for (i = PHY_FORCE_TIME; i > 0; i--) {
5579 /* Read the MII Status Register and wait for Link Status bit
5583 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5587 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5591 if (mii_status_reg & MII_SR_LINK_STATUS) break;
5594 return E1000_SUCCESS;
5597 /*******************************************************************************
5599 * Check for EEPROM Auto Read bit done.
5601 * hw: Struct containing variables accessed by shared code
5603 * returns: - E1000_ERR_RESET if fail to reset MAC
5604 * E1000_SUCCESS at any other case.
5606 ******************************************************************************/
5607 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
5609 DEBUGFUNC("e1000_get_auto_rd_done");
5611 return E1000_SUCCESS;
5614 /***************************************************************************
5615 * Checks if the PHY configuration is done
5617 * hw: Struct containing variables accessed by shared code
5619 * returns: - E1000_ERR_RESET if fail to reset MAC
5620 * E1000_SUCCESS at any other case.
5622 ***************************************************************************/
5623 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
5625 DEBUGFUNC("e1000_get_phy_cfg_done");
5627 return E1000_SUCCESS;