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_swfw_sync_acquire(struct e1000_hw *hw, u16 mask);
37 static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask);
39 static s32 e1000_check_downshift(struct e1000_hw *hw);
40 static s32 e1000_check_polarity(struct e1000_hw *hw,
41 e1000_rev_polarity *polarity);
42 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
43 static void e1000_clear_vfta(struct e1000_hw *hw);
44 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
46 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
47 static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
48 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
49 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
51 static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
52 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
53 static s32 e1000_id_led_init(struct e1000_hw *hw);
54 static void e1000_init_rx_addrs(struct e1000_hw *hw);
55 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
56 struct e1000_phy_info *phy_info);
57 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
59 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
61 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
62 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
63 struct e1000_phy_info *phy_info);
64 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
65 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
66 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
67 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
68 static s32 e1000_set_phy_type(struct e1000_hw *hw);
69 static void e1000_phy_init_script(struct e1000_hw *hw);
70 static s32 e1000_setup_copper_link(struct e1000_hw *hw);
71 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
72 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
73 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
74 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
75 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
76 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
77 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data,
79 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
80 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
81 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
82 u16 words, u16 *data);
83 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
84 u16 words, u16 *data);
85 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
86 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
87 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
88 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
89 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
91 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw,u32 reg_addr,
93 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
94 static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
95 static void e1000_release_eeprom(struct e1000_hw *hw);
96 static void e1000_standby_eeprom(struct e1000_hw *hw);
97 static s32 e1000_set_vco_speed(struct e1000_hw *hw);
98 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
99 static s32 e1000_set_phy_mode(struct e1000_hw *hw);
100 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
101 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data);
103 /* IGP cable length table */
105 u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
106 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
107 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
108 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
109 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
110 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
111 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
112 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
113 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
115 static DEFINE_SPINLOCK(e1000_eeprom_lock);
117 /******************************************************************************
118 * Set the phy type member in the hw struct.
120 * hw - Struct containing variables accessed by shared code
121 *****************************************************************************/
122 static s32 e1000_set_phy_type(struct e1000_hw *hw)
124 DEBUGFUNC("e1000_set_phy_type");
126 if (hw->mac_type == e1000_undefined)
127 return -E1000_ERR_PHY_TYPE;
129 switch (hw->phy_id) {
130 case M88E1000_E_PHY_ID:
131 case M88E1000_I_PHY_ID:
132 case M88E1011_I_PHY_ID:
133 case M88E1111_I_PHY_ID:
134 hw->phy_type = e1000_phy_m88;
136 case IGP01E1000_I_PHY_ID:
137 if (hw->mac_type == e1000_82541 ||
138 hw->mac_type == e1000_82541_rev_2 ||
139 hw->mac_type == e1000_82547 ||
140 hw->mac_type == e1000_82547_rev_2) {
141 hw->phy_type = e1000_phy_igp;
145 /* Should never have loaded on this device */
146 hw->phy_type = e1000_phy_undefined;
147 return -E1000_ERR_PHY_TYPE;
150 return E1000_SUCCESS;
153 /******************************************************************************
154 * IGP phy init script - initializes the GbE PHY
156 * hw - Struct containing variables accessed by shared code
157 *****************************************************************************/
158 static void e1000_phy_init_script(struct e1000_hw *hw)
163 DEBUGFUNC("e1000_phy_init_script");
165 if (hw->phy_init_script) {
168 /* Save off the current value of register 0x2F5B to be restored at
169 * the end of this routine. */
170 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
172 /* Disabled the PHY transmitter */
173 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
177 e1000_write_phy_reg(hw,0x0000,0x0140);
181 switch (hw->mac_type) {
184 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
186 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
188 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
190 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
192 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
194 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
196 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
198 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
200 e1000_write_phy_reg(hw, 0x2010, 0x0008);
203 case e1000_82541_rev_2:
204 case e1000_82547_rev_2:
205 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
211 e1000_write_phy_reg(hw, 0x0000, 0x3300);
215 /* Now enable the transmitter */
216 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
218 if (hw->mac_type == e1000_82547) {
219 u16 fused, fine, coarse;
221 /* Move to analog registers page */
222 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
224 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
225 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
227 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
228 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
230 if (coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
231 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
232 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
233 } else if (coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
234 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
236 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
237 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
238 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
240 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
241 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
242 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
248 /******************************************************************************
249 * Set the mac type member in the hw struct.
251 * hw - Struct containing variables accessed by shared code
252 *****************************************************************************/
253 s32 e1000_set_mac_type(struct e1000_hw *hw)
255 DEBUGFUNC("e1000_set_mac_type");
257 switch (hw->device_id) {
258 case E1000_DEV_ID_82542:
259 switch (hw->revision_id) {
260 case E1000_82542_2_0_REV_ID:
261 hw->mac_type = e1000_82542_rev2_0;
263 case E1000_82542_2_1_REV_ID:
264 hw->mac_type = e1000_82542_rev2_1;
267 /* Invalid 82542 revision ID */
268 return -E1000_ERR_MAC_TYPE;
271 case E1000_DEV_ID_82543GC_FIBER:
272 case E1000_DEV_ID_82543GC_COPPER:
273 hw->mac_type = e1000_82543;
275 case E1000_DEV_ID_82544EI_COPPER:
276 case E1000_DEV_ID_82544EI_FIBER:
277 case E1000_DEV_ID_82544GC_COPPER:
278 case E1000_DEV_ID_82544GC_LOM:
279 hw->mac_type = e1000_82544;
281 case E1000_DEV_ID_82540EM:
282 case E1000_DEV_ID_82540EM_LOM:
283 case E1000_DEV_ID_82540EP:
284 case E1000_DEV_ID_82540EP_LOM:
285 case E1000_DEV_ID_82540EP_LP:
286 hw->mac_type = e1000_82540;
288 case E1000_DEV_ID_82545EM_COPPER:
289 case E1000_DEV_ID_82545EM_FIBER:
290 hw->mac_type = e1000_82545;
292 case E1000_DEV_ID_82545GM_COPPER:
293 case E1000_DEV_ID_82545GM_FIBER:
294 case E1000_DEV_ID_82545GM_SERDES:
295 hw->mac_type = e1000_82545_rev_3;
297 case E1000_DEV_ID_82546EB_COPPER:
298 case E1000_DEV_ID_82546EB_FIBER:
299 case E1000_DEV_ID_82546EB_QUAD_COPPER:
300 hw->mac_type = e1000_82546;
302 case E1000_DEV_ID_82546GB_COPPER:
303 case E1000_DEV_ID_82546GB_FIBER:
304 case E1000_DEV_ID_82546GB_SERDES:
305 case E1000_DEV_ID_82546GB_PCIE:
306 case E1000_DEV_ID_82546GB_QUAD_COPPER:
307 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
308 hw->mac_type = e1000_82546_rev_3;
310 case E1000_DEV_ID_82541EI:
311 case E1000_DEV_ID_82541EI_MOBILE:
312 case E1000_DEV_ID_82541ER_LOM:
313 hw->mac_type = e1000_82541;
315 case E1000_DEV_ID_82541ER:
316 case E1000_DEV_ID_82541GI:
317 case E1000_DEV_ID_82541GI_LF:
318 case E1000_DEV_ID_82541GI_MOBILE:
319 hw->mac_type = e1000_82541_rev_2;
321 case E1000_DEV_ID_82547EI:
322 case E1000_DEV_ID_82547EI_MOBILE:
323 hw->mac_type = e1000_82547;
325 case E1000_DEV_ID_82547GI:
326 hw->mac_type = e1000_82547_rev_2;
329 /* Should never have loaded on this device */
330 return -E1000_ERR_MAC_TYPE;
333 switch (hw->mac_type) {
336 case e1000_82541_rev_2:
337 case e1000_82547_rev_2:
338 hw->asf_firmware_present = true;
344 /* The 82543 chip does not count tx_carrier_errors properly in
347 if (hw->mac_type == e1000_82543)
348 hw->bad_tx_carr_stats_fd = true;
350 if (hw->mac_type > e1000_82544)
351 hw->has_smbus = true;
353 return E1000_SUCCESS;
356 /*****************************************************************************
357 * Set media type and TBI compatibility.
359 * hw - Struct containing variables accessed by shared code
360 * **************************************************************************/
361 void e1000_set_media_type(struct e1000_hw *hw)
365 DEBUGFUNC("e1000_set_media_type");
367 if (hw->mac_type != e1000_82543) {
368 /* tbi_compatibility is only valid on 82543 */
369 hw->tbi_compatibility_en = false;
372 switch (hw->device_id) {
373 case E1000_DEV_ID_82545GM_SERDES:
374 case E1000_DEV_ID_82546GB_SERDES:
375 hw->media_type = e1000_media_type_internal_serdes;
378 switch (hw->mac_type) {
379 case e1000_82542_rev2_0:
380 case e1000_82542_rev2_1:
381 hw->media_type = e1000_media_type_fiber;
384 status = er32(STATUS);
385 if (status & E1000_STATUS_TBIMODE) {
386 hw->media_type = e1000_media_type_fiber;
387 /* tbi_compatibility not valid on fiber */
388 hw->tbi_compatibility_en = false;
390 hw->media_type = e1000_media_type_copper;
397 /******************************************************************************
398 * Reset the transmit and receive units; mask and clear all interrupts.
400 * hw - Struct containing variables accessed by shared code
401 *****************************************************************************/
402 s32 e1000_reset_hw(struct e1000_hw *hw)
411 DEBUGFUNC("e1000_reset_hw");
413 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
414 if (hw->mac_type == e1000_82542_rev2_0) {
415 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
416 e1000_pci_clear_mwi(hw);
419 /* Clear interrupt mask to stop board from generating interrupts */
420 DEBUGOUT("Masking off all interrupts\n");
421 ew32(IMC, 0xffffffff);
423 /* Disable the Transmit and Receive units. Then delay to allow
424 * any pending transactions to complete before we hit the MAC with
428 ew32(TCTL, E1000_TCTL_PSP);
431 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
432 hw->tbi_compatibility_on = false;
434 /* Delay to allow any outstanding PCI transactions to complete before
435 * resetting the device
441 /* Must reset the PHY before resetting the MAC */
442 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
443 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
447 /* Issue a global reset to the MAC. This will reset the chip's
448 * transmit, receive, DMA, and link units. It will not effect
449 * the current PCI configuration. The global reset bit is self-
450 * clearing, and should clear within a microsecond.
452 DEBUGOUT("Issuing a global reset to MAC\n");
454 switch (hw->mac_type) {
460 case e1000_82541_rev_2:
461 /* These controllers can't ack the 64-bit write when issuing the
462 * reset, so use IO-mapping as a workaround to issue the reset */
463 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
465 case e1000_82545_rev_3:
466 case e1000_82546_rev_3:
467 /* Reset is performed on a shadow of the control register */
468 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
471 ew32(CTRL, (ctrl | E1000_CTRL_RST));
475 /* After MAC reset, force reload of EEPROM to restore power-on settings to
476 * device. Later controllers reload the EEPROM automatically, so just wait
477 * for reload to complete.
479 switch (hw->mac_type) {
480 case e1000_82542_rev2_0:
481 case e1000_82542_rev2_1:
484 /* Wait for reset to complete */
486 ctrl_ext = er32(CTRL_EXT);
487 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
488 ew32(CTRL_EXT, ctrl_ext);
490 /* Wait for EEPROM reload */
494 case e1000_82541_rev_2:
496 case e1000_82547_rev_2:
497 /* Wait for EEPROM reload */
501 /* Auto read done will delay 5ms or poll based on mac type */
502 ret_val = e1000_get_auto_rd_done(hw);
508 /* Disable HW ARPs on ASF enabled adapters */
509 if (hw->mac_type >= e1000_82540) {
511 manc &= ~(E1000_MANC_ARP_EN);
515 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
516 e1000_phy_init_script(hw);
518 /* Configure activity LED after PHY reset */
519 led_ctrl = er32(LEDCTL);
520 led_ctrl &= IGP_ACTIVITY_LED_MASK;
521 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
522 ew32(LEDCTL, led_ctrl);
525 /* Clear interrupt mask to stop board from generating interrupts */
526 DEBUGOUT("Masking off all interrupts\n");
527 ew32(IMC, 0xffffffff);
529 /* Clear any pending interrupt events. */
532 /* If MWI was previously enabled, reenable it. */
533 if (hw->mac_type == e1000_82542_rev2_0) {
534 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
535 e1000_pci_set_mwi(hw);
538 return E1000_SUCCESS;
541 /******************************************************************************
542 * Performs basic configuration of the adapter.
544 * hw - Struct containing variables accessed by shared code
546 * Assumes that the controller has previously been reset and is in a
547 * post-reset uninitialized state. Initializes the receive address registers,
548 * multicast table, and VLAN filter table. Calls routines to setup link
549 * configuration and flow control settings. Clears all on-chip counters. Leaves
550 * the transmit and receive units disabled and uninitialized.
551 *****************************************************************************/
552 s32 e1000_init_hw(struct e1000_hw *hw)
560 DEBUGFUNC("e1000_init_hw");
562 /* Initialize Identification LED */
563 ret_val = e1000_id_led_init(hw);
565 DEBUGOUT("Error Initializing Identification LED\n");
569 /* Set the media type and TBI compatibility */
570 e1000_set_media_type(hw);
572 /* Disabling VLAN filtering. */
573 DEBUGOUT("Initializing the IEEE VLAN\n");
574 if (hw->mac_type < e1000_82545_rev_3)
576 e1000_clear_vfta(hw);
578 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
579 if (hw->mac_type == e1000_82542_rev2_0) {
580 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
581 e1000_pci_clear_mwi(hw);
582 ew32(RCTL, E1000_RCTL_RST);
587 /* Setup the receive address. This involves initializing all of the Receive
588 * Address Registers (RARs 0 - 15).
590 e1000_init_rx_addrs(hw);
592 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
593 if (hw->mac_type == e1000_82542_rev2_0) {
597 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
598 e1000_pci_set_mwi(hw);
601 /* Zero out the Multicast HASH table */
602 DEBUGOUT("Zeroing the MTA\n");
603 mta_size = E1000_MC_TBL_SIZE;
604 for (i = 0; i < mta_size; i++) {
605 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
606 /* use write flush to prevent Memory Write Block (MWB) from
607 * occuring when accessing our register space */
611 /* Set the PCI priority bit correctly in the CTRL register. This
612 * determines if the adapter gives priority to receives, or if it
613 * gives equal priority to transmits and receives. Valid only on
614 * 82542 and 82543 silicon.
616 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
618 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
621 switch (hw->mac_type) {
622 case e1000_82545_rev_3:
623 case e1000_82546_rev_3:
626 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
627 if (hw->bus_type == e1000_bus_type_pcix && e1000_pcix_get_mmrbc(hw) > 2048)
628 e1000_pcix_set_mmrbc(hw, 2048);
632 /* Call a subroutine to configure the link and setup flow control. */
633 ret_val = e1000_setup_link(hw);
635 /* Set the transmit descriptor write-back policy */
636 if (hw->mac_type > e1000_82544) {
638 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
642 /* Clear all of the statistics registers (clear on read). It is
643 * important that we do this after we have tried to establish link
644 * because the symbol error count will increment wildly if there
647 e1000_clear_hw_cntrs(hw);
649 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
650 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
651 ctrl_ext = er32(CTRL_EXT);
652 /* Relaxed ordering must be disabled to avoid a parity
653 * error crash in a PCI slot. */
654 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
655 ew32(CTRL_EXT, ctrl_ext);
661 /******************************************************************************
662 * Adjust SERDES output amplitude based on EEPROM setting.
664 * hw - Struct containing variables accessed by shared code.
665 *****************************************************************************/
666 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
671 DEBUGFUNC("e1000_adjust_serdes_amplitude");
673 if (hw->media_type != e1000_media_type_internal_serdes)
674 return E1000_SUCCESS;
676 switch (hw->mac_type) {
677 case e1000_82545_rev_3:
678 case e1000_82546_rev_3:
681 return E1000_SUCCESS;
684 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
689 if (eeprom_data != EEPROM_RESERVED_WORD) {
690 /* Adjust SERDES output amplitude only. */
691 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
692 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
697 return E1000_SUCCESS;
700 /******************************************************************************
701 * Configures flow control and link settings.
703 * hw - Struct containing variables accessed by shared code
705 * Determines which flow control settings to use. Calls the apropriate media-
706 * specific link configuration function. Configures the flow control settings.
707 * Assuming the adapter has a valid link partner, a valid link should be
708 * established. Assumes the hardware has previously been reset and the
709 * transmitter and receiver are not enabled.
710 *****************************************************************************/
711 s32 e1000_setup_link(struct e1000_hw *hw)
717 DEBUGFUNC("e1000_setup_link");
719 /* Read and store word 0x0F of the EEPROM. This word contains bits
720 * that determine the hardware's default PAUSE (flow control) mode,
721 * a bit that determines whether the HW defaults to enabling or
722 * disabling auto-negotiation, and the direction of the
723 * SW defined pins. If there is no SW over-ride of the flow
724 * control setting, then the variable hw->fc will
725 * be initialized based on a value in the EEPROM.
727 if (hw->fc == E1000_FC_DEFAULT) {
728 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
731 DEBUGOUT("EEPROM Read Error\n");
732 return -E1000_ERR_EEPROM;
734 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
735 hw->fc = E1000_FC_NONE;
736 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
737 EEPROM_WORD0F_ASM_DIR)
738 hw->fc = E1000_FC_TX_PAUSE;
740 hw->fc = E1000_FC_FULL;
743 /* We want to save off the original Flow Control configuration just
744 * in case we get disconnected and then reconnected into a different
745 * hub or switch with different Flow Control capabilities.
747 if (hw->mac_type == e1000_82542_rev2_0)
748 hw->fc &= (~E1000_FC_TX_PAUSE);
750 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
751 hw->fc &= (~E1000_FC_RX_PAUSE);
753 hw->original_fc = hw->fc;
755 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
757 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
758 * polarity value for the SW controlled pins, and setup the
759 * Extended Device Control reg with that info.
760 * This is needed because one of the SW controlled pins is used for
761 * signal detection. So this should be done before e1000_setup_pcs_link()
762 * or e1000_phy_setup() is called.
764 if (hw->mac_type == e1000_82543) {
765 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
768 DEBUGOUT("EEPROM Read Error\n");
769 return -E1000_ERR_EEPROM;
771 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
773 ew32(CTRL_EXT, ctrl_ext);
776 /* Call the necessary subroutine to configure the link. */
777 ret_val = (hw->media_type == e1000_media_type_copper) ?
778 e1000_setup_copper_link(hw) :
779 e1000_setup_fiber_serdes_link(hw);
781 /* Initialize the flow control address, type, and PAUSE timer
782 * registers to their default values. This is done even if flow
783 * control is disabled, because it does not hurt anything to
784 * initialize these registers.
786 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
788 ew32(FCT, FLOW_CONTROL_TYPE);
789 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
790 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
792 ew32(FCTTV, hw->fc_pause_time);
794 /* Set the flow control receive threshold registers. Normally,
795 * these registers will be set to a default threshold that may be
796 * adjusted later by the driver's runtime code. However, if the
797 * ability to transmit pause frames in not enabled, then these
798 * registers will be set to 0.
800 if (!(hw->fc & E1000_FC_TX_PAUSE)) {
804 /* We need to set up the Receive Threshold high and low water marks
805 * as well as (optionally) enabling the transmission of XON frames.
807 if (hw->fc_send_xon) {
808 ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
809 ew32(FCRTH, hw->fc_high_water);
811 ew32(FCRTL, hw->fc_low_water);
812 ew32(FCRTH, hw->fc_high_water);
818 /******************************************************************************
819 * Sets up link for a fiber based or serdes based adapter
821 * hw - Struct containing variables accessed by shared code
823 * Manipulates Physical Coding Sublayer functions in order to configure
824 * link. Assumes the hardware has been previously reset and the transmitter
825 * and receiver are not enabled.
826 *****************************************************************************/
827 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
836 DEBUGFUNC("e1000_setup_fiber_serdes_link");
838 /* On adapters with a MAC newer than 82544, SWDP 1 will be
839 * set when the optics detect a signal. On older adapters, it will be
840 * cleared when there is a signal. This applies to fiber media only.
841 * If we're on serdes media, adjust the output amplitude to value
845 if (hw->media_type == e1000_media_type_fiber)
846 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
848 ret_val = e1000_adjust_serdes_amplitude(hw);
852 /* Take the link out of reset */
853 ctrl &= ~(E1000_CTRL_LRST);
855 /* Adjust VCO speed to improve BER performance */
856 ret_val = e1000_set_vco_speed(hw);
860 e1000_config_collision_dist(hw);
862 /* Check for a software override of the flow control settings, and setup
863 * the device accordingly. If auto-negotiation is enabled, then software
864 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
865 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
866 * auto-negotiation is disabled, then software will have to manually
867 * configure the two flow control enable bits in the CTRL register.
869 * The possible values of the "fc" parameter are:
870 * 0: Flow control is completely disabled
871 * 1: Rx flow control is enabled (we can receive pause frames, but
872 * not send pause frames).
873 * 2: Tx flow control is enabled (we can send pause frames but we do
874 * not support receiving pause frames).
875 * 3: Both Rx and TX flow control (symmetric) are enabled.
879 /* Flow control is completely disabled by a software over-ride. */
880 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
882 case E1000_FC_RX_PAUSE:
883 /* RX Flow control is enabled and TX Flow control is disabled by a
884 * software over-ride. Since there really isn't a way to advertise
885 * that we are capable of RX Pause ONLY, we will advertise that we
886 * support both symmetric and asymmetric RX PAUSE. Later, we will
887 * disable the adapter's ability to send PAUSE frames.
889 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
891 case E1000_FC_TX_PAUSE:
892 /* TX Flow control is enabled, and RX Flow control is disabled, by a
893 * software over-ride.
895 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
898 /* Flow control (both RX and TX) is enabled by a software over-ride. */
899 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
902 DEBUGOUT("Flow control param set incorrectly\n");
903 return -E1000_ERR_CONFIG;
907 /* Since auto-negotiation is enabled, take the link out of reset (the link
908 * will be in reset, because we previously reset the chip). This will
909 * restart auto-negotiation. If auto-neogtiation is successful then the
910 * link-up status bit will be set and the flow control enable bits (RFCE
911 * and TFCE) will be set according to their negotiated value.
913 DEBUGOUT("Auto-negotiation enabled\n");
922 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
923 * indication in the Device Status Register. Time-out if a link isn't
924 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
925 * less than 500 milliseconds even if the other end is doing it in SW).
926 * For internal serdes, we just assume a signal is present, then poll.
928 if (hw->media_type == e1000_media_type_internal_serdes ||
929 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
930 DEBUGOUT("Looking for Link\n");
931 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
933 status = er32(STATUS);
934 if (status & E1000_STATUS_LU) break;
936 if (i == (LINK_UP_TIMEOUT / 10)) {
937 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
938 hw->autoneg_failed = 1;
939 /* AutoNeg failed to achieve a link, so we'll call
940 * e1000_check_for_link. This routine will force the link up if
941 * we detect a signal. This will allow us to communicate with
942 * non-autonegotiating link partners.
944 ret_val = e1000_check_for_link(hw);
946 DEBUGOUT("Error while checking for link\n");
949 hw->autoneg_failed = 0;
951 hw->autoneg_failed = 0;
952 DEBUGOUT("Valid Link Found\n");
955 DEBUGOUT("No Signal Detected\n");
957 return E1000_SUCCESS;
960 /******************************************************************************
961 * Make sure we have a valid PHY and change PHY mode before link setup.
963 * hw - Struct containing variables accessed by shared code
964 ******************************************************************************/
965 static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
971 DEBUGFUNC("e1000_copper_link_preconfig");
974 /* With 82543, we need to force speed and duplex on the MAC equal to what
975 * the PHY speed and duplex configuration is. In addition, we need to
976 * perform a hardware reset on the PHY to take it out of reset.
978 if (hw->mac_type > e1000_82543) {
979 ctrl |= E1000_CTRL_SLU;
980 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
983 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
985 ret_val = e1000_phy_hw_reset(hw);
990 /* Make sure we have a valid PHY */
991 ret_val = e1000_detect_gig_phy(hw);
993 DEBUGOUT("Error, did not detect valid phy.\n");
996 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
998 /* Set PHY to class A mode (if necessary) */
999 ret_val = e1000_set_phy_mode(hw);
1003 if ((hw->mac_type == e1000_82545_rev_3) ||
1004 (hw->mac_type == e1000_82546_rev_3)) {
1005 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1006 phy_data |= 0x00000008;
1007 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1010 if (hw->mac_type <= e1000_82543 ||
1011 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1012 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1013 hw->phy_reset_disable = false;
1015 return E1000_SUCCESS;
1019 /********************************************************************
1020 * Copper link setup for e1000_phy_igp series.
1022 * hw - Struct containing variables accessed by shared code
1023 *********************************************************************/
1024 static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1030 DEBUGFUNC("e1000_copper_link_igp_setup");
1032 if (hw->phy_reset_disable)
1033 return E1000_SUCCESS;
1035 ret_val = e1000_phy_reset(hw);
1037 DEBUGOUT("Error Resetting the PHY\n");
1041 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1043 /* Configure activity LED after PHY reset */
1044 led_ctrl = er32(LEDCTL);
1045 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1046 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1047 ew32(LEDCTL, led_ctrl);
1049 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1050 if (hw->phy_type == e1000_phy_igp) {
1051 /* disable lplu d3 during driver init */
1052 ret_val = e1000_set_d3_lplu_state(hw, false);
1054 DEBUGOUT("Error Disabling LPLU D3\n");
1059 /* Configure mdi-mdix settings */
1060 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1064 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1065 hw->dsp_config_state = e1000_dsp_config_disabled;
1066 /* Force MDI for earlier revs of the IGP PHY */
1067 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1071 hw->dsp_config_state = e1000_dsp_config_enabled;
1072 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1076 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1079 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1083 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1087 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1091 /* set auto-master slave resolution settings */
1093 e1000_ms_type phy_ms_setting = hw->master_slave;
1095 if (hw->ffe_config_state == e1000_ffe_config_active)
1096 hw->ffe_config_state = e1000_ffe_config_enabled;
1098 if (hw->dsp_config_state == e1000_dsp_config_activated)
1099 hw->dsp_config_state = e1000_dsp_config_enabled;
1101 /* when autonegotiation advertisment is only 1000Mbps then we
1102 * should disable SmartSpeed and enable Auto MasterSlave
1103 * resolution as hardware default. */
1104 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1105 /* Disable SmartSpeed */
1106 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1110 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1111 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1115 /* Set auto Master/Slave resolution process */
1116 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1119 phy_data &= ~CR_1000T_MS_ENABLE;
1120 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1125 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1129 /* load defaults for future use */
1130 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1131 ((phy_data & CR_1000T_MS_VALUE) ?
1132 e1000_ms_force_master :
1133 e1000_ms_force_slave) :
1136 switch (phy_ms_setting) {
1137 case e1000_ms_force_master:
1138 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1140 case e1000_ms_force_slave:
1141 phy_data |= CR_1000T_MS_ENABLE;
1142 phy_data &= ~(CR_1000T_MS_VALUE);
1145 phy_data &= ~CR_1000T_MS_ENABLE;
1149 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1154 return E1000_SUCCESS;
1157 /********************************************************************
1158 * Copper link setup for e1000_phy_m88 series.
1160 * hw - Struct containing variables accessed by shared code
1161 *********************************************************************/
1162 static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1167 DEBUGFUNC("e1000_copper_link_mgp_setup");
1169 if (hw->phy_reset_disable)
1170 return E1000_SUCCESS;
1172 /* Enable CRS on TX. This must be set for half-duplex operation. */
1173 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1177 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1180 * MDI/MDI-X = 0 (default)
1181 * 0 - Auto for all speeds
1184 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1186 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1190 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1193 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1196 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1200 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1205 * disable_polarity_correction = 0 (default)
1206 * Automatic Correction for Reversed Cable Polarity
1210 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1211 if (hw->disable_polarity_correction == 1)
1212 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1213 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1217 if (hw->phy_revision < M88E1011_I_REV_4) {
1218 /* Force TX_CLK in the Extended PHY Specific Control Register
1221 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1225 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1227 if ((hw->phy_revision == E1000_REVISION_2) &&
1228 (hw->phy_id == M88E1111_I_PHY_ID)) {
1229 /* Vidalia Phy, set the downshift counter to 5x */
1230 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1231 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1232 ret_val = e1000_write_phy_reg(hw,
1233 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1237 /* Configure Master and Slave downshift values */
1238 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1239 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1240 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1241 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1242 ret_val = e1000_write_phy_reg(hw,
1243 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1249 /* SW Reset the PHY so all changes take effect */
1250 ret_val = e1000_phy_reset(hw);
1252 DEBUGOUT("Error Resetting the PHY\n");
1256 return E1000_SUCCESS;
1259 /********************************************************************
1260 * Setup auto-negotiation and flow control advertisements,
1261 * and then perform auto-negotiation.
1263 * hw - Struct containing variables accessed by shared code
1264 *********************************************************************/
1265 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1270 DEBUGFUNC("e1000_copper_link_autoneg");
1272 /* Perform some bounds checking on the hw->autoneg_advertised
1273 * parameter. If this variable is zero, then set it to the default.
1275 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1277 /* If autoneg_advertised is zero, we assume it was not defaulted
1278 * by the calling code so we set to advertise full capability.
1280 if (hw->autoneg_advertised == 0)
1281 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1283 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1284 ret_val = e1000_phy_setup_autoneg(hw);
1286 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1289 DEBUGOUT("Restarting Auto-Neg\n");
1291 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1292 * the Auto Neg Restart bit in the PHY control register.
1294 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1298 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1299 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1303 /* Does the user want to wait for Auto-Neg to complete here, or
1304 * check at a later time (for example, callback routine).
1306 if (hw->wait_autoneg_complete) {
1307 ret_val = e1000_wait_autoneg(hw);
1309 DEBUGOUT("Error while waiting for autoneg to complete\n");
1314 hw->get_link_status = true;
1316 return E1000_SUCCESS;
1319 /******************************************************************************
1320 * Config the MAC and the PHY after link is up.
1321 * 1) Set up the MAC to the current PHY speed/duplex
1322 * if we are on 82543. If we
1323 * are on newer silicon, we only need to configure
1324 * collision distance in the Transmit Control Register.
1325 * 2) Set up flow control on the MAC to that established with
1327 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1329 * hw - Struct containing variables accessed by shared code
1330 ******************************************************************************/
1331 static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
1334 DEBUGFUNC("e1000_copper_link_postconfig");
1336 if (hw->mac_type >= e1000_82544) {
1337 e1000_config_collision_dist(hw);
1339 ret_val = e1000_config_mac_to_phy(hw);
1341 DEBUGOUT("Error configuring MAC to PHY settings\n");
1345 ret_val = e1000_config_fc_after_link_up(hw);
1347 DEBUGOUT("Error Configuring Flow Control\n");
1351 /* Config DSP to improve Giga link quality */
1352 if (hw->phy_type == e1000_phy_igp) {
1353 ret_val = e1000_config_dsp_after_link_change(hw, true);
1355 DEBUGOUT("Error Configuring DSP after link up\n");
1360 return E1000_SUCCESS;
1363 /******************************************************************************
1364 * Detects which PHY is present and setup the speed and duplex
1366 * hw - Struct containing variables accessed by shared code
1367 ******************************************************************************/
1368 static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1374 DEBUGFUNC("e1000_setup_copper_link");
1376 /* Check if it is a valid PHY and set PHY mode if necessary. */
1377 ret_val = e1000_copper_link_preconfig(hw);
1381 if (hw->phy_type == e1000_phy_igp) {
1382 ret_val = e1000_copper_link_igp_setup(hw);
1385 } else if (hw->phy_type == e1000_phy_m88) {
1386 ret_val = e1000_copper_link_mgp_setup(hw);
1392 /* Setup autoneg and flow control advertisement
1393 * and perform autonegotiation */
1394 ret_val = e1000_copper_link_autoneg(hw);
1398 /* PHY will be set to 10H, 10F, 100H,or 100F
1399 * depending on value from forced_speed_duplex. */
1400 DEBUGOUT("Forcing speed and duplex\n");
1401 ret_val = e1000_phy_force_speed_duplex(hw);
1403 DEBUGOUT("Error Forcing Speed and Duplex\n");
1408 /* Check link status. Wait up to 100 microseconds for link to become
1411 for (i = 0; i < 10; i++) {
1412 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1415 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1419 if (phy_data & MII_SR_LINK_STATUS) {
1420 /* Config the MAC and PHY after link is up */
1421 ret_val = e1000_copper_link_postconfig(hw);
1425 DEBUGOUT("Valid link established!!!\n");
1426 return E1000_SUCCESS;
1431 DEBUGOUT("Unable to establish link!!!\n");
1432 return E1000_SUCCESS;
1435 /******************************************************************************
1436 * Configures PHY autoneg and flow control advertisement settings
1438 * hw - Struct containing variables accessed by shared code
1439 ******************************************************************************/
1440 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1443 u16 mii_autoneg_adv_reg;
1444 u16 mii_1000t_ctrl_reg;
1446 DEBUGFUNC("e1000_phy_setup_autoneg");
1448 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1449 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1453 /* Read the MII 1000Base-T Control Register (Address 9). */
1454 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1458 /* Need to parse both autoneg_advertised and fc and set up
1459 * the appropriate PHY registers. First we will parse for
1460 * autoneg_advertised software override. Since we can advertise
1461 * a plethora of combinations, we need to check each bit
1465 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1466 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1467 * the 1000Base-T Control Register (Address 9).
1469 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1470 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1472 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1474 /* Do we want to advertise 10 Mb Half Duplex? */
1475 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1476 DEBUGOUT("Advertise 10mb Half duplex\n");
1477 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1480 /* Do we want to advertise 10 Mb Full Duplex? */
1481 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1482 DEBUGOUT("Advertise 10mb Full duplex\n");
1483 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1486 /* Do we want to advertise 100 Mb Half Duplex? */
1487 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1488 DEBUGOUT("Advertise 100mb Half duplex\n");
1489 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1492 /* Do we want to advertise 100 Mb Full Duplex? */
1493 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1494 DEBUGOUT("Advertise 100mb Full duplex\n");
1495 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1498 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1499 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1500 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1503 /* Do we want to advertise 1000 Mb Full Duplex? */
1504 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1505 DEBUGOUT("Advertise 1000mb Full duplex\n");
1506 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1509 /* Check for a software override of the flow control settings, and
1510 * setup the PHY advertisement registers accordingly. If
1511 * auto-negotiation is enabled, then software will have to set the
1512 * "PAUSE" bits to the correct value in the Auto-Negotiation
1513 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1515 * The possible values of the "fc" parameter are:
1516 * 0: Flow control is completely disabled
1517 * 1: Rx flow control is enabled (we can receive pause frames
1518 * but not send pause frames).
1519 * 2: Tx flow control is enabled (we can send pause frames
1520 * but we do not support receiving pause frames).
1521 * 3: Both Rx and TX flow control (symmetric) are enabled.
1522 * other: No software override. The flow control configuration
1523 * in the EEPROM is used.
1526 case E1000_FC_NONE: /* 0 */
1527 /* Flow control (RX & TX) is completely disabled by a
1528 * software over-ride.
1530 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1532 case E1000_FC_RX_PAUSE: /* 1 */
1533 /* RX Flow control is enabled, and TX Flow control is
1534 * disabled, by a software over-ride.
1536 /* Since there really isn't a way to advertise that we are
1537 * capable of RX Pause ONLY, we will advertise that we
1538 * support both symmetric and asymmetric RX PAUSE. Later
1539 * (in e1000_config_fc_after_link_up) we will disable the
1540 *hw's ability to send PAUSE frames.
1542 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1544 case E1000_FC_TX_PAUSE: /* 2 */
1545 /* TX Flow control is enabled, and RX Flow control is
1546 * disabled, by a software over-ride.
1548 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1549 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1551 case E1000_FC_FULL: /* 3 */
1552 /* Flow control (both RX and TX) is enabled by a software
1555 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1558 DEBUGOUT("Flow control param set incorrectly\n");
1559 return -E1000_ERR_CONFIG;
1562 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1566 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1568 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1572 return E1000_SUCCESS;
1575 /******************************************************************************
1576 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1578 * hw - Struct containing variables accessed by shared code
1579 ******************************************************************************/
1580 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1589 DEBUGFUNC("e1000_phy_force_speed_duplex");
1591 /* Turn off Flow control if we are forcing speed and duplex. */
1592 hw->fc = E1000_FC_NONE;
1594 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1596 /* Read the Device Control Register. */
1599 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1600 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1601 ctrl &= ~(DEVICE_SPEED_MASK);
1603 /* Clear the Auto Speed Detect Enable bit. */
1604 ctrl &= ~E1000_CTRL_ASDE;
1606 /* Read the MII Control Register. */
1607 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1611 /* We need to disable autoneg in order to force link and duplex. */
1613 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1615 /* Are we forcing Full or Half Duplex? */
1616 if (hw->forced_speed_duplex == e1000_100_full ||
1617 hw->forced_speed_duplex == e1000_10_full) {
1618 /* We want to force full duplex so we SET the full duplex bits in the
1619 * Device and MII Control Registers.
1621 ctrl |= E1000_CTRL_FD;
1622 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1623 DEBUGOUT("Full Duplex\n");
1625 /* We want to force half duplex so we CLEAR the full duplex bits in
1626 * the Device and MII Control Registers.
1628 ctrl &= ~E1000_CTRL_FD;
1629 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1630 DEBUGOUT("Half Duplex\n");
1633 /* Are we forcing 100Mbps??? */
1634 if (hw->forced_speed_duplex == e1000_100_full ||
1635 hw->forced_speed_duplex == e1000_100_half) {
1636 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1637 ctrl |= E1000_CTRL_SPD_100;
1638 mii_ctrl_reg |= MII_CR_SPEED_100;
1639 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1640 DEBUGOUT("Forcing 100mb ");
1642 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1643 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1644 mii_ctrl_reg |= MII_CR_SPEED_10;
1645 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1646 DEBUGOUT("Forcing 10mb ");
1649 e1000_config_collision_dist(hw);
1651 /* Write the configured values back to the Device Control Reg. */
1654 if (hw->phy_type == e1000_phy_m88) {
1655 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1659 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1660 * forced whenever speed are duplex are forced.
1662 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1663 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1667 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1669 /* Need to reset the PHY or these changes will be ignored */
1670 mii_ctrl_reg |= MII_CR_RESET;
1673 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1674 * forced whenever speed or duplex are forced.
1676 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1680 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1681 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1683 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1688 /* Write back the modified PHY MII control register. */
1689 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1695 /* The wait_autoneg_complete flag may be a little misleading here.
1696 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1697 * But we do want to delay for a period while forcing only so we
1698 * don't generate false No Link messages. So we will wait here
1699 * only if the user has set wait_autoneg_complete to 1, which is
1702 if (hw->wait_autoneg_complete) {
1703 /* We will wait for autoneg to complete. */
1704 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1707 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1708 for (i = PHY_FORCE_TIME; i > 0; i--) {
1709 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1712 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1716 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1720 if (mii_status_reg & MII_SR_LINK_STATUS) break;
1724 (hw->phy_type == e1000_phy_m88)) {
1725 /* We didn't get link. Reset the DSP and wait again for link. */
1726 ret_val = e1000_phy_reset_dsp(hw);
1728 DEBUGOUT("Error Resetting PHY DSP\n");
1732 /* This loop will early-out if the link condition has been met. */
1733 for (i = PHY_FORCE_TIME; i > 0; i--) {
1734 if (mii_status_reg & MII_SR_LINK_STATUS) break;
1736 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1739 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1743 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1749 if (hw->phy_type == e1000_phy_m88) {
1750 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1751 * Extended PHY Specific Control Register to 25MHz clock. This value
1752 * defaults back to a 2.5MHz clock when the PHY is reset.
1754 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1758 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1759 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1763 /* In addition, because of the s/w reset above, we need to enable CRS on
1764 * TX. This must be set for both full and half duplex operation.
1766 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1770 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1771 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1775 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1776 (!hw->autoneg) && (hw->forced_speed_duplex == e1000_10_full ||
1777 hw->forced_speed_duplex == e1000_10_half)) {
1778 ret_val = e1000_polarity_reversal_workaround(hw);
1783 return E1000_SUCCESS;
1786 /******************************************************************************
1787 * Sets the collision distance in the Transmit Control register
1789 * hw - Struct containing variables accessed by shared code
1791 * Link should have been established previously. Reads the speed and duplex
1792 * information from the Device Status register.
1793 ******************************************************************************/
1794 void e1000_config_collision_dist(struct e1000_hw *hw)
1796 u32 tctl, coll_dist;
1798 DEBUGFUNC("e1000_config_collision_dist");
1800 if (hw->mac_type < e1000_82543)
1801 coll_dist = E1000_COLLISION_DISTANCE_82542;
1803 coll_dist = E1000_COLLISION_DISTANCE;
1807 tctl &= ~E1000_TCTL_COLD;
1808 tctl |= coll_dist << E1000_COLD_SHIFT;
1811 E1000_WRITE_FLUSH();
1814 /******************************************************************************
1815 * Sets MAC speed and duplex settings to reflect the those in the PHY
1817 * hw - Struct containing variables accessed by shared code
1818 * mii_reg - data to write to the MII control register
1820 * The contents of the PHY register containing the needed information need to
1822 ******************************************************************************/
1823 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
1829 DEBUGFUNC("e1000_config_mac_to_phy");
1831 /* 82544 or newer MAC, Auto Speed Detection takes care of
1832 * MAC speed/duplex configuration.*/
1833 if (hw->mac_type >= e1000_82544)
1834 return E1000_SUCCESS;
1836 /* Read the Device Control Register and set the bits to Force Speed
1840 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1841 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1843 /* Set up duplex in the Device Control and Transmit Control
1844 * registers depending on negotiated values.
1846 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1850 if (phy_data & M88E1000_PSSR_DPLX)
1851 ctrl |= E1000_CTRL_FD;
1853 ctrl &= ~E1000_CTRL_FD;
1855 e1000_config_collision_dist(hw);
1857 /* Set up speed in the Device Control register depending on
1858 * negotiated values.
1860 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1861 ctrl |= E1000_CTRL_SPD_1000;
1862 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1863 ctrl |= E1000_CTRL_SPD_100;
1865 /* Write the configured values back to the Device Control Reg. */
1867 return E1000_SUCCESS;
1870 /******************************************************************************
1871 * Forces the MAC's flow control settings.
1873 * hw - Struct containing variables accessed by shared code
1875 * Sets the TFCE and RFCE bits in the device control register to reflect
1876 * the adapter settings. TFCE and RFCE need to be explicitly set by
1877 * software when a Copper PHY is used because autonegotiation is managed
1878 * by the PHY rather than the MAC. Software must also configure these
1879 * bits when link is forced on a fiber connection.
1880 *****************************************************************************/
1881 s32 e1000_force_mac_fc(struct e1000_hw *hw)
1885 DEBUGFUNC("e1000_force_mac_fc");
1887 /* Get the current configuration of the Device Control Register */
1890 /* Because we didn't get link via the internal auto-negotiation
1891 * mechanism (we either forced link or we got link via PHY
1892 * auto-neg), we have to manually enable/disable transmit an
1893 * receive flow control.
1895 * The "Case" statement below enables/disable flow control
1896 * according to the "hw->fc" parameter.
1898 * The possible values of the "fc" parameter are:
1899 * 0: Flow control is completely disabled
1900 * 1: Rx flow control is enabled (we can receive pause
1901 * frames but not send pause frames).
1902 * 2: Tx flow control is enabled (we can send pause frames
1903 * frames but we do not receive pause frames).
1904 * 3: Both Rx and TX flow control (symmetric) is enabled.
1905 * other: No other values should be possible at this point.
1910 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1912 case E1000_FC_RX_PAUSE:
1913 ctrl &= (~E1000_CTRL_TFCE);
1914 ctrl |= E1000_CTRL_RFCE;
1916 case E1000_FC_TX_PAUSE:
1917 ctrl &= (~E1000_CTRL_RFCE);
1918 ctrl |= E1000_CTRL_TFCE;
1921 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1924 DEBUGOUT("Flow control param set incorrectly\n");
1925 return -E1000_ERR_CONFIG;
1928 /* Disable TX Flow Control for 82542 (rev 2.0) */
1929 if (hw->mac_type == e1000_82542_rev2_0)
1930 ctrl &= (~E1000_CTRL_TFCE);
1933 return E1000_SUCCESS;
1936 /******************************************************************************
1937 * Configures flow control settings after link is established
1939 * hw - Struct containing variables accessed by shared code
1941 * Should be called immediately after a valid link has been established.
1942 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1943 * and autonegotiation is enabled, the MAC flow control settings will be set
1944 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1945 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1946 *****************************************************************************/
1947 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1951 u16 mii_nway_adv_reg;
1952 u16 mii_nway_lp_ability_reg;
1956 DEBUGFUNC("e1000_config_fc_after_link_up");
1958 /* Check for the case where we have fiber media and auto-neg failed
1959 * so we had to force link. In this case, we need to force the
1960 * configuration of the MAC to match the "fc" parameter.
1962 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1963 ((hw->media_type == e1000_media_type_internal_serdes) &&
1964 (hw->autoneg_failed)) ||
1965 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1966 ret_val = e1000_force_mac_fc(hw);
1968 DEBUGOUT("Error forcing flow control settings\n");
1973 /* Check for the case where we have copper media and auto-neg is
1974 * enabled. In this case, we need to check and see if Auto-Neg
1975 * has completed, and if so, how the PHY and link partner has
1976 * flow control configured.
1978 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1979 /* Read the MII Status Register and check to see if AutoNeg
1980 * has completed. We read this twice because this reg has
1981 * some "sticky" (latched) bits.
1983 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1986 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1990 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1991 /* The AutoNeg process has completed, so we now need to
1992 * read both the Auto Negotiation Advertisement Register
1993 * (Address 4) and the Auto_Negotiation Base Page Ability
1994 * Register (Address 5) to determine how flow control was
1997 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2001 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2002 &mii_nway_lp_ability_reg);
2006 /* Two bits in the Auto Negotiation Advertisement Register
2007 * (Address 4) and two bits in the Auto Negotiation Base
2008 * Page Ability Register (Address 5) determine flow control
2009 * for both the PHY and the link partner. The following
2010 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2011 * 1999, describes these PAUSE resolution bits and how flow
2012 * control is determined based upon these settings.
2013 * NOTE: DC = Don't Care
2015 * LOCAL DEVICE | LINK PARTNER
2016 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2017 *-------|---------|-------|---------|--------------------
2018 * 0 | 0 | DC | DC | E1000_FC_NONE
2019 * 0 | 1 | 0 | DC | E1000_FC_NONE
2020 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2021 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2022 * 1 | 0 | 0 | DC | E1000_FC_NONE
2023 * 1 | DC | 1 | DC | E1000_FC_FULL
2024 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2025 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2028 /* Are both PAUSE bits set to 1? If so, this implies
2029 * Symmetric Flow Control is enabled at both ends. The
2030 * ASM_DIR bits are irrelevant per the spec.
2032 * For Symmetric Flow Control:
2034 * LOCAL DEVICE | LINK PARTNER
2035 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2036 *-------|---------|-------|---------|--------------------
2037 * 1 | DC | 1 | DC | E1000_FC_FULL
2040 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2041 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2042 /* Now we need to check if the user selected RX ONLY
2043 * of pause frames. In this case, we had to advertise
2044 * FULL flow control because we could not advertise RX
2045 * ONLY. Hence, we must now check to see if we need to
2046 * turn OFF the TRANSMISSION of PAUSE frames.
2048 if (hw->original_fc == E1000_FC_FULL) {
2049 hw->fc = E1000_FC_FULL;
2050 DEBUGOUT("Flow Control = FULL.\n");
2052 hw->fc = E1000_FC_RX_PAUSE;
2053 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2056 /* For receiving PAUSE frames ONLY.
2058 * LOCAL DEVICE | LINK PARTNER
2059 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2060 *-------|---------|-------|---------|--------------------
2061 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2064 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2065 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2066 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2067 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2068 hw->fc = E1000_FC_TX_PAUSE;
2069 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2071 /* For transmitting PAUSE frames ONLY.
2073 * LOCAL DEVICE | LINK PARTNER
2074 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2075 *-------|---------|-------|---------|--------------------
2076 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2079 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2080 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2081 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2082 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2083 hw->fc = E1000_FC_RX_PAUSE;
2084 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2086 /* Per the IEEE spec, at this point flow control should be
2087 * disabled. However, we want to consider that we could
2088 * be connected to a legacy switch that doesn't advertise
2089 * desired flow control, but can be forced on the link
2090 * partner. So if we advertised no flow control, that is
2091 * what we will resolve to. If we advertised some kind of
2092 * receive capability (Rx Pause Only or Full Flow Control)
2093 * and the link partner advertised none, we will configure
2094 * ourselves to enable Rx Flow Control only. We can do
2095 * this safely for two reasons: If the link partner really
2096 * didn't want flow control enabled, and we enable Rx, no
2097 * harm done since we won't be receiving any PAUSE frames
2098 * anyway. If the intent on the link partner was to have
2099 * flow control enabled, then by us enabling RX only, we
2100 * can at least receive pause frames and process them.
2101 * This is a good idea because in most cases, since we are
2102 * predominantly a server NIC, more times than not we will
2103 * be asked to delay transmission of packets than asking
2104 * our link partner to pause transmission of frames.
2106 else if ((hw->original_fc == E1000_FC_NONE ||
2107 hw->original_fc == E1000_FC_TX_PAUSE) ||
2108 hw->fc_strict_ieee) {
2109 hw->fc = E1000_FC_NONE;
2110 DEBUGOUT("Flow Control = NONE.\n");
2112 hw->fc = E1000_FC_RX_PAUSE;
2113 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2116 /* Now we need to do one last check... If we auto-
2117 * negotiated to HALF DUPLEX, flow control should not be
2118 * enabled per IEEE 802.3 spec.
2120 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2122 DEBUGOUT("Error getting link speed and duplex\n");
2126 if (duplex == HALF_DUPLEX)
2127 hw->fc = E1000_FC_NONE;
2129 /* Now we call a subroutine to actually force the MAC
2130 * controller to use the correct flow control settings.
2132 ret_val = e1000_force_mac_fc(hw);
2134 DEBUGOUT("Error forcing flow control settings\n");
2138 DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
2141 return E1000_SUCCESS;
2144 /******************************************************************************
2145 * Checks to see if the link status of the hardware has changed.
2147 * hw - Struct containing variables accessed by shared code
2149 * Called by any function that needs to check the link status of the adapter.
2150 *****************************************************************************/
2151 s32 e1000_check_for_link(struct e1000_hw *hw)
2162 DEBUGFUNC("e1000_check_for_link");
2165 status = er32(STATUS);
2167 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2168 * set when the optics detect a signal. On older adapters, it will be
2169 * cleared when there is a signal. This applies to fiber media only.
2171 if ((hw->media_type == e1000_media_type_fiber) ||
2172 (hw->media_type == e1000_media_type_internal_serdes)) {
2175 if (hw->media_type == e1000_media_type_fiber) {
2176 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2177 if (status & E1000_STATUS_LU)
2178 hw->get_link_status = false;
2182 /* If we have a copper PHY then we only want to go out to the PHY
2183 * registers to see if Auto-Neg has completed and/or if our link
2184 * status has changed. The get_link_status flag will be set if we
2185 * receive a Link Status Change interrupt or we have Rx Sequence
2188 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2189 /* First we want to see if the MII Status Register reports
2190 * link. If so, then we want to get the current speed/duplex
2192 * Read the register twice since the link bit is sticky.
2194 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2197 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2201 if (phy_data & MII_SR_LINK_STATUS) {
2202 hw->get_link_status = false;
2203 /* Check if there was DownShift, must be checked immediately after
2205 e1000_check_downshift(hw);
2207 /* If we are on 82544 or 82543 silicon and speed/duplex
2208 * are forced to 10H or 10F, then we will implement the polarity
2209 * reversal workaround. We disable interrupts first, and upon
2210 * returning, place the devices interrupt state to its previous
2211 * value except for the link status change interrupt which will
2212 * happen due to the execution of this workaround.
2215 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2217 (hw->forced_speed_duplex == e1000_10_full ||
2218 hw->forced_speed_duplex == e1000_10_half)) {
2219 ew32(IMC, 0xffffffff);
2220 ret_val = e1000_polarity_reversal_workaround(hw);
2222 ew32(ICS, (icr & ~E1000_ICS_LSC));
2223 ew32(IMS, IMS_ENABLE_MASK);
2227 /* No link detected */
2228 e1000_config_dsp_after_link_change(hw, false);
2232 /* If we are forcing speed/duplex, then we simply return since
2233 * we have already determined whether we have link or not.
2235 if (!hw->autoneg) return -E1000_ERR_CONFIG;
2237 /* optimize the dsp settings for the igp phy */
2238 e1000_config_dsp_after_link_change(hw, true);
2240 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2241 * have Si on board that is 82544 or newer, Auto
2242 * Speed Detection takes care of MAC speed/duplex
2243 * configuration. So we only need to configure Collision
2244 * Distance in the MAC. Otherwise, we need to force
2245 * speed/duplex on the MAC to the current PHY speed/duplex
2248 if (hw->mac_type >= e1000_82544)
2249 e1000_config_collision_dist(hw);
2251 ret_val = e1000_config_mac_to_phy(hw);
2253 DEBUGOUT("Error configuring MAC to PHY settings\n");
2258 /* Configure Flow Control now that Auto-Neg has completed. First, we
2259 * need to restore the desired flow control settings because we may
2260 * have had to re-autoneg with a different link partner.
2262 ret_val = e1000_config_fc_after_link_up(hw);
2264 DEBUGOUT("Error configuring flow control\n");
2268 /* At this point we know that we are on copper and we have
2269 * auto-negotiated link. These are conditions for checking the link
2270 * partner capability register. We use the link speed to determine if
2271 * TBI compatibility needs to be turned on or off. If the link is not
2272 * at gigabit speed, then TBI compatibility is not needed. If we are
2273 * at gigabit speed, we turn on TBI compatibility.
2275 if (hw->tbi_compatibility_en) {
2277 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2279 DEBUGOUT("Error getting link speed and duplex\n");
2282 if (speed != SPEED_1000) {
2283 /* If link speed is not set to gigabit speed, we do not need
2284 * to enable TBI compatibility.
2286 if (hw->tbi_compatibility_on) {
2287 /* If we previously were in the mode, turn it off. */
2289 rctl &= ~E1000_RCTL_SBP;
2291 hw->tbi_compatibility_on = false;
2294 /* If TBI compatibility is was previously off, turn it on. For
2295 * compatibility with a TBI link partner, we will store bad
2296 * packets. Some frames have an additional byte on the end and
2297 * will look like CRC errors to the hardware.
2299 if (!hw->tbi_compatibility_on) {
2300 hw->tbi_compatibility_on = true;
2302 rctl |= E1000_RCTL_SBP;
2308 /* If we don't have link (auto-negotiation failed or link partner cannot
2309 * auto-negotiate), the cable is plugged in (we have signal), and our
2310 * link partner is not trying to auto-negotiate with us (we are receiving
2311 * idles or data), we need to force link up. We also need to give
2312 * auto-negotiation time to complete, in case the cable was just plugged
2313 * in. The autoneg_failed flag does this.
2315 else if ((((hw->media_type == e1000_media_type_fiber) &&
2316 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2317 (hw->media_type == e1000_media_type_internal_serdes)) &&
2318 (!(status & E1000_STATUS_LU)) &&
2319 (!(rxcw & E1000_RXCW_C))) {
2320 if (hw->autoneg_failed == 0) {
2321 hw->autoneg_failed = 1;
2324 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2326 /* Disable auto-negotiation in the TXCW register */
2327 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2329 /* Force link-up and also force full-duplex. */
2331 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2334 /* Configure Flow Control after forcing link up. */
2335 ret_val = e1000_config_fc_after_link_up(hw);
2337 DEBUGOUT("Error configuring flow control\n");
2341 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2342 * auto-negotiation in the TXCW register and disable forced link in the
2343 * Device Control register in an attempt to auto-negotiate with our link
2346 else if (((hw->media_type == e1000_media_type_fiber) ||
2347 (hw->media_type == e1000_media_type_internal_serdes)) &&
2348 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2349 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2350 ew32(TXCW, hw->txcw);
2351 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2353 hw->serdes_link_down = false;
2355 /* If we force link for non-auto-negotiation switch, check link status
2356 * based on MAC synchronization for internal serdes media type.
2358 else if ((hw->media_type == e1000_media_type_internal_serdes) &&
2359 !(E1000_TXCW_ANE & er32(TXCW))) {
2360 /* SYNCH bit and IV bit are sticky. */
2362 if (E1000_RXCW_SYNCH & er32(RXCW)) {
2363 if (!(rxcw & E1000_RXCW_IV)) {
2364 hw->serdes_link_down = false;
2365 DEBUGOUT("SERDES: Link is up.\n");
2368 hw->serdes_link_down = true;
2369 DEBUGOUT("SERDES: Link is down.\n");
2372 if ((hw->media_type == e1000_media_type_internal_serdes) &&
2373 (E1000_TXCW_ANE & er32(TXCW))) {
2374 hw->serdes_link_down = !(E1000_STATUS_LU & er32(STATUS));
2376 return E1000_SUCCESS;
2379 /******************************************************************************
2380 * Detects the current speed and duplex settings of the hardware.
2382 * hw - Struct containing variables accessed by shared code
2383 * speed - Speed of the connection
2384 * duplex - Duplex setting of the connection
2385 *****************************************************************************/
2386 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
2392 DEBUGFUNC("e1000_get_speed_and_duplex");
2394 if (hw->mac_type >= e1000_82543) {
2395 status = er32(STATUS);
2396 if (status & E1000_STATUS_SPEED_1000) {
2397 *speed = SPEED_1000;
2398 DEBUGOUT("1000 Mbs, ");
2399 } else if (status & E1000_STATUS_SPEED_100) {
2401 DEBUGOUT("100 Mbs, ");
2404 DEBUGOUT("10 Mbs, ");
2407 if (status & E1000_STATUS_FD) {
2408 *duplex = FULL_DUPLEX;
2409 DEBUGOUT("Full Duplex\n");
2411 *duplex = HALF_DUPLEX;
2412 DEBUGOUT(" Half Duplex\n");
2415 DEBUGOUT("1000 Mbs, Full Duplex\n");
2416 *speed = SPEED_1000;
2417 *duplex = FULL_DUPLEX;
2420 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2421 * if it is operating at half duplex. Here we set the duplex settings to
2422 * match the duplex in the link partner's capabilities.
2424 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2425 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2429 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2430 *duplex = HALF_DUPLEX;
2432 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2435 if ((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2436 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2437 *duplex = HALF_DUPLEX;
2441 return E1000_SUCCESS;
2444 /******************************************************************************
2445 * Blocks until autoneg completes or times out (~4.5 seconds)
2447 * hw - Struct containing variables accessed by shared code
2448 ******************************************************************************/
2449 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
2455 DEBUGFUNC("e1000_wait_autoneg");
2456 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2458 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2459 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2460 /* Read the MII Status Register and wait for Auto-Neg
2461 * Complete bit to be set.
2463 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2466 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2469 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2470 return E1000_SUCCESS;
2474 return E1000_SUCCESS;
2477 /******************************************************************************
2478 * Raises the Management Data Clock
2480 * hw - Struct containing variables accessed by shared code
2481 * ctrl - Device control register's current value
2482 ******************************************************************************/
2483 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2485 /* Raise the clock input to the Management Data Clock (by setting the MDC
2486 * bit), and then delay 10 microseconds.
2488 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2489 E1000_WRITE_FLUSH();
2493 /******************************************************************************
2494 * Lowers the Management Data Clock
2496 * hw - Struct containing variables accessed by shared code
2497 * ctrl - Device control register's current value
2498 ******************************************************************************/
2499 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2501 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2502 * bit), and then delay 10 microseconds.
2504 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2505 E1000_WRITE_FLUSH();
2509 /******************************************************************************
2510 * Shifts data bits out to the PHY
2512 * hw - Struct containing variables accessed by shared code
2513 * data - Data to send out to the PHY
2514 * count - Number of bits to shift out
2516 * Bits are shifted out in MSB to LSB order.
2517 ******************************************************************************/
2518 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
2523 /* We need to shift "count" number of bits out to the PHY. So, the value
2524 * in the "data" parameter will be shifted out to the PHY one bit at a
2525 * time. In order to do this, "data" must be broken down into bits.
2528 mask <<= (count - 1);
2532 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2533 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2536 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2537 * then raising and lowering the Management Data Clock. A "0" is
2538 * shifted out to the PHY by setting the MDIO bit to "0" and then
2539 * raising and lowering the clock.
2542 ctrl |= E1000_CTRL_MDIO;
2544 ctrl &= ~E1000_CTRL_MDIO;
2547 E1000_WRITE_FLUSH();
2551 e1000_raise_mdi_clk(hw, &ctrl);
2552 e1000_lower_mdi_clk(hw, &ctrl);
2558 /******************************************************************************
2559 * Shifts data bits in from the PHY
2561 * hw - Struct containing variables accessed by shared code
2563 * Bits are shifted in in MSB to LSB order.
2564 ******************************************************************************/
2565 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2571 /* In order to read a register from the PHY, we need to shift in a total
2572 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2573 * to avoid contention on the MDIO pin when a read operation is performed.
2574 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2575 * by raising the input to the Management Data Clock (setting the MDC bit),
2576 * and then reading the value of the MDIO bit.
2580 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2581 ctrl &= ~E1000_CTRL_MDIO_DIR;
2582 ctrl &= ~E1000_CTRL_MDIO;
2585 E1000_WRITE_FLUSH();
2587 /* Raise and Lower the clock before reading in the data. This accounts for
2588 * the turnaround bits. The first clock occurred when we clocked out the
2589 * last bit of the Register Address.
2591 e1000_raise_mdi_clk(hw, &ctrl);
2592 e1000_lower_mdi_clk(hw, &ctrl);
2594 for (data = 0, i = 0; i < 16; i++) {
2596 e1000_raise_mdi_clk(hw, &ctrl);
2598 /* Check to see if we shifted in a "1". */
2599 if (ctrl & E1000_CTRL_MDIO)
2601 e1000_lower_mdi_clk(hw, &ctrl);
2604 e1000_raise_mdi_clk(hw, &ctrl);
2605 e1000_lower_mdi_clk(hw, &ctrl);
2610 static s32 e1000_swfw_sync_acquire(struct e1000_hw *hw, u16 mask)
2614 u32 fwmask = mask << 16;
2617 DEBUGFUNC("e1000_swfw_sync_acquire");
2619 if (!hw->swfw_sync_present)
2620 return e1000_get_hw_eeprom_semaphore(hw);
2623 if (e1000_get_hw_eeprom_semaphore(hw))
2624 return -E1000_ERR_SWFW_SYNC;
2626 swfw_sync = er32(SW_FW_SYNC);
2627 if (!(swfw_sync & (fwmask | swmask))) {
2631 /* firmware currently using resource (fwmask) */
2632 /* or other software thread currently using resource (swmask) */
2633 e1000_put_hw_eeprom_semaphore(hw);
2639 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
2640 return -E1000_ERR_SWFW_SYNC;
2643 swfw_sync |= swmask;
2644 ew32(SW_FW_SYNC, swfw_sync);
2646 e1000_put_hw_eeprom_semaphore(hw);
2647 return E1000_SUCCESS;
2650 static void e1000_swfw_sync_release(struct e1000_hw *hw, u16 mask)
2655 DEBUGFUNC("e1000_swfw_sync_release");
2657 if (!hw->swfw_sync_present) {
2658 e1000_put_hw_eeprom_semaphore(hw);
2662 /* if (e1000_get_hw_eeprom_semaphore(hw))
2663 * return -E1000_ERR_SWFW_SYNC; */
2664 while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
2667 swfw_sync = er32(SW_FW_SYNC);
2668 swfw_sync &= ~swmask;
2669 ew32(SW_FW_SYNC, swfw_sync);
2671 e1000_put_hw_eeprom_semaphore(hw);
2674 /*****************************************************************************
2675 * Reads the value from a PHY register, if the value is on a specific non zero
2676 * page, sets the page first.
2677 * hw - Struct containing variables accessed by shared code
2678 * reg_addr - address of the PHY register to read
2679 ******************************************************************************/
2680 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
2685 DEBUGFUNC("e1000_read_phy_reg");
2687 swfw = E1000_SWFW_PHY0_SM;
2688 if (e1000_swfw_sync_acquire(hw, swfw))
2689 return -E1000_ERR_SWFW_SYNC;
2691 if ((hw->phy_type == e1000_phy_igp) &&
2692 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2693 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2696 e1000_swfw_sync_release(hw, swfw);
2701 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2704 e1000_swfw_sync_release(hw, swfw);
2708 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2713 const u32 phy_addr = 1;
2715 DEBUGFUNC("e1000_read_phy_reg_ex");
2717 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2718 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2719 return -E1000_ERR_PARAM;
2722 if (hw->mac_type > e1000_82543) {
2723 /* Set up Op-code, Phy Address, and register address in the MDI
2724 * Control register. The MAC will take care of interfacing with the
2725 * PHY to retrieve the desired data.
2727 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2728 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2729 (E1000_MDIC_OP_READ));
2733 /* Poll the ready bit to see if the MDI read completed */
2734 for (i = 0; i < 64; i++) {
2737 if (mdic & E1000_MDIC_READY) break;
2739 if (!(mdic & E1000_MDIC_READY)) {
2740 DEBUGOUT("MDI Read did not complete\n");
2741 return -E1000_ERR_PHY;
2743 if (mdic & E1000_MDIC_ERROR) {
2744 DEBUGOUT("MDI Error\n");
2745 return -E1000_ERR_PHY;
2747 *phy_data = (u16)mdic;
2749 /* We must first send a preamble through the MDIO pin to signal the
2750 * beginning of an MII instruction. This is done by sending 32
2751 * consecutive "1" bits.
2753 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2755 /* Now combine the next few fields that are required for a read
2756 * operation. We use this method instead of calling the
2757 * e1000_shift_out_mdi_bits routine five different times. The format of
2758 * a MII read instruction consists of a shift out of 14 bits and is
2759 * defined as follows:
2760 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2761 * followed by a shift in of 18 bits. This first two bits shifted in
2762 * are TurnAround bits used to avoid contention on the MDIO pin when a
2763 * READ operation is performed. These two bits are thrown away
2764 * followed by a shift in of 16 bits which contains the desired data.
2766 mdic = ((reg_addr) | (phy_addr << 5) |
2767 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2769 e1000_shift_out_mdi_bits(hw, mdic, 14);
2771 /* Now that we've shifted out the read command to the MII, we need to
2772 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2775 *phy_data = e1000_shift_in_mdi_bits(hw);
2777 return E1000_SUCCESS;
2780 /******************************************************************************
2781 * Writes a value to a PHY register
2783 * hw - Struct containing variables accessed by shared code
2784 * reg_addr - address of the PHY register to write
2785 * data - data to write to the PHY
2786 ******************************************************************************/
2787 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
2792 DEBUGFUNC("e1000_write_phy_reg");
2794 swfw = E1000_SWFW_PHY0_SM;
2795 if (e1000_swfw_sync_acquire(hw, swfw))
2796 return -E1000_ERR_SWFW_SYNC;
2798 if ((hw->phy_type == e1000_phy_igp) &&
2799 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2800 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2803 e1000_swfw_sync_release(hw, swfw);
2808 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2811 e1000_swfw_sync_release(hw, swfw);
2815 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2820 const u32 phy_addr = 1;
2822 DEBUGFUNC("e1000_write_phy_reg_ex");
2824 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2825 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2826 return -E1000_ERR_PARAM;
2829 if (hw->mac_type > e1000_82543) {
2830 /* Set up Op-code, Phy Address, register address, and data intended
2831 * for the PHY register in the MDI Control register. The MAC will take
2832 * care of interfacing with the PHY to send the desired data.
2834 mdic = (((u32)phy_data) |
2835 (reg_addr << E1000_MDIC_REG_SHIFT) |
2836 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2837 (E1000_MDIC_OP_WRITE));
2841 /* Poll the ready bit to see if the MDI read completed */
2842 for (i = 0; i < 641; i++) {
2845 if (mdic & E1000_MDIC_READY) break;
2847 if (!(mdic & E1000_MDIC_READY)) {
2848 DEBUGOUT("MDI Write did not complete\n");
2849 return -E1000_ERR_PHY;
2852 /* We'll need to use the SW defined pins to shift the write command
2853 * out to the PHY. We first send a preamble to the PHY to signal the
2854 * beginning of the MII instruction. This is done by sending 32
2855 * consecutive "1" bits.
2857 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2859 /* Now combine the remaining required fields that will indicate a
2860 * write operation. We use this method instead of calling the
2861 * e1000_shift_out_mdi_bits routine for each field in the command. The
2862 * format of a MII write instruction is as follows:
2863 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2865 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2866 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2868 mdic |= (u32)phy_data;
2870 e1000_shift_out_mdi_bits(hw, mdic, 32);
2873 return E1000_SUCCESS;
2876 /******************************************************************************
2877 * Returns the PHY to the power-on reset state
2879 * hw - Struct containing variables accessed by shared code
2880 ******************************************************************************/
2881 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
2888 DEBUGFUNC("e1000_phy_hw_reset");
2890 DEBUGOUT("Resetting Phy...\n");
2892 if (hw->mac_type > e1000_82543) {
2893 swfw = E1000_SWFW_PHY0_SM;
2894 if (e1000_swfw_sync_acquire(hw, swfw)) {
2895 DEBUGOUT("Unable to acquire swfw sync\n");
2896 return -E1000_ERR_SWFW_SYNC;
2898 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2899 * bit. Then, take it out of reset.
2900 * For e1000 hardware, we delay for 10ms between the assert
2904 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2905 E1000_WRITE_FLUSH();
2910 E1000_WRITE_FLUSH();
2912 e1000_swfw_sync_release(hw, swfw);
2914 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2915 * bit to put the PHY into reset. Then, take it out of reset.
2917 ctrl_ext = er32(CTRL_EXT);
2918 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2919 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2920 ew32(CTRL_EXT, ctrl_ext);
2921 E1000_WRITE_FLUSH();
2923 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2924 ew32(CTRL_EXT, ctrl_ext);
2925 E1000_WRITE_FLUSH();
2929 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2930 /* Configure activity LED after PHY reset */
2931 led_ctrl = er32(LEDCTL);
2932 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2933 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2934 ew32(LEDCTL, led_ctrl);
2937 /* Wait for FW to finish PHY configuration. */
2938 ret_val = e1000_get_phy_cfg_done(hw);
2939 if (ret_val != E1000_SUCCESS)
2945 /******************************************************************************
2948 * hw - Struct containing variables accessed by shared code
2950 * Sets bit 15 of the MII Control register
2951 ******************************************************************************/
2952 s32 e1000_phy_reset(struct e1000_hw *hw)
2957 DEBUGFUNC("e1000_phy_reset");
2959 switch (hw->phy_type) {
2961 ret_val = e1000_phy_hw_reset(hw);
2966 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2970 phy_data |= MII_CR_RESET;
2971 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2979 if (hw->phy_type == e1000_phy_igp)
2980 e1000_phy_init_script(hw);
2982 return E1000_SUCCESS;
2985 /******************************************************************************
2986 * Probes the expected PHY address for known PHY IDs
2988 * hw - Struct containing variables accessed by shared code
2989 ******************************************************************************/
2990 static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
2992 s32 phy_init_status, ret_val;
2993 u16 phy_id_high, phy_id_low;
2996 DEBUGFUNC("e1000_detect_gig_phy");
2998 if (hw->phy_id != 0)
2999 return E1000_SUCCESS;
3001 /* Read the PHY ID Registers to identify which PHY is onboard. */
3002 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3006 hw->phy_id = (u32)(phy_id_high << 16);
3008 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3012 hw->phy_id |= (u32)(phy_id_low & PHY_REVISION_MASK);
3013 hw->phy_revision = (u32)phy_id_low & ~PHY_REVISION_MASK;
3015 switch (hw->mac_type) {
3017 if (hw->phy_id == M88E1000_E_PHY_ID) match = true;
3020 if (hw->phy_id == M88E1000_I_PHY_ID) match = true;
3024 case e1000_82545_rev_3:
3026 case e1000_82546_rev_3:
3027 if (hw->phy_id == M88E1011_I_PHY_ID) match = true;
3030 case e1000_82541_rev_2:
3032 case e1000_82547_rev_2:
3033 if (hw->phy_id == IGP01E1000_I_PHY_ID) match = true;
3036 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3037 return -E1000_ERR_CONFIG;
3039 phy_init_status = e1000_set_phy_type(hw);
3041 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3042 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3043 return E1000_SUCCESS;
3045 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3046 return -E1000_ERR_PHY;
3049 /******************************************************************************
3050 * Resets the PHY's DSP
3052 * hw - Struct containing variables accessed by shared code
3053 ******************************************************************************/
3054 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
3057 DEBUGFUNC("e1000_phy_reset_dsp");
3060 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3062 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3064 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3066 ret_val = E1000_SUCCESS;
3072 /******************************************************************************
3073 * Get PHY information from various PHY registers for igp PHY only.
3075 * hw - Struct containing variables accessed by shared code
3076 * phy_info - PHY information structure
3077 ******************************************************************************/
3078 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3079 struct e1000_phy_info *phy_info)
3082 u16 phy_data, min_length, max_length, average;
3083 e1000_rev_polarity polarity;
3085 DEBUGFUNC("e1000_phy_igp_get_info");
3087 /* The downshift status is checked only once, after link is established,
3088 * and it stored in the hw->speed_downgraded parameter. */
3089 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3091 /* IGP01E1000 does not need to support it. */
3092 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3094 /* IGP01E1000 always correct polarity reversal */
3095 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3097 /* Check polarity status */
3098 ret_val = e1000_check_polarity(hw, &polarity);
3102 phy_info->cable_polarity = polarity;
3104 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3108 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & IGP01E1000_PSSR_MDIX) >>
3109 IGP01E1000_PSSR_MDIX_SHIFT);
3111 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3112 IGP01E1000_PSSR_SPEED_1000MBPS) {
3113 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3114 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3118 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3119 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3120 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3121 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3122 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3123 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3125 /* Get cable length */
3126 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3130 /* Translate to old method */
3131 average = (max_length + min_length) / 2;
3133 if (average <= e1000_igp_cable_length_50)
3134 phy_info->cable_length = e1000_cable_length_50;
3135 else if (average <= e1000_igp_cable_length_80)
3136 phy_info->cable_length = e1000_cable_length_50_80;
3137 else if (average <= e1000_igp_cable_length_110)
3138 phy_info->cable_length = e1000_cable_length_80_110;
3139 else if (average <= e1000_igp_cable_length_140)
3140 phy_info->cable_length = e1000_cable_length_110_140;
3142 phy_info->cable_length = e1000_cable_length_140;
3145 return E1000_SUCCESS;
3149 /******************************************************************************
3150 * Get PHY information from various PHY registers fot m88 PHY only.
3152 * hw - Struct containing variables accessed by shared code
3153 * phy_info - PHY information structure
3154 ******************************************************************************/
3155 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3156 struct e1000_phy_info *phy_info)
3160 e1000_rev_polarity polarity;
3162 DEBUGFUNC("e1000_phy_m88_get_info");
3164 /* The downshift status is checked only once, after link is established,
3165 * and it stored in the hw->speed_downgraded parameter. */
3166 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3168 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3172 phy_info->extended_10bt_distance =
3173 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3174 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3175 e1000_10bt_ext_dist_enable_lower : e1000_10bt_ext_dist_enable_normal;
3177 phy_info->polarity_correction =
3178 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3179 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3180 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
3182 /* Check polarity status */
3183 ret_val = e1000_check_polarity(hw, &polarity);
3186 phy_info->cable_polarity = polarity;
3188 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3192 phy_info->mdix_mode = (e1000_auto_x_mode)((phy_data & M88E1000_PSSR_MDIX) >>
3193 M88E1000_PSSR_MDIX_SHIFT);
3195 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3196 /* Cable Length Estimation and Local/Remote Receiver Information
3197 * are only valid at 1000 Mbps.
3199 phy_info->cable_length = (e1000_cable_length)((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3200 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3202 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3206 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3207 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3208 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3209 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3210 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3211 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3215 return E1000_SUCCESS;
3218 /******************************************************************************
3219 * Get PHY information from various PHY registers
3221 * hw - Struct containing variables accessed by shared code
3222 * phy_info - PHY information structure
3223 ******************************************************************************/
3224 s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
3229 DEBUGFUNC("e1000_phy_get_info");
3231 phy_info->cable_length = e1000_cable_length_undefined;
3232 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3233 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3234 phy_info->downshift = e1000_downshift_undefined;
3235 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3236 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3237 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3238 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3240 if (hw->media_type != e1000_media_type_copper) {
3241 DEBUGOUT("PHY info is only valid for copper media\n");
3242 return -E1000_ERR_CONFIG;
3245 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3249 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3253 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3254 DEBUGOUT("PHY info is only valid if link is up\n");
3255 return -E1000_ERR_CONFIG;
3258 if (hw->phy_type == e1000_phy_igp)
3259 return e1000_phy_igp_get_info(hw, phy_info);
3261 return e1000_phy_m88_get_info(hw, phy_info);
3264 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
3266 DEBUGFUNC("e1000_validate_mdi_settings");
3268 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3269 DEBUGOUT("Invalid MDI setting detected\n");
3271 return -E1000_ERR_CONFIG;
3273 return E1000_SUCCESS;
3277 /******************************************************************************
3278 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3281 * hw - Struct containing variables accessed by shared code
3282 *****************************************************************************/
3283 s32 e1000_init_eeprom_params(struct e1000_hw *hw)
3285 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3286 u32 eecd = er32(EECD);
3287 s32 ret_val = E1000_SUCCESS;
3290 DEBUGFUNC("e1000_init_eeprom_params");
3292 switch (hw->mac_type) {
3293 case e1000_82542_rev2_0:
3294 case e1000_82542_rev2_1:
3297 eeprom->type = e1000_eeprom_microwire;
3298 eeprom->word_size = 64;
3299 eeprom->opcode_bits = 3;
3300 eeprom->address_bits = 6;
3301 eeprom->delay_usec = 50;
3302 eeprom->use_eerd = false;
3303 eeprom->use_eewr = false;
3307 case e1000_82545_rev_3:
3309 case e1000_82546_rev_3:
3310 eeprom->type = e1000_eeprom_microwire;
3311 eeprom->opcode_bits = 3;
3312 eeprom->delay_usec = 50;
3313 if (eecd & E1000_EECD_SIZE) {
3314 eeprom->word_size = 256;
3315 eeprom->address_bits = 8;
3317 eeprom->word_size = 64;
3318 eeprom->address_bits = 6;
3320 eeprom->use_eerd = false;
3321 eeprom->use_eewr = false;
3324 case e1000_82541_rev_2:
3326 case e1000_82547_rev_2:
3327 if (eecd & E1000_EECD_TYPE) {
3328 eeprom->type = e1000_eeprom_spi;
3329 eeprom->opcode_bits = 8;
3330 eeprom->delay_usec = 1;
3331 if (eecd & E1000_EECD_ADDR_BITS) {
3332 eeprom->page_size = 32;
3333 eeprom->address_bits = 16;
3335 eeprom->page_size = 8;
3336 eeprom->address_bits = 8;
3339 eeprom->type = e1000_eeprom_microwire;
3340 eeprom->opcode_bits = 3;
3341 eeprom->delay_usec = 50;
3342 if (eecd & E1000_EECD_ADDR_BITS) {
3343 eeprom->word_size = 256;
3344 eeprom->address_bits = 8;
3346 eeprom->word_size = 64;
3347 eeprom->address_bits = 6;
3350 eeprom->use_eerd = false;
3351 eeprom->use_eewr = false;
3357 if (eeprom->type == e1000_eeprom_spi) {
3358 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3359 * 32KB (incremented by powers of 2).
3361 /* Set to default value for initial eeprom read. */
3362 eeprom->word_size = 64;
3363 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3366 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3367 /* 256B eeprom size was not supported in earlier hardware, so we
3368 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3369 * is never the result used in the shifting logic below. */
3373 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3378 /******************************************************************************
3379 * Raises the EEPROM's clock input.
3381 * hw - Struct containing variables accessed by shared code
3382 * eecd - EECD's current value
3383 *****************************************************************************/
3384 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
3386 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3387 * wait <delay> microseconds.
3389 *eecd = *eecd | E1000_EECD_SK;
3391 E1000_WRITE_FLUSH();
3392 udelay(hw->eeprom.delay_usec);
3395 /******************************************************************************
3396 * Lowers the EEPROM's clock input.
3398 * hw - Struct containing variables accessed by shared code
3399 * eecd - EECD's current value
3400 *****************************************************************************/
3401 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
3403 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3404 * wait 50 microseconds.
3406 *eecd = *eecd & ~E1000_EECD_SK;
3408 E1000_WRITE_FLUSH();
3409 udelay(hw->eeprom.delay_usec);
3412 /******************************************************************************
3413 * Shift data bits out to the EEPROM.
3415 * hw - Struct containing variables accessed by shared code
3416 * data - data to send to the EEPROM
3417 * count - number of bits to shift out
3418 *****************************************************************************/
3419 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
3421 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3425 /* We need to shift "count" bits out to the EEPROM. So, value in the
3426 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3427 * In order to do this, "data" must be broken down into bits.
3429 mask = 0x01 << (count - 1);
3431 if (eeprom->type == e1000_eeprom_microwire) {
3432 eecd &= ~E1000_EECD_DO;
3433 } else if (eeprom->type == e1000_eeprom_spi) {
3434 eecd |= E1000_EECD_DO;
3437 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3438 * and then raising and then lowering the clock (the SK bit controls
3439 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3440 * by setting "DI" to "0" and then raising and then lowering the clock.
3442 eecd &= ~E1000_EECD_DI;
3445 eecd |= E1000_EECD_DI;
3448 E1000_WRITE_FLUSH();
3450 udelay(eeprom->delay_usec);
3452 e1000_raise_ee_clk(hw, &eecd);
3453 e1000_lower_ee_clk(hw, &eecd);
3459 /* We leave the "DI" bit set to "0" when we leave this routine. */
3460 eecd &= ~E1000_EECD_DI;
3464 /******************************************************************************
3465 * Shift data bits in from the EEPROM
3467 * hw - Struct containing variables accessed by shared code
3468 *****************************************************************************/
3469 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
3475 /* In order to read a register from the EEPROM, we need to shift 'count'
3476 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3477 * input to the EEPROM (setting the SK bit), and then reading the value of
3478 * the "DO" bit. During this "shifting in" process the "DI" bit should
3484 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3487 for (i = 0; i < count; i++) {
3489 e1000_raise_ee_clk(hw, &eecd);
3493 eecd &= ~(E1000_EECD_DI);
3494 if (eecd & E1000_EECD_DO)
3497 e1000_lower_ee_clk(hw, &eecd);
3503 /******************************************************************************
3504 * Prepares EEPROM for access
3506 * hw - Struct containing variables accessed by shared code
3508 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3509 * function should be called before issuing a command to the EEPROM.
3510 *****************************************************************************/
3511 static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
3513 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3516 DEBUGFUNC("e1000_acquire_eeprom");
3518 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
3519 return -E1000_ERR_SWFW_SYNC;
3522 /* Request EEPROM Access */
3523 if (hw->mac_type > e1000_82544) {
3524 eecd |= E1000_EECD_REQ;
3527 while ((!(eecd & E1000_EECD_GNT)) &&
3528 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3533 if (!(eecd & E1000_EECD_GNT)) {
3534 eecd &= ~E1000_EECD_REQ;
3536 DEBUGOUT("Could not acquire EEPROM grant\n");
3537 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
3538 return -E1000_ERR_EEPROM;
3542 /* Setup EEPROM for Read/Write */
3544 if (eeprom->type == e1000_eeprom_microwire) {
3545 /* Clear SK and DI */
3546 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3550 eecd |= E1000_EECD_CS;
3552 } else if (eeprom->type == e1000_eeprom_spi) {
3553 /* Clear SK and CS */
3554 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3559 return E1000_SUCCESS;
3562 /******************************************************************************
3563 * Returns EEPROM to a "standby" state
3565 * hw - Struct containing variables accessed by shared code
3566 *****************************************************************************/
3567 static void e1000_standby_eeprom(struct e1000_hw *hw)
3569 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3574 if (eeprom->type == e1000_eeprom_microwire) {
3575 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3577 E1000_WRITE_FLUSH();
3578 udelay(eeprom->delay_usec);
3581 eecd |= E1000_EECD_SK;
3583 E1000_WRITE_FLUSH();
3584 udelay(eeprom->delay_usec);
3587 eecd |= E1000_EECD_CS;
3589 E1000_WRITE_FLUSH();
3590 udelay(eeprom->delay_usec);
3593 eecd &= ~E1000_EECD_SK;
3595 E1000_WRITE_FLUSH();
3596 udelay(eeprom->delay_usec);
3597 } else if (eeprom->type == e1000_eeprom_spi) {
3598 /* Toggle CS to flush commands */
3599 eecd |= E1000_EECD_CS;
3601 E1000_WRITE_FLUSH();
3602 udelay(eeprom->delay_usec);
3603 eecd &= ~E1000_EECD_CS;
3605 E1000_WRITE_FLUSH();
3606 udelay(eeprom->delay_usec);
3610 /******************************************************************************
3611 * Terminates a command by inverting the EEPROM's chip select pin
3613 * hw - Struct containing variables accessed by shared code
3614 *****************************************************************************/
3615 static void e1000_release_eeprom(struct e1000_hw *hw)
3619 DEBUGFUNC("e1000_release_eeprom");
3623 if (hw->eeprom.type == e1000_eeprom_spi) {
3624 eecd |= E1000_EECD_CS; /* Pull CS high */
3625 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3629 udelay(hw->eeprom.delay_usec);
3630 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3631 /* cleanup eeprom */
3633 /* CS on Microwire is active-high */
3634 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3638 /* Rising edge of clock */
3639 eecd |= E1000_EECD_SK;
3641 E1000_WRITE_FLUSH();
3642 udelay(hw->eeprom.delay_usec);
3644 /* Falling edge of clock */
3645 eecd &= ~E1000_EECD_SK;
3647 E1000_WRITE_FLUSH();
3648 udelay(hw->eeprom.delay_usec);
3651 /* Stop requesting EEPROM access */
3652 if (hw->mac_type > e1000_82544) {
3653 eecd &= ~E1000_EECD_REQ;
3657 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
3660 /******************************************************************************
3661 * Reads a 16 bit word from the EEPROM.
3663 * hw - Struct containing variables accessed by shared code
3664 *****************************************************************************/
3665 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3667 u16 retry_count = 0;
3670 DEBUGFUNC("e1000_spi_eeprom_ready");
3672 /* Read "Status Register" repeatedly until the LSB is cleared. The
3673 * EEPROM will signal that the command has been completed by clearing
3674 * bit 0 of the internal status register. If it's not cleared within
3675 * 5 milliseconds, then error out.
3679 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3680 hw->eeprom.opcode_bits);
3681 spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8);
3682 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3688 e1000_standby_eeprom(hw);
3689 } while (retry_count < EEPROM_MAX_RETRY_SPI);
3691 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3692 * only 0-5mSec on 5V devices)
3694 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3695 DEBUGOUT("SPI EEPROM Status error\n");
3696 return -E1000_ERR_EEPROM;
3699 return E1000_SUCCESS;
3702 /******************************************************************************
3703 * Reads a 16 bit word from the EEPROM.
3705 * hw - Struct containing variables accessed by shared code
3706 * offset - offset of word in the EEPROM to read
3707 * data - word read from the EEPROM
3708 * words - number of words to read
3709 *****************************************************************************/
3710 s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3713 spin_lock(&e1000_eeprom_lock);
3714 ret = e1000_do_read_eeprom(hw, offset, words, data);
3715 spin_unlock(&e1000_eeprom_lock);
3719 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3721 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3724 DEBUGFUNC("e1000_read_eeprom");
3726 /* If eeprom is not yet detected, do so now */
3727 if (eeprom->word_size == 0)
3728 e1000_init_eeprom_params(hw);
3730 /* A check for invalid values: offset too large, too many words, and not
3733 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3735 DEBUGOUT2("\"words\" parameter out of bounds. Words = %d, size = %d\n", offset, eeprom->word_size);
3736 return -E1000_ERR_EEPROM;
3739 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3740 * directly. In this case, we need to acquire the EEPROM so that
3741 * FW or other port software does not interrupt.
3743 if (!hw->eeprom.use_eerd) {
3744 /* Prepare the EEPROM for bit-bang reading */
3745 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3746 return -E1000_ERR_EEPROM;
3749 /* Eerd register EEPROM access requires no eeprom aquire/release */
3750 if (eeprom->use_eerd)
3751 return e1000_read_eeprom_eerd(hw, offset, words, data);
3753 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3754 * acquired the EEPROM at this point, so any returns should relase it */
3755 if (eeprom->type == e1000_eeprom_spi) {
3757 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
3759 if (e1000_spi_eeprom_ready(hw)) {
3760 e1000_release_eeprom(hw);
3761 return -E1000_ERR_EEPROM;
3764 e1000_standby_eeprom(hw);
3766 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3767 if ((eeprom->address_bits == 8) && (offset >= 128))
3768 read_opcode |= EEPROM_A8_OPCODE_SPI;
3770 /* Send the READ command (opcode + addr) */
3771 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3772 e1000_shift_out_ee_bits(hw, (u16)(offset*2), eeprom->address_bits);
3774 /* Read the data. The address of the eeprom internally increments with
3775 * each byte (spi) being read, saving on the overhead of eeprom setup
3776 * and tear-down. The address counter will roll over if reading beyond
3777 * the size of the eeprom, thus allowing the entire memory to be read
3778 * starting from any offset. */
3779 for (i = 0; i < words; i++) {
3780 word_in = e1000_shift_in_ee_bits(hw, 16);
3781 data[i] = (word_in >> 8) | (word_in << 8);
3783 } else if (eeprom->type == e1000_eeprom_microwire) {
3784 for (i = 0; i < words; i++) {
3785 /* Send the READ command (opcode + addr) */
3786 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3787 eeprom->opcode_bits);
3788 e1000_shift_out_ee_bits(hw, (u16)(offset + i),
3789 eeprom->address_bits);
3791 /* Read the data. For microwire, each word requires the overhead
3792 * of eeprom setup and tear-down. */
3793 data[i] = e1000_shift_in_ee_bits(hw, 16);
3794 e1000_standby_eeprom(hw);
3798 /* End this read operation */
3799 e1000_release_eeprom(hw);
3801 return E1000_SUCCESS;
3804 /******************************************************************************
3805 * Reads a 16 bit word from the EEPROM using the EERD register.
3807 * hw - Struct containing variables accessed by shared code
3808 * offset - offset of word in the EEPROM to read
3809 * data - word read from the EEPROM
3810 * words - number of words to read
3811 *****************************************************************************/
3812 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3818 for (i = 0; i < words; i++) {
3819 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3820 E1000_EEPROM_RW_REG_START;
3823 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3828 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
3835 /******************************************************************************
3836 * Writes a 16 bit word from the EEPROM using the EEWR register.
3838 * hw - Struct containing variables accessed by shared code
3839 * offset - offset of word in the EEPROM to read
3840 * data - word read from the EEPROM
3841 * words - number of words to read
3842 *****************************************************************************/
3843 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3846 u32 register_value = 0;
3850 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
3851 return -E1000_ERR_SWFW_SYNC;
3853 for (i = 0; i < words; i++) {
3854 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3855 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3856 E1000_EEPROM_RW_REG_START;
3858 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3863 ew32(EEWR, register_value);
3865 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3872 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
3876 /******************************************************************************
3877 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3879 * hw - Struct containing variables accessed by shared code
3880 *****************************************************************************/
3881 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
3883 u32 attempts = 100000;
3885 s32 done = E1000_ERR_EEPROM;
3887 for (i = 0; i < attempts; i++) {
3888 if (eerd == E1000_EEPROM_POLL_READ)
3893 if (reg & E1000_EEPROM_RW_REG_DONE) {
3894 done = E1000_SUCCESS;
3903 /******************************************************************************
3904 * Verifies that the EEPROM has a valid checksum
3906 * hw - Struct containing variables accessed by shared code
3908 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3909 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3911 *****************************************************************************/
3912 s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3917 DEBUGFUNC("e1000_validate_eeprom_checksum");
3919 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3920 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3921 DEBUGOUT("EEPROM Read Error\n");
3922 return -E1000_ERR_EEPROM;
3924 checksum += eeprom_data;
3927 if (checksum == (u16)EEPROM_SUM)
3928 return E1000_SUCCESS;
3930 DEBUGOUT("EEPROM Checksum Invalid\n");
3931 return -E1000_ERR_EEPROM;
3935 /******************************************************************************
3936 * Calculates the EEPROM checksum and writes it to the EEPROM
3938 * hw - Struct containing variables accessed by shared code
3940 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3941 * Writes the difference to word offset 63 of the EEPROM.
3942 *****************************************************************************/
3943 s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3948 DEBUGFUNC("e1000_update_eeprom_checksum");
3950 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3951 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3952 DEBUGOUT("EEPROM Read Error\n");
3953 return -E1000_ERR_EEPROM;
3955 checksum += eeprom_data;
3957 checksum = (u16)EEPROM_SUM - checksum;
3958 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3959 DEBUGOUT("EEPROM Write Error\n");
3960 return -E1000_ERR_EEPROM;
3962 return E1000_SUCCESS;
3965 /******************************************************************************
3966 * Parent function for writing words to the different EEPROM types.
3968 * hw - Struct containing variables accessed by shared code
3969 * offset - offset within the EEPROM to be written to
3970 * words - number of words to write
3971 * data - 16 bit word to be written to the EEPROM
3973 * If e1000_update_eeprom_checksum is not called after this function, the
3974 * EEPROM will most likely contain an invalid checksum.
3975 *****************************************************************************/
3976 s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3979 spin_lock(&e1000_eeprom_lock);
3980 ret = e1000_do_write_eeprom(hw, offset, words, data);
3981 spin_unlock(&e1000_eeprom_lock);
3986 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3988 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3991 DEBUGFUNC("e1000_write_eeprom");
3993 /* If eeprom is not yet detected, do so now */
3994 if (eeprom->word_size == 0)
3995 e1000_init_eeprom_params(hw);
3997 /* A check for invalid values: offset too large, too many words, and not
4000 if ((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4002 DEBUGOUT("\"words\" parameter out of bounds\n");
4003 return -E1000_ERR_EEPROM;
4006 if (eeprom->use_eewr)
4007 return e1000_write_eeprom_eewr(hw, offset, words, data);
4009 /* Prepare the EEPROM for writing */
4010 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4011 return -E1000_ERR_EEPROM;
4013 if (eeprom->type == e1000_eeprom_microwire) {
4014 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4016 status = e1000_write_eeprom_spi(hw, offset, words, data);
4020 /* Done with writing */
4021 e1000_release_eeprom(hw);
4026 /******************************************************************************
4027 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4029 * hw - Struct containing variables accessed by shared code
4030 * offset - offset within the EEPROM to be written to
4031 * words - number of words to write
4032 * data - pointer to array of 8 bit words to be written to the EEPROM
4034 *****************************************************************************/
4035 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4038 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4041 DEBUGFUNC("e1000_write_eeprom_spi");
4043 while (widx < words) {
4044 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
4046 if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4048 e1000_standby_eeprom(hw);
4050 /* Send the WRITE ENABLE command (8 bit opcode ) */
4051 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4052 eeprom->opcode_bits);
4054 e1000_standby_eeprom(hw);
4056 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4057 if ((eeprom->address_bits == 8) && (offset >= 128))
4058 write_opcode |= EEPROM_A8_OPCODE_SPI;
4060 /* Send the Write command (8-bit opcode + addr) */
4061 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4063 e1000_shift_out_ee_bits(hw, (u16)((offset + widx)*2),
4064 eeprom->address_bits);
4068 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4069 while (widx < words) {
4070 u16 word_out = data[widx];
4071 word_out = (word_out >> 8) | (word_out << 8);
4072 e1000_shift_out_ee_bits(hw, word_out, 16);
4075 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4076 * operation, while the smaller eeproms are capable of an 8-byte
4077 * PAGE WRITE operation. Break the inner loop to pass new address
4079 if ((((offset + widx)*2) % eeprom->page_size) == 0) {
4080 e1000_standby_eeprom(hw);
4086 return E1000_SUCCESS;
4089 /******************************************************************************
4090 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4092 * hw - Struct containing variables accessed by shared code
4093 * offset - offset within the EEPROM to be written to
4094 * words - number of words to write
4095 * data - pointer to array of 16 bit words to be written to the EEPROM
4097 *****************************************************************************/
4098 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4099 u16 words, u16 *data)
4101 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4103 u16 words_written = 0;
4106 DEBUGFUNC("e1000_write_eeprom_microwire");
4108 /* Send the write enable command to the EEPROM (3-bit opcode plus
4109 * 6/8-bit dummy address beginning with 11). It's less work to include
4110 * the 11 of the dummy address as part of the opcode than it is to shift
4111 * it over the correct number of bits for the address. This puts the
4112 * EEPROM into write/erase mode.
4114 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4115 (u16)(eeprom->opcode_bits + 2));
4117 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
4119 /* Prepare the EEPROM */
4120 e1000_standby_eeprom(hw);
4122 while (words_written < words) {
4123 /* Send the Write command (3-bit opcode + addr) */
4124 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4125 eeprom->opcode_bits);
4127 e1000_shift_out_ee_bits(hw, (u16)(offset + words_written),
4128 eeprom->address_bits);
4131 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4133 /* Toggle the CS line. This in effect tells the EEPROM to execute
4134 * the previous command.
4136 e1000_standby_eeprom(hw);
4138 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4139 * signal that the command has been completed by raising the DO signal.
4140 * If DO does not go high in 10 milliseconds, then error out.
4142 for (i = 0; i < 200; i++) {
4144 if (eecd & E1000_EECD_DO) break;
4148 DEBUGOUT("EEPROM Write did not complete\n");
4149 return -E1000_ERR_EEPROM;
4152 /* Recover from write */
4153 e1000_standby_eeprom(hw);
4158 /* Send the write disable command to the EEPROM (3-bit opcode plus
4159 * 6/8-bit dummy address beginning with 10). It's less work to include
4160 * the 10 of the dummy address as part of the opcode than it is to shift
4161 * it over the correct number of bits for the address. This takes the
4162 * EEPROM out of write/erase mode.
4164 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4165 (u16)(eeprom->opcode_bits + 2));
4167 e1000_shift_out_ee_bits(hw, 0, (u16)(eeprom->address_bits - 2));
4169 return E1000_SUCCESS;
4172 /******************************************************************************
4173 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4174 * second function of dual function devices
4176 * hw - Struct containing variables accessed by shared code
4177 *****************************************************************************/
4178 s32 e1000_read_mac_addr(struct e1000_hw *hw)
4183 DEBUGFUNC("e1000_read_mac_addr");
4185 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4187 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4188 DEBUGOUT("EEPROM Read Error\n");
4189 return -E1000_ERR_EEPROM;
4191 hw->perm_mac_addr[i] = (u8)(eeprom_data & 0x00FF);
4192 hw->perm_mac_addr[i+1] = (u8)(eeprom_data >> 8);
4195 switch (hw->mac_type) {
4199 case e1000_82546_rev_3:
4200 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4201 hw->perm_mac_addr[5] ^= 0x01;
4205 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4206 hw->mac_addr[i] = hw->perm_mac_addr[i];
4207 return E1000_SUCCESS;
4210 /******************************************************************************
4211 * Initializes receive address filters.
4213 * hw - Struct containing variables accessed by shared code
4215 * Places the MAC address in receive address register 0 and clears the rest
4216 * of the receive addresss registers. Clears the multicast table. Assumes
4217 * the receiver is in reset when the routine is called.
4218 *****************************************************************************/
4219 static void e1000_init_rx_addrs(struct e1000_hw *hw)
4224 DEBUGFUNC("e1000_init_rx_addrs");
4226 /* Setup the receive address. */
4227 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4229 e1000_rar_set(hw, hw->mac_addr, 0);
4231 rar_num = E1000_RAR_ENTRIES;
4233 /* Zero out the other 15 receive addresses. */
4234 DEBUGOUT("Clearing RAR[1-15]\n");
4235 for (i = 1; i < rar_num; i++) {
4236 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4237 E1000_WRITE_FLUSH();
4238 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4239 E1000_WRITE_FLUSH();
4243 /******************************************************************************
4244 * Hashes an address to determine its location in the multicast table
4246 * hw - Struct containing variables accessed by shared code
4247 * mc_addr - the multicast address to hash
4248 *****************************************************************************/
4249 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
4253 /* The portion of the address that is used for the hash table is
4254 * determined by the mc_filter_type setting.
4256 switch (hw->mc_filter_type) {
4257 /* [0] [1] [2] [3] [4] [5]
4262 /* [47:36] i.e. 0x563 for above example address */
4263 hash_value = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
4266 /* [46:35] i.e. 0xAC6 for above example address */
4267 hash_value = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
4270 /* [45:34] i.e. 0x5D8 for above example address */
4271 hash_value = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
4274 /* [43:32] i.e. 0x634 for above example address */
4275 hash_value = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
4279 hash_value &= 0xFFF;
4283 /******************************************************************************
4284 * Puts an ethernet address into a receive address register.
4286 * hw - Struct containing variables accessed by shared code
4287 * addr - Address to put into receive address register
4288 * index - Receive address register to write
4289 *****************************************************************************/
4290 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
4292 u32 rar_low, rar_high;
4294 /* HW expects these in little endian so we reverse the byte order
4295 * from network order (big endian) to little endian
4297 rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
4298 ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
4299 rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
4301 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4305 * If there are any Rx frames queued up or otherwise present in the HW
4306 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4307 * hang. To work around this issue, we have to disable receives and
4308 * flush out all Rx frames before we enable RSS. To do so, we modify we
4309 * redirect all Rx traffic to manageability and then reset the HW.
4310 * This flushes away Rx frames, and (since the redirections to
4311 * manageability persists across resets) keeps new ones from coming in
4312 * while we work. Then, we clear the Address Valid AV bit for all MAC
4313 * addresses and undo the re-direction to manageability.
4314 * Now, frames are coming in again, but the MAC won't accept them, so
4315 * far so good. We now proceed to initialize RSS (if necessary) and
4316 * configure the Rx unit. Last, we re-enable the AV bits and continue
4319 switch (hw->mac_type) {
4321 /* Indicate to hardware the Address is Valid. */
4322 rar_high |= E1000_RAH_AV;
4326 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4327 E1000_WRITE_FLUSH();
4328 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4329 E1000_WRITE_FLUSH();
4332 /******************************************************************************
4333 * Writes a value to the specified offset in the VLAN filter table.
4335 * hw - Struct containing variables accessed by shared code
4336 * offset - Offset in VLAN filer table to write
4337 * value - Value to write into VLAN filter table
4338 *****************************************************************************/
4339 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
4343 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4344 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4345 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4346 E1000_WRITE_FLUSH();
4347 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4348 E1000_WRITE_FLUSH();
4350 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4351 E1000_WRITE_FLUSH();
4355 /******************************************************************************
4356 * Clears the VLAN filer table
4358 * hw - Struct containing variables accessed by shared code
4359 *****************************************************************************/
4360 static void e1000_clear_vfta(struct e1000_hw *hw)
4364 u32 vfta_offset = 0;
4365 u32 vfta_bit_in_reg = 0;
4367 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4368 /* If the offset we want to clear is the same offset of the
4369 * manageability VLAN ID, then clear all bits except that of the
4370 * manageability unit */
4371 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4372 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4373 E1000_WRITE_FLUSH();
4377 static s32 e1000_id_led_init(struct e1000_hw *hw)
4380 const u32 ledctl_mask = 0x000000FF;
4381 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4382 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4383 u16 eeprom_data, i, temp;
4384 const u16 led_mask = 0x0F;
4386 DEBUGFUNC("e1000_id_led_init");
4388 if (hw->mac_type < e1000_82540) {
4390 return E1000_SUCCESS;
4393 ledctl = er32(LEDCTL);
4394 hw->ledctl_default = ledctl;
4395 hw->ledctl_mode1 = hw->ledctl_default;
4396 hw->ledctl_mode2 = hw->ledctl_default;
4398 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4399 DEBUGOUT("EEPROM Read Error\n");
4400 return -E1000_ERR_EEPROM;
4403 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4404 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4405 eeprom_data = ID_LED_DEFAULT;
4408 for (i = 0; i < 4; i++) {
4409 temp = (eeprom_data >> (i << 2)) & led_mask;
4411 case ID_LED_ON1_DEF2:
4412 case ID_LED_ON1_ON2:
4413 case ID_LED_ON1_OFF2:
4414 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4415 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4417 case ID_LED_OFF1_DEF2:
4418 case ID_LED_OFF1_ON2:
4419 case ID_LED_OFF1_OFF2:
4420 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4421 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4428 case ID_LED_DEF1_ON2:
4429 case ID_LED_ON1_ON2:
4430 case ID_LED_OFF1_ON2:
4431 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4432 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4434 case ID_LED_DEF1_OFF2:
4435 case ID_LED_ON1_OFF2:
4436 case ID_LED_OFF1_OFF2:
4437 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4438 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4445 return E1000_SUCCESS;
4448 /******************************************************************************
4449 * Prepares SW controlable LED for use and saves the current state of the LED.
4451 * hw - Struct containing variables accessed by shared code
4452 *****************************************************************************/
4453 s32 e1000_setup_led(struct e1000_hw *hw)
4456 s32 ret_val = E1000_SUCCESS;
4458 DEBUGFUNC("e1000_setup_led");
4460 switch (hw->mac_type) {
4461 case e1000_82542_rev2_0:
4462 case e1000_82542_rev2_1:
4465 /* No setup necessary */
4469 case e1000_82541_rev_2:
4470 case e1000_82547_rev_2:
4471 /* Turn off PHY Smart Power Down (if enabled) */
4472 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4473 &hw->phy_spd_default);
4476 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4477 (u16)(hw->phy_spd_default &
4478 ~IGP01E1000_GMII_SPD));
4483 if (hw->media_type == e1000_media_type_fiber) {
4484 ledctl = er32(LEDCTL);
4485 /* Save current LEDCTL settings */
4486 hw->ledctl_default = ledctl;
4488 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4489 E1000_LEDCTL_LED0_BLINK |
4490 E1000_LEDCTL_LED0_MODE_MASK);
4491 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4492 E1000_LEDCTL_LED0_MODE_SHIFT);
4493 ew32(LEDCTL, ledctl);
4494 } else if (hw->media_type == e1000_media_type_copper)
4495 ew32(LEDCTL, hw->ledctl_mode1);
4499 return E1000_SUCCESS;
4502 /******************************************************************************
4503 * Restores the saved state of the SW controlable LED.
4505 * hw - Struct containing variables accessed by shared code
4506 *****************************************************************************/
4507 s32 e1000_cleanup_led(struct e1000_hw *hw)
4509 s32 ret_val = E1000_SUCCESS;
4511 DEBUGFUNC("e1000_cleanup_led");
4513 switch (hw->mac_type) {
4514 case e1000_82542_rev2_0:
4515 case e1000_82542_rev2_1:
4518 /* No cleanup necessary */
4522 case e1000_82541_rev_2:
4523 case e1000_82547_rev_2:
4524 /* Turn on PHY Smart Power Down (if previously enabled) */
4525 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4526 hw->phy_spd_default);
4531 /* Restore LEDCTL settings */
4532 ew32(LEDCTL, hw->ledctl_default);
4536 return E1000_SUCCESS;
4539 /******************************************************************************
4540 * Turns on the software controllable LED
4542 * hw - Struct containing variables accessed by shared code
4543 *****************************************************************************/
4544 s32 e1000_led_on(struct e1000_hw *hw)
4546 u32 ctrl = er32(CTRL);
4548 DEBUGFUNC("e1000_led_on");
4550 switch (hw->mac_type) {
4551 case e1000_82542_rev2_0:
4552 case e1000_82542_rev2_1:
4554 /* Set SW Defineable Pin 0 to turn on the LED */
4555 ctrl |= E1000_CTRL_SWDPIN0;
4556 ctrl |= E1000_CTRL_SWDPIO0;
4559 if (hw->media_type == e1000_media_type_fiber) {
4560 /* Set SW Defineable Pin 0 to turn on the LED */
4561 ctrl |= E1000_CTRL_SWDPIN0;
4562 ctrl |= E1000_CTRL_SWDPIO0;
4564 /* Clear SW Defineable Pin 0 to turn on the LED */
4565 ctrl &= ~E1000_CTRL_SWDPIN0;
4566 ctrl |= E1000_CTRL_SWDPIO0;
4570 if (hw->media_type == e1000_media_type_fiber) {
4571 /* Clear SW Defineable Pin 0 to turn on the LED */
4572 ctrl &= ~E1000_CTRL_SWDPIN0;
4573 ctrl |= E1000_CTRL_SWDPIO0;
4574 } else if (hw->media_type == e1000_media_type_copper) {
4575 ew32(LEDCTL, hw->ledctl_mode2);
4576 return E1000_SUCCESS;
4583 return E1000_SUCCESS;
4586 /******************************************************************************
4587 * Turns off the software controllable LED
4589 * hw - Struct containing variables accessed by shared code
4590 *****************************************************************************/
4591 s32 e1000_led_off(struct e1000_hw *hw)
4593 u32 ctrl = er32(CTRL);
4595 DEBUGFUNC("e1000_led_off");
4597 switch (hw->mac_type) {
4598 case e1000_82542_rev2_0:
4599 case e1000_82542_rev2_1:
4601 /* Clear SW Defineable Pin 0 to turn off the LED */
4602 ctrl &= ~E1000_CTRL_SWDPIN0;
4603 ctrl |= E1000_CTRL_SWDPIO0;
4606 if (hw->media_type == e1000_media_type_fiber) {
4607 /* Clear SW Defineable Pin 0 to turn off the LED */
4608 ctrl &= ~E1000_CTRL_SWDPIN0;
4609 ctrl |= E1000_CTRL_SWDPIO0;
4611 /* Set SW Defineable Pin 0 to turn off the LED */
4612 ctrl |= E1000_CTRL_SWDPIN0;
4613 ctrl |= E1000_CTRL_SWDPIO0;
4617 if (hw->media_type == e1000_media_type_fiber) {
4618 /* Set SW Defineable Pin 0 to turn off the LED */
4619 ctrl |= E1000_CTRL_SWDPIN0;
4620 ctrl |= E1000_CTRL_SWDPIO0;
4621 } else if (hw->media_type == e1000_media_type_copper) {
4622 ew32(LEDCTL, hw->ledctl_mode1);
4623 return E1000_SUCCESS;
4630 return E1000_SUCCESS;
4633 /******************************************************************************
4634 * Clears all hardware statistics counters.
4636 * hw - Struct containing variables accessed by shared code
4637 *****************************************************************************/
4638 static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
4642 temp = er32(CRCERRS);
4643 temp = er32(SYMERRS);
4648 temp = er32(LATECOL);
4653 temp = er32(XONRXC);
4654 temp = er32(XONTXC);
4655 temp = er32(XOFFRXC);
4656 temp = er32(XOFFTXC);
4660 temp = er32(PRC127);
4661 temp = er32(PRC255);
4662 temp = er32(PRC511);
4663 temp = er32(PRC1023);
4664 temp = er32(PRC1522);
4687 temp = er32(PTC127);
4688 temp = er32(PTC255);
4689 temp = er32(PTC511);
4690 temp = er32(PTC1023);
4691 temp = er32(PTC1522);
4696 if (hw->mac_type < e1000_82543) return;
4698 temp = er32(ALGNERRC);
4699 temp = er32(RXERRC);
4701 temp = er32(CEXTERR);
4703 temp = er32(TSCTFC);
4705 if (hw->mac_type <= e1000_82544) return;
4707 temp = er32(MGTPRC);
4708 temp = er32(MGTPDC);
4709 temp = er32(MGTPTC);
4712 /******************************************************************************
4713 * Resets Adaptive IFS to its default state.
4715 * hw - Struct containing variables accessed by shared code
4717 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4718 * hw->ifs_params_forced to true. However, you must initialize hw->
4719 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4720 * before calling this function.
4721 *****************************************************************************/
4722 void e1000_reset_adaptive(struct e1000_hw *hw)
4724 DEBUGFUNC("e1000_reset_adaptive");
4726 if (hw->adaptive_ifs) {
4727 if (!hw->ifs_params_forced) {
4728 hw->current_ifs_val = 0;
4729 hw->ifs_min_val = IFS_MIN;
4730 hw->ifs_max_val = IFS_MAX;
4731 hw->ifs_step_size = IFS_STEP;
4732 hw->ifs_ratio = IFS_RATIO;
4734 hw->in_ifs_mode = false;
4737 DEBUGOUT("Not in Adaptive IFS mode!\n");
4741 /******************************************************************************
4742 * Called during the callback/watchdog routine to update IFS value based on
4743 * the ratio of transmits to collisions.
4745 * hw - Struct containing variables accessed by shared code
4746 * tx_packets - Number of transmits since last callback
4747 * total_collisions - Number of collisions since last callback
4748 *****************************************************************************/
4749 void e1000_update_adaptive(struct e1000_hw *hw)
4751 DEBUGFUNC("e1000_update_adaptive");
4753 if (hw->adaptive_ifs) {
4754 if ((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4755 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4756 hw->in_ifs_mode = true;
4757 if (hw->current_ifs_val < hw->ifs_max_val) {
4758 if (hw->current_ifs_val == 0)
4759 hw->current_ifs_val = hw->ifs_min_val;
4761 hw->current_ifs_val += hw->ifs_step_size;
4762 ew32(AIT, hw->current_ifs_val);
4766 if (hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4767 hw->current_ifs_val = 0;
4768 hw->in_ifs_mode = false;
4773 DEBUGOUT("Not in Adaptive IFS mode!\n");
4777 /******************************************************************************
4778 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4780 * hw - Struct containing variables accessed by shared code
4781 * frame_len - The length of the frame in question
4782 * mac_addr - The Ethernet destination address of the frame in question
4783 *****************************************************************************/
4784 void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4785 u32 frame_len, u8 *mac_addr)
4789 /* First adjust the frame length. */
4791 /* We need to adjust the statistics counters, since the hardware
4792 * counters overcount this packet as a CRC error and undercount
4793 * the packet as a good packet
4795 /* This packet should not be counted as a CRC error. */
4797 /* This packet does count as a Good Packet Received. */
4800 /* Adjust the Good Octets received counters */
4801 carry_bit = 0x80000000 & stats->gorcl;
4802 stats->gorcl += frame_len;
4803 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4804 * Received Count) was one before the addition,
4805 * AND it is zero after, then we lost the carry out,
4806 * need to add one to Gorch (Good Octets Received Count High).
4807 * This could be simplified if all environments supported
4810 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4812 /* Is this a broadcast or multicast? Check broadcast first,
4813 * since the test for a multicast frame will test positive on
4814 * a broadcast frame.
4816 if ((mac_addr[0] == (u8)0xff) && (mac_addr[1] == (u8)0xff))
4817 /* Broadcast packet */
4819 else if (*mac_addr & 0x01)
4820 /* Multicast packet */
4823 if (frame_len == hw->max_frame_size) {
4824 /* In this case, the hardware has overcounted the number of
4831 /* Adjust the bin counters when the extra byte put the frame in the
4832 * wrong bin. Remember that the frame_len was adjusted above.
4834 if (frame_len == 64) {
4837 } else if (frame_len == 127) {
4840 } else if (frame_len == 255) {
4843 } else if (frame_len == 511) {
4846 } else if (frame_len == 1023) {
4849 } else if (frame_len == 1522) {
4854 /******************************************************************************
4855 * Gets the current PCI bus type, speed, and width of the hardware
4857 * hw - Struct containing variables accessed by shared code
4858 *****************************************************************************/
4859 void e1000_get_bus_info(struct e1000_hw *hw)
4863 switch (hw->mac_type) {
4864 case e1000_82542_rev2_0:
4865 case e1000_82542_rev2_1:
4866 hw->bus_type = e1000_bus_type_pci;
4867 hw->bus_speed = e1000_bus_speed_unknown;
4868 hw->bus_width = e1000_bus_width_unknown;
4871 status = er32(STATUS);
4872 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4873 e1000_bus_type_pcix : e1000_bus_type_pci;
4875 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4876 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4877 e1000_bus_speed_66 : e1000_bus_speed_120;
4878 } else if (hw->bus_type == e1000_bus_type_pci) {
4879 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4880 e1000_bus_speed_66 : e1000_bus_speed_33;
4882 switch (status & E1000_STATUS_PCIX_SPEED) {
4883 case E1000_STATUS_PCIX_SPEED_66:
4884 hw->bus_speed = e1000_bus_speed_66;
4886 case E1000_STATUS_PCIX_SPEED_100:
4887 hw->bus_speed = e1000_bus_speed_100;
4889 case E1000_STATUS_PCIX_SPEED_133:
4890 hw->bus_speed = e1000_bus_speed_133;
4893 hw->bus_speed = e1000_bus_speed_reserved;
4897 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4898 e1000_bus_width_64 : e1000_bus_width_32;
4903 /******************************************************************************
4904 * Writes a value to one of the devices registers using port I/O (as opposed to
4905 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4907 * hw - Struct containing variables accessed by shared code
4908 * offset - offset to write to
4909 * value - value to write
4910 *****************************************************************************/
4911 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
4913 unsigned long io_addr = hw->io_base;
4914 unsigned long io_data = hw->io_base + 4;
4916 e1000_io_write(hw, io_addr, offset);
4917 e1000_io_write(hw, io_data, value);
4920 /******************************************************************************
4921 * Estimates the cable length.
4923 * hw - Struct containing variables accessed by shared code
4924 * min_length - The estimated minimum length
4925 * max_length - The estimated maximum length
4927 * returns: - E1000_ERR_XXX
4930 * This function always returns a ranged length (minimum & maximum).
4931 * So for M88 phy's, this function interprets the one value returned from the
4932 * register to the minimum and maximum range.
4933 * For IGP phy's, the function calculates the range by the AGC registers.
4934 *****************************************************************************/
4935 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4943 DEBUGFUNC("e1000_get_cable_length");
4945 *min_length = *max_length = 0;
4947 /* Use old method for Phy older than IGP */
4948 if (hw->phy_type == e1000_phy_m88) {
4950 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4954 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4955 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4957 /* Convert the enum value to ranged values */
4958 switch (cable_length) {
4959 case e1000_cable_length_50:
4961 *max_length = e1000_igp_cable_length_50;
4963 case e1000_cable_length_50_80:
4964 *min_length = e1000_igp_cable_length_50;
4965 *max_length = e1000_igp_cable_length_80;
4967 case e1000_cable_length_80_110:
4968 *min_length = e1000_igp_cable_length_80;
4969 *max_length = e1000_igp_cable_length_110;
4971 case e1000_cable_length_110_140:
4972 *min_length = e1000_igp_cable_length_110;
4973 *max_length = e1000_igp_cable_length_140;
4975 case e1000_cable_length_140:
4976 *min_length = e1000_igp_cable_length_140;
4977 *max_length = e1000_igp_cable_length_170;
4980 return -E1000_ERR_PHY;
4983 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4985 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4986 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4987 {IGP01E1000_PHY_AGC_A,
4988 IGP01E1000_PHY_AGC_B,
4989 IGP01E1000_PHY_AGC_C,
4990 IGP01E1000_PHY_AGC_D};
4991 /* Read the AGC registers for all channels */
4992 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4994 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4998 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5000 /* Value bound check. */
5001 if ((cur_agc_value >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5002 (cur_agc_value == 0))
5003 return -E1000_ERR_PHY;
5005 agc_value += cur_agc_value;
5007 /* Update minimal AGC value. */
5008 if (min_agc_value > cur_agc_value)
5009 min_agc_value = cur_agc_value;
5012 /* Remove the minimal AGC result for length < 50m */
5013 if (agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5014 agc_value -= min_agc_value;
5016 /* Get the average length of the remaining 3 channels */
5017 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5019 /* Get the average length of all the 4 channels. */
5020 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5023 /* Set the range of the calculated length. */
5024 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5025 IGP01E1000_AGC_RANGE) > 0) ?
5026 (e1000_igp_cable_length_table[agc_value] -
5027 IGP01E1000_AGC_RANGE) : 0;
5028 *max_length = e1000_igp_cable_length_table[agc_value] +
5029 IGP01E1000_AGC_RANGE;
5032 return E1000_SUCCESS;
5035 /******************************************************************************
5036 * Check the cable polarity
5038 * hw - Struct containing variables accessed by shared code
5039 * polarity - output parameter : 0 - Polarity is not reversed
5040 * 1 - Polarity is reversed.
5042 * returns: - E1000_ERR_XXX
5045 * For phy's older than IGP, this function simply reads the polarity bit in the
5046 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5047 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5048 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5049 * IGP01E1000_PHY_PCS_INIT_REG.
5050 *****************************************************************************/
5051 static s32 e1000_check_polarity(struct e1000_hw *hw,
5052 e1000_rev_polarity *polarity)
5057 DEBUGFUNC("e1000_check_polarity");
5059 if (hw->phy_type == e1000_phy_m88) {
5060 /* return the Polarity bit in the Status register. */
5061 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5065 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5066 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5067 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5069 } else if (hw->phy_type == e1000_phy_igp) {
5070 /* Read the Status register to check the speed */
5071 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5076 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5077 * find the polarity status */
5078 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5079 IGP01E1000_PSSR_SPEED_1000MBPS) {
5081 /* Read the GIG initialization PCS register (0x00B4) */
5082 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5087 /* Check the polarity bits */
5088 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5089 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5091 /* For 10 Mbps, read the polarity bit in the status register. (for
5092 * 100 Mbps this bit is always 0) */
5093 *polarity = (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5094 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5097 return E1000_SUCCESS;
5100 /******************************************************************************
5101 * Check if Downshift occured
5103 * hw - Struct containing variables accessed by shared code
5104 * downshift - output parameter : 0 - No Downshift ocured.
5105 * 1 - Downshift ocured.
5107 * returns: - E1000_ERR_XXX
5110 * For phy's older than IGP, this function reads the Downshift bit in the Phy
5111 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5112 * Link Health register. In IGP this bit is latched high, so the driver must
5113 * read it immediately after link is established.
5114 *****************************************************************************/
5115 static s32 e1000_check_downshift(struct e1000_hw *hw)
5120 DEBUGFUNC("e1000_check_downshift");
5122 if (hw->phy_type == e1000_phy_igp) {
5123 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5128 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5129 } else if (hw->phy_type == e1000_phy_m88) {
5130 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5135 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5136 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5139 return E1000_SUCCESS;
5142 /*****************************************************************************
5144 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5145 * gigabit link is achieved to improve link quality.
5147 * hw: Struct containing variables accessed by shared code
5149 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5150 * E1000_SUCCESS at any other case.
5152 ****************************************************************************/
5154 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
5157 u16 phy_data, phy_saved_data, speed, duplex, i;
5158 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5159 {IGP01E1000_PHY_AGC_PARAM_A,
5160 IGP01E1000_PHY_AGC_PARAM_B,
5161 IGP01E1000_PHY_AGC_PARAM_C,
5162 IGP01E1000_PHY_AGC_PARAM_D};
5163 u16 min_length, max_length;
5165 DEBUGFUNC("e1000_config_dsp_after_link_change");
5167 if (hw->phy_type != e1000_phy_igp)
5168 return E1000_SUCCESS;
5171 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5173 DEBUGOUT("Error getting link speed and duplex\n");
5177 if (speed == SPEED_1000) {
5179 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
5183 if ((hw->dsp_config_state == e1000_dsp_config_enabled) &&
5184 min_length >= e1000_igp_cable_length_50) {
5186 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5187 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5192 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5194 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5199 hw->dsp_config_state = e1000_dsp_config_activated;
5202 if ((hw->ffe_config_state == e1000_ffe_config_enabled) &&
5203 (min_length < e1000_igp_cable_length_50)) {
5205 u16 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5208 /* clear previous idle error counts */
5209 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5214 for (i = 0; i < ffe_idle_err_timeout; i++) {
5216 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5221 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5222 if (idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5223 hw->ffe_config_state = e1000_ffe_config_active;
5225 ret_val = e1000_write_phy_reg(hw,
5226 IGP01E1000_PHY_DSP_FFE,
5227 IGP01E1000_PHY_DSP_FFE_CM_CP);
5234 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5239 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5240 /* Save off the current value of register 0x2F5B to be restored at
5241 * the end of the routines. */
5242 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5247 /* Disable the PHY transmitter */
5248 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5255 ret_val = e1000_write_phy_reg(hw, 0x0000,
5256 IGP01E1000_IEEE_FORCE_GIGA);
5259 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5260 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5264 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5265 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5267 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5272 ret_val = e1000_write_phy_reg(hw, 0x0000,
5273 IGP01E1000_IEEE_RESTART_AUTONEG);
5279 /* Now enable the transmitter */
5280 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5285 hw->dsp_config_state = e1000_dsp_config_enabled;
5288 if (hw->ffe_config_state == e1000_ffe_config_active) {
5289 /* Save off the current value of register 0x2F5B to be restored at
5290 * the end of the routines. */
5291 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5296 /* Disable the PHY transmitter */
5297 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5304 ret_val = e1000_write_phy_reg(hw, 0x0000,
5305 IGP01E1000_IEEE_FORCE_GIGA);
5308 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5309 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5313 ret_val = e1000_write_phy_reg(hw, 0x0000,
5314 IGP01E1000_IEEE_RESTART_AUTONEG);
5320 /* Now enable the transmitter */
5321 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5326 hw->ffe_config_state = e1000_ffe_config_enabled;
5329 return E1000_SUCCESS;
5332 /*****************************************************************************
5333 * Set PHY to class A mode
5334 * Assumes the following operations will follow to enable the new class mode.
5335 * 1. Do a PHY soft reset
5336 * 2. Restart auto-negotiation or force link.
5338 * hw - Struct containing variables accessed by shared code
5339 ****************************************************************************/
5340 static s32 e1000_set_phy_mode(struct e1000_hw *hw)
5345 DEBUGFUNC("e1000_set_phy_mode");
5347 if ((hw->mac_type == e1000_82545_rev_3) &&
5348 (hw->media_type == e1000_media_type_copper)) {
5349 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5354 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5355 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5356 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5359 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5363 hw->phy_reset_disable = false;
5367 return E1000_SUCCESS;
5370 /*****************************************************************************
5372 * This function sets the lplu state according to the active flag. When
5373 * activating lplu this function also disables smart speed and vise versa.
5374 * lplu will not be activated unless the device autonegotiation advertisment
5375 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5376 * hw: Struct containing variables accessed by shared code
5377 * active - true to enable lplu false to disable lplu.
5379 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5380 * E1000_SUCCESS at any other case.
5382 ****************************************************************************/
5384 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
5388 DEBUGFUNC("e1000_set_d3_lplu_state");
5390 if (hw->phy_type != e1000_phy_igp)
5391 return E1000_SUCCESS;
5393 /* During driver activity LPLU should not be used or it will attain link
5394 * from the lowest speeds starting from 10Mbps. The capability is used for
5395 * Dx transitions and states */
5396 if (hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
5397 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5401 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5407 if (hw->mac_type == e1000_82541_rev_2 ||
5408 hw->mac_type == e1000_82547_rev_2) {
5409 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5410 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5414 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5415 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5421 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5422 * Dx states where the power conservation is most important. During
5423 * driver activity we should enable SmartSpeed, so performance is
5425 if (hw->smart_speed == e1000_smart_speed_on) {
5426 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5431 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5432 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5436 } else if (hw->smart_speed == e1000_smart_speed_off) {
5437 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5442 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5443 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5449 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5450 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5451 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5453 if (hw->mac_type == e1000_82541_rev_2 ||
5454 hw->mac_type == e1000_82547_rev_2) {
5455 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5456 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5460 phy_data |= IGP02E1000_PM_D3_LPLU;
5461 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5467 /* When LPLU is enabled we should disable SmartSpeed */
5468 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5472 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5473 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5478 return E1000_SUCCESS;
5481 /******************************************************************************
5482 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5484 * hw - Struct containing variables accessed by shared code
5485 *****************************************************************************/
5486 static s32 e1000_set_vco_speed(struct e1000_hw *hw)
5489 u16 default_page = 0;
5492 DEBUGFUNC("e1000_set_vco_speed");
5494 switch (hw->mac_type) {
5495 case e1000_82545_rev_3:
5496 case e1000_82546_rev_3:
5499 return E1000_SUCCESS;
5502 /* Set PHY register 30, page 5, bit 8 to 0 */
5504 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5508 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5512 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5516 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5517 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5521 /* Set PHY register 30, page 4, bit 11 to 1 */
5523 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5527 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5531 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5532 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5536 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5540 return E1000_SUCCESS;
5544 /******************************************************************************
5545 * Verifies the hardware needs to allow ARPs to be processed by the host
5547 * hw - Struct containing variables accessed by shared code
5549 * returns: - true/false
5551 *****************************************************************************/
5552 u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5556 if (hw->asf_firmware_present) {
5559 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5560 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5562 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5568 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5574 /* Polarity reversal workaround for forced 10F/10H links. */
5576 /* Disable the transmitter on the PHY */
5578 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5581 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5585 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5589 /* This loop will early-out if the NO link condition has been met. */
5590 for (i = PHY_FORCE_TIME; i > 0; i--) {
5591 /* Read the MII Status Register and wait for Link Status bit
5595 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5599 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5603 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
5607 /* Recommended delay time after link has been lost */
5610 /* Now we will re-enable th transmitter on the PHY */
5612 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5616 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5620 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5624 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5628 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5632 /* This loop will early-out if the link condition has been met. */
5633 for (i = PHY_FORCE_TIME; i > 0; i--) {
5634 /* Read the MII Status Register and wait for Link Status bit
5638 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5642 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5646 if (mii_status_reg & MII_SR_LINK_STATUS) break;
5649 return E1000_SUCCESS;
5652 /*******************************************************************************
5654 * Check for EEPROM Auto Read bit done.
5656 * hw: Struct containing variables accessed by shared code
5658 * returns: - E1000_ERR_RESET if fail to reset MAC
5659 * E1000_SUCCESS at any other case.
5661 ******************************************************************************/
5662 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
5664 DEBUGFUNC("e1000_get_auto_rd_done");
5666 return E1000_SUCCESS;
5669 /***************************************************************************
5670 * Checks if the PHY configuration is done
5672 * hw: Struct containing variables accessed by shared code
5674 * returns: - E1000_ERR_RESET if fail to reset MAC
5675 * E1000_SUCCESS at any other case.
5677 ***************************************************************************/
5678 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
5680 DEBUGFUNC("e1000_get_phy_cfg_done");
5682 return E1000_SUCCESS;
5685 /***************************************************************************
5687 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
5688 * adapter or Eeprom access.
5690 * hw: Struct containing variables accessed by shared code
5692 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
5693 * E1000_SUCCESS at any other case.
5695 ***************************************************************************/
5696 static s32 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
5701 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
5703 if (!hw->eeprom_semaphore_present)
5704 return E1000_SUCCESS;
5706 /* Get the FW semaphore. */
5707 timeout = hw->eeprom.word_size + 1;
5710 swsm |= E1000_SWSM_SWESMBI;
5712 /* if we managed to set the bit we got the semaphore. */
5714 if (swsm & E1000_SWSM_SWESMBI)
5722 /* Release semaphores */
5723 e1000_put_hw_eeprom_semaphore(hw);
5724 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
5725 return -E1000_ERR_EEPROM;
5728 return E1000_SUCCESS;
5731 /***************************************************************************
5732 * This function clears HW semaphore bits.
5734 * hw: Struct containing variables accessed by shared code
5738 ***************************************************************************/
5739 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
5743 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
5745 if (!hw->eeprom_semaphore_present)
5749 swsm &= ~(E1000_SWSM_SWESMBI);