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_polarity_reversal_workaround(struct e1000_hw *hw);
69 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
71 /* IGP cable length table */
73 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
74 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
75 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
76 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
77 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
78 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
79 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
80 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
81 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
84 /******************************************************************************
85 * Set the phy type member in the hw struct.
87 * hw - Struct containing variables accessed by shared code
88 *****************************************************************************/
90 e1000_set_phy_type(struct e1000_hw *hw)
92 DEBUGFUNC("e1000_set_phy_type");
95 case M88E1000_E_PHY_ID:
96 case M88E1000_I_PHY_ID:
97 case M88E1011_I_PHY_ID:
98 hw->phy_type = e1000_phy_m88;
100 case IGP01E1000_I_PHY_ID:
101 if(hw->mac_type == e1000_82541 ||
102 hw->mac_type == e1000_82541_rev_2 ||
103 hw->mac_type == e1000_82547 ||
104 hw->mac_type == e1000_82547_rev_2) {
105 hw->phy_type = e1000_phy_igp;
110 /* Should never have loaded on this device */
111 hw->phy_type = e1000_phy_undefined;
112 return -E1000_ERR_PHY_TYPE;
115 return E1000_SUCCESS;
118 /******************************************************************************
119 * IGP phy init script - initializes the GbE PHY
121 * hw - Struct containing variables accessed by shared code
122 *****************************************************************************/
124 e1000_phy_init_script(struct e1000_hw *hw)
127 uint16_t phy_saved_data;
129 DEBUGFUNC("e1000_phy_init_script");
132 if(hw->phy_init_script) {
135 /* Save off the current value of register 0x2F5B to be restored at
136 * the end of this routine. */
137 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
139 /* Disabled the PHY transmitter */
140 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
144 e1000_write_phy_reg(hw,0x0000,0x0140);
148 switch(hw->mac_type) {
151 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
153 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
155 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
157 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
159 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
161 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
163 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
165 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
167 e1000_write_phy_reg(hw, 0x2010, 0x0008);
170 case e1000_82541_rev_2:
171 case e1000_82547_rev_2:
172 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
178 e1000_write_phy_reg(hw, 0x0000, 0x3300);
182 /* Now enable the transmitter */
183 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
185 if(hw->mac_type == e1000_82547) {
186 uint16_t fused, fine, coarse;
188 /* Move to analog registers page */
189 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
191 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
192 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
194 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
195 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
197 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
198 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
199 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
200 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
201 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
203 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
204 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
205 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
207 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
208 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
209 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
215 /******************************************************************************
216 * Set the mac type member in the hw struct.
218 * hw - Struct containing variables accessed by shared code
219 *****************************************************************************/
221 e1000_set_mac_type(struct e1000_hw *hw)
223 DEBUGFUNC("e1000_set_mac_type");
225 switch (hw->device_id) {
226 case E1000_DEV_ID_82542:
227 switch (hw->revision_id) {
228 case E1000_82542_2_0_REV_ID:
229 hw->mac_type = e1000_82542_rev2_0;
231 case E1000_82542_2_1_REV_ID:
232 hw->mac_type = e1000_82542_rev2_1;
235 /* Invalid 82542 revision ID */
236 return -E1000_ERR_MAC_TYPE;
239 case E1000_DEV_ID_82543GC_FIBER:
240 case E1000_DEV_ID_82543GC_COPPER:
241 hw->mac_type = e1000_82543;
243 case E1000_DEV_ID_82544EI_COPPER:
244 case E1000_DEV_ID_82544EI_FIBER:
245 case E1000_DEV_ID_82544GC_COPPER:
246 case E1000_DEV_ID_82544GC_LOM:
247 hw->mac_type = e1000_82544;
249 case E1000_DEV_ID_82540EM:
250 case E1000_DEV_ID_82540EM_LOM:
251 case E1000_DEV_ID_82540EP:
252 case E1000_DEV_ID_82540EP_LOM:
253 case E1000_DEV_ID_82540EP_LP:
254 hw->mac_type = e1000_82540;
256 case E1000_DEV_ID_82545EM_COPPER:
257 case E1000_DEV_ID_82545EM_FIBER:
258 hw->mac_type = e1000_82545;
260 case E1000_DEV_ID_82545GM_COPPER:
261 case E1000_DEV_ID_82545GM_FIBER:
262 case E1000_DEV_ID_82545GM_SERDES:
263 hw->mac_type = e1000_82545_rev_3;
265 case E1000_DEV_ID_82546EB_COPPER:
266 case E1000_DEV_ID_82546EB_FIBER:
267 case E1000_DEV_ID_82546EB_QUAD_COPPER:
268 hw->mac_type = e1000_82546;
270 case E1000_DEV_ID_82546GB_COPPER:
271 case E1000_DEV_ID_82546GB_FIBER:
272 case E1000_DEV_ID_82546GB_SERDES:
273 case E1000_DEV_ID_82546GB_PCIE:
274 hw->mac_type = e1000_82546_rev_3;
276 case E1000_DEV_ID_82541EI:
277 case E1000_DEV_ID_82541EI_MOBILE:
278 hw->mac_type = e1000_82541;
280 case E1000_DEV_ID_82541ER:
281 case E1000_DEV_ID_82541GI:
282 case E1000_DEV_ID_82541GI_LF:
283 case E1000_DEV_ID_82541GI_MOBILE:
284 hw->mac_type = e1000_82541_rev_2;
286 case E1000_DEV_ID_82547EI:
287 hw->mac_type = e1000_82547;
289 case E1000_DEV_ID_82547GI:
290 hw->mac_type = e1000_82547_rev_2;
293 /* Should never have loaded on this device */
294 return -E1000_ERR_MAC_TYPE;
297 switch(hw->mac_type) {
300 case e1000_82541_rev_2:
301 case e1000_82547_rev_2:
302 hw->asf_firmware_present = TRUE;
308 return E1000_SUCCESS;
311 /*****************************************************************************
312 * Set media type and TBI compatibility.
314 * hw - Struct containing variables accessed by shared code
315 * **************************************************************************/
317 e1000_set_media_type(struct e1000_hw *hw)
321 DEBUGFUNC("e1000_set_media_type");
323 if(hw->mac_type != e1000_82543) {
324 /* tbi_compatibility is only valid on 82543 */
325 hw->tbi_compatibility_en = FALSE;
328 switch (hw->device_id) {
329 case E1000_DEV_ID_82545GM_SERDES:
330 case E1000_DEV_ID_82546GB_SERDES:
331 hw->media_type = e1000_media_type_internal_serdes;
334 if(hw->mac_type >= e1000_82543) {
335 status = E1000_READ_REG(hw, STATUS);
336 if(status & E1000_STATUS_TBIMODE) {
337 hw->media_type = e1000_media_type_fiber;
338 /* tbi_compatibility not valid on fiber */
339 hw->tbi_compatibility_en = FALSE;
341 hw->media_type = e1000_media_type_copper;
344 /* This is an 82542 (fiber only) */
345 hw->media_type = e1000_media_type_fiber;
350 /******************************************************************************
351 * Reset the transmit and receive units; mask and clear all interrupts.
353 * hw - Struct containing variables accessed by shared code
354 *****************************************************************************/
356 e1000_reset_hw(struct e1000_hw *hw)
364 DEBUGFUNC("e1000_reset_hw");
366 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
367 if(hw->mac_type == e1000_82542_rev2_0) {
368 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
369 e1000_pci_clear_mwi(hw);
372 /* Clear interrupt mask to stop board from generating interrupts */
373 DEBUGOUT("Masking off all interrupts\n");
374 E1000_WRITE_REG(hw, IMC, 0xffffffff);
376 /* Disable the Transmit and Receive units. Then delay to allow
377 * any pending transactions to complete before we hit the MAC with
380 E1000_WRITE_REG(hw, RCTL, 0);
381 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
382 E1000_WRITE_FLUSH(hw);
384 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
385 hw->tbi_compatibility_on = FALSE;
387 /* Delay to allow any outstanding PCI transactions to complete before
388 * resetting the device
392 ctrl = E1000_READ_REG(hw, CTRL);
394 /* Must reset the PHY before resetting the MAC */
395 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
396 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
400 /* Issue a global reset to the MAC. This will reset the chip's
401 * transmit, receive, DMA, and link units. It will not effect
402 * the current PCI configuration. The global reset bit is self-
403 * clearing, and should clear within a microsecond.
405 DEBUGOUT("Issuing a global reset to MAC\n");
407 switch(hw->mac_type) {
413 case e1000_82541_rev_2:
414 /* These controllers can't ack the 64-bit write when issuing the
415 * reset, so use IO-mapping as a workaround to issue the reset */
416 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
418 case e1000_82545_rev_3:
419 case e1000_82546_rev_3:
420 /* Reset is performed on a shadow of the control register */
421 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
424 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
428 /* After MAC reset, force reload of EEPROM to restore power-on settings to
429 * device. Later controllers reload the EEPROM automatically, so just wait
430 * for reload to complete.
432 switch(hw->mac_type) {
433 case e1000_82542_rev2_0:
434 case e1000_82542_rev2_1:
437 /* Wait for reset to complete */
439 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
440 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
441 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
442 E1000_WRITE_FLUSH(hw);
443 /* Wait for EEPROM reload */
447 case e1000_82541_rev_2:
449 case e1000_82547_rev_2:
450 /* Wait for EEPROM reload */
454 /* Wait for EEPROM reload (it happens automatically) */
459 /* Disable HW ARPs on ASF enabled adapters */
460 if(hw->mac_type >= e1000_82540) {
461 manc = E1000_READ_REG(hw, MANC);
462 manc &= ~(E1000_MANC_ARP_EN);
463 E1000_WRITE_REG(hw, MANC, manc);
466 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
467 e1000_phy_init_script(hw);
469 /* Configure activity LED after PHY reset */
470 led_ctrl = E1000_READ_REG(hw, LEDCTL);
471 led_ctrl &= IGP_ACTIVITY_LED_MASK;
472 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
473 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
476 /* Clear interrupt mask to stop board from generating interrupts */
477 DEBUGOUT("Masking off all interrupts\n");
478 E1000_WRITE_REG(hw, IMC, 0xffffffff);
480 /* Clear any pending interrupt events. */
481 icr = E1000_READ_REG(hw, ICR);
483 /* If MWI was previously enabled, reenable it. */
484 if(hw->mac_type == e1000_82542_rev2_0) {
485 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
486 e1000_pci_set_mwi(hw);
489 return E1000_SUCCESS;
492 /******************************************************************************
493 * Performs basic configuration of the adapter.
495 * hw - Struct containing variables accessed by shared code
497 * Assumes that the controller has previously been reset and is in a
498 * post-reset uninitialized state. Initializes the receive address registers,
499 * multicast table, and VLAN filter table. Calls routines to setup link
500 * configuration and flow control settings. Clears all on-chip counters. Leaves
501 * the transmit and receive units disabled and uninitialized.
502 *****************************************************************************/
504 e1000_init_hw(struct e1000_hw *hw)
509 uint16_t pcix_cmd_word;
510 uint16_t pcix_stat_hi_word;
513 DEBUGFUNC("e1000_init_hw");
515 /* Initialize Identification LED */
516 ret_val = e1000_id_led_init(hw);
518 DEBUGOUT("Error Initializing Identification LED\n");
522 /* Set the media type and TBI compatibility */
523 e1000_set_media_type(hw);
525 /* Disabling VLAN filtering. */
526 DEBUGOUT("Initializing the IEEE VLAN\n");
527 E1000_WRITE_REG(hw, VET, 0);
529 e1000_clear_vfta(hw);
531 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
532 if(hw->mac_type == e1000_82542_rev2_0) {
533 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
534 e1000_pci_clear_mwi(hw);
535 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
536 E1000_WRITE_FLUSH(hw);
540 /* Setup the receive address. This involves initializing all of the Receive
541 * Address Registers (RARs 0 - 15).
543 e1000_init_rx_addrs(hw);
545 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
546 if(hw->mac_type == e1000_82542_rev2_0) {
547 E1000_WRITE_REG(hw, RCTL, 0);
548 E1000_WRITE_FLUSH(hw);
550 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
551 e1000_pci_set_mwi(hw);
554 /* Zero out the Multicast HASH table */
555 DEBUGOUT("Zeroing the MTA\n");
556 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
557 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
559 /* Set the PCI priority bit correctly in the CTRL register. This
560 * determines if the adapter gives priority to receives, or if it
561 * gives equal priority to transmits and receives.
563 if(hw->dma_fairness) {
564 ctrl = E1000_READ_REG(hw, CTRL);
565 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
568 switch(hw->mac_type) {
569 case e1000_82545_rev_3:
570 case e1000_82546_rev_3:
573 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
574 if(hw->bus_type == e1000_bus_type_pcix) {
575 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
576 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
578 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
579 PCIX_COMMAND_MMRBC_SHIFT;
580 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
581 PCIX_STATUS_HI_MMRBC_SHIFT;
582 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
583 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
584 if(cmd_mmrbc > stat_mmrbc) {
585 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
586 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
587 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
594 /* Call a subroutine to configure the link and setup flow control. */
595 ret_val = e1000_setup_link(hw);
597 /* Set the transmit descriptor write-back policy */
598 if(hw->mac_type > e1000_82544) {
599 ctrl = E1000_READ_REG(hw, TXDCTL);
600 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
601 E1000_WRITE_REG(hw, TXDCTL, ctrl);
604 /* Clear all of the statistics registers (clear on read). It is
605 * important that we do this after we have tried to establish link
606 * because the symbol error count will increment wildly if there
609 e1000_clear_hw_cntrs(hw);
614 /******************************************************************************
615 * Adjust SERDES output amplitude based on EEPROM setting.
617 * hw - Struct containing variables accessed by shared code.
618 *****************************************************************************/
620 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
622 uint16_t eeprom_data;
625 DEBUGFUNC("e1000_adjust_serdes_amplitude");
627 if(hw->media_type != e1000_media_type_internal_serdes)
628 return E1000_SUCCESS;
630 switch(hw->mac_type) {
631 case e1000_82545_rev_3:
632 case e1000_82546_rev_3:
635 return E1000_SUCCESS;
638 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
643 if(eeprom_data != EEPROM_RESERVED_WORD) {
644 /* Adjust SERDES output amplitude only. */
645 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
646 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
651 return E1000_SUCCESS;
654 /******************************************************************************
655 * Configures flow control and link settings.
657 * hw - Struct containing variables accessed by shared code
659 * Determines which flow control settings to use. Calls the apropriate media-
660 * specific link configuration function. Configures the flow control settings.
661 * Assuming the adapter has a valid link partner, a valid link should be
662 * established. Assumes the hardware has previously been reset and the
663 * transmitter and receiver are not enabled.
664 *****************************************************************************/
666 e1000_setup_link(struct e1000_hw *hw)
670 uint16_t eeprom_data;
672 DEBUGFUNC("e1000_setup_link");
674 /* Read and store word 0x0F of the EEPROM. This word contains bits
675 * that determine the hardware's default PAUSE (flow control) mode,
676 * a bit that determines whether the HW defaults to enabling or
677 * disabling auto-negotiation, and the direction of the
678 * SW defined pins. If there is no SW over-ride of the flow
679 * control setting, then the variable hw->fc will
680 * be initialized based on a value in the EEPROM.
682 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
683 DEBUGOUT("EEPROM Read Error\n");
684 return -E1000_ERR_EEPROM;
687 if(hw->fc == e1000_fc_default) {
688 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
689 hw->fc = e1000_fc_none;
690 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
691 EEPROM_WORD0F_ASM_DIR)
692 hw->fc = e1000_fc_tx_pause;
694 hw->fc = e1000_fc_full;
697 /* We want to save off the original Flow Control configuration just
698 * in case we get disconnected and then reconnected into a different
699 * hub or switch with different Flow Control capabilities.
701 if(hw->mac_type == e1000_82542_rev2_0)
702 hw->fc &= (~e1000_fc_tx_pause);
704 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
705 hw->fc &= (~e1000_fc_rx_pause);
707 hw->original_fc = hw->fc;
709 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
711 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
712 * polarity value for the SW controlled pins, and setup the
713 * Extended Device Control reg with that info.
714 * This is needed because one of the SW controlled pins is used for
715 * signal detection. So this should be done before e1000_setup_pcs_link()
716 * or e1000_phy_setup() is called.
718 if(hw->mac_type == e1000_82543) {
719 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
721 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
724 /* Call the necessary subroutine to configure the link. */
725 ret_val = (hw->media_type == e1000_media_type_copper) ?
726 e1000_setup_copper_link(hw) :
727 e1000_setup_fiber_serdes_link(hw);
729 /* Initialize the flow control address, type, and PAUSE timer
730 * registers to their default values. This is done even if flow
731 * control is disabled, because it does not hurt anything to
732 * initialize these registers.
734 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
736 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
737 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
738 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
739 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
741 /* Set the flow control receive threshold registers. Normally,
742 * these registers will be set to a default threshold that may be
743 * adjusted later by the driver's runtime code. However, if the
744 * ability to transmit pause frames in not enabled, then these
745 * registers will be set to 0.
747 if(!(hw->fc & e1000_fc_tx_pause)) {
748 E1000_WRITE_REG(hw, FCRTL, 0);
749 E1000_WRITE_REG(hw, FCRTH, 0);
751 /* We need to set up the Receive Threshold high and low water marks
752 * as well as (optionally) enabling the transmission of XON frames.
754 if(hw->fc_send_xon) {
755 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
756 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
758 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
759 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
765 /******************************************************************************
766 * Sets up link for a fiber based or serdes based adapter
768 * hw - Struct containing variables accessed by shared code
770 * Manipulates Physical Coding Sublayer functions in order to configure
771 * link. Assumes the hardware has been previously reset and the transmitter
772 * and receiver are not enabled.
773 *****************************************************************************/
775 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
784 DEBUGFUNC("e1000_setup_fiber_serdes_link");
786 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
787 * set when the optics detect a signal. On older adapters, it will be
788 * cleared when there is a signal. This applies to fiber media only.
789 * If we're on serdes media, adjust the output amplitude to value set in
792 ctrl = E1000_READ_REG(hw, CTRL);
793 if(hw->media_type == e1000_media_type_fiber)
794 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
796 ret_val = e1000_adjust_serdes_amplitude(hw);
800 /* Take the link out of reset */
801 ctrl &= ~(E1000_CTRL_LRST);
803 /* Adjust VCO speed to improve BER performance */
804 ret_val = e1000_set_vco_speed(hw);
808 e1000_config_collision_dist(hw);
810 /* Check for a software override of the flow control settings, and setup
811 * the device accordingly. If auto-negotiation is enabled, then software
812 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
813 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
814 * auto-negotiation is disabled, then software will have to manually
815 * configure the two flow control enable bits in the CTRL register.
817 * The possible values of the "fc" parameter are:
818 * 0: Flow control is completely disabled
819 * 1: Rx flow control is enabled (we can receive pause frames, but
820 * not send pause frames).
821 * 2: Tx flow control is enabled (we can send pause frames but we do
822 * not support receiving pause frames).
823 * 3: Both Rx and TX flow control (symmetric) are enabled.
827 /* Flow control is completely disabled by a software over-ride. */
828 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
830 case e1000_fc_rx_pause:
831 /* RX Flow control is enabled and TX Flow control is disabled by a
832 * software over-ride. Since there really isn't a way to advertise
833 * that we are capable of RX Pause ONLY, we will advertise that we
834 * support both symmetric and asymmetric RX PAUSE. Later, we will
835 * disable the adapter's ability to send PAUSE frames.
837 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
839 case e1000_fc_tx_pause:
840 /* TX Flow control is enabled, and RX Flow control is disabled, by a
841 * software over-ride.
843 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
846 /* Flow control (both RX and TX) is enabled by a software over-ride. */
847 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
850 DEBUGOUT("Flow control param set incorrectly\n");
851 return -E1000_ERR_CONFIG;
855 /* Since auto-negotiation is enabled, take the link out of reset (the link
856 * will be in reset, because we previously reset the chip). This will
857 * restart auto-negotiation. If auto-neogtiation is successful then the
858 * link-up status bit will be set and the flow control enable bits (RFCE
859 * and TFCE) will be set according to their negotiated value.
861 DEBUGOUT("Auto-negotiation enabled\n");
863 E1000_WRITE_REG(hw, TXCW, txcw);
864 E1000_WRITE_REG(hw, CTRL, ctrl);
865 E1000_WRITE_FLUSH(hw);
870 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
871 * indication in the Device Status Register. Time-out if a link isn't
872 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
873 * less than 500 milliseconds even if the other end is doing it in SW).
874 * For internal serdes, we just assume a signal is present, then poll.
876 if(hw->media_type == e1000_media_type_internal_serdes ||
877 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
878 DEBUGOUT("Looking for Link\n");
879 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
881 status = E1000_READ_REG(hw, STATUS);
882 if(status & E1000_STATUS_LU) break;
884 if(i == (LINK_UP_TIMEOUT / 10)) {
885 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
886 hw->autoneg_failed = 1;
887 /* AutoNeg failed to achieve a link, so we'll call
888 * e1000_check_for_link. This routine will force the link up if
889 * we detect a signal. This will allow us to communicate with
890 * non-autonegotiating link partners.
892 ret_val = e1000_check_for_link(hw);
894 DEBUGOUT("Error while checking for link\n");
897 hw->autoneg_failed = 0;
899 hw->autoneg_failed = 0;
900 DEBUGOUT("Valid Link Found\n");
903 DEBUGOUT("No Signal Detected\n");
905 return E1000_SUCCESS;
908 /******************************************************************************
909 * Detects which PHY is present and the speed and duplex
911 * hw - Struct containing variables accessed by shared code
912 ******************************************************************************/
914 e1000_setup_copper_link(struct e1000_hw *hw)
922 DEBUGFUNC("e1000_setup_copper_link");
924 ctrl = E1000_READ_REG(hw, CTRL);
925 /* With 82543, we need to force speed and duplex on the MAC equal to what
926 * the PHY speed and duplex configuration is. In addition, we need to
927 * perform a hardware reset on the PHY to take it out of reset.
929 if(hw->mac_type > e1000_82543) {
930 ctrl |= E1000_CTRL_SLU;
931 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
932 E1000_WRITE_REG(hw, CTRL, ctrl);
934 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
935 E1000_WRITE_REG(hw, CTRL, ctrl);
936 e1000_phy_hw_reset(hw);
939 /* Make sure we have a valid PHY */
940 ret_val = e1000_detect_gig_phy(hw);
942 DEBUGOUT("Error, did not detect valid phy.\n");
945 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
947 /* Set PHY to class A mode (if necessary) */
948 ret_val = e1000_set_phy_mode(hw);
952 if((hw->mac_type == e1000_82545_rev_3) ||
953 (hw->mac_type == e1000_82546_rev_3)) {
954 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
955 phy_data |= 0x00000008;
956 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
959 if(hw->mac_type <= e1000_82543 ||
960 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
961 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
962 hw->phy_reset_disable = FALSE;
964 if(!hw->phy_reset_disable) {
965 if (hw->phy_type == e1000_phy_igp) {
967 ret_val = e1000_phy_reset(hw);
969 DEBUGOUT("Error Resetting the PHY\n");
973 /* Wait 10ms for MAC to configure PHY from eeprom settings */
976 /* Configure activity LED after PHY reset */
977 led_ctrl = E1000_READ_REG(hw, LEDCTL);
978 led_ctrl &= IGP_ACTIVITY_LED_MASK;
979 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
980 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
982 /* disable lplu d3 during driver init */
983 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
985 DEBUGOUT("Error Disabling LPLU D3\n");
989 /* Configure mdi-mdix settings */
990 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
995 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
996 hw->dsp_config_state = e1000_dsp_config_disabled;
997 /* Force MDI for earlier revs of the IGP PHY */
998 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
999 IGP01E1000_PSCR_FORCE_MDI_MDIX);
1003 hw->dsp_config_state = e1000_dsp_config_enabled;
1004 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1008 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1011 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1015 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1019 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
1024 /* set auto-master slave resolution settings */
1026 e1000_ms_type phy_ms_setting = hw->master_slave;
1028 if(hw->ffe_config_state == e1000_ffe_config_active)
1029 hw->ffe_config_state = e1000_ffe_config_enabled;
1031 if(hw->dsp_config_state == e1000_dsp_config_activated)
1032 hw->dsp_config_state = e1000_dsp_config_enabled;
1034 /* when autonegotiation advertisment is only 1000Mbps then we
1035 * should disable SmartSpeed and enable Auto MasterSlave
1036 * resolution as hardware default. */
1037 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1038 /* Disable SmartSpeed */
1039 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1043 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1044 ret_val = e1000_write_phy_reg(hw,
1045 IGP01E1000_PHY_PORT_CONFIG,
1049 /* Set auto Master/Slave resolution process */
1050 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1053 phy_data &= ~CR_1000T_MS_ENABLE;
1054 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1059 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1063 /* load defaults for future use */
1064 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1065 ((phy_data & CR_1000T_MS_VALUE) ?
1066 e1000_ms_force_master :
1067 e1000_ms_force_slave) :
1070 switch (phy_ms_setting) {
1071 case e1000_ms_force_master:
1072 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1074 case e1000_ms_force_slave:
1075 phy_data |= CR_1000T_MS_ENABLE;
1076 phy_data &= ~(CR_1000T_MS_VALUE);
1079 phy_data &= ~CR_1000T_MS_ENABLE;
1083 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1088 /* Enable CRS on TX. This must be set for half-duplex operation. */
1089 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1094 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1097 * MDI/MDI-X = 0 (default)
1098 * 0 - Auto for all speeds
1101 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1103 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1107 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1110 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1113 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1117 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1122 * disable_polarity_correction = 0 (default)
1123 * Automatic Correction for Reversed Cable Polarity
1127 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1128 if(hw->disable_polarity_correction == 1)
1129 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1130 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1135 /* Force TX_CLK in the Extended PHY Specific Control Register
1138 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1143 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1145 if (hw->phy_revision < M88E1011_I_REV_4) {
1146 /* Configure Master and Slave downshift values */
1147 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1148 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1149 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1150 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1151 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1157 /* SW Reset the PHY so all changes take effect */
1158 ret_val = e1000_phy_reset(hw);
1160 DEBUGOUT("Error Resetting the PHY\n");
1166 * autoneg = 1 (default)
1167 * PHY will advertise value(s) parsed from
1168 * autoneg_advertised and fc
1170 * PHY will be set to 10H, 10F, 100H, or 100F
1171 * depending on value parsed from forced_speed_duplex.
1174 /* Is autoneg enabled? This is enabled by default or by software
1175 * override. If so, call e1000_phy_setup_autoneg routine to parse the
1176 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1177 * the user should have provided a speed/duplex override. If so, then
1178 * call e1000_phy_force_speed_duplex to parse and set this up.
1181 /* Perform some bounds checking on the hw->autoneg_advertised
1182 * parameter. If this variable is zero, then set it to the default.
1184 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1186 /* If autoneg_advertised is zero, we assume it was not defaulted
1187 * by the calling code so we set to advertise full capability.
1189 if(hw->autoneg_advertised == 0)
1190 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1192 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1193 ret_val = e1000_phy_setup_autoneg(hw);
1195 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1198 DEBUGOUT("Restarting Auto-Neg\n");
1200 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1201 * the Auto Neg Restart bit in the PHY control register.
1203 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1207 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1208 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1212 /* Does the user want to wait for Auto-Neg to complete here, or
1213 * check at a later time (for example, callback routine).
1215 if(hw->wait_autoneg_complete) {
1216 ret_val = e1000_wait_autoneg(hw);
1218 DEBUGOUT("Error while waiting for autoneg to complete\n");
1222 hw->get_link_status = TRUE;
1224 DEBUGOUT("Forcing speed and duplex\n");
1225 ret_val = e1000_phy_force_speed_duplex(hw);
1227 DEBUGOUT("Error Forcing Speed and Duplex\n");
1231 } /* !hw->phy_reset_disable */
1233 /* Check link status. Wait up to 100 microseconds for link to become
1236 for(i = 0; i < 10; i++) {
1237 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1240 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1244 if(phy_data & MII_SR_LINK_STATUS) {
1245 /* We have link, so we need to finish the config process:
1246 * 1) Set up the MAC to the current PHY speed/duplex
1247 * if we are on 82543. If we
1248 * are on newer silicon, we only need to configure
1249 * collision distance in the Transmit Control Register.
1250 * 2) Set up flow control on the MAC to that established with
1253 if(hw->mac_type >= e1000_82544) {
1254 e1000_config_collision_dist(hw);
1256 ret_val = e1000_config_mac_to_phy(hw);
1258 DEBUGOUT("Error configuring MAC to PHY settings\n");
1262 ret_val = e1000_config_fc_after_link_up(hw);
1264 DEBUGOUT("Error Configuring Flow Control\n");
1267 DEBUGOUT("Valid link established!!!\n");
1269 if(hw->phy_type == e1000_phy_igp) {
1270 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1272 DEBUGOUT("Error Configuring DSP after link up\n");
1276 DEBUGOUT("Valid link established!!!\n");
1277 return E1000_SUCCESS;
1282 DEBUGOUT("Unable to establish link!!!\n");
1283 return E1000_SUCCESS;
1286 /******************************************************************************
1287 * Configures PHY autoneg and flow control advertisement settings
1289 * hw - Struct containing variables accessed by shared code
1290 ******************************************************************************/
1292 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1295 uint16_t mii_autoneg_adv_reg;
1296 uint16_t mii_1000t_ctrl_reg;
1298 DEBUGFUNC("e1000_phy_setup_autoneg");
1300 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1301 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1305 /* Read the MII 1000Base-T Control Register (Address 9). */
1306 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1310 /* Need to parse both autoneg_advertised and fc and set up
1311 * the appropriate PHY registers. First we will parse for
1312 * autoneg_advertised software override. Since we can advertise
1313 * a plethora of combinations, we need to check each bit
1317 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1318 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1319 * the 1000Base-T Control Register (Address 9).
1321 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1322 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1324 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1326 /* Do we want to advertise 10 Mb Half Duplex? */
1327 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1328 DEBUGOUT("Advertise 10mb Half duplex\n");
1329 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1332 /* Do we want to advertise 10 Mb Full Duplex? */
1333 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1334 DEBUGOUT("Advertise 10mb Full duplex\n");
1335 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1338 /* Do we want to advertise 100 Mb Half Duplex? */
1339 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1340 DEBUGOUT("Advertise 100mb Half duplex\n");
1341 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1344 /* Do we want to advertise 100 Mb Full Duplex? */
1345 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1346 DEBUGOUT("Advertise 100mb Full duplex\n");
1347 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1350 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1351 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1352 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1355 /* Do we want to advertise 1000 Mb Full Duplex? */
1356 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1357 DEBUGOUT("Advertise 1000mb Full duplex\n");
1358 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1361 /* Check for a software override of the flow control settings, and
1362 * setup the PHY advertisement registers accordingly. If
1363 * auto-negotiation is enabled, then software will have to set the
1364 * "PAUSE" bits to the correct value in the Auto-Negotiation
1365 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1367 * The possible values of the "fc" parameter are:
1368 * 0: Flow control is completely disabled
1369 * 1: Rx flow control is enabled (we can receive pause frames
1370 * but not send pause frames).
1371 * 2: Tx flow control is enabled (we can send pause frames
1372 * but we do not support receiving pause frames).
1373 * 3: Both Rx and TX flow control (symmetric) are enabled.
1374 * other: No software override. The flow control configuration
1375 * in the EEPROM is used.
1378 case e1000_fc_none: /* 0 */
1379 /* Flow control (RX & TX) is completely disabled by a
1380 * software over-ride.
1382 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1384 case e1000_fc_rx_pause: /* 1 */
1385 /* RX Flow control is enabled, and TX Flow control is
1386 * disabled, by a software over-ride.
1388 /* Since there really isn't a way to advertise that we are
1389 * capable of RX Pause ONLY, we will advertise that we
1390 * support both symmetric and asymmetric RX PAUSE. Later
1391 * (in e1000_config_fc_after_link_up) we will disable the
1392 *hw's ability to send PAUSE frames.
1394 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1396 case e1000_fc_tx_pause: /* 2 */
1397 /* TX Flow control is enabled, and RX Flow control is
1398 * disabled, by a software over-ride.
1400 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1401 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1403 case e1000_fc_full: /* 3 */
1404 /* Flow control (both RX and TX) is enabled by a software
1407 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1410 DEBUGOUT("Flow control param set incorrectly\n");
1411 return -E1000_ERR_CONFIG;
1414 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1418 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1420 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1424 return E1000_SUCCESS;
1427 /******************************************************************************
1428 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1430 * hw - Struct containing variables accessed by shared code
1431 ******************************************************************************/
1433 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1437 uint16_t mii_ctrl_reg;
1438 uint16_t mii_status_reg;
1442 DEBUGFUNC("e1000_phy_force_speed_duplex");
1444 /* Turn off Flow control if we are forcing speed and duplex. */
1445 hw->fc = e1000_fc_none;
1447 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1449 /* Read the Device Control Register. */
1450 ctrl = E1000_READ_REG(hw, CTRL);
1452 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1453 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1454 ctrl &= ~(DEVICE_SPEED_MASK);
1456 /* Clear the Auto Speed Detect Enable bit. */
1457 ctrl &= ~E1000_CTRL_ASDE;
1459 /* Read the MII Control Register. */
1460 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1464 /* We need to disable autoneg in order to force link and duplex. */
1466 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1468 /* Are we forcing Full or Half Duplex? */
1469 if(hw->forced_speed_duplex == e1000_100_full ||
1470 hw->forced_speed_duplex == e1000_10_full) {
1471 /* We want to force full duplex so we SET the full duplex bits in the
1472 * Device and MII Control Registers.
1474 ctrl |= E1000_CTRL_FD;
1475 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1476 DEBUGOUT("Full Duplex\n");
1478 /* We want to force half duplex so we CLEAR the full duplex bits in
1479 * the Device and MII Control Registers.
1481 ctrl &= ~E1000_CTRL_FD;
1482 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1483 DEBUGOUT("Half Duplex\n");
1486 /* Are we forcing 100Mbps??? */
1487 if(hw->forced_speed_duplex == e1000_100_full ||
1488 hw->forced_speed_duplex == e1000_100_half) {
1489 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1490 ctrl |= E1000_CTRL_SPD_100;
1491 mii_ctrl_reg |= MII_CR_SPEED_100;
1492 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1493 DEBUGOUT("Forcing 100mb ");
1495 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1496 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1497 mii_ctrl_reg |= MII_CR_SPEED_10;
1498 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1499 DEBUGOUT("Forcing 10mb ");
1502 e1000_config_collision_dist(hw);
1504 /* Write the configured values back to the Device Control Reg. */
1505 E1000_WRITE_REG(hw, CTRL, ctrl);
1507 if (hw->phy_type == e1000_phy_m88) {
1508 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1512 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1513 * forced whenever speed are duplex are forced.
1515 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1516 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1520 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1522 /* Need to reset the PHY or these changes will be ignored */
1523 mii_ctrl_reg |= MII_CR_RESET;
1525 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1526 * forced whenever speed or duplex are forced.
1528 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1532 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1533 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1535 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1540 /* Write back the modified PHY MII control register. */
1541 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1547 /* The wait_autoneg_complete flag may be a little misleading here.
1548 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1549 * But we do want to delay for a period while forcing only so we
1550 * don't generate false No Link messages. So we will wait here
1551 * only if the user has set wait_autoneg_complete to 1, which is
1554 if(hw->wait_autoneg_complete) {
1555 /* We will wait for autoneg to complete. */
1556 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1559 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1560 for(i = PHY_FORCE_TIME; i > 0; i--) {
1561 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1564 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1568 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1572 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1575 if((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1576 /* We didn't get link. Reset the DSP and wait again for link. */
1577 ret_val = e1000_phy_reset_dsp(hw);
1579 DEBUGOUT("Error Resetting PHY DSP\n");
1583 /* This loop will early-out if the link condition has been met. */
1584 for(i = PHY_FORCE_TIME; i > 0; i--) {
1585 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1587 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1590 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1594 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1600 if (hw->phy_type == e1000_phy_m88) {
1601 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1602 * Extended PHY Specific Control Register to 25MHz clock. This value
1603 * defaults back to a 2.5MHz clock when the PHY is reset.
1605 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1609 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1610 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1614 /* In addition, because of the s/w reset above, we need to enable CRS on
1615 * TX. This must be set for both full and half duplex operation.
1617 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1621 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1622 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1626 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1628 (hw->forced_speed_duplex == e1000_10_full ||
1629 hw->forced_speed_duplex == e1000_10_half)) {
1630 ret_val = e1000_polarity_reversal_workaround(hw);
1635 return E1000_SUCCESS;
1638 /******************************************************************************
1639 * Sets the collision distance in the Transmit Control register
1641 * hw - Struct containing variables accessed by shared code
1643 * Link should have been established previously. Reads the speed and duplex
1644 * information from the Device Status register.
1645 ******************************************************************************/
1647 e1000_config_collision_dist(struct e1000_hw *hw)
1651 DEBUGFUNC("e1000_config_collision_dist");
1653 tctl = E1000_READ_REG(hw, TCTL);
1655 tctl &= ~E1000_TCTL_COLD;
1656 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1658 E1000_WRITE_REG(hw, TCTL, tctl);
1659 E1000_WRITE_FLUSH(hw);
1662 /******************************************************************************
1663 * Sets MAC speed and duplex settings to reflect the those in the PHY
1665 * hw - Struct containing variables accessed by shared code
1666 * mii_reg - data to write to the MII control register
1668 * The contents of the PHY register containing the needed information need to
1670 ******************************************************************************/
1672 e1000_config_mac_to_phy(struct e1000_hw *hw)
1678 DEBUGFUNC("e1000_config_mac_to_phy");
1680 /* Read the Device Control Register and set the bits to Force Speed
1683 ctrl = E1000_READ_REG(hw, CTRL);
1684 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1685 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1687 /* Set up duplex in the Device Control and Transmit Control
1688 * registers depending on negotiated values.
1690 if (hw->phy_type == e1000_phy_igp) {
1691 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
1696 if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
1697 else ctrl &= ~E1000_CTRL_FD;
1699 e1000_config_collision_dist(hw);
1701 /* Set up speed in the Device Control register depending on
1702 * negotiated values.
1704 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1705 IGP01E1000_PSSR_SPEED_1000MBPS)
1706 ctrl |= E1000_CTRL_SPD_1000;
1707 else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1708 IGP01E1000_PSSR_SPEED_100MBPS)
1709 ctrl |= E1000_CTRL_SPD_100;
1711 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
1716 if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1717 else ctrl &= ~E1000_CTRL_FD;
1719 e1000_config_collision_dist(hw);
1721 /* Set up speed in the Device Control register depending on
1722 * negotiated values.
1724 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1725 ctrl |= E1000_CTRL_SPD_1000;
1726 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1727 ctrl |= E1000_CTRL_SPD_100;
1729 /* Write the configured values back to the Device Control Reg. */
1730 E1000_WRITE_REG(hw, CTRL, ctrl);
1731 return E1000_SUCCESS;
1734 /******************************************************************************
1735 * Forces the MAC's flow control settings.
1737 * hw - Struct containing variables accessed by shared code
1739 * Sets the TFCE and RFCE bits in the device control register to reflect
1740 * the adapter settings. TFCE and RFCE need to be explicitly set by
1741 * software when a Copper PHY is used because autonegotiation is managed
1742 * by the PHY rather than the MAC. Software must also configure these
1743 * bits when link is forced on a fiber connection.
1744 *****************************************************************************/
1746 e1000_force_mac_fc(struct e1000_hw *hw)
1750 DEBUGFUNC("e1000_force_mac_fc");
1752 /* Get the current configuration of the Device Control Register */
1753 ctrl = E1000_READ_REG(hw, CTRL);
1755 /* Because we didn't get link via the internal auto-negotiation
1756 * mechanism (we either forced link or we got link via PHY
1757 * auto-neg), we have to manually enable/disable transmit an
1758 * receive flow control.
1760 * The "Case" statement below enables/disable flow control
1761 * according to the "hw->fc" parameter.
1763 * The possible values of the "fc" parameter are:
1764 * 0: Flow control is completely disabled
1765 * 1: Rx flow control is enabled (we can receive pause
1766 * frames but not send pause frames).
1767 * 2: Tx flow control is enabled (we can send pause frames
1768 * frames but we do not receive pause frames).
1769 * 3: Both Rx and TX flow control (symmetric) is enabled.
1770 * other: No other values should be possible at this point.
1775 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1777 case e1000_fc_rx_pause:
1778 ctrl &= (~E1000_CTRL_TFCE);
1779 ctrl |= E1000_CTRL_RFCE;
1781 case e1000_fc_tx_pause:
1782 ctrl &= (~E1000_CTRL_RFCE);
1783 ctrl |= E1000_CTRL_TFCE;
1786 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1789 DEBUGOUT("Flow control param set incorrectly\n");
1790 return -E1000_ERR_CONFIG;
1793 /* Disable TX Flow Control for 82542 (rev 2.0) */
1794 if(hw->mac_type == e1000_82542_rev2_0)
1795 ctrl &= (~E1000_CTRL_TFCE);
1797 E1000_WRITE_REG(hw, CTRL, ctrl);
1798 return E1000_SUCCESS;
1801 /******************************************************************************
1802 * Configures flow control settings after link is established
1804 * hw - Struct containing variables accessed by shared code
1806 * Should be called immediately after a valid link has been established.
1807 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1808 * and autonegotiation is enabled, the MAC flow control settings will be set
1809 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1810 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1811 *****************************************************************************/
1813 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1816 uint16_t mii_status_reg;
1817 uint16_t mii_nway_adv_reg;
1818 uint16_t mii_nway_lp_ability_reg;
1822 DEBUGFUNC("e1000_config_fc_after_link_up");
1824 /* Check for the case where we have fiber media and auto-neg failed
1825 * so we had to force link. In this case, we need to force the
1826 * configuration of the MAC to match the "fc" parameter.
1828 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1829 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
1830 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1831 ret_val = e1000_force_mac_fc(hw);
1833 DEBUGOUT("Error forcing flow control settings\n");
1838 /* Check for the case where we have copper media and auto-neg is
1839 * enabled. In this case, we need to check and see if Auto-Neg
1840 * has completed, and if so, how the PHY and link partner has
1841 * flow control configured.
1843 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1844 /* Read the MII Status Register and check to see if AutoNeg
1845 * has completed. We read this twice because this reg has
1846 * some "sticky" (latched) bits.
1848 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1851 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1855 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1856 /* The AutoNeg process has completed, so we now need to
1857 * read both the Auto Negotiation Advertisement Register
1858 * (Address 4) and the Auto_Negotiation Base Page Ability
1859 * Register (Address 5) to determine how flow control was
1862 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1866 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1867 &mii_nway_lp_ability_reg);
1871 /* Two bits in the Auto Negotiation Advertisement Register
1872 * (Address 4) and two bits in the Auto Negotiation Base
1873 * Page Ability Register (Address 5) determine flow control
1874 * for both the PHY and the link partner. The following
1875 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1876 * 1999, describes these PAUSE resolution bits and how flow
1877 * control is determined based upon these settings.
1878 * NOTE: DC = Don't Care
1880 * LOCAL DEVICE | LINK PARTNER
1881 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1882 *-------|---------|-------|---------|--------------------
1883 * 0 | 0 | DC | DC | e1000_fc_none
1884 * 0 | 1 | 0 | DC | e1000_fc_none
1885 * 0 | 1 | 1 | 0 | e1000_fc_none
1886 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1887 * 1 | 0 | 0 | DC | e1000_fc_none
1888 * 1 | DC | 1 | DC | e1000_fc_full
1889 * 1 | 1 | 0 | 0 | e1000_fc_none
1890 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1893 /* Are both PAUSE bits set to 1? If so, this implies
1894 * Symmetric Flow Control is enabled at both ends. The
1895 * ASM_DIR bits are irrelevant per the spec.
1897 * For Symmetric Flow Control:
1899 * LOCAL DEVICE | LINK PARTNER
1900 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1901 *-------|---------|-------|---------|--------------------
1902 * 1 | DC | 1 | DC | e1000_fc_full
1905 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1906 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1907 /* Now we need to check if the user selected RX ONLY
1908 * of pause frames. In this case, we had to advertise
1909 * FULL flow control because we could not advertise RX
1910 * ONLY. Hence, we must now check to see if we need to
1911 * turn OFF the TRANSMISSION of PAUSE frames.
1913 if(hw->original_fc == e1000_fc_full) {
1914 hw->fc = e1000_fc_full;
1915 DEBUGOUT("Flow Control = FULL.\r\n");
1917 hw->fc = e1000_fc_rx_pause;
1918 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1921 /* For receiving PAUSE frames ONLY.
1923 * LOCAL DEVICE | LINK PARTNER
1924 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1925 *-------|---------|-------|---------|--------------------
1926 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1929 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1930 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1931 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1932 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1933 hw->fc = e1000_fc_tx_pause;
1934 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1936 /* For transmitting PAUSE frames ONLY.
1938 * LOCAL DEVICE | LINK PARTNER
1939 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1940 *-------|---------|-------|---------|--------------------
1941 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1944 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1945 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1946 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1947 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1948 hw->fc = e1000_fc_rx_pause;
1949 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1951 /* Per the IEEE spec, at this point flow control should be
1952 * disabled. However, we want to consider that we could
1953 * be connected to a legacy switch that doesn't advertise
1954 * desired flow control, but can be forced on the link
1955 * partner. So if we advertised no flow control, that is
1956 * what we will resolve to. If we advertised some kind of
1957 * receive capability (Rx Pause Only or Full Flow Control)
1958 * and the link partner advertised none, we will configure
1959 * ourselves to enable Rx Flow Control only. We can do
1960 * this safely for two reasons: If the link partner really
1961 * didn't want flow control enabled, and we enable Rx, no
1962 * harm done since we won't be receiving any PAUSE frames
1963 * anyway. If the intent on the link partner was to have
1964 * flow control enabled, then by us enabling RX only, we
1965 * can at least receive pause frames and process them.
1966 * This is a good idea because in most cases, since we are
1967 * predominantly a server NIC, more times than not we will
1968 * be asked to delay transmission of packets than asking
1969 * our link partner to pause transmission of frames.
1971 else if((hw->original_fc == e1000_fc_none ||
1972 hw->original_fc == e1000_fc_tx_pause) ||
1973 hw->fc_strict_ieee) {
1974 hw->fc = e1000_fc_none;
1975 DEBUGOUT("Flow Control = NONE.\r\n");
1977 hw->fc = e1000_fc_rx_pause;
1978 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1981 /* Now we need to do one last check... If we auto-
1982 * negotiated to HALF DUPLEX, flow control should not be
1983 * enabled per IEEE 802.3 spec.
1985 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
1987 DEBUGOUT("Error getting link speed and duplex\n");
1991 if(duplex == HALF_DUPLEX)
1992 hw->fc = e1000_fc_none;
1994 /* Now we call a subroutine to actually force the MAC
1995 * controller to use the correct flow control settings.
1997 ret_val = e1000_force_mac_fc(hw);
1999 DEBUGOUT("Error forcing flow control settings\n");
2003 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2006 return E1000_SUCCESS;
2009 /******************************************************************************
2010 * Checks to see if the link status of the hardware has changed.
2012 * hw - Struct containing variables accessed by shared code
2014 * Called by any function that needs to check the link status of the adapter.
2015 *****************************************************************************/
2017 e1000_check_for_link(struct e1000_hw *hw)
2024 uint32_t signal = 0;
2028 DEBUGFUNC("e1000_check_for_link");
2030 ctrl = E1000_READ_REG(hw, CTRL);
2031 status = E1000_READ_REG(hw, STATUS);
2033 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2034 * set when the optics detect a signal. On older adapters, it will be
2035 * cleared when there is a signal. This applies to fiber media only.
2037 if((hw->media_type == e1000_media_type_fiber) ||
2038 (hw->media_type == e1000_media_type_internal_serdes)) {
2039 rxcw = E1000_READ_REG(hw, RXCW);
2041 if(hw->media_type == e1000_media_type_fiber) {
2042 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2043 if(status & E1000_STATUS_LU)
2044 hw->get_link_status = FALSE;
2048 /* If we have a copper PHY then we only want to go out to the PHY
2049 * registers to see if Auto-Neg has completed and/or if our link
2050 * status has changed. The get_link_status flag will be set if we
2051 * receive a Link Status Change interrupt or we have Rx Sequence
2054 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2055 /* First we want to see if the MII Status Register reports
2056 * link. If so, then we want to get the current speed/duplex
2058 * Read the register twice since the link bit is sticky.
2060 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2063 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2067 if(phy_data & MII_SR_LINK_STATUS) {
2068 hw->get_link_status = FALSE;
2069 /* Check if there was DownShift, must be checked immediately after
2071 e1000_check_downshift(hw);
2073 /* If we are on 82544 or 82543 silicon and speed/duplex
2074 * are forced to 10H or 10F, then we will implement the polarity
2075 * reversal workaround. We disable interrupts first, and upon
2076 * returning, place the devices interrupt state to its previous
2077 * value except for the link status change interrupt which will
2078 * happen due to the execution of this workaround.
2081 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2083 (hw->forced_speed_duplex == e1000_10_full ||
2084 hw->forced_speed_duplex == e1000_10_half)) {
2085 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2086 ret_val = e1000_polarity_reversal_workaround(hw);
2087 icr = E1000_READ_REG(hw, ICR);
2088 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2089 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2093 /* No link detected */
2094 e1000_config_dsp_after_link_change(hw, FALSE);
2098 /* If we are forcing speed/duplex, then we simply return since
2099 * we have already determined whether we have link or not.
2101 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2103 /* optimize the dsp settings for the igp phy */
2104 e1000_config_dsp_after_link_change(hw, TRUE);
2106 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2107 * have Si on board that is 82544 or newer, Auto
2108 * Speed Detection takes care of MAC speed/duplex
2109 * configuration. So we only need to configure Collision
2110 * Distance in the MAC. Otherwise, we need to force
2111 * speed/duplex on the MAC to the current PHY speed/duplex
2114 if(hw->mac_type >= e1000_82544)
2115 e1000_config_collision_dist(hw);
2117 ret_val = e1000_config_mac_to_phy(hw);
2119 DEBUGOUT("Error configuring MAC to PHY settings\n");
2124 /* Configure Flow Control now that Auto-Neg has completed. First, we
2125 * need to restore the desired flow control settings because we may
2126 * have had to re-autoneg with a different link partner.
2128 ret_val = e1000_config_fc_after_link_up(hw);
2130 DEBUGOUT("Error configuring flow control\n");
2134 /* At this point we know that we are on copper and we have
2135 * auto-negotiated link. These are conditions for checking the link
2136 * partner capability register. We use the link speed to determine if
2137 * TBI compatibility needs to be turned on or off. If the link is not
2138 * at gigabit speed, then TBI compatibility is not needed. If we are
2139 * at gigabit speed, we turn on TBI compatibility.
2141 if(hw->tbi_compatibility_en) {
2142 uint16_t speed, duplex;
2143 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2144 if(speed != SPEED_1000) {
2145 /* If link speed is not set to gigabit speed, we do not need
2146 * to enable TBI compatibility.
2148 if(hw->tbi_compatibility_on) {
2149 /* If we previously were in the mode, turn it off. */
2150 rctl = E1000_READ_REG(hw, RCTL);
2151 rctl &= ~E1000_RCTL_SBP;
2152 E1000_WRITE_REG(hw, RCTL, rctl);
2153 hw->tbi_compatibility_on = FALSE;
2156 /* If TBI compatibility is was previously off, turn it on. For
2157 * compatibility with a TBI link partner, we will store bad
2158 * packets. Some frames have an additional byte on the end and
2159 * will look like CRC errors to to the hardware.
2161 if(!hw->tbi_compatibility_on) {
2162 hw->tbi_compatibility_on = TRUE;
2163 rctl = E1000_READ_REG(hw, RCTL);
2164 rctl |= E1000_RCTL_SBP;
2165 E1000_WRITE_REG(hw, RCTL, rctl);
2170 /* If we don't have link (auto-negotiation failed or link partner cannot
2171 * auto-negotiate), the cable is plugged in (we have signal), and our
2172 * link partner is not trying to auto-negotiate with us (we are receiving
2173 * idles or data), we need to force link up. We also need to give
2174 * auto-negotiation time to complete, in case the cable was just plugged
2175 * in. The autoneg_failed flag does this.
2177 else if((((hw->media_type == e1000_media_type_fiber) &&
2178 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2179 (hw->media_type == e1000_media_type_internal_serdes)) &&
2180 (!(status & E1000_STATUS_LU)) &&
2181 (!(rxcw & E1000_RXCW_C))) {
2182 if(hw->autoneg_failed == 0) {
2183 hw->autoneg_failed = 1;
2186 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2188 /* Disable auto-negotiation in the TXCW register */
2189 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2191 /* Force link-up and also force full-duplex. */
2192 ctrl = E1000_READ_REG(hw, CTRL);
2193 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2194 E1000_WRITE_REG(hw, CTRL, ctrl);
2196 /* Configure Flow Control after forcing link up. */
2197 ret_val = e1000_config_fc_after_link_up(hw);
2199 DEBUGOUT("Error configuring flow control\n");
2203 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2204 * auto-negotiation in the TXCW register and disable forced link in the
2205 * Device Control register in an attempt to auto-negotiate with our link
2208 else if(((hw->media_type == e1000_media_type_fiber) ||
2209 (hw->media_type == e1000_media_type_internal_serdes)) &&
2210 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2211 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2212 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2213 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2215 hw->serdes_link_down = FALSE;
2217 /* If we force link for non-auto-negotiation switch, check link status
2218 * based on MAC synchronization for internal serdes media type.
2220 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2221 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2222 /* SYNCH bit and IV bit are sticky. */
2224 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2225 if(!(rxcw & E1000_RXCW_IV)) {
2226 hw->serdes_link_down = FALSE;
2227 DEBUGOUT("SERDES: Link is up.\n");
2230 hw->serdes_link_down = TRUE;
2231 DEBUGOUT("SERDES: Link is down.\n");
2234 if((hw->media_type == e1000_media_type_internal_serdes) &&
2235 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2236 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2238 return E1000_SUCCESS;
2241 /******************************************************************************
2242 * Detects the current speed and duplex settings of the hardware.
2244 * hw - Struct containing variables accessed by shared code
2245 * speed - Speed of the connection
2246 * duplex - Duplex setting of the connection
2247 *****************************************************************************/
2249 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2257 DEBUGFUNC("e1000_get_speed_and_duplex");
2259 if(hw->mac_type >= e1000_82543) {
2260 status = E1000_READ_REG(hw, STATUS);
2261 if(status & E1000_STATUS_SPEED_1000) {
2262 *speed = SPEED_1000;
2263 DEBUGOUT("1000 Mbs, ");
2264 } else if(status & E1000_STATUS_SPEED_100) {
2266 DEBUGOUT("100 Mbs, ");
2269 DEBUGOUT("10 Mbs, ");
2272 if(status & E1000_STATUS_FD) {
2273 *duplex = FULL_DUPLEX;
2274 DEBUGOUT("Full Duplex\r\n");
2276 *duplex = HALF_DUPLEX;
2277 DEBUGOUT(" Half Duplex\r\n");
2280 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2281 *speed = SPEED_1000;
2282 *duplex = FULL_DUPLEX;
2285 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2286 * if it is operating at half duplex. Here we set the duplex settings to
2287 * match the duplex in the link partner's capabilities.
2289 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2290 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2294 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2295 *duplex = HALF_DUPLEX;
2297 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2300 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2301 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2302 *duplex = HALF_DUPLEX;
2306 return E1000_SUCCESS;
2309 /******************************************************************************
2310 * Blocks until autoneg completes or times out (~4.5 seconds)
2312 * hw - Struct containing variables accessed by shared code
2313 ******************************************************************************/
2315 e1000_wait_autoneg(struct e1000_hw *hw)
2321 DEBUGFUNC("e1000_wait_autoneg");
2322 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2324 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2325 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2326 /* Read the MII Status Register and wait for Auto-Neg
2327 * Complete bit to be set.
2329 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2332 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2335 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2336 return E1000_SUCCESS;
2340 return E1000_SUCCESS;
2343 /******************************************************************************
2344 * Raises the Management Data Clock
2346 * hw - Struct containing variables accessed by shared code
2347 * ctrl - Device control register's current value
2348 ******************************************************************************/
2350 e1000_raise_mdi_clk(struct e1000_hw *hw,
2353 /* Raise the clock input to the Management Data Clock (by setting the MDC
2354 * bit), and then delay 10 microseconds.
2356 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2357 E1000_WRITE_FLUSH(hw);
2361 /******************************************************************************
2362 * Lowers the Management Data Clock
2364 * hw - Struct containing variables accessed by shared code
2365 * ctrl - Device control register's current value
2366 ******************************************************************************/
2368 e1000_lower_mdi_clk(struct e1000_hw *hw,
2371 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2372 * bit), and then delay 10 microseconds.
2374 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2375 E1000_WRITE_FLUSH(hw);
2379 /******************************************************************************
2380 * Shifts data bits out to the PHY
2382 * hw - Struct containing variables accessed by shared code
2383 * data - Data to send out to the PHY
2384 * count - Number of bits to shift out
2386 * Bits are shifted out in MSB to LSB order.
2387 ******************************************************************************/
2389 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2396 /* We need to shift "count" number of bits out to the PHY. So, the value
2397 * in the "data" parameter will be shifted out to the PHY one bit at a
2398 * time. In order to do this, "data" must be broken down into bits.
2401 mask <<= (count - 1);
2403 ctrl = E1000_READ_REG(hw, CTRL);
2405 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2406 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2409 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2410 * then raising and lowering the Management Data Clock. A "0" is
2411 * shifted out to the PHY by setting the MDIO bit to "0" and then
2412 * raising and lowering the clock.
2414 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2415 else ctrl &= ~E1000_CTRL_MDIO;
2417 E1000_WRITE_REG(hw, CTRL, ctrl);
2418 E1000_WRITE_FLUSH(hw);
2422 e1000_raise_mdi_clk(hw, &ctrl);
2423 e1000_lower_mdi_clk(hw, &ctrl);
2429 /******************************************************************************
2430 * Shifts data bits in from the PHY
2432 * hw - Struct containing variables accessed by shared code
2434 * Bits are shifted in in MSB to LSB order.
2435 ******************************************************************************/
2437 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2443 /* In order to read a register from the PHY, we need to shift in a total
2444 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2445 * to avoid contention on the MDIO pin when a read operation is performed.
2446 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2447 * by raising the input to the Management Data Clock (setting the MDC bit),
2448 * and then reading the value of the MDIO bit.
2450 ctrl = E1000_READ_REG(hw, CTRL);
2452 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2453 ctrl &= ~E1000_CTRL_MDIO_DIR;
2454 ctrl &= ~E1000_CTRL_MDIO;
2456 E1000_WRITE_REG(hw, CTRL, ctrl);
2457 E1000_WRITE_FLUSH(hw);
2459 /* Raise and Lower the clock before reading in the data. This accounts for
2460 * the turnaround bits. The first clock occurred when we clocked out the
2461 * last bit of the Register Address.
2463 e1000_raise_mdi_clk(hw, &ctrl);
2464 e1000_lower_mdi_clk(hw, &ctrl);
2466 for(data = 0, i = 0; i < 16; i++) {
2468 e1000_raise_mdi_clk(hw, &ctrl);
2469 ctrl = E1000_READ_REG(hw, CTRL);
2470 /* Check to see if we shifted in a "1". */
2471 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2472 e1000_lower_mdi_clk(hw, &ctrl);
2475 e1000_raise_mdi_clk(hw, &ctrl);
2476 e1000_lower_mdi_clk(hw, &ctrl);
2481 /*****************************************************************************
2482 * Reads the value from a PHY register, if the value is on a specific non zero
2483 * page, sets the page first.
2484 * hw - Struct containing variables accessed by shared code
2485 * reg_addr - address of the PHY register to read
2486 ******************************************************************************/
2488 e1000_read_phy_reg(struct e1000_hw *hw,
2494 DEBUGFUNC("e1000_read_phy_reg");
2497 if(hw->phy_type == e1000_phy_igp &&
2498 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2499 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2500 (uint16_t)reg_addr);
2506 ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2513 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2519 const uint32_t phy_addr = 1;
2521 DEBUGFUNC("e1000_read_phy_reg_ex");
2523 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2524 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2525 return -E1000_ERR_PARAM;
2528 if(hw->mac_type > e1000_82543) {
2529 /* Set up Op-code, Phy Address, and register address in the MDI
2530 * Control register. The MAC will take care of interfacing with the
2531 * PHY to retrieve the desired data.
2533 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2534 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2535 (E1000_MDIC_OP_READ));
2537 E1000_WRITE_REG(hw, MDIC, mdic);
2539 /* Poll the ready bit to see if the MDI read completed */
2540 for(i = 0; i < 64; i++) {
2542 mdic = E1000_READ_REG(hw, MDIC);
2543 if(mdic & E1000_MDIC_READY) break;
2545 if(!(mdic & E1000_MDIC_READY)) {
2546 DEBUGOUT("MDI Read did not complete\n");
2547 return -E1000_ERR_PHY;
2549 if(mdic & E1000_MDIC_ERROR) {
2550 DEBUGOUT("MDI Error\n");
2551 return -E1000_ERR_PHY;
2553 *phy_data = (uint16_t) mdic;
2555 /* We must first send a preamble through the MDIO pin to signal the
2556 * beginning of an MII instruction. This is done by sending 32
2557 * consecutive "1" bits.
2559 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2561 /* Now combine the next few fields that are required for a read
2562 * operation. We use this method instead of calling the
2563 * e1000_shift_out_mdi_bits routine five different times. The format of
2564 * a MII read instruction consists of a shift out of 14 bits and is
2565 * defined as follows:
2566 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2567 * followed by a shift in of 18 bits. This first two bits shifted in
2568 * are TurnAround bits used to avoid contention on the MDIO pin when a
2569 * READ operation is performed. These two bits are thrown away
2570 * followed by a shift in of 16 bits which contains the desired data.
2572 mdic = ((reg_addr) | (phy_addr << 5) |
2573 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2575 e1000_shift_out_mdi_bits(hw, mdic, 14);
2577 /* Now that we've shifted out the read command to the MII, we need to
2578 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2581 *phy_data = e1000_shift_in_mdi_bits(hw);
2583 return E1000_SUCCESS;
2586 /******************************************************************************
2587 * Writes a value to a PHY register
2589 * hw - Struct containing variables accessed by shared code
2590 * reg_addr - address of the PHY register to write
2591 * data - data to write to the PHY
2592 ******************************************************************************/
2594 e1000_write_phy_reg(struct e1000_hw *hw,
2600 DEBUGFUNC("e1000_write_phy_reg");
2603 if(hw->phy_type == e1000_phy_igp &&
2604 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2605 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2606 (uint16_t)reg_addr);
2612 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2619 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2625 const uint32_t phy_addr = 1;
2627 DEBUGFUNC("e1000_write_phy_reg_ex");
2629 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2630 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2631 return -E1000_ERR_PARAM;
2634 if(hw->mac_type > e1000_82543) {
2635 /* Set up Op-code, Phy Address, register address, and data intended
2636 * for the PHY register in the MDI Control register. The MAC will take
2637 * care of interfacing with the PHY to send the desired data.
2639 mdic = (((uint32_t) phy_data) |
2640 (reg_addr << E1000_MDIC_REG_SHIFT) |
2641 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2642 (E1000_MDIC_OP_WRITE));
2644 E1000_WRITE_REG(hw, MDIC, mdic);
2646 /* Poll the ready bit to see if the MDI read completed */
2647 for(i = 0; i < 640; i++) {
2649 mdic = E1000_READ_REG(hw, MDIC);
2650 if(mdic & E1000_MDIC_READY) break;
2652 if(!(mdic & E1000_MDIC_READY)) {
2653 DEBUGOUT("MDI Write did not complete\n");
2654 return -E1000_ERR_PHY;
2657 /* We'll need to use the SW defined pins to shift the write command
2658 * out to the PHY. We first send a preamble to the PHY to signal the
2659 * beginning of the MII instruction. This is done by sending 32
2660 * consecutive "1" bits.
2662 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2664 /* Now combine the remaining required fields that will indicate a
2665 * write operation. We use this method instead of calling the
2666 * e1000_shift_out_mdi_bits routine for each field in the command. The
2667 * format of a MII write instruction is as follows:
2668 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2670 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2671 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2673 mdic |= (uint32_t) phy_data;
2675 e1000_shift_out_mdi_bits(hw, mdic, 32);
2678 return E1000_SUCCESS;
2681 /******************************************************************************
2682 * Returns the PHY to the power-on reset state
2684 * hw - Struct containing variables accessed by shared code
2685 ******************************************************************************/
2687 e1000_phy_hw_reset(struct e1000_hw *hw)
2689 uint32_t ctrl, ctrl_ext;
2692 DEBUGFUNC("e1000_phy_hw_reset");
2694 DEBUGOUT("Resetting Phy...\n");
2696 if(hw->mac_type > e1000_82543) {
2697 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2698 * bit. Then, take it out of reset.
2700 ctrl = E1000_READ_REG(hw, CTRL);
2701 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2702 E1000_WRITE_FLUSH(hw);
2704 E1000_WRITE_REG(hw, CTRL, ctrl);
2705 E1000_WRITE_FLUSH(hw);
2707 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2708 * bit to put the PHY into reset. Then, take it out of reset.
2710 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2711 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2712 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2713 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2714 E1000_WRITE_FLUSH(hw);
2716 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2717 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2718 E1000_WRITE_FLUSH(hw);
2722 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2723 /* Configure activity LED after PHY reset */
2724 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2725 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2726 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2727 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2731 /******************************************************************************
2734 * hw - Struct containing variables accessed by shared code
2736 * Sets bit 15 of the MII Control regiser
2737 ******************************************************************************/
2739 e1000_phy_reset(struct e1000_hw *hw)
2744 DEBUGFUNC("e1000_phy_reset");
2746 if(hw->mac_type != e1000_82541_rev_2) {
2747 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2751 phy_data |= MII_CR_RESET;
2752 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2757 } else e1000_phy_hw_reset(hw);
2759 if(hw->phy_type == e1000_phy_igp)
2760 e1000_phy_init_script(hw);
2762 return E1000_SUCCESS;
2765 /******************************************************************************
2766 * Probes the expected PHY address for known PHY IDs
2768 * hw - Struct containing variables accessed by shared code
2769 ******************************************************************************/
2771 e1000_detect_gig_phy(struct e1000_hw *hw)
2773 int32_t phy_init_status, ret_val;
2774 uint16_t phy_id_high, phy_id_low;
2775 boolean_t match = FALSE;
2777 DEBUGFUNC("e1000_detect_gig_phy");
2779 /* Read the PHY ID Registers to identify which PHY is onboard. */
2780 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2784 hw->phy_id = (uint32_t) (phy_id_high << 16);
2786 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2790 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2791 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2793 switch(hw->mac_type) {
2795 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2798 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2802 case e1000_82545_rev_3:
2804 case e1000_82546_rev_3:
2805 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2808 case e1000_82541_rev_2:
2810 case e1000_82547_rev_2:
2811 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
2814 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2815 return -E1000_ERR_CONFIG;
2817 phy_init_status = e1000_set_phy_type(hw);
2819 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2820 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2821 return E1000_SUCCESS;
2823 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2824 return -E1000_ERR_PHY;
2827 /******************************************************************************
2828 * Resets the PHY's DSP
2830 * hw - Struct containing variables accessed by shared code
2831 ******************************************************************************/
2833 e1000_phy_reset_dsp(struct e1000_hw *hw)
2836 DEBUGFUNC("e1000_phy_reset_dsp");
2839 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
2841 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
2843 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
2845 ret_val = E1000_SUCCESS;
2851 /******************************************************************************
2852 * Get PHY information from various PHY registers for igp PHY only.
2854 * hw - Struct containing variables accessed by shared code
2855 * phy_info - PHY information structure
2856 ******************************************************************************/
2858 e1000_phy_igp_get_info(struct e1000_hw *hw,
2859 struct e1000_phy_info *phy_info)
2862 uint16_t phy_data, polarity, min_length, max_length, average;
2864 DEBUGFUNC("e1000_phy_igp_get_info");
2866 /* The downshift status is checked only once, after link is established,
2867 * and it stored in the hw->speed_downgraded parameter. */
2868 phy_info->downshift = hw->speed_downgraded;
2870 /* IGP01E1000 does not need to support it. */
2871 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2873 /* IGP01E1000 always correct polarity reversal */
2874 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
2876 /* Check polarity status */
2877 ret_val = e1000_check_polarity(hw, &polarity);
2881 phy_info->cable_polarity = polarity;
2883 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
2887 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
2888 IGP01E1000_PSSR_MDIX_SHIFT;
2890 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
2891 IGP01E1000_PSSR_SPEED_1000MBPS) {
2892 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2893 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2897 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2898 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2899 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2900 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2902 /* Get cable length */
2903 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
2907 /* transalte to old method */
2908 average = (max_length + min_length) / 2;
2910 if(average <= e1000_igp_cable_length_50)
2911 phy_info->cable_length = e1000_cable_length_50;
2912 else if(average <= e1000_igp_cable_length_80)
2913 phy_info->cable_length = e1000_cable_length_50_80;
2914 else if(average <= e1000_igp_cable_length_110)
2915 phy_info->cable_length = e1000_cable_length_80_110;
2916 else if(average <= e1000_igp_cable_length_140)
2917 phy_info->cable_length = e1000_cable_length_110_140;
2919 phy_info->cable_length = e1000_cable_length_140;
2922 return E1000_SUCCESS;
2925 /******************************************************************************
2926 * Get PHY information from various PHY registers fot m88 PHY only.
2928 * hw - Struct containing variables accessed by shared code
2929 * phy_info - PHY information structure
2930 ******************************************************************************/
2932 e1000_phy_m88_get_info(struct e1000_hw *hw,
2933 struct e1000_phy_info *phy_info)
2936 uint16_t phy_data, polarity;
2938 DEBUGFUNC("e1000_phy_m88_get_info");
2940 /* The downshift status is checked only once, after link is established,
2941 * and it stored in the hw->speed_downgraded parameter. */
2942 phy_info->downshift = hw->speed_downgraded;
2944 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2948 phy_info->extended_10bt_distance =
2949 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2950 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2951 phy_info->polarity_correction =
2952 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2953 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2955 /* Check polarity status */
2956 ret_val = e1000_check_polarity(hw, &polarity);
2960 phy_info->cable_polarity = polarity;
2962 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2966 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2967 M88E1000_PSSR_MDIX_SHIFT;
2969 if(phy_data & M88E1000_PSSR_1000MBS) {
2970 /* Cable Length Estimation and Local/Remote Receiver Informatoion
2971 * are only valid at 1000 Mbps
2973 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2974 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2976 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2980 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2981 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2983 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2984 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2987 return E1000_SUCCESS;
2990 /******************************************************************************
2991 * Get PHY information from various PHY registers
2993 * hw - Struct containing variables accessed by shared code
2994 * phy_info - PHY information structure
2995 ******************************************************************************/
2997 e1000_phy_get_info(struct e1000_hw *hw,
2998 struct e1000_phy_info *phy_info)
3003 DEBUGFUNC("e1000_phy_get_info");
3005 phy_info->cable_length = e1000_cable_length_undefined;
3006 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3007 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3008 phy_info->downshift = e1000_downshift_undefined;
3009 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3010 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3011 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3012 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3014 if(hw->media_type != e1000_media_type_copper) {
3015 DEBUGOUT("PHY info is only valid for copper media\n");
3016 return -E1000_ERR_CONFIG;
3019 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3023 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3027 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3028 DEBUGOUT("PHY info is only valid if link is up\n");
3029 return -E1000_ERR_CONFIG;
3032 if(hw->phy_type == e1000_phy_igp)
3033 return e1000_phy_igp_get_info(hw, phy_info);
3035 return e1000_phy_m88_get_info(hw, phy_info);
3039 e1000_validate_mdi_setting(struct e1000_hw *hw)
3041 DEBUGFUNC("e1000_validate_mdi_settings");
3043 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3044 DEBUGOUT("Invalid MDI setting detected\n");
3046 return -E1000_ERR_CONFIG;
3048 return E1000_SUCCESS;
3052 /******************************************************************************
3053 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3056 * hw - Struct containing variables accessed by shared code
3057 *****************************************************************************/
3059 e1000_init_eeprom_params(struct e1000_hw *hw)
3061 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3062 uint32_t eecd = E1000_READ_REG(hw, EECD);
3063 uint16_t eeprom_size;
3065 DEBUGFUNC("e1000_init_eeprom_params");
3067 switch (hw->mac_type) {
3068 case e1000_82542_rev2_0:
3069 case e1000_82542_rev2_1:
3072 eeprom->type = e1000_eeprom_microwire;
3073 eeprom->word_size = 64;
3074 eeprom->opcode_bits = 3;
3075 eeprom->address_bits = 6;
3076 eeprom->delay_usec = 50;
3080 case e1000_82545_rev_3:
3082 case e1000_82546_rev_3:
3083 eeprom->type = e1000_eeprom_microwire;
3084 eeprom->opcode_bits = 3;
3085 eeprom->delay_usec = 50;
3086 if(eecd & E1000_EECD_SIZE) {
3087 eeprom->word_size = 256;
3088 eeprom->address_bits = 8;
3090 eeprom->word_size = 64;
3091 eeprom->address_bits = 6;
3095 case e1000_82541_rev_2:
3097 case e1000_82547_rev_2:
3098 if (eecd & E1000_EECD_TYPE) {
3099 eeprom->type = e1000_eeprom_spi;
3100 eeprom->opcode_bits = 8;
3101 eeprom->delay_usec = 1;
3102 if (eecd & E1000_EECD_ADDR_BITS) {
3103 eeprom->page_size = 32;
3104 eeprom->address_bits = 16;
3106 eeprom->page_size = 8;
3107 eeprom->address_bits = 8;
3110 eeprom->type = e1000_eeprom_microwire;
3111 eeprom->opcode_bits = 3;
3112 eeprom->delay_usec = 50;
3113 if (eecd & E1000_EECD_ADDR_BITS) {
3114 eeprom->word_size = 256;
3115 eeprom->address_bits = 8;
3117 eeprom->word_size = 64;
3118 eeprom->address_bits = 6;
3126 if (eeprom->type == e1000_eeprom_spi) {
3127 eeprom->word_size = 64;
3128 if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
3129 eeprom_size &= EEPROM_SIZE_MASK;
3131 switch (eeprom_size) {
3132 case EEPROM_SIZE_16KB:
3133 eeprom->word_size = 8192;
3135 case EEPROM_SIZE_8KB:
3136 eeprom->word_size = 4096;
3138 case EEPROM_SIZE_4KB:
3139 eeprom->word_size = 2048;
3141 case EEPROM_SIZE_2KB:
3142 eeprom->word_size = 1024;
3144 case EEPROM_SIZE_1KB:
3145 eeprom->word_size = 512;
3147 case EEPROM_SIZE_512B:
3148 eeprom->word_size = 256;
3150 case EEPROM_SIZE_128B:
3152 eeprom->word_size = 64;
3159 /******************************************************************************
3160 * Raises the EEPROM's clock input.
3162 * hw - Struct containing variables accessed by shared code
3163 * eecd - EECD's current value
3164 *****************************************************************************/
3166 e1000_raise_ee_clk(struct e1000_hw *hw,
3169 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3170 * wait <delay> microseconds.
3172 *eecd = *eecd | E1000_EECD_SK;
3173 E1000_WRITE_REG(hw, EECD, *eecd);
3174 E1000_WRITE_FLUSH(hw);
3175 udelay(hw->eeprom.delay_usec);
3178 /******************************************************************************
3179 * Lowers the EEPROM's clock input.
3181 * hw - Struct containing variables accessed by shared code
3182 * eecd - EECD's current value
3183 *****************************************************************************/
3185 e1000_lower_ee_clk(struct e1000_hw *hw,
3188 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3189 * wait 50 microseconds.
3191 *eecd = *eecd & ~E1000_EECD_SK;
3192 E1000_WRITE_REG(hw, EECD, *eecd);
3193 E1000_WRITE_FLUSH(hw);
3194 udelay(hw->eeprom.delay_usec);
3197 /******************************************************************************
3198 * Shift data bits out to the EEPROM.
3200 * hw - Struct containing variables accessed by shared code
3201 * data - data to send to the EEPROM
3202 * count - number of bits to shift out
3203 *****************************************************************************/
3205 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3209 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3213 /* We need to shift "count" bits out to the EEPROM. So, value in the
3214 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3215 * In order to do this, "data" must be broken down into bits.
3217 mask = 0x01 << (count - 1);
3218 eecd = E1000_READ_REG(hw, EECD);
3219 if (eeprom->type == e1000_eeprom_microwire) {
3220 eecd &= ~E1000_EECD_DO;
3221 } else if (eeprom->type == e1000_eeprom_spi) {
3222 eecd |= E1000_EECD_DO;
3225 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3226 * and then raising and then lowering the clock (the SK bit controls
3227 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3228 * by setting "DI" to "0" and then raising and then lowering the clock.
3230 eecd &= ~E1000_EECD_DI;
3233 eecd |= E1000_EECD_DI;
3235 E1000_WRITE_REG(hw, EECD, eecd);
3236 E1000_WRITE_FLUSH(hw);
3238 udelay(eeprom->delay_usec);
3240 e1000_raise_ee_clk(hw, &eecd);
3241 e1000_lower_ee_clk(hw, &eecd);
3247 /* We leave the "DI" bit set to "0" when we leave this routine. */
3248 eecd &= ~E1000_EECD_DI;
3249 E1000_WRITE_REG(hw, EECD, eecd);
3252 /******************************************************************************
3253 * Shift data bits in from the EEPROM
3255 * hw - Struct containing variables accessed by shared code
3256 *****************************************************************************/
3258 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3265 /* In order to read a register from the EEPROM, we need to shift 'count'
3266 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3267 * input to the EEPROM (setting the SK bit), and then reading the value of
3268 * the "DO" bit. During this "shifting in" process the "DI" bit should
3272 eecd = E1000_READ_REG(hw, EECD);
3274 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3277 for(i = 0; i < count; i++) {
3279 e1000_raise_ee_clk(hw, &eecd);
3281 eecd = E1000_READ_REG(hw, EECD);
3283 eecd &= ~(E1000_EECD_DI);
3284 if(eecd & E1000_EECD_DO)
3287 e1000_lower_ee_clk(hw, &eecd);
3293 /******************************************************************************
3294 * Prepares EEPROM for access
3296 * hw - Struct containing variables accessed by shared code
3298 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3299 * function should be called before issuing a command to the EEPROM.
3300 *****************************************************************************/
3302 e1000_acquire_eeprom(struct e1000_hw *hw)
3304 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3307 DEBUGFUNC("e1000_acquire_eeprom");
3309 eecd = E1000_READ_REG(hw, EECD);
3311 /* Request EEPROM Access */
3312 if(hw->mac_type > e1000_82544) {
3313 eecd |= E1000_EECD_REQ;
3314 E1000_WRITE_REG(hw, EECD, eecd);
3315 eecd = E1000_READ_REG(hw, EECD);
3316 while((!(eecd & E1000_EECD_GNT)) &&
3317 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3320 eecd = E1000_READ_REG(hw, EECD);
3322 if(!(eecd & E1000_EECD_GNT)) {
3323 eecd &= ~E1000_EECD_REQ;
3324 E1000_WRITE_REG(hw, EECD, eecd);
3325 DEBUGOUT("Could not acquire EEPROM grant\n");
3326 return -E1000_ERR_EEPROM;
3330 /* Setup EEPROM for Read/Write */
3332 if (eeprom->type == e1000_eeprom_microwire) {
3333 /* Clear SK and DI */
3334 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3335 E1000_WRITE_REG(hw, EECD, eecd);
3338 eecd |= E1000_EECD_CS;
3339 E1000_WRITE_REG(hw, EECD, eecd);
3340 } else if (eeprom->type == e1000_eeprom_spi) {
3341 /* Clear SK and CS */
3342 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3343 E1000_WRITE_REG(hw, EECD, eecd);
3347 return E1000_SUCCESS;
3350 /******************************************************************************
3351 * Returns EEPROM to a "standby" state
3353 * hw - Struct containing variables accessed by shared code
3354 *****************************************************************************/
3356 e1000_standby_eeprom(struct e1000_hw *hw)
3358 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3361 eecd = E1000_READ_REG(hw, EECD);
3363 if(eeprom->type == e1000_eeprom_microwire) {
3364 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3365 E1000_WRITE_REG(hw, EECD, eecd);
3366 E1000_WRITE_FLUSH(hw);
3367 udelay(eeprom->delay_usec);
3370 eecd |= E1000_EECD_SK;
3371 E1000_WRITE_REG(hw, EECD, eecd);
3372 E1000_WRITE_FLUSH(hw);
3373 udelay(eeprom->delay_usec);
3376 eecd |= E1000_EECD_CS;
3377 E1000_WRITE_REG(hw, EECD, eecd);
3378 E1000_WRITE_FLUSH(hw);
3379 udelay(eeprom->delay_usec);
3382 eecd &= ~E1000_EECD_SK;
3383 E1000_WRITE_REG(hw, EECD, eecd);
3384 E1000_WRITE_FLUSH(hw);
3385 udelay(eeprom->delay_usec);
3386 } else if(eeprom->type == e1000_eeprom_spi) {
3387 /* Toggle CS to flush commands */
3388 eecd |= E1000_EECD_CS;
3389 E1000_WRITE_REG(hw, EECD, eecd);
3390 E1000_WRITE_FLUSH(hw);
3391 udelay(eeprom->delay_usec);
3392 eecd &= ~E1000_EECD_CS;
3393 E1000_WRITE_REG(hw, EECD, eecd);
3394 E1000_WRITE_FLUSH(hw);
3395 udelay(eeprom->delay_usec);
3399 /******************************************************************************
3400 * Terminates a command by inverting the EEPROM's chip select pin
3402 * hw - Struct containing variables accessed by shared code
3403 *****************************************************************************/
3405 e1000_release_eeprom(struct e1000_hw *hw)
3409 DEBUGFUNC("e1000_release_eeprom");
3411 eecd = E1000_READ_REG(hw, EECD);
3413 if (hw->eeprom.type == e1000_eeprom_spi) {
3414 eecd |= E1000_EECD_CS; /* Pull CS high */
3415 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3417 E1000_WRITE_REG(hw, EECD, eecd);
3419 udelay(hw->eeprom.delay_usec);
3420 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3421 /* cleanup eeprom */
3423 /* CS on Microwire is active-high */
3424 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3426 E1000_WRITE_REG(hw, EECD, eecd);
3428 /* Rising edge of clock */
3429 eecd |= E1000_EECD_SK;
3430 E1000_WRITE_REG(hw, EECD, eecd);
3431 E1000_WRITE_FLUSH(hw);
3432 udelay(hw->eeprom.delay_usec);
3434 /* Falling edge of clock */
3435 eecd &= ~E1000_EECD_SK;
3436 E1000_WRITE_REG(hw, EECD, eecd);
3437 E1000_WRITE_FLUSH(hw);
3438 udelay(hw->eeprom.delay_usec);
3441 /* Stop requesting EEPROM access */
3442 if(hw->mac_type > e1000_82544) {
3443 eecd &= ~E1000_EECD_REQ;
3444 E1000_WRITE_REG(hw, EECD, eecd);
3448 /******************************************************************************
3449 * Reads a 16 bit word from the EEPROM.
3451 * hw - Struct containing variables accessed by shared code
3452 *****************************************************************************/
3454 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3456 uint16_t retry_count = 0;
3457 uint8_t spi_stat_reg;
3459 DEBUGFUNC("e1000_spi_eeprom_ready");
3461 /* Read "Status Register" repeatedly until the LSB is cleared. The
3462 * EEPROM will signal that the command has been completed by clearing
3463 * bit 0 of the internal status register. If it's not cleared within
3464 * 5 milliseconds, then error out.
3468 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3469 hw->eeprom.opcode_bits);
3470 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3471 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3477 e1000_standby_eeprom(hw);
3478 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3480 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3481 * only 0-5mSec on 5V devices)
3483 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3484 DEBUGOUT("SPI EEPROM Status error\n");
3485 return -E1000_ERR_EEPROM;
3488 return E1000_SUCCESS;
3491 /******************************************************************************
3492 * Reads a 16 bit word from the EEPROM.
3494 * hw - Struct containing variables accessed by shared code
3495 * offset - offset of word in the EEPROM to read
3496 * data - word read from the EEPROM
3497 * words - number of words to read
3498 *****************************************************************************/
3500 e1000_read_eeprom(struct e1000_hw *hw,
3505 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3508 DEBUGFUNC("e1000_read_eeprom");
3509 /* A check for invalid values: offset too large, too many words, and not
3512 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3514 DEBUGOUT("\"words\" parameter out of bounds\n");
3515 return -E1000_ERR_EEPROM;
3518 /* Prepare the EEPROM for reading */
3519 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3520 return -E1000_ERR_EEPROM;
3522 if(eeprom->type == e1000_eeprom_spi) {
3524 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3526 if(e1000_spi_eeprom_ready(hw)) {
3527 e1000_release_eeprom(hw);
3528 return -E1000_ERR_EEPROM;
3531 e1000_standby_eeprom(hw);
3533 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3534 if((eeprom->address_bits == 8) && (offset >= 128))
3535 read_opcode |= EEPROM_A8_OPCODE_SPI;
3537 /* Send the READ command (opcode + addr) */
3538 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3539 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3541 /* Read the data. The address of the eeprom internally increments with
3542 * each byte (spi) being read, saving on the overhead of eeprom setup
3543 * and tear-down. The address counter will roll over if reading beyond
3544 * the size of the eeprom, thus allowing the entire memory to be read
3545 * starting from any offset. */
3546 for (i = 0; i < words; i++) {
3547 word_in = e1000_shift_in_ee_bits(hw, 16);
3548 data[i] = (word_in >> 8) | (word_in << 8);
3550 } else if(eeprom->type == e1000_eeprom_microwire) {
3551 for (i = 0; i < words; i++) {
3552 /* Send the READ command (opcode + addr) */
3553 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3554 eeprom->opcode_bits);
3555 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3556 eeprom->address_bits);
3558 /* Read the data. For microwire, each word requires the overhead
3559 * of eeprom setup and tear-down. */
3560 data[i] = e1000_shift_in_ee_bits(hw, 16);
3561 e1000_standby_eeprom(hw);
3565 /* End this read operation */
3566 e1000_release_eeprom(hw);
3568 return E1000_SUCCESS;
3571 /******************************************************************************
3572 * Verifies that the EEPROM has a valid checksum
3574 * hw - Struct containing variables accessed by shared code
3576 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3577 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3579 *****************************************************************************/
3581 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3583 uint16_t checksum = 0;
3584 uint16_t i, eeprom_data;
3586 DEBUGFUNC("e1000_validate_eeprom_checksum");
3588 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3589 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3590 DEBUGOUT("EEPROM Read Error\n");
3591 return -E1000_ERR_EEPROM;
3593 checksum += eeprom_data;
3596 if(checksum == (uint16_t) EEPROM_SUM)
3597 return E1000_SUCCESS;
3599 DEBUGOUT("EEPROM Checksum Invalid\n");
3600 return -E1000_ERR_EEPROM;
3604 /******************************************************************************
3605 * Calculates the EEPROM checksum and writes it to the EEPROM
3607 * hw - Struct containing variables accessed by shared code
3609 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3610 * Writes the difference to word offset 63 of the EEPROM.
3611 *****************************************************************************/
3613 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3615 uint16_t checksum = 0;
3616 uint16_t i, eeprom_data;
3618 DEBUGFUNC("e1000_update_eeprom_checksum");
3620 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3621 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3622 DEBUGOUT("EEPROM Read Error\n");
3623 return -E1000_ERR_EEPROM;
3625 checksum += eeprom_data;
3627 checksum = (uint16_t) EEPROM_SUM - checksum;
3628 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3629 DEBUGOUT("EEPROM Write Error\n");
3630 return -E1000_ERR_EEPROM;
3632 return E1000_SUCCESS;
3635 /******************************************************************************
3636 * Parent function for writing words to the different EEPROM types.
3638 * hw - Struct containing variables accessed by shared code
3639 * offset - offset within the EEPROM to be written to
3640 * words - number of words to write
3641 * data - 16 bit word to be written to the EEPROM
3643 * If e1000_update_eeprom_checksum is not called after this function, the
3644 * EEPROM will most likely contain an invalid checksum.
3645 *****************************************************************************/
3647 e1000_write_eeprom(struct e1000_hw *hw,
3652 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3655 DEBUGFUNC("e1000_write_eeprom");
3657 /* A check for invalid values: offset too large, too many words, and not
3660 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3662 DEBUGOUT("\"words\" parameter out of bounds\n");
3663 return -E1000_ERR_EEPROM;
3666 /* Prepare the EEPROM for writing */
3667 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3668 return -E1000_ERR_EEPROM;
3670 if(eeprom->type == e1000_eeprom_microwire) {
3671 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3673 status = e1000_write_eeprom_spi(hw, offset, words, data);
3677 /* Done with writing */
3678 e1000_release_eeprom(hw);
3683 /******************************************************************************
3684 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3686 * hw - Struct containing variables accessed by shared code
3687 * offset - offset within the EEPROM to be written to
3688 * words - number of words to write
3689 * data - pointer to array of 8 bit words to be written to the EEPROM
3691 *****************************************************************************/
3693 e1000_write_eeprom_spi(struct e1000_hw *hw,
3698 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3701 DEBUGFUNC("e1000_write_eeprom_spi");
3703 while (widx < words) {
3704 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
3706 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3708 e1000_standby_eeprom(hw);
3710 /* Send the WRITE ENABLE command (8 bit opcode ) */
3711 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3712 eeprom->opcode_bits);
3714 e1000_standby_eeprom(hw);
3716 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3717 if((eeprom->address_bits == 8) && (offset >= 128))
3718 write_opcode |= EEPROM_A8_OPCODE_SPI;
3720 /* Send the Write command (8-bit opcode + addr) */
3721 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3723 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
3724 eeprom->address_bits);
3728 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3729 while (widx < words) {
3730 uint16_t word_out = data[widx];
3731 word_out = (word_out >> 8) | (word_out << 8);
3732 e1000_shift_out_ee_bits(hw, word_out, 16);
3735 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3736 * operation, while the smaller eeproms are capable of an 8-byte
3737 * PAGE WRITE operation. Break the inner loop to pass new address
3739 if((((offset + widx)*2) % eeprom->page_size) == 0) {
3740 e1000_standby_eeprom(hw);
3746 return E1000_SUCCESS;
3749 /******************************************************************************
3750 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3752 * hw - Struct containing variables accessed by shared code
3753 * offset - offset within the EEPROM to be written to
3754 * words - number of words to write
3755 * data - pointer to array of 16 bit words to be written to the EEPROM
3757 *****************************************************************************/
3759 e1000_write_eeprom_microwire(struct e1000_hw *hw,
3764 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3766 uint16_t words_written = 0;
3769 DEBUGFUNC("e1000_write_eeprom_microwire");
3771 /* Send the write enable command to the EEPROM (3-bit opcode plus
3772 * 6/8-bit dummy address beginning with 11). It's less work to include
3773 * the 11 of the dummy address as part of the opcode than it is to shift
3774 * it over the correct number of bits for the address. This puts the
3775 * EEPROM into write/erase mode.
3777 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
3778 (uint16_t)(eeprom->opcode_bits + 2));
3780 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3782 /* Prepare the EEPROM */
3783 e1000_standby_eeprom(hw);
3785 while (words_written < words) {
3786 /* Send the Write command (3-bit opcode + addr) */
3787 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
3788 eeprom->opcode_bits);
3790 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
3791 eeprom->address_bits);
3794 e1000_shift_out_ee_bits(hw, data[words_written], 16);
3796 /* Toggle the CS line. This in effect tells the EEPROM to execute
3797 * the previous command.
3799 e1000_standby_eeprom(hw);
3801 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
3802 * signal that the command has been completed by raising the DO signal.
3803 * If DO does not go high in 10 milliseconds, then error out.
3805 for(i = 0; i < 200; i++) {
3806 eecd = E1000_READ_REG(hw, EECD);
3807 if(eecd & E1000_EECD_DO) break;
3811 DEBUGOUT("EEPROM Write did not complete\n");
3812 return -E1000_ERR_EEPROM;
3815 /* Recover from write */
3816 e1000_standby_eeprom(hw);
3821 /* Send the write disable command to the EEPROM (3-bit opcode plus
3822 * 6/8-bit dummy address beginning with 10). It's less work to include
3823 * the 10 of the dummy address as part of the opcode than it is to shift
3824 * it over the correct number of bits for the address. This takes the
3825 * EEPROM out of write/erase mode.
3827 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
3828 (uint16_t)(eeprom->opcode_bits + 2));
3830 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3832 return E1000_SUCCESS;
3835 /******************************************************************************
3836 * Reads the adapter's part number from the EEPROM
3838 * hw - Struct containing variables accessed by shared code
3839 * part_num - Adapter's part number
3840 *****************************************************************************/
3842 e1000_read_part_num(struct e1000_hw *hw,
3845 uint16_t offset = EEPROM_PBA_BYTE_1;
3846 uint16_t eeprom_data;
3848 DEBUGFUNC("e1000_read_part_num");
3850 /* Get word 0 from EEPROM */
3851 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3852 DEBUGOUT("EEPROM Read Error\n");
3853 return -E1000_ERR_EEPROM;
3855 /* Save word 0 in upper half of part_num */
3856 *part_num = (uint32_t) (eeprom_data << 16);
3858 /* Get word 1 from EEPROM */
3859 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
3860 DEBUGOUT("EEPROM Read Error\n");
3861 return -E1000_ERR_EEPROM;
3863 /* Save word 1 in lower half of part_num */
3864 *part_num |= eeprom_data;
3866 return E1000_SUCCESS;
3869 /******************************************************************************
3870 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3871 * second function of dual function devices
3873 * hw - Struct containing variables accessed by shared code
3874 *****************************************************************************/
3876 e1000_read_mac_addr(struct e1000_hw * hw)
3879 uint16_t eeprom_data, i;
3881 DEBUGFUNC("e1000_read_mac_addr");
3883 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
3885 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3886 DEBUGOUT("EEPROM Read Error\n");
3887 return -E1000_ERR_EEPROM;
3889 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
3890 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
3892 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
3893 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
3894 hw->perm_mac_addr[5] ^= 0x01;
3896 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
3897 hw->mac_addr[i] = hw->perm_mac_addr[i];
3898 return E1000_SUCCESS;
3901 /******************************************************************************
3902 * Initializes receive address filters.
3904 * hw - Struct containing variables accessed by shared code
3906 * Places the MAC address in receive address register 0 and clears the rest
3907 * of the receive addresss registers. Clears the multicast table. Assumes
3908 * the receiver is in reset when the routine is called.
3909 *****************************************************************************/
3911 e1000_init_rx_addrs(struct e1000_hw *hw)
3915 DEBUGFUNC("e1000_init_rx_addrs");
3917 /* Setup the receive address. */
3918 DEBUGOUT("Programming MAC Address into RAR[0]\n");
3920 e1000_rar_set(hw, hw->mac_addr, 0);
3922 /* Zero out the other 15 receive addresses. */
3923 DEBUGOUT("Clearing RAR[1-15]\n");
3924 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
3925 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3926 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3930 /******************************************************************************
3931 * Updates the MAC's list of multicast addresses.
3933 * hw - Struct containing variables accessed by shared code
3934 * mc_addr_list - the list of new multicast addresses
3935 * mc_addr_count - number of addresses
3936 * pad - number of bytes between addresses in the list
3937 * rar_used_count - offset where to start adding mc addresses into the RAR's
3939 * The given list replaces any existing list. Clears the last 15 receive
3940 * address registers and the multicast table. Uses receive address registers
3941 * for the first 15 multicast addresses, and hashes the rest into the
3943 *****************************************************************************/
3945 e1000_mc_addr_list_update(struct e1000_hw *hw,
3946 uint8_t *mc_addr_list,
3947 uint32_t mc_addr_count,
3949 uint32_t rar_used_count)
3951 uint32_t hash_value;
3954 DEBUGFUNC("e1000_mc_addr_list_update");
3956 /* Set the new number of MC addresses that we are being requested to use. */
3957 hw->num_mc_addrs = mc_addr_count;
3959 /* Clear RAR[1-15] */
3960 DEBUGOUT(" Clearing RAR[1-15]\n");
3961 for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
3962 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3963 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3967 DEBUGOUT(" Clearing MTA\n");
3968 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
3969 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
3972 /* Add the new addresses */
3973 for(i = 0; i < mc_addr_count; i++) {
3974 DEBUGOUT(" Adding the multicast addresses:\n");
3975 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
3976 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
3977 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
3978 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
3979 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
3980 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
3981 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
3983 hash_value = e1000_hash_mc_addr(hw,
3985 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
3987 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
3989 /* Place this multicast address in the RAR if there is room, *
3990 * else put it in the MTA
3992 if(rar_used_count < E1000_RAR_ENTRIES) {
3994 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
3998 e1000_mta_set(hw, hash_value);
4001 DEBUGOUT("MC Update Complete\n");
4004 /******************************************************************************
4005 * Hashes an address to determine its location in the multicast table
4007 * hw - Struct containing variables accessed by shared code
4008 * mc_addr - the multicast address to hash
4009 *****************************************************************************/
4011 e1000_hash_mc_addr(struct e1000_hw *hw,
4014 uint32_t hash_value = 0;
4016 /* The portion of the address that is used for the hash table is
4017 * determined by the mc_filter_type setting.
4019 switch (hw->mc_filter_type) {
4020 /* [0] [1] [2] [3] [4] [5]
4025 /* [47:36] i.e. 0x563 for above example address */
4026 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
4029 /* [46:35] i.e. 0xAC6 for above example address */
4030 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4033 /* [45:34] i.e. 0x5D8 for above example address */
4034 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4037 /* [43:32] i.e. 0x634 for above example address */
4038 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4042 hash_value &= 0xFFF;
4046 /******************************************************************************
4047 * Sets the bit in the multicast table corresponding to the hash value.
4049 * hw - Struct containing variables accessed by shared code
4050 * hash_value - Multicast address hash value
4051 *****************************************************************************/
4053 e1000_mta_set(struct e1000_hw *hw,
4054 uint32_t hash_value)
4056 uint32_t hash_bit, hash_reg;
4060 /* The MTA is a register array of 128 32-bit registers.
4061 * It is treated like an array of 4096 bits. We want to set
4062 * bit BitArray[hash_value]. So we figure out what register
4063 * the bit is in, read it, OR in the new bit, then write
4064 * back the new value. The register is determined by the
4065 * upper 7 bits of the hash value and the bit within that
4066 * register are determined by the lower 5 bits of the value.
4068 hash_reg = (hash_value >> 5) & 0x7F;
4069 hash_bit = hash_value & 0x1F;
4071 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4073 mta |= (1 << hash_bit);
4075 /* If we are on an 82544 and we are trying to write an odd offset
4076 * in the MTA, save off the previous entry before writing and
4077 * restore the old value after writing.
4079 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4080 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4081 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4082 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4084 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4088 /******************************************************************************
4089 * Puts an ethernet address into a receive address register.
4091 * hw - Struct containing variables accessed by shared code
4092 * addr - Address to put into receive address register
4093 * index - Receive address register to write
4094 *****************************************************************************/
4096 e1000_rar_set(struct e1000_hw *hw,
4100 uint32_t rar_low, rar_high;
4102 /* HW expects these in little endian so we reverse the byte order
4103 * from network order (big endian) to little endian
4105 rar_low = ((uint32_t) addr[0] |
4106 ((uint32_t) addr[1] << 8) |
4107 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4109 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4111 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4112 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4115 /******************************************************************************
4116 * Writes a value to the specified offset in the VLAN filter table.
4118 * hw - Struct containing variables accessed by shared code
4119 * offset - Offset in VLAN filer table to write
4120 * value - Value to write into VLAN filter table
4121 *****************************************************************************/
4123 e1000_write_vfta(struct e1000_hw *hw,
4129 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4130 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4131 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4132 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4134 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4138 /******************************************************************************
4139 * Clears the VLAN filer table
4141 * hw - Struct containing variables accessed by shared code
4142 *****************************************************************************/
4144 e1000_clear_vfta(struct e1000_hw *hw)
4148 for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
4149 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
4153 e1000_id_led_init(struct e1000_hw * hw)
4156 const uint32_t ledctl_mask = 0x000000FF;
4157 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4158 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4159 uint16_t eeprom_data, i, temp;
4160 const uint16_t led_mask = 0x0F;
4162 DEBUGFUNC("e1000_id_led_init");
4164 if(hw->mac_type < e1000_82540) {
4166 return E1000_SUCCESS;
4169 ledctl = E1000_READ_REG(hw, LEDCTL);
4170 hw->ledctl_default = ledctl;
4171 hw->ledctl_mode1 = hw->ledctl_default;
4172 hw->ledctl_mode2 = hw->ledctl_default;
4174 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4175 DEBUGOUT("EEPROM Read Error\n");
4176 return -E1000_ERR_EEPROM;
4178 if((eeprom_data== ID_LED_RESERVED_0000) ||
4179 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4180 for(i = 0; i < 4; i++) {
4181 temp = (eeprom_data >> (i << 2)) & led_mask;
4183 case ID_LED_ON1_DEF2:
4184 case ID_LED_ON1_ON2:
4185 case ID_LED_ON1_OFF2:
4186 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4187 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4189 case ID_LED_OFF1_DEF2:
4190 case ID_LED_OFF1_ON2:
4191 case ID_LED_OFF1_OFF2:
4192 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4193 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4200 case ID_LED_DEF1_ON2:
4201 case ID_LED_ON1_ON2:
4202 case ID_LED_OFF1_ON2:
4203 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4204 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4206 case ID_LED_DEF1_OFF2:
4207 case ID_LED_ON1_OFF2:
4208 case ID_LED_OFF1_OFF2:
4209 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4210 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4217 return E1000_SUCCESS;
4220 /******************************************************************************
4221 * Prepares SW controlable LED for use and saves the current state of the LED.
4223 * hw - Struct containing variables accessed by shared code
4224 *****************************************************************************/
4226 e1000_setup_led(struct e1000_hw *hw)
4229 int32_t ret_val = E1000_SUCCESS;
4231 DEBUGFUNC("e1000_setup_led");
4233 switch(hw->mac_type) {
4234 case e1000_82542_rev2_0:
4235 case e1000_82542_rev2_1:
4238 /* No setup necessary */
4242 case e1000_82541_rev_2:
4243 case e1000_82547_rev_2:
4244 /* Turn off PHY Smart Power Down (if enabled) */
4245 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4246 &hw->phy_spd_default);
4249 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4250 (uint16_t)(hw->phy_spd_default &
4251 ~IGP01E1000_GMII_SPD));
4256 if(hw->media_type == e1000_media_type_fiber) {
4257 ledctl = E1000_READ_REG(hw, LEDCTL);
4258 /* Save current LEDCTL settings */
4259 hw->ledctl_default = ledctl;
4261 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4262 E1000_LEDCTL_LED0_BLINK |
4263 E1000_LEDCTL_LED0_MODE_MASK);
4264 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4265 E1000_LEDCTL_LED0_MODE_SHIFT);
4266 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4267 } else if(hw->media_type == e1000_media_type_copper)
4268 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4272 return E1000_SUCCESS;
4275 /******************************************************************************
4276 * Restores the saved state of the SW controlable LED.
4278 * hw - Struct containing variables accessed by shared code
4279 *****************************************************************************/
4281 e1000_cleanup_led(struct e1000_hw *hw)
4283 int32_t ret_val = E1000_SUCCESS;
4285 DEBUGFUNC("e1000_cleanup_led");
4287 switch(hw->mac_type) {
4288 case e1000_82542_rev2_0:
4289 case e1000_82542_rev2_1:
4292 /* No cleanup necessary */
4296 case e1000_82541_rev_2:
4297 case e1000_82547_rev_2:
4298 /* Turn on PHY Smart Power Down (if previously enabled) */
4299 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4300 hw->phy_spd_default);
4305 /* Restore LEDCTL settings */
4306 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4310 return E1000_SUCCESS;
4313 /******************************************************************************
4314 * Turns on the software controllable LED
4316 * hw - Struct containing variables accessed by shared code
4317 *****************************************************************************/
4319 e1000_led_on(struct e1000_hw *hw)
4321 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4323 DEBUGFUNC("e1000_led_on");
4325 switch(hw->mac_type) {
4326 case e1000_82542_rev2_0:
4327 case e1000_82542_rev2_1:
4329 /* Set SW Defineable Pin 0 to turn on the LED */
4330 ctrl |= E1000_CTRL_SWDPIN0;
4331 ctrl |= E1000_CTRL_SWDPIO0;
4334 if(hw->media_type == e1000_media_type_fiber) {
4335 /* Set SW Defineable Pin 0 to turn on the LED */
4336 ctrl |= E1000_CTRL_SWDPIN0;
4337 ctrl |= E1000_CTRL_SWDPIO0;
4339 /* Clear SW Defineable Pin 0 to turn on the LED */
4340 ctrl &= ~E1000_CTRL_SWDPIN0;
4341 ctrl |= E1000_CTRL_SWDPIO0;
4345 if(hw->media_type == e1000_media_type_fiber) {
4346 /* Clear SW Defineable Pin 0 to turn on the LED */
4347 ctrl &= ~E1000_CTRL_SWDPIN0;
4348 ctrl |= E1000_CTRL_SWDPIO0;
4349 } else if(hw->media_type == e1000_media_type_copper) {
4350 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4351 return E1000_SUCCESS;
4356 E1000_WRITE_REG(hw, CTRL, ctrl);
4358 return E1000_SUCCESS;
4361 /******************************************************************************
4362 * Turns off the software controllable LED
4364 * hw - Struct containing variables accessed by shared code
4365 *****************************************************************************/
4367 e1000_led_off(struct e1000_hw *hw)
4369 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4371 DEBUGFUNC("e1000_led_off");
4373 switch(hw->mac_type) {
4374 case e1000_82542_rev2_0:
4375 case e1000_82542_rev2_1:
4377 /* Clear SW Defineable Pin 0 to turn off the LED */
4378 ctrl &= ~E1000_CTRL_SWDPIN0;
4379 ctrl |= E1000_CTRL_SWDPIO0;
4382 if(hw->media_type == e1000_media_type_fiber) {
4383 /* Clear SW Defineable Pin 0 to turn off the LED */
4384 ctrl &= ~E1000_CTRL_SWDPIN0;
4385 ctrl |= E1000_CTRL_SWDPIO0;
4387 /* Set SW Defineable Pin 0 to turn off the LED */
4388 ctrl |= E1000_CTRL_SWDPIN0;
4389 ctrl |= E1000_CTRL_SWDPIO0;
4393 if(hw->media_type == e1000_media_type_fiber) {
4394 /* Set SW Defineable Pin 0 to turn off the LED */
4395 ctrl |= E1000_CTRL_SWDPIN0;
4396 ctrl |= E1000_CTRL_SWDPIO0;
4397 } else if(hw->media_type == e1000_media_type_copper) {
4398 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4399 return E1000_SUCCESS;
4404 E1000_WRITE_REG(hw, CTRL, ctrl);
4406 return E1000_SUCCESS;
4409 /******************************************************************************
4410 * Clears all hardware statistics counters.
4412 * hw - Struct containing variables accessed by shared code
4413 *****************************************************************************/
4415 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4417 volatile uint32_t temp;
4419 temp = E1000_READ_REG(hw, CRCERRS);
4420 temp = E1000_READ_REG(hw, SYMERRS);
4421 temp = E1000_READ_REG(hw, MPC);
4422 temp = E1000_READ_REG(hw, SCC);
4423 temp = E1000_READ_REG(hw, ECOL);
4424 temp = E1000_READ_REG(hw, MCC);
4425 temp = E1000_READ_REG(hw, LATECOL);
4426 temp = E1000_READ_REG(hw, COLC);
4427 temp = E1000_READ_REG(hw, DC);
4428 temp = E1000_READ_REG(hw, SEC);
4429 temp = E1000_READ_REG(hw, RLEC);
4430 temp = E1000_READ_REG(hw, XONRXC);
4431 temp = E1000_READ_REG(hw, XONTXC);
4432 temp = E1000_READ_REG(hw, XOFFRXC);
4433 temp = E1000_READ_REG(hw, XOFFTXC);
4434 temp = E1000_READ_REG(hw, FCRUC);
4435 temp = E1000_READ_REG(hw, PRC64);
4436 temp = E1000_READ_REG(hw, PRC127);
4437 temp = E1000_READ_REG(hw, PRC255);
4438 temp = E1000_READ_REG(hw, PRC511);
4439 temp = E1000_READ_REG(hw, PRC1023);
4440 temp = E1000_READ_REG(hw, PRC1522);
4441 temp = E1000_READ_REG(hw, GPRC);
4442 temp = E1000_READ_REG(hw, BPRC);
4443 temp = E1000_READ_REG(hw, MPRC);
4444 temp = E1000_READ_REG(hw, GPTC);
4445 temp = E1000_READ_REG(hw, GORCL);
4446 temp = E1000_READ_REG(hw, GORCH);
4447 temp = E1000_READ_REG(hw, GOTCL);
4448 temp = E1000_READ_REG(hw, GOTCH);
4449 temp = E1000_READ_REG(hw, RNBC);
4450 temp = E1000_READ_REG(hw, RUC);
4451 temp = E1000_READ_REG(hw, RFC);
4452 temp = E1000_READ_REG(hw, ROC);
4453 temp = E1000_READ_REG(hw, RJC);
4454 temp = E1000_READ_REG(hw, TORL);
4455 temp = E1000_READ_REG(hw, TORH);
4456 temp = E1000_READ_REG(hw, TOTL);
4457 temp = E1000_READ_REG(hw, TOTH);
4458 temp = E1000_READ_REG(hw, TPR);
4459 temp = E1000_READ_REG(hw, TPT);
4460 temp = E1000_READ_REG(hw, PTC64);
4461 temp = E1000_READ_REG(hw, PTC127);
4462 temp = E1000_READ_REG(hw, PTC255);
4463 temp = E1000_READ_REG(hw, PTC511);
4464 temp = E1000_READ_REG(hw, PTC1023);
4465 temp = E1000_READ_REG(hw, PTC1522);
4466 temp = E1000_READ_REG(hw, MPTC);
4467 temp = E1000_READ_REG(hw, BPTC);
4469 if(hw->mac_type < e1000_82543) return;
4471 temp = E1000_READ_REG(hw, ALGNERRC);
4472 temp = E1000_READ_REG(hw, RXERRC);
4473 temp = E1000_READ_REG(hw, TNCRS);
4474 temp = E1000_READ_REG(hw, CEXTERR);
4475 temp = E1000_READ_REG(hw, TSCTC);
4476 temp = E1000_READ_REG(hw, TSCTFC);
4478 if(hw->mac_type <= e1000_82544) return;
4480 temp = E1000_READ_REG(hw, MGTPRC);
4481 temp = E1000_READ_REG(hw, MGTPDC);
4482 temp = E1000_READ_REG(hw, MGTPTC);
4485 /******************************************************************************
4486 * Resets Adaptive IFS to its default state.
4488 * hw - Struct containing variables accessed by shared code
4490 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4491 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4492 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4493 * before calling this function.
4494 *****************************************************************************/
4496 e1000_reset_adaptive(struct e1000_hw *hw)
4498 DEBUGFUNC("e1000_reset_adaptive");
4500 if(hw->adaptive_ifs) {
4501 if(!hw->ifs_params_forced) {
4502 hw->current_ifs_val = 0;
4503 hw->ifs_min_val = IFS_MIN;
4504 hw->ifs_max_val = IFS_MAX;
4505 hw->ifs_step_size = IFS_STEP;
4506 hw->ifs_ratio = IFS_RATIO;
4508 hw->in_ifs_mode = FALSE;
4509 E1000_WRITE_REG(hw, AIT, 0);
4511 DEBUGOUT("Not in Adaptive IFS mode!\n");
4515 /******************************************************************************
4516 * Called during the callback/watchdog routine to update IFS value based on
4517 * the ratio of transmits to collisions.
4519 * hw - Struct containing variables accessed by shared code
4520 * tx_packets - Number of transmits since last callback
4521 * total_collisions - Number of collisions since last callback
4522 *****************************************************************************/
4524 e1000_update_adaptive(struct e1000_hw *hw)
4526 DEBUGFUNC("e1000_update_adaptive");
4528 if(hw->adaptive_ifs) {
4529 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4530 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
4531 hw->in_ifs_mode = TRUE;
4532 if(hw->current_ifs_val < hw->ifs_max_val) {
4533 if(hw->current_ifs_val == 0)
4534 hw->current_ifs_val = hw->ifs_min_val;
4536 hw->current_ifs_val += hw->ifs_step_size;
4537 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
4541 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4542 hw->current_ifs_val = 0;
4543 hw->in_ifs_mode = FALSE;
4544 E1000_WRITE_REG(hw, AIT, 0);
4548 DEBUGOUT("Not in Adaptive IFS mode!\n");
4552 /******************************************************************************
4553 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4555 * hw - Struct containing variables accessed by shared code
4556 * frame_len - The length of the frame in question
4557 * mac_addr - The Ethernet destination address of the frame in question
4558 *****************************************************************************/
4560 e1000_tbi_adjust_stats(struct e1000_hw *hw,
4561 struct e1000_hw_stats *stats,
4567 /* First adjust the frame length. */
4569 /* We need to adjust the statistics counters, since the hardware
4570 * counters overcount this packet as a CRC error and undercount
4571 * the packet as a good packet
4573 /* This packet should not be counted as a CRC error. */
4575 /* This packet does count as a Good Packet Received. */
4578 /* Adjust the Good Octets received counters */
4579 carry_bit = 0x80000000 & stats->gorcl;
4580 stats->gorcl += frame_len;
4581 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4582 * Received Count) was one before the addition,
4583 * AND it is zero after, then we lost the carry out,
4584 * need to add one to Gorch (Good Octets Received Count High).
4585 * This could be simplified if all environments supported
4588 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
4590 /* Is this a broadcast or multicast? Check broadcast first,
4591 * since the test for a multicast frame will test positive on
4592 * a broadcast frame.
4594 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
4595 /* Broadcast packet */
4597 else if(*mac_addr & 0x01)
4598 /* Multicast packet */
4601 if(frame_len == hw->max_frame_size) {
4602 /* In this case, the hardware has overcounted the number of
4609 /* Adjust the bin counters when the extra byte put the frame in the
4610 * wrong bin. Remember that the frame_len was adjusted above.
4612 if(frame_len == 64) {
4615 } else if(frame_len == 127) {
4618 } else if(frame_len == 255) {
4621 } else if(frame_len == 511) {
4624 } else if(frame_len == 1023) {
4627 } else if(frame_len == 1522) {
4632 /******************************************************************************
4633 * Gets the current PCI bus type, speed, and width of the hardware
4635 * hw - Struct containing variables accessed by shared code
4636 *****************************************************************************/
4638 e1000_get_bus_info(struct e1000_hw *hw)
4642 if(hw->mac_type < e1000_82543) {
4643 hw->bus_type = e1000_bus_type_unknown;
4644 hw->bus_speed = e1000_bus_speed_unknown;
4645 hw->bus_width = e1000_bus_width_unknown;
4649 status = E1000_READ_REG(hw, STATUS);
4650 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4651 e1000_bus_type_pcix : e1000_bus_type_pci;
4653 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4654 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4655 e1000_bus_speed_66 : e1000_bus_speed_120;
4656 } else if(hw->bus_type == e1000_bus_type_pci) {
4657 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4658 e1000_bus_speed_66 : e1000_bus_speed_33;
4660 switch (status & E1000_STATUS_PCIX_SPEED) {
4661 case E1000_STATUS_PCIX_SPEED_66:
4662 hw->bus_speed = e1000_bus_speed_66;
4664 case E1000_STATUS_PCIX_SPEED_100:
4665 hw->bus_speed = e1000_bus_speed_100;
4667 case E1000_STATUS_PCIX_SPEED_133:
4668 hw->bus_speed = e1000_bus_speed_133;
4671 hw->bus_speed = e1000_bus_speed_reserved;
4675 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4676 e1000_bus_width_64 : e1000_bus_width_32;
4678 /******************************************************************************
4679 * Reads a value from one of the devices registers using port I/O (as opposed
4680 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4682 * hw - Struct containing variables accessed by shared code
4683 * offset - offset to read from
4684 *****************************************************************************/
4686 e1000_read_reg_io(struct e1000_hw *hw,
4689 unsigned long io_addr = hw->io_base;
4690 unsigned long io_data = hw->io_base + 4;
4692 e1000_io_write(hw, io_addr, offset);
4693 return e1000_io_read(hw, io_data);
4696 /******************************************************************************
4697 * Writes a value to one of the devices registers using port I/O (as opposed to
4698 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4700 * hw - Struct containing variables accessed by shared code
4701 * offset - offset to write to
4702 * value - value to write
4703 *****************************************************************************/
4705 e1000_write_reg_io(struct e1000_hw *hw,
4709 unsigned long io_addr = hw->io_base;
4710 unsigned long io_data = hw->io_base + 4;
4712 e1000_io_write(hw, io_addr, offset);
4713 e1000_io_write(hw, io_data, value);
4717 /******************************************************************************
4718 * Estimates the cable length.
4720 * hw - Struct containing variables accessed by shared code
4721 * min_length - The estimated minimum length
4722 * max_length - The estimated maximum length
4724 * returns: - E1000_ERR_XXX
4727 * This function always returns a ranged length (minimum & maximum).
4728 * So for M88 phy's, this function interprets the one value returned from the
4729 * register to the minimum and maximum range.
4730 * For IGP phy's, the function calculates the range by the AGC registers.
4731 *****************************************************************************/
4733 e1000_get_cable_length(struct e1000_hw *hw,
4734 uint16_t *min_length,
4735 uint16_t *max_length)
4738 uint16_t agc_value = 0;
4739 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4740 uint16_t i, phy_data;
4742 DEBUGFUNC("e1000_get_cable_length");
4744 *min_length = *max_length = 0;
4746 /* Use old method for Phy older than IGP */
4747 if(hw->phy_type == e1000_phy_m88) {
4748 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4753 /* Convert the enum value to ranged values */
4754 switch((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4755 M88E1000_PSSR_CABLE_LENGTH_SHIFT) {
4756 case e1000_cable_length_50:
4758 *max_length = e1000_igp_cable_length_50;
4760 case e1000_cable_length_50_80:
4761 *min_length = e1000_igp_cable_length_50;
4762 *max_length = e1000_igp_cable_length_80;
4764 case e1000_cable_length_80_110:
4765 *min_length = e1000_igp_cable_length_80;
4766 *max_length = e1000_igp_cable_length_110;
4768 case e1000_cable_length_110_140:
4769 *min_length = e1000_igp_cable_length_110;
4770 *max_length = e1000_igp_cable_length_140;
4772 case e1000_cable_length_140:
4773 *min_length = e1000_igp_cable_length_140;
4774 *max_length = e1000_igp_cable_length_170;
4777 return -E1000_ERR_PHY;
4780 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4781 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4782 {IGP01E1000_PHY_AGC_A,
4783 IGP01E1000_PHY_AGC_B,
4784 IGP01E1000_PHY_AGC_C,
4785 IGP01E1000_PHY_AGC_D};
4786 /* Read the AGC registers for all channels */
4787 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4789 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4793 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4795 /* Array bound check. */
4796 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4798 return -E1000_ERR_PHY;
4800 agc_value += cur_agc;
4802 /* Update minimal AGC value. */
4803 if(min_agc > cur_agc)
4807 /* Remove the minimal AGC result for length < 50m */
4808 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4809 agc_value -= min_agc;
4811 /* Get the average length of the remaining 3 channels */
4812 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4814 /* Get the average length of all the 4 channels. */
4815 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4818 /* Set the range of the calculated length. */
4819 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4820 IGP01E1000_AGC_RANGE) > 0) ?
4821 (e1000_igp_cable_length_table[agc_value] -
4822 IGP01E1000_AGC_RANGE) : 0;
4823 *max_length = e1000_igp_cable_length_table[agc_value] +
4824 IGP01E1000_AGC_RANGE;
4827 return E1000_SUCCESS;
4830 /******************************************************************************
4831 * Check the cable polarity
4833 * hw - Struct containing variables accessed by shared code
4834 * polarity - output parameter : 0 - Polarity is not reversed
4835 * 1 - Polarity is reversed.
4837 * returns: - E1000_ERR_XXX
4840 * For phy's older then IGP, this function simply reads the polarity bit in the
4841 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4842 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4843 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4844 * IGP01E1000_PHY_PCS_INIT_REG.
4845 *****************************************************************************/
4847 e1000_check_polarity(struct e1000_hw *hw,
4853 DEBUGFUNC("e1000_check_polarity");
4855 if(hw->phy_type == e1000_phy_m88) {
4856 /* return the Polarity bit in the Status register. */
4857 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4861 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
4862 M88E1000_PSSR_REV_POLARITY_SHIFT;
4863 } else if(hw->phy_type == e1000_phy_igp) {
4864 /* Read the Status register to check the speed */
4865 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4870 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4871 * find the polarity status */
4872 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4873 IGP01E1000_PSSR_SPEED_1000MBPS) {
4875 /* Read the GIG initialization PCS register (0x00B4) */
4876 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4881 /* Check the polarity bits */
4882 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
4884 /* For 10 Mbps, read the polarity bit in the status register. (for
4885 * 100 Mbps this bit is always 0) */
4886 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
4889 return E1000_SUCCESS;
4892 /******************************************************************************
4893 * Check if Downshift occured
4895 * hw - Struct containing variables accessed by shared code
4896 * downshift - output parameter : 0 - No Downshift ocured.
4897 * 1 - Downshift ocured.
4899 * returns: - E1000_ERR_XXX
4902 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4903 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
4904 * Link Health register. In IGP this bit is latched high, so the driver must
4905 * read it immediately after link is established.
4906 *****************************************************************************/
4908 e1000_check_downshift(struct e1000_hw *hw)
4913 DEBUGFUNC("e1000_check_downshift");
4915 if(hw->phy_type == e1000_phy_igp) {
4916 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
4921 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
4923 else if(hw->phy_type == e1000_phy_m88) {
4924 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4929 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
4930 M88E1000_PSSR_DOWNSHIFT_SHIFT;
4932 return E1000_SUCCESS;
4935 /*****************************************************************************
4937 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4938 * gigabit link is achieved to improve link quality.
4940 * hw: Struct containing variables accessed by shared code
4942 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4943 * E1000_SUCCESS at any other case.
4945 ****************************************************************************/
4948 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
4952 uint16_t phy_data, phy_saved_data, speed, duplex, i;
4953 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4954 {IGP01E1000_PHY_AGC_PARAM_A,
4955 IGP01E1000_PHY_AGC_PARAM_B,
4956 IGP01E1000_PHY_AGC_PARAM_C,
4957 IGP01E1000_PHY_AGC_PARAM_D};
4958 uint16_t min_length, max_length;
4960 DEBUGFUNC("e1000_config_dsp_after_link_change");
4962 if(hw->phy_type != e1000_phy_igp)
4963 return E1000_SUCCESS;
4966 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
4968 DEBUGOUT("Error getting link speed and duplex\n");
4972 if(speed == SPEED_1000) {
4974 e1000_get_cable_length(hw, &min_length, &max_length);
4976 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
4977 min_length >= e1000_igp_cable_length_50) {
4979 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4980 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4985 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4987 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
4992 hw->dsp_config_state = e1000_dsp_config_activated;
4995 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
4996 (min_length < e1000_igp_cable_length_50)) {
4998 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
4999 uint32_t idle_errs = 0;
5001 /* clear previous idle error counts */
5002 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5007 for(i = 0; i < ffe_idle_err_timeout; i++) {
5009 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5014 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5015 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5016 hw->ffe_config_state = e1000_ffe_config_active;
5018 ret_val = e1000_write_phy_reg(hw,
5019 IGP01E1000_PHY_DSP_FFE,
5020 IGP01E1000_PHY_DSP_FFE_CM_CP);
5027 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5032 if(hw->dsp_config_state == e1000_dsp_config_activated) {
5033 /* Save off the current value of register 0x2F5B to be restored at
5034 * the end of the routines. */
5035 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5040 /* Disable the PHY transmitter */
5041 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5048 ret_val = e1000_write_phy_reg(hw, 0x0000,
5049 IGP01E1000_IEEE_FORCE_GIGA);
5052 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5053 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5057 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5058 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5060 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5065 ret_val = e1000_write_phy_reg(hw, 0x0000,
5066 IGP01E1000_IEEE_RESTART_AUTONEG);
5072 /* Now enable the transmitter */
5073 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5078 hw->dsp_config_state = e1000_dsp_config_enabled;
5081 if(hw->ffe_config_state == e1000_ffe_config_active) {
5082 /* Save off the current value of register 0x2F5B to be restored at
5083 * the end of the routines. */
5084 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5089 /* Disable the PHY transmitter */
5090 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5097 ret_val = e1000_write_phy_reg(hw, 0x0000,
5098 IGP01E1000_IEEE_FORCE_GIGA);
5101 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5102 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5106 ret_val = e1000_write_phy_reg(hw, 0x0000,
5107 IGP01E1000_IEEE_RESTART_AUTONEG);
5113 /* Now enable the transmitter */
5114 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5119 hw->ffe_config_state = e1000_ffe_config_enabled;
5122 return E1000_SUCCESS;
5125 /*****************************************************************************
5126 * Set PHY to class A mode
5127 * Assumes the following operations will follow to enable the new class mode.
5128 * 1. Do a PHY soft reset
5129 * 2. Restart auto-negotiation or force link.
5131 * hw - Struct containing variables accessed by shared code
5132 ****************************************************************************/
5134 e1000_set_phy_mode(struct e1000_hw *hw)
5137 uint16_t eeprom_data;
5139 DEBUGFUNC("e1000_set_phy_mode");
5141 if((hw->mac_type == e1000_82545_rev_3) &&
5142 (hw->media_type == e1000_media_type_copper)) {
5143 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5148 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5149 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5150 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5153 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5157 hw->phy_reset_disable = FALSE;
5161 return E1000_SUCCESS;
5164 /*****************************************************************************
5166 * This function sets the lplu state according to the active flag. When
5167 * activating lplu this function also disables smart speed and vise versa.
5168 * lplu will not be activated unless the device autonegotiation advertisment
5169 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5170 * hw: Struct containing variables accessed by shared code
5171 * active - true to enable lplu false to disable lplu.
5173 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5174 * E1000_SUCCESS at any other case.
5176 ****************************************************************************/
5179 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5184 DEBUGFUNC("e1000_set_d3_lplu_state");
5186 if(!((hw->mac_type == e1000_82541_rev_2) ||
5187 (hw->mac_type == e1000_82547_rev_2)))
5188 return E1000_SUCCESS;
5190 /* During driver activity LPLU should not be used or it will attain link
5191 * from the lowest speeds starting from 10Mbps. The capability is used for
5192 * Dx transitions and states */
5193 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5198 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5199 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5203 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5204 * Dx states where the power conservation is most important. During
5205 * driver activity we should enable SmartSpeed, so performance is
5207 if (hw->smart_speed == e1000_smart_speed_on) {
5208 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5213 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5214 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5218 } else if (hw->smart_speed == e1000_smart_speed_off) {
5219 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5224 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5225 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5231 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5232 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5233 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5235 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5236 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5240 /* When LPLU is enabled we should disable SmartSpeed */
5241 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5245 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5246 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5251 return E1000_SUCCESS;
5254 /******************************************************************************
5255 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5257 * hw - Struct containing variables accessed by shared code
5258 *****************************************************************************/
5260 e1000_set_vco_speed(struct e1000_hw *hw)
5263 uint16_t default_page = 0;
5266 DEBUGFUNC("e1000_set_vco_speed");
5268 switch(hw->mac_type) {
5269 case e1000_82545_rev_3:
5270 case e1000_82546_rev_3:
5273 return E1000_SUCCESS;
5276 /* Set PHY register 30, page 5, bit 8 to 0 */
5278 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5282 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5286 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5290 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5291 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5295 /* Set PHY register 30, page 4, bit 11 to 1 */
5297 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5301 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5305 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5306 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5310 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5314 return E1000_SUCCESS;
5318 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5321 uint16_t mii_status_reg;
5324 /* Polarity reversal workaround for forced 10F/10H links. */
5326 /* Disable the transmitter on the PHY */
5328 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5331 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5335 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5339 /* This loop will early-out if the NO link condition has been met. */
5340 for(i = PHY_FORCE_TIME; i > 0; i--) {
5341 /* Read the MII Status Register and wait for Link Status bit
5345 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5349 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5353 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
5354 msec_delay_irq(100);
5357 /* Recommended delay time after link has been lost */
5358 msec_delay_irq(1000);
5360 /* Now we will re-enable th transmitter on the PHY */
5362 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5366 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5370 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5374 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5378 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5382 /* This loop will early-out if the link condition has been met. */
5383 for(i = PHY_FORCE_TIME; i > 0; i--) {
5384 /* Read the MII Status Register and wait for Link Status bit
5388 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5392 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5396 if(mii_status_reg & MII_SR_LINK_STATUS) break;
5397 msec_delay_irq(100);
5399 return E1000_SUCCESS;