1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Shared functions for accessing and configuring the MAC
35 static s32 e1000_check_downshift(struct e1000_hw *hw);
36 static s32 e1000_check_polarity(struct e1000_hw *hw,
37 e1000_rev_polarity *polarity);
38 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
39 static void e1000_clear_vfta(struct e1000_hw *hw);
40 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
42 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw);
43 static s32 e1000_detect_gig_phy(struct e1000_hw *hw);
44 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw);
45 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
47 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw);
48 static s32 e1000_id_led_init(struct e1000_hw *hw);
49 static void e1000_init_rx_addrs(struct e1000_hw *hw);
50 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
51 struct e1000_phy_info *phy_info);
52 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
54 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
56 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
57 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
58 struct e1000_phy_info *phy_info);
59 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active);
60 static s32 e1000_wait_autoneg(struct e1000_hw *hw);
61 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value);
62 static s32 e1000_set_phy_type(struct e1000_hw *hw);
63 static void e1000_phy_init_script(struct e1000_hw *hw);
64 static s32 e1000_setup_copper_link(struct e1000_hw *hw);
65 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
66 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
67 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw);
68 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw);
69 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
70 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl);
71 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count);
72 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw);
73 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw);
74 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset,
75 u16 words, u16 *data);
76 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
77 u16 words, u16 *data);
78 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw);
79 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd);
80 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd);
81 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count);
82 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
84 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
86 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count);
87 static s32 e1000_acquire_eeprom(struct e1000_hw *hw);
88 static void e1000_release_eeprom(struct e1000_hw *hw);
89 static void e1000_standby_eeprom(struct e1000_hw *hw);
90 static s32 e1000_set_vco_speed(struct e1000_hw *hw);
91 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw);
92 static s32 e1000_set_phy_mode(struct e1000_hw *hw);
93 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
95 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
98 /* IGP cable length table */
100 u16 e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] = {
101 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
102 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
103 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
104 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
105 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
106 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100,
108 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
110 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120,
114 static DEFINE_SPINLOCK(e1000_eeprom_lock);
117 * e1000_set_phy_type - Set the phy type member in the hw struct.
118 * @hw: Struct containing variables accessed by shared code
120 static s32 e1000_set_phy_type(struct e1000_hw *hw)
122 DEBUGFUNC("e1000_set_phy_type");
124 if (hw->mac_type == e1000_undefined)
125 return -E1000_ERR_PHY_TYPE;
127 switch (hw->phy_id) {
128 case M88E1000_E_PHY_ID:
129 case M88E1000_I_PHY_ID:
130 case M88E1011_I_PHY_ID:
131 case M88E1111_I_PHY_ID:
132 hw->phy_type = e1000_phy_m88;
134 case IGP01E1000_I_PHY_ID:
135 if (hw->mac_type == e1000_82541 ||
136 hw->mac_type == e1000_82541_rev_2 ||
137 hw->mac_type == e1000_82547 ||
138 hw->mac_type == e1000_82547_rev_2) {
139 hw->phy_type = e1000_phy_igp;
143 /* Should never have loaded on this device */
144 hw->phy_type = e1000_phy_undefined;
145 return -E1000_ERR_PHY_TYPE;
148 return E1000_SUCCESS;
152 * e1000_phy_init_script - IGP phy init script - initializes the GbE PHY
153 * @hw: Struct containing variables accessed by shared code
155 static void e1000_phy_init_script(struct e1000_hw *hw)
160 DEBUGFUNC("e1000_phy_init_script");
162 if (hw->phy_init_script) {
165 /* Save off the current value of register 0x2F5B to be restored at
166 * the end of this routine. */
167 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
169 /* Disabled the PHY transmitter */
170 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
173 e1000_write_phy_reg(hw, 0x0000, 0x0140);
176 switch (hw->mac_type) {
179 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
180 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
181 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
182 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
183 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
184 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
185 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
186 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
187 e1000_write_phy_reg(hw, 0x2010, 0x0008);
190 case e1000_82541_rev_2:
191 case e1000_82547_rev_2:
192 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
198 e1000_write_phy_reg(hw, 0x0000, 0x3300);
201 /* Now enable the transmitter */
202 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
204 if (hw->mac_type == e1000_82547) {
205 u16 fused, fine, coarse;
207 /* Move to analog registers page */
208 e1000_read_phy_reg(hw,
209 IGP01E1000_ANALOG_SPARE_FUSE_STATUS,
212 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
213 e1000_read_phy_reg(hw,
214 IGP01E1000_ANALOG_FUSE_STATUS,
217 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
219 fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
222 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
224 IGP01E1000_ANALOG_FUSE_COARSE_10;
225 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
227 IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
228 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
231 (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
232 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
234 IGP01E1000_ANALOG_FUSE_COARSE_MASK);
236 e1000_write_phy_reg(hw,
237 IGP01E1000_ANALOG_FUSE_CONTROL,
239 e1000_write_phy_reg(hw,
240 IGP01E1000_ANALOG_FUSE_BYPASS,
241 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
248 * e1000_set_mac_type - Set the mac type member in the hw struct.
249 * @hw: Struct containing variables accessed by shared code
251 s32 e1000_set_mac_type(struct e1000_hw *hw)
253 DEBUGFUNC("e1000_set_mac_type");
255 switch (hw->device_id) {
256 case E1000_DEV_ID_82542:
257 switch (hw->revision_id) {
258 case E1000_82542_2_0_REV_ID:
259 hw->mac_type = e1000_82542_rev2_0;
261 case E1000_82542_2_1_REV_ID:
262 hw->mac_type = e1000_82542_rev2_1;
265 /* Invalid 82542 revision ID */
266 return -E1000_ERR_MAC_TYPE;
269 case E1000_DEV_ID_82543GC_FIBER:
270 case E1000_DEV_ID_82543GC_COPPER:
271 hw->mac_type = e1000_82543;
273 case E1000_DEV_ID_82544EI_COPPER:
274 case E1000_DEV_ID_82544EI_FIBER:
275 case E1000_DEV_ID_82544GC_COPPER:
276 case E1000_DEV_ID_82544GC_LOM:
277 hw->mac_type = e1000_82544;
279 case E1000_DEV_ID_82540EM:
280 case E1000_DEV_ID_82540EM_LOM:
281 case E1000_DEV_ID_82540EP:
282 case E1000_DEV_ID_82540EP_LOM:
283 case E1000_DEV_ID_82540EP_LP:
284 hw->mac_type = e1000_82540;
286 case E1000_DEV_ID_82545EM_COPPER:
287 case E1000_DEV_ID_82545EM_FIBER:
288 hw->mac_type = e1000_82545;
290 case E1000_DEV_ID_82545GM_COPPER:
291 case E1000_DEV_ID_82545GM_FIBER:
292 case E1000_DEV_ID_82545GM_SERDES:
293 hw->mac_type = e1000_82545_rev_3;
295 case E1000_DEV_ID_82546EB_COPPER:
296 case E1000_DEV_ID_82546EB_FIBER:
297 case E1000_DEV_ID_82546EB_QUAD_COPPER:
298 hw->mac_type = e1000_82546;
300 case E1000_DEV_ID_82546GB_COPPER:
301 case E1000_DEV_ID_82546GB_FIBER:
302 case E1000_DEV_ID_82546GB_SERDES:
303 case E1000_DEV_ID_82546GB_PCIE:
304 case E1000_DEV_ID_82546GB_QUAD_COPPER:
305 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
306 hw->mac_type = e1000_82546_rev_3;
308 case E1000_DEV_ID_82541EI:
309 case E1000_DEV_ID_82541EI_MOBILE:
310 case E1000_DEV_ID_82541ER_LOM:
311 hw->mac_type = e1000_82541;
313 case E1000_DEV_ID_82541ER:
314 case E1000_DEV_ID_82541GI:
315 case E1000_DEV_ID_82541GI_LF:
316 case E1000_DEV_ID_82541GI_MOBILE:
317 hw->mac_type = e1000_82541_rev_2;
319 case E1000_DEV_ID_82547EI:
320 case E1000_DEV_ID_82547EI_MOBILE:
321 hw->mac_type = e1000_82547;
323 case E1000_DEV_ID_82547GI:
324 hw->mac_type = e1000_82547_rev_2;
327 /* Should never have loaded on this device */
328 return -E1000_ERR_MAC_TYPE;
331 switch (hw->mac_type) {
334 case e1000_82541_rev_2:
335 case e1000_82547_rev_2:
336 hw->asf_firmware_present = true;
342 /* The 82543 chip does not count tx_carrier_errors properly in
345 if (hw->mac_type == e1000_82543)
346 hw->bad_tx_carr_stats_fd = true;
348 if (hw->mac_type > e1000_82544)
349 hw->has_smbus = true;
351 return E1000_SUCCESS;
355 * e1000_set_media_type - Set media type and TBI compatibility.
356 * @hw: Struct containing variables accessed by shared code
358 void e1000_set_media_type(struct e1000_hw *hw)
362 DEBUGFUNC("e1000_set_media_type");
364 if (hw->mac_type != e1000_82543) {
365 /* tbi_compatibility is only valid on 82543 */
366 hw->tbi_compatibility_en = false;
369 switch (hw->device_id) {
370 case E1000_DEV_ID_82545GM_SERDES:
371 case E1000_DEV_ID_82546GB_SERDES:
372 hw->media_type = e1000_media_type_internal_serdes;
375 switch (hw->mac_type) {
376 case e1000_82542_rev2_0:
377 case e1000_82542_rev2_1:
378 hw->media_type = e1000_media_type_fiber;
381 status = er32(STATUS);
382 if (status & E1000_STATUS_TBIMODE) {
383 hw->media_type = e1000_media_type_fiber;
384 /* tbi_compatibility not valid on fiber */
385 hw->tbi_compatibility_en = false;
387 hw->media_type = e1000_media_type_copper;
395 * e1000_reset_hw: reset the hardware completely
396 * @hw: Struct containing variables accessed by shared code
398 * Reset the transmit and receive units; mask and clear all interrupts.
400 s32 e1000_reset_hw(struct e1000_hw *hw)
409 DEBUGFUNC("e1000_reset_hw");
411 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
412 if (hw->mac_type == e1000_82542_rev2_0) {
413 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
414 e1000_pci_clear_mwi(hw);
417 /* Clear interrupt mask to stop board from generating interrupts */
418 DEBUGOUT("Masking off all interrupts\n");
419 ew32(IMC, 0xffffffff);
421 /* Disable the Transmit and Receive units. Then delay to allow
422 * any pending transactions to complete before we hit the MAC with
426 ew32(TCTL, E1000_TCTL_PSP);
429 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
430 hw->tbi_compatibility_on = false;
432 /* Delay to allow any outstanding PCI transactions to complete before
433 * resetting the device
439 /* Must reset the PHY before resetting the MAC */
440 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
441 ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
445 /* Issue a global reset to the MAC. This will reset the chip's
446 * transmit, receive, DMA, and link units. It will not effect
447 * the current PCI configuration. The global reset bit is self-
448 * clearing, and should clear within a microsecond.
450 DEBUGOUT("Issuing a global reset to MAC\n");
452 switch (hw->mac_type) {
458 case e1000_82541_rev_2:
459 /* These controllers can't ack the 64-bit write when issuing the
460 * reset, so use IO-mapping as a workaround to issue the reset */
461 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
463 case e1000_82545_rev_3:
464 case e1000_82546_rev_3:
465 /* Reset is performed on a shadow of the control register */
466 ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST));
469 ew32(CTRL, (ctrl | E1000_CTRL_RST));
473 /* After MAC reset, force reload of EEPROM to restore power-on settings to
474 * device. Later controllers reload the EEPROM automatically, so just wait
475 * for reload to complete.
477 switch (hw->mac_type) {
478 case e1000_82542_rev2_0:
479 case e1000_82542_rev2_1:
482 /* Wait for reset to complete */
484 ctrl_ext = er32(CTRL_EXT);
485 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
486 ew32(CTRL_EXT, ctrl_ext);
488 /* Wait for EEPROM reload */
492 case e1000_82541_rev_2:
494 case e1000_82547_rev_2:
495 /* Wait for EEPROM reload */
499 /* Auto read done will delay 5ms or poll based on mac type */
500 ret_val = e1000_get_auto_rd_done(hw);
506 /* Disable HW ARPs on ASF enabled adapters */
507 if (hw->mac_type >= e1000_82540) {
509 manc &= ~(E1000_MANC_ARP_EN);
513 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
514 e1000_phy_init_script(hw);
516 /* Configure activity LED after PHY reset */
517 led_ctrl = er32(LEDCTL);
518 led_ctrl &= IGP_ACTIVITY_LED_MASK;
519 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
520 ew32(LEDCTL, led_ctrl);
523 /* Clear interrupt mask to stop board from generating interrupts */
524 DEBUGOUT("Masking off all interrupts\n");
525 ew32(IMC, 0xffffffff);
527 /* Clear any pending interrupt events. */
530 /* If MWI was previously enabled, reenable it. */
531 if (hw->mac_type == e1000_82542_rev2_0) {
532 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
533 e1000_pci_set_mwi(hw);
536 return E1000_SUCCESS;
540 * e1000_init_hw: Performs basic configuration of the adapter.
541 * @hw: Struct containing variables accessed by shared code
543 * Assumes that the controller has previously been reset and is in a
544 * post-reset uninitialized state. Initializes the receive address registers,
545 * multicast table, and VLAN filter table. Calls routines to setup link
546 * configuration and flow control settings. Clears all on-chip counters. Leaves
547 * the transmit and receive units disabled and uninitialized.
549 s32 e1000_init_hw(struct e1000_hw *hw)
557 DEBUGFUNC("e1000_init_hw");
559 /* Initialize Identification LED */
560 ret_val = e1000_id_led_init(hw);
562 DEBUGOUT("Error Initializing Identification LED\n");
566 /* Set the media type and TBI compatibility */
567 e1000_set_media_type(hw);
569 /* Disabling VLAN filtering. */
570 DEBUGOUT("Initializing the IEEE VLAN\n");
571 if (hw->mac_type < e1000_82545_rev_3)
573 e1000_clear_vfta(hw);
575 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
576 if (hw->mac_type == e1000_82542_rev2_0) {
577 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
578 e1000_pci_clear_mwi(hw);
579 ew32(RCTL, E1000_RCTL_RST);
584 /* Setup the receive address. This involves initializing all of the Receive
585 * Address Registers (RARs 0 - 15).
587 e1000_init_rx_addrs(hw);
589 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
590 if (hw->mac_type == e1000_82542_rev2_0) {
594 if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
595 e1000_pci_set_mwi(hw);
598 /* Zero out the Multicast HASH table */
599 DEBUGOUT("Zeroing the MTA\n");
600 mta_size = E1000_MC_TBL_SIZE;
601 for (i = 0; i < mta_size; i++) {
602 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
603 /* use write flush to prevent Memory Write Block (MWB) from
604 * occurring when accessing our register space */
608 /* Set the PCI priority bit correctly in the CTRL register. This
609 * determines if the adapter gives priority to receives, or if it
610 * gives equal priority to transmits and receives. Valid only on
611 * 82542 and 82543 silicon.
613 if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
615 ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
618 switch (hw->mac_type) {
619 case e1000_82545_rev_3:
620 case e1000_82546_rev_3:
623 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
624 if (hw->bus_type == e1000_bus_type_pcix
625 && e1000_pcix_get_mmrbc(hw) > 2048)
626 e1000_pcix_set_mmrbc(hw, 2048);
630 /* Call a subroutine to configure the link and setup flow control. */
631 ret_val = e1000_setup_link(hw);
633 /* Set the transmit descriptor write-back policy */
634 if (hw->mac_type > e1000_82544) {
637 (ctrl & ~E1000_TXDCTL_WTHRESH) |
638 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);
662 * e1000_adjust_serdes_amplitude - Adjust SERDES output amplitude based on EEPROM setting.
663 * @hw: Struct containing variables accessed by shared code.
665 static s32 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
670 DEBUGFUNC("e1000_adjust_serdes_amplitude");
672 if (hw->media_type != e1000_media_type_internal_serdes)
673 return E1000_SUCCESS;
675 switch (hw->mac_type) {
676 case e1000_82545_rev_3:
677 case e1000_82546_rev_3:
680 return E1000_SUCCESS;
683 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
689 if (eeprom_data != EEPROM_RESERVED_WORD) {
690 /* Adjust SERDES output amplitude only. */
691 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
693 e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
698 return E1000_SUCCESS;
702 * e1000_setup_link - 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 appropriate 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.
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) : e1000_setup_fiber_serdes_link(hw);
780 /* Initialize the flow control address, type, and PAUSE timer
781 * registers to their default values. This is done even if flow
782 * control is disabled, because it does not hurt anything to
783 * initialize these registers.
786 ("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);
819 * e1000_setup_fiber_serdes_link - prepare fiber or serdes link
820 * @hw: Struct containing variables accessed by shared code
822 * Manipulates Physical Coding Sublayer functions in order to configure
823 * link. Assumes the hardware has been previously reset and the transmitter
824 * and receiver are not enabled.
826 static s32 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
835 DEBUGFUNC("e1000_setup_fiber_serdes_link");
837 /* On adapters with a MAC newer than 82544, SWDP 1 will be
838 * set when the optics detect a signal. On older adapters, it will be
839 * cleared when there is a signal. This applies to fiber media only.
840 * If we're on serdes media, adjust the output amplitude to value
844 if (hw->media_type == e1000_media_type_fiber)
845 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
847 ret_val = e1000_adjust_serdes_amplitude(hw);
851 /* Take the link out of reset */
852 ctrl &= ~(E1000_CTRL_LRST);
854 /* Adjust VCO speed to improve BER performance */
855 ret_val = e1000_set_vco_speed(hw);
859 e1000_config_collision_dist(hw);
861 /* Check for a software override of the flow control settings, and setup
862 * the device accordingly. If auto-negotiation is enabled, then software
863 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
864 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
865 * auto-negotiation is disabled, then software will have to manually
866 * configure the two flow control enable bits in the CTRL register.
868 * The possible values of the "fc" parameter are:
869 * 0: Flow control is completely disabled
870 * 1: Rx flow control is enabled (we can receive pause frames, but
871 * not send pause frames).
872 * 2: Tx flow control is enabled (we can send pause frames but we do
873 * not support receiving pause frames).
874 * 3: Both Rx and TX flow control (symmetric) are enabled.
878 /* Flow control is completely disabled by a software over-ride. */
879 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
881 case E1000_FC_RX_PAUSE:
882 /* RX Flow control is enabled and TX Flow control is disabled by a
883 * software over-ride. Since there really isn't a way to advertise
884 * that we are capable of RX Pause ONLY, we will advertise that we
885 * support both symmetric and asymmetric RX PAUSE. Later, we will
886 * disable the adapter's ability to send PAUSE frames.
888 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
890 case E1000_FC_TX_PAUSE:
891 /* TX Flow control is enabled, and RX Flow control is disabled, by a
892 * software over-ride.
894 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
897 /* Flow control (both RX and TX) is enabled by a software over-ride. */
898 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
901 DEBUGOUT("Flow control param set incorrectly\n");
902 return -E1000_ERR_CONFIG;
906 /* Since auto-negotiation is enabled, take the link out of reset (the link
907 * will be in reset, because we previously reset the chip). This will
908 * restart auto-negotiation. If auto-negotiation is successful then the
909 * link-up status bit will be set and the flow control enable bits (RFCE
910 * and TFCE) will be set according to their negotiated value.
912 DEBUGOUT("Auto-negotiation enabled\n");
921 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
922 * indication in the Device Status Register. Time-out if a link isn't
923 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
924 * less than 500 milliseconds even if the other end is doing it in SW).
925 * For internal serdes, we just assume a signal is present, then poll.
927 if (hw->media_type == e1000_media_type_internal_serdes ||
928 (er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
929 DEBUGOUT("Looking for Link\n");
930 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
932 status = er32(STATUS);
933 if (status & E1000_STATUS_LU)
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;
961 * e1000_copper_link_preconfig - early configuration for copper
962 * @hw: Struct containing variables accessed by shared code
964 * Make sure we have a valid PHY and change PHY mode before link setup.
966 static s32 e1000_copper_link_preconfig(struct e1000_hw *hw)
972 DEBUGFUNC("e1000_copper_link_preconfig");
975 /* With 82543, we need to force speed and duplex on the MAC equal to what
976 * the PHY speed and duplex configuration is. In addition, we need to
977 * perform a hardware reset on the PHY to take it out of reset.
979 if (hw->mac_type > e1000_82543) {
980 ctrl |= E1000_CTRL_SLU;
981 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
985 (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
987 ret_val = e1000_phy_hw_reset(hw);
992 /* Make sure we have a valid PHY */
993 ret_val = e1000_detect_gig_phy(hw);
995 DEBUGOUT("Error, did not detect valid phy.\n");
998 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1000 /* Set PHY to class A mode (if necessary) */
1001 ret_val = e1000_set_phy_mode(hw);
1005 if ((hw->mac_type == e1000_82545_rev_3) ||
1006 (hw->mac_type == e1000_82546_rev_3)) {
1008 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1009 phy_data |= 0x00000008;
1011 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1014 if (hw->mac_type <= e1000_82543 ||
1015 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1016 hw->mac_type == e1000_82541_rev_2
1017 || hw->mac_type == e1000_82547_rev_2)
1018 hw->phy_reset_disable = false;
1020 return E1000_SUCCESS;
1024 * e1000_copper_link_igp_setup - Copper link setup for e1000_phy_igp series.
1025 * @hw: Struct containing variables accessed by shared code
1027 static s32 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1033 DEBUGFUNC("e1000_copper_link_igp_setup");
1035 if (hw->phy_reset_disable)
1036 return E1000_SUCCESS;
1038 ret_val = e1000_phy_reset(hw);
1040 DEBUGOUT("Error Resetting the PHY\n");
1044 /* Wait 15ms for MAC to configure PHY from eeprom settings */
1046 /* Configure activity LED after PHY reset */
1047 led_ctrl = er32(LEDCTL);
1048 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1049 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1050 ew32(LEDCTL, led_ctrl);
1052 /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
1053 if (hw->phy_type == e1000_phy_igp) {
1054 /* disable lplu d3 during driver init */
1055 ret_val = e1000_set_d3_lplu_state(hw, false);
1057 DEBUGOUT("Error Disabling LPLU D3\n");
1062 /* Configure mdi-mdix settings */
1063 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1067 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1068 hw->dsp_config_state = e1000_dsp_config_disabled;
1069 /* Force MDI for earlier revs of the IGP PHY */
1071 ~(IGP01E1000_PSCR_AUTO_MDIX |
1072 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1076 hw->dsp_config_state = e1000_dsp_config_enabled;
1077 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1081 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1084 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1088 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1092 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1096 /* set auto-master slave resolution settings */
1098 e1000_ms_type phy_ms_setting = hw->master_slave;
1100 if (hw->ffe_config_state == e1000_ffe_config_active)
1101 hw->ffe_config_state = e1000_ffe_config_enabled;
1103 if (hw->dsp_config_state == e1000_dsp_config_activated)
1104 hw->dsp_config_state = e1000_dsp_config_enabled;
1106 /* when autonegotiation advertisement is only 1000Mbps then we
1107 * should disable SmartSpeed and enable Auto MasterSlave
1108 * resolution as hardware default. */
1109 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1110 /* Disable SmartSpeed */
1112 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1116 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1118 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1122 /* Set auto Master/Slave resolution process */
1124 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1127 phy_data &= ~CR_1000T_MS_ENABLE;
1129 e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1134 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1138 /* load defaults for future use */
1139 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1140 ((phy_data & CR_1000T_MS_VALUE) ?
1141 e1000_ms_force_master :
1142 e1000_ms_force_slave) : e1000_ms_auto;
1144 switch (phy_ms_setting) {
1145 case e1000_ms_force_master:
1146 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1148 case e1000_ms_force_slave:
1149 phy_data |= CR_1000T_MS_ENABLE;
1150 phy_data &= ~(CR_1000T_MS_VALUE);
1153 phy_data &= ~CR_1000T_MS_ENABLE;
1157 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1162 return E1000_SUCCESS;
1166 * e1000_copper_link_mgp_setup - Copper link setup for e1000_phy_m88 series.
1167 * @hw: Struct containing variables accessed by shared code
1169 static s32 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1174 DEBUGFUNC("e1000_copper_link_mgp_setup");
1176 if (hw->phy_reset_disable)
1177 return E1000_SUCCESS;
1179 /* Enable CRS on TX. This must be set for half-duplex operation. */
1180 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1184 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1187 * MDI/MDI-X = 0 (default)
1188 * 0 - Auto for all speeds
1191 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1193 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1197 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1200 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1203 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1207 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1212 * disable_polarity_correction = 0 (default)
1213 * Automatic Correction for Reversed Cable Polarity
1217 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1218 if (hw->disable_polarity_correction == 1)
1219 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1220 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1224 if (hw->phy_revision < M88E1011_I_REV_4) {
1225 /* Force TX_CLK in the Extended PHY Specific Control Register
1229 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1234 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1236 if ((hw->phy_revision == E1000_REVISION_2) &&
1237 (hw->phy_id == M88E1111_I_PHY_ID)) {
1238 /* Vidalia Phy, set the downshift counter to 5x */
1239 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
1240 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
1241 ret_val = e1000_write_phy_reg(hw,
1242 M88E1000_EXT_PHY_SPEC_CTRL,
1247 /* Configure Master and Slave downshift values */
1248 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1249 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1250 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1251 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1252 ret_val = e1000_write_phy_reg(hw,
1253 M88E1000_EXT_PHY_SPEC_CTRL,
1260 /* SW Reset the PHY so all changes take effect */
1261 ret_val = e1000_phy_reset(hw);
1263 DEBUGOUT("Error Resetting the PHY\n");
1267 return E1000_SUCCESS;
1271 * e1000_copper_link_autoneg - setup auto-neg
1272 * @hw: Struct containing variables accessed by shared code
1274 * Setup auto-negotiation and flow control advertisements,
1275 * and then perform auto-negotiation.
1277 static s32 e1000_copper_link_autoneg(struct e1000_hw *hw)
1282 DEBUGFUNC("e1000_copper_link_autoneg");
1284 /* Perform some bounds checking on the hw->autoneg_advertised
1285 * parameter. If this variable is zero, then set it to the default.
1287 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1289 /* If autoneg_advertised is zero, we assume it was not defaulted
1290 * by the calling code so we set to advertise full capability.
1292 if (hw->autoneg_advertised == 0)
1293 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1295 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1296 ret_val = e1000_phy_setup_autoneg(hw);
1298 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1301 DEBUGOUT("Restarting Auto-Neg\n");
1303 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1304 * the Auto Neg Restart bit in the PHY control register.
1306 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1310 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1311 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1315 /* Does the user want to wait for Auto-Neg to complete here, or
1316 * check at a later time (for example, callback routine).
1318 if (hw->wait_autoneg_complete) {
1319 ret_val = e1000_wait_autoneg(hw);
1322 ("Error while waiting for autoneg to complete\n");
1327 hw->get_link_status = true;
1329 return E1000_SUCCESS;
1333 * e1000_copper_link_postconfig - post link setup
1334 * @hw: Struct containing variables accessed by shared code
1336 * Config the MAC and the PHY after link is up.
1337 * 1) Set up the MAC to the current PHY speed/duplex
1338 * if we are on 82543. If we
1339 * are on newer silicon, we only need to configure
1340 * collision distance in the Transmit Control Register.
1341 * 2) Set up flow control on the MAC to that established with
1343 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1345 static s32 e1000_copper_link_postconfig(struct e1000_hw *hw)
1348 DEBUGFUNC("e1000_copper_link_postconfig");
1350 if (hw->mac_type >= e1000_82544) {
1351 e1000_config_collision_dist(hw);
1353 ret_val = e1000_config_mac_to_phy(hw);
1355 DEBUGOUT("Error configuring MAC to PHY settings\n");
1359 ret_val = e1000_config_fc_after_link_up(hw);
1361 DEBUGOUT("Error Configuring Flow Control\n");
1365 /* Config DSP to improve Giga link quality */
1366 if (hw->phy_type == e1000_phy_igp) {
1367 ret_val = e1000_config_dsp_after_link_change(hw, true);
1369 DEBUGOUT("Error Configuring DSP after link up\n");
1374 return E1000_SUCCESS;
1378 * e1000_setup_copper_link - phy/speed/duplex setting
1379 * @hw: Struct containing variables accessed by shared code
1381 * Detects which PHY is present and sets up the speed and duplex
1383 static s32 e1000_setup_copper_link(struct e1000_hw *hw)
1389 DEBUGFUNC("e1000_setup_copper_link");
1391 /* Check if it is a valid PHY and set PHY mode if necessary. */
1392 ret_val = e1000_copper_link_preconfig(hw);
1396 if (hw->phy_type == e1000_phy_igp) {
1397 ret_val = e1000_copper_link_igp_setup(hw);
1400 } else if (hw->phy_type == e1000_phy_m88) {
1401 ret_val = e1000_copper_link_mgp_setup(hw);
1407 /* Setup autoneg and flow control advertisement
1408 * and perform autonegotiation */
1409 ret_val = e1000_copper_link_autoneg(hw);
1413 /* PHY will be set to 10H, 10F, 100H,or 100F
1414 * depending on value from forced_speed_duplex. */
1415 DEBUGOUT("Forcing speed and duplex\n");
1416 ret_val = e1000_phy_force_speed_duplex(hw);
1418 DEBUGOUT("Error Forcing Speed and Duplex\n");
1423 /* Check link status. Wait up to 100 microseconds for link to become
1426 for (i = 0; i < 10; i++) {
1427 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1430 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1434 if (phy_data & MII_SR_LINK_STATUS) {
1435 /* Config the MAC and PHY after link is up */
1436 ret_val = e1000_copper_link_postconfig(hw);
1440 DEBUGOUT("Valid link established!!!\n");
1441 return E1000_SUCCESS;
1446 DEBUGOUT("Unable to establish link!!!\n");
1447 return E1000_SUCCESS;
1451 * e1000_phy_setup_autoneg - phy settings
1452 * @hw: Struct containing variables accessed by shared code
1454 * Configures PHY autoneg and flow control advertisement settings
1456 s32 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1459 u16 mii_autoneg_adv_reg;
1460 u16 mii_1000t_ctrl_reg;
1462 DEBUGFUNC("e1000_phy_setup_autoneg");
1464 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1465 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1469 /* Read the MII 1000Base-T Control Register (Address 9). */
1471 e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1475 /* Need to parse both autoneg_advertised and fc and set up
1476 * the appropriate PHY registers. First we will parse for
1477 * autoneg_advertised software override. Since we can advertise
1478 * a plethora of combinations, we need to check each bit
1482 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1483 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1484 * the 1000Base-T Control Register (Address 9).
1486 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1487 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1489 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1491 /* Do we want to advertise 10 Mb Half Duplex? */
1492 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
1493 DEBUGOUT("Advertise 10mb Half duplex\n");
1494 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1497 /* Do we want to advertise 10 Mb Full Duplex? */
1498 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
1499 DEBUGOUT("Advertise 10mb Full duplex\n");
1500 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1503 /* Do we want to advertise 100 Mb Half Duplex? */
1504 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
1505 DEBUGOUT("Advertise 100mb Half duplex\n");
1506 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1509 /* Do we want to advertise 100 Mb Full Duplex? */
1510 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
1511 DEBUGOUT("Advertise 100mb Full duplex\n");
1512 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1515 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1516 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1518 ("Advertise 1000mb Half duplex requested, request denied!\n");
1521 /* Do we want to advertise 1000 Mb Full Duplex? */
1522 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1523 DEBUGOUT("Advertise 1000mb Full duplex\n");
1524 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1527 /* Check for a software override of the flow control settings, and
1528 * setup the PHY advertisement registers accordingly. If
1529 * auto-negotiation is enabled, then software will have to set the
1530 * "PAUSE" bits to the correct value in the Auto-Negotiation
1531 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1533 * The possible values of the "fc" parameter are:
1534 * 0: Flow control is completely disabled
1535 * 1: Rx flow control is enabled (we can receive pause frames
1536 * but not send pause frames).
1537 * 2: Tx flow control is enabled (we can send pause frames
1538 * but we do not support receiving pause frames).
1539 * 3: Both Rx and TX flow control (symmetric) are enabled.
1540 * other: No software override. The flow control configuration
1541 * in the EEPROM is used.
1544 case E1000_FC_NONE: /* 0 */
1545 /* Flow control (RX & TX) is completely disabled by a
1546 * software over-ride.
1548 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1550 case E1000_FC_RX_PAUSE: /* 1 */
1551 /* RX Flow control is enabled, and TX Flow control is
1552 * disabled, by a software over-ride.
1554 /* Since there really isn't a way to advertise that we are
1555 * capable of RX Pause ONLY, we will advertise that we
1556 * support both symmetric and asymmetric RX PAUSE. Later
1557 * (in e1000_config_fc_after_link_up) we will disable the
1558 *hw's ability to send PAUSE frames.
1560 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1562 case E1000_FC_TX_PAUSE: /* 2 */
1563 /* TX Flow control is enabled, and RX Flow control is
1564 * disabled, by a software over-ride.
1566 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1567 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1569 case E1000_FC_FULL: /* 3 */
1570 /* Flow control (both RX and TX) is enabled by a software
1573 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1576 DEBUGOUT("Flow control param set incorrectly\n");
1577 return -E1000_ERR_CONFIG;
1580 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1584 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1586 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1590 return E1000_SUCCESS;
1594 * e1000_phy_force_speed_duplex - force link settings
1595 * @hw: Struct containing variables accessed by shared code
1597 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1599 static s32 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1608 DEBUGFUNC("e1000_phy_force_speed_duplex");
1610 /* Turn off Flow control if we are forcing speed and duplex. */
1611 hw->fc = E1000_FC_NONE;
1613 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1615 /* Read the Device Control Register. */
1618 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1619 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1620 ctrl &= ~(DEVICE_SPEED_MASK);
1622 /* Clear the Auto Speed Detect Enable bit. */
1623 ctrl &= ~E1000_CTRL_ASDE;
1625 /* Read the MII Control Register. */
1626 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1630 /* We need to disable autoneg in order to force link and duplex. */
1632 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1634 /* Are we forcing Full or Half Duplex? */
1635 if (hw->forced_speed_duplex == e1000_100_full ||
1636 hw->forced_speed_duplex == e1000_10_full) {
1637 /* We want to force full duplex so we SET the full duplex bits in the
1638 * Device and MII Control Registers.
1640 ctrl |= E1000_CTRL_FD;
1641 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1642 DEBUGOUT("Full Duplex\n");
1644 /* We want to force half duplex so we CLEAR the full duplex bits in
1645 * the Device and MII Control Registers.
1647 ctrl &= ~E1000_CTRL_FD;
1648 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1649 DEBUGOUT("Half Duplex\n");
1652 /* Are we forcing 100Mbps??? */
1653 if (hw->forced_speed_duplex == e1000_100_full ||
1654 hw->forced_speed_duplex == e1000_100_half) {
1655 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1656 ctrl |= E1000_CTRL_SPD_100;
1657 mii_ctrl_reg |= MII_CR_SPEED_100;
1658 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1659 DEBUGOUT("Forcing 100mb ");
1661 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1662 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1663 mii_ctrl_reg |= MII_CR_SPEED_10;
1664 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1665 DEBUGOUT("Forcing 10mb ");
1668 e1000_config_collision_dist(hw);
1670 /* Write the configured values back to the Device Control Reg. */
1673 if (hw->phy_type == e1000_phy_m88) {
1675 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1679 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1680 * forced whenever speed are duplex are forced.
1682 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1684 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1688 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1690 /* Need to reset the PHY or these changes will be ignored */
1691 mii_ctrl_reg |= MII_CR_RESET;
1693 /* Disable MDI-X support for 10/100 */
1695 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1696 * forced whenever speed or duplex are forced.
1699 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1703 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1704 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1707 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1712 /* Write back the modified PHY MII control register. */
1713 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1719 /* The wait_autoneg_complete flag may be a little misleading here.
1720 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1721 * But we do want to delay for a period while forcing only so we
1722 * don't generate false No Link messages. So we will wait here
1723 * only if the user has set wait_autoneg_complete to 1, which is
1726 if (hw->wait_autoneg_complete) {
1727 /* We will wait for autoneg to complete. */
1728 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1731 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1732 for (i = PHY_FORCE_TIME; i > 0; i--) {
1733 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1737 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1742 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1746 if (mii_status_reg & MII_SR_LINK_STATUS)
1750 if ((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1751 /* We didn't get link. Reset the DSP and wait again for link. */
1752 ret_val = e1000_phy_reset_dsp(hw);
1754 DEBUGOUT("Error Resetting PHY DSP\n");
1758 /* This loop will early-out if the link condition has been met. */
1759 for (i = PHY_FORCE_TIME; i > 0; i--) {
1760 if (mii_status_reg & MII_SR_LINK_STATUS)
1763 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1767 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1772 e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1778 if (hw->phy_type == e1000_phy_m88) {
1779 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1780 * Extended PHY Specific Control Register to 25MHz clock. This value
1781 * defaults back to a 2.5MHz clock when the PHY is reset.
1784 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1789 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1791 e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1796 /* In addition, because of the s/w reset above, we need to enable CRS on
1797 * TX. This must be set for both full and half duplex operation.
1800 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1804 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1806 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1810 if ((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543)
1812 && (hw->forced_speed_duplex == e1000_10_full
1813 || hw->forced_speed_duplex == e1000_10_half)) {
1814 ret_val = e1000_polarity_reversal_workaround(hw);
1819 return E1000_SUCCESS;
1823 * e1000_config_collision_dist - set collision distance register
1824 * @hw: Struct containing variables accessed by shared code
1826 * Sets the collision distance in the Transmit Control register.
1827 * Link should have been established previously. Reads the speed and duplex
1828 * information from the Device Status register.
1830 void e1000_config_collision_dist(struct e1000_hw *hw)
1832 u32 tctl, coll_dist;
1834 DEBUGFUNC("e1000_config_collision_dist");
1836 if (hw->mac_type < e1000_82543)
1837 coll_dist = E1000_COLLISION_DISTANCE_82542;
1839 coll_dist = E1000_COLLISION_DISTANCE;
1843 tctl &= ~E1000_TCTL_COLD;
1844 tctl |= coll_dist << E1000_COLD_SHIFT;
1847 E1000_WRITE_FLUSH();
1851 * e1000_config_mac_to_phy - sync phy and mac settings
1852 * @hw: Struct containing variables accessed by shared code
1853 * @mii_reg: data to write to the MII control register
1855 * Sets MAC speed and duplex settings to reflect the those in the PHY
1856 * The contents of the PHY register containing the needed information need to
1859 static s32 e1000_config_mac_to_phy(struct e1000_hw *hw)
1865 DEBUGFUNC("e1000_config_mac_to_phy");
1867 /* 82544 or newer MAC, Auto Speed Detection takes care of
1868 * MAC speed/duplex configuration.*/
1869 if (hw->mac_type >= e1000_82544)
1870 return E1000_SUCCESS;
1872 /* Read the Device Control Register and set the bits to Force Speed
1876 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1877 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1879 /* Set up duplex in the Device Control and Transmit Control
1880 * registers depending on negotiated values.
1882 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1886 if (phy_data & M88E1000_PSSR_DPLX)
1887 ctrl |= E1000_CTRL_FD;
1889 ctrl &= ~E1000_CTRL_FD;
1891 e1000_config_collision_dist(hw);
1893 /* Set up speed in the Device Control register depending on
1894 * negotiated values.
1896 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1897 ctrl |= E1000_CTRL_SPD_1000;
1898 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1899 ctrl |= E1000_CTRL_SPD_100;
1901 /* Write the configured values back to the Device Control Reg. */
1903 return E1000_SUCCESS;
1907 * e1000_force_mac_fc - force flow control settings
1908 * @hw: Struct containing variables accessed by shared code
1910 * Forces the MAC's flow control settings.
1911 * Sets the TFCE and RFCE bits in the device control register to reflect
1912 * the adapter settings. TFCE and RFCE need to be explicitly set by
1913 * software when a Copper PHY is used because autonegotiation is managed
1914 * by the PHY rather than the MAC. Software must also configure these
1915 * bits when link is forced on a fiber connection.
1917 s32 e1000_force_mac_fc(struct e1000_hw *hw)
1921 DEBUGFUNC("e1000_force_mac_fc");
1923 /* Get the current configuration of the Device Control Register */
1926 /* Because we didn't get link via the internal auto-negotiation
1927 * mechanism (we either forced link or we got link via PHY
1928 * auto-neg), we have to manually enable/disable transmit an
1929 * receive flow control.
1931 * The "Case" statement below enables/disable flow control
1932 * according to the "hw->fc" parameter.
1934 * The possible values of the "fc" parameter are:
1935 * 0: Flow control is completely disabled
1936 * 1: Rx flow control is enabled (we can receive pause
1937 * frames but not send pause frames).
1938 * 2: Tx flow control is enabled (we can send pause frames
1939 * frames but we do not receive pause frames).
1940 * 3: Both Rx and TX flow control (symmetric) is enabled.
1941 * other: No other values should be possible at this point.
1946 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1948 case E1000_FC_RX_PAUSE:
1949 ctrl &= (~E1000_CTRL_TFCE);
1950 ctrl |= E1000_CTRL_RFCE;
1952 case E1000_FC_TX_PAUSE:
1953 ctrl &= (~E1000_CTRL_RFCE);
1954 ctrl |= E1000_CTRL_TFCE;
1957 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1960 DEBUGOUT("Flow control param set incorrectly\n");
1961 return -E1000_ERR_CONFIG;
1964 /* Disable TX Flow Control for 82542 (rev 2.0) */
1965 if (hw->mac_type == e1000_82542_rev2_0)
1966 ctrl &= (~E1000_CTRL_TFCE);
1969 return E1000_SUCCESS;
1973 * e1000_config_fc_after_link_up - configure flow control after autoneg
1974 * @hw: Struct containing variables accessed by shared code
1976 * Configures flow control settings after link is established
1977 * Should be called immediately after a valid link has been established.
1978 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1979 * and autonegotiation is enabled, the MAC flow control settings will be set
1980 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1981 * and RFCE bits will be automatically set to the negotiated flow control mode.
1983 static s32 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1987 u16 mii_nway_adv_reg;
1988 u16 mii_nway_lp_ability_reg;
1992 DEBUGFUNC("e1000_config_fc_after_link_up");
1994 /* Check for the case where we have fiber media and auto-neg failed
1995 * so we had to force link. In this case, we need to force the
1996 * configuration of the MAC to match the "fc" parameter.
1998 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
1999 || ((hw->media_type == e1000_media_type_internal_serdes)
2000 && (hw->autoneg_failed))
2001 || ((hw->media_type == e1000_media_type_copper)
2002 && (!hw->autoneg))) {
2003 ret_val = e1000_force_mac_fc(hw);
2005 DEBUGOUT("Error forcing flow control settings\n");
2010 /* Check for the case where we have copper media and auto-neg is
2011 * enabled. In this case, we need to check and see if Auto-Neg
2012 * has completed, and if so, how the PHY and link partner has
2013 * flow control configured.
2015 if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2016 /* Read the MII Status Register and check to see if AutoNeg
2017 * has completed. We read this twice because this reg has
2018 * some "sticky" (latched) bits.
2020 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2027 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2028 /* The AutoNeg process has completed, so we now need to
2029 * read both the Auto Negotiation Advertisement Register
2030 * (Address 4) and the Auto_Negotiation Base Page Ability
2031 * Register (Address 5) to determine how flow control was
2034 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2038 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2039 &mii_nway_lp_ability_reg);
2043 /* Two bits in the Auto Negotiation Advertisement Register
2044 * (Address 4) and two bits in the Auto Negotiation Base
2045 * Page Ability Register (Address 5) determine flow control
2046 * for both the PHY and the link partner. The following
2047 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2048 * 1999, describes these PAUSE resolution bits and how flow
2049 * control is determined based upon these settings.
2050 * NOTE: DC = Don't Care
2052 * LOCAL DEVICE | LINK PARTNER
2053 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2054 *-------|---------|-------|---------|--------------------
2055 * 0 | 0 | DC | DC | E1000_FC_NONE
2056 * 0 | 1 | 0 | DC | E1000_FC_NONE
2057 * 0 | 1 | 1 | 0 | E1000_FC_NONE
2058 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2059 * 1 | 0 | 0 | DC | E1000_FC_NONE
2060 * 1 | DC | 1 | DC | E1000_FC_FULL
2061 * 1 | 1 | 0 | 0 | E1000_FC_NONE
2062 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2065 /* Are both PAUSE bits set to 1? If so, this implies
2066 * Symmetric Flow Control is enabled at both ends. The
2067 * ASM_DIR bits are irrelevant per the spec.
2069 * For Symmetric Flow Control:
2071 * LOCAL DEVICE | LINK PARTNER
2072 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2073 *-------|---------|-------|---------|--------------------
2074 * 1 | DC | 1 | DC | E1000_FC_FULL
2077 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2078 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2079 /* Now we need to check if the user selected RX ONLY
2080 * of pause frames. In this case, we had to advertise
2081 * FULL flow control because we could not advertise RX
2082 * ONLY. Hence, we must now check to see if we need to
2083 * turn OFF the TRANSMISSION of PAUSE frames.
2085 if (hw->original_fc == E1000_FC_FULL) {
2086 hw->fc = E1000_FC_FULL;
2087 DEBUGOUT("Flow Control = FULL.\n");
2089 hw->fc = E1000_FC_RX_PAUSE;
2091 ("Flow Control = RX PAUSE frames only.\n");
2094 /* For receiving PAUSE frames ONLY.
2096 * LOCAL DEVICE | LINK PARTNER
2097 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2098 *-------|---------|-------|---------|--------------------
2099 * 0 | 1 | 1 | 1 | E1000_FC_TX_PAUSE
2102 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2103 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2104 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2105 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2107 hw->fc = E1000_FC_TX_PAUSE;
2109 ("Flow Control = TX PAUSE frames only.\n");
2111 /* For transmitting PAUSE frames ONLY.
2113 * LOCAL DEVICE | LINK PARTNER
2114 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2115 *-------|---------|-------|---------|--------------------
2116 * 1 | 1 | 0 | 1 | E1000_FC_RX_PAUSE
2119 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2120 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2121 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2122 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
2124 hw->fc = E1000_FC_RX_PAUSE;
2126 ("Flow Control = RX PAUSE frames only.\n");
2128 /* Per the IEEE spec, at this point flow control should be
2129 * disabled. However, we want to consider that we could
2130 * be connected to a legacy switch that doesn't advertise
2131 * desired flow control, but can be forced on the link
2132 * partner. So if we advertised no flow control, that is
2133 * what we will resolve to. If we advertised some kind of
2134 * receive capability (Rx Pause Only or Full Flow Control)
2135 * and the link partner advertised none, we will configure
2136 * ourselves to enable Rx Flow Control only. We can do
2137 * this safely for two reasons: If the link partner really
2138 * didn't want flow control enabled, and we enable Rx, no
2139 * harm done since we won't be receiving any PAUSE frames
2140 * anyway. If the intent on the link partner was to have
2141 * flow control enabled, then by us enabling RX only, we
2142 * can at least receive pause frames and process them.
2143 * This is a good idea because in most cases, since we are
2144 * predominantly a server NIC, more times than not we will
2145 * be asked to delay transmission of packets than asking
2146 * our link partner to pause transmission of frames.
2148 else if ((hw->original_fc == E1000_FC_NONE ||
2149 hw->original_fc == E1000_FC_TX_PAUSE) ||
2150 hw->fc_strict_ieee) {
2151 hw->fc = E1000_FC_NONE;
2152 DEBUGOUT("Flow Control = NONE.\n");
2154 hw->fc = E1000_FC_RX_PAUSE;
2156 ("Flow Control = RX PAUSE frames only.\n");
2159 /* Now we need to do one last check... If we auto-
2160 * negotiated to HALF DUPLEX, flow control should not be
2161 * enabled per IEEE 802.3 spec.
2164 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2167 ("Error getting link speed and duplex\n");
2171 if (duplex == HALF_DUPLEX)
2172 hw->fc = E1000_FC_NONE;
2174 /* Now we call a subroutine to actually force the MAC
2175 * controller to use the correct flow control settings.
2177 ret_val = e1000_force_mac_fc(hw);
2180 ("Error forcing flow control settings\n");
2185 ("Copper PHY and Auto Neg has not completed.\n");
2188 return E1000_SUCCESS;
2192 * e1000_check_for_serdes_link_generic - Check for link (Serdes)
2193 * @hw: pointer to the HW structure
2195 * Checks for link up on the hardware. If link is not up and we have
2196 * a signal, then we need to force link up.
2198 s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
2203 s32 ret_val = E1000_SUCCESS;
2205 DEBUGFUNC("e1000_check_for_serdes_link_generic");
2208 status = er32(STATUS);
2212 * If we don't have link (auto-negotiation failed or link partner
2213 * cannot auto-negotiate), and our link partner is not trying to
2214 * auto-negotiate with us (we are receiving idles or data),
2215 * we need to force link up. We also need to give auto-negotiation
2218 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
2219 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
2220 if (hw->autoneg_failed == 0) {
2221 hw->autoneg_failed = 1;
2224 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
2226 /* Disable auto-negotiation in the TXCW register */
2227 ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2229 /* Force link-up and also force full-duplex. */
2231 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2234 /* Configure Flow Control after forcing link up. */
2235 ret_val = e1000_config_fc_after_link_up(hw);
2237 DEBUGOUT("Error configuring flow control\n");
2240 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2242 * If we are forcing link and we are receiving /C/ ordered
2243 * sets, re-enable auto-negotiation in the TXCW register
2244 * and disable forced link in the Device Control register
2245 * in an attempt to auto-negotiate with our link partner.
2247 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
2248 ew32(TXCW, hw->txcw);
2249 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
2251 hw->serdes_has_link = true;
2252 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
2254 * If we force link for non-auto-negotiation switch, check
2255 * link status based on MAC synchronization for internal
2256 * serdes media type.
2258 /* SYNCH bit and IV bit are sticky. */
2261 if (rxcw & E1000_RXCW_SYNCH) {
2262 if (!(rxcw & E1000_RXCW_IV)) {
2263 hw->serdes_has_link = true;
2264 DEBUGOUT("SERDES: Link up - forced.\n");
2267 hw->serdes_has_link = false;
2268 DEBUGOUT("SERDES: Link down - force failed.\n");
2272 if (E1000_TXCW_ANE & er32(TXCW)) {
2273 status = er32(STATUS);
2274 if (status & E1000_STATUS_LU) {
2275 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
2278 if (rxcw & E1000_RXCW_SYNCH) {
2279 if (!(rxcw & E1000_RXCW_IV)) {
2280 hw->serdes_has_link = true;
2281 DEBUGOUT("SERDES: Link up - autoneg "
2282 "completed successfully.\n");
2284 hw->serdes_has_link = false;
2285 DEBUGOUT("SERDES: Link down - invalid"
2286 "codewords detected in autoneg.\n");
2289 hw->serdes_has_link = false;
2290 DEBUGOUT("SERDES: Link down - no sync.\n");
2293 hw->serdes_has_link = false;
2294 DEBUGOUT("SERDES: Link down - autoneg failed\n");
2303 * e1000_check_for_link
2304 * @hw: Struct containing variables accessed by shared code
2306 * Checks to see if the link status of the hardware has changed.
2307 * Called by any function that needs to check the link status of the adapter.
2309 s32 e1000_check_for_link(struct e1000_hw *hw)
2320 DEBUGFUNC("e1000_check_for_link");
2323 status = er32(STATUS);
2325 /* On adapters with a MAC newer than 82544, SW Definable pin 1 will be
2326 * set when the optics detect a signal. On older adapters, it will be
2327 * cleared when there is a signal. This applies to fiber media only.
2329 if ((hw->media_type == e1000_media_type_fiber) ||
2330 (hw->media_type == e1000_media_type_internal_serdes)) {
2333 if (hw->media_type == e1000_media_type_fiber) {
2336 e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2337 if (status & E1000_STATUS_LU)
2338 hw->get_link_status = false;
2342 /* If we have a copper PHY then we only want to go out to the PHY
2343 * registers to see if Auto-Neg has completed and/or if our link
2344 * status has changed. The get_link_status flag will be set if we
2345 * receive a Link Status Change interrupt or we have Rx Sequence
2348 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2349 /* First we want to see if the MII Status Register reports
2350 * link. If so, then we want to get the current speed/duplex
2352 * Read the register twice since the link bit is sticky.
2354 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2357 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2361 if (phy_data & MII_SR_LINK_STATUS) {
2362 hw->get_link_status = false;
2363 /* Check if there was DownShift, must be checked immediately after
2365 e1000_check_downshift(hw);
2367 /* If we are on 82544 or 82543 silicon and speed/duplex
2368 * are forced to 10H or 10F, then we will implement the polarity
2369 * reversal workaround. We disable interrupts first, and upon
2370 * returning, place the devices interrupt state to its previous
2371 * value except for the link status change interrupt which will
2372 * happen due to the execution of this workaround.
2375 if ((hw->mac_type == e1000_82544
2376 || hw->mac_type == e1000_82543) && (!hw->autoneg)
2377 && (hw->forced_speed_duplex == e1000_10_full
2378 || hw->forced_speed_duplex == e1000_10_half)) {
2379 ew32(IMC, 0xffffffff);
2381 e1000_polarity_reversal_workaround(hw);
2383 ew32(ICS, (icr & ~E1000_ICS_LSC));
2384 ew32(IMS, IMS_ENABLE_MASK);
2388 /* No link detected */
2389 e1000_config_dsp_after_link_change(hw, false);
2393 /* If we are forcing speed/duplex, then we simply return since
2394 * we have already determined whether we have link or not.
2397 return -E1000_ERR_CONFIG;
2399 /* optimize the dsp settings for the igp phy */
2400 e1000_config_dsp_after_link_change(hw, true);
2402 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2403 * have Si on board that is 82544 or newer, Auto
2404 * Speed Detection takes care of MAC speed/duplex
2405 * configuration. So we only need to configure Collision
2406 * Distance in the MAC. Otherwise, we need to force
2407 * speed/duplex on the MAC to the current PHY speed/duplex
2410 if (hw->mac_type >= e1000_82544)
2411 e1000_config_collision_dist(hw);
2413 ret_val = e1000_config_mac_to_phy(hw);
2416 ("Error configuring MAC to PHY settings\n");
2421 /* Configure Flow Control now that Auto-Neg has completed. First, we
2422 * need to restore the desired flow control settings because we may
2423 * have had to re-autoneg with a different link partner.
2425 ret_val = e1000_config_fc_after_link_up(hw);
2427 DEBUGOUT("Error configuring flow control\n");
2431 /* At this point we know that we are on copper and we have
2432 * auto-negotiated link. These are conditions for checking the link
2433 * partner capability register. We use the link speed to determine if
2434 * TBI compatibility needs to be turned on or off. If the link is not
2435 * at gigabit speed, then TBI compatibility is not needed. If we are
2436 * at gigabit speed, we turn on TBI compatibility.
2438 if (hw->tbi_compatibility_en) {
2441 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2444 ("Error getting link speed and duplex\n");
2447 if (speed != SPEED_1000) {
2448 /* If link speed is not set to gigabit speed, we do not need
2449 * to enable TBI compatibility.
2451 if (hw->tbi_compatibility_on) {
2452 /* If we previously were in the mode, turn it off. */
2454 rctl &= ~E1000_RCTL_SBP;
2456 hw->tbi_compatibility_on = false;
2459 /* If TBI compatibility is was previously off, turn it on. For
2460 * compatibility with a TBI link partner, we will store bad
2461 * packets. Some frames have an additional byte on the end and
2462 * will look like CRC errors to to the hardware.
2464 if (!hw->tbi_compatibility_on) {
2465 hw->tbi_compatibility_on = true;
2467 rctl |= E1000_RCTL_SBP;
2474 if ((hw->media_type == e1000_media_type_fiber) ||
2475 (hw->media_type == e1000_media_type_internal_serdes))
2476 e1000_check_for_serdes_link_generic(hw);
2478 return E1000_SUCCESS;
2482 * e1000_get_speed_and_duplex
2483 * @hw: Struct containing variables accessed by shared code
2484 * @speed: Speed of the connection
2485 * @duplex: Duplex setting of the connection
2487 * Detects the current speed and duplex settings of the hardware.
2489 s32 e1000_get_speed_and_duplex(struct e1000_hw *hw, u16 *speed, u16 *duplex)
2495 DEBUGFUNC("e1000_get_speed_and_duplex");
2497 if (hw->mac_type >= e1000_82543) {
2498 status = er32(STATUS);
2499 if (status & E1000_STATUS_SPEED_1000) {
2500 *speed = SPEED_1000;
2501 DEBUGOUT("1000 Mbs, ");
2502 } else if (status & E1000_STATUS_SPEED_100) {
2504 DEBUGOUT("100 Mbs, ");
2507 DEBUGOUT("10 Mbs, ");
2510 if (status & E1000_STATUS_FD) {
2511 *duplex = FULL_DUPLEX;
2512 DEBUGOUT("Full Duplex\n");
2514 *duplex = HALF_DUPLEX;
2515 DEBUGOUT(" Half Duplex\n");
2518 DEBUGOUT("1000 Mbs, Full Duplex\n");
2519 *speed = SPEED_1000;
2520 *duplex = FULL_DUPLEX;
2523 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2524 * if it is operating at half duplex. Here we set the duplex settings to
2525 * match the duplex in the link partner's capabilities.
2527 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2528 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2532 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2533 *duplex = HALF_DUPLEX;
2536 e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2539 if ((*speed == SPEED_100
2540 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
2541 || (*speed == SPEED_10
2542 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2543 *duplex = HALF_DUPLEX;
2547 return E1000_SUCCESS;
2551 * e1000_wait_autoneg
2552 * @hw: Struct containing variables accessed by shared code
2554 * Blocks until autoneg completes or times out (~4.5 seconds)
2556 static s32 e1000_wait_autoneg(struct e1000_hw *hw)
2562 DEBUGFUNC("e1000_wait_autoneg");
2563 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2565 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2566 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2567 /* Read the MII Status Register and wait for Auto-Neg
2568 * Complete bit to be set.
2570 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2573 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2576 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
2577 return E1000_SUCCESS;
2581 return E1000_SUCCESS;
2585 * e1000_raise_mdi_clk - Raises the Management Data Clock
2586 * @hw: Struct containing variables accessed by shared code
2587 * @ctrl: Device control register's current value
2589 static void e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2591 /* Raise the clock input to the Management Data Clock (by setting the MDC
2592 * bit), and then delay 10 microseconds.
2594 ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
2595 E1000_WRITE_FLUSH();
2600 * e1000_lower_mdi_clk - Lowers the Management Data Clock
2601 * @hw: Struct containing variables accessed by shared code
2602 * @ctrl: Device control register's current value
2604 static void e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
2606 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2607 * bit), and then delay 10 microseconds.
2609 ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
2610 E1000_WRITE_FLUSH();
2615 * e1000_shift_out_mdi_bits - Shifts data bits out to the PHY
2616 * @hw: Struct containing variables accessed by shared code
2617 * @data: Data to send out to the PHY
2618 * @count: Number of bits to shift out
2620 * Bits are shifted out in MSB to LSB order.
2622 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, u32 data, u16 count)
2627 /* We need to shift "count" number of bits out to the PHY. So, the value
2628 * in the "data" parameter will be shifted out to the PHY one bit at a
2629 * time. In order to do this, "data" must be broken down into bits.
2632 mask <<= (count - 1);
2636 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2637 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2640 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2641 * then raising and lowering the Management Data Clock. A "0" is
2642 * shifted out to the PHY by setting the MDIO bit to "0" and then
2643 * raising and lowering the clock.
2646 ctrl |= E1000_CTRL_MDIO;
2648 ctrl &= ~E1000_CTRL_MDIO;
2651 E1000_WRITE_FLUSH();
2655 e1000_raise_mdi_clk(hw, &ctrl);
2656 e1000_lower_mdi_clk(hw, &ctrl);
2663 * e1000_shift_in_mdi_bits - Shifts data bits in from the PHY
2664 * @hw: Struct containing variables accessed by shared code
2666 * Bits are shifted in in MSB to LSB order.
2668 static u16 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2674 /* In order to read a register from the PHY, we need to shift in a total
2675 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2676 * to avoid contention on the MDIO pin when a read operation is performed.
2677 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2678 * by raising the input to the Management Data Clock (setting the MDC bit),
2679 * and then reading the value of the MDIO bit.
2683 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2684 ctrl &= ~E1000_CTRL_MDIO_DIR;
2685 ctrl &= ~E1000_CTRL_MDIO;
2688 E1000_WRITE_FLUSH();
2690 /* Raise and Lower the clock before reading in the data. This accounts for
2691 * the turnaround bits. The first clock occurred when we clocked out the
2692 * last bit of the Register Address.
2694 e1000_raise_mdi_clk(hw, &ctrl);
2695 e1000_lower_mdi_clk(hw, &ctrl);
2697 for (data = 0, i = 0; i < 16; i++) {
2699 e1000_raise_mdi_clk(hw, &ctrl);
2701 /* Check to see if we shifted in a "1". */
2702 if (ctrl & E1000_CTRL_MDIO)
2704 e1000_lower_mdi_clk(hw, &ctrl);
2707 e1000_raise_mdi_clk(hw, &ctrl);
2708 e1000_lower_mdi_clk(hw, &ctrl);
2715 * e1000_read_phy_reg - read a phy register
2716 * @hw: Struct containing variables accessed by shared code
2717 * @reg_addr: address of the PHY register to read
2719 * Reads the value from a PHY register, if the value is on a specific non zero
2720 * page, sets the page first.
2722 s32 e1000_read_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 *phy_data)
2726 DEBUGFUNC("e1000_read_phy_reg");
2728 if ((hw->phy_type == e1000_phy_igp) &&
2729 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2730 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2736 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2742 static s32 e1000_read_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2747 const u32 phy_addr = 1;
2749 DEBUGFUNC("e1000_read_phy_reg_ex");
2751 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2752 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2753 return -E1000_ERR_PARAM;
2756 if (hw->mac_type > e1000_82543) {
2757 /* Set up Op-code, Phy Address, and register address in the MDI
2758 * Control register. The MAC will take care of interfacing with the
2759 * PHY to retrieve the desired data.
2761 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2762 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2763 (E1000_MDIC_OP_READ));
2767 /* Poll the ready bit to see if the MDI read completed */
2768 for (i = 0; i < 64; i++) {
2771 if (mdic & E1000_MDIC_READY)
2774 if (!(mdic & E1000_MDIC_READY)) {
2775 DEBUGOUT("MDI Read did not complete\n");
2776 return -E1000_ERR_PHY;
2778 if (mdic & E1000_MDIC_ERROR) {
2779 DEBUGOUT("MDI Error\n");
2780 return -E1000_ERR_PHY;
2782 *phy_data = (u16) mdic;
2784 /* We must first send a preamble through the MDIO pin to signal the
2785 * beginning of an MII instruction. This is done by sending 32
2786 * consecutive "1" bits.
2788 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2790 /* Now combine the next few fields that are required for a read
2791 * operation. We use this method instead of calling the
2792 * e1000_shift_out_mdi_bits routine five different times. The format of
2793 * a MII read instruction consists of a shift out of 14 bits and is
2794 * defined as follows:
2795 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2796 * followed by a shift in of 18 bits. This first two bits shifted in
2797 * are TurnAround bits used to avoid contention on the MDIO pin when a
2798 * READ operation is performed. These two bits are thrown away
2799 * followed by a shift in of 16 bits which contains the desired data.
2801 mdic = ((reg_addr) | (phy_addr << 5) |
2802 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2804 e1000_shift_out_mdi_bits(hw, mdic, 14);
2806 /* Now that we've shifted out the read command to the MII, we need to
2807 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2810 *phy_data = e1000_shift_in_mdi_bits(hw);
2812 return E1000_SUCCESS;
2816 * e1000_write_phy_reg - write a phy register
2818 * @hw: Struct containing variables accessed by shared code
2819 * @reg_addr: address of the PHY register to write
2820 * @data: data to write to the PHY
2822 * Writes a value to a PHY register
2824 s32 e1000_write_phy_reg(struct e1000_hw *hw, u32 reg_addr, u16 phy_data)
2828 DEBUGFUNC("e1000_write_phy_reg");
2830 if ((hw->phy_type == e1000_phy_igp) &&
2831 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2832 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2838 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2844 static s32 e1000_write_phy_reg_ex(struct e1000_hw *hw, u32 reg_addr,
2849 const u32 phy_addr = 1;
2851 DEBUGFUNC("e1000_write_phy_reg_ex");
2853 if (reg_addr > MAX_PHY_REG_ADDRESS) {
2854 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2855 return -E1000_ERR_PARAM;
2858 if (hw->mac_type > e1000_82543) {
2859 /* Set up Op-code, Phy Address, register address, and data intended
2860 * for the PHY register in the MDI Control register. The MAC will take
2861 * care of interfacing with the PHY to send the desired data.
2863 mdic = (((u32) phy_data) |
2864 (reg_addr << E1000_MDIC_REG_SHIFT) |
2865 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2866 (E1000_MDIC_OP_WRITE));
2870 /* Poll the ready bit to see if the MDI read completed */
2871 for (i = 0; i < 641; i++) {
2874 if (mdic & E1000_MDIC_READY)
2877 if (!(mdic & E1000_MDIC_READY)) {
2878 DEBUGOUT("MDI Write did not complete\n");
2879 return -E1000_ERR_PHY;
2882 /* We'll need to use the SW defined pins to shift the write command
2883 * out to the PHY. We first send a preamble to the PHY to signal the
2884 * beginning of the MII instruction. This is done by sending 32
2885 * consecutive "1" bits.
2887 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2889 /* Now combine the remaining required fields that will indicate a
2890 * write operation. We use this method instead of calling the
2891 * e1000_shift_out_mdi_bits routine for each field in the command. The
2892 * format of a MII write instruction is as follows:
2893 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2895 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2896 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2898 mdic |= (u32) phy_data;
2900 e1000_shift_out_mdi_bits(hw, mdic, 32);
2903 return E1000_SUCCESS;
2907 * e1000_phy_hw_reset - reset the phy, hardware style
2908 * @hw: Struct containing variables accessed by shared code
2910 * Returns the PHY to the power-on reset state
2912 s32 e1000_phy_hw_reset(struct e1000_hw *hw)
2918 DEBUGFUNC("e1000_phy_hw_reset");
2920 DEBUGOUT("Resetting Phy...\n");
2922 if (hw->mac_type > e1000_82543) {
2923 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2924 * bit. Then, take it out of reset.
2925 * For e1000 hardware, we delay for 10ms between the assert
2929 ew32(CTRL, ctrl | E1000_CTRL_PHY_RST);
2930 E1000_WRITE_FLUSH();
2935 E1000_WRITE_FLUSH();
2938 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2939 * bit to put the PHY into reset. Then, take it out of reset.
2941 ctrl_ext = er32(CTRL_EXT);
2942 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2943 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2944 ew32(CTRL_EXT, ctrl_ext);
2945 E1000_WRITE_FLUSH();
2947 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2948 ew32(CTRL_EXT, ctrl_ext);
2949 E1000_WRITE_FLUSH();
2953 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2954 /* Configure activity LED after PHY reset */
2955 led_ctrl = er32(LEDCTL);
2956 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2957 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2958 ew32(LEDCTL, led_ctrl);
2961 /* Wait for FW to finish PHY configuration. */
2962 ret_val = e1000_get_phy_cfg_done(hw);
2963 if (ret_val != E1000_SUCCESS)
2970 * e1000_phy_reset - reset the phy to commit settings
2971 * @hw: Struct containing variables accessed by shared code
2974 * Sets bit 15 of the MII Control register
2976 s32 e1000_phy_reset(struct e1000_hw *hw)
2981 DEBUGFUNC("e1000_phy_reset");
2983 switch (hw->phy_type) {
2985 ret_val = e1000_phy_hw_reset(hw);
2990 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2994 phy_data |= MII_CR_RESET;
2995 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3003 if (hw->phy_type == e1000_phy_igp)
3004 e1000_phy_init_script(hw);
3006 return E1000_SUCCESS;
3010 * e1000_detect_gig_phy - check the phy type
3011 * @hw: Struct containing variables accessed by shared code
3013 * Probes the expected PHY address for known PHY IDs
3015 static s32 e1000_detect_gig_phy(struct e1000_hw *hw)
3017 s32 phy_init_status, ret_val;
3018 u16 phy_id_high, phy_id_low;
3021 DEBUGFUNC("e1000_detect_gig_phy");
3023 if (hw->phy_id != 0)
3024 return E1000_SUCCESS;
3026 /* Read the PHY ID Registers to identify which PHY is onboard. */
3027 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3031 hw->phy_id = (u32) (phy_id_high << 16);
3033 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3037 hw->phy_id |= (u32) (phy_id_low & PHY_REVISION_MASK);
3038 hw->phy_revision = (u32) phy_id_low & ~PHY_REVISION_MASK;
3040 switch (hw->mac_type) {
3042 if (hw->phy_id == M88E1000_E_PHY_ID)
3046 if (hw->phy_id == M88E1000_I_PHY_ID)
3051 case e1000_82545_rev_3:
3053 case e1000_82546_rev_3:
3054 if (hw->phy_id == M88E1011_I_PHY_ID)
3058 case e1000_82541_rev_2:
3060 case e1000_82547_rev_2:
3061 if (hw->phy_id == IGP01E1000_I_PHY_ID)
3065 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3066 return -E1000_ERR_CONFIG;
3068 phy_init_status = e1000_set_phy_type(hw);
3070 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3071 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3072 return E1000_SUCCESS;
3074 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3075 return -E1000_ERR_PHY;
3079 * e1000_phy_reset_dsp - reset DSP
3080 * @hw: Struct containing variables accessed by shared code
3082 * Resets the PHY's DSP
3084 static s32 e1000_phy_reset_dsp(struct e1000_hw *hw)
3087 DEBUGFUNC("e1000_phy_reset_dsp");
3090 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3093 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3096 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3099 ret_val = E1000_SUCCESS;
3106 * e1000_phy_igp_get_info - get igp specific registers
3107 * @hw: Struct containing variables accessed by shared code
3108 * @phy_info: PHY information structure
3110 * Get PHY information from various PHY registers for igp PHY only.
3112 static s32 e1000_phy_igp_get_info(struct e1000_hw *hw,
3113 struct e1000_phy_info *phy_info)
3116 u16 phy_data, min_length, max_length, average;
3117 e1000_rev_polarity polarity;
3119 DEBUGFUNC("e1000_phy_igp_get_info");
3121 /* The downshift status is checked only once, after link is established,
3122 * and it stored in the hw->speed_downgraded parameter. */
3123 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3125 /* IGP01E1000 does not need to support it. */
3126 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3128 /* IGP01E1000 always correct polarity reversal */
3129 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3131 /* Check polarity status */
3132 ret_val = e1000_check_polarity(hw, &polarity);
3136 phy_info->cable_polarity = polarity;
3138 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3142 phy_info->mdix_mode =
3143 (e1000_auto_x_mode) ((phy_data & IGP01E1000_PSSR_MDIX) >>
3144 IGP01E1000_PSSR_MDIX_SHIFT);
3146 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3147 IGP01E1000_PSSR_SPEED_1000MBPS) {
3148 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3149 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3153 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3154 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3155 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3156 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3157 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3158 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3160 /* Get cable length */
3161 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3165 /* Translate to old method */
3166 average = (max_length + min_length) / 2;
3168 if (average <= e1000_igp_cable_length_50)
3169 phy_info->cable_length = e1000_cable_length_50;
3170 else if (average <= e1000_igp_cable_length_80)
3171 phy_info->cable_length = e1000_cable_length_50_80;
3172 else if (average <= e1000_igp_cable_length_110)
3173 phy_info->cable_length = e1000_cable_length_80_110;
3174 else if (average <= e1000_igp_cable_length_140)
3175 phy_info->cable_length = e1000_cable_length_110_140;
3177 phy_info->cable_length = e1000_cable_length_140;
3180 return E1000_SUCCESS;
3184 * e1000_phy_m88_get_info - get m88 specific registers
3185 * @hw: Struct containing variables accessed by shared code
3186 * @phy_info: PHY information structure
3188 * Get PHY information from various PHY registers for m88 PHY only.
3190 static s32 e1000_phy_m88_get_info(struct e1000_hw *hw,
3191 struct e1000_phy_info *phy_info)
3195 e1000_rev_polarity polarity;
3197 DEBUGFUNC("e1000_phy_m88_get_info");
3199 /* The downshift status is checked only once, after link is established,
3200 * and it stored in the hw->speed_downgraded parameter. */
3201 phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
3203 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3207 phy_info->extended_10bt_distance =
3208 ((phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3209 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT) ?
3210 e1000_10bt_ext_dist_enable_lower :
3211 e1000_10bt_ext_dist_enable_normal;
3213 phy_info->polarity_correction =
3214 ((phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3215 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT) ?
3216 e1000_polarity_reversal_disabled : e1000_polarity_reversal_enabled;
3218 /* Check polarity status */
3219 ret_val = e1000_check_polarity(hw, &polarity);
3222 phy_info->cable_polarity = polarity;
3224 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3228 phy_info->mdix_mode =
3229 (e1000_auto_x_mode) ((phy_data & M88E1000_PSSR_MDIX) >>
3230 M88E1000_PSSR_MDIX_SHIFT);
3232 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3233 /* Cable Length Estimation and Local/Remote Receiver Information
3234 * are only valid at 1000 Mbps.
3236 phy_info->cable_length =
3237 (e1000_cable_length) ((phy_data &
3238 M88E1000_PSSR_CABLE_LENGTH) >>
3239 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3241 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3245 phy_info->local_rx = ((phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3246 SR_1000T_LOCAL_RX_STATUS_SHIFT) ?
3247 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3248 phy_info->remote_rx = ((phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3249 SR_1000T_REMOTE_RX_STATUS_SHIFT) ?
3250 e1000_1000t_rx_status_ok : e1000_1000t_rx_status_not_ok;
3254 return E1000_SUCCESS;
3258 * e1000_phy_get_info - request phy info
3259 * @hw: Struct containing variables accessed by shared code
3260 * @phy_info: PHY information structure
3262 * Get PHY information from various PHY registers
3264 s32 e1000_phy_get_info(struct e1000_hw *hw, struct e1000_phy_info *phy_info)
3269 DEBUGFUNC("e1000_phy_get_info");
3271 phy_info->cable_length = e1000_cable_length_undefined;
3272 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3273 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3274 phy_info->downshift = e1000_downshift_undefined;
3275 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3276 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3277 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3278 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3280 if (hw->media_type != e1000_media_type_copper) {
3281 DEBUGOUT("PHY info is only valid for copper media\n");
3282 return -E1000_ERR_CONFIG;
3285 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3289 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3293 if ((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3294 DEBUGOUT("PHY info is only valid if link is up\n");
3295 return -E1000_ERR_CONFIG;
3298 if (hw->phy_type == e1000_phy_igp)
3299 return e1000_phy_igp_get_info(hw, phy_info);
3301 return e1000_phy_m88_get_info(hw, phy_info);
3304 s32 e1000_validate_mdi_setting(struct e1000_hw *hw)
3306 DEBUGFUNC("e1000_validate_mdi_settings");
3308 if (!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3309 DEBUGOUT("Invalid MDI setting detected\n");
3311 return -E1000_ERR_CONFIG;
3313 return E1000_SUCCESS;
3317 * e1000_init_eeprom_params - initialize sw eeprom vars
3318 * @hw: Struct containing variables accessed by shared code
3320 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3323 s32 e1000_init_eeprom_params(struct e1000_hw *hw)
3325 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3326 u32 eecd = er32(EECD);
3327 s32 ret_val = E1000_SUCCESS;
3330 DEBUGFUNC("e1000_init_eeprom_params");
3332 switch (hw->mac_type) {
3333 case e1000_82542_rev2_0:
3334 case e1000_82542_rev2_1:
3337 eeprom->type = e1000_eeprom_microwire;
3338 eeprom->word_size = 64;
3339 eeprom->opcode_bits = 3;
3340 eeprom->address_bits = 6;
3341 eeprom->delay_usec = 50;
3342 eeprom->use_eerd = false;
3343 eeprom->use_eewr = false;
3347 case e1000_82545_rev_3:
3349 case e1000_82546_rev_3:
3350 eeprom->type = e1000_eeprom_microwire;
3351 eeprom->opcode_bits = 3;
3352 eeprom->delay_usec = 50;
3353 if (eecd & E1000_EECD_SIZE) {
3354 eeprom->word_size = 256;
3355 eeprom->address_bits = 8;
3357 eeprom->word_size = 64;
3358 eeprom->address_bits = 6;
3360 eeprom->use_eerd = false;
3361 eeprom->use_eewr = false;
3364 case e1000_82541_rev_2:
3366 case e1000_82547_rev_2:
3367 if (eecd & E1000_EECD_TYPE) {
3368 eeprom->type = e1000_eeprom_spi;
3369 eeprom->opcode_bits = 8;
3370 eeprom->delay_usec = 1;
3371 if (eecd & E1000_EECD_ADDR_BITS) {
3372 eeprom->page_size = 32;
3373 eeprom->address_bits = 16;
3375 eeprom->page_size = 8;
3376 eeprom->address_bits = 8;
3379 eeprom->type = e1000_eeprom_microwire;
3380 eeprom->opcode_bits = 3;
3381 eeprom->delay_usec = 50;
3382 if (eecd & E1000_EECD_ADDR_BITS) {
3383 eeprom->word_size = 256;
3384 eeprom->address_bits = 8;
3386 eeprom->word_size = 64;
3387 eeprom->address_bits = 6;
3390 eeprom->use_eerd = false;
3391 eeprom->use_eewr = false;
3397 if (eeprom->type == e1000_eeprom_spi) {
3398 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3399 * 32KB (incremented by powers of 2).
3401 /* Set to default value for initial eeprom read. */
3402 eeprom->word_size = 64;
3403 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3407 (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3408 /* 256B eeprom size was not supported in earlier hardware, so we
3409 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3410 * is never the result used in the shifting logic below. */
3414 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3420 * e1000_raise_ee_clk - Raises the EEPROM's clock input.
3421 * @hw: Struct containing variables accessed by shared code
3422 * @eecd: EECD's current value
3424 static void e1000_raise_ee_clk(struct e1000_hw *hw, u32 *eecd)
3426 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3427 * wait <delay> microseconds.
3429 *eecd = *eecd | E1000_EECD_SK;
3431 E1000_WRITE_FLUSH();
3432 udelay(hw->eeprom.delay_usec);
3436 * e1000_lower_ee_clk - Lowers the EEPROM's clock input.
3437 * @hw: Struct containing variables accessed by shared code
3438 * @eecd: EECD's current value
3440 static void e1000_lower_ee_clk(struct e1000_hw *hw, u32 *eecd)
3442 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3443 * wait 50 microseconds.
3445 *eecd = *eecd & ~E1000_EECD_SK;
3447 E1000_WRITE_FLUSH();
3448 udelay(hw->eeprom.delay_usec);
3452 * e1000_shift_out_ee_bits - Shift data bits out to the EEPROM.
3453 * @hw: Struct containing variables accessed by shared code
3454 * @data: data to send to the EEPROM
3455 * @count: number of bits to shift out
3457 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, u16 data, u16 count)
3459 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3463 /* We need to shift "count" bits out to the EEPROM. So, value in the
3464 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3465 * In order to do this, "data" must be broken down into bits.
3467 mask = 0x01 << (count - 1);
3469 if (eeprom->type == e1000_eeprom_microwire) {
3470 eecd &= ~E1000_EECD_DO;
3471 } else if (eeprom->type == e1000_eeprom_spi) {
3472 eecd |= E1000_EECD_DO;
3475 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3476 * and then raising and then lowering the clock (the SK bit controls
3477 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3478 * by setting "DI" to "0" and then raising and then lowering the clock.
3480 eecd &= ~E1000_EECD_DI;
3483 eecd |= E1000_EECD_DI;
3486 E1000_WRITE_FLUSH();
3488 udelay(eeprom->delay_usec);
3490 e1000_raise_ee_clk(hw, &eecd);
3491 e1000_lower_ee_clk(hw, &eecd);
3497 /* We leave the "DI" bit set to "0" when we leave this routine. */
3498 eecd &= ~E1000_EECD_DI;
3503 * e1000_shift_in_ee_bits - Shift data bits in from the EEPROM
3504 * @hw: Struct containing variables accessed by shared code
3505 * @count: number of bits to shift in
3507 static u16 e1000_shift_in_ee_bits(struct e1000_hw *hw, u16 count)
3513 /* In order to read a register from the EEPROM, we need to shift 'count'
3514 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3515 * input to the EEPROM (setting the SK bit), and then reading the value of
3516 * the "DO" bit. During this "shifting in" process the "DI" bit should
3522 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3525 for (i = 0; i < count; i++) {
3527 e1000_raise_ee_clk(hw, &eecd);
3531 eecd &= ~(E1000_EECD_DI);
3532 if (eecd & E1000_EECD_DO)
3535 e1000_lower_ee_clk(hw, &eecd);
3542 * e1000_acquire_eeprom - Prepares EEPROM for access
3543 * @hw: Struct containing variables accessed by shared code
3545 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3546 * function should be called before issuing a command to the EEPROM.
3548 static s32 e1000_acquire_eeprom(struct e1000_hw *hw)
3550 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3553 DEBUGFUNC("e1000_acquire_eeprom");
3557 /* Request EEPROM Access */
3558 if (hw->mac_type > e1000_82544) {
3559 eecd |= E1000_EECD_REQ;
3562 while ((!(eecd & E1000_EECD_GNT)) &&
3563 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3568 if (!(eecd & E1000_EECD_GNT)) {
3569 eecd &= ~E1000_EECD_REQ;
3571 DEBUGOUT("Could not acquire EEPROM grant\n");
3572 return -E1000_ERR_EEPROM;
3576 /* Setup EEPROM for Read/Write */
3578 if (eeprom->type == e1000_eeprom_microwire) {
3579 /* Clear SK and DI */
3580 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3584 eecd |= E1000_EECD_CS;
3586 } else if (eeprom->type == e1000_eeprom_spi) {
3587 /* Clear SK and CS */
3588 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3593 return E1000_SUCCESS;
3597 * e1000_standby_eeprom - Returns EEPROM to a "standby" state
3598 * @hw: Struct containing variables accessed by shared code
3600 static void e1000_standby_eeprom(struct e1000_hw *hw)
3602 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3607 if (eeprom->type == e1000_eeprom_microwire) {
3608 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3610 E1000_WRITE_FLUSH();
3611 udelay(eeprom->delay_usec);
3614 eecd |= E1000_EECD_SK;
3616 E1000_WRITE_FLUSH();
3617 udelay(eeprom->delay_usec);
3620 eecd |= E1000_EECD_CS;
3622 E1000_WRITE_FLUSH();
3623 udelay(eeprom->delay_usec);
3626 eecd &= ~E1000_EECD_SK;
3628 E1000_WRITE_FLUSH();
3629 udelay(eeprom->delay_usec);
3630 } else if (eeprom->type == e1000_eeprom_spi) {
3631 /* Toggle CS to flush commands */
3632 eecd |= E1000_EECD_CS;
3634 E1000_WRITE_FLUSH();
3635 udelay(eeprom->delay_usec);
3636 eecd &= ~E1000_EECD_CS;
3638 E1000_WRITE_FLUSH();
3639 udelay(eeprom->delay_usec);
3644 * e1000_release_eeprom - drop chip select
3645 * @hw: Struct containing variables accessed by shared code
3647 * Terminates a command by inverting the EEPROM's chip select pin
3649 static void e1000_release_eeprom(struct e1000_hw *hw)
3653 DEBUGFUNC("e1000_release_eeprom");
3657 if (hw->eeprom.type == e1000_eeprom_spi) {
3658 eecd |= E1000_EECD_CS; /* Pull CS high */
3659 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3663 udelay(hw->eeprom.delay_usec);
3664 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
3665 /* cleanup eeprom */
3667 /* CS on Microwire is active-high */
3668 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3672 /* Rising edge of clock */
3673 eecd |= E1000_EECD_SK;
3675 E1000_WRITE_FLUSH();
3676 udelay(hw->eeprom.delay_usec);
3678 /* Falling edge of clock */
3679 eecd &= ~E1000_EECD_SK;
3681 E1000_WRITE_FLUSH();
3682 udelay(hw->eeprom.delay_usec);
3685 /* Stop requesting EEPROM access */
3686 if (hw->mac_type > e1000_82544) {
3687 eecd &= ~E1000_EECD_REQ;
3693 * e1000_spi_eeprom_ready - Reads a 16 bit word from the EEPROM.
3694 * @hw: Struct containing variables accessed by shared code
3696 static s32 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3698 u16 retry_count = 0;
3701 DEBUGFUNC("e1000_spi_eeprom_ready");
3703 /* Read "Status Register" repeatedly until the LSB is cleared. The
3704 * EEPROM will signal that the command has been completed by clearing
3705 * bit 0 of the internal status register. If it's not cleared within
3706 * 5 milliseconds, then error out.
3710 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3711 hw->eeprom.opcode_bits);
3712 spi_stat_reg = (u8) e1000_shift_in_ee_bits(hw, 8);
3713 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3719 e1000_standby_eeprom(hw);
3720 } while (retry_count < EEPROM_MAX_RETRY_SPI);
3722 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3723 * only 0-5mSec on 5V devices)
3725 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
3726 DEBUGOUT("SPI EEPROM Status error\n");
3727 return -E1000_ERR_EEPROM;
3730 return E1000_SUCCESS;
3734 * e1000_read_eeprom - Reads a 16 bit word from the EEPROM.
3735 * @hw: Struct containing variables accessed by shared code
3736 * @offset: offset of word in the EEPROM to read
3737 * @data: word read from the EEPROM
3738 * @words: number of words to read
3740 s32 e1000_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
3743 spin_lock(&e1000_eeprom_lock);
3744 ret = e1000_do_read_eeprom(hw, offset, words, data);
3745 spin_unlock(&e1000_eeprom_lock);
3749 static s32 e1000_do_read_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
3752 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3755 DEBUGFUNC("e1000_read_eeprom");
3757 /* If eeprom is not yet detected, do so now */
3758 if (eeprom->word_size == 0)
3759 e1000_init_eeprom_params(hw);
3761 /* A check for invalid values: offset too large, too many words, and not
3764 if ((offset >= eeprom->word_size)
3765 || (words > eeprom->word_size - offset) || (words == 0)) {
3767 ("\"words\" parameter out of bounds. Words = %d, size = %d\n",
3768 offset, eeprom->word_size);
3769 return -E1000_ERR_EEPROM;
3772 /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
3773 * directly. In this case, we need to acquire the EEPROM so that
3774 * FW or other port software does not interrupt.
3776 if (!hw->eeprom.use_eerd) {
3777 /* Prepare the EEPROM for bit-bang reading */
3778 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3779 return -E1000_ERR_EEPROM;
3782 /* Eerd register EEPROM access requires no eeprom aquire/release */
3783 if (eeprom->use_eerd)
3784 return e1000_read_eeprom_eerd(hw, offset, words, data);
3786 /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
3787 * acquired the EEPROM at this point, so any returns should release it */
3788 if (eeprom->type == e1000_eeprom_spi) {
3790 u8 read_opcode = EEPROM_READ_OPCODE_SPI;
3792 if (e1000_spi_eeprom_ready(hw)) {
3793 e1000_release_eeprom(hw);
3794 return -E1000_ERR_EEPROM;
3797 e1000_standby_eeprom(hw);
3799 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3800 if ((eeprom->address_bits == 8) && (offset >= 128))
3801 read_opcode |= EEPROM_A8_OPCODE_SPI;
3803 /* Send the READ command (opcode + addr) */
3804 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3805 e1000_shift_out_ee_bits(hw, (u16) (offset * 2),
3806 eeprom->address_bits);
3808 /* Read the data. The address of the eeprom internally increments with
3809 * each byte (spi) being read, saving on the overhead of eeprom setup
3810 * and tear-down. The address counter will roll over if reading beyond
3811 * the size of the eeprom, thus allowing the entire memory to be read
3812 * starting from any offset. */
3813 for (i = 0; i < words; i++) {
3814 word_in = e1000_shift_in_ee_bits(hw, 16);
3815 data[i] = (word_in >> 8) | (word_in << 8);
3817 } else if (eeprom->type == e1000_eeprom_microwire) {
3818 for (i = 0; i < words; i++) {
3819 /* Send the READ command (opcode + addr) */
3820 e1000_shift_out_ee_bits(hw,
3821 EEPROM_READ_OPCODE_MICROWIRE,
3822 eeprom->opcode_bits);
3823 e1000_shift_out_ee_bits(hw, (u16) (offset + i),
3824 eeprom->address_bits);
3826 /* Read the data. For microwire, each word requires the overhead
3827 * of eeprom setup and tear-down. */
3828 data[i] = e1000_shift_in_ee_bits(hw, 16);
3829 e1000_standby_eeprom(hw);
3833 /* End this read operation */
3834 e1000_release_eeprom(hw);
3836 return E1000_SUCCESS;
3840 * Reads a 16 bit word from the EEPROM using the EERD register.
3842 * @hw: Struct containing variables accessed by shared code
3843 * offset - offset of word in the EEPROM to read
3844 * data - word read from the EEPROM
3845 * words - number of words to read
3847 static s32 e1000_read_eeprom_eerd(struct e1000_hw *hw, u16 offset, u16 words,
3853 for (i = 0; i < words; i++) {
3854 eerd = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3855 E1000_EEPROM_RW_REG_START;
3858 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3863 data[i] = (er32(EERD) >> E1000_EEPROM_RW_REG_DATA);
3871 * Writes a 16 bit word from the EEPROM using the EEWR register.
3873 * @hw: Struct containing variables accessed by shared code
3874 * offset - offset of word in the EEPROM to read
3875 * data - word read from the EEPROM
3876 * words - number of words to read
3878 static s32 e1000_write_eeprom_eewr(struct e1000_hw *hw, u16 offset, u16 words,
3881 u32 register_value = 0;
3885 for (i = 0; i < words; i++) {
3886 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3887 ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3888 E1000_EEPROM_RW_REG_START;
3890 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3895 ew32(EEWR, register_value);
3897 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3908 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3910 * @hw: Struct containing variables accessed by shared code
3912 static s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
3914 u32 attempts = 100000;
3916 s32 done = E1000_ERR_EEPROM;
3918 for (i = 0; i < attempts; i++) {
3919 if (eerd == E1000_EEPROM_POLL_READ)
3924 if (reg & E1000_EEPROM_RW_REG_DONE) {
3925 done = E1000_SUCCESS;
3935 * e1000_validate_eeprom_checksum - Verifies that the EEPROM has a valid checksum
3936 * @hw: Struct containing variables accessed by shared code
3938 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3939 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3942 s32 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3947 DEBUGFUNC("e1000_validate_eeprom_checksum");
3949 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3950 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3951 DEBUGOUT("EEPROM Read Error\n");
3952 return -E1000_ERR_EEPROM;
3954 checksum += eeprom_data;
3957 if (checksum == (u16) EEPROM_SUM)
3958 return E1000_SUCCESS;
3960 DEBUGOUT("EEPROM Checksum Invalid\n");
3961 return -E1000_ERR_EEPROM;
3966 * e1000_update_eeprom_checksum - Calculates/writes the EEPROM checksum
3967 * @hw: Struct containing variables accessed by shared code
3969 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3970 * Writes the difference to word offset 63 of the EEPROM.
3972 s32 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3977 DEBUGFUNC("e1000_update_eeprom_checksum");
3979 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3980 if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3981 DEBUGOUT("EEPROM Read Error\n");
3982 return -E1000_ERR_EEPROM;
3984 checksum += eeprom_data;
3986 checksum = (u16) EEPROM_SUM - checksum;
3987 if (e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3988 DEBUGOUT("EEPROM Write Error\n");
3989 return -E1000_ERR_EEPROM;
3991 return E1000_SUCCESS;
3995 * e1000_write_eeprom - write words to the different EEPROM types.
3996 * @hw: Struct containing variables accessed by shared code
3997 * @offset: offset within the EEPROM to be written to
3998 * @words: number of words to write
3999 * @data: 16 bit word to be written to the EEPROM
4001 * If e1000_update_eeprom_checksum is not called after this function, the
4002 * EEPROM will most likely contain an invalid checksum.
4004 s32 e1000_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
4007 spin_lock(&e1000_eeprom_lock);
4008 ret = e1000_do_write_eeprom(hw, offset, words, data);
4009 spin_unlock(&e1000_eeprom_lock);
4013 static s32 e1000_do_write_eeprom(struct e1000_hw *hw, u16 offset, u16 words,
4016 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4019 DEBUGFUNC("e1000_write_eeprom");
4021 /* If eeprom is not yet detected, do so now */
4022 if (eeprom->word_size == 0)
4023 e1000_init_eeprom_params(hw);
4025 /* A check for invalid values: offset too large, too many words, and not
4028 if ((offset >= eeprom->word_size)
4029 || (words > eeprom->word_size - offset) || (words == 0)) {
4030 DEBUGOUT("\"words\" parameter out of bounds\n");
4031 return -E1000_ERR_EEPROM;
4034 if (eeprom->use_eewr)
4035 return e1000_write_eeprom_eewr(hw, offset, words, data);
4037 /* Prepare the EEPROM for writing */
4038 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4039 return -E1000_ERR_EEPROM;
4041 if (eeprom->type == e1000_eeprom_microwire) {
4042 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4044 status = e1000_write_eeprom_spi(hw, offset, words, data);
4048 /* Done with writing */
4049 e1000_release_eeprom(hw);
4055 * e1000_write_eeprom_spi - Writes a 16 bit word to a given offset in an SPI EEPROM.
4056 * @hw: Struct containing variables accessed by shared code
4057 * @offset: offset within the EEPROM to be written to
4058 * @words: number of words to write
4059 * @data: pointer to array of 8 bit words to be written to the EEPROM
4061 static s32 e1000_write_eeprom_spi(struct e1000_hw *hw, u16 offset, u16 words,
4064 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4067 DEBUGFUNC("e1000_write_eeprom_spi");
4069 while (widx < words) {
4070 u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
4072 if (e1000_spi_eeprom_ready(hw))
4073 return -E1000_ERR_EEPROM;
4075 e1000_standby_eeprom(hw);
4077 /* Send the WRITE ENABLE command (8 bit opcode ) */
4078 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4079 eeprom->opcode_bits);
4081 e1000_standby_eeprom(hw);
4083 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4084 if ((eeprom->address_bits == 8) && (offset >= 128))
4085 write_opcode |= EEPROM_A8_OPCODE_SPI;
4087 /* Send the Write command (8-bit opcode + addr) */
4088 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4090 e1000_shift_out_ee_bits(hw, (u16) ((offset + widx) * 2),
4091 eeprom->address_bits);
4095 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4096 while (widx < words) {
4097 u16 word_out = data[widx];
4098 word_out = (word_out >> 8) | (word_out << 8);
4099 e1000_shift_out_ee_bits(hw, word_out, 16);
4102 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4103 * operation, while the smaller eeproms are capable of an 8-byte
4104 * PAGE WRITE operation. Break the inner loop to pass new address
4106 if ((((offset + widx) * 2) % eeprom->page_size) == 0) {
4107 e1000_standby_eeprom(hw);
4113 return E1000_SUCCESS;
4117 * e1000_write_eeprom_microwire - Writes a 16 bit word to a given offset in a Microwire EEPROM.
4118 * @hw: Struct containing variables accessed by shared code
4119 * @offset: offset within the EEPROM to be written to
4120 * @words: number of words to write
4121 * @data: pointer to array of 8 bit words to be written to the EEPROM
4123 static s32 e1000_write_eeprom_microwire(struct e1000_hw *hw, u16 offset,
4124 u16 words, u16 *data)
4126 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4128 u16 words_written = 0;
4131 DEBUGFUNC("e1000_write_eeprom_microwire");
4133 /* Send the write enable command to the EEPROM (3-bit opcode plus
4134 * 6/8-bit dummy address beginning with 11). It's less work to include
4135 * the 11 of the dummy address as part of the opcode than it is to shift
4136 * it over the correct number of bits for the address. This puts the
4137 * EEPROM into write/erase mode.
4139 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4140 (u16) (eeprom->opcode_bits + 2));
4142 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4144 /* Prepare the EEPROM */
4145 e1000_standby_eeprom(hw);
4147 while (words_written < words) {
4148 /* Send the Write command (3-bit opcode + addr) */
4149 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4150 eeprom->opcode_bits);
4152 e1000_shift_out_ee_bits(hw, (u16) (offset + words_written),
4153 eeprom->address_bits);
4156 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4158 /* Toggle the CS line. This in effect tells the EEPROM to execute
4159 * the previous command.
4161 e1000_standby_eeprom(hw);
4163 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4164 * signal that the command has been completed by raising the DO signal.
4165 * If DO does not go high in 10 milliseconds, then error out.
4167 for (i = 0; i < 200; i++) {
4169 if (eecd & E1000_EECD_DO)
4174 DEBUGOUT("EEPROM Write did not complete\n");
4175 return -E1000_ERR_EEPROM;
4178 /* Recover from write */
4179 e1000_standby_eeprom(hw);
4184 /* Send the write disable command to the EEPROM (3-bit opcode plus
4185 * 6/8-bit dummy address beginning with 10). It's less work to include
4186 * the 10 of the dummy address as part of the opcode than it is to shift
4187 * it over the correct number of bits for the address. This takes the
4188 * EEPROM out of write/erase mode.
4190 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4191 (u16) (eeprom->opcode_bits + 2));
4193 e1000_shift_out_ee_bits(hw, 0, (u16) (eeprom->address_bits - 2));
4195 return E1000_SUCCESS;
4199 * e1000_read_mac_addr - read the adapters MAC from eeprom
4200 * @hw: Struct containing variables accessed by shared code
4202 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4203 * second function of dual function devices
4205 s32 e1000_read_mac_addr(struct e1000_hw *hw)
4210 DEBUGFUNC("e1000_read_mac_addr");
4212 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4214 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4215 DEBUGOUT("EEPROM Read Error\n");
4216 return -E1000_ERR_EEPROM;
4218 hw->perm_mac_addr[i] = (u8) (eeprom_data & 0x00FF);
4219 hw->perm_mac_addr[i + 1] = (u8) (eeprom_data >> 8);
4222 switch (hw->mac_type) {
4226 case e1000_82546_rev_3:
4227 if (er32(STATUS) & E1000_STATUS_FUNC_1)
4228 hw->perm_mac_addr[5] ^= 0x01;
4232 for (i = 0; i < NODE_ADDRESS_SIZE; i++)
4233 hw->mac_addr[i] = hw->perm_mac_addr[i];
4234 return E1000_SUCCESS;
4238 * e1000_init_rx_addrs - Initializes receive address filters.
4239 * @hw: Struct containing variables accessed by shared code
4241 * Places the MAC address in receive address register 0 and clears the rest
4242 * of the receive address registers. Clears the multicast table. Assumes
4243 * the receiver is in reset when the routine is called.
4245 static void e1000_init_rx_addrs(struct e1000_hw *hw)
4250 DEBUGFUNC("e1000_init_rx_addrs");
4252 /* Setup the receive address. */
4253 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4255 e1000_rar_set(hw, hw->mac_addr, 0);
4257 rar_num = E1000_RAR_ENTRIES;
4259 /* Zero out the other 15 receive addresses. */
4260 DEBUGOUT("Clearing RAR[1-15]\n");
4261 for (i = 1; i < rar_num; i++) {
4262 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4263 E1000_WRITE_FLUSH();
4264 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4265 E1000_WRITE_FLUSH();
4270 * e1000_hash_mc_addr - Hashes an address to determine its location in the multicast table
4271 * @hw: Struct containing variables accessed by shared code
4272 * @mc_addr: the multicast address to hash
4274 u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
4278 /* The portion of the address that is used for the hash table is
4279 * determined by the mc_filter_type setting.
4281 switch (hw->mc_filter_type) {
4282 /* [0] [1] [2] [3] [4] [5]
4287 /* [47:36] i.e. 0x563 for above example address */
4288 hash_value = ((mc_addr[4] >> 4) | (((u16) mc_addr[5]) << 4));
4291 /* [46:35] i.e. 0xAC6 for above example address */
4292 hash_value = ((mc_addr[4] >> 3) | (((u16) mc_addr[5]) << 5));
4295 /* [45:34] i.e. 0x5D8 for above example address */
4296 hash_value = ((mc_addr[4] >> 2) | (((u16) mc_addr[5]) << 6));
4299 /* [43:32] i.e. 0x634 for above example address */
4300 hash_value = ((mc_addr[4]) | (((u16) mc_addr[5]) << 8));
4304 hash_value &= 0xFFF;
4309 * e1000_rar_set - Puts an ethernet address into a receive address register.
4310 * @hw: Struct containing variables accessed by shared code
4311 * @addr: Address to put into receive address register
4312 * @index: Receive address register to write
4314 void e1000_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
4316 u32 rar_low, rar_high;
4318 /* HW expects these in little endian so we reverse the byte order
4319 * from network order (big endian) to little endian
4321 rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4322 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4323 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4325 /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
4329 * If there are any Rx frames queued up or otherwise present in the HW
4330 * before RSS is enabled, and then we enable RSS, the HW Rx unit will
4331 * hang. To work around this issue, we have to disable receives and
4332 * flush out all Rx frames before we enable RSS. To do so, we modify we
4333 * redirect all Rx traffic to manageability and then reset the HW.
4334 * This flushes away Rx frames, and (since the redirections to
4335 * manageability persists across resets) keeps new ones from coming in
4336 * while we work. Then, we clear the Address Valid AV bit for all MAC
4337 * addresses and undo the re-direction to manageability.
4338 * Now, frames are coming in again, but the MAC won't accept them, so
4339 * far so good. We now proceed to initialize RSS (if necessary) and
4340 * configure the Rx unit. Last, we re-enable the AV bits and continue
4343 switch (hw->mac_type) {
4345 /* Indicate to hardware the Address is Valid. */
4346 rar_high |= E1000_RAH_AV;
4350 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4351 E1000_WRITE_FLUSH();
4352 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4353 E1000_WRITE_FLUSH();
4357 * e1000_write_vfta - Writes a value to the specified offset in the VLAN filter table.
4358 * @hw: Struct containing variables accessed by shared code
4359 * @offset: Offset in VLAN filer table to write
4360 * @value: Value to write into VLAN filter table
4362 void e1000_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
4366 if ((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4367 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4368 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4369 E1000_WRITE_FLUSH();
4370 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4371 E1000_WRITE_FLUSH();
4373 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4374 E1000_WRITE_FLUSH();
4379 * e1000_clear_vfta - Clears the VLAN filer table
4380 * @hw: Struct containing variables accessed by shared code
4382 static void e1000_clear_vfta(struct e1000_hw *hw)
4386 u32 vfta_offset = 0;
4387 u32 vfta_bit_in_reg = 0;
4389 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4390 /* If the offset we want to clear is the same offset of the
4391 * manageability VLAN ID, then clear all bits except that of the
4392 * manageability unit */
4393 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4394 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4395 E1000_WRITE_FLUSH();
4399 static s32 e1000_id_led_init(struct e1000_hw *hw)
4402 const u32 ledctl_mask = 0x000000FF;
4403 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4404 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4405 u16 eeprom_data, i, temp;
4406 const u16 led_mask = 0x0F;
4408 DEBUGFUNC("e1000_id_led_init");
4410 if (hw->mac_type < e1000_82540) {
4412 return E1000_SUCCESS;
4415 ledctl = er32(LEDCTL);
4416 hw->ledctl_default = ledctl;
4417 hw->ledctl_mode1 = hw->ledctl_default;
4418 hw->ledctl_mode2 = hw->ledctl_default;
4420 if (e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4421 DEBUGOUT("EEPROM Read Error\n");
4422 return -E1000_ERR_EEPROM;
4425 if ((eeprom_data == ID_LED_RESERVED_0000) ||
4426 (eeprom_data == ID_LED_RESERVED_FFFF)) {
4427 eeprom_data = ID_LED_DEFAULT;
4430 for (i = 0; i < 4; i++) {
4431 temp = (eeprom_data >> (i << 2)) & led_mask;
4433 case ID_LED_ON1_DEF2:
4434 case ID_LED_ON1_ON2:
4435 case ID_LED_ON1_OFF2:
4436 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4437 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4439 case ID_LED_OFF1_DEF2:
4440 case ID_LED_OFF1_ON2:
4441 case ID_LED_OFF1_OFF2:
4442 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4443 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4450 case ID_LED_DEF1_ON2:
4451 case ID_LED_ON1_ON2:
4452 case ID_LED_OFF1_ON2:
4453 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4454 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4456 case ID_LED_DEF1_OFF2:
4457 case ID_LED_ON1_OFF2:
4458 case ID_LED_OFF1_OFF2:
4459 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4460 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4467 return E1000_SUCCESS;
4472 * @hw: Struct containing variables accessed by shared code
4474 * Prepares SW controlable LED for use and saves the current state of the LED.
4476 s32 e1000_setup_led(struct e1000_hw *hw)
4479 s32 ret_val = E1000_SUCCESS;
4481 DEBUGFUNC("e1000_setup_led");
4483 switch (hw->mac_type) {
4484 case e1000_82542_rev2_0:
4485 case e1000_82542_rev2_1:
4488 /* No setup necessary */
4492 case e1000_82541_rev_2:
4493 case e1000_82547_rev_2:
4494 /* Turn off PHY Smart Power Down (if enabled) */
4495 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4496 &hw->phy_spd_default);
4499 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4500 (u16) (hw->phy_spd_default &
4501 ~IGP01E1000_GMII_SPD));
4506 if (hw->media_type == e1000_media_type_fiber) {
4507 ledctl = er32(LEDCTL);
4508 /* Save current LEDCTL settings */
4509 hw->ledctl_default = ledctl;
4511 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4512 E1000_LEDCTL_LED0_BLINK |
4513 E1000_LEDCTL_LED0_MODE_MASK);
4514 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4515 E1000_LEDCTL_LED0_MODE_SHIFT);
4516 ew32(LEDCTL, ledctl);
4517 } else if (hw->media_type == e1000_media_type_copper)
4518 ew32(LEDCTL, hw->ledctl_mode1);
4522 return E1000_SUCCESS;
4526 * e1000_cleanup_led - Restores the saved state of the SW controlable LED.
4527 * @hw: Struct containing variables accessed by shared code
4529 s32 e1000_cleanup_led(struct e1000_hw *hw)
4531 s32 ret_val = E1000_SUCCESS;
4533 DEBUGFUNC("e1000_cleanup_led");
4535 switch (hw->mac_type) {
4536 case e1000_82542_rev2_0:
4537 case e1000_82542_rev2_1:
4540 /* No cleanup necessary */
4544 case e1000_82541_rev_2:
4545 case e1000_82547_rev_2:
4546 /* Turn on PHY Smart Power Down (if previously enabled) */
4547 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4548 hw->phy_spd_default);
4553 /* Restore LEDCTL settings */
4554 ew32(LEDCTL, hw->ledctl_default);
4558 return E1000_SUCCESS;
4562 * e1000_led_on - Turns on the software controllable LED
4563 * @hw: Struct containing variables accessed by shared code
4565 s32 e1000_led_on(struct e1000_hw *hw)
4567 u32 ctrl = er32(CTRL);
4569 DEBUGFUNC("e1000_led_on");
4571 switch (hw->mac_type) {
4572 case e1000_82542_rev2_0:
4573 case e1000_82542_rev2_1:
4575 /* Set SW Defineable Pin 0 to turn on the LED */
4576 ctrl |= E1000_CTRL_SWDPIN0;
4577 ctrl |= E1000_CTRL_SWDPIO0;
4580 if (hw->media_type == e1000_media_type_fiber) {
4581 /* Set SW Defineable Pin 0 to turn on the LED */
4582 ctrl |= E1000_CTRL_SWDPIN0;
4583 ctrl |= E1000_CTRL_SWDPIO0;
4585 /* Clear SW Defineable Pin 0 to turn on the LED */
4586 ctrl &= ~E1000_CTRL_SWDPIN0;
4587 ctrl |= E1000_CTRL_SWDPIO0;
4591 if (hw->media_type == e1000_media_type_fiber) {
4592 /* Clear SW Defineable Pin 0 to turn on the LED */
4593 ctrl &= ~E1000_CTRL_SWDPIN0;
4594 ctrl |= E1000_CTRL_SWDPIO0;
4595 } else if (hw->media_type == e1000_media_type_copper) {
4596 ew32(LEDCTL, hw->ledctl_mode2);
4597 return E1000_SUCCESS;
4604 return E1000_SUCCESS;
4608 * e1000_led_off - Turns off the software controllable LED
4609 * @hw: Struct containing variables accessed by shared code
4611 s32 e1000_led_off(struct e1000_hw *hw)
4613 u32 ctrl = er32(CTRL);
4615 DEBUGFUNC("e1000_led_off");
4617 switch (hw->mac_type) {
4618 case e1000_82542_rev2_0:
4619 case e1000_82542_rev2_1:
4621 /* Clear SW Defineable Pin 0 to turn off the LED */
4622 ctrl &= ~E1000_CTRL_SWDPIN0;
4623 ctrl |= E1000_CTRL_SWDPIO0;
4626 if (hw->media_type == e1000_media_type_fiber) {
4627 /* Clear SW Defineable Pin 0 to turn off the LED */
4628 ctrl &= ~E1000_CTRL_SWDPIN0;
4629 ctrl |= E1000_CTRL_SWDPIO0;
4631 /* Set SW Defineable Pin 0 to turn off the LED */
4632 ctrl |= E1000_CTRL_SWDPIN0;
4633 ctrl |= E1000_CTRL_SWDPIO0;
4637 if (hw->media_type == e1000_media_type_fiber) {
4638 /* Set SW Defineable Pin 0 to turn off the LED */
4639 ctrl |= E1000_CTRL_SWDPIN0;
4640 ctrl |= E1000_CTRL_SWDPIO0;
4641 } else if (hw->media_type == e1000_media_type_copper) {
4642 ew32(LEDCTL, hw->ledctl_mode1);
4643 return E1000_SUCCESS;
4650 return E1000_SUCCESS;
4654 * e1000_clear_hw_cntrs - Clears all hardware statistics counters.
4655 * @hw: Struct containing variables accessed by shared code
4657 static void e1000_clear_hw_cntrs(struct e1000_hw *hw)
4661 temp = er32(CRCERRS);
4662 temp = er32(SYMERRS);
4667 temp = er32(LATECOL);
4672 temp = er32(XONRXC);
4673 temp = er32(XONTXC);
4674 temp = er32(XOFFRXC);
4675 temp = er32(XOFFTXC);
4679 temp = er32(PRC127);
4680 temp = er32(PRC255);
4681 temp = er32(PRC511);
4682 temp = er32(PRC1023);
4683 temp = er32(PRC1522);
4706 temp = er32(PTC127);
4707 temp = er32(PTC255);
4708 temp = er32(PTC511);
4709 temp = er32(PTC1023);
4710 temp = er32(PTC1522);
4715 if (hw->mac_type < e1000_82543)
4718 temp = er32(ALGNERRC);
4719 temp = er32(RXERRC);
4721 temp = er32(CEXTERR);
4723 temp = er32(TSCTFC);
4725 if (hw->mac_type <= e1000_82544)
4728 temp = er32(MGTPRC);
4729 temp = er32(MGTPDC);
4730 temp = er32(MGTPTC);
4734 * e1000_reset_adaptive - Resets Adaptive IFS to its default state.
4735 * @hw: Struct containing variables accessed by shared code
4737 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4738 * hw->ifs_params_forced to true. However, you must initialize hw->
4739 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4740 * before calling this function.
4742 void e1000_reset_adaptive(struct e1000_hw *hw)
4744 DEBUGFUNC("e1000_reset_adaptive");
4746 if (hw->adaptive_ifs) {
4747 if (!hw->ifs_params_forced) {
4748 hw->current_ifs_val = 0;
4749 hw->ifs_min_val = IFS_MIN;
4750 hw->ifs_max_val = IFS_MAX;
4751 hw->ifs_step_size = IFS_STEP;
4752 hw->ifs_ratio = IFS_RATIO;
4754 hw->in_ifs_mode = false;
4757 DEBUGOUT("Not in Adaptive IFS mode!\n");
4762 * e1000_update_adaptive - update adaptive IFS
4763 * @hw: Struct containing variables accessed by shared code
4764 * @tx_packets: Number of transmits since last callback
4765 * @total_collisions: Number of collisions since last callback
4767 * Called during the callback/watchdog routine to update IFS value based on
4768 * the ratio of transmits to collisions.
4770 void e1000_update_adaptive(struct e1000_hw *hw)
4772 DEBUGFUNC("e1000_update_adaptive");
4774 if (hw->adaptive_ifs) {
4775 if ((hw->collision_delta *hw->ifs_ratio) > hw->tx_packet_delta) {
4776 if (hw->tx_packet_delta > MIN_NUM_XMITS) {
4777 hw->in_ifs_mode = true;
4778 if (hw->current_ifs_val < hw->ifs_max_val) {
4779 if (hw->current_ifs_val == 0)
4780 hw->current_ifs_val =
4783 hw->current_ifs_val +=
4785 ew32(AIT, hw->current_ifs_val);
4790 && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4791 hw->current_ifs_val = 0;
4792 hw->in_ifs_mode = false;
4797 DEBUGOUT("Not in Adaptive IFS mode!\n");
4802 * e1000_tbi_adjust_stats
4803 * @hw: Struct containing variables accessed by shared code
4804 * @frame_len: The length of the frame in question
4805 * @mac_addr: The Ethernet destination address of the frame in question
4807 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4809 void e1000_tbi_adjust_stats(struct e1000_hw *hw, struct e1000_hw_stats *stats,
4810 u32 frame_len, u8 *mac_addr)
4814 /* First adjust the frame length. */
4816 /* We need to adjust the statistics counters, since the hardware
4817 * counters overcount this packet as a CRC error and undercount
4818 * the packet as a good packet
4820 /* This packet should not be counted as a CRC error. */
4822 /* This packet does count as a Good Packet Received. */
4825 /* Adjust the Good Octets received counters */
4826 carry_bit = 0x80000000 & stats->gorcl;
4827 stats->gorcl += frame_len;
4828 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4829 * Received Count) was one before the addition,
4830 * AND it is zero after, then we lost the carry out,
4831 * need to add one to Gorch (Good Octets Received Count High).
4832 * This could be simplified if all environments supported
4835 if (carry_bit && ((stats->gorcl & 0x80000000) == 0))
4837 /* Is this a broadcast or multicast? Check broadcast first,
4838 * since the test for a multicast frame will test positive on
4839 * a broadcast frame.
4841 if ((mac_addr[0] == (u8) 0xff) && (mac_addr[1] == (u8) 0xff))
4842 /* Broadcast packet */
4844 else if (*mac_addr & 0x01)
4845 /* Multicast packet */
4848 if (frame_len == hw->max_frame_size) {
4849 /* In this case, the hardware has overcounted the number of
4856 /* Adjust the bin counters when the extra byte put the frame in the
4857 * wrong bin. Remember that the frame_len was adjusted above.
4859 if (frame_len == 64) {
4862 } else if (frame_len == 127) {
4865 } else if (frame_len == 255) {
4868 } else if (frame_len == 511) {
4871 } else if (frame_len == 1023) {
4874 } else if (frame_len == 1522) {
4880 * e1000_get_bus_info
4881 * @hw: Struct containing variables accessed by shared code
4883 * Gets the current PCI bus type, speed, and width of the hardware
4885 void e1000_get_bus_info(struct e1000_hw *hw)
4889 switch (hw->mac_type) {
4890 case e1000_82542_rev2_0:
4891 case e1000_82542_rev2_1:
4892 hw->bus_type = e1000_bus_type_pci;
4893 hw->bus_speed = e1000_bus_speed_unknown;
4894 hw->bus_width = e1000_bus_width_unknown;
4897 status = er32(STATUS);
4898 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4899 e1000_bus_type_pcix : e1000_bus_type_pci;
4901 if (hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4902 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4903 e1000_bus_speed_66 : e1000_bus_speed_120;
4904 } else if (hw->bus_type == e1000_bus_type_pci) {
4905 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4906 e1000_bus_speed_66 : e1000_bus_speed_33;
4908 switch (status & E1000_STATUS_PCIX_SPEED) {
4909 case E1000_STATUS_PCIX_SPEED_66:
4910 hw->bus_speed = e1000_bus_speed_66;
4912 case E1000_STATUS_PCIX_SPEED_100:
4913 hw->bus_speed = e1000_bus_speed_100;
4915 case E1000_STATUS_PCIX_SPEED_133:
4916 hw->bus_speed = e1000_bus_speed_133;
4919 hw->bus_speed = e1000_bus_speed_reserved;
4923 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4924 e1000_bus_width_64 : e1000_bus_width_32;
4930 * e1000_write_reg_io
4931 * @hw: Struct containing variables accessed by shared code
4932 * @offset: offset to write to
4933 * @value: value to write
4935 * Writes a value to one of the devices registers using port I/O (as opposed to
4936 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4938 static void e1000_write_reg_io(struct e1000_hw *hw, u32 offset, u32 value)
4940 unsigned long io_addr = hw->io_base;
4941 unsigned long io_data = hw->io_base + 4;
4943 e1000_io_write(hw, io_addr, offset);
4944 e1000_io_write(hw, io_data, value);
4948 * e1000_get_cable_length - Estimates the cable length.
4949 * @hw: Struct containing variables accessed by shared code
4950 * @min_length: The estimated minimum length
4951 * @max_length: The estimated maximum length
4953 * returns: - E1000_ERR_XXX
4956 * This function always returns a ranged length (minimum & maximum).
4957 * So for M88 phy's, this function interprets the one value returned from the
4958 * register to the minimum and maximum range.
4959 * For IGP phy's, the function calculates the range by the AGC registers.
4961 static s32 e1000_get_cable_length(struct e1000_hw *hw, u16 *min_length,
4969 DEBUGFUNC("e1000_get_cable_length");
4971 *min_length = *max_length = 0;
4973 /* Use old method for Phy older than IGP */
4974 if (hw->phy_type == e1000_phy_m88) {
4976 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4980 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4981 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
4983 /* Convert the enum value to ranged values */
4984 switch (cable_length) {
4985 case e1000_cable_length_50:
4987 *max_length = e1000_igp_cable_length_50;
4989 case e1000_cable_length_50_80:
4990 *min_length = e1000_igp_cable_length_50;
4991 *max_length = e1000_igp_cable_length_80;
4993 case e1000_cable_length_80_110:
4994 *min_length = e1000_igp_cable_length_80;
4995 *max_length = e1000_igp_cable_length_110;
4997 case e1000_cable_length_110_140:
4998 *min_length = e1000_igp_cable_length_110;
4999 *max_length = e1000_igp_cable_length_140;
5001 case e1000_cable_length_140:
5002 *min_length = e1000_igp_cable_length_140;
5003 *max_length = e1000_igp_cable_length_170;
5006 return -E1000_ERR_PHY;
5009 } else if (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5011 u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5012 u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5013 { IGP01E1000_PHY_AGC_A,
5014 IGP01E1000_PHY_AGC_B,
5015 IGP01E1000_PHY_AGC_C,
5016 IGP01E1000_PHY_AGC_D
5018 /* Read the AGC registers for all channels */
5019 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5022 e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5026 cur_agc_value = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5028 /* Value bound check. */
5029 if ((cur_agc_value >=
5030 IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1)
5031 || (cur_agc_value == 0))
5032 return -E1000_ERR_PHY;
5034 agc_value += cur_agc_value;
5036 /* Update minimal AGC value. */
5037 if (min_agc_value > cur_agc_value)
5038 min_agc_value = cur_agc_value;
5041 /* Remove the minimal AGC result for length < 50m */
5043 IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5044 agc_value -= min_agc_value;
5046 /* Get the average length of the remaining 3 channels */
5047 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5049 /* Get the average length of all the 4 channels. */
5050 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5053 /* Set the range of the calculated length. */
5054 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5055 IGP01E1000_AGC_RANGE) > 0) ?
5056 (e1000_igp_cable_length_table[agc_value] -
5057 IGP01E1000_AGC_RANGE) : 0;
5058 *max_length = e1000_igp_cable_length_table[agc_value] +
5059 IGP01E1000_AGC_RANGE;
5062 return E1000_SUCCESS;
5066 * e1000_check_polarity - Check the cable polarity
5067 * @hw: Struct containing variables accessed by shared code
5068 * @polarity: output parameter : 0 - Polarity is not reversed
5069 * 1 - Polarity is reversed.
5071 * returns: - E1000_ERR_XXX
5074 * For phy's older than IGP, this function simply reads the polarity bit in the
5075 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5076 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5077 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5078 * IGP01E1000_PHY_PCS_INIT_REG.
5080 static s32 e1000_check_polarity(struct e1000_hw *hw,
5081 e1000_rev_polarity *polarity)
5086 DEBUGFUNC("e1000_check_polarity");
5088 if (hw->phy_type == e1000_phy_m88) {
5089 /* return the Polarity bit in the Status register. */
5090 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5094 *polarity = ((phy_data & M88E1000_PSSR_REV_POLARITY) >>
5095 M88E1000_PSSR_REV_POLARITY_SHIFT) ?
5096 e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
5098 } else if (hw->phy_type == e1000_phy_igp) {
5099 /* Read the Status register to check the speed */
5100 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5105 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5106 * find the polarity status */
5107 if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5108 IGP01E1000_PSSR_SPEED_1000MBPS) {
5110 /* Read the GIG initialization PCS register (0x00B4) */
5112 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5117 /* Check the polarity bits */
5118 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
5119 e1000_rev_polarity_reversed :
5120 e1000_rev_polarity_normal;
5122 /* For 10 Mbps, read the polarity bit in the status register. (for
5123 * 100 Mbps this bit is always 0) */
5125 (phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
5126 e1000_rev_polarity_reversed :
5127 e1000_rev_polarity_normal;
5130 return E1000_SUCCESS;
5134 * e1000_check_downshift - Check if Downshift occurred
5135 * @hw: Struct containing variables accessed by shared code
5136 * @downshift: output parameter : 0 - No Downshift occurred.
5137 * 1 - Downshift occurred.
5139 * returns: - E1000_ERR_XXX
5142 * For phy's older than IGP, this function reads the Downshift bit in the Phy
5143 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5144 * Link Health register. In IGP this bit is latched high, so the driver must
5145 * read it immediately after link is established.
5147 static s32 e1000_check_downshift(struct e1000_hw *hw)
5152 DEBUGFUNC("e1000_check_downshift");
5154 if (hw->phy_type == e1000_phy_igp) {
5155 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5160 hw->speed_downgraded =
5161 (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5162 } else if (hw->phy_type == e1000_phy_m88) {
5163 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5168 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5169 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5172 return E1000_SUCCESS;
5176 * e1000_config_dsp_after_link_change
5177 * @hw: Struct containing variables accessed by shared code
5178 * @link_up: was link up at the time this was called
5180 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5181 * E1000_SUCCESS at any other case.
5183 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5184 * gigabit link is achieved to improve link quality.
5187 static s32 e1000_config_dsp_after_link_change(struct e1000_hw *hw, bool link_up)
5190 u16 phy_data, phy_saved_data, speed, duplex, i;
5191 u16 dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5192 { IGP01E1000_PHY_AGC_PARAM_A,
5193 IGP01E1000_PHY_AGC_PARAM_B,
5194 IGP01E1000_PHY_AGC_PARAM_C,
5195 IGP01E1000_PHY_AGC_PARAM_D
5197 u16 min_length, max_length;
5199 DEBUGFUNC("e1000_config_dsp_after_link_change");
5201 if (hw->phy_type != e1000_phy_igp)
5202 return E1000_SUCCESS;
5205 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5207 DEBUGOUT("Error getting link speed and duplex\n");
5211 if (speed == SPEED_1000) {
5214 e1000_get_cable_length(hw, &min_length,
5219 if ((hw->dsp_config_state == e1000_dsp_config_enabled)
5220 && min_length >= e1000_igp_cable_length_50) {
5222 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5224 e1000_read_phy_reg(hw,
5231 ~IGP01E1000_PHY_EDAC_MU_INDEX;
5234 e1000_write_phy_reg(hw,
5240 hw->dsp_config_state =
5241 e1000_dsp_config_activated;
5244 if ((hw->ffe_config_state == e1000_ffe_config_enabled)
5245 && (min_length < e1000_igp_cable_length_50)) {
5247 u16 ffe_idle_err_timeout =
5248 FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5251 /* clear previous idle error counts */
5253 e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5258 for (i = 0; i < ffe_idle_err_timeout; i++) {
5261 e1000_read_phy_reg(hw,
5269 SR_1000T_IDLE_ERROR_CNT);
5271 SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT)
5273 hw->ffe_config_state =
5274 e1000_ffe_config_active;
5277 e1000_write_phy_reg(hw,
5278 IGP01E1000_PHY_DSP_FFE,
5279 IGP01E1000_PHY_DSP_FFE_CM_CP);
5286 ffe_idle_err_timeout =
5287 FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5292 if (hw->dsp_config_state == e1000_dsp_config_activated) {
5293 /* Save off the current value of register 0x2F5B to be restored at
5294 * the end of the routines. */
5296 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5301 /* Disable the PHY transmitter */
5302 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5309 ret_val = e1000_write_phy_reg(hw, 0x0000,
5310 IGP01E1000_IEEE_FORCE_GIGA);
5313 for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5315 e1000_read_phy_reg(hw, dsp_reg_array[i],
5320 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5321 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5324 e1000_write_phy_reg(hw, dsp_reg_array[i],
5330 ret_val = e1000_write_phy_reg(hw, 0x0000,
5331 IGP01E1000_IEEE_RESTART_AUTONEG);
5337 /* Now enable the transmitter */
5339 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5344 hw->dsp_config_state = e1000_dsp_config_enabled;
5347 if (hw->ffe_config_state == e1000_ffe_config_active) {
5348 /* Save off the current value of register 0x2F5B to be restored at
5349 * the end of the routines. */
5351 e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5356 /* Disable the PHY transmitter */
5357 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5364 ret_val = e1000_write_phy_reg(hw, 0x0000,
5365 IGP01E1000_IEEE_FORCE_GIGA);
5369 e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5370 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5374 ret_val = e1000_write_phy_reg(hw, 0x0000,
5375 IGP01E1000_IEEE_RESTART_AUTONEG);
5381 /* Now enable the transmitter */
5383 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5388 hw->ffe_config_state = e1000_ffe_config_enabled;
5391 return E1000_SUCCESS;
5395 * e1000_set_phy_mode - Set PHY to class A mode
5396 * @hw: Struct containing variables accessed by shared code
5398 * Assumes the following operations will follow to enable the new class mode.
5399 * 1. Do a PHY soft reset
5400 * 2. Restart auto-negotiation or force link.
5402 static s32 e1000_set_phy_mode(struct e1000_hw *hw)
5407 DEBUGFUNC("e1000_set_phy_mode");
5409 if ((hw->mac_type == e1000_82545_rev_3) &&
5410 (hw->media_type == e1000_media_type_copper)) {
5412 e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1,
5418 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
5419 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5421 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5426 e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
5431 hw->phy_reset_disable = false;
5435 return E1000_SUCCESS;
5439 * e1000_set_d3_lplu_state - set d3 link power state
5440 * @hw: Struct containing variables accessed by shared code
5441 * @active: true to enable lplu false to disable lplu.
5443 * This function sets the lplu state according to the active flag. When
5444 * activating lplu this function also disables smart speed and vise versa.
5445 * lplu will not be activated unless the device autonegotiation advertisement
5446 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5448 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5449 * E1000_SUCCESS at any other case.
5451 static s32 e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
5455 DEBUGFUNC("e1000_set_d3_lplu_state");
5457 if (hw->phy_type != e1000_phy_igp)
5458 return E1000_SUCCESS;
5460 /* During driver activity LPLU should not be used or it will attain link
5461 * from the lowest speeds starting from 10Mbps. The capability is used for
5462 * Dx transitions and states */
5463 if (hw->mac_type == e1000_82541_rev_2
5464 || hw->mac_type == e1000_82547_rev_2) {
5466 e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5472 if (hw->mac_type == e1000_82541_rev_2 ||
5473 hw->mac_type == e1000_82547_rev_2) {
5474 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5476 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5482 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5483 * Dx states where the power conservation is most important. During
5484 * driver activity we should enable SmartSpeed, so performance is
5486 if (hw->smart_speed == e1000_smart_speed_on) {
5488 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5493 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5495 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5499 } else if (hw->smart_speed == e1000_smart_speed_off) {
5501 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5506 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5508 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5513 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
5514 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL)
5515 || (hw->autoneg_advertised ==
5516 AUTONEG_ADVERTISE_10_100_ALL)) {
5518 if (hw->mac_type == e1000_82541_rev_2 ||
5519 hw->mac_type == e1000_82547_rev_2) {
5520 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5522 e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
5528 /* When LPLU is enabled we should disable SmartSpeed */
5530 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5535 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5537 e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5543 return E1000_SUCCESS;
5547 * e1000_set_vco_speed
5548 * @hw: Struct containing variables accessed by shared code
5550 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5552 static s32 e1000_set_vco_speed(struct e1000_hw *hw)
5555 u16 default_page = 0;
5558 DEBUGFUNC("e1000_set_vco_speed");
5560 switch (hw->mac_type) {
5561 case e1000_82545_rev_3:
5562 case e1000_82546_rev_3:
5565 return E1000_SUCCESS;
5568 /* Set PHY register 30, page 5, bit 8 to 0 */
5571 e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5575 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5579 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5583 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5584 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5588 /* Set PHY register 30, page 4, bit 11 to 1 */
5590 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5594 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5598 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5599 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5604 e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5608 return E1000_SUCCESS;
5613 * e1000_enable_mng_pass_thru - check for bmc pass through
5614 * @hw: Struct containing variables accessed by shared code
5616 * Verifies the hardware needs to allow ARPs to be processed by the host
5617 * returns: - true/false
5619 u32 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5623 if (hw->asf_firmware_present) {
5626 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5627 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5629 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
5635 static s32 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5641 /* Polarity reversal workaround for forced 10F/10H links. */
5643 /* Disable the transmitter on the PHY */
5645 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5648 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5652 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5656 /* This loop will early-out if the NO link condition has been met. */
5657 for (i = PHY_FORCE_TIME; i > 0; i--) {
5658 /* Read the MII Status Register and wait for Link Status bit
5662 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5666 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5670 if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0)
5675 /* Recommended delay time after link has been lost */
5678 /* Now we will re-enable th transmitter on the PHY */
5680 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5684 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5688 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5692 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5696 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5700 /* This loop will early-out if the link condition has been met. */
5701 for (i = PHY_FORCE_TIME; i > 0; i--) {
5702 /* Read the MII Status Register and wait for Link Status bit
5706 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5710 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5714 if (mii_status_reg & MII_SR_LINK_STATUS)
5718 return E1000_SUCCESS;
5722 * e1000_get_auto_rd_done
5723 * @hw: Struct containing variables accessed by shared code
5725 * Check for EEPROM Auto Read bit done.
5726 * returns: - E1000_ERR_RESET if fail to reset MAC
5727 * E1000_SUCCESS at any other case.
5729 static s32 e1000_get_auto_rd_done(struct e1000_hw *hw)
5731 DEBUGFUNC("e1000_get_auto_rd_done");
5733 return E1000_SUCCESS;
5737 * e1000_get_phy_cfg_done
5738 * @hw: Struct containing variables accessed by shared code
5740 * Checks if the PHY configuration is done
5741 * returns: - E1000_ERR_RESET if fail to reset MAC
5742 * E1000_SUCCESS at any other case.
5744 static s32 e1000_get_phy_cfg_done(struct e1000_hw *hw)
5746 DEBUGFUNC("e1000_get_phy_cfg_done");
5748 return E1000_SUCCESS;