1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_id_led_init(struct e1000_hw * hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
70 /* IGP cable length table */
72 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
73 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
74 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
75 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
76 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
77 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
78 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
79 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
80 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
83 /******************************************************************************
84 * Set the phy type member in the hw struct.
86 * hw - Struct containing variables accessed by shared code
87 *****************************************************************************/
89 e1000_set_phy_type(struct e1000_hw *hw)
91 DEBUGFUNC("e1000_set_phy_type");
94 case M88E1000_E_PHY_ID:
95 case M88E1000_I_PHY_ID:
96 case M88E1011_I_PHY_ID:
97 hw->phy_type = e1000_phy_m88;
99 case IGP01E1000_I_PHY_ID:
100 if(hw->mac_type == e1000_82541 ||
101 hw->mac_type == e1000_82541_rev_2 ||
102 hw->mac_type == e1000_82547 ||
103 hw->mac_type == e1000_82547_rev_2) {
104 hw->phy_type = e1000_phy_igp;
109 /* Should never have loaded on this device */
110 hw->phy_type = e1000_phy_undefined;
111 return -E1000_ERR_PHY_TYPE;
114 return E1000_SUCCESS;
117 /******************************************************************************
118 * IGP phy init script - initializes the GbE PHY
120 * hw - Struct containing variables accessed by shared code
121 *****************************************************************************/
123 e1000_phy_init_script(struct e1000_hw *hw)
125 DEBUGFUNC("e1000_phy_init_script");
127 if(hw->phy_init_script) {
130 e1000_write_phy_reg(hw,0x0000,0x0140);
134 if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
135 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
137 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
139 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
141 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
143 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
145 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
147 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
149 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
151 e1000_write_phy_reg(hw, 0x2010, 0x0008);
153 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
156 e1000_write_phy_reg(hw, 0x0000, 0x3300);
158 if(hw->mac_type == e1000_82547) {
159 uint16_t fused, fine, coarse;
161 /* Move to analog registers page */
162 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
164 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
165 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
167 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
168 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
170 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
171 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
172 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
173 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
174 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
176 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
177 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
178 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
180 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
181 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
182 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
188 /******************************************************************************
189 * Set the mac type member in the hw struct.
191 * hw - Struct containing variables accessed by shared code
192 *****************************************************************************/
194 e1000_set_mac_type(struct e1000_hw *hw)
196 DEBUGFUNC("e1000_set_mac_type");
198 switch (hw->device_id) {
199 case E1000_DEV_ID_82542:
200 switch (hw->revision_id) {
201 case E1000_82542_2_0_REV_ID:
202 hw->mac_type = e1000_82542_rev2_0;
204 case E1000_82542_2_1_REV_ID:
205 hw->mac_type = e1000_82542_rev2_1;
208 /* Invalid 82542 revision ID */
209 return -E1000_ERR_MAC_TYPE;
212 case E1000_DEV_ID_82543GC_FIBER:
213 case E1000_DEV_ID_82543GC_COPPER:
214 hw->mac_type = e1000_82543;
216 case E1000_DEV_ID_82544EI_COPPER:
217 case E1000_DEV_ID_82544EI_FIBER:
218 case E1000_DEV_ID_82544GC_COPPER:
219 case E1000_DEV_ID_82544GC_LOM:
220 hw->mac_type = e1000_82544;
222 case E1000_DEV_ID_82540EM:
223 case E1000_DEV_ID_82540EM_LOM:
224 case E1000_DEV_ID_82540EP:
225 case E1000_DEV_ID_82540EP_LOM:
226 case E1000_DEV_ID_82540EP_LP:
227 hw->mac_type = e1000_82540;
229 case E1000_DEV_ID_82545EM_COPPER:
230 case E1000_DEV_ID_82545EM_FIBER:
231 hw->mac_type = e1000_82545;
233 case E1000_DEV_ID_82545GM_COPPER:
234 case E1000_DEV_ID_82545GM_FIBER:
235 case E1000_DEV_ID_82545GM_SERDES:
236 hw->mac_type = e1000_82545_rev_3;
238 case E1000_DEV_ID_82546EB_COPPER:
239 case E1000_DEV_ID_82546EB_FIBER:
240 case E1000_DEV_ID_82546EB_QUAD_COPPER:
241 hw->mac_type = e1000_82546;
243 case E1000_DEV_ID_82546GB_COPPER:
244 case E1000_DEV_ID_82546GB_FIBER:
245 case E1000_DEV_ID_82546GB_SERDES:
246 hw->mac_type = e1000_82546_rev_3;
248 case E1000_DEV_ID_82541EI:
249 case E1000_DEV_ID_82541EI_MOBILE:
250 hw->mac_type = e1000_82541;
252 case E1000_DEV_ID_82541ER:
253 case E1000_DEV_ID_82541GI:
254 case E1000_DEV_ID_82541GI_MOBILE:
255 hw->mac_type = e1000_82541_rev_2;
257 case E1000_DEV_ID_82547EI:
258 hw->mac_type = e1000_82547;
260 case E1000_DEV_ID_82547GI:
261 hw->mac_type = e1000_82547_rev_2;
264 /* Should never have loaded on this device */
265 return -E1000_ERR_MAC_TYPE;
268 switch(hw->mac_type) {
271 case e1000_82541_rev_2:
272 case e1000_82547_rev_2:
273 hw->asf_firmware_present = TRUE;
279 return E1000_SUCCESS;
282 /*****************************************************************************
283 * Set media type and TBI compatibility.
285 * hw - Struct containing variables accessed by shared code
286 * **************************************************************************/
288 e1000_set_media_type(struct e1000_hw *hw)
292 DEBUGFUNC("e1000_set_media_type");
294 if(hw->mac_type != e1000_82543) {
295 /* tbi_compatibility is only valid on 82543 */
296 hw->tbi_compatibility_en = FALSE;
299 switch (hw->device_id) {
300 case E1000_DEV_ID_82545GM_SERDES:
301 case E1000_DEV_ID_82546GB_SERDES:
302 hw->media_type = e1000_media_type_internal_serdes;
305 if(hw->mac_type >= e1000_82543) {
306 status = E1000_READ_REG(hw, STATUS);
307 if(status & E1000_STATUS_TBIMODE) {
308 hw->media_type = e1000_media_type_fiber;
309 /* tbi_compatibility not valid on fiber */
310 hw->tbi_compatibility_en = FALSE;
312 hw->media_type = e1000_media_type_copper;
315 /* This is an 82542 (fiber only) */
316 hw->media_type = e1000_media_type_fiber;
321 /******************************************************************************
322 * Reset the transmit and receive units; mask and clear all interrupts.
324 * hw - Struct containing variables accessed by shared code
325 *****************************************************************************/
327 e1000_reset_hw(struct e1000_hw *hw)
335 DEBUGFUNC("e1000_reset_hw");
337 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
338 if(hw->mac_type == e1000_82542_rev2_0) {
339 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
340 e1000_pci_clear_mwi(hw);
343 /* Clear interrupt mask to stop board from generating interrupts */
344 DEBUGOUT("Masking off all interrupts\n");
345 E1000_WRITE_REG(hw, IMC, 0xffffffff);
347 /* Disable the Transmit and Receive units. Then delay to allow
348 * any pending transactions to complete before we hit the MAC with
351 E1000_WRITE_REG(hw, RCTL, 0);
352 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
353 E1000_WRITE_FLUSH(hw);
355 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
356 hw->tbi_compatibility_on = FALSE;
358 /* Delay to allow any outstanding PCI transactions to complete before
359 * resetting the device
363 ctrl = E1000_READ_REG(hw, CTRL);
365 /* Must reset the PHY before resetting the MAC */
366 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
367 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
371 /* Issue a global reset to the MAC. This will reset the chip's
372 * transmit, receive, DMA, and link units. It will not effect
373 * the current PCI configuration. The global reset bit is self-
374 * clearing, and should clear within a microsecond.
376 DEBUGOUT("Issuing a global reset to MAC\n");
378 switch(hw->mac_type) {
384 case e1000_82541_rev_2:
385 /* These controllers can't ack the 64-bit write when issuing the
386 * reset, so use IO-mapping as a workaround to issue the reset */
387 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
389 case e1000_82545_rev_3:
390 case e1000_82546_rev_3:
391 /* Reset is performed on a shadow of the control register */
392 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
395 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
399 /* After MAC reset, force reload of EEPROM to restore power-on settings to
400 * device. Later controllers reload the EEPROM automatically, so just wait
401 * for reload to complete.
403 switch(hw->mac_type) {
404 case e1000_82542_rev2_0:
405 case e1000_82542_rev2_1:
408 /* Wait for reset to complete */
410 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
411 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
412 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
413 E1000_WRITE_FLUSH(hw);
414 /* Wait for EEPROM reload */
418 case e1000_82541_rev_2:
420 case e1000_82547_rev_2:
421 /* Wait for EEPROM reload */
425 /* Wait for EEPROM reload (it happens automatically) */
430 /* Disable HW ARPs on ASF enabled adapters */
431 if(hw->mac_type >= e1000_82540) {
432 manc = E1000_READ_REG(hw, MANC);
433 manc &= ~(E1000_MANC_ARP_EN);
434 E1000_WRITE_REG(hw, MANC, manc);
437 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
438 e1000_phy_init_script(hw);
440 /* Configure activity LED after PHY reset */
441 led_ctrl = E1000_READ_REG(hw, LEDCTL);
442 led_ctrl &= IGP_ACTIVITY_LED_MASK;
443 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
444 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
447 /* Clear interrupt mask to stop board from generating interrupts */
448 DEBUGOUT("Masking off all interrupts\n");
449 E1000_WRITE_REG(hw, IMC, 0xffffffff);
451 /* Clear any pending interrupt events. */
452 icr = E1000_READ_REG(hw, ICR);
454 /* If MWI was previously enabled, reenable it. */
455 if(hw->mac_type == e1000_82542_rev2_0) {
456 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
457 e1000_pci_set_mwi(hw);
460 return E1000_SUCCESS;
463 /******************************************************************************
464 * Performs basic configuration of the adapter.
466 * hw - Struct containing variables accessed by shared code
468 * Assumes that the controller has previously been reset and is in a
469 * post-reset uninitialized state. Initializes the receive address registers,
470 * multicast table, and VLAN filter table. Calls routines to setup link
471 * configuration and flow control settings. Clears all on-chip counters. Leaves
472 * the transmit and receive units disabled and uninitialized.
473 *****************************************************************************/
475 e1000_init_hw(struct e1000_hw *hw)
480 uint16_t pcix_cmd_word;
481 uint16_t pcix_stat_hi_word;
484 DEBUGFUNC("e1000_init_hw");
486 /* Initialize Identification LED */
487 ret_val = e1000_id_led_init(hw);
489 DEBUGOUT("Error Initializing Identification LED\n");
493 /* Set the media type and TBI compatibility */
494 e1000_set_media_type(hw);
496 /* Disabling VLAN filtering. */
497 DEBUGOUT("Initializing the IEEE VLAN\n");
498 E1000_WRITE_REG(hw, VET, 0);
500 e1000_clear_vfta(hw);
502 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
503 if(hw->mac_type == e1000_82542_rev2_0) {
504 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
505 e1000_pci_clear_mwi(hw);
506 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
507 E1000_WRITE_FLUSH(hw);
511 /* Setup the receive address. This involves initializing all of the Receive
512 * Address Registers (RARs 0 - 15).
514 e1000_init_rx_addrs(hw);
516 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
517 if(hw->mac_type == e1000_82542_rev2_0) {
518 E1000_WRITE_REG(hw, RCTL, 0);
519 E1000_WRITE_FLUSH(hw);
521 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
522 e1000_pci_set_mwi(hw);
525 /* Zero out the Multicast HASH table */
526 DEBUGOUT("Zeroing the MTA\n");
527 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
528 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
530 /* Set the PCI priority bit correctly in the CTRL register. This
531 * determines if the adapter gives priority to receives, or if it
532 * gives equal priority to transmits and receives.
534 if(hw->dma_fairness) {
535 ctrl = E1000_READ_REG(hw, CTRL);
536 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
539 switch(hw->mac_type) {
540 case e1000_82545_rev_3:
541 case e1000_82546_rev_3:
544 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
545 if(hw->bus_type == e1000_bus_type_pcix) {
546 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
547 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
549 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
550 PCIX_COMMAND_MMRBC_SHIFT;
551 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
552 PCIX_STATUS_HI_MMRBC_SHIFT;
553 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
554 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
555 if(cmd_mmrbc > stat_mmrbc) {
556 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
557 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
558 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
565 /* Call a subroutine to configure the link and setup flow control. */
566 ret_val = e1000_setup_link(hw);
568 /* Set the transmit descriptor write-back policy */
569 if(hw->mac_type > e1000_82544) {
570 ctrl = E1000_READ_REG(hw, TXDCTL);
571 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
572 E1000_WRITE_REG(hw, TXDCTL, ctrl);
575 /* Clear all of the statistics registers (clear on read). It is
576 * important that we do this after we have tried to establish link
577 * because the symbol error count will increment wildly if there
580 e1000_clear_hw_cntrs(hw);
585 /******************************************************************************
586 * Adjust SERDES output amplitude based on EEPROM setting.
588 * hw - Struct containing variables accessed by shared code.
589 *****************************************************************************/
591 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
593 uint16_t eeprom_data;
596 DEBUGFUNC("e1000_adjust_serdes_amplitude");
598 if(hw->media_type != e1000_media_type_internal_serdes)
599 return E1000_SUCCESS;
601 switch(hw->mac_type) {
602 case e1000_82545_rev_3:
603 case e1000_82546_rev_3:
606 return E1000_SUCCESS;
609 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
614 if(eeprom_data != EEPROM_RESERVED_WORD) {
615 /* Adjust SERDES output amplitude only. */
616 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
617 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
622 return E1000_SUCCESS;
625 /******************************************************************************
626 * Configures flow control and link settings.
628 * hw - Struct containing variables accessed by shared code
630 * Determines which flow control settings to use. Calls the apropriate media-
631 * specific link configuration function. Configures the flow control settings.
632 * Assuming the adapter has a valid link partner, a valid link should be
633 * established. Assumes the hardware has previously been reset and the
634 * transmitter and receiver are not enabled.
635 *****************************************************************************/
637 e1000_setup_link(struct e1000_hw *hw)
641 uint16_t eeprom_data;
643 DEBUGFUNC("e1000_setup_link");
645 /* Read and store word 0x0F of the EEPROM. This word contains bits
646 * that determine the hardware's default PAUSE (flow control) mode,
647 * a bit that determines whether the HW defaults to enabling or
648 * disabling auto-negotiation, and the direction of the
649 * SW defined pins. If there is no SW over-ride of the flow
650 * control setting, then the variable hw->fc will
651 * be initialized based on a value in the EEPROM.
653 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
654 DEBUGOUT("EEPROM Read Error\n");
655 return -E1000_ERR_EEPROM;
658 if(hw->fc == e1000_fc_default) {
659 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
660 hw->fc = e1000_fc_none;
661 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
662 EEPROM_WORD0F_ASM_DIR)
663 hw->fc = e1000_fc_tx_pause;
665 hw->fc = e1000_fc_full;
668 /* We want to save off the original Flow Control configuration just
669 * in case we get disconnected and then reconnected into a different
670 * hub or switch with different Flow Control capabilities.
672 if(hw->mac_type == e1000_82542_rev2_0)
673 hw->fc &= (~e1000_fc_tx_pause);
675 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
676 hw->fc &= (~e1000_fc_rx_pause);
678 hw->original_fc = hw->fc;
680 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
682 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
683 * polarity value for the SW controlled pins, and setup the
684 * Extended Device Control reg with that info.
685 * This is needed because one of the SW controlled pins is used for
686 * signal detection. So this should be done before e1000_setup_pcs_link()
687 * or e1000_phy_setup() is called.
689 if(hw->mac_type == e1000_82543) {
690 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
692 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
695 /* Call the necessary subroutine to configure the link. */
696 ret_val = (hw->media_type == e1000_media_type_copper) ?
697 e1000_setup_copper_link(hw) :
698 e1000_setup_fiber_serdes_link(hw);
700 /* Initialize the flow control address, type, and PAUSE timer
701 * registers to their default values. This is done even if flow
702 * control is disabled, because it does not hurt anything to
703 * initialize these registers.
705 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
707 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
708 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
709 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
710 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
712 /* Set the flow control receive threshold registers. Normally,
713 * these registers will be set to a default threshold that may be
714 * adjusted later by the driver's runtime code. However, if the
715 * ability to transmit pause frames in not enabled, then these
716 * registers will be set to 0.
718 if(!(hw->fc & e1000_fc_tx_pause)) {
719 E1000_WRITE_REG(hw, FCRTL, 0);
720 E1000_WRITE_REG(hw, FCRTH, 0);
722 /* We need to set up the Receive Threshold high and low water marks
723 * as well as (optionally) enabling the transmission of XON frames.
725 if(hw->fc_send_xon) {
726 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
727 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
729 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
730 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
736 /******************************************************************************
737 * Sets up link for a fiber based or serdes based adapter
739 * hw - Struct containing variables accessed by shared code
741 * Manipulates Physical Coding Sublayer functions in order to configure
742 * link. Assumes the hardware has been previously reset and the transmitter
743 * and receiver are not enabled.
744 *****************************************************************************/
746 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
755 DEBUGFUNC("e1000_setup_fiber_serdes_link");
757 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
758 * set when the optics detect a signal. On older adapters, it will be
759 * cleared when there is a signal. This applies to fiber media only.
760 * If we're on serdes media, adjust the output amplitude to value set in
763 ctrl = E1000_READ_REG(hw, CTRL);
764 if(hw->media_type == e1000_media_type_fiber)
765 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
767 ret_val = e1000_adjust_serdes_amplitude(hw);
771 /* Take the link out of reset */
772 ctrl &= ~(E1000_CTRL_LRST);
774 /* Adjust VCO speed to improve BER performance */
775 ret_val = e1000_set_vco_speed(hw);
779 e1000_config_collision_dist(hw);
781 /* Check for a software override of the flow control settings, and setup
782 * the device accordingly. If auto-negotiation is enabled, then software
783 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
784 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
785 * auto-negotiation is disabled, then software will have to manually
786 * configure the two flow control enable bits in the CTRL register.
788 * The possible values of the "fc" parameter are:
789 * 0: Flow control is completely disabled
790 * 1: Rx flow control is enabled (we can receive pause frames, but
791 * not send pause frames).
792 * 2: Tx flow control is enabled (we can send pause frames but we do
793 * not support receiving pause frames).
794 * 3: Both Rx and TX flow control (symmetric) are enabled.
798 /* Flow control is completely disabled by a software over-ride. */
799 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
801 case e1000_fc_rx_pause:
802 /* RX Flow control is enabled and TX Flow control is disabled by a
803 * software over-ride. Since there really isn't a way to advertise
804 * that we are capable of RX Pause ONLY, we will advertise that we
805 * support both symmetric and asymmetric RX PAUSE. Later, we will
806 * disable the adapter's ability to send PAUSE frames.
808 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
810 case e1000_fc_tx_pause:
811 /* TX Flow control is enabled, and RX Flow control is disabled, by a
812 * software over-ride.
814 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
817 /* Flow control (both RX and TX) is enabled by a software over-ride. */
818 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
821 DEBUGOUT("Flow control param set incorrectly\n");
822 return -E1000_ERR_CONFIG;
826 /* Since auto-negotiation is enabled, take the link out of reset (the link
827 * will be in reset, because we previously reset the chip). This will
828 * restart auto-negotiation. If auto-neogtiation is successful then the
829 * link-up status bit will be set and the flow control enable bits (RFCE
830 * and TFCE) will be set according to their negotiated value.
832 DEBUGOUT("Auto-negotiation enabled\n");
834 E1000_WRITE_REG(hw, TXCW, txcw);
835 E1000_WRITE_REG(hw, CTRL, ctrl);
836 E1000_WRITE_FLUSH(hw);
841 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
842 * indication in the Device Status Register. Time-out if a link isn't
843 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
844 * less than 500 milliseconds even if the other end is doing it in SW).
845 * For internal serdes, we just assume a signal is present, then poll.
847 if(hw->media_type == e1000_media_type_internal_serdes ||
848 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
849 DEBUGOUT("Looking for Link\n");
850 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
852 status = E1000_READ_REG(hw, STATUS);
853 if(status & E1000_STATUS_LU) break;
855 if(i == (LINK_UP_TIMEOUT / 10)) {
856 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
857 hw->autoneg_failed = 1;
858 /* AutoNeg failed to achieve a link, so we'll call
859 * e1000_check_for_link. This routine will force the link up if
860 * we detect a signal. This will allow us to communicate with
861 * non-autonegotiating link partners.
863 ret_val = e1000_check_for_link(hw);
865 DEBUGOUT("Error while checking for link\n");
868 hw->autoneg_failed = 0;
870 hw->autoneg_failed = 0;
871 DEBUGOUT("Valid Link Found\n");
874 DEBUGOUT("No Signal Detected\n");
876 return E1000_SUCCESS;
879 /******************************************************************************
880 * Detects which PHY is present and the speed and duplex
882 * hw - Struct containing variables accessed by shared code
883 ******************************************************************************/
885 e1000_setup_copper_link(struct e1000_hw *hw)
893 DEBUGFUNC("e1000_setup_copper_link");
895 ctrl = E1000_READ_REG(hw, CTRL);
896 /* With 82543, we need to force speed and duplex on the MAC equal to what
897 * the PHY speed and duplex configuration is. In addition, we need to
898 * perform a hardware reset on the PHY to take it out of reset.
900 if(hw->mac_type > e1000_82543) {
901 ctrl |= E1000_CTRL_SLU;
902 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
903 E1000_WRITE_REG(hw, CTRL, ctrl);
905 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
906 E1000_WRITE_REG(hw, CTRL, ctrl);
907 e1000_phy_hw_reset(hw);
910 /* Make sure we have a valid PHY */
911 ret_val = e1000_detect_gig_phy(hw);
913 DEBUGOUT("Error, did not detect valid phy.\n");
916 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
918 /* Set PHY to class A mode (if necessary) */
919 ret_val = e1000_set_phy_mode(hw);
923 if(hw->mac_type == e1000_82545_rev_3) {
924 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
925 phy_data |= 0x00000008;
926 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
929 if(hw->mac_type <= e1000_82543 ||
930 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
931 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
932 hw->phy_reset_disable = FALSE;
934 if(!hw->phy_reset_disable) {
935 if (hw->phy_type == e1000_phy_igp) {
937 ret_val = e1000_phy_reset(hw);
939 DEBUGOUT("Error Resetting the PHY\n");
943 /* Wait 10ms for MAC to configure PHY from eeprom settings */
946 /* Configure activity LED after PHY reset */
947 led_ctrl = E1000_READ_REG(hw, LEDCTL);
948 led_ctrl &= IGP_ACTIVITY_LED_MASK;
949 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
950 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
952 /* disable lplu d3 during driver init */
953 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
955 DEBUGOUT("Error Disabling LPLU D3\n");
959 /* Configure mdi-mdix settings */
960 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
965 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
966 hw->dsp_config_state = e1000_dsp_config_disabled;
967 /* Force MDI for IGP B-0 PHY */
968 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
969 IGP01E1000_PSCR_FORCE_MDI_MDIX);
973 hw->dsp_config_state = e1000_dsp_config_enabled;
974 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
978 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
981 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
985 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
989 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
994 /* set auto-master slave resolution settings */
996 e1000_ms_type phy_ms_setting = hw->master_slave;
998 if(hw->ffe_config_state == e1000_ffe_config_active)
999 hw->ffe_config_state = e1000_ffe_config_enabled;
1001 if(hw->dsp_config_state == e1000_dsp_config_activated)
1002 hw->dsp_config_state = e1000_dsp_config_enabled;
1004 /* when autonegotiation advertisment is only 1000Mbps then we
1005 * should disable SmartSpeed and enable Auto MasterSlave
1006 * resolution as hardware default. */
1007 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1008 /* Disable SmartSpeed */
1009 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1013 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1014 ret_val = e1000_write_phy_reg(hw,
1015 IGP01E1000_PHY_PORT_CONFIG,
1019 /* Set auto Master/Slave resolution process */
1020 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1023 phy_data &= ~CR_1000T_MS_ENABLE;
1024 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1029 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1033 /* load defaults for future use */
1034 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1035 ((phy_data & CR_1000T_MS_VALUE) ?
1036 e1000_ms_force_master :
1037 e1000_ms_force_slave) :
1040 switch (phy_ms_setting) {
1041 case e1000_ms_force_master:
1042 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1044 case e1000_ms_force_slave:
1045 phy_data |= CR_1000T_MS_ENABLE;
1046 phy_data &= ~(CR_1000T_MS_VALUE);
1049 phy_data &= ~CR_1000T_MS_ENABLE;
1053 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1058 /* Enable CRS on TX. This must be set for half-duplex operation. */
1059 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1064 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1067 * MDI/MDI-X = 0 (default)
1068 * 0 - Auto for all speeds
1071 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1073 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1077 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1080 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1083 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1087 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1092 * disable_polarity_correction = 0 (default)
1093 * Automatic Correction for Reversed Cable Polarity
1097 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1098 if(hw->disable_polarity_correction == 1)
1099 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1100 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1105 /* Force TX_CLK in the Extended PHY Specific Control Register
1108 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1113 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1115 if (hw->phy_revision < M88E1011_I_REV_4) {
1116 /* Configure Master and Slave downshift values */
1117 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1118 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1119 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1120 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1121 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1127 /* SW Reset the PHY so all changes take effect */
1128 ret_val = e1000_phy_reset(hw);
1130 DEBUGOUT("Error Resetting the PHY\n");
1136 * autoneg = 1 (default)
1137 * PHY will advertise value(s) parsed from
1138 * autoneg_advertised and fc
1140 * PHY will be set to 10H, 10F, 100H, or 100F
1141 * depending on value parsed from forced_speed_duplex.
1144 /* Is autoneg enabled? This is enabled by default or by software
1145 * override. If so, call e1000_phy_setup_autoneg routine to parse the
1146 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1147 * the user should have provided a speed/duplex override. If so, then
1148 * call e1000_phy_force_speed_duplex to parse and set this up.
1151 /* Perform some bounds checking on the hw->autoneg_advertised
1152 * parameter. If this variable is zero, then set it to the default.
1154 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1156 /* If autoneg_advertised is zero, we assume it was not defaulted
1157 * by the calling code so we set to advertise full capability.
1159 if(hw->autoneg_advertised == 0)
1160 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1162 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1163 ret_val = e1000_phy_setup_autoneg(hw);
1165 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1168 DEBUGOUT("Restarting Auto-Neg\n");
1170 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1171 * the Auto Neg Restart bit in the PHY control register.
1173 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1177 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1178 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1182 /* Does the user want to wait for Auto-Neg to complete here, or
1183 * check at a later time (for example, callback routine).
1185 if(hw->wait_autoneg_complete) {
1186 ret_val = e1000_wait_autoneg(hw);
1188 DEBUGOUT("Error while waiting for autoneg to complete\n");
1192 hw->get_link_status = TRUE;
1194 DEBUGOUT("Forcing speed and duplex\n");
1195 ret_val = e1000_phy_force_speed_duplex(hw);
1197 DEBUGOUT("Error Forcing Speed and Duplex\n");
1201 } /* !hw->phy_reset_disable */
1203 /* Check link status. Wait up to 100 microseconds for link to become
1206 for(i = 0; i < 10; i++) {
1207 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1210 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1214 if(phy_data & MII_SR_LINK_STATUS) {
1215 /* We have link, so we need to finish the config process:
1216 * 1) Set up the MAC to the current PHY speed/duplex
1217 * if we are on 82543. If we
1218 * are on newer silicon, we only need to configure
1219 * collision distance in the Transmit Control Register.
1220 * 2) Set up flow control on the MAC to that established with
1223 if(hw->mac_type >= e1000_82544) {
1224 e1000_config_collision_dist(hw);
1226 ret_val = e1000_config_mac_to_phy(hw);
1228 DEBUGOUT("Error configuring MAC to PHY settings\n");
1232 ret_val = e1000_config_fc_after_link_up(hw);
1234 DEBUGOUT("Error Configuring Flow Control\n");
1237 DEBUGOUT("Valid link established!!!\n");
1239 if(hw->phy_type == e1000_phy_igp) {
1240 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1242 DEBUGOUT("Error Configuring DSP after link up\n");
1246 DEBUGOUT("Valid link established!!!\n");
1247 return E1000_SUCCESS;
1252 DEBUGOUT("Unable to establish link!!!\n");
1253 return E1000_SUCCESS;
1256 /******************************************************************************
1257 * Configures PHY autoneg and flow control advertisement settings
1259 * hw - Struct containing variables accessed by shared code
1260 ******************************************************************************/
1262 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1265 uint16_t mii_autoneg_adv_reg;
1266 uint16_t mii_1000t_ctrl_reg;
1268 DEBUGFUNC("e1000_phy_setup_autoneg");
1270 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1271 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1275 /* Read the MII 1000Base-T Control Register (Address 9). */
1276 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1280 /* Need to parse both autoneg_advertised and fc and set up
1281 * the appropriate PHY registers. First we will parse for
1282 * autoneg_advertised software override. Since we can advertise
1283 * a plethora of combinations, we need to check each bit
1287 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1288 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1289 * the 1000Base-T Control Register (Address 9).
1291 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1292 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1294 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1296 /* Do we want to advertise 10 Mb Half Duplex? */
1297 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1298 DEBUGOUT("Advertise 10mb Half duplex\n");
1299 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1302 /* Do we want to advertise 10 Mb Full Duplex? */
1303 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1304 DEBUGOUT("Advertise 10mb Full duplex\n");
1305 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1308 /* Do we want to advertise 100 Mb Half Duplex? */
1309 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1310 DEBUGOUT("Advertise 100mb Half duplex\n");
1311 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1314 /* Do we want to advertise 100 Mb Full Duplex? */
1315 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1316 DEBUGOUT("Advertise 100mb Full duplex\n");
1317 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1320 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1321 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1322 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1325 /* Do we want to advertise 1000 Mb Full Duplex? */
1326 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1327 DEBUGOUT("Advertise 1000mb Full duplex\n");
1328 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1331 /* Check for a software override of the flow control settings, and
1332 * setup the PHY advertisement registers accordingly. If
1333 * auto-negotiation is enabled, then software will have to set the
1334 * "PAUSE" bits to the correct value in the Auto-Negotiation
1335 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1337 * The possible values of the "fc" parameter are:
1338 * 0: Flow control is completely disabled
1339 * 1: Rx flow control is enabled (we can receive pause frames
1340 * but not send pause frames).
1341 * 2: Tx flow control is enabled (we can send pause frames
1342 * but we do not support receiving pause frames).
1343 * 3: Both Rx and TX flow control (symmetric) are enabled.
1344 * other: No software override. The flow control configuration
1345 * in the EEPROM is used.
1348 case e1000_fc_none: /* 0 */
1349 /* Flow control (RX & TX) is completely disabled by a
1350 * software over-ride.
1352 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1354 case e1000_fc_rx_pause: /* 1 */
1355 /* RX Flow control is enabled, and TX Flow control is
1356 * disabled, by a software over-ride.
1358 /* Since there really isn't a way to advertise that we are
1359 * capable of RX Pause ONLY, we will advertise that we
1360 * support both symmetric and asymmetric RX PAUSE. Later
1361 * (in e1000_config_fc_after_link_up) we will disable the
1362 *hw's ability to send PAUSE frames.
1364 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1366 case e1000_fc_tx_pause: /* 2 */
1367 /* TX Flow control is enabled, and RX Flow control is
1368 * disabled, by a software over-ride.
1370 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1371 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1373 case e1000_fc_full: /* 3 */
1374 /* Flow control (both RX and TX) is enabled by a software
1377 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1380 DEBUGOUT("Flow control param set incorrectly\n");
1381 return -E1000_ERR_CONFIG;
1384 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1388 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1390 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1394 return E1000_SUCCESS;
1397 /******************************************************************************
1398 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1400 * hw - Struct containing variables accessed by shared code
1401 ******************************************************************************/
1403 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1407 uint16_t mii_ctrl_reg;
1408 uint16_t mii_status_reg;
1412 DEBUGFUNC("e1000_phy_force_speed_duplex");
1414 /* Turn off Flow control if we are forcing speed and duplex. */
1415 hw->fc = e1000_fc_none;
1417 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1419 /* Read the Device Control Register. */
1420 ctrl = E1000_READ_REG(hw, CTRL);
1422 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1423 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1424 ctrl &= ~(DEVICE_SPEED_MASK);
1426 /* Clear the Auto Speed Detect Enable bit. */
1427 ctrl &= ~E1000_CTRL_ASDE;
1429 /* Read the MII Control Register. */
1430 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1434 /* We need to disable autoneg in order to force link and duplex. */
1436 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1438 /* Are we forcing Full or Half Duplex? */
1439 if(hw->forced_speed_duplex == e1000_100_full ||
1440 hw->forced_speed_duplex == e1000_10_full) {
1441 /* We want to force full duplex so we SET the full duplex bits in the
1442 * Device and MII Control Registers.
1444 ctrl |= E1000_CTRL_FD;
1445 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1446 DEBUGOUT("Full Duplex\n");
1448 /* We want to force half duplex so we CLEAR the full duplex bits in
1449 * the Device and MII Control Registers.
1451 ctrl &= ~E1000_CTRL_FD;
1452 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1453 DEBUGOUT("Half Duplex\n");
1456 /* Are we forcing 100Mbps??? */
1457 if(hw->forced_speed_duplex == e1000_100_full ||
1458 hw->forced_speed_duplex == e1000_100_half) {
1459 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1460 ctrl |= E1000_CTRL_SPD_100;
1461 mii_ctrl_reg |= MII_CR_SPEED_100;
1462 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1463 DEBUGOUT("Forcing 100mb ");
1465 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1466 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1467 mii_ctrl_reg |= MII_CR_SPEED_10;
1468 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1469 DEBUGOUT("Forcing 10mb ");
1472 e1000_config_collision_dist(hw);
1474 /* Write the configured values back to the Device Control Reg. */
1475 E1000_WRITE_REG(hw, CTRL, ctrl);
1477 if (hw->phy_type == e1000_phy_m88) {
1478 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1482 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1483 * forced whenever speed are duplex are forced.
1485 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1486 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1490 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1492 /* Need to reset the PHY or these changes will be ignored */
1493 mii_ctrl_reg |= MII_CR_RESET;
1495 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1496 * forced whenever speed or duplex are forced.
1498 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1502 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1503 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1505 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1510 /* Write back the modified PHY MII control register. */
1511 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1517 /* The wait_autoneg_complete flag may be a little misleading here.
1518 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1519 * But we do want to delay for a period while forcing only so we
1520 * don't generate false No Link messages. So we will wait here
1521 * only if the user has set wait_autoneg_complete to 1, which is
1524 if(hw->wait_autoneg_complete) {
1525 /* We will wait for autoneg to complete. */
1526 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1529 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1530 for(i = PHY_FORCE_TIME; i > 0; i--) {
1531 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1534 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1538 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1542 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1545 if((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1546 /* We didn't get link. Reset the DSP and wait again for link. */
1547 ret_val = e1000_phy_reset_dsp(hw);
1549 DEBUGOUT("Error Resetting PHY DSP\n");
1553 /* This loop will early-out if the link condition has been met. */
1554 for(i = PHY_FORCE_TIME; i > 0; i--) {
1555 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1557 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1560 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1564 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1570 if (hw->phy_type == e1000_phy_m88) {
1571 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1572 * Extended PHY Specific Control Register to 25MHz clock. This value
1573 * defaults back to a 2.5MHz clock when the PHY is reset.
1575 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1579 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1580 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1584 /* In addition, because of the s/w reset above, we need to enable CRS on
1585 * TX. This must be set for both full and half duplex operation.
1587 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1591 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1592 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1596 return E1000_SUCCESS;
1599 /******************************************************************************
1600 * Sets the collision distance in the Transmit Control register
1602 * hw - Struct containing variables accessed by shared code
1604 * Link should have been established previously. Reads the speed and duplex
1605 * information from the Device Status register.
1606 ******************************************************************************/
1608 e1000_config_collision_dist(struct e1000_hw *hw)
1612 DEBUGFUNC("e1000_config_collision_dist");
1614 tctl = E1000_READ_REG(hw, TCTL);
1616 tctl &= ~E1000_TCTL_COLD;
1617 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1619 E1000_WRITE_REG(hw, TCTL, tctl);
1620 E1000_WRITE_FLUSH(hw);
1623 /******************************************************************************
1624 * Sets MAC speed and duplex settings to reflect the those in the PHY
1626 * hw - Struct containing variables accessed by shared code
1627 * mii_reg - data to write to the MII control register
1629 * The contents of the PHY register containing the needed information need to
1631 ******************************************************************************/
1633 e1000_config_mac_to_phy(struct e1000_hw *hw)
1639 DEBUGFUNC("e1000_config_mac_to_phy");
1641 /* Read the Device Control Register and set the bits to Force Speed
1644 ctrl = E1000_READ_REG(hw, CTRL);
1645 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1646 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1648 /* Set up duplex in the Device Control and Transmit Control
1649 * registers depending on negotiated values.
1651 if (hw->phy_type == e1000_phy_igp) {
1652 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
1657 if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
1658 else ctrl &= ~E1000_CTRL_FD;
1660 e1000_config_collision_dist(hw);
1662 /* Set up speed in the Device Control register depending on
1663 * negotiated values.
1665 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1666 IGP01E1000_PSSR_SPEED_1000MBPS)
1667 ctrl |= E1000_CTRL_SPD_1000;
1668 else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1669 IGP01E1000_PSSR_SPEED_100MBPS)
1670 ctrl |= E1000_CTRL_SPD_100;
1672 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
1677 if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1678 else ctrl &= ~E1000_CTRL_FD;
1680 e1000_config_collision_dist(hw);
1682 /* Set up speed in the Device Control register depending on
1683 * negotiated values.
1685 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1686 ctrl |= E1000_CTRL_SPD_1000;
1687 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1688 ctrl |= E1000_CTRL_SPD_100;
1690 /* Write the configured values back to the Device Control Reg. */
1691 E1000_WRITE_REG(hw, CTRL, ctrl);
1692 return E1000_SUCCESS;
1695 /******************************************************************************
1696 * Forces the MAC's flow control settings.
1698 * hw - Struct containing variables accessed by shared code
1700 * Sets the TFCE and RFCE bits in the device control register to reflect
1701 * the adapter settings. TFCE and RFCE need to be explicitly set by
1702 * software when a Copper PHY is used because autonegotiation is managed
1703 * by the PHY rather than the MAC. Software must also configure these
1704 * bits when link is forced on a fiber connection.
1705 *****************************************************************************/
1707 e1000_force_mac_fc(struct e1000_hw *hw)
1711 DEBUGFUNC("e1000_force_mac_fc");
1713 /* Get the current configuration of the Device Control Register */
1714 ctrl = E1000_READ_REG(hw, CTRL);
1716 /* Because we didn't get link via the internal auto-negotiation
1717 * mechanism (we either forced link or we got link via PHY
1718 * auto-neg), we have to manually enable/disable transmit an
1719 * receive flow control.
1721 * The "Case" statement below enables/disable flow control
1722 * according to the "hw->fc" parameter.
1724 * The possible values of the "fc" parameter are:
1725 * 0: Flow control is completely disabled
1726 * 1: Rx flow control is enabled (we can receive pause
1727 * frames but not send pause frames).
1728 * 2: Tx flow control is enabled (we can send pause frames
1729 * frames but we do not receive pause frames).
1730 * 3: Both Rx and TX flow control (symmetric) is enabled.
1731 * other: No other values should be possible at this point.
1736 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1738 case e1000_fc_rx_pause:
1739 ctrl &= (~E1000_CTRL_TFCE);
1740 ctrl |= E1000_CTRL_RFCE;
1742 case e1000_fc_tx_pause:
1743 ctrl &= (~E1000_CTRL_RFCE);
1744 ctrl |= E1000_CTRL_TFCE;
1747 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1750 DEBUGOUT("Flow control param set incorrectly\n");
1751 return -E1000_ERR_CONFIG;
1754 /* Disable TX Flow Control for 82542 (rev 2.0) */
1755 if(hw->mac_type == e1000_82542_rev2_0)
1756 ctrl &= (~E1000_CTRL_TFCE);
1758 E1000_WRITE_REG(hw, CTRL, ctrl);
1759 return E1000_SUCCESS;
1762 /******************************************************************************
1763 * Configures flow control settings after link is established
1765 * hw - Struct containing variables accessed by shared code
1767 * Should be called immediately after a valid link has been established.
1768 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1769 * and autonegotiation is enabled, the MAC flow control settings will be set
1770 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1771 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1772 *****************************************************************************/
1774 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1777 uint16_t mii_status_reg;
1778 uint16_t mii_nway_adv_reg;
1779 uint16_t mii_nway_lp_ability_reg;
1783 DEBUGFUNC("e1000_config_fc_after_link_up");
1785 /* Check for the case where we have fiber media and auto-neg failed
1786 * so we had to force link. In this case, we need to force the
1787 * configuration of the MAC to match the "fc" parameter.
1789 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1790 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
1791 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1792 ret_val = e1000_force_mac_fc(hw);
1794 DEBUGOUT("Error forcing flow control settings\n");
1799 /* Check for the case where we have copper media and auto-neg is
1800 * enabled. In this case, we need to check and see if Auto-Neg
1801 * has completed, and if so, how the PHY and link partner has
1802 * flow control configured.
1804 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1805 /* Read the MII Status Register and check to see if AutoNeg
1806 * has completed. We read this twice because this reg has
1807 * some "sticky" (latched) bits.
1809 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1812 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1816 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1817 /* The AutoNeg process has completed, so we now need to
1818 * read both the Auto Negotiation Advertisement Register
1819 * (Address 4) and the Auto_Negotiation Base Page Ability
1820 * Register (Address 5) to determine how flow control was
1823 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1827 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1828 &mii_nway_lp_ability_reg);
1832 /* Two bits in the Auto Negotiation Advertisement Register
1833 * (Address 4) and two bits in the Auto Negotiation Base
1834 * Page Ability Register (Address 5) determine flow control
1835 * for both the PHY and the link partner. The following
1836 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1837 * 1999, describes these PAUSE resolution bits and how flow
1838 * control is determined based upon these settings.
1839 * NOTE: DC = Don't Care
1841 * LOCAL DEVICE | LINK PARTNER
1842 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1843 *-------|---------|-------|---------|--------------------
1844 * 0 | 0 | DC | DC | e1000_fc_none
1845 * 0 | 1 | 0 | DC | e1000_fc_none
1846 * 0 | 1 | 1 | 0 | e1000_fc_none
1847 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1848 * 1 | 0 | 0 | DC | e1000_fc_none
1849 * 1 | DC | 1 | DC | e1000_fc_full
1850 * 1 | 1 | 0 | 0 | e1000_fc_none
1851 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1854 /* Are both PAUSE bits set to 1? If so, this implies
1855 * Symmetric Flow Control is enabled at both ends. The
1856 * ASM_DIR bits are irrelevant per the spec.
1858 * For Symmetric Flow Control:
1860 * LOCAL DEVICE | LINK PARTNER
1861 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1862 *-------|---------|-------|---------|--------------------
1863 * 1 | DC | 1 | DC | e1000_fc_full
1866 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1867 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1868 /* Now we need to check if the user selected RX ONLY
1869 * of pause frames. In this case, we had to advertise
1870 * FULL flow control because we could not advertise RX
1871 * ONLY. Hence, we must now check to see if we need to
1872 * turn OFF the TRANSMISSION of PAUSE frames.
1874 if(hw->original_fc == e1000_fc_full) {
1875 hw->fc = e1000_fc_full;
1876 DEBUGOUT("Flow Control = FULL.\r\n");
1878 hw->fc = e1000_fc_rx_pause;
1879 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1882 /* For receiving PAUSE frames ONLY.
1884 * LOCAL DEVICE | LINK PARTNER
1885 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1886 *-------|---------|-------|---------|--------------------
1887 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1890 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1891 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1892 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1893 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1894 hw->fc = e1000_fc_tx_pause;
1895 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1897 /* For transmitting PAUSE frames ONLY.
1899 * LOCAL DEVICE | LINK PARTNER
1900 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1901 *-------|---------|-------|---------|--------------------
1902 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1905 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1906 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1907 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1908 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1909 hw->fc = e1000_fc_rx_pause;
1910 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1912 /* Per the IEEE spec, at this point flow control should be
1913 * disabled. However, we want to consider that we could
1914 * be connected to a legacy switch that doesn't advertise
1915 * desired flow control, but can be forced on the link
1916 * partner. So if we advertised no flow control, that is
1917 * what we will resolve to. If we advertised some kind of
1918 * receive capability (Rx Pause Only or Full Flow Control)
1919 * and the link partner advertised none, we will configure
1920 * ourselves to enable Rx Flow Control only. We can do
1921 * this safely for two reasons: If the link partner really
1922 * didn't want flow control enabled, and we enable Rx, no
1923 * harm done since we won't be receiving any PAUSE frames
1924 * anyway. If the intent on the link partner was to have
1925 * flow control enabled, then by us enabling RX only, we
1926 * can at least receive pause frames and process them.
1927 * This is a good idea because in most cases, since we are
1928 * predominantly a server NIC, more times than not we will
1929 * be asked to delay transmission of packets than asking
1930 * our link partner to pause transmission of frames.
1932 else if((hw->original_fc == e1000_fc_none ||
1933 hw->original_fc == e1000_fc_tx_pause) ||
1934 hw->fc_strict_ieee) {
1935 hw->fc = e1000_fc_none;
1936 DEBUGOUT("Flow Control = NONE.\r\n");
1938 hw->fc = e1000_fc_rx_pause;
1939 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1942 /* Now we need to do one last check... If we auto-
1943 * negotiated to HALF DUPLEX, flow control should not be
1944 * enabled per IEEE 802.3 spec.
1946 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
1948 DEBUGOUT("Error getting link speed and duplex\n");
1952 if(duplex == HALF_DUPLEX)
1953 hw->fc = e1000_fc_none;
1955 /* Now we call a subroutine to actually force the MAC
1956 * controller to use the correct flow control settings.
1958 ret_val = e1000_force_mac_fc(hw);
1960 DEBUGOUT("Error forcing flow control settings\n");
1964 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
1967 return E1000_SUCCESS;
1970 /******************************************************************************
1971 * Checks to see if the link status of the hardware has changed.
1973 * hw - Struct containing variables accessed by shared code
1975 * Called by any function that needs to check the link status of the adapter.
1976 *****************************************************************************/
1978 e1000_check_for_link(struct e1000_hw *hw)
1984 uint32_t signal = 0;
1988 DEBUGFUNC("e1000_check_for_link");
1990 ctrl = E1000_READ_REG(hw, CTRL);
1991 status = E1000_READ_REG(hw, STATUS);
1993 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1994 * set when the optics detect a signal. On older adapters, it will be
1995 * cleared when there is a signal. This applies to fiber media only.
1997 if((hw->media_type == e1000_media_type_fiber) ||
1998 (hw->media_type == e1000_media_type_internal_serdes)) {
1999 rxcw = E1000_READ_REG(hw, RXCW);
2001 if(hw->media_type == e1000_media_type_fiber) {
2002 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2003 if(status & E1000_STATUS_LU)
2004 hw->get_link_status = FALSE;
2008 /* If we have a copper PHY then we only want to go out to the PHY
2009 * registers to see if Auto-Neg has completed and/or if our link
2010 * status has changed. The get_link_status flag will be set if we
2011 * receive a Link Status Change interrupt or we have Rx Sequence
2014 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2015 /* First we want to see if the MII Status Register reports
2016 * link. If so, then we want to get the current speed/duplex
2018 * Read the register twice since the link bit is sticky.
2020 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2027 if(phy_data & MII_SR_LINK_STATUS) {
2028 hw->get_link_status = FALSE;
2029 /* Check if there was DownShift, must be checked immediately after
2031 e1000_check_downshift(hw);
2034 /* No link detected */
2035 e1000_config_dsp_after_link_change(hw, FALSE);
2039 /* If we are forcing speed/duplex, then we simply return since
2040 * we have already determined whether we have link or not.
2042 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2044 /* optimize the dsp settings for the igp phy */
2045 e1000_config_dsp_after_link_change(hw, TRUE);
2047 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2048 * have Si on board that is 82544 or newer, Auto
2049 * Speed Detection takes care of MAC speed/duplex
2050 * configuration. So we only need to configure Collision
2051 * Distance in the MAC. Otherwise, we need to force
2052 * speed/duplex on the MAC to the current PHY speed/duplex
2055 if(hw->mac_type >= e1000_82544)
2056 e1000_config_collision_dist(hw);
2058 ret_val = e1000_config_mac_to_phy(hw);
2060 DEBUGOUT("Error configuring MAC to PHY settings\n");
2065 /* Configure Flow Control now that Auto-Neg has completed. First, we
2066 * need to restore the desired flow control settings because we may
2067 * have had to re-autoneg with a different link partner.
2069 ret_val = e1000_config_fc_after_link_up(hw);
2071 DEBUGOUT("Error configuring flow control\n");
2075 /* At this point we know that we are on copper and we have
2076 * auto-negotiated link. These are conditions for checking the link
2077 * partner capability register. We use the link speed to determine if
2078 * TBI compatibility needs to be turned on or off. If the link is not
2079 * at gigabit speed, then TBI compatibility is not needed. If we are
2080 * at gigabit speed, we turn on TBI compatibility.
2082 if(hw->tbi_compatibility_en) {
2083 uint16_t speed, duplex;
2084 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2085 if(speed != SPEED_1000) {
2086 /* If link speed is not set to gigabit speed, we do not need
2087 * to enable TBI compatibility.
2089 if(hw->tbi_compatibility_on) {
2090 /* If we previously were in the mode, turn it off. */
2091 rctl = E1000_READ_REG(hw, RCTL);
2092 rctl &= ~E1000_RCTL_SBP;
2093 E1000_WRITE_REG(hw, RCTL, rctl);
2094 hw->tbi_compatibility_on = FALSE;
2097 /* If TBI compatibility is was previously off, turn it on. For
2098 * compatibility with a TBI link partner, we will store bad
2099 * packets. Some frames have an additional byte on the end and
2100 * will look like CRC errors to to the hardware.
2102 if(!hw->tbi_compatibility_on) {
2103 hw->tbi_compatibility_on = TRUE;
2104 rctl = E1000_READ_REG(hw, RCTL);
2105 rctl |= E1000_RCTL_SBP;
2106 E1000_WRITE_REG(hw, RCTL, rctl);
2111 /* If we don't have link (auto-negotiation failed or link partner cannot
2112 * auto-negotiate), the cable is plugged in (we have signal), and our
2113 * link partner is not trying to auto-negotiate with us (we are receiving
2114 * idles or data), we need to force link up. We also need to give
2115 * auto-negotiation time to complete, in case the cable was just plugged
2116 * in. The autoneg_failed flag does this.
2118 else if((((hw->media_type == e1000_media_type_fiber) &&
2119 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2120 (hw->media_type == e1000_media_type_internal_serdes)) &&
2121 (!(status & E1000_STATUS_LU)) &&
2122 (!(rxcw & E1000_RXCW_C))) {
2123 if(hw->autoneg_failed == 0) {
2124 hw->autoneg_failed = 1;
2127 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2129 /* Disable auto-negotiation in the TXCW register */
2130 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2132 /* Force link-up and also force full-duplex. */
2133 ctrl = E1000_READ_REG(hw, CTRL);
2134 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2135 E1000_WRITE_REG(hw, CTRL, ctrl);
2137 /* Configure Flow Control after forcing link up. */
2138 ret_val = e1000_config_fc_after_link_up(hw);
2140 DEBUGOUT("Error configuring flow control\n");
2144 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2145 * auto-negotiation in the TXCW register and disable forced link in the
2146 * Device Control register in an attempt to auto-negotiate with our link
2149 else if(((hw->media_type == e1000_media_type_fiber) ||
2150 (hw->media_type == e1000_media_type_internal_serdes)) &&
2151 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2152 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2153 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2154 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2156 hw->serdes_link_down = FALSE;
2158 /* If we force link for non-auto-negotiation switch, check link status
2159 * based on MAC synchronization for internal serdes media type.
2161 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2162 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2163 /* SYNCH bit and IV bit are sticky. */
2165 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2166 if(!(rxcw & E1000_RXCW_IV)) {
2167 hw->serdes_link_down = FALSE;
2168 DEBUGOUT("SERDES: Link is up.\n");
2171 hw->serdes_link_down = TRUE;
2172 DEBUGOUT("SERDES: Link is down.\n");
2175 if((hw->media_type == e1000_media_type_internal_serdes) &&
2176 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2177 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2179 return E1000_SUCCESS;
2182 /******************************************************************************
2183 * Detects the current speed and duplex settings of the hardware.
2185 * hw - Struct containing variables accessed by shared code
2186 * speed - Speed of the connection
2187 * duplex - Duplex setting of the connection
2188 *****************************************************************************/
2190 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2198 DEBUGFUNC("e1000_get_speed_and_duplex");
2200 if(hw->mac_type >= e1000_82543) {
2201 status = E1000_READ_REG(hw, STATUS);
2202 if(status & E1000_STATUS_SPEED_1000) {
2203 *speed = SPEED_1000;
2204 DEBUGOUT("1000 Mbs, ");
2205 } else if(status & E1000_STATUS_SPEED_100) {
2207 DEBUGOUT("100 Mbs, ");
2210 DEBUGOUT("10 Mbs, ");
2213 if(status & E1000_STATUS_FD) {
2214 *duplex = FULL_DUPLEX;
2215 DEBUGOUT("Full Duplex\r\n");
2217 *duplex = HALF_DUPLEX;
2218 DEBUGOUT(" Half Duplex\r\n");
2221 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2222 *speed = SPEED_1000;
2223 *duplex = FULL_DUPLEX;
2226 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2227 * if it is operating at half duplex. Here we set the duplex settings to
2228 * match the duplex in the link partner's capabilities.
2230 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2231 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2235 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2236 *duplex = HALF_DUPLEX;
2238 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2241 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2242 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2243 *duplex = HALF_DUPLEX;
2247 return E1000_SUCCESS;
2250 /******************************************************************************
2251 * Blocks until autoneg completes or times out (~4.5 seconds)
2253 * hw - Struct containing variables accessed by shared code
2254 ******************************************************************************/
2256 e1000_wait_autoneg(struct e1000_hw *hw)
2262 DEBUGFUNC("e1000_wait_autoneg");
2263 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2265 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2266 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2267 /* Read the MII Status Register and wait for Auto-Neg
2268 * Complete bit to be set.
2270 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2273 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2276 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2277 return E1000_SUCCESS;
2281 return E1000_SUCCESS;
2284 /******************************************************************************
2285 * Raises the Management Data Clock
2287 * hw - Struct containing variables accessed by shared code
2288 * ctrl - Device control register's current value
2289 ******************************************************************************/
2291 e1000_raise_mdi_clk(struct e1000_hw *hw,
2294 /* Raise the clock input to the Management Data Clock (by setting the MDC
2295 * bit), and then delay 10 microseconds.
2297 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2298 E1000_WRITE_FLUSH(hw);
2302 /******************************************************************************
2303 * Lowers the Management Data Clock
2305 * hw - Struct containing variables accessed by shared code
2306 * ctrl - Device control register's current value
2307 ******************************************************************************/
2309 e1000_lower_mdi_clk(struct e1000_hw *hw,
2312 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2313 * bit), and then delay 10 microseconds.
2315 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2316 E1000_WRITE_FLUSH(hw);
2320 /******************************************************************************
2321 * Shifts data bits out to the PHY
2323 * hw - Struct containing variables accessed by shared code
2324 * data - Data to send out to the PHY
2325 * count - Number of bits to shift out
2327 * Bits are shifted out in MSB to LSB order.
2328 ******************************************************************************/
2330 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2337 /* We need to shift "count" number of bits out to the PHY. So, the value
2338 * in the "data" parameter will be shifted out to the PHY one bit at a
2339 * time. In order to do this, "data" must be broken down into bits.
2342 mask <<= (count - 1);
2344 ctrl = E1000_READ_REG(hw, CTRL);
2346 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2347 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2350 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2351 * then raising and lowering the Management Data Clock. A "0" is
2352 * shifted out to the PHY by setting the MDIO bit to "0" and then
2353 * raising and lowering the clock.
2355 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2356 else ctrl &= ~E1000_CTRL_MDIO;
2358 E1000_WRITE_REG(hw, CTRL, ctrl);
2359 E1000_WRITE_FLUSH(hw);
2363 e1000_raise_mdi_clk(hw, &ctrl);
2364 e1000_lower_mdi_clk(hw, &ctrl);
2370 /******************************************************************************
2371 * Shifts data bits in from the PHY
2373 * hw - Struct containing variables accessed by shared code
2375 * Bits are shifted in in MSB to LSB order.
2376 ******************************************************************************/
2378 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2384 /* In order to read a register from the PHY, we need to shift in a total
2385 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2386 * to avoid contention on the MDIO pin when a read operation is performed.
2387 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2388 * by raising the input to the Management Data Clock (setting the MDC bit),
2389 * and then reading the value of the MDIO bit.
2391 ctrl = E1000_READ_REG(hw, CTRL);
2393 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2394 ctrl &= ~E1000_CTRL_MDIO_DIR;
2395 ctrl &= ~E1000_CTRL_MDIO;
2397 E1000_WRITE_REG(hw, CTRL, ctrl);
2398 E1000_WRITE_FLUSH(hw);
2400 /* Raise and Lower the clock before reading in the data. This accounts for
2401 * the turnaround bits. The first clock occurred when we clocked out the
2402 * last bit of the Register Address.
2404 e1000_raise_mdi_clk(hw, &ctrl);
2405 e1000_lower_mdi_clk(hw, &ctrl);
2407 for(data = 0, i = 0; i < 16; i++) {
2409 e1000_raise_mdi_clk(hw, &ctrl);
2410 ctrl = E1000_READ_REG(hw, CTRL);
2411 /* Check to see if we shifted in a "1". */
2412 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2413 e1000_lower_mdi_clk(hw, &ctrl);
2416 e1000_raise_mdi_clk(hw, &ctrl);
2417 e1000_lower_mdi_clk(hw, &ctrl);
2422 /*****************************************************************************
2423 * Reads the value from a PHY register, if the value is on a specific non zero
2424 * page, sets the page first.
2425 * hw - Struct containing variables accessed by shared code
2426 * reg_addr - address of the PHY register to read
2427 ******************************************************************************/
2429 e1000_read_phy_reg(struct e1000_hw *hw,
2435 DEBUGFUNC("e1000_read_phy_reg");
2437 if(hw->phy_type == e1000_phy_igp &&
2438 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2439 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2440 (uint16_t)reg_addr);
2445 ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2452 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2458 const uint32_t phy_addr = 1;
2460 DEBUGFUNC("e1000_read_phy_reg_ex");
2462 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2463 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2464 return -E1000_ERR_PARAM;
2467 if(hw->mac_type > e1000_82543) {
2468 /* Set up Op-code, Phy Address, and register address in the MDI
2469 * Control register. The MAC will take care of interfacing with the
2470 * PHY to retrieve the desired data.
2472 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2473 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2474 (E1000_MDIC_OP_READ));
2476 E1000_WRITE_REG(hw, MDIC, mdic);
2478 /* Poll the ready bit to see if the MDI read completed */
2479 for(i = 0; i < 64; i++) {
2481 mdic = E1000_READ_REG(hw, MDIC);
2482 if(mdic & E1000_MDIC_READY) break;
2484 if(!(mdic & E1000_MDIC_READY)) {
2485 DEBUGOUT("MDI Read did not complete\n");
2486 return -E1000_ERR_PHY;
2488 if(mdic & E1000_MDIC_ERROR) {
2489 DEBUGOUT("MDI Error\n");
2490 return -E1000_ERR_PHY;
2492 *phy_data = (uint16_t) mdic;
2494 /* We must first send a preamble through the MDIO pin to signal the
2495 * beginning of an MII instruction. This is done by sending 32
2496 * consecutive "1" bits.
2498 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2500 /* Now combine the next few fields that are required for a read
2501 * operation. We use this method instead of calling the
2502 * e1000_shift_out_mdi_bits routine five different times. The format of
2503 * a MII read instruction consists of a shift out of 14 bits and is
2504 * defined as follows:
2505 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2506 * followed by a shift in of 18 bits. This first two bits shifted in
2507 * are TurnAround bits used to avoid contention on the MDIO pin when a
2508 * READ operation is performed. These two bits are thrown away
2509 * followed by a shift in of 16 bits which contains the desired data.
2511 mdic = ((reg_addr) | (phy_addr << 5) |
2512 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2514 e1000_shift_out_mdi_bits(hw, mdic, 14);
2516 /* Now that we've shifted out the read command to the MII, we need to
2517 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2520 *phy_data = e1000_shift_in_mdi_bits(hw);
2522 return E1000_SUCCESS;
2525 /******************************************************************************
2526 * Writes a value to a PHY register
2528 * hw - Struct containing variables accessed by shared code
2529 * reg_addr - address of the PHY register to write
2530 * data - data to write to the PHY
2531 ******************************************************************************/
2533 e1000_write_phy_reg(struct e1000_hw *hw,
2539 DEBUGFUNC("e1000_write_phy_reg");
2541 if(hw->phy_type == e1000_phy_igp &&
2542 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2543 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2544 (uint16_t)reg_addr);
2549 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2556 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2562 const uint32_t phy_addr = 1;
2564 DEBUGFUNC("e1000_write_phy_reg_ex");
2566 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2567 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2568 return -E1000_ERR_PARAM;
2571 if(hw->mac_type > e1000_82543) {
2572 /* Set up Op-code, Phy Address, register address, and data intended
2573 * for the PHY register in the MDI Control register. The MAC will take
2574 * care of interfacing with the PHY to send the desired data.
2576 mdic = (((uint32_t) phy_data) |
2577 (reg_addr << E1000_MDIC_REG_SHIFT) |
2578 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2579 (E1000_MDIC_OP_WRITE));
2581 E1000_WRITE_REG(hw, MDIC, mdic);
2583 /* Poll the ready bit to see if the MDI read completed */
2584 for(i = 0; i < 640; i++) {
2586 mdic = E1000_READ_REG(hw, MDIC);
2587 if(mdic & E1000_MDIC_READY) break;
2589 if(!(mdic & E1000_MDIC_READY)) {
2590 DEBUGOUT("MDI Write did not complete\n");
2591 return -E1000_ERR_PHY;
2594 /* We'll need to use the SW defined pins to shift the write command
2595 * out to the PHY. We first send a preamble to the PHY to signal the
2596 * beginning of the MII instruction. This is done by sending 32
2597 * consecutive "1" bits.
2599 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2601 /* Now combine the remaining required fields that will indicate a
2602 * write operation. We use this method instead of calling the
2603 * e1000_shift_out_mdi_bits routine for each field in the command. The
2604 * format of a MII write instruction is as follows:
2605 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2607 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2608 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2610 mdic |= (uint32_t) phy_data;
2612 e1000_shift_out_mdi_bits(hw, mdic, 32);
2615 return E1000_SUCCESS;
2618 /******************************************************************************
2619 * Returns the PHY to the power-on reset state
2621 * hw - Struct containing variables accessed by shared code
2622 ******************************************************************************/
2624 e1000_phy_hw_reset(struct e1000_hw *hw)
2626 uint32_t ctrl, ctrl_ext;
2629 DEBUGFUNC("e1000_phy_hw_reset");
2631 DEBUGOUT("Resetting Phy...\n");
2633 if(hw->mac_type > e1000_82543) {
2634 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2635 * bit. Then, take it out of reset.
2637 ctrl = E1000_READ_REG(hw, CTRL);
2638 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2639 E1000_WRITE_FLUSH(hw);
2641 E1000_WRITE_REG(hw, CTRL, ctrl);
2642 E1000_WRITE_FLUSH(hw);
2644 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2645 * bit to put the PHY into reset. Then, take it out of reset.
2647 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2648 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2649 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2650 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2651 E1000_WRITE_FLUSH(hw);
2653 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2654 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2655 E1000_WRITE_FLUSH(hw);
2659 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2660 /* Configure activity LED after PHY reset */
2661 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2662 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2663 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2664 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2668 /******************************************************************************
2671 * hw - Struct containing variables accessed by shared code
2673 * Sets bit 15 of the MII Control regiser
2674 ******************************************************************************/
2676 e1000_phy_reset(struct e1000_hw *hw)
2681 DEBUGFUNC("e1000_phy_reset");
2683 if(hw->mac_type != e1000_82541_rev_2) {
2684 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2688 phy_data |= MII_CR_RESET;
2689 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2694 } else e1000_phy_hw_reset(hw);
2696 if(hw->phy_type == e1000_phy_igp)
2697 e1000_phy_init_script(hw);
2699 return E1000_SUCCESS;
2702 /******************************************************************************
2703 * Probes the expected PHY address for known PHY IDs
2705 * hw - Struct containing variables accessed by shared code
2706 ******************************************************************************/
2708 e1000_detect_gig_phy(struct e1000_hw *hw)
2710 int32_t phy_init_status, ret_val;
2711 uint16_t phy_id_high, phy_id_low;
2712 boolean_t match = FALSE;
2714 DEBUGFUNC("e1000_detect_gig_phy");
2716 /* Read the PHY ID Registers to identify which PHY is onboard. */
2717 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2721 hw->phy_id = (uint32_t) (phy_id_high << 16);
2723 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2727 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2728 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2730 switch(hw->mac_type) {
2732 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2735 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2739 case e1000_82545_rev_3:
2741 case e1000_82546_rev_3:
2742 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2745 case e1000_82541_rev_2:
2747 case e1000_82547_rev_2:
2748 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
2751 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2752 return -E1000_ERR_CONFIG;
2754 phy_init_status = e1000_set_phy_type(hw);
2756 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2757 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2758 return E1000_SUCCESS;
2760 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2761 return -E1000_ERR_PHY;
2764 /******************************************************************************
2765 * Resets the PHY's DSP
2767 * hw - Struct containing variables accessed by shared code
2768 ******************************************************************************/
2770 e1000_phy_reset_dsp(struct e1000_hw *hw)
2773 DEBUGFUNC("e1000_phy_reset_dsp");
2776 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
2778 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
2780 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
2782 ret_val = E1000_SUCCESS;
2788 /******************************************************************************
2789 * Get PHY information from various PHY registers for igp PHY only.
2791 * hw - Struct containing variables accessed by shared code
2792 * phy_info - PHY information structure
2793 ******************************************************************************/
2795 e1000_phy_igp_get_info(struct e1000_hw *hw,
2796 struct e1000_phy_info *phy_info)
2799 uint16_t phy_data, polarity, min_length, max_length, average;
2801 DEBUGFUNC("e1000_phy_igp_get_info");
2803 /* The downshift status is checked only once, after link is established,
2804 * and it stored in the hw->speed_downgraded parameter. */
2805 phy_info->downshift = hw->speed_downgraded;
2807 /* IGP01E1000 does not need to support it. */
2808 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2810 /* IGP01E1000 always correct polarity reversal */
2811 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
2813 /* Check polarity status */
2814 ret_val = e1000_check_polarity(hw, &polarity);
2818 phy_info->cable_polarity = polarity;
2820 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
2824 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
2825 IGP01E1000_PSSR_MDIX_SHIFT;
2827 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
2828 IGP01E1000_PSSR_SPEED_1000MBPS) {
2829 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2830 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2834 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2835 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2836 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2837 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2839 /* Get cable length */
2840 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
2844 /* transalte to old method */
2845 average = (max_length + min_length) / 2;
2847 if(average <= e1000_igp_cable_length_50)
2848 phy_info->cable_length = e1000_cable_length_50;
2849 else if(average <= e1000_igp_cable_length_80)
2850 phy_info->cable_length = e1000_cable_length_50_80;
2851 else if(average <= e1000_igp_cable_length_110)
2852 phy_info->cable_length = e1000_cable_length_80_110;
2853 else if(average <= e1000_igp_cable_length_140)
2854 phy_info->cable_length = e1000_cable_length_110_140;
2856 phy_info->cable_length = e1000_cable_length_140;
2859 return E1000_SUCCESS;
2862 /******************************************************************************
2863 * Get PHY information from various PHY registers fot m88 PHY only.
2865 * hw - Struct containing variables accessed by shared code
2866 * phy_info - PHY information structure
2867 ******************************************************************************/
2869 e1000_phy_m88_get_info(struct e1000_hw *hw,
2870 struct e1000_phy_info *phy_info)
2873 uint16_t phy_data, polarity;
2875 DEBUGFUNC("e1000_phy_m88_get_info");
2877 /* The downshift status is checked only once, after link is established,
2878 * and it stored in the hw->speed_downgraded parameter. */
2879 phy_info->downshift = hw->speed_downgraded;
2881 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2885 phy_info->extended_10bt_distance =
2886 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2887 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2888 phy_info->polarity_correction =
2889 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2890 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2892 /* Check polarity status */
2893 ret_val = e1000_check_polarity(hw, &polarity);
2897 phy_info->cable_polarity = polarity;
2899 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2903 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2904 M88E1000_PSSR_MDIX_SHIFT;
2906 if(phy_data & M88E1000_PSSR_1000MBS) {
2907 /* Cable Length Estimation and Local/Remote Receiver Informatoion
2908 * are only valid at 1000 Mbps
2910 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2911 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2913 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2917 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2918 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2920 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2921 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2924 return E1000_SUCCESS;
2927 /******************************************************************************
2928 * Get PHY information from various PHY registers
2930 * hw - Struct containing variables accessed by shared code
2931 * phy_info - PHY information structure
2932 ******************************************************************************/
2934 e1000_phy_get_info(struct e1000_hw *hw,
2935 struct e1000_phy_info *phy_info)
2940 DEBUGFUNC("e1000_phy_get_info");
2942 phy_info->cable_length = e1000_cable_length_undefined;
2943 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
2944 phy_info->cable_polarity = e1000_rev_polarity_undefined;
2945 phy_info->downshift = e1000_downshift_undefined;
2946 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
2947 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
2948 phy_info->local_rx = e1000_1000t_rx_status_undefined;
2949 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
2951 if(hw->media_type != e1000_media_type_copper) {
2952 DEBUGOUT("PHY info is only valid for copper media\n");
2953 return -E1000_ERR_CONFIG;
2956 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2960 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2964 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
2965 DEBUGOUT("PHY info is only valid if link is up\n");
2966 return -E1000_ERR_CONFIG;
2969 if(hw->phy_type == e1000_phy_igp)
2970 return e1000_phy_igp_get_info(hw, phy_info);
2972 return e1000_phy_m88_get_info(hw, phy_info);
2976 e1000_validate_mdi_setting(struct e1000_hw *hw)
2978 DEBUGFUNC("e1000_validate_mdi_settings");
2980 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
2981 DEBUGOUT("Invalid MDI setting detected\n");
2983 return -E1000_ERR_CONFIG;
2985 return E1000_SUCCESS;
2989 /******************************************************************************
2990 * Sets up eeprom variables in the hw struct. Must be called after mac_type
2993 * hw - Struct containing variables accessed by shared code
2994 *****************************************************************************/
2996 e1000_init_eeprom_params(struct e1000_hw *hw)
2998 struct e1000_eeprom_info *eeprom = &hw->eeprom;
2999 uint32_t eecd = E1000_READ_REG(hw, EECD);
3000 uint16_t eeprom_size;
3002 DEBUGFUNC("e1000_init_eeprom_params");
3004 switch (hw->mac_type) {
3005 case e1000_82542_rev2_0:
3006 case e1000_82542_rev2_1:
3009 eeprom->type = e1000_eeprom_microwire;
3010 eeprom->word_size = 64;
3011 eeprom->opcode_bits = 3;
3012 eeprom->address_bits = 6;
3013 eeprom->delay_usec = 50;
3017 case e1000_82545_rev_3:
3019 case e1000_82546_rev_3:
3020 eeprom->type = e1000_eeprom_microwire;
3021 eeprom->opcode_bits = 3;
3022 eeprom->delay_usec = 50;
3023 if(eecd & E1000_EECD_SIZE) {
3024 eeprom->word_size = 256;
3025 eeprom->address_bits = 8;
3027 eeprom->word_size = 64;
3028 eeprom->address_bits = 6;
3032 case e1000_82541_rev_2:
3034 case e1000_82547_rev_2:
3035 if (eecd & E1000_EECD_TYPE) {
3036 eeprom->type = e1000_eeprom_spi;
3037 eeprom->opcode_bits = 8;
3038 eeprom->delay_usec = 1;
3039 if (eecd & E1000_EECD_ADDR_BITS) {
3040 eeprom->page_size = 32;
3041 eeprom->address_bits = 16;
3043 eeprom->page_size = 8;
3044 eeprom->address_bits = 8;
3047 eeprom->type = e1000_eeprom_microwire;
3048 eeprom->opcode_bits = 3;
3049 eeprom->delay_usec = 50;
3050 if (eecd & E1000_EECD_ADDR_BITS) {
3051 eeprom->word_size = 256;
3052 eeprom->address_bits = 8;
3054 eeprom->word_size = 64;
3055 eeprom->address_bits = 6;
3060 eeprom->type = e1000_eeprom_spi;
3061 eeprom->opcode_bits = 8;
3062 eeprom->delay_usec = 1;
3063 if (eecd & E1000_EECD_ADDR_BITS) {
3064 eeprom->page_size = 32;
3065 eeprom->address_bits = 16;
3067 eeprom->page_size = 8;
3068 eeprom->address_bits = 8;
3073 if (eeprom->type == e1000_eeprom_spi) {
3074 eeprom->word_size = 64;
3075 if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
3076 eeprom_size &= EEPROM_SIZE_MASK;
3078 switch (eeprom_size) {
3079 case EEPROM_SIZE_16KB:
3080 eeprom->word_size = 8192;
3082 case EEPROM_SIZE_8KB:
3083 eeprom->word_size = 4096;
3085 case EEPROM_SIZE_4KB:
3086 eeprom->word_size = 2048;
3088 case EEPROM_SIZE_2KB:
3089 eeprom->word_size = 1024;
3091 case EEPROM_SIZE_1KB:
3092 eeprom->word_size = 512;
3094 case EEPROM_SIZE_512B:
3095 eeprom->word_size = 256;
3097 case EEPROM_SIZE_128B:
3099 eeprom->word_size = 64;
3106 /******************************************************************************
3107 * Raises the EEPROM's clock input.
3109 * hw - Struct containing variables accessed by shared code
3110 * eecd - EECD's current value
3111 *****************************************************************************/
3113 e1000_raise_ee_clk(struct e1000_hw *hw,
3116 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3117 * wait <delay> microseconds.
3119 *eecd = *eecd | E1000_EECD_SK;
3120 E1000_WRITE_REG(hw, EECD, *eecd);
3121 E1000_WRITE_FLUSH(hw);
3122 udelay(hw->eeprom.delay_usec);
3125 /******************************************************************************
3126 * Lowers the EEPROM's clock input.
3128 * hw - Struct containing variables accessed by shared code
3129 * eecd - EECD's current value
3130 *****************************************************************************/
3132 e1000_lower_ee_clk(struct e1000_hw *hw,
3135 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3136 * wait 50 microseconds.
3138 *eecd = *eecd & ~E1000_EECD_SK;
3139 E1000_WRITE_REG(hw, EECD, *eecd);
3140 E1000_WRITE_FLUSH(hw);
3141 udelay(hw->eeprom.delay_usec);
3144 /******************************************************************************
3145 * Shift data bits out to the EEPROM.
3147 * hw - Struct containing variables accessed by shared code
3148 * data - data to send to the EEPROM
3149 * count - number of bits to shift out
3150 *****************************************************************************/
3152 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3156 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3160 /* We need to shift "count" bits out to the EEPROM. So, value in the
3161 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3162 * In order to do this, "data" must be broken down into bits.
3164 mask = 0x01 << (count - 1);
3165 eecd = E1000_READ_REG(hw, EECD);
3166 if (eeprom->type == e1000_eeprom_microwire) {
3167 eecd &= ~E1000_EECD_DO;
3168 } else if (eeprom->type == e1000_eeprom_spi) {
3169 eecd |= E1000_EECD_DO;
3172 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3173 * and then raising and then lowering the clock (the SK bit controls
3174 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3175 * by setting "DI" to "0" and then raising and then lowering the clock.
3177 eecd &= ~E1000_EECD_DI;
3180 eecd |= E1000_EECD_DI;
3182 E1000_WRITE_REG(hw, EECD, eecd);
3183 E1000_WRITE_FLUSH(hw);
3185 udelay(eeprom->delay_usec);
3187 e1000_raise_ee_clk(hw, &eecd);
3188 e1000_lower_ee_clk(hw, &eecd);
3194 /* We leave the "DI" bit set to "0" when we leave this routine. */
3195 eecd &= ~E1000_EECD_DI;
3196 E1000_WRITE_REG(hw, EECD, eecd);
3199 /******************************************************************************
3200 * Shift data bits in from the EEPROM
3202 * hw - Struct containing variables accessed by shared code
3203 *****************************************************************************/
3205 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3212 /* In order to read a register from the EEPROM, we need to shift 'count'
3213 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3214 * input to the EEPROM (setting the SK bit), and then reading the value of
3215 * the "DO" bit. During this "shifting in" process the "DI" bit should
3219 eecd = E1000_READ_REG(hw, EECD);
3221 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3224 for(i = 0; i < count; i++) {
3226 e1000_raise_ee_clk(hw, &eecd);
3228 eecd = E1000_READ_REG(hw, EECD);
3230 eecd &= ~(E1000_EECD_DI);
3231 if(eecd & E1000_EECD_DO)
3234 e1000_lower_ee_clk(hw, &eecd);
3240 /******************************************************************************
3241 * Prepares EEPROM for access
3243 * hw - Struct containing variables accessed by shared code
3245 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3246 * function should be called before issuing a command to the EEPROM.
3247 *****************************************************************************/
3249 e1000_acquire_eeprom(struct e1000_hw *hw)
3251 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3254 DEBUGFUNC("e1000_acquire_eeprom");
3256 eecd = E1000_READ_REG(hw, EECD);
3258 /* Request EEPROM Access */
3259 if(hw->mac_type > e1000_82544) {
3260 eecd |= E1000_EECD_REQ;
3261 E1000_WRITE_REG(hw, EECD, eecd);
3262 eecd = E1000_READ_REG(hw, EECD);
3263 while((!(eecd & E1000_EECD_GNT)) &&
3264 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3267 eecd = E1000_READ_REG(hw, EECD);
3269 if(!(eecd & E1000_EECD_GNT)) {
3270 eecd &= ~E1000_EECD_REQ;
3271 E1000_WRITE_REG(hw, EECD, eecd);
3272 DEBUGOUT("Could not acquire EEPROM grant\n");
3273 return -E1000_ERR_EEPROM;
3277 /* Setup EEPROM for Read/Write */
3279 if (eeprom->type == e1000_eeprom_microwire) {
3280 /* Clear SK and DI */
3281 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3282 E1000_WRITE_REG(hw, EECD, eecd);
3285 eecd |= E1000_EECD_CS;
3286 E1000_WRITE_REG(hw, EECD, eecd);
3287 } else if (eeprom->type == e1000_eeprom_spi) {
3288 /* Clear SK and CS */
3289 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3290 E1000_WRITE_REG(hw, EECD, eecd);
3294 return E1000_SUCCESS;
3297 /******************************************************************************
3298 * Returns EEPROM to a "standby" state
3300 * hw - Struct containing variables accessed by shared code
3301 *****************************************************************************/
3303 e1000_standby_eeprom(struct e1000_hw *hw)
3305 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3308 eecd = E1000_READ_REG(hw, EECD);
3310 if(eeprom->type == e1000_eeprom_microwire) {
3311 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3312 E1000_WRITE_REG(hw, EECD, eecd);
3313 E1000_WRITE_FLUSH(hw);
3314 udelay(eeprom->delay_usec);
3317 eecd |= E1000_EECD_SK;
3318 E1000_WRITE_REG(hw, EECD, eecd);
3319 E1000_WRITE_FLUSH(hw);
3320 udelay(eeprom->delay_usec);
3323 eecd |= E1000_EECD_CS;
3324 E1000_WRITE_REG(hw, EECD, eecd);
3325 E1000_WRITE_FLUSH(hw);
3326 udelay(eeprom->delay_usec);
3329 eecd &= ~E1000_EECD_SK;
3330 E1000_WRITE_REG(hw, EECD, eecd);
3331 E1000_WRITE_FLUSH(hw);
3332 udelay(eeprom->delay_usec);
3333 } else if(eeprom->type == e1000_eeprom_spi) {
3334 /* Toggle CS to flush commands */
3335 eecd |= E1000_EECD_CS;
3336 E1000_WRITE_REG(hw, EECD, eecd);
3337 E1000_WRITE_FLUSH(hw);
3338 udelay(eeprom->delay_usec);
3339 eecd &= ~E1000_EECD_CS;
3340 E1000_WRITE_REG(hw, EECD, eecd);
3341 E1000_WRITE_FLUSH(hw);
3342 udelay(eeprom->delay_usec);
3346 /******************************************************************************
3347 * Terminates a command by inverting the EEPROM's chip select pin
3349 * hw - Struct containing variables accessed by shared code
3350 *****************************************************************************/
3352 e1000_release_eeprom(struct e1000_hw *hw)
3356 DEBUGFUNC("e1000_release_eeprom");
3358 eecd = E1000_READ_REG(hw, EECD);
3360 if (hw->eeprom.type == e1000_eeprom_spi) {
3361 eecd |= E1000_EECD_CS; /* Pull CS high */
3362 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3364 E1000_WRITE_REG(hw, EECD, eecd);
3366 udelay(hw->eeprom.delay_usec);
3367 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3368 /* cleanup eeprom */
3370 /* CS on Microwire is active-high */
3371 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3373 E1000_WRITE_REG(hw, EECD, eecd);
3375 /* Rising edge of clock */
3376 eecd |= E1000_EECD_SK;
3377 E1000_WRITE_REG(hw, EECD, eecd);
3378 E1000_WRITE_FLUSH(hw);
3379 udelay(hw->eeprom.delay_usec);
3381 /* Falling edge of clock */
3382 eecd &= ~E1000_EECD_SK;
3383 E1000_WRITE_REG(hw, EECD, eecd);
3384 E1000_WRITE_FLUSH(hw);
3385 udelay(hw->eeprom.delay_usec);
3388 /* Stop requesting EEPROM access */
3389 if(hw->mac_type > e1000_82544) {
3390 eecd &= ~E1000_EECD_REQ;
3391 E1000_WRITE_REG(hw, EECD, eecd);
3395 /******************************************************************************
3396 * Reads a 16 bit word from the EEPROM.
3398 * hw - Struct containing variables accessed by shared code
3399 *****************************************************************************/
3401 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3403 uint16_t retry_count = 0;
3404 uint8_t spi_stat_reg;
3406 DEBUGFUNC("e1000_spi_eeprom_ready");
3408 /* Read "Status Register" repeatedly until the LSB is cleared. The
3409 * EEPROM will signal that the command has been completed by clearing
3410 * bit 0 of the internal status register. If it's not cleared within
3411 * 5 milliseconds, then error out.
3415 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3416 hw->eeprom.opcode_bits);
3417 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3418 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3424 e1000_standby_eeprom(hw);
3425 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3427 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3428 * only 0-5mSec on 5V devices)
3430 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3431 DEBUGOUT("SPI EEPROM Status error\n");
3432 return -E1000_ERR_EEPROM;
3435 return E1000_SUCCESS;
3438 /******************************************************************************
3439 * Reads a 16 bit word from the EEPROM.
3441 * hw - Struct containing variables accessed by shared code
3442 * offset - offset of word in the EEPROM to read
3443 * data - word read from the EEPROM
3444 * words - number of words to read
3445 *****************************************************************************/
3447 e1000_read_eeprom(struct e1000_hw *hw,
3452 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3455 DEBUGFUNC("e1000_read_eeprom");
3457 /* A check for invalid values: offset too large, too many words, and not
3460 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3462 DEBUGOUT("\"words\" parameter out of bounds\n");
3463 return -E1000_ERR_EEPROM;
3466 /* Prepare the EEPROM for reading */
3467 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3468 return -E1000_ERR_EEPROM;
3470 if(eeprom->type == e1000_eeprom_spi) {
3472 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3474 if(e1000_spi_eeprom_ready(hw)) {
3475 e1000_release_eeprom(hw);
3476 return -E1000_ERR_EEPROM;
3479 e1000_standby_eeprom(hw);
3481 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3482 if((eeprom->address_bits == 8) && (offset >= 128))
3483 read_opcode |= EEPROM_A8_OPCODE_SPI;
3485 /* Send the READ command (opcode + addr) */
3486 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3487 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3489 /* Read the data. The address of the eeprom internally increments with
3490 * each byte (spi) being read, saving on the overhead of eeprom setup
3491 * and tear-down. The address counter will roll over if reading beyond
3492 * the size of the eeprom, thus allowing the entire memory to be read
3493 * starting from any offset. */
3494 for (i = 0; i < words; i++) {
3495 word_in = e1000_shift_in_ee_bits(hw, 16);
3496 data[i] = (word_in >> 8) | (word_in << 8);
3498 } else if(eeprom->type == e1000_eeprom_microwire) {
3499 for (i = 0; i < words; i++) {
3500 /* Send the READ command (opcode + addr) */
3501 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3502 eeprom->opcode_bits);
3503 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3504 eeprom->address_bits);
3506 /* Read the data. For microwire, each word requires the overhead
3507 * of eeprom setup and tear-down. */
3508 data[i] = e1000_shift_in_ee_bits(hw, 16);
3509 e1000_standby_eeprom(hw);
3513 /* End this read operation */
3514 e1000_release_eeprom(hw);
3516 return E1000_SUCCESS;
3519 /******************************************************************************
3520 * Verifies that the EEPROM has a valid checksum
3522 * hw - Struct containing variables accessed by shared code
3524 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3525 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3527 *****************************************************************************/
3529 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3531 uint16_t checksum = 0;
3532 uint16_t i, eeprom_data;
3534 DEBUGFUNC("e1000_validate_eeprom_checksum");
3536 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3537 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3538 DEBUGOUT("EEPROM Read Error\n");
3539 return -E1000_ERR_EEPROM;
3541 checksum += eeprom_data;
3544 if(checksum == (uint16_t) EEPROM_SUM)
3545 return E1000_SUCCESS;
3547 DEBUGOUT("EEPROM Checksum Invalid\n");
3548 return -E1000_ERR_EEPROM;
3552 /******************************************************************************
3553 * Calculates the EEPROM checksum and writes it to the EEPROM
3555 * hw - Struct containing variables accessed by shared code
3557 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3558 * Writes the difference to word offset 63 of the EEPROM.
3559 *****************************************************************************/
3561 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3563 uint16_t checksum = 0;
3564 uint16_t i, eeprom_data;
3566 DEBUGFUNC("e1000_update_eeprom_checksum");
3568 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3569 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3570 DEBUGOUT("EEPROM Read Error\n");
3571 return -E1000_ERR_EEPROM;
3573 checksum += eeprom_data;
3575 checksum = (uint16_t) EEPROM_SUM - checksum;
3576 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3577 DEBUGOUT("EEPROM Write Error\n");
3578 return -E1000_ERR_EEPROM;
3580 return E1000_SUCCESS;
3583 /******************************************************************************
3584 * Parent function for writing words to the different EEPROM types.
3586 * hw - Struct containing variables accessed by shared code
3587 * offset - offset within the EEPROM to be written to
3588 * words - number of words to write
3589 * data - 16 bit word to be written to the EEPROM
3591 * If e1000_update_eeprom_checksum is not called after this function, the
3592 * EEPROM will most likely contain an invalid checksum.
3593 *****************************************************************************/
3595 e1000_write_eeprom(struct e1000_hw *hw,
3600 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3603 DEBUGFUNC("e1000_write_eeprom");
3605 /* A check for invalid values: offset too large, too many words, and not
3608 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3610 DEBUGOUT("\"words\" parameter out of bounds\n");
3611 return -E1000_ERR_EEPROM;
3614 /* Prepare the EEPROM for writing */
3615 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3616 return -E1000_ERR_EEPROM;
3618 if(eeprom->type == e1000_eeprom_microwire) {
3619 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3621 status = e1000_write_eeprom_spi(hw, offset, words, data);
3625 /* Done with writing */
3626 e1000_release_eeprom(hw);
3631 /******************************************************************************
3632 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3634 * hw - Struct containing variables accessed by shared code
3635 * offset - offset within the EEPROM to be written to
3636 * words - number of words to write
3637 * data - pointer to array of 8 bit words to be written to the EEPROM
3639 *****************************************************************************/
3641 e1000_write_eeprom_spi(struct e1000_hw *hw,
3646 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3649 DEBUGFUNC("e1000_write_eeprom_spi");
3651 while (widx < words) {
3652 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
3654 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3656 e1000_standby_eeprom(hw);
3658 /* Send the WRITE ENABLE command (8 bit opcode ) */
3659 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3660 eeprom->opcode_bits);
3662 e1000_standby_eeprom(hw);
3664 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3665 if((eeprom->address_bits == 8) && (offset >= 128))
3666 write_opcode |= EEPROM_A8_OPCODE_SPI;
3668 /* Send the Write command (8-bit opcode + addr) */
3669 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3671 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
3672 eeprom->address_bits);
3676 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3677 while (widx < words) {
3678 uint16_t word_out = data[widx];
3679 word_out = (word_out >> 8) | (word_out << 8);
3680 e1000_shift_out_ee_bits(hw, word_out, 16);
3683 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3684 * operation, while the smaller eeproms are capable of an 8-byte
3685 * PAGE WRITE operation. Break the inner loop to pass new address
3687 if((((offset + widx)*2) % eeprom->page_size) == 0) {
3688 e1000_standby_eeprom(hw);
3694 return E1000_SUCCESS;
3697 /******************************************************************************
3698 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3700 * hw - Struct containing variables accessed by shared code
3701 * offset - offset within the EEPROM to be written to
3702 * words - number of words to write
3703 * data - pointer to array of 16 bit words to be written to the EEPROM
3705 *****************************************************************************/
3707 e1000_write_eeprom_microwire(struct e1000_hw *hw,
3712 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3714 uint16_t words_written = 0;
3717 DEBUGFUNC("e1000_write_eeprom_microwire");
3719 /* Send the write enable command to the EEPROM (3-bit opcode plus
3720 * 6/8-bit dummy address beginning with 11). It's less work to include
3721 * the 11 of the dummy address as part of the opcode than it is to shift
3722 * it over the correct number of bits for the address. This puts the
3723 * EEPROM into write/erase mode.
3725 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
3726 (uint16_t)(eeprom->opcode_bits + 2));
3728 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3730 /* Prepare the EEPROM */
3731 e1000_standby_eeprom(hw);
3733 while (words_written < words) {
3734 /* Send the Write command (3-bit opcode + addr) */
3735 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
3736 eeprom->opcode_bits);
3738 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
3739 eeprom->address_bits);
3742 e1000_shift_out_ee_bits(hw, data[words_written], 16);
3744 /* Toggle the CS line. This in effect tells the EEPROM to execute
3745 * the previous command.
3747 e1000_standby_eeprom(hw);
3749 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
3750 * signal that the command has been completed by raising the DO signal.
3751 * If DO does not go high in 10 milliseconds, then error out.
3753 for(i = 0; i < 200; i++) {
3754 eecd = E1000_READ_REG(hw, EECD);
3755 if(eecd & E1000_EECD_DO) break;
3759 DEBUGOUT("EEPROM Write did not complete\n");
3760 return -E1000_ERR_EEPROM;
3763 /* Recover from write */
3764 e1000_standby_eeprom(hw);
3769 /* Send the write disable command to the EEPROM (3-bit opcode plus
3770 * 6/8-bit dummy address beginning with 10). It's less work to include
3771 * the 10 of the dummy address as part of the opcode than it is to shift
3772 * it over the correct number of bits for the address. This takes the
3773 * EEPROM out of write/erase mode.
3775 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
3776 (uint16_t)(eeprom->opcode_bits + 2));
3778 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3780 return E1000_SUCCESS;
3783 /******************************************************************************
3784 * Reads the adapter's part number from the EEPROM
3786 * hw - Struct containing variables accessed by shared code
3787 * part_num - Adapter's part number
3788 *****************************************************************************/
3790 e1000_read_part_num(struct e1000_hw *hw,
3793 uint16_t offset = EEPROM_PBA_BYTE_1;
3794 uint16_t eeprom_data;
3796 DEBUGFUNC("e1000_read_part_num");
3798 /* Get word 0 from EEPROM */
3799 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3800 DEBUGOUT("EEPROM Read Error\n");
3801 return -E1000_ERR_EEPROM;
3803 /* Save word 0 in upper half of part_num */
3804 *part_num = (uint32_t) (eeprom_data << 16);
3806 /* Get word 1 from EEPROM */
3807 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
3808 DEBUGOUT("EEPROM Read Error\n");
3809 return -E1000_ERR_EEPROM;
3811 /* Save word 1 in lower half of part_num */
3812 *part_num |= eeprom_data;
3814 return E1000_SUCCESS;
3817 /******************************************************************************
3818 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3819 * second function of dual function devices
3821 * hw - Struct containing variables accessed by shared code
3822 *****************************************************************************/
3824 e1000_read_mac_addr(struct e1000_hw * hw)
3827 uint16_t eeprom_data, i;
3829 DEBUGFUNC("e1000_read_mac_addr");
3831 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
3833 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3834 DEBUGOUT("EEPROM Read Error\n");
3835 return -E1000_ERR_EEPROM;
3837 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
3838 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
3840 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
3841 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
3842 hw->perm_mac_addr[5] ^= 0x01;
3844 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
3845 hw->mac_addr[i] = hw->perm_mac_addr[i];
3846 return E1000_SUCCESS;
3849 /******************************************************************************
3850 * Initializes receive address filters.
3852 * hw - Struct containing variables accessed by shared code
3854 * Places the MAC address in receive address register 0 and clears the rest
3855 * of the receive addresss registers. Clears the multicast table. Assumes
3856 * the receiver is in reset when the routine is called.
3857 *****************************************************************************/
3859 e1000_init_rx_addrs(struct e1000_hw *hw)
3863 DEBUGFUNC("e1000_init_rx_addrs");
3865 /* Setup the receive address. */
3866 DEBUGOUT("Programming MAC Address into RAR[0]\n");
3868 e1000_rar_set(hw, hw->mac_addr, 0);
3870 /* Zero out the other 15 receive addresses. */
3871 DEBUGOUT("Clearing RAR[1-15]\n");
3872 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
3873 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3874 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3878 /******************************************************************************
3879 * Updates the MAC's list of multicast addresses.
3881 * hw - Struct containing variables accessed by shared code
3882 * mc_addr_list - the list of new multicast addresses
3883 * mc_addr_count - number of addresses
3884 * pad - number of bytes between addresses in the list
3885 * rar_used_count - offset where to start adding mc addresses into the RAR's
3887 * The given list replaces any existing list. Clears the last 15 receive
3888 * address registers and the multicast table. Uses receive address registers
3889 * for the first 15 multicast addresses, and hashes the rest into the
3891 *****************************************************************************/
3893 e1000_mc_addr_list_update(struct e1000_hw *hw,
3894 uint8_t *mc_addr_list,
3895 uint32_t mc_addr_count,
3897 uint32_t rar_used_count)
3899 uint32_t hash_value;
3902 DEBUGFUNC("e1000_mc_addr_list_update");
3904 /* Set the new number of MC addresses that we are being requested to use. */
3905 hw->num_mc_addrs = mc_addr_count;
3907 /* Clear RAR[1-15] */
3908 DEBUGOUT(" Clearing RAR[1-15]\n");
3909 for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
3910 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3911 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3915 DEBUGOUT(" Clearing MTA\n");
3916 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
3917 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
3920 /* Add the new addresses */
3921 for(i = 0; i < mc_addr_count; i++) {
3922 DEBUGOUT(" Adding the multicast addresses:\n");
3923 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
3924 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
3925 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
3926 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
3927 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
3928 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
3929 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
3931 hash_value = e1000_hash_mc_addr(hw,
3933 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
3935 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
3937 /* Place this multicast address in the RAR if there is room, *
3938 * else put it in the MTA
3940 if(rar_used_count < E1000_RAR_ENTRIES) {
3942 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
3946 e1000_mta_set(hw, hash_value);
3949 DEBUGOUT("MC Update Complete\n");
3952 /******************************************************************************
3953 * Hashes an address to determine its location in the multicast table
3955 * hw - Struct containing variables accessed by shared code
3956 * mc_addr - the multicast address to hash
3957 *****************************************************************************/
3959 e1000_hash_mc_addr(struct e1000_hw *hw,
3962 uint32_t hash_value = 0;
3964 /* The portion of the address that is used for the hash table is
3965 * determined by the mc_filter_type setting.
3967 switch (hw->mc_filter_type) {
3968 /* [0] [1] [2] [3] [4] [5]
3973 /* [47:36] i.e. 0x563 for above example address */
3974 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
3977 /* [46:35] i.e. 0xAC6 for above example address */
3978 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
3981 /* [45:34] i.e. 0x5D8 for above example address */
3982 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
3985 /* [43:32] i.e. 0x634 for above example address */
3986 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
3990 hash_value &= 0xFFF;
3994 /******************************************************************************
3995 * Sets the bit in the multicast table corresponding to the hash value.
3997 * hw - Struct containing variables accessed by shared code
3998 * hash_value - Multicast address hash value
3999 *****************************************************************************/
4001 e1000_mta_set(struct e1000_hw *hw,
4002 uint32_t hash_value)
4004 uint32_t hash_bit, hash_reg;
4008 /* The MTA is a register array of 128 32-bit registers.
4009 * It is treated like an array of 4096 bits. We want to set
4010 * bit BitArray[hash_value]. So we figure out what register
4011 * the bit is in, read it, OR in the new bit, then write
4012 * back the new value. The register is determined by the
4013 * upper 7 bits of the hash value and the bit within that
4014 * register are determined by the lower 5 bits of the value.
4016 hash_reg = (hash_value >> 5) & 0x7F;
4017 hash_bit = hash_value & 0x1F;
4019 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4021 mta |= (1 << hash_bit);
4023 /* If we are on an 82544 and we are trying to write an odd offset
4024 * in the MTA, save off the previous entry before writing and
4025 * restore the old value after writing.
4027 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4028 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4029 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4030 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4032 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4036 /******************************************************************************
4037 * Puts an ethernet address into a receive address register.
4039 * hw - Struct containing variables accessed by shared code
4040 * addr - Address to put into receive address register
4041 * index - Receive address register to write
4042 *****************************************************************************/
4044 e1000_rar_set(struct e1000_hw *hw,
4048 uint32_t rar_low, rar_high;
4050 /* HW expects these in little endian so we reverse the byte order
4051 * from network order (big endian) to little endian
4053 rar_low = ((uint32_t) addr[0] |
4054 ((uint32_t) addr[1] << 8) |
4055 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4057 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4059 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4060 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4063 /******************************************************************************
4064 * Writes a value to the specified offset in the VLAN filter table.
4066 * hw - Struct containing variables accessed by shared code
4067 * offset - Offset in VLAN filer table to write
4068 * value - Value to write into VLAN filter table
4069 *****************************************************************************/
4071 e1000_write_vfta(struct e1000_hw *hw,
4077 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4078 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4079 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4080 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4082 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4086 /******************************************************************************
4087 * Clears the VLAN filer table
4089 * hw - Struct containing variables accessed by shared code
4090 *****************************************************************************/
4092 e1000_clear_vfta(struct e1000_hw *hw)
4096 for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
4097 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
4101 e1000_id_led_init(struct e1000_hw * hw)
4104 const uint32_t ledctl_mask = 0x000000FF;
4105 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4106 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4107 uint16_t eeprom_data, i, temp;
4108 const uint16_t led_mask = 0x0F;
4110 DEBUGFUNC("e1000_id_led_init");
4112 if(hw->mac_type < e1000_82540) {
4114 return E1000_SUCCESS;
4117 ledctl = E1000_READ_REG(hw, LEDCTL);
4118 hw->ledctl_default = ledctl;
4119 hw->ledctl_mode1 = hw->ledctl_default;
4120 hw->ledctl_mode2 = hw->ledctl_default;
4122 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4123 DEBUGOUT("EEPROM Read Error\n");
4124 return -E1000_ERR_EEPROM;
4126 if((eeprom_data== ID_LED_RESERVED_0000) ||
4127 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4128 for(i = 0; i < 4; i++) {
4129 temp = (eeprom_data >> (i << 2)) & led_mask;
4131 case ID_LED_ON1_DEF2:
4132 case ID_LED_ON1_ON2:
4133 case ID_LED_ON1_OFF2:
4134 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4135 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4137 case ID_LED_OFF1_DEF2:
4138 case ID_LED_OFF1_ON2:
4139 case ID_LED_OFF1_OFF2:
4140 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4141 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4148 case ID_LED_DEF1_ON2:
4149 case ID_LED_ON1_ON2:
4150 case ID_LED_OFF1_ON2:
4151 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4152 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4154 case ID_LED_DEF1_OFF2:
4155 case ID_LED_ON1_OFF2:
4156 case ID_LED_OFF1_OFF2:
4157 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4158 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4165 return E1000_SUCCESS;
4168 /******************************************************************************
4169 * Prepares SW controlable LED for use and saves the current state of the LED.
4171 * hw - Struct containing variables accessed by shared code
4172 *****************************************************************************/
4174 e1000_setup_led(struct e1000_hw *hw)
4177 int32_t ret_val = E1000_SUCCESS;
4179 DEBUGFUNC("e1000_setup_led");
4181 switch(hw->mac_type) {
4182 case e1000_82542_rev2_0:
4183 case e1000_82542_rev2_1:
4186 /* No setup necessary */
4190 case e1000_82541_rev_2:
4191 case e1000_82547_rev_2:
4192 /* Turn off PHY Smart Power Down (if enabled) */
4193 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4194 &hw->phy_spd_default);
4197 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4198 (uint16_t)(hw->phy_spd_default &
4199 ~IGP01E1000_GMII_SPD));
4204 if(hw->media_type == e1000_media_type_fiber) {
4205 ledctl = E1000_READ_REG(hw, LEDCTL);
4206 /* Save current LEDCTL settings */
4207 hw->ledctl_default = ledctl;
4209 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4210 E1000_LEDCTL_LED0_BLINK |
4211 E1000_LEDCTL_LED0_MODE_MASK);
4212 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4213 E1000_LEDCTL_LED0_MODE_SHIFT);
4214 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4215 } else if(hw->media_type == e1000_media_type_copper)
4216 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4220 return E1000_SUCCESS;
4223 /******************************************************************************
4224 * Restores the saved state of the SW controlable LED.
4226 * hw - Struct containing variables accessed by shared code
4227 *****************************************************************************/
4229 e1000_cleanup_led(struct e1000_hw *hw)
4231 int32_t ret_val = E1000_SUCCESS;
4233 DEBUGFUNC("e1000_cleanup_led");
4235 switch(hw->mac_type) {
4236 case e1000_82542_rev2_0:
4237 case e1000_82542_rev2_1:
4240 /* No cleanup necessary */
4244 case e1000_82541_rev_2:
4245 case e1000_82547_rev_2:
4246 /* Turn on PHY Smart Power Down (if previously enabled) */
4247 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4248 hw->phy_spd_default);
4253 /* Restore LEDCTL settings */
4254 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4258 return E1000_SUCCESS;
4261 /******************************************************************************
4262 * Turns on the software controllable LED
4264 * hw - Struct containing variables accessed by shared code
4265 *****************************************************************************/
4267 e1000_led_on(struct e1000_hw *hw)
4269 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4271 DEBUGFUNC("e1000_led_on");
4273 switch(hw->mac_type) {
4274 case e1000_82542_rev2_0:
4275 case e1000_82542_rev2_1:
4277 /* Set SW Defineable Pin 0 to turn on the LED */
4278 ctrl |= E1000_CTRL_SWDPIN0;
4279 ctrl |= E1000_CTRL_SWDPIO0;
4282 if(hw->media_type == e1000_media_type_fiber) {
4283 /* Set SW Defineable Pin 0 to turn on the LED */
4284 ctrl |= E1000_CTRL_SWDPIN0;
4285 ctrl |= E1000_CTRL_SWDPIO0;
4287 /* Clear SW Defineable Pin 0 to turn on the LED */
4288 ctrl &= ~E1000_CTRL_SWDPIN0;
4289 ctrl |= E1000_CTRL_SWDPIO0;
4293 if(hw->media_type == e1000_media_type_fiber) {
4294 /* Clear SW Defineable Pin 0 to turn on the LED */
4295 ctrl &= ~E1000_CTRL_SWDPIN0;
4296 ctrl |= E1000_CTRL_SWDPIO0;
4297 } else if(hw->media_type == e1000_media_type_copper) {
4298 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4299 return E1000_SUCCESS;
4304 E1000_WRITE_REG(hw, CTRL, ctrl);
4306 return E1000_SUCCESS;
4309 /******************************************************************************
4310 * Turns off the software controllable LED
4312 * hw - Struct containing variables accessed by shared code
4313 *****************************************************************************/
4315 e1000_led_off(struct e1000_hw *hw)
4317 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4319 DEBUGFUNC("e1000_led_off");
4321 switch(hw->mac_type) {
4322 case e1000_82542_rev2_0:
4323 case e1000_82542_rev2_1:
4325 /* Clear SW Defineable Pin 0 to turn off the LED */
4326 ctrl &= ~E1000_CTRL_SWDPIN0;
4327 ctrl |= E1000_CTRL_SWDPIO0;
4330 if(hw->media_type == e1000_media_type_fiber) {
4331 /* Clear SW Defineable Pin 0 to turn off the LED */
4332 ctrl &= ~E1000_CTRL_SWDPIN0;
4333 ctrl |= E1000_CTRL_SWDPIO0;
4335 /* Set SW Defineable Pin 0 to turn off the LED */
4336 ctrl |= E1000_CTRL_SWDPIN0;
4337 ctrl |= E1000_CTRL_SWDPIO0;
4341 if(hw->media_type == e1000_media_type_fiber) {
4342 /* Set SW Defineable Pin 0 to turn off the LED */
4343 ctrl |= E1000_CTRL_SWDPIN0;
4344 ctrl |= E1000_CTRL_SWDPIO0;
4345 } else if(hw->media_type == e1000_media_type_copper) {
4346 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4347 return E1000_SUCCESS;
4352 E1000_WRITE_REG(hw, CTRL, ctrl);
4354 return E1000_SUCCESS;
4357 /******************************************************************************
4358 * Clears all hardware statistics counters.
4360 * hw - Struct containing variables accessed by shared code
4361 *****************************************************************************/
4363 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4365 volatile uint32_t temp;
4367 temp = E1000_READ_REG(hw, CRCERRS);
4368 temp = E1000_READ_REG(hw, SYMERRS);
4369 temp = E1000_READ_REG(hw, MPC);
4370 temp = E1000_READ_REG(hw, SCC);
4371 temp = E1000_READ_REG(hw, ECOL);
4372 temp = E1000_READ_REG(hw, MCC);
4373 temp = E1000_READ_REG(hw, LATECOL);
4374 temp = E1000_READ_REG(hw, COLC);
4375 temp = E1000_READ_REG(hw, DC);
4376 temp = E1000_READ_REG(hw, SEC);
4377 temp = E1000_READ_REG(hw, RLEC);
4378 temp = E1000_READ_REG(hw, XONRXC);
4379 temp = E1000_READ_REG(hw, XONTXC);
4380 temp = E1000_READ_REG(hw, XOFFRXC);
4381 temp = E1000_READ_REG(hw, XOFFTXC);
4382 temp = E1000_READ_REG(hw, FCRUC);
4383 temp = E1000_READ_REG(hw, PRC64);
4384 temp = E1000_READ_REG(hw, PRC127);
4385 temp = E1000_READ_REG(hw, PRC255);
4386 temp = E1000_READ_REG(hw, PRC511);
4387 temp = E1000_READ_REG(hw, PRC1023);
4388 temp = E1000_READ_REG(hw, PRC1522);
4389 temp = E1000_READ_REG(hw, GPRC);
4390 temp = E1000_READ_REG(hw, BPRC);
4391 temp = E1000_READ_REG(hw, MPRC);
4392 temp = E1000_READ_REG(hw, GPTC);
4393 temp = E1000_READ_REG(hw, GORCL);
4394 temp = E1000_READ_REG(hw, GORCH);
4395 temp = E1000_READ_REG(hw, GOTCL);
4396 temp = E1000_READ_REG(hw, GOTCH);
4397 temp = E1000_READ_REG(hw, RNBC);
4398 temp = E1000_READ_REG(hw, RUC);
4399 temp = E1000_READ_REG(hw, RFC);
4400 temp = E1000_READ_REG(hw, ROC);
4401 temp = E1000_READ_REG(hw, RJC);
4402 temp = E1000_READ_REG(hw, TORL);
4403 temp = E1000_READ_REG(hw, TORH);
4404 temp = E1000_READ_REG(hw, TOTL);
4405 temp = E1000_READ_REG(hw, TOTH);
4406 temp = E1000_READ_REG(hw, TPR);
4407 temp = E1000_READ_REG(hw, TPT);
4408 temp = E1000_READ_REG(hw, PTC64);
4409 temp = E1000_READ_REG(hw, PTC127);
4410 temp = E1000_READ_REG(hw, PTC255);
4411 temp = E1000_READ_REG(hw, PTC511);
4412 temp = E1000_READ_REG(hw, PTC1023);
4413 temp = E1000_READ_REG(hw, PTC1522);
4414 temp = E1000_READ_REG(hw, MPTC);
4415 temp = E1000_READ_REG(hw, BPTC);
4417 if(hw->mac_type < e1000_82543) return;
4419 temp = E1000_READ_REG(hw, ALGNERRC);
4420 temp = E1000_READ_REG(hw, RXERRC);
4421 temp = E1000_READ_REG(hw, TNCRS);
4422 temp = E1000_READ_REG(hw, CEXTERR);
4423 temp = E1000_READ_REG(hw, TSCTC);
4424 temp = E1000_READ_REG(hw, TSCTFC);
4426 if(hw->mac_type <= e1000_82544) return;
4428 temp = E1000_READ_REG(hw, MGTPRC);
4429 temp = E1000_READ_REG(hw, MGTPDC);
4430 temp = E1000_READ_REG(hw, MGTPTC);
4433 /******************************************************************************
4434 * Resets Adaptive IFS to its default state.
4436 * hw - Struct containing variables accessed by shared code
4438 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4439 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4440 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4441 * before calling this function.
4442 *****************************************************************************/
4444 e1000_reset_adaptive(struct e1000_hw *hw)
4446 DEBUGFUNC("e1000_reset_adaptive");
4448 if(hw->adaptive_ifs) {
4449 if(!hw->ifs_params_forced) {
4450 hw->current_ifs_val = 0;
4451 hw->ifs_min_val = IFS_MIN;
4452 hw->ifs_max_val = IFS_MAX;
4453 hw->ifs_step_size = IFS_STEP;
4454 hw->ifs_ratio = IFS_RATIO;
4456 hw->in_ifs_mode = FALSE;
4457 E1000_WRITE_REG(hw, AIT, 0);
4459 DEBUGOUT("Not in Adaptive IFS mode!\n");
4463 /******************************************************************************
4464 * Called during the callback/watchdog routine to update IFS value based on
4465 * the ratio of transmits to collisions.
4467 * hw - Struct containing variables accessed by shared code
4468 * tx_packets - Number of transmits since last callback
4469 * total_collisions - Number of collisions since last callback
4470 *****************************************************************************/
4472 e1000_update_adaptive(struct e1000_hw *hw)
4474 DEBUGFUNC("e1000_update_adaptive");
4476 if(hw->adaptive_ifs) {
4477 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4478 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
4479 hw->in_ifs_mode = TRUE;
4480 if(hw->current_ifs_val < hw->ifs_max_val) {
4481 if(hw->current_ifs_val == 0)
4482 hw->current_ifs_val = hw->ifs_min_val;
4484 hw->current_ifs_val += hw->ifs_step_size;
4485 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
4489 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4490 hw->current_ifs_val = 0;
4491 hw->in_ifs_mode = FALSE;
4492 E1000_WRITE_REG(hw, AIT, 0);
4496 DEBUGOUT("Not in Adaptive IFS mode!\n");
4500 /******************************************************************************
4501 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4503 * hw - Struct containing variables accessed by shared code
4504 * frame_len - The length of the frame in question
4505 * mac_addr - The Ethernet destination address of the frame in question
4506 *****************************************************************************/
4508 e1000_tbi_adjust_stats(struct e1000_hw *hw,
4509 struct e1000_hw_stats *stats,
4515 /* First adjust the frame length. */
4517 /* We need to adjust the statistics counters, since the hardware
4518 * counters overcount this packet as a CRC error and undercount
4519 * the packet as a good packet
4521 /* This packet should not be counted as a CRC error. */
4523 /* This packet does count as a Good Packet Received. */
4526 /* Adjust the Good Octets received counters */
4527 carry_bit = 0x80000000 & stats->gorcl;
4528 stats->gorcl += frame_len;
4529 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4530 * Received Count) was one before the addition,
4531 * AND it is zero after, then we lost the carry out,
4532 * need to add one to Gorch (Good Octets Received Count High).
4533 * This could be simplified if all environments supported
4536 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
4538 /* Is this a broadcast or multicast? Check broadcast first,
4539 * since the test for a multicast frame will test positive on
4540 * a broadcast frame.
4542 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
4543 /* Broadcast packet */
4545 else if(*mac_addr & 0x01)
4546 /* Multicast packet */
4549 if(frame_len == hw->max_frame_size) {
4550 /* In this case, the hardware has overcounted the number of
4557 /* Adjust the bin counters when the extra byte put the frame in the
4558 * wrong bin. Remember that the frame_len was adjusted above.
4560 if(frame_len == 64) {
4563 } else if(frame_len == 127) {
4566 } else if(frame_len == 255) {
4569 } else if(frame_len == 511) {
4572 } else if(frame_len == 1023) {
4575 } else if(frame_len == 1522) {
4580 /******************************************************************************
4581 * Gets the current PCI bus type, speed, and width of the hardware
4583 * hw - Struct containing variables accessed by shared code
4584 *****************************************************************************/
4586 e1000_get_bus_info(struct e1000_hw *hw)
4590 if(hw->mac_type < e1000_82543) {
4591 hw->bus_type = e1000_bus_type_unknown;
4592 hw->bus_speed = e1000_bus_speed_unknown;
4593 hw->bus_width = e1000_bus_width_unknown;
4597 status = E1000_READ_REG(hw, STATUS);
4598 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4599 e1000_bus_type_pcix : e1000_bus_type_pci;
4601 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4602 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4603 e1000_bus_speed_66 : e1000_bus_speed_120;
4604 } else if(hw->bus_type == e1000_bus_type_pci) {
4605 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4606 e1000_bus_speed_66 : e1000_bus_speed_33;
4608 switch (status & E1000_STATUS_PCIX_SPEED) {
4609 case E1000_STATUS_PCIX_SPEED_66:
4610 hw->bus_speed = e1000_bus_speed_66;
4612 case E1000_STATUS_PCIX_SPEED_100:
4613 hw->bus_speed = e1000_bus_speed_100;
4615 case E1000_STATUS_PCIX_SPEED_133:
4616 hw->bus_speed = e1000_bus_speed_133;
4619 hw->bus_speed = e1000_bus_speed_reserved;
4623 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4624 e1000_bus_width_64 : e1000_bus_width_32;
4626 /******************************************************************************
4627 * Reads a value from one of the devices registers using port I/O (as opposed
4628 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4630 * hw - Struct containing variables accessed by shared code
4631 * offset - offset to read from
4632 *****************************************************************************/
4634 e1000_read_reg_io(struct e1000_hw *hw,
4637 unsigned long io_addr = hw->io_base;
4638 unsigned long io_data = hw->io_base + 4;
4640 e1000_io_write(hw, io_addr, offset);
4641 return e1000_io_read(hw, io_data);
4644 /******************************************************************************
4645 * Writes a value to one of the devices registers using port I/O (as opposed to
4646 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4648 * hw - Struct containing variables accessed by shared code
4649 * offset - offset to write to
4650 * value - value to write
4651 *****************************************************************************/
4653 e1000_write_reg_io(struct e1000_hw *hw,
4657 unsigned long io_addr = hw->io_base;
4658 unsigned long io_data = hw->io_base + 4;
4660 e1000_io_write(hw, io_addr, offset);
4661 e1000_io_write(hw, io_data, value);
4665 /******************************************************************************
4666 * Estimates the cable length.
4668 * hw - Struct containing variables accessed by shared code
4669 * min_length - The estimated minimum length
4670 * max_length - The estimated maximum length
4672 * returns: - E1000_ERR_XXX
4675 * This function always returns a ranged length (minimum & maximum).
4676 * So for M88 phy's, this function interprets the one value returned from the
4677 * register to the minimum and maximum range.
4678 * For IGP phy's, the function calculates the range by the AGC registers.
4679 *****************************************************************************/
4681 e1000_get_cable_length(struct e1000_hw *hw,
4682 uint16_t *min_length,
4683 uint16_t *max_length)
4686 uint16_t agc_value = 0;
4687 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4688 uint16_t i, phy_data;
4690 DEBUGFUNC("e1000_get_cable_length");
4692 *min_length = *max_length = 0;
4694 /* Use old method for Phy older than IGP */
4695 if(hw->phy_type == e1000_phy_m88) {
4696 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4701 /* Convert the enum value to ranged values */
4702 switch((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4703 M88E1000_PSSR_CABLE_LENGTH_SHIFT) {
4704 case e1000_cable_length_50:
4706 *max_length = e1000_igp_cable_length_50;
4708 case e1000_cable_length_50_80:
4709 *min_length = e1000_igp_cable_length_50;
4710 *max_length = e1000_igp_cable_length_80;
4712 case e1000_cable_length_80_110:
4713 *min_length = e1000_igp_cable_length_80;
4714 *max_length = e1000_igp_cable_length_110;
4716 case e1000_cable_length_110_140:
4717 *min_length = e1000_igp_cable_length_110;
4718 *max_length = e1000_igp_cable_length_140;
4720 case e1000_cable_length_140:
4721 *min_length = e1000_igp_cable_length_140;
4722 *max_length = e1000_igp_cable_length_170;
4725 return -E1000_ERR_PHY;
4728 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4729 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4730 {IGP01E1000_PHY_AGC_A,
4731 IGP01E1000_PHY_AGC_B,
4732 IGP01E1000_PHY_AGC_C,
4733 IGP01E1000_PHY_AGC_D};
4734 /* Read the AGC registers for all channels */
4735 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4737 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4741 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4743 /* Array bound check. */
4744 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4746 return -E1000_ERR_PHY;
4748 agc_value += cur_agc;
4750 /* Update minimal AGC value. */
4751 if(min_agc > cur_agc)
4755 /* Remove the minimal AGC result for length < 50m */
4756 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4757 agc_value -= min_agc;
4759 /* Get the average length of the remaining 3 channels */
4760 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4762 /* Get the average length of all the 4 channels. */
4763 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4766 /* Set the range of the calculated length. */
4767 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4768 IGP01E1000_AGC_RANGE) > 0) ?
4769 (e1000_igp_cable_length_table[agc_value] -
4770 IGP01E1000_AGC_RANGE) : 0;
4771 *max_length = e1000_igp_cable_length_table[agc_value] +
4772 IGP01E1000_AGC_RANGE;
4775 return E1000_SUCCESS;
4778 /******************************************************************************
4779 * Check the cable polarity
4781 * hw - Struct containing variables accessed by shared code
4782 * polarity - output parameter : 0 - Polarity is not reversed
4783 * 1 - Polarity is reversed.
4785 * returns: - E1000_ERR_XXX
4788 * For phy's older then IGP, this function simply reads the polarity bit in the
4789 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4790 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4791 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4792 * IGP01E1000_PHY_PCS_INIT_REG.
4793 *****************************************************************************/
4795 e1000_check_polarity(struct e1000_hw *hw,
4801 DEBUGFUNC("e1000_check_polarity");
4803 if(hw->phy_type == e1000_phy_m88) {
4804 /* return the Polarity bit in the Status register. */
4805 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4809 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
4810 M88E1000_PSSR_REV_POLARITY_SHIFT;
4811 } else if(hw->phy_type == e1000_phy_igp) {
4812 /* Read the Status register to check the speed */
4813 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4818 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4819 * find the polarity status */
4820 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4821 IGP01E1000_PSSR_SPEED_1000MBPS) {
4823 /* Read the GIG initialization PCS register (0x00B4) */
4824 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4829 /* Check the polarity bits */
4830 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
4832 /* For 10 Mbps, read the polarity bit in the status register. (for
4833 * 100 Mbps this bit is always 0) */
4834 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
4837 return E1000_SUCCESS;
4840 /******************************************************************************
4841 * Check if Downshift occured
4843 * hw - Struct containing variables accessed by shared code
4844 * downshift - output parameter : 0 - No Downshift ocured.
4845 * 1 - Downshift ocured.
4847 * returns: - E1000_ERR_XXX
4850 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4851 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
4852 * Link Health register. In IGP this bit is latched high, so the driver must
4853 * read it immediately after link is established.
4854 *****************************************************************************/
4856 e1000_check_downshift(struct e1000_hw *hw)
4861 DEBUGFUNC("e1000_check_downshift");
4863 if(hw->phy_type == e1000_phy_igp) {
4864 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
4869 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
4871 else if(hw->phy_type == e1000_phy_m88) {
4872 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4877 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
4878 M88E1000_PSSR_DOWNSHIFT_SHIFT;
4880 return E1000_SUCCESS;
4883 /*****************************************************************************
4885 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4886 * gigabit link is achieved to improve link quality.
4888 * hw: Struct containing variables accessed by shared code
4890 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4891 * E1000_SUCCESS at any other case.
4893 ****************************************************************************/
4896 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
4900 uint16_t phy_data, speed, duplex, i;
4901 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4902 {IGP01E1000_PHY_AGC_PARAM_A,
4903 IGP01E1000_PHY_AGC_PARAM_B,
4904 IGP01E1000_PHY_AGC_PARAM_C,
4905 IGP01E1000_PHY_AGC_PARAM_D};
4906 uint16_t min_length, max_length;
4908 DEBUGFUNC("e1000_config_dsp_after_link_change");
4910 if(hw->phy_type != e1000_phy_igp)
4911 return E1000_SUCCESS;
4914 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
4916 DEBUGOUT("Error getting link speed and duplex\n");
4920 if(speed == SPEED_1000) {
4922 e1000_get_cable_length(hw, &min_length, &max_length);
4924 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
4925 min_length >= e1000_igp_cable_length_50) {
4927 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4928 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4933 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4935 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
4940 hw->dsp_config_state = e1000_dsp_config_activated;
4943 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
4944 (min_length < e1000_igp_cable_length_50)) {
4946 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
4947 uint32_t idle_errs = 0;
4949 /* clear previous idle error counts */
4950 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4955 for(i = 0; i < ffe_idle_err_timeout; i++) {
4957 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4962 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
4963 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
4964 hw->ffe_config_state = e1000_ffe_config_active;
4966 ret_val = e1000_write_phy_reg(hw,
4967 IGP01E1000_PHY_DSP_FFE,
4968 IGP01E1000_PHY_DSP_FFE_CM_CP);
4975 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
4980 if(hw->dsp_config_state == e1000_dsp_config_activated) {
4981 ret_val = e1000_write_phy_reg(hw, 0x0000,
4982 IGP01E1000_IEEE_FORCE_GIGA);
4985 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4986 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
4990 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4991 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
4993 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
4998 ret_val = e1000_write_phy_reg(hw, 0x0000,
4999 IGP01E1000_IEEE_RESTART_AUTONEG);
5003 hw->dsp_config_state = e1000_dsp_config_enabled;
5006 if(hw->ffe_config_state == e1000_ffe_config_active) {
5007 ret_val = e1000_write_phy_reg(hw, 0x0000,
5008 IGP01E1000_IEEE_FORCE_GIGA);
5011 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5012 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5016 ret_val = e1000_write_phy_reg(hw, 0x0000,
5017 IGP01E1000_IEEE_RESTART_AUTONEG);
5020 hw->ffe_config_state = e1000_ffe_config_enabled;
5023 return E1000_SUCCESS;
5026 /*****************************************************************************
5027 * Set PHY to class A mode
5028 * Assumes the following operations will follow to enable the new class mode.
5029 * 1. Do a PHY soft reset
5030 * 2. Restart auto-negotiation or force link.
5032 * hw - Struct containing variables accessed by shared code
5033 ****************************************************************************/
5035 e1000_set_phy_mode(struct e1000_hw *hw)
5038 uint16_t eeprom_data;
5040 DEBUGFUNC("e1000_set_phy_mode");
5042 if((hw->mac_type == e1000_82545_rev_3) &&
5043 (hw->media_type == e1000_media_type_copper)) {
5044 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5049 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5050 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5051 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5054 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5058 hw->phy_reset_disable = FALSE;
5062 return E1000_SUCCESS;
5065 /*****************************************************************************
5067 * This function sets the lplu state according to the active flag. When
5068 * activating lplu this function also disables smart speed and vise versa.
5069 * lplu will not be activated unless the device autonegotiation advertisment
5070 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5071 * hw: Struct containing variables accessed by shared code
5072 * active - true to enable lplu false to disable lplu.
5074 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5075 * E1000_SUCCESS at any other case.
5077 ****************************************************************************/
5080 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5085 DEBUGFUNC("e1000_set_d3_lplu_state");
5087 if(!((hw->mac_type == e1000_82541_rev_2) ||
5088 (hw->mac_type == e1000_82547_rev_2)))
5089 return E1000_SUCCESS;
5091 /* During driver activity LPLU should not be used or it will attain link
5092 * from the lowest speeds starting from 10Mbps. The capability is used for
5093 * Dx transitions and states */
5094 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5099 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5100 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5104 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5105 * Dx states where the power conservation is most important. During
5106 * driver activity we should enable SmartSpeed, so performance is
5108 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5112 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5113 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5117 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5118 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5119 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5121 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5122 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5126 /* When LPLU is enabled we should disable SmartSpeed */
5127 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5131 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5132 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5137 return E1000_SUCCESS;
5140 /******************************************************************************
5141 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5143 * hw - Struct containing variables accessed by shared code
5144 *****************************************************************************/
5146 e1000_set_vco_speed(struct e1000_hw *hw)
5149 uint16_t default_page = 0;
5152 DEBUGFUNC("e1000_set_vco_speed");
5154 switch(hw->mac_type) {
5155 case e1000_82545_rev_3:
5156 case e1000_82546_rev_3:
5159 return E1000_SUCCESS;
5162 /* Set PHY register 30, page 5, bit 8 to 0 */
5164 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5168 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5172 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5176 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5177 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5181 /* Set PHY register 30, page 4, bit 11 to 1 */
5183 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5187 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5191 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5192 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5196 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5200 return E1000_SUCCESS;
5203 /******************************************************************************
5204 * Verifies the hardware needs to allow ARPs to be processed by the host
5206 * hw - Struct containing variables accessed by shared code
5208 * returns: - TRUE/FALSE
5210 *****************************************************************************/
5212 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5216 if (hw->asf_firmware_present) {
5217 manc = E1000_READ_REG(hw, MANC);
5219 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5220 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5222 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))