1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_id_led_init(struct e1000_hw * hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
70 /* IGP cable length table */
72 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
73 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
74 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
75 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
76 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
77 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
78 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
79 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
80 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
83 /******************************************************************************
84 * Set the phy type member in the hw struct.
86 * hw - Struct containing variables accessed by shared code
87 *****************************************************************************/
89 e1000_set_phy_type(struct e1000_hw *hw)
91 DEBUGFUNC("e1000_set_phy_type");
94 case M88E1000_E_PHY_ID:
95 case M88E1000_I_PHY_ID:
96 case M88E1011_I_PHY_ID:
97 hw->phy_type = e1000_phy_m88;
99 case IGP01E1000_I_PHY_ID:
100 if(hw->mac_type == e1000_82541 ||
101 hw->mac_type == e1000_82541_rev_2 ||
102 hw->mac_type == e1000_82547 ||
103 hw->mac_type == e1000_82547_rev_2) {
104 hw->phy_type = e1000_phy_igp;
109 /* Should never have loaded on this device */
110 hw->phy_type = e1000_phy_undefined;
111 return -E1000_ERR_PHY_TYPE;
114 return E1000_SUCCESS;
117 /******************************************************************************
118 * IGP phy init script - initializes the GbE PHY
120 * hw - Struct containing variables accessed by shared code
121 *****************************************************************************/
123 e1000_phy_init_script(struct e1000_hw *hw)
125 DEBUGFUNC("e1000_phy_init_script");
127 if(hw->phy_init_script) {
130 e1000_write_phy_reg(hw,0x0000,0x0140);
134 if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
135 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
137 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
139 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
141 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
143 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
145 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
147 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
149 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
151 e1000_write_phy_reg(hw, 0x2010, 0x0008);
153 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
156 e1000_write_phy_reg(hw, 0x0000, 0x3300);
158 if(hw->mac_type == e1000_82547) {
159 uint16_t fused, fine, coarse;
161 /* Move to analog registers page */
162 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
164 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
165 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
167 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
168 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
170 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
171 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
172 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
173 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
174 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
176 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
177 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
178 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
180 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
181 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
182 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
188 /******************************************************************************
189 * Set the mac type member in the hw struct.
191 * hw - Struct containing variables accessed by shared code
192 *****************************************************************************/
194 e1000_set_mac_type(struct e1000_hw *hw)
196 DEBUGFUNC("e1000_set_mac_type");
198 switch (hw->device_id) {
199 case E1000_DEV_ID_82542:
200 switch (hw->revision_id) {
201 case E1000_82542_2_0_REV_ID:
202 hw->mac_type = e1000_82542_rev2_0;
204 case E1000_82542_2_1_REV_ID:
205 hw->mac_type = e1000_82542_rev2_1;
208 /* Invalid 82542 revision ID */
209 return -E1000_ERR_MAC_TYPE;
212 case E1000_DEV_ID_82543GC_FIBER:
213 case E1000_DEV_ID_82543GC_COPPER:
214 hw->mac_type = e1000_82543;
216 case E1000_DEV_ID_82544EI_COPPER:
217 case E1000_DEV_ID_82544EI_FIBER:
218 case E1000_DEV_ID_82544GC_COPPER:
219 case E1000_DEV_ID_82544GC_LOM:
220 hw->mac_type = e1000_82544;
222 case E1000_DEV_ID_82540EM:
223 case E1000_DEV_ID_82540EM_LOM:
224 case E1000_DEV_ID_82540EP:
225 case E1000_DEV_ID_82540EP_LOM:
226 case E1000_DEV_ID_82540EP_LP:
227 hw->mac_type = e1000_82540;
229 case E1000_DEV_ID_82545EM_COPPER:
230 case E1000_DEV_ID_82545EM_FIBER:
231 hw->mac_type = e1000_82545;
233 case E1000_DEV_ID_82545GM_COPPER:
234 case E1000_DEV_ID_82545GM_FIBER:
235 case E1000_DEV_ID_82545GM_SERDES:
236 hw->mac_type = e1000_82545_rev_3;
238 case E1000_DEV_ID_82546EB_COPPER:
239 case E1000_DEV_ID_82546EB_FIBER:
240 case E1000_DEV_ID_82546EB_QUAD_COPPER:
241 hw->mac_type = e1000_82546;
243 case E1000_DEV_ID_82546GB_COPPER:
244 case E1000_DEV_ID_82546GB_FIBER:
245 case E1000_DEV_ID_82546GB_SERDES:
246 hw->mac_type = e1000_82546_rev_3;
248 case E1000_DEV_ID_82541EI:
249 case E1000_DEV_ID_82541EI_MOBILE:
250 hw->mac_type = e1000_82541;
252 case E1000_DEV_ID_82541ER:
253 case E1000_DEV_ID_82541GI:
254 case E1000_DEV_ID_82541GI_LF:
255 case E1000_DEV_ID_82541GI_MOBILE:
256 hw->mac_type = e1000_82541_rev_2;
258 case E1000_DEV_ID_82547EI:
259 hw->mac_type = e1000_82547;
261 case E1000_DEV_ID_82547GI:
262 hw->mac_type = e1000_82547_rev_2;
265 /* Should never have loaded on this device */
266 return -E1000_ERR_MAC_TYPE;
269 switch(hw->mac_type) {
272 case e1000_82541_rev_2:
273 case e1000_82547_rev_2:
274 hw->asf_firmware_present = TRUE;
280 return E1000_SUCCESS;
283 /*****************************************************************************
284 * Set media type and TBI compatibility.
286 * hw - Struct containing variables accessed by shared code
287 * **************************************************************************/
289 e1000_set_media_type(struct e1000_hw *hw)
293 DEBUGFUNC("e1000_set_media_type");
295 if(hw->mac_type != e1000_82543) {
296 /* tbi_compatibility is only valid on 82543 */
297 hw->tbi_compatibility_en = FALSE;
300 switch (hw->device_id) {
301 case E1000_DEV_ID_82545GM_SERDES:
302 case E1000_DEV_ID_82546GB_SERDES:
303 hw->media_type = e1000_media_type_internal_serdes;
306 if(hw->mac_type >= e1000_82543) {
307 status = E1000_READ_REG(hw, STATUS);
308 if(status & E1000_STATUS_TBIMODE) {
309 hw->media_type = e1000_media_type_fiber;
310 /* tbi_compatibility not valid on fiber */
311 hw->tbi_compatibility_en = FALSE;
313 hw->media_type = e1000_media_type_copper;
316 /* This is an 82542 (fiber only) */
317 hw->media_type = e1000_media_type_fiber;
322 /******************************************************************************
323 * Reset the transmit and receive units; mask and clear all interrupts.
325 * hw - Struct containing variables accessed by shared code
326 *****************************************************************************/
328 e1000_reset_hw(struct e1000_hw *hw)
336 DEBUGFUNC("e1000_reset_hw");
338 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
339 if(hw->mac_type == e1000_82542_rev2_0) {
340 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
341 e1000_pci_clear_mwi(hw);
344 /* Clear interrupt mask to stop board from generating interrupts */
345 DEBUGOUT("Masking off all interrupts\n");
346 E1000_WRITE_REG(hw, IMC, 0xffffffff);
348 /* Disable the Transmit and Receive units. Then delay to allow
349 * any pending transactions to complete before we hit the MAC with
352 E1000_WRITE_REG(hw, RCTL, 0);
353 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
354 E1000_WRITE_FLUSH(hw);
356 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
357 hw->tbi_compatibility_on = FALSE;
359 /* Delay to allow any outstanding PCI transactions to complete before
360 * resetting the device
364 ctrl = E1000_READ_REG(hw, CTRL);
366 /* Must reset the PHY before resetting the MAC */
367 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
368 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
372 /* Issue a global reset to the MAC. This will reset the chip's
373 * transmit, receive, DMA, and link units. It will not effect
374 * the current PCI configuration. The global reset bit is self-
375 * clearing, and should clear within a microsecond.
377 DEBUGOUT("Issuing a global reset to MAC\n");
379 switch(hw->mac_type) {
385 case e1000_82541_rev_2:
386 /* These controllers can't ack the 64-bit write when issuing the
387 * reset, so use IO-mapping as a workaround to issue the reset */
388 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
390 case e1000_82545_rev_3:
391 case e1000_82546_rev_3:
392 /* Reset is performed on a shadow of the control register */
393 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
396 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
400 /* After MAC reset, force reload of EEPROM to restore power-on settings to
401 * device. Later controllers reload the EEPROM automatically, so just wait
402 * for reload to complete.
404 switch(hw->mac_type) {
405 case e1000_82542_rev2_0:
406 case e1000_82542_rev2_1:
409 /* Wait for reset to complete */
411 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
412 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
413 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
414 E1000_WRITE_FLUSH(hw);
415 /* Wait for EEPROM reload */
419 case e1000_82541_rev_2:
421 case e1000_82547_rev_2:
422 /* Wait for EEPROM reload */
426 /* Wait for EEPROM reload (it happens automatically) */
431 /* Disable HW ARPs on ASF enabled adapters */
432 if(hw->mac_type >= e1000_82540) {
433 manc = E1000_READ_REG(hw, MANC);
434 manc &= ~(E1000_MANC_ARP_EN);
435 E1000_WRITE_REG(hw, MANC, manc);
438 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
439 e1000_phy_init_script(hw);
441 /* Configure activity LED after PHY reset */
442 led_ctrl = E1000_READ_REG(hw, LEDCTL);
443 led_ctrl &= IGP_ACTIVITY_LED_MASK;
444 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
445 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
448 /* Clear interrupt mask to stop board from generating interrupts */
449 DEBUGOUT("Masking off all interrupts\n");
450 E1000_WRITE_REG(hw, IMC, 0xffffffff);
452 /* Clear any pending interrupt events. */
453 icr = E1000_READ_REG(hw, ICR);
455 /* If MWI was previously enabled, reenable it. */
456 if(hw->mac_type == e1000_82542_rev2_0) {
457 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
458 e1000_pci_set_mwi(hw);
461 return E1000_SUCCESS;
464 /******************************************************************************
465 * Performs basic configuration of the adapter.
467 * hw - Struct containing variables accessed by shared code
469 * Assumes that the controller has previously been reset and is in a
470 * post-reset uninitialized state. Initializes the receive address registers,
471 * multicast table, and VLAN filter table. Calls routines to setup link
472 * configuration and flow control settings. Clears all on-chip counters. Leaves
473 * the transmit and receive units disabled and uninitialized.
474 *****************************************************************************/
476 e1000_init_hw(struct e1000_hw *hw)
481 uint16_t pcix_cmd_word;
482 uint16_t pcix_stat_hi_word;
485 DEBUGFUNC("e1000_init_hw");
487 /* Initialize Identification LED */
488 ret_val = e1000_id_led_init(hw);
490 DEBUGOUT("Error Initializing Identification LED\n");
494 /* Set the media type and TBI compatibility */
495 e1000_set_media_type(hw);
497 /* Disabling VLAN filtering. */
498 DEBUGOUT("Initializing the IEEE VLAN\n");
499 E1000_WRITE_REG(hw, VET, 0);
501 e1000_clear_vfta(hw);
503 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
504 if(hw->mac_type == e1000_82542_rev2_0) {
505 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
506 e1000_pci_clear_mwi(hw);
507 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
508 E1000_WRITE_FLUSH(hw);
512 /* Setup the receive address. This involves initializing all of the Receive
513 * Address Registers (RARs 0 - 15).
515 e1000_init_rx_addrs(hw);
517 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
518 if(hw->mac_type == e1000_82542_rev2_0) {
519 E1000_WRITE_REG(hw, RCTL, 0);
520 E1000_WRITE_FLUSH(hw);
522 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
523 e1000_pci_set_mwi(hw);
526 /* Zero out the Multicast HASH table */
527 DEBUGOUT("Zeroing the MTA\n");
528 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
529 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
531 /* Set the PCI priority bit correctly in the CTRL register. This
532 * determines if the adapter gives priority to receives, or if it
533 * gives equal priority to transmits and receives.
535 if(hw->dma_fairness) {
536 ctrl = E1000_READ_REG(hw, CTRL);
537 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
540 switch(hw->mac_type) {
541 case e1000_82545_rev_3:
542 case e1000_82546_rev_3:
545 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
546 if(hw->bus_type == e1000_bus_type_pcix) {
547 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
548 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
550 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
551 PCIX_COMMAND_MMRBC_SHIFT;
552 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
553 PCIX_STATUS_HI_MMRBC_SHIFT;
554 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
555 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
556 if(cmd_mmrbc > stat_mmrbc) {
557 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
558 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
559 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
566 /* Call a subroutine to configure the link and setup flow control. */
567 ret_val = e1000_setup_link(hw);
569 /* Set the transmit descriptor write-back policy */
570 if(hw->mac_type > e1000_82544) {
571 ctrl = E1000_READ_REG(hw, TXDCTL);
572 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
573 E1000_WRITE_REG(hw, TXDCTL, ctrl);
576 /* Clear all of the statistics registers (clear on read). It is
577 * important that we do this after we have tried to establish link
578 * because the symbol error count will increment wildly if there
581 e1000_clear_hw_cntrs(hw);
586 /******************************************************************************
587 * Adjust SERDES output amplitude based on EEPROM setting.
589 * hw - Struct containing variables accessed by shared code.
590 *****************************************************************************/
592 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
594 uint16_t eeprom_data;
597 DEBUGFUNC("e1000_adjust_serdes_amplitude");
599 if(hw->media_type != e1000_media_type_internal_serdes)
600 return E1000_SUCCESS;
602 switch(hw->mac_type) {
603 case e1000_82545_rev_3:
604 case e1000_82546_rev_3:
607 return E1000_SUCCESS;
610 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
615 if(eeprom_data != EEPROM_RESERVED_WORD) {
616 /* Adjust SERDES output amplitude only. */
617 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
618 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
623 return E1000_SUCCESS;
626 /******************************************************************************
627 * Configures flow control and link settings.
629 * hw - Struct containing variables accessed by shared code
631 * Determines which flow control settings to use. Calls the apropriate media-
632 * specific link configuration function. Configures the flow control settings.
633 * Assuming the adapter has a valid link partner, a valid link should be
634 * established. Assumes the hardware has previously been reset and the
635 * transmitter and receiver are not enabled.
636 *****************************************************************************/
638 e1000_setup_link(struct e1000_hw *hw)
642 uint16_t eeprom_data;
644 DEBUGFUNC("e1000_setup_link");
646 /* Read and store word 0x0F of the EEPROM. This word contains bits
647 * that determine the hardware's default PAUSE (flow control) mode,
648 * a bit that determines whether the HW defaults to enabling or
649 * disabling auto-negotiation, and the direction of the
650 * SW defined pins. If there is no SW over-ride of the flow
651 * control setting, then the variable hw->fc will
652 * be initialized based on a value in the EEPROM.
654 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
655 DEBUGOUT("EEPROM Read Error\n");
656 return -E1000_ERR_EEPROM;
659 if(hw->fc == e1000_fc_default) {
660 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
661 hw->fc = e1000_fc_none;
662 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
663 EEPROM_WORD0F_ASM_DIR)
664 hw->fc = e1000_fc_tx_pause;
666 hw->fc = e1000_fc_full;
669 /* We want to save off the original Flow Control configuration just
670 * in case we get disconnected and then reconnected into a different
671 * hub or switch with different Flow Control capabilities.
673 if(hw->mac_type == e1000_82542_rev2_0)
674 hw->fc &= (~e1000_fc_tx_pause);
676 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
677 hw->fc &= (~e1000_fc_rx_pause);
679 hw->original_fc = hw->fc;
681 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
683 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
684 * polarity value for the SW controlled pins, and setup the
685 * Extended Device Control reg with that info.
686 * This is needed because one of the SW controlled pins is used for
687 * signal detection. So this should be done before e1000_setup_pcs_link()
688 * or e1000_phy_setup() is called.
690 if(hw->mac_type == e1000_82543) {
691 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
693 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
696 /* Call the necessary subroutine to configure the link. */
697 ret_val = (hw->media_type == e1000_media_type_copper) ?
698 e1000_setup_copper_link(hw) :
699 e1000_setup_fiber_serdes_link(hw);
701 /* Initialize the flow control address, type, and PAUSE timer
702 * registers to their default values. This is done even if flow
703 * control is disabled, because it does not hurt anything to
704 * initialize these registers.
706 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
708 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
709 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
710 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
711 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
713 /* Set the flow control receive threshold registers. Normally,
714 * these registers will be set to a default threshold that may be
715 * adjusted later by the driver's runtime code. However, if the
716 * ability to transmit pause frames in not enabled, then these
717 * registers will be set to 0.
719 if(!(hw->fc & e1000_fc_tx_pause)) {
720 E1000_WRITE_REG(hw, FCRTL, 0);
721 E1000_WRITE_REG(hw, FCRTH, 0);
723 /* We need to set up the Receive Threshold high and low water marks
724 * as well as (optionally) enabling the transmission of XON frames.
726 if(hw->fc_send_xon) {
727 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
728 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
730 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
731 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
737 /******************************************************************************
738 * Sets up link for a fiber based or serdes based adapter
740 * hw - Struct containing variables accessed by shared code
742 * Manipulates Physical Coding Sublayer functions in order to configure
743 * link. Assumes the hardware has been previously reset and the transmitter
744 * and receiver are not enabled.
745 *****************************************************************************/
747 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
756 DEBUGFUNC("e1000_setup_fiber_serdes_link");
758 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
759 * set when the optics detect a signal. On older adapters, it will be
760 * cleared when there is a signal. This applies to fiber media only.
761 * If we're on serdes media, adjust the output amplitude to value set in
764 ctrl = E1000_READ_REG(hw, CTRL);
765 if(hw->media_type == e1000_media_type_fiber)
766 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
768 ret_val = e1000_adjust_serdes_amplitude(hw);
772 /* Take the link out of reset */
773 ctrl &= ~(E1000_CTRL_LRST);
775 /* Adjust VCO speed to improve BER performance */
776 ret_val = e1000_set_vco_speed(hw);
780 e1000_config_collision_dist(hw);
782 /* Check for a software override of the flow control settings, and setup
783 * the device accordingly. If auto-negotiation is enabled, then software
784 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
785 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
786 * auto-negotiation is disabled, then software will have to manually
787 * configure the two flow control enable bits in the CTRL register.
789 * The possible values of the "fc" parameter are:
790 * 0: Flow control is completely disabled
791 * 1: Rx flow control is enabled (we can receive pause frames, but
792 * not send pause frames).
793 * 2: Tx flow control is enabled (we can send pause frames but we do
794 * not support receiving pause frames).
795 * 3: Both Rx and TX flow control (symmetric) are enabled.
799 /* Flow control is completely disabled by a software over-ride. */
800 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
802 case e1000_fc_rx_pause:
803 /* RX Flow control is enabled and TX Flow control is disabled by a
804 * software over-ride. Since there really isn't a way to advertise
805 * that we are capable of RX Pause ONLY, we will advertise that we
806 * support both symmetric and asymmetric RX PAUSE. Later, we will
807 * disable the adapter's ability to send PAUSE frames.
809 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
811 case e1000_fc_tx_pause:
812 /* TX Flow control is enabled, and RX Flow control is disabled, by a
813 * software over-ride.
815 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
818 /* Flow control (both RX and TX) is enabled by a software over-ride. */
819 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
822 DEBUGOUT("Flow control param set incorrectly\n");
823 return -E1000_ERR_CONFIG;
827 /* Since auto-negotiation is enabled, take the link out of reset (the link
828 * will be in reset, because we previously reset the chip). This will
829 * restart auto-negotiation. If auto-neogtiation is successful then the
830 * link-up status bit will be set and the flow control enable bits (RFCE
831 * and TFCE) will be set according to their negotiated value.
833 DEBUGOUT("Auto-negotiation enabled\n");
835 E1000_WRITE_REG(hw, TXCW, txcw);
836 E1000_WRITE_REG(hw, CTRL, ctrl);
837 E1000_WRITE_FLUSH(hw);
842 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
843 * indication in the Device Status Register. Time-out if a link isn't
844 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
845 * less than 500 milliseconds even if the other end is doing it in SW).
846 * For internal serdes, we just assume a signal is present, then poll.
848 if(hw->media_type == e1000_media_type_internal_serdes ||
849 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
850 DEBUGOUT("Looking for Link\n");
851 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
853 status = E1000_READ_REG(hw, STATUS);
854 if(status & E1000_STATUS_LU) break;
856 if(i == (LINK_UP_TIMEOUT / 10)) {
857 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
858 hw->autoneg_failed = 1;
859 /* AutoNeg failed to achieve a link, so we'll call
860 * e1000_check_for_link. This routine will force the link up if
861 * we detect a signal. This will allow us to communicate with
862 * non-autonegotiating link partners.
864 ret_val = e1000_check_for_link(hw);
866 DEBUGOUT("Error while checking for link\n");
869 hw->autoneg_failed = 0;
871 hw->autoneg_failed = 0;
872 DEBUGOUT("Valid Link Found\n");
875 DEBUGOUT("No Signal Detected\n");
877 return E1000_SUCCESS;
880 /******************************************************************************
881 * Detects which PHY is present and the speed and duplex
883 * hw - Struct containing variables accessed by shared code
884 ******************************************************************************/
886 e1000_setup_copper_link(struct e1000_hw *hw)
894 DEBUGFUNC("e1000_setup_copper_link");
896 ctrl = E1000_READ_REG(hw, CTRL);
897 /* With 82543, we need to force speed and duplex on the MAC equal to what
898 * the PHY speed and duplex configuration is. In addition, we need to
899 * perform a hardware reset on the PHY to take it out of reset.
901 if(hw->mac_type > e1000_82543) {
902 ctrl |= E1000_CTRL_SLU;
903 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
904 E1000_WRITE_REG(hw, CTRL, ctrl);
906 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
907 E1000_WRITE_REG(hw, CTRL, ctrl);
908 e1000_phy_hw_reset(hw);
911 /* Make sure we have a valid PHY */
912 ret_val = e1000_detect_gig_phy(hw);
914 DEBUGOUT("Error, did not detect valid phy.\n");
917 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
919 /* Set PHY to class A mode (if necessary) */
920 ret_val = e1000_set_phy_mode(hw);
924 if((hw->mac_type == e1000_82545_rev_3) ||
925 (hw->mac_type == e1000_82546_rev_3)) {
926 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
927 phy_data |= 0x00000008;
928 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
931 if(hw->mac_type <= e1000_82543 ||
932 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
933 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
934 hw->phy_reset_disable = FALSE;
936 if(!hw->phy_reset_disable) {
937 if (hw->phy_type == e1000_phy_igp) {
939 ret_val = e1000_phy_reset(hw);
941 DEBUGOUT("Error Resetting the PHY\n");
945 /* Wait 10ms for MAC to configure PHY from eeprom settings */
948 /* Configure activity LED after PHY reset */
949 led_ctrl = E1000_READ_REG(hw, LEDCTL);
950 led_ctrl &= IGP_ACTIVITY_LED_MASK;
951 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
952 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
954 /* disable lplu d3 during driver init */
955 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
957 DEBUGOUT("Error Disabling LPLU D3\n");
961 /* Configure mdi-mdix settings */
962 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
967 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
968 hw->dsp_config_state = e1000_dsp_config_disabled;
969 /* Force MDI for IGP B-0 PHY */
970 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
971 IGP01E1000_PSCR_FORCE_MDI_MDIX);
975 hw->dsp_config_state = e1000_dsp_config_enabled;
976 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
980 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
983 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
987 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
991 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
996 /* set auto-master slave resolution settings */
998 e1000_ms_type phy_ms_setting = hw->master_slave;
1000 if(hw->ffe_config_state == e1000_ffe_config_active)
1001 hw->ffe_config_state = e1000_ffe_config_enabled;
1003 if(hw->dsp_config_state == e1000_dsp_config_activated)
1004 hw->dsp_config_state = e1000_dsp_config_enabled;
1006 /* when autonegotiation advertisment is only 1000Mbps then we
1007 * should disable SmartSpeed and enable Auto MasterSlave
1008 * resolution as hardware default. */
1009 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1010 /* Disable SmartSpeed */
1011 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1015 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1016 ret_val = e1000_write_phy_reg(hw,
1017 IGP01E1000_PHY_PORT_CONFIG,
1021 /* Set auto Master/Slave resolution process */
1022 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1025 phy_data &= ~CR_1000T_MS_ENABLE;
1026 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1031 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1035 /* load defaults for future use */
1036 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1037 ((phy_data & CR_1000T_MS_VALUE) ?
1038 e1000_ms_force_master :
1039 e1000_ms_force_slave) :
1042 switch (phy_ms_setting) {
1043 case e1000_ms_force_master:
1044 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1046 case e1000_ms_force_slave:
1047 phy_data |= CR_1000T_MS_ENABLE;
1048 phy_data &= ~(CR_1000T_MS_VALUE);
1051 phy_data &= ~CR_1000T_MS_ENABLE;
1055 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1060 /* Enable CRS on TX. This must be set for half-duplex operation. */
1061 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1066 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1069 * MDI/MDI-X = 0 (default)
1070 * 0 - Auto for all speeds
1073 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1075 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1079 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1082 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1085 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1089 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1094 * disable_polarity_correction = 0 (default)
1095 * Automatic Correction for Reversed Cable Polarity
1099 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1100 if(hw->disable_polarity_correction == 1)
1101 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1102 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1107 /* Force TX_CLK in the Extended PHY Specific Control Register
1110 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1115 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1117 if (hw->phy_revision < M88E1011_I_REV_4) {
1118 /* Configure Master and Slave downshift values */
1119 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1120 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1121 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1122 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1123 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1129 /* SW Reset the PHY so all changes take effect */
1130 ret_val = e1000_phy_reset(hw);
1132 DEBUGOUT("Error Resetting the PHY\n");
1138 * autoneg = 1 (default)
1139 * PHY will advertise value(s) parsed from
1140 * autoneg_advertised and fc
1142 * PHY will be set to 10H, 10F, 100H, or 100F
1143 * depending on value parsed from forced_speed_duplex.
1146 /* Is autoneg enabled? This is enabled by default or by software
1147 * override. If so, call e1000_phy_setup_autoneg routine to parse the
1148 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1149 * the user should have provided a speed/duplex override. If so, then
1150 * call e1000_phy_force_speed_duplex to parse and set this up.
1153 /* Perform some bounds checking on the hw->autoneg_advertised
1154 * parameter. If this variable is zero, then set it to the default.
1156 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1158 /* If autoneg_advertised is zero, we assume it was not defaulted
1159 * by the calling code so we set to advertise full capability.
1161 if(hw->autoneg_advertised == 0)
1162 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1164 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1165 ret_val = e1000_phy_setup_autoneg(hw);
1167 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1170 DEBUGOUT("Restarting Auto-Neg\n");
1172 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1173 * the Auto Neg Restart bit in the PHY control register.
1175 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1179 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1180 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1184 /* Does the user want to wait for Auto-Neg to complete here, or
1185 * check at a later time (for example, callback routine).
1187 if(hw->wait_autoneg_complete) {
1188 ret_val = e1000_wait_autoneg(hw);
1190 DEBUGOUT("Error while waiting for autoneg to complete\n");
1194 hw->get_link_status = TRUE;
1196 DEBUGOUT("Forcing speed and duplex\n");
1197 ret_val = e1000_phy_force_speed_duplex(hw);
1199 DEBUGOUT("Error Forcing Speed and Duplex\n");
1203 } /* !hw->phy_reset_disable */
1205 /* Check link status. Wait up to 100 microseconds for link to become
1208 for(i = 0; i < 10; i++) {
1209 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1212 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1216 if(phy_data & MII_SR_LINK_STATUS) {
1217 /* We have link, so we need to finish the config process:
1218 * 1) Set up the MAC to the current PHY speed/duplex
1219 * if we are on 82543. If we
1220 * are on newer silicon, we only need to configure
1221 * collision distance in the Transmit Control Register.
1222 * 2) Set up flow control on the MAC to that established with
1225 if(hw->mac_type >= e1000_82544) {
1226 e1000_config_collision_dist(hw);
1228 ret_val = e1000_config_mac_to_phy(hw);
1230 DEBUGOUT("Error configuring MAC to PHY settings\n");
1234 ret_val = e1000_config_fc_after_link_up(hw);
1236 DEBUGOUT("Error Configuring Flow Control\n");
1239 DEBUGOUT("Valid link established!!!\n");
1241 if(hw->phy_type == e1000_phy_igp) {
1242 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1244 DEBUGOUT("Error Configuring DSP after link up\n");
1248 DEBUGOUT("Valid link established!!!\n");
1249 return E1000_SUCCESS;
1254 DEBUGOUT("Unable to establish link!!!\n");
1255 return E1000_SUCCESS;
1258 /******************************************************************************
1259 * Configures PHY autoneg and flow control advertisement settings
1261 * hw - Struct containing variables accessed by shared code
1262 ******************************************************************************/
1264 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1267 uint16_t mii_autoneg_adv_reg;
1268 uint16_t mii_1000t_ctrl_reg;
1270 DEBUGFUNC("e1000_phy_setup_autoneg");
1272 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1273 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1277 /* Read the MII 1000Base-T Control Register (Address 9). */
1278 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1282 /* Need to parse both autoneg_advertised and fc and set up
1283 * the appropriate PHY registers. First we will parse for
1284 * autoneg_advertised software override. Since we can advertise
1285 * a plethora of combinations, we need to check each bit
1289 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1290 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1291 * the 1000Base-T Control Register (Address 9).
1293 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1294 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1296 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1298 /* Do we want to advertise 10 Mb Half Duplex? */
1299 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1300 DEBUGOUT("Advertise 10mb Half duplex\n");
1301 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1304 /* Do we want to advertise 10 Mb Full Duplex? */
1305 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1306 DEBUGOUT("Advertise 10mb Full duplex\n");
1307 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1310 /* Do we want to advertise 100 Mb Half Duplex? */
1311 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1312 DEBUGOUT("Advertise 100mb Half duplex\n");
1313 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1316 /* Do we want to advertise 100 Mb Full Duplex? */
1317 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1318 DEBUGOUT("Advertise 100mb Full duplex\n");
1319 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1322 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1323 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1324 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1327 /* Do we want to advertise 1000 Mb Full Duplex? */
1328 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1329 DEBUGOUT("Advertise 1000mb Full duplex\n");
1330 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1333 /* Check for a software override of the flow control settings, and
1334 * setup the PHY advertisement registers accordingly. If
1335 * auto-negotiation is enabled, then software will have to set the
1336 * "PAUSE" bits to the correct value in the Auto-Negotiation
1337 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1339 * The possible values of the "fc" parameter are:
1340 * 0: Flow control is completely disabled
1341 * 1: Rx flow control is enabled (we can receive pause frames
1342 * but not send pause frames).
1343 * 2: Tx flow control is enabled (we can send pause frames
1344 * but we do not support receiving pause frames).
1345 * 3: Both Rx and TX flow control (symmetric) are enabled.
1346 * other: No software override. The flow control configuration
1347 * in the EEPROM is used.
1350 case e1000_fc_none: /* 0 */
1351 /* Flow control (RX & TX) is completely disabled by a
1352 * software over-ride.
1354 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1356 case e1000_fc_rx_pause: /* 1 */
1357 /* RX Flow control is enabled, and TX Flow control is
1358 * disabled, by a software over-ride.
1360 /* Since there really isn't a way to advertise that we are
1361 * capable of RX Pause ONLY, we will advertise that we
1362 * support both symmetric and asymmetric RX PAUSE. Later
1363 * (in e1000_config_fc_after_link_up) we will disable the
1364 *hw's ability to send PAUSE frames.
1366 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1368 case e1000_fc_tx_pause: /* 2 */
1369 /* TX Flow control is enabled, and RX Flow control is
1370 * disabled, by a software over-ride.
1372 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1373 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1375 case e1000_fc_full: /* 3 */
1376 /* Flow control (both RX and TX) is enabled by a software
1379 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1382 DEBUGOUT("Flow control param set incorrectly\n");
1383 return -E1000_ERR_CONFIG;
1386 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1390 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1392 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1396 return E1000_SUCCESS;
1399 /******************************************************************************
1400 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1402 * hw - Struct containing variables accessed by shared code
1403 ******************************************************************************/
1405 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1409 uint16_t mii_ctrl_reg;
1410 uint16_t mii_status_reg;
1414 DEBUGFUNC("e1000_phy_force_speed_duplex");
1416 /* Turn off Flow control if we are forcing speed and duplex. */
1417 hw->fc = e1000_fc_none;
1419 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1421 /* Read the Device Control Register. */
1422 ctrl = E1000_READ_REG(hw, CTRL);
1424 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1425 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1426 ctrl &= ~(DEVICE_SPEED_MASK);
1428 /* Clear the Auto Speed Detect Enable bit. */
1429 ctrl &= ~E1000_CTRL_ASDE;
1431 /* Read the MII Control Register. */
1432 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1436 /* We need to disable autoneg in order to force link and duplex. */
1438 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1440 /* Are we forcing Full or Half Duplex? */
1441 if(hw->forced_speed_duplex == e1000_100_full ||
1442 hw->forced_speed_duplex == e1000_10_full) {
1443 /* We want to force full duplex so we SET the full duplex bits in the
1444 * Device and MII Control Registers.
1446 ctrl |= E1000_CTRL_FD;
1447 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1448 DEBUGOUT("Full Duplex\n");
1450 /* We want to force half duplex so we CLEAR the full duplex bits in
1451 * the Device and MII Control Registers.
1453 ctrl &= ~E1000_CTRL_FD;
1454 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1455 DEBUGOUT("Half Duplex\n");
1458 /* Are we forcing 100Mbps??? */
1459 if(hw->forced_speed_duplex == e1000_100_full ||
1460 hw->forced_speed_duplex == e1000_100_half) {
1461 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1462 ctrl |= E1000_CTRL_SPD_100;
1463 mii_ctrl_reg |= MII_CR_SPEED_100;
1464 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1465 DEBUGOUT("Forcing 100mb ");
1467 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1468 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1469 mii_ctrl_reg |= MII_CR_SPEED_10;
1470 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1471 DEBUGOUT("Forcing 10mb ");
1474 e1000_config_collision_dist(hw);
1476 /* Write the configured values back to the Device Control Reg. */
1477 E1000_WRITE_REG(hw, CTRL, ctrl);
1479 if (hw->phy_type == e1000_phy_m88) {
1480 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1484 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1485 * forced whenever speed are duplex are forced.
1487 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1488 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1492 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1494 /* Need to reset the PHY or these changes will be ignored */
1495 mii_ctrl_reg |= MII_CR_RESET;
1497 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1498 * forced whenever speed or duplex are forced.
1500 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1504 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1505 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1507 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1512 /* Write back the modified PHY MII control register. */
1513 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1519 /* The wait_autoneg_complete flag may be a little misleading here.
1520 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1521 * But we do want to delay for a period while forcing only so we
1522 * don't generate false No Link messages. So we will wait here
1523 * only if the user has set wait_autoneg_complete to 1, which is
1526 if(hw->wait_autoneg_complete) {
1527 /* We will wait for autoneg to complete. */
1528 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1531 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1532 for(i = PHY_FORCE_TIME; i > 0; i--) {
1533 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1536 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1540 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1544 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1547 if((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1548 /* We didn't get link. Reset the DSP and wait again for link. */
1549 ret_val = e1000_phy_reset_dsp(hw);
1551 DEBUGOUT("Error Resetting PHY DSP\n");
1555 /* This loop will early-out if the link condition has been met. */
1556 for(i = PHY_FORCE_TIME; i > 0; i--) {
1557 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1559 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1562 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1566 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1572 if (hw->phy_type == e1000_phy_m88) {
1573 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1574 * Extended PHY Specific Control Register to 25MHz clock. This value
1575 * defaults back to a 2.5MHz clock when the PHY is reset.
1577 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1581 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1582 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1586 /* In addition, because of the s/w reset above, we need to enable CRS on
1587 * TX. This must be set for both full and half duplex operation.
1589 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1593 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1594 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1598 return E1000_SUCCESS;
1601 /******************************************************************************
1602 * Sets the collision distance in the Transmit Control register
1604 * hw - Struct containing variables accessed by shared code
1606 * Link should have been established previously. Reads the speed and duplex
1607 * information from the Device Status register.
1608 ******************************************************************************/
1610 e1000_config_collision_dist(struct e1000_hw *hw)
1614 DEBUGFUNC("e1000_config_collision_dist");
1616 tctl = E1000_READ_REG(hw, TCTL);
1618 tctl &= ~E1000_TCTL_COLD;
1619 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1621 E1000_WRITE_REG(hw, TCTL, tctl);
1622 E1000_WRITE_FLUSH(hw);
1625 /******************************************************************************
1626 * Sets MAC speed and duplex settings to reflect the those in the PHY
1628 * hw - Struct containing variables accessed by shared code
1629 * mii_reg - data to write to the MII control register
1631 * The contents of the PHY register containing the needed information need to
1633 ******************************************************************************/
1635 e1000_config_mac_to_phy(struct e1000_hw *hw)
1641 DEBUGFUNC("e1000_config_mac_to_phy");
1643 /* Read the Device Control Register and set the bits to Force Speed
1646 ctrl = E1000_READ_REG(hw, CTRL);
1647 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1648 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1650 /* Set up duplex in the Device Control and Transmit Control
1651 * registers depending on negotiated values.
1653 if (hw->phy_type == e1000_phy_igp) {
1654 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
1659 if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
1660 else ctrl &= ~E1000_CTRL_FD;
1662 e1000_config_collision_dist(hw);
1664 /* Set up speed in the Device Control register depending on
1665 * negotiated values.
1667 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1668 IGP01E1000_PSSR_SPEED_1000MBPS)
1669 ctrl |= E1000_CTRL_SPD_1000;
1670 else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1671 IGP01E1000_PSSR_SPEED_100MBPS)
1672 ctrl |= E1000_CTRL_SPD_100;
1674 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
1679 if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1680 else ctrl &= ~E1000_CTRL_FD;
1682 e1000_config_collision_dist(hw);
1684 /* Set up speed in the Device Control register depending on
1685 * negotiated values.
1687 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1688 ctrl |= E1000_CTRL_SPD_1000;
1689 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1690 ctrl |= E1000_CTRL_SPD_100;
1692 /* Write the configured values back to the Device Control Reg. */
1693 E1000_WRITE_REG(hw, CTRL, ctrl);
1694 return E1000_SUCCESS;
1697 /******************************************************************************
1698 * Forces the MAC's flow control settings.
1700 * hw - Struct containing variables accessed by shared code
1702 * Sets the TFCE and RFCE bits in the device control register to reflect
1703 * the adapter settings. TFCE and RFCE need to be explicitly set by
1704 * software when a Copper PHY is used because autonegotiation is managed
1705 * by the PHY rather than the MAC. Software must also configure these
1706 * bits when link is forced on a fiber connection.
1707 *****************************************************************************/
1709 e1000_force_mac_fc(struct e1000_hw *hw)
1713 DEBUGFUNC("e1000_force_mac_fc");
1715 /* Get the current configuration of the Device Control Register */
1716 ctrl = E1000_READ_REG(hw, CTRL);
1718 /* Because we didn't get link via the internal auto-negotiation
1719 * mechanism (we either forced link or we got link via PHY
1720 * auto-neg), we have to manually enable/disable transmit an
1721 * receive flow control.
1723 * The "Case" statement below enables/disable flow control
1724 * according to the "hw->fc" parameter.
1726 * The possible values of the "fc" parameter are:
1727 * 0: Flow control is completely disabled
1728 * 1: Rx flow control is enabled (we can receive pause
1729 * frames but not send pause frames).
1730 * 2: Tx flow control is enabled (we can send pause frames
1731 * frames but we do not receive pause frames).
1732 * 3: Both Rx and TX flow control (symmetric) is enabled.
1733 * other: No other values should be possible at this point.
1738 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1740 case e1000_fc_rx_pause:
1741 ctrl &= (~E1000_CTRL_TFCE);
1742 ctrl |= E1000_CTRL_RFCE;
1744 case e1000_fc_tx_pause:
1745 ctrl &= (~E1000_CTRL_RFCE);
1746 ctrl |= E1000_CTRL_TFCE;
1749 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1752 DEBUGOUT("Flow control param set incorrectly\n");
1753 return -E1000_ERR_CONFIG;
1756 /* Disable TX Flow Control for 82542 (rev 2.0) */
1757 if(hw->mac_type == e1000_82542_rev2_0)
1758 ctrl &= (~E1000_CTRL_TFCE);
1760 E1000_WRITE_REG(hw, CTRL, ctrl);
1761 return E1000_SUCCESS;
1764 /******************************************************************************
1765 * Configures flow control settings after link is established
1767 * hw - Struct containing variables accessed by shared code
1769 * Should be called immediately after a valid link has been established.
1770 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1771 * and autonegotiation is enabled, the MAC flow control settings will be set
1772 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1773 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1774 *****************************************************************************/
1776 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1779 uint16_t mii_status_reg;
1780 uint16_t mii_nway_adv_reg;
1781 uint16_t mii_nway_lp_ability_reg;
1785 DEBUGFUNC("e1000_config_fc_after_link_up");
1787 /* Check for the case where we have fiber media and auto-neg failed
1788 * so we had to force link. In this case, we need to force the
1789 * configuration of the MAC to match the "fc" parameter.
1791 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1792 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
1793 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1794 ret_val = e1000_force_mac_fc(hw);
1796 DEBUGOUT("Error forcing flow control settings\n");
1801 /* Check for the case where we have copper media and auto-neg is
1802 * enabled. In this case, we need to check and see if Auto-Neg
1803 * has completed, and if so, how the PHY and link partner has
1804 * flow control configured.
1806 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1807 /* Read the MII Status Register and check to see if AutoNeg
1808 * has completed. We read this twice because this reg has
1809 * some "sticky" (latched) bits.
1811 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1814 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1818 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1819 /* The AutoNeg process has completed, so we now need to
1820 * read both the Auto Negotiation Advertisement Register
1821 * (Address 4) and the Auto_Negotiation Base Page Ability
1822 * Register (Address 5) to determine how flow control was
1825 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1829 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1830 &mii_nway_lp_ability_reg);
1834 /* Two bits in the Auto Negotiation Advertisement Register
1835 * (Address 4) and two bits in the Auto Negotiation Base
1836 * Page Ability Register (Address 5) determine flow control
1837 * for both the PHY and the link partner. The following
1838 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1839 * 1999, describes these PAUSE resolution bits and how flow
1840 * control is determined based upon these settings.
1841 * NOTE: DC = Don't Care
1843 * LOCAL DEVICE | LINK PARTNER
1844 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1845 *-------|---------|-------|---------|--------------------
1846 * 0 | 0 | DC | DC | e1000_fc_none
1847 * 0 | 1 | 0 | DC | e1000_fc_none
1848 * 0 | 1 | 1 | 0 | e1000_fc_none
1849 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1850 * 1 | 0 | 0 | DC | e1000_fc_none
1851 * 1 | DC | 1 | DC | e1000_fc_full
1852 * 1 | 1 | 0 | 0 | e1000_fc_none
1853 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1856 /* Are both PAUSE bits set to 1? If so, this implies
1857 * Symmetric Flow Control is enabled at both ends. The
1858 * ASM_DIR bits are irrelevant per the spec.
1860 * For Symmetric Flow Control:
1862 * LOCAL DEVICE | LINK PARTNER
1863 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1864 *-------|---------|-------|---------|--------------------
1865 * 1 | DC | 1 | DC | e1000_fc_full
1868 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1869 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1870 /* Now we need to check if the user selected RX ONLY
1871 * of pause frames. In this case, we had to advertise
1872 * FULL flow control because we could not advertise RX
1873 * ONLY. Hence, we must now check to see if we need to
1874 * turn OFF the TRANSMISSION of PAUSE frames.
1876 if(hw->original_fc == e1000_fc_full) {
1877 hw->fc = e1000_fc_full;
1878 DEBUGOUT("Flow Control = FULL.\r\n");
1880 hw->fc = e1000_fc_rx_pause;
1881 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1884 /* For receiving PAUSE frames ONLY.
1886 * LOCAL DEVICE | LINK PARTNER
1887 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1888 *-------|---------|-------|---------|--------------------
1889 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1892 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1893 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1894 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1895 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1896 hw->fc = e1000_fc_tx_pause;
1897 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1899 /* For transmitting PAUSE frames ONLY.
1901 * LOCAL DEVICE | LINK PARTNER
1902 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1903 *-------|---------|-------|---------|--------------------
1904 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1907 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1908 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1909 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1910 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1911 hw->fc = e1000_fc_rx_pause;
1912 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1914 /* Per the IEEE spec, at this point flow control should be
1915 * disabled. However, we want to consider that we could
1916 * be connected to a legacy switch that doesn't advertise
1917 * desired flow control, but can be forced on the link
1918 * partner. So if we advertised no flow control, that is
1919 * what we will resolve to. If we advertised some kind of
1920 * receive capability (Rx Pause Only or Full Flow Control)
1921 * and the link partner advertised none, we will configure
1922 * ourselves to enable Rx Flow Control only. We can do
1923 * this safely for two reasons: If the link partner really
1924 * didn't want flow control enabled, and we enable Rx, no
1925 * harm done since we won't be receiving any PAUSE frames
1926 * anyway. If the intent on the link partner was to have
1927 * flow control enabled, then by us enabling RX only, we
1928 * can at least receive pause frames and process them.
1929 * This is a good idea because in most cases, since we are
1930 * predominantly a server NIC, more times than not we will
1931 * be asked to delay transmission of packets than asking
1932 * our link partner to pause transmission of frames.
1934 else if((hw->original_fc == e1000_fc_none ||
1935 hw->original_fc == e1000_fc_tx_pause) ||
1936 hw->fc_strict_ieee) {
1937 hw->fc = e1000_fc_none;
1938 DEBUGOUT("Flow Control = NONE.\r\n");
1940 hw->fc = e1000_fc_rx_pause;
1941 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1944 /* Now we need to do one last check... If we auto-
1945 * negotiated to HALF DUPLEX, flow control should not be
1946 * enabled per IEEE 802.3 spec.
1948 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
1950 DEBUGOUT("Error getting link speed and duplex\n");
1954 if(duplex == HALF_DUPLEX)
1955 hw->fc = e1000_fc_none;
1957 /* Now we call a subroutine to actually force the MAC
1958 * controller to use the correct flow control settings.
1960 ret_val = e1000_force_mac_fc(hw);
1962 DEBUGOUT("Error forcing flow control settings\n");
1966 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
1969 return E1000_SUCCESS;
1972 /******************************************************************************
1973 * Checks to see if the link status of the hardware has changed.
1975 * hw - Struct containing variables accessed by shared code
1977 * Called by any function that needs to check the link status of the adapter.
1978 *****************************************************************************/
1980 e1000_check_for_link(struct e1000_hw *hw)
1986 uint32_t signal = 0;
1990 DEBUGFUNC("e1000_check_for_link");
1992 ctrl = E1000_READ_REG(hw, CTRL);
1993 status = E1000_READ_REG(hw, STATUS);
1995 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1996 * set when the optics detect a signal. On older adapters, it will be
1997 * cleared when there is a signal. This applies to fiber media only.
1999 if((hw->media_type == e1000_media_type_fiber) ||
2000 (hw->media_type == e1000_media_type_internal_serdes)) {
2001 rxcw = E1000_READ_REG(hw, RXCW);
2003 if(hw->media_type == e1000_media_type_fiber) {
2004 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2005 if(status & E1000_STATUS_LU)
2006 hw->get_link_status = FALSE;
2010 /* If we have a copper PHY then we only want to go out to the PHY
2011 * registers to see if Auto-Neg has completed and/or if our link
2012 * status has changed. The get_link_status flag will be set if we
2013 * receive a Link Status Change interrupt or we have Rx Sequence
2016 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2017 /* First we want to see if the MII Status Register reports
2018 * link. If so, then we want to get the current speed/duplex
2020 * Read the register twice since the link bit is sticky.
2022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2025 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2029 if(phy_data & MII_SR_LINK_STATUS) {
2030 hw->get_link_status = FALSE;
2031 /* Check if there was DownShift, must be checked immediately after
2033 e1000_check_downshift(hw);
2036 /* No link detected */
2037 e1000_config_dsp_after_link_change(hw, FALSE);
2041 /* If we are forcing speed/duplex, then we simply return since
2042 * we have already determined whether we have link or not.
2044 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2046 /* optimize the dsp settings for the igp phy */
2047 e1000_config_dsp_after_link_change(hw, TRUE);
2049 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2050 * have Si on board that is 82544 or newer, Auto
2051 * Speed Detection takes care of MAC speed/duplex
2052 * configuration. So we only need to configure Collision
2053 * Distance in the MAC. Otherwise, we need to force
2054 * speed/duplex on the MAC to the current PHY speed/duplex
2057 if(hw->mac_type >= e1000_82544)
2058 e1000_config_collision_dist(hw);
2060 ret_val = e1000_config_mac_to_phy(hw);
2062 DEBUGOUT("Error configuring MAC to PHY settings\n");
2067 /* Configure Flow Control now that Auto-Neg has completed. First, we
2068 * need to restore the desired flow control settings because we may
2069 * have had to re-autoneg with a different link partner.
2071 ret_val = e1000_config_fc_after_link_up(hw);
2073 DEBUGOUT("Error configuring flow control\n");
2077 /* At this point we know that we are on copper and we have
2078 * auto-negotiated link. These are conditions for checking the link
2079 * partner capability register. We use the link speed to determine if
2080 * TBI compatibility needs to be turned on or off. If the link is not
2081 * at gigabit speed, then TBI compatibility is not needed. If we are
2082 * at gigabit speed, we turn on TBI compatibility.
2084 if(hw->tbi_compatibility_en) {
2085 uint16_t speed, duplex;
2086 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2087 if(speed != SPEED_1000) {
2088 /* If link speed is not set to gigabit speed, we do not need
2089 * to enable TBI compatibility.
2091 if(hw->tbi_compatibility_on) {
2092 /* If we previously were in the mode, turn it off. */
2093 rctl = E1000_READ_REG(hw, RCTL);
2094 rctl &= ~E1000_RCTL_SBP;
2095 E1000_WRITE_REG(hw, RCTL, rctl);
2096 hw->tbi_compatibility_on = FALSE;
2099 /* If TBI compatibility is was previously off, turn it on. For
2100 * compatibility with a TBI link partner, we will store bad
2101 * packets. Some frames have an additional byte on the end and
2102 * will look like CRC errors to to the hardware.
2104 if(!hw->tbi_compatibility_on) {
2105 hw->tbi_compatibility_on = TRUE;
2106 rctl = E1000_READ_REG(hw, RCTL);
2107 rctl |= E1000_RCTL_SBP;
2108 E1000_WRITE_REG(hw, RCTL, rctl);
2113 /* If we don't have link (auto-negotiation failed or link partner cannot
2114 * auto-negotiate), the cable is plugged in (we have signal), and our
2115 * link partner is not trying to auto-negotiate with us (we are receiving
2116 * idles or data), we need to force link up. We also need to give
2117 * auto-negotiation time to complete, in case the cable was just plugged
2118 * in. The autoneg_failed flag does this.
2120 else if((((hw->media_type == e1000_media_type_fiber) &&
2121 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2122 (hw->media_type == e1000_media_type_internal_serdes)) &&
2123 (!(status & E1000_STATUS_LU)) &&
2124 (!(rxcw & E1000_RXCW_C))) {
2125 if(hw->autoneg_failed == 0) {
2126 hw->autoneg_failed = 1;
2129 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2131 /* Disable auto-negotiation in the TXCW register */
2132 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2134 /* Force link-up and also force full-duplex. */
2135 ctrl = E1000_READ_REG(hw, CTRL);
2136 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2137 E1000_WRITE_REG(hw, CTRL, ctrl);
2139 /* Configure Flow Control after forcing link up. */
2140 ret_val = e1000_config_fc_after_link_up(hw);
2142 DEBUGOUT("Error configuring flow control\n");
2146 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2147 * auto-negotiation in the TXCW register and disable forced link in the
2148 * Device Control register in an attempt to auto-negotiate with our link
2151 else if(((hw->media_type == e1000_media_type_fiber) ||
2152 (hw->media_type == e1000_media_type_internal_serdes)) &&
2153 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2154 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2155 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2156 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2158 hw->serdes_link_down = FALSE;
2160 /* If we force link for non-auto-negotiation switch, check link status
2161 * based on MAC synchronization for internal serdes media type.
2163 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2164 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2165 /* SYNCH bit and IV bit are sticky. */
2167 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2168 if(!(rxcw & E1000_RXCW_IV)) {
2169 hw->serdes_link_down = FALSE;
2170 DEBUGOUT("SERDES: Link is up.\n");
2173 hw->serdes_link_down = TRUE;
2174 DEBUGOUT("SERDES: Link is down.\n");
2177 if((hw->media_type == e1000_media_type_internal_serdes) &&
2178 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2179 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2181 return E1000_SUCCESS;
2184 /******************************************************************************
2185 * Detects the current speed and duplex settings of the hardware.
2187 * hw - Struct containing variables accessed by shared code
2188 * speed - Speed of the connection
2189 * duplex - Duplex setting of the connection
2190 *****************************************************************************/
2192 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2200 DEBUGFUNC("e1000_get_speed_and_duplex");
2202 if(hw->mac_type >= e1000_82543) {
2203 status = E1000_READ_REG(hw, STATUS);
2204 if(status & E1000_STATUS_SPEED_1000) {
2205 *speed = SPEED_1000;
2206 DEBUGOUT("1000 Mbs, ");
2207 } else if(status & E1000_STATUS_SPEED_100) {
2209 DEBUGOUT("100 Mbs, ");
2212 DEBUGOUT("10 Mbs, ");
2215 if(status & E1000_STATUS_FD) {
2216 *duplex = FULL_DUPLEX;
2217 DEBUGOUT("Full Duplex\r\n");
2219 *duplex = HALF_DUPLEX;
2220 DEBUGOUT(" Half Duplex\r\n");
2223 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2224 *speed = SPEED_1000;
2225 *duplex = FULL_DUPLEX;
2228 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2229 * if it is operating at half duplex. Here we set the duplex settings to
2230 * match the duplex in the link partner's capabilities.
2232 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2233 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2237 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2238 *duplex = HALF_DUPLEX;
2240 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2243 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2244 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2245 *duplex = HALF_DUPLEX;
2249 return E1000_SUCCESS;
2252 /******************************************************************************
2253 * Blocks until autoneg completes or times out (~4.5 seconds)
2255 * hw - Struct containing variables accessed by shared code
2256 ******************************************************************************/
2258 e1000_wait_autoneg(struct e1000_hw *hw)
2264 DEBUGFUNC("e1000_wait_autoneg");
2265 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2267 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2268 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2269 /* Read the MII Status Register and wait for Auto-Neg
2270 * Complete bit to be set.
2272 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2275 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2278 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2279 return E1000_SUCCESS;
2283 return E1000_SUCCESS;
2286 /******************************************************************************
2287 * Raises the Management Data Clock
2289 * hw - Struct containing variables accessed by shared code
2290 * ctrl - Device control register's current value
2291 ******************************************************************************/
2293 e1000_raise_mdi_clk(struct e1000_hw *hw,
2296 /* Raise the clock input to the Management Data Clock (by setting the MDC
2297 * bit), and then delay 10 microseconds.
2299 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2300 E1000_WRITE_FLUSH(hw);
2304 /******************************************************************************
2305 * Lowers the Management Data Clock
2307 * hw - Struct containing variables accessed by shared code
2308 * ctrl - Device control register's current value
2309 ******************************************************************************/
2311 e1000_lower_mdi_clk(struct e1000_hw *hw,
2314 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2315 * bit), and then delay 10 microseconds.
2317 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2318 E1000_WRITE_FLUSH(hw);
2322 /******************************************************************************
2323 * Shifts data bits out to the PHY
2325 * hw - Struct containing variables accessed by shared code
2326 * data - Data to send out to the PHY
2327 * count - Number of bits to shift out
2329 * Bits are shifted out in MSB to LSB order.
2330 ******************************************************************************/
2332 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2339 /* We need to shift "count" number of bits out to the PHY. So, the value
2340 * in the "data" parameter will be shifted out to the PHY one bit at a
2341 * time. In order to do this, "data" must be broken down into bits.
2344 mask <<= (count - 1);
2346 ctrl = E1000_READ_REG(hw, CTRL);
2348 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2349 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2352 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2353 * then raising and lowering the Management Data Clock. A "0" is
2354 * shifted out to the PHY by setting the MDIO bit to "0" and then
2355 * raising and lowering the clock.
2357 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2358 else ctrl &= ~E1000_CTRL_MDIO;
2360 E1000_WRITE_REG(hw, CTRL, ctrl);
2361 E1000_WRITE_FLUSH(hw);
2365 e1000_raise_mdi_clk(hw, &ctrl);
2366 e1000_lower_mdi_clk(hw, &ctrl);
2372 /******************************************************************************
2373 * Shifts data bits in from the PHY
2375 * hw - Struct containing variables accessed by shared code
2377 * Bits are shifted in in MSB to LSB order.
2378 ******************************************************************************/
2380 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2386 /* In order to read a register from the PHY, we need to shift in a total
2387 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2388 * to avoid contention on the MDIO pin when a read operation is performed.
2389 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2390 * by raising the input to the Management Data Clock (setting the MDC bit),
2391 * and then reading the value of the MDIO bit.
2393 ctrl = E1000_READ_REG(hw, CTRL);
2395 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2396 ctrl &= ~E1000_CTRL_MDIO_DIR;
2397 ctrl &= ~E1000_CTRL_MDIO;
2399 E1000_WRITE_REG(hw, CTRL, ctrl);
2400 E1000_WRITE_FLUSH(hw);
2402 /* Raise and Lower the clock before reading in the data. This accounts for
2403 * the turnaround bits. The first clock occurred when we clocked out the
2404 * last bit of the Register Address.
2406 e1000_raise_mdi_clk(hw, &ctrl);
2407 e1000_lower_mdi_clk(hw, &ctrl);
2409 for(data = 0, i = 0; i < 16; i++) {
2411 e1000_raise_mdi_clk(hw, &ctrl);
2412 ctrl = E1000_READ_REG(hw, CTRL);
2413 /* Check to see if we shifted in a "1". */
2414 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2415 e1000_lower_mdi_clk(hw, &ctrl);
2418 e1000_raise_mdi_clk(hw, &ctrl);
2419 e1000_lower_mdi_clk(hw, &ctrl);
2424 /*****************************************************************************
2425 * Reads the value from a PHY register, if the value is on a specific non zero
2426 * page, sets the page first.
2427 * hw - Struct containing variables accessed by shared code
2428 * reg_addr - address of the PHY register to read
2429 ******************************************************************************/
2431 e1000_read_phy_reg(struct e1000_hw *hw,
2437 DEBUGFUNC("e1000_read_phy_reg");
2439 if(hw->phy_type == e1000_phy_igp &&
2440 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2441 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2442 (uint16_t)reg_addr);
2447 ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2454 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2460 const uint32_t phy_addr = 1;
2462 DEBUGFUNC("e1000_read_phy_reg_ex");
2464 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2465 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2466 return -E1000_ERR_PARAM;
2469 if(hw->mac_type > e1000_82543) {
2470 /* Set up Op-code, Phy Address, and register address in the MDI
2471 * Control register. The MAC will take care of interfacing with the
2472 * PHY to retrieve the desired data.
2474 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2475 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2476 (E1000_MDIC_OP_READ));
2478 E1000_WRITE_REG(hw, MDIC, mdic);
2480 /* Poll the ready bit to see if the MDI read completed */
2481 for(i = 0; i < 64; i++) {
2483 mdic = E1000_READ_REG(hw, MDIC);
2484 if(mdic & E1000_MDIC_READY) break;
2486 if(!(mdic & E1000_MDIC_READY)) {
2487 DEBUGOUT("MDI Read did not complete\n");
2488 return -E1000_ERR_PHY;
2490 if(mdic & E1000_MDIC_ERROR) {
2491 DEBUGOUT("MDI Error\n");
2492 return -E1000_ERR_PHY;
2494 *phy_data = (uint16_t) mdic;
2496 /* We must first send a preamble through the MDIO pin to signal the
2497 * beginning of an MII instruction. This is done by sending 32
2498 * consecutive "1" bits.
2500 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2502 /* Now combine the next few fields that are required for a read
2503 * operation. We use this method instead of calling the
2504 * e1000_shift_out_mdi_bits routine five different times. The format of
2505 * a MII read instruction consists of a shift out of 14 bits and is
2506 * defined as follows:
2507 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2508 * followed by a shift in of 18 bits. This first two bits shifted in
2509 * are TurnAround bits used to avoid contention on the MDIO pin when a
2510 * READ operation is performed. These two bits are thrown away
2511 * followed by a shift in of 16 bits which contains the desired data.
2513 mdic = ((reg_addr) | (phy_addr << 5) |
2514 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2516 e1000_shift_out_mdi_bits(hw, mdic, 14);
2518 /* Now that we've shifted out the read command to the MII, we need to
2519 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2522 *phy_data = e1000_shift_in_mdi_bits(hw);
2524 return E1000_SUCCESS;
2527 /******************************************************************************
2528 * Writes a value to a PHY register
2530 * hw - Struct containing variables accessed by shared code
2531 * reg_addr - address of the PHY register to write
2532 * data - data to write to the PHY
2533 ******************************************************************************/
2535 e1000_write_phy_reg(struct e1000_hw *hw,
2541 DEBUGFUNC("e1000_write_phy_reg");
2543 if(hw->phy_type == e1000_phy_igp &&
2544 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2545 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2546 (uint16_t)reg_addr);
2551 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2558 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2564 const uint32_t phy_addr = 1;
2566 DEBUGFUNC("e1000_write_phy_reg_ex");
2568 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2569 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2570 return -E1000_ERR_PARAM;
2573 if(hw->mac_type > e1000_82543) {
2574 /* Set up Op-code, Phy Address, register address, and data intended
2575 * for the PHY register in the MDI Control register. The MAC will take
2576 * care of interfacing with the PHY to send the desired data.
2578 mdic = (((uint32_t) phy_data) |
2579 (reg_addr << E1000_MDIC_REG_SHIFT) |
2580 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2581 (E1000_MDIC_OP_WRITE));
2583 E1000_WRITE_REG(hw, MDIC, mdic);
2585 /* Poll the ready bit to see if the MDI read completed */
2586 for(i = 0; i < 640; i++) {
2588 mdic = E1000_READ_REG(hw, MDIC);
2589 if(mdic & E1000_MDIC_READY) break;
2591 if(!(mdic & E1000_MDIC_READY)) {
2592 DEBUGOUT("MDI Write did not complete\n");
2593 return -E1000_ERR_PHY;
2596 /* We'll need to use the SW defined pins to shift the write command
2597 * out to the PHY. We first send a preamble to the PHY to signal the
2598 * beginning of the MII instruction. This is done by sending 32
2599 * consecutive "1" bits.
2601 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2603 /* Now combine the remaining required fields that will indicate a
2604 * write operation. We use this method instead of calling the
2605 * e1000_shift_out_mdi_bits routine for each field in the command. The
2606 * format of a MII write instruction is as follows:
2607 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2609 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2610 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2612 mdic |= (uint32_t) phy_data;
2614 e1000_shift_out_mdi_bits(hw, mdic, 32);
2617 return E1000_SUCCESS;
2620 /******************************************************************************
2621 * Returns the PHY to the power-on reset state
2623 * hw - Struct containing variables accessed by shared code
2624 ******************************************************************************/
2626 e1000_phy_hw_reset(struct e1000_hw *hw)
2628 uint32_t ctrl, ctrl_ext;
2631 DEBUGFUNC("e1000_phy_hw_reset");
2633 DEBUGOUT("Resetting Phy...\n");
2635 if(hw->mac_type > e1000_82543) {
2636 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2637 * bit. Then, take it out of reset.
2639 ctrl = E1000_READ_REG(hw, CTRL);
2640 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2641 E1000_WRITE_FLUSH(hw);
2643 E1000_WRITE_REG(hw, CTRL, ctrl);
2644 E1000_WRITE_FLUSH(hw);
2646 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2647 * bit to put the PHY into reset. Then, take it out of reset.
2649 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2650 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2651 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2652 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2653 E1000_WRITE_FLUSH(hw);
2655 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2656 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2657 E1000_WRITE_FLUSH(hw);
2661 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2662 /* Configure activity LED after PHY reset */
2663 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2664 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2665 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2666 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2670 /******************************************************************************
2673 * hw - Struct containing variables accessed by shared code
2675 * Sets bit 15 of the MII Control regiser
2676 ******************************************************************************/
2678 e1000_phy_reset(struct e1000_hw *hw)
2683 DEBUGFUNC("e1000_phy_reset");
2685 if(hw->mac_type != e1000_82541_rev_2) {
2686 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2690 phy_data |= MII_CR_RESET;
2691 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2696 } else e1000_phy_hw_reset(hw);
2698 if(hw->phy_type == e1000_phy_igp)
2699 e1000_phy_init_script(hw);
2701 return E1000_SUCCESS;
2704 /******************************************************************************
2705 * Probes the expected PHY address for known PHY IDs
2707 * hw - Struct containing variables accessed by shared code
2708 ******************************************************************************/
2710 e1000_detect_gig_phy(struct e1000_hw *hw)
2712 int32_t phy_init_status, ret_val;
2713 uint16_t phy_id_high, phy_id_low;
2714 boolean_t match = FALSE;
2716 DEBUGFUNC("e1000_detect_gig_phy");
2718 /* Read the PHY ID Registers to identify which PHY is onboard. */
2719 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2723 hw->phy_id = (uint32_t) (phy_id_high << 16);
2725 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2729 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2730 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2732 switch(hw->mac_type) {
2734 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2737 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2741 case e1000_82545_rev_3:
2743 case e1000_82546_rev_3:
2744 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2747 case e1000_82541_rev_2:
2749 case e1000_82547_rev_2:
2750 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
2753 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2754 return -E1000_ERR_CONFIG;
2756 phy_init_status = e1000_set_phy_type(hw);
2758 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2759 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2760 return E1000_SUCCESS;
2762 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2763 return -E1000_ERR_PHY;
2766 /******************************************************************************
2767 * Resets the PHY's DSP
2769 * hw - Struct containing variables accessed by shared code
2770 ******************************************************************************/
2772 e1000_phy_reset_dsp(struct e1000_hw *hw)
2775 DEBUGFUNC("e1000_phy_reset_dsp");
2778 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
2780 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
2782 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
2784 ret_val = E1000_SUCCESS;
2790 /******************************************************************************
2791 * Get PHY information from various PHY registers for igp PHY only.
2793 * hw - Struct containing variables accessed by shared code
2794 * phy_info - PHY information structure
2795 ******************************************************************************/
2797 e1000_phy_igp_get_info(struct e1000_hw *hw,
2798 struct e1000_phy_info *phy_info)
2801 uint16_t phy_data, polarity, min_length, max_length, average;
2803 DEBUGFUNC("e1000_phy_igp_get_info");
2805 /* The downshift status is checked only once, after link is established,
2806 * and it stored in the hw->speed_downgraded parameter. */
2807 phy_info->downshift = hw->speed_downgraded;
2809 /* IGP01E1000 does not need to support it. */
2810 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2812 /* IGP01E1000 always correct polarity reversal */
2813 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
2815 /* Check polarity status */
2816 ret_val = e1000_check_polarity(hw, &polarity);
2820 phy_info->cable_polarity = polarity;
2822 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
2826 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
2827 IGP01E1000_PSSR_MDIX_SHIFT;
2829 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
2830 IGP01E1000_PSSR_SPEED_1000MBPS) {
2831 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2832 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2836 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2837 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2838 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2839 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2841 /* Get cable length */
2842 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
2846 /* transalte to old method */
2847 average = (max_length + min_length) / 2;
2849 if(average <= e1000_igp_cable_length_50)
2850 phy_info->cable_length = e1000_cable_length_50;
2851 else if(average <= e1000_igp_cable_length_80)
2852 phy_info->cable_length = e1000_cable_length_50_80;
2853 else if(average <= e1000_igp_cable_length_110)
2854 phy_info->cable_length = e1000_cable_length_80_110;
2855 else if(average <= e1000_igp_cable_length_140)
2856 phy_info->cable_length = e1000_cable_length_110_140;
2858 phy_info->cable_length = e1000_cable_length_140;
2861 return E1000_SUCCESS;
2864 /******************************************************************************
2865 * Get PHY information from various PHY registers fot m88 PHY only.
2867 * hw - Struct containing variables accessed by shared code
2868 * phy_info - PHY information structure
2869 ******************************************************************************/
2871 e1000_phy_m88_get_info(struct e1000_hw *hw,
2872 struct e1000_phy_info *phy_info)
2875 uint16_t phy_data, polarity;
2877 DEBUGFUNC("e1000_phy_m88_get_info");
2879 /* The downshift status is checked only once, after link is established,
2880 * and it stored in the hw->speed_downgraded parameter. */
2881 phy_info->downshift = hw->speed_downgraded;
2883 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2887 phy_info->extended_10bt_distance =
2888 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2889 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2890 phy_info->polarity_correction =
2891 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2892 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2894 /* Check polarity status */
2895 ret_val = e1000_check_polarity(hw, &polarity);
2899 phy_info->cable_polarity = polarity;
2901 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2905 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2906 M88E1000_PSSR_MDIX_SHIFT;
2908 if(phy_data & M88E1000_PSSR_1000MBS) {
2909 /* Cable Length Estimation and Local/Remote Receiver Informatoion
2910 * are only valid at 1000 Mbps
2912 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2913 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2915 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2919 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2920 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2922 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2923 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2926 return E1000_SUCCESS;
2929 /******************************************************************************
2930 * Get PHY information from various PHY registers
2932 * hw - Struct containing variables accessed by shared code
2933 * phy_info - PHY information structure
2934 ******************************************************************************/
2936 e1000_phy_get_info(struct e1000_hw *hw,
2937 struct e1000_phy_info *phy_info)
2942 DEBUGFUNC("e1000_phy_get_info");
2944 phy_info->cable_length = e1000_cable_length_undefined;
2945 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
2946 phy_info->cable_polarity = e1000_rev_polarity_undefined;
2947 phy_info->downshift = e1000_downshift_undefined;
2948 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
2949 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
2950 phy_info->local_rx = e1000_1000t_rx_status_undefined;
2951 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
2953 if(hw->media_type != e1000_media_type_copper) {
2954 DEBUGOUT("PHY info is only valid for copper media\n");
2955 return -E1000_ERR_CONFIG;
2958 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2962 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2966 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
2967 DEBUGOUT("PHY info is only valid if link is up\n");
2968 return -E1000_ERR_CONFIG;
2971 if(hw->phy_type == e1000_phy_igp)
2972 return e1000_phy_igp_get_info(hw, phy_info);
2974 return e1000_phy_m88_get_info(hw, phy_info);
2978 e1000_validate_mdi_setting(struct e1000_hw *hw)
2980 DEBUGFUNC("e1000_validate_mdi_settings");
2982 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
2983 DEBUGOUT("Invalid MDI setting detected\n");
2985 return -E1000_ERR_CONFIG;
2987 return E1000_SUCCESS;
2991 /******************************************************************************
2992 * Sets up eeprom variables in the hw struct. Must be called after mac_type
2995 * hw - Struct containing variables accessed by shared code
2996 *****************************************************************************/
2998 e1000_init_eeprom_params(struct e1000_hw *hw)
3000 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3001 uint32_t eecd = E1000_READ_REG(hw, EECD);
3002 uint16_t eeprom_size;
3004 DEBUGFUNC("e1000_init_eeprom_params");
3006 switch (hw->mac_type) {
3007 case e1000_82542_rev2_0:
3008 case e1000_82542_rev2_1:
3011 eeprom->type = e1000_eeprom_microwire;
3012 eeprom->word_size = 64;
3013 eeprom->opcode_bits = 3;
3014 eeprom->address_bits = 6;
3015 eeprom->delay_usec = 50;
3019 case e1000_82545_rev_3:
3021 case e1000_82546_rev_3:
3022 eeprom->type = e1000_eeprom_microwire;
3023 eeprom->opcode_bits = 3;
3024 eeprom->delay_usec = 50;
3025 if(eecd & E1000_EECD_SIZE) {
3026 eeprom->word_size = 256;
3027 eeprom->address_bits = 8;
3029 eeprom->word_size = 64;
3030 eeprom->address_bits = 6;
3034 case e1000_82541_rev_2:
3036 case e1000_82547_rev_2:
3037 if (eecd & E1000_EECD_TYPE) {
3038 eeprom->type = e1000_eeprom_spi;
3039 eeprom->opcode_bits = 8;
3040 eeprom->delay_usec = 1;
3041 if (eecd & E1000_EECD_ADDR_BITS) {
3042 eeprom->page_size = 32;
3043 eeprom->address_bits = 16;
3045 eeprom->page_size = 8;
3046 eeprom->address_bits = 8;
3049 eeprom->type = e1000_eeprom_microwire;
3050 eeprom->opcode_bits = 3;
3051 eeprom->delay_usec = 50;
3052 if (eecd & E1000_EECD_ADDR_BITS) {
3053 eeprom->word_size = 256;
3054 eeprom->address_bits = 8;
3056 eeprom->word_size = 64;
3057 eeprom->address_bits = 6;
3065 if (eeprom->type == e1000_eeprom_spi) {
3066 eeprom->word_size = 64;
3067 if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
3068 eeprom_size &= EEPROM_SIZE_MASK;
3070 switch (eeprom_size) {
3071 case EEPROM_SIZE_16KB:
3072 eeprom->word_size = 8192;
3074 case EEPROM_SIZE_8KB:
3075 eeprom->word_size = 4096;
3077 case EEPROM_SIZE_4KB:
3078 eeprom->word_size = 2048;
3080 case EEPROM_SIZE_2KB:
3081 eeprom->word_size = 1024;
3083 case EEPROM_SIZE_1KB:
3084 eeprom->word_size = 512;
3086 case EEPROM_SIZE_512B:
3087 eeprom->word_size = 256;
3089 case EEPROM_SIZE_128B:
3091 eeprom->word_size = 64;
3098 /******************************************************************************
3099 * Raises the EEPROM's clock input.
3101 * hw - Struct containing variables accessed by shared code
3102 * eecd - EECD's current value
3103 *****************************************************************************/
3105 e1000_raise_ee_clk(struct e1000_hw *hw,
3108 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3109 * wait <delay> microseconds.
3111 *eecd = *eecd | E1000_EECD_SK;
3112 E1000_WRITE_REG(hw, EECD, *eecd);
3113 E1000_WRITE_FLUSH(hw);
3114 udelay(hw->eeprom.delay_usec);
3117 /******************************************************************************
3118 * Lowers the EEPROM's clock input.
3120 * hw - Struct containing variables accessed by shared code
3121 * eecd - EECD's current value
3122 *****************************************************************************/
3124 e1000_lower_ee_clk(struct e1000_hw *hw,
3127 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3128 * wait 50 microseconds.
3130 *eecd = *eecd & ~E1000_EECD_SK;
3131 E1000_WRITE_REG(hw, EECD, *eecd);
3132 E1000_WRITE_FLUSH(hw);
3133 udelay(hw->eeprom.delay_usec);
3136 /******************************************************************************
3137 * Shift data bits out to the EEPROM.
3139 * hw - Struct containing variables accessed by shared code
3140 * data - data to send to the EEPROM
3141 * count - number of bits to shift out
3142 *****************************************************************************/
3144 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3148 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3152 /* We need to shift "count" bits out to the EEPROM. So, value in the
3153 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3154 * In order to do this, "data" must be broken down into bits.
3156 mask = 0x01 << (count - 1);
3157 eecd = E1000_READ_REG(hw, EECD);
3158 if (eeprom->type == e1000_eeprom_microwire) {
3159 eecd &= ~E1000_EECD_DO;
3160 } else if (eeprom->type == e1000_eeprom_spi) {
3161 eecd |= E1000_EECD_DO;
3164 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3165 * and then raising and then lowering the clock (the SK bit controls
3166 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3167 * by setting "DI" to "0" and then raising and then lowering the clock.
3169 eecd &= ~E1000_EECD_DI;
3172 eecd |= E1000_EECD_DI;
3174 E1000_WRITE_REG(hw, EECD, eecd);
3175 E1000_WRITE_FLUSH(hw);
3177 udelay(eeprom->delay_usec);
3179 e1000_raise_ee_clk(hw, &eecd);
3180 e1000_lower_ee_clk(hw, &eecd);
3186 /* We leave the "DI" bit set to "0" when we leave this routine. */
3187 eecd &= ~E1000_EECD_DI;
3188 E1000_WRITE_REG(hw, EECD, eecd);
3191 /******************************************************************************
3192 * Shift data bits in from the EEPROM
3194 * hw - Struct containing variables accessed by shared code
3195 *****************************************************************************/
3197 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3204 /* In order to read a register from the EEPROM, we need to shift 'count'
3205 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3206 * input to the EEPROM (setting the SK bit), and then reading the value of
3207 * the "DO" bit. During this "shifting in" process the "DI" bit should
3211 eecd = E1000_READ_REG(hw, EECD);
3213 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3216 for(i = 0; i < count; i++) {
3218 e1000_raise_ee_clk(hw, &eecd);
3220 eecd = E1000_READ_REG(hw, EECD);
3222 eecd &= ~(E1000_EECD_DI);
3223 if(eecd & E1000_EECD_DO)
3226 e1000_lower_ee_clk(hw, &eecd);
3232 /******************************************************************************
3233 * Prepares EEPROM for access
3235 * hw - Struct containing variables accessed by shared code
3237 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3238 * function should be called before issuing a command to the EEPROM.
3239 *****************************************************************************/
3241 e1000_acquire_eeprom(struct e1000_hw *hw)
3243 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3246 DEBUGFUNC("e1000_acquire_eeprom");
3248 eecd = E1000_READ_REG(hw, EECD);
3250 /* Request EEPROM Access */
3251 if(hw->mac_type > e1000_82544) {
3252 eecd |= E1000_EECD_REQ;
3253 E1000_WRITE_REG(hw, EECD, eecd);
3254 eecd = E1000_READ_REG(hw, EECD);
3255 while((!(eecd & E1000_EECD_GNT)) &&
3256 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3259 eecd = E1000_READ_REG(hw, EECD);
3261 if(!(eecd & E1000_EECD_GNT)) {
3262 eecd &= ~E1000_EECD_REQ;
3263 E1000_WRITE_REG(hw, EECD, eecd);
3264 DEBUGOUT("Could not acquire EEPROM grant\n");
3265 return -E1000_ERR_EEPROM;
3269 /* Setup EEPROM for Read/Write */
3271 if (eeprom->type == e1000_eeprom_microwire) {
3272 /* Clear SK and DI */
3273 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3274 E1000_WRITE_REG(hw, EECD, eecd);
3277 eecd |= E1000_EECD_CS;
3278 E1000_WRITE_REG(hw, EECD, eecd);
3279 } else if (eeprom->type == e1000_eeprom_spi) {
3280 /* Clear SK and CS */
3281 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3282 E1000_WRITE_REG(hw, EECD, eecd);
3286 return E1000_SUCCESS;
3289 /******************************************************************************
3290 * Returns EEPROM to a "standby" state
3292 * hw - Struct containing variables accessed by shared code
3293 *****************************************************************************/
3295 e1000_standby_eeprom(struct e1000_hw *hw)
3297 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3300 eecd = E1000_READ_REG(hw, EECD);
3302 if(eeprom->type == e1000_eeprom_microwire) {
3303 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3304 E1000_WRITE_REG(hw, EECD, eecd);
3305 E1000_WRITE_FLUSH(hw);
3306 udelay(eeprom->delay_usec);
3309 eecd |= E1000_EECD_SK;
3310 E1000_WRITE_REG(hw, EECD, eecd);
3311 E1000_WRITE_FLUSH(hw);
3312 udelay(eeprom->delay_usec);
3315 eecd |= E1000_EECD_CS;
3316 E1000_WRITE_REG(hw, EECD, eecd);
3317 E1000_WRITE_FLUSH(hw);
3318 udelay(eeprom->delay_usec);
3321 eecd &= ~E1000_EECD_SK;
3322 E1000_WRITE_REG(hw, EECD, eecd);
3323 E1000_WRITE_FLUSH(hw);
3324 udelay(eeprom->delay_usec);
3325 } else if(eeprom->type == e1000_eeprom_spi) {
3326 /* Toggle CS to flush commands */
3327 eecd |= E1000_EECD_CS;
3328 E1000_WRITE_REG(hw, EECD, eecd);
3329 E1000_WRITE_FLUSH(hw);
3330 udelay(eeprom->delay_usec);
3331 eecd &= ~E1000_EECD_CS;
3332 E1000_WRITE_REG(hw, EECD, eecd);
3333 E1000_WRITE_FLUSH(hw);
3334 udelay(eeprom->delay_usec);
3338 /******************************************************************************
3339 * Terminates a command by inverting the EEPROM's chip select pin
3341 * hw - Struct containing variables accessed by shared code
3342 *****************************************************************************/
3344 e1000_release_eeprom(struct e1000_hw *hw)
3348 DEBUGFUNC("e1000_release_eeprom");
3350 eecd = E1000_READ_REG(hw, EECD);
3352 if (hw->eeprom.type == e1000_eeprom_spi) {
3353 eecd |= E1000_EECD_CS; /* Pull CS high */
3354 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3356 E1000_WRITE_REG(hw, EECD, eecd);
3358 udelay(hw->eeprom.delay_usec);
3359 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3360 /* cleanup eeprom */
3362 /* CS on Microwire is active-high */
3363 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3365 E1000_WRITE_REG(hw, EECD, eecd);
3367 /* Rising edge of clock */
3368 eecd |= E1000_EECD_SK;
3369 E1000_WRITE_REG(hw, EECD, eecd);
3370 E1000_WRITE_FLUSH(hw);
3371 udelay(hw->eeprom.delay_usec);
3373 /* Falling edge of clock */
3374 eecd &= ~E1000_EECD_SK;
3375 E1000_WRITE_REG(hw, EECD, eecd);
3376 E1000_WRITE_FLUSH(hw);
3377 udelay(hw->eeprom.delay_usec);
3380 /* Stop requesting EEPROM access */
3381 if(hw->mac_type > e1000_82544) {
3382 eecd &= ~E1000_EECD_REQ;
3383 E1000_WRITE_REG(hw, EECD, eecd);
3387 /******************************************************************************
3388 * Reads a 16 bit word from the EEPROM.
3390 * hw - Struct containing variables accessed by shared code
3391 *****************************************************************************/
3393 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3395 uint16_t retry_count = 0;
3396 uint8_t spi_stat_reg;
3398 DEBUGFUNC("e1000_spi_eeprom_ready");
3400 /* Read "Status Register" repeatedly until the LSB is cleared. The
3401 * EEPROM will signal that the command has been completed by clearing
3402 * bit 0 of the internal status register. If it's not cleared within
3403 * 5 milliseconds, then error out.
3407 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3408 hw->eeprom.opcode_bits);
3409 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3410 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3416 e1000_standby_eeprom(hw);
3417 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3419 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3420 * only 0-5mSec on 5V devices)
3422 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3423 DEBUGOUT("SPI EEPROM Status error\n");
3424 return -E1000_ERR_EEPROM;
3427 return E1000_SUCCESS;
3430 /******************************************************************************
3431 * Reads a 16 bit word from the EEPROM.
3433 * hw - Struct containing variables accessed by shared code
3434 * offset - offset of word in the EEPROM to read
3435 * data - word read from the EEPROM
3436 * words - number of words to read
3437 *****************************************************************************/
3439 e1000_read_eeprom(struct e1000_hw *hw,
3444 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3447 DEBUGFUNC("e1000_read_eeprom");
3448 /* A check for invalid values: offset too large, too many words, and not
3451 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3453 DEBUGOUT("\"words\" parameter out of bounds\n");
3454 return -E1000_ERR_EEPROM;
3457 /* Prepare the EEPROM for reading */
3458 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3459 return -E1000_ERR_EEPROM;
3461 if(eeprom->type == e1000_eeprom_spi) {
3463 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3465 if(e1000_spi_eeprom_ready(hw)) {
3466 e1000_release_eeprom(hw);
3467 return -E1000_ERR_EEPROM;
3470 e1000_standby_eeprom(hw);
3472 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3473 if((eeprom->address_bits == 8) && (offset >= 128))
3474 read_opcode |= EEPROM_A8_OPCODE_SPI;
3476 /* Send the READ command (opcode + addr) */
3477 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3478 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3480 /* Read the data. The address of the eeprom internally increments with
3481 * each byte (spi) being read, saving on the overhead of eeprom setup
3482 * and tear-down. The address counter will roll over if reading beyond
3483 * the size of the eeprom, thus allowing the entire memory to be read
3484 * starting from any offset. */
3485 for (i = 0; i < words; i++) {
3486 word_in = e1000_shift_in_ee_bits(hw, 16);
3487 data[i] = (word_in >> 8) | (word_in << 8);
3489 } else if(eeprom->type == e1000_eeprom_microwire) {
3490 for (i = 0; i < words; i++) {
3491 /* Send the READ command (opcode + addr) */
3492 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3493 eeprom->opcode_bits);
3494 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3495 eeprom->address_bits);
3497 /* Read the data. For microwire, each word requires the overhead
3498 * of eeprom setup and tear-down. */
3499 data[i] = e1000_shift_in_ee_bits(hw, 16);
3500 e1000_standby_eeprom(hw);
3504 /* End this read operation */
3505 e1000_release_eeprom(hw);
3507 return E1000_SUCCESS;
3510 /******************************************************************************
3511 * Verifies that the EEPROM has a valid checksum
3513 * hw - Struct containing variables accessed by shared code
3515 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3516 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3518 *****************************************************************************/
3520 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3522 uint16_t checksum = 0;
3523 uint16_t i, eeprom_data;
3525 DEBUGFUNC("e1000_validate_eeprom_checksum");
3527 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3528 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3529 DEBUGOUT("EEPROM Read Error\n");
3530 return -E1000_ERR_EEPROM;
3532 checksum += eeprom_data;
3535 if(checksum == (uint16_t) EEPROM_SUM)
3536 return E1000_SUCCESS;
3538 DEBUGOUT("EEPROM Checksum Invalid\n");
3539 return -E1000_ERR_EEPROM;
3543 /******************************************************************************
3544 * Calculates the EEPROM checksum and writes it to the EEPROM
3546 * hw - Struct containing variables accessed by shared code
3548 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3549 * Writes the difference to word offset 63 of the EEPROM.
3550 *****************************************************************************/
3552 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3554 uint16_t checksum = 0;
3555 uint16_t i, eeprom_data;
3557 DEBUGFUNC("e1000_update_eeprom_checksum");
3559 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3560 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3561 DEBUGOUT("EEPROM Read Error\n");
3562 return -E1000_ERR_EEPROM;
3564 checksum += eeprom_data;
3566 checksum = (uint16_t) EEPROM_SUM - checksum;
3567 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3568 DEBUGOUT("EEPROM Write Error\n");
3569 return -E1000_ERR_EEPROM;
3571 return E1000_SUCCESS;
3574 /******************************************************************************
3575 * Parent function for writing words to the different EEPROM types.
3577 * hw - Struct containing variables accessed by shared code
3578 * offset - offset within the EEPROM to be written to
3579 * words - number of words to write
3580 * data - 16 bit word to be written to the EEPROM
3582 * If e1000_update_eeprom_checksum is not called after this function, the
3583 * EEPROM will most likely contain an invalid checksum.
3584 *****************************************************************************/
3586 e1000_write_eeprom(struct e1000_hw *hw,
3591 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3594 DEBUGFUNC("e1000_write_eeprom");
3596 /* A check for invalid values: offset too large, too many words, and not
3599 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3601 DEBUGOUT("\"words\" parameter out of bounds\n");
3602 return -E1000_ERR_EEPROM;
3605 /* Prepare the EEPROM for writing */
3606 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3607 return -E1000_ERR_EEPROM;
3609 if(eeprom->type == e1000_eeprom_microwire) {
3610 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3612 status = e1000_write_eeprom_spi(hw, offset, words, data);
3616 /* Done with writing */
3617 e1000_release_eeprom(hw);
3622 /******************************************************************************
3623 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3625 * hw - Struct containing variables accessed by shared code
3626 * offset - offset within the EEPROM to be written to
3627 * words - number of words to write
3628 * data - pointer to array of 8 bit words to be written to the EEPROM
3630 *****************************************************************************/
3632 e1000_write_eeprom_spi(struct e1000_hw *hw,
3637 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3640 DEBUGFUNC("e1000_write_eeprom_spi");
3642 while (widx < words) {
3643 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
3645 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3647 e1000_standby_eeprom(hw);
3649 /* Send the WRITE ENABLE command (8 bit opcode ) */
3650 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3651 eeprom->opcode_bits);
3653 e1000_standby_eeprom(hw);
3655 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3656 if((eeprom->address_bits == 8) && (offset >= 128))
3657 write_opcode |= EEPROM_A8_OPCODE_SPI;
3659 /* Send the Write command (8-bit opcode + addr) */
3660 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3662 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
3663 eeprom->address_bits);
3667 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3668 while (widx < words) {
3669 uint16_t word_out = data[widx];
3670 word_out = (word_out >> 8) | (word_out << 8);
3671 e1000_shift_out_ee_bits(hw, word_out, 16);
3674 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3675 * operation, while the smaller eeproms are capable of an 8-byte
3676 * PAGE WRITE operation. Break the inner loop to pass new address
3678 if((((offset + widx)*2) % eeprom->page_size) == 0) {
3679 e1000_standby_eeprom(hw);
3685 return E1000_SUCCESS;
3688 /******************************************************************************
3689 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3691 * hw - Struct containing variables accessed by shared code
3692 * offset - offset within the EEPROM to be written to
3693 * words - number of words to write
3694 * data - pointer to array of 16 bit words to be written to the EEPROM
3696 *****************************************************************************/
3698 e1000_write_eeprom_microwire(struct e1000_hw *hw,
3703 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3705 uint16_t words_written = 0;
3708 DEBUGFUNC("e1000_write_eeprom_microwire");
3710 /* Send the write enable command to the EEPROM (3-bit opcode plus
3711 * 6/8-bit dummy address beginning with 11). It's less work to include
3712 * the 11 of the dummy address as part of the opcode than it is to shift
3713 * it over the correct number of bits for the address. This puts the
3714 * EEPROM into write/erase mode.
3716 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
3717 (uint16_t)(eeprom->opcode_bits + 2));
3719 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3721 /* Prepare the EEPROM */
3722 e1000_standby_eeprom(hw);
3724 while (words_written < words) {
3725 /* Send the Write command (3-bit opcode + addr) */
3726 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
3727 eeprom->opcode_bits);
3729 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
3730 eeprom->address_bits);
3733 e1000_shift_out_ee_bits(hw, data[words_written], 16);
3735 /* Toggle the CS line. This in effect tells the EEPROM to execute
3736 * the previous command.
3738 e1000_standby_eeprom(hw);
3740 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
3741 * signal that the command has been completed by raising the DO signal.
3742 * If DO does not go high in 10 milliseconds, then error out.
3744 for(i = 0; i < 200; i++) {
3745 eecd = E1000_READ_REG(hw, EECD);
3746 if(eecd & E1000_EECD_DO) break;
3750 DEBUGOUT("EEPROM Write did not complete\n");
3751 return -E1000_ERR_EEPROM;
3754 /* Recover from write */
3755 e1000_standby_eeprom(hw);
3760 /* Send the write disable command to the EEPROM (3-bit opcode plus
3761 * 6/8-bit dummy address beginning with 10). It's less work to include
3762 * the 10 of the dummy address as part of the opcode than it is to shift
3763 * it over the correct number of bits for the address. This takes the
3764 * EEPROM out of write/erase mode.
3766 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
3767 (uint16_t)(eeprom->opcode_bits + 2));
3769 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3771 return E1000_SUCCESS;
3774 /******************************************************************************
3775 * Reads the adapter's part number from the EEPROM
3777 * hw - Struct containing variables accessed by shared code
3778 * part_num - Adapter's part number
3779 *****************************************************************************/
3781 e1000_read_part_num(struct e1000_hw *hw,
3784 uint16_t offset = EEPROM_PBA_BYTE_1;
3785 uint16_t eeprom_data;
3787 DEBUGFUNC("e1000_read_part_num");
3789 /* Get word 0 from EEPROM */
3790 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3791 DEBUGOUT("EEPROM Read Error\n");
3792 return -E1000_ERR_EEPROM;
3794 /* Save word 0 in upper half of part_num */
3795 *part_num = (uint32_t) (eeprom_data << 16);
3797 /* Get word 1 from EEPROM */
3798 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
3799 DEBUGOUT("EEPROM Read Error\n");
3800 return -E1000_ERR_EEPROM;
3802 /* Save word 1 in lower half of part_num */
3803 *part_num |= eeprom_data;
3805 return E1000_SUCCESS;
3808 /******************************************************************************
3809 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3810 * second function of dual function devices
3812 * hw - Struct containing variables accessed by shared code
3813 *****************************************************************************/
3815 e1000_read_mac_addr(struct e1000_hw * hw)
3818 uint16_t eeprom_data, i;
3820 DEBUGFUNC("e1000_read_mac_addr");
3822 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
3824 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3825 DEBUGOUT("EEPROM Read Error\n");
3826 return -E1000_ERR_EEPROM;
3828 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
3829 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
3831 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
3832 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
3833 hw->perm_mac_addr[5] ^= 0x01;
3835 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
3836 hw->mac_addr[i] = hw->perm_mac_addr[i];
3837 return E1000_SUCCESS;
3840 /******************************************************************************
3841 * Initializes receive address filters.
3843 * hw - Struct containing variables accessed by shared code
3845 * Places the MAC address in receive address register 0 and clears the rest
3846 * of the receive addresss registers. Clears the multicast table. Assumes
3847 * the receiver is in reset when the routine is called.
3848 *****************************************************************************/
3850 e1000_init_rx_addrs(struct e1000_hw *hw)
3854 DEBUGFUNC("e1000_init_rx_addrs");
3856 /* Setup the receive address. */
3857 DEBUGOUT("Programming MAC Address into RAR[0]\n");
3859 e1000_rar_set(hw, hw->mac_addr, 0);
3861 /* Zero out the other 15 receive addresses. */
3862 DEBUGOUT("Clearing RAR[1-15]\n");
3863 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
3864 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3865 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3869 /******************************************************************************
3870 * Updates the MAC's list of multicast addresses.
3872 * hw - Struct containing variables accessed by shared code
3873 * mc_addr_list - the list of new multicast addresses
3874 * mc_addr_count - number of addresses
3875 * pad - number of bytes between addresses in the list
3876 * rar_used_count - offset where to start adding mc addresses into the RAR's
3878 * The given list replaces any existing list. Clears the last 15 receive
3879 * address registers and the multicast table. Uses receive address registers
3880 * for the first 15 multicast addresses, and hashes the rest into the
3882 *****************************************************************************/
3884 e1000_mc_addr_list_update(struct e1000_hw *hw,
3885 uint8_t *mc_addr_list,
3886 uint32_t mc_addr_count,
3888 uint32_t rar_used_count)
3890 uint32_t hash_value;
3893 DEBUGFUNC("e1000_mc_addr_list_update");
3895 /* Set the new number of MC addresses that we are being requested to use. */
3896 hw->num_mc_addrs = mc_addr_count;
3898 /* Clear RAR[1-15] */
3899 DEBUGOUT(" Clearing RAR[1-15]\n");
3900 for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
3901 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3902 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3906 DEBUGOUT(" Clearing MTA\n");
3907 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
3908 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
3911 /* Add the new addresses */
3912 for(i = 0; i < mc_addr_count; i++) {
3913 DEBUGOUT(" Adding the multicast addresses:\n");
3914 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
3915 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
3916 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
3917 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
3918 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
3919 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
3920 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
3922 hash_value = e1000_hash_mc_addr(hw,
3924 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
3926 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
3928 /* Place this multicast address in the RAR if there is room, *
3929 * else put it in the MTA
3931 if(rar_used_count < E1000_RAR_ENTRIES) {
3933 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
3937 e1000_mta_set(hw, hash_value);
3940 DEBUGOUT("MC Update Complete\n");
3943 /******************************************************************************
3944 * Hashes an address to determine its location in the multicast table
3946 * hw - Struct containing variables accessed by shared code
3947 * mc_addr - the multicast address to hash
3948 *****************************************************************************/
3950 e1000_hash_mc_addr(struct e1000_hw *hw,
3953 uint32_t hash_value = 0;
3955 /* The portion of the address that is used for the hash table is
3956 * determined by the mc_filter_type setting.
3958 switch (hw->mc_filter_type) {
3959 /* [0] [1] [2] [3] [4] [5]
3964 /* [47:36] i.e. 0x563 for above example address */
3965 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
3968 /* [46:35] i.e. 0xAC6 for above example address */
3969 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
3972 /* [45:34] i.e. 0x5D8 for above example address */
3973 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
3976 /* [43:32] i.e. 0x634 for above example address */
3977 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
3981 hash_value &= 0xFFF;
3985 /******************************************************************************
3986 * Sets the bit in the multicast table corresponding to the hash value.
3988 * hw - Struct containing variables accessed by shared code
3989 * hash_value - Multicast address hash value
3990 *****************************************************************************/
3992 e1000_mta_set(struct e1000_hw *hw,
3993 uint32_t hash_value)
3995 uint32_t hash_bit, hash_reg;
3999 /* The MTA is a register array of 128 32-bit registers.
4000 * It is treated like an array of 4096 bits. We want to set
4001 * bit BitArray[hash_value]. So we figure out what register
4002 * the bit is in, read it, OR in the new bit, then write
4003 * back the new value. The register is determined by the
4004 * upper 7 bits of the hash value and the bit within that
4005 * register are determined by the lower 5 bits of the value.
4007 hash_reg = (hash_value >> 5) & 0x7F;
4008 hash_bit = hash_value & 0x1F;
4010 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4012 mta |= (1 << hash_bit);
4014 /* If we are on an 82544 and we are trying to write an odd offset
4015 * in the MTA, save off the previous entry before writing and
4016 * restore the old value after writing.
4018 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4019 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4020 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4021 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4023 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4027 /******************************************************************************
4028 * Puts an ethernet address into a receive address register.
4030 * hw - Struct containing variables accessed by shared code
4031 * addr - Address to put into receive address register
4032 * index - Receive address register to write
4033 *****************************************************************************/
4035 e1000_rar_set(struct e1000_hw *hw,
4039 uint32_t rar_low, rar_high;
4041 /* HW expects these in little endian so we reverse the byte order
4042 * from network order (big endian) to little endian
4044 rar_low = ((uint32_t) addr[0] |
4045 ((uint32_t) addr[1] << 8) |
4046 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4048 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4050 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4051 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4054 /******************************************************************************
4055 * Writes a value to the specified offset in the VLAN filter table.
4057 * hw - Struct containing variables accessed by shared code
4058 * offset - Offset in VLAN filer table to write
4059 * value - Value to write into VLAN filter table
4060 *****************************************************************************/
4062 e1000_write_vfta(struct e1000_hw *hw,
4068 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4069 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4070 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4071 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4073 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4077 /******************************************************************************
4078 * Clears the VLAN filer table
4080 * hw - Struct containing variables accessed by shared code
4081 *****************************************************************************/
4083 e1000_clear_vfta(struct e1000_hw *hw)
4087 for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
4088 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
4092 e1000_id_led_init(struct e1000_hw * hw)
4095 const uint32_t ledctl_mask = 0x000000FF;
4096 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4097 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4098 uint16_t eeprom_data, i, temp;
4099 const uint16_t led_mask = 0x0F;
4101 DEBUGFUNC("e1000_id_led_init");
4103 if(hw->mac_type < e1000_82540) {
4105 return E1000_SUCCESS;
4108 ledctl = E1000_READ_REG(hw, LEDCTL);
4109 hw->ledctl_default = ledctl;
4110 hw->ledctl_mode1 = hw->ledctl_default;
4111 hw->ledctl_mode2 = hw->ledctl_default;
4113 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4114 DEBUGOUT("EEPROM Read Error\n");
4115 return -E1000_ERR_EEPROM;
4117 if((eeprom_data== ID_LED_RESERVED_0000) ||
4118 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4119 for(i = 0; i < 4; i++) {
4120 temp = (eeprom_data >> (i << 2)) & led_mask;
4122 case ID_LED_ON1_DEF2:
4123 case ID_LED_ON1_ON2:
4124 case ID_LED_ON1_OFF2:
4125 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4126 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4128 case ID_LED_OFF1_DEF2:
4129 case ID_LED_OFF1_ON2:
4130 case ID_LED_OFF1_OFF2:
4131 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4132 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4139 case ID_LED_DEF1_ON2:
4140 case ID_LED_ON1_ON2:
4141 case ID_LED_OFF1_ON2:
4142 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4143 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4145 case ID_LED_DEF1_OFF2:
4146 case ID_LED_ON1_OFF2:
4147 case ID_LED_OFF1_OFF2:
4148 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4149 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4156 return E1000_SUCCESS;
4159 /******************************************************************************
4160 * Prepares SW controlable LED for use and saves the current state of the LED.
4162 * hw - Struct containing variables accessed by shared code
4163 *****************************************************************************/
4165 e1000_setup_led(struct e1000_hw *hw)
4168 int32_t ret_val = E1000_SUCCESS;
4170 DEBUGFUNC("e1000_setup_led");
4172 switch(hw->mac_type) {
4173 case e1000_82542_rev2_0:
4174 case e1000_82542_rev2_1:
4177 /* No setup necessary */
4181 case e1000_82541_rev_2:
4182 case e1000_82547_rev_2:
4183 /* Turn off PHY Smart Power Down (if enabled) */
4184 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4185 &hw->phy_spd_default);
4188 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4189 (uint16_t)(hw->phy_spd_default &
4190 ~IGP01E1000_GMII_SPD));
4195 if(hw->media_type == e1000_media_type_fiber) {
4196 ledctl = E1000_READ_REG(hw, LEDCTL);
4197 /* Save current LEDCTL settings */
4198 hw->ledctl_default = ledctl;
4200 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4201 E1000_LEDCTL_LED0_BLINK |
4202 E1000_LEDCTL_LED0_MODE_MASK);
4203 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4204 E1000_LEDCTL_LED0_MODE_SHIFT);
4205 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4206 } else if(hw->media_type == e1000_media_type_copper)
4207 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4211 return E1000_SUCCESS;
4214 /******************************************************************************
4215 * Restores the saved state of the SW controlable LED.
4217 * hw - Struct containing variables accessed by shared code
4218 *****************************************************************************/
4220 e1000_cleanup_led(struct e1000_hw *hw)
4222 int32_t ret_val = E1000_SUCCESS;
4224 DEBUGFUNC("e1000_cleanup_led");
4226 switch(hw->mac_type) {
4227 case e1000_82542_rev2_0:
4228 case e1000_82542_rev2_1:
4231 /* No cleanup necessary */
4235 case e1000_82541_rev_2:
4236 case e1000_82547_rev_2:
4237 /* Turn on PHY Smart Power Down (if previously enabled) */
4238 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4239 hw->phy_spd_default);
4244 /* Restore LEDCTL settings */
4245 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4249 return E1000_SUCCESS;
4252 /******************************************************************************
4253 * Turns on the software controllable LED
4255 * hw - Struct containing variables accessed by shared code
4256 *****************************************************************************/
4258 e1000_led_on(struct e1000_hw *hw)
4260 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4262 DEBUGFUNC("e1000_led_on");
4264 switch(hw->mac_type) {
4265 case e1000_82542_rev2_0:
4266 case e1000_82542_rev2_1:
4268 /* Set SW Defineable Pin 0 to turn on the LED */
4269 ctrl |= E1000_CTRL_SWDPIN0;
4270 ctrl |= E1000_CTRL_SWDPIO0;
4273 if(hw->media_type == e1000_media_type_fiber) {
4274 /* Set SW Defineable Pin 0 to turn on the LED */
4275 ctrl |= E1000_CTRL_SWDPIN0;
4276 ctrl |= E1000_CTRL_SWDPIO0;
4278 /* Clear SW Defineable Pin 0 to turn on the LED */
4279 ctrl &= ~E1000_CTRL_SWDPIN0;
4280 ctrl |= E1000_CTRL_SWDPIO0;
4284 if(hw->media_type == e1000_media_type_fiber) {
4285 /* Clear SW Defineable Pin 0 to turn on the LED */
4286 ctrl &= ~E1000_CTRL_SWDPIN0;
4287 ctrl |= E1000_CTRL_SWDPIO0;
4288 } else if(hw->media_type == e1000_media_type_copper) {
4289 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4290 return E1000_SUCCESS;
4295 E1000_WRITE_REG(hw, CTRL, ctrl);
4297 return E1000_SUCCESS;
4300 /******************************************************************************
4301 * Turns off the software controllable LED
4303 * hw - Struct containing variables accessed by shared code
4304 *****************************************************************************/
4306 e1000_led_off(struct e1000_hw *hw)
4308 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4310 DEBUGFUNC("e1000_led_off");
4312 switch(hw->mac_type) {
4313 case e1000_82542_rev2_0:
4314 case e1000_82542_rev2_1:
4316 /* Clear SW Defineable Pin 0 to turn off the LED */
4317 ctrl &= ~E1000_CTRL_SWDPIN0;
4318 ctrl |= E1000_CTRL_SWDPIO0;
4321 if(hw->media_type == e1000_media_type_fiber) {
4322 /* Clear SW Defineable Pin 0 to turn off the LED */
4323 ctrl &= ~E1000_CTRL_SWDPIN0;
4324 ctrl |= E1000_CTRL_SWDPIO0;
4326 /* Set SW Defineable Pin 0 to turn off the LED */
4327 ctrl |= E1000_CTRL_SWDPIN0;
4328 ctrl |= E1000_CTRL_SWDPIO0;
4332 if(hw->media_type == e1000_media_type_fiber) {
4333 /* Set SW Defineable Pin 0 to turn off the LED */
4334 ctrl |= E1000_CTRL_SWDPIN0;
4335 ctrl |= E1000_CTRL_SWDPIO0;
4336 } else if(hw->media_type == e1000_media_type_copper) {
4337 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4338 return E1000_SUCCESS;
4343 E1000_WRITE_REG(hw, CTRL, ctrl);
4345 return E1000_SUCCESS;
4348 /******************************************************************************
4349 * Clears all hardware statistics counters.
4351 * hw - Struct containing variables accessed by shared code
4352 *****************************************************************************/
4354 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4356 volatile uint32_t temp;
4358 temp = E1000_READ_REG(hw, CRCERRS);
4359 temp = E1000_READ_REG(hw, SYMERRS);
4360 temp = E1000_READ_REG(hw, MPC);
4361 temp = E1000_READ_REG(hw, SCC);
4362 temp = E1000_READ_REG(hw, ECOL);
4363 temp = E1000_READ_REG(hw, MCC);
4364 temp = E1000_READ_REG(hw, LATECOL);
4365 temp = E1000_READ_REG(hw, COLC);
4366 temp = E1000_READ_REG(hw, DC);
4367 temp = E1000_READ_REG(hw, SEC);
4368 temp = E1000_READ_REG(hw, RLEC);
4369 temp = E1000_READ_REG(hw, XONRXC);
4370 temp = E1000_READ_REG(hw, XONTXC);
4371 temp = E1000_READ_REG(hw, XOFFRXC);
4372 temp = E1000_READ_REG(hw, XOFFTXC);
4373 temp = E1000_READ_REG(hw, FCRUC);
4374 temp = E1000_READ_REG(hw, PRC64);
4375 temp = E1000_READ_REG(hw, PRC127);
4376 temp = E1000_READ_REG(hw, PRC255);
4377 temp = E1000_READ_REG(hw, PRC511);
4378 temp = E1000_READ_REG(hw, PRC1023);
4379 temp = E1000_READ_REG(hw, PRC1522);
4380 temp = E1000_READ_REG(hw, GPRC);
4381 temp = E1000_READ_REG(hw, BPRC);
4382 temp = E1000_READ_REG(hw, MPRC);
4383 temp = E1000_READ_REG(hw, GPTC);
4384 temp = E1000_READ_REG(hw, GORCL);
4385 temp = E1000_READ_REG(hw, GORCH);
4386 temp = E1000_READ_REG(hw, GOTCL);
4387 temp = E1000_READ_REG(hw, GOTCH);
4388 temp = E1000_READ_REG(hw, RNBC);
4389 temp = E1000_READ_REG(hw, RUC);
4390 temp = E1000_READ_REG(hw, RFC);
4391 temp = E1000_READ_REG(hw, ROC);
4392 temp = E1000_READ_REG(hw, RJC);
4393 temp = E1000_READ_REG(hw, TORL);
4394 temp = E1000_READ_REG(hw, TORH);
4395 temp = E1000_READ_REG(hw, TOTL);
4396 temp = E1000_READ_REG(hw, TOTH);
4397 temp = E1000_READ_REG(hw, TPR);
4398 temp = E1000_READ_REG(hw, TPT);
4399 temp = E1000_READ_REG(hw, PTC64);
4400 temp = E1000_READ_REG(hw, PTC127);
4401 temp = E1000_READ_REG(hw, PTC255);
4402 temp = E1000_READ_REG(hw, PTC511);
4403 temp = E1000_READ_REG(hw, PTC1023);
4404 temp = E1000_READ_REG(hw, PTC1522);
4405 temp = E1000_READ_REG(hw, MPTC);
4406 temp = E1000_READ_REG(hw, BPTC);
4408 if(hw->mac_type < e1000_82543) return;
4410 temp = E1000_READ_REG(hw, ALGNERRC);
4411 temp = E1000_READ_REG(hw, RXERRC);
4412 temp = E1000_READ_REG(hw, TNCRS);
4413 temp = E1000_READ_REG(hw, CEXTERR);
4414 temp = E1000_READ_REG(hw, TSCTC);
4415 temp = E1000_READ_REG(hw, TSCTFC);
4417 if(hw->mac_type <= e1000_82544) return;
4419 temp = E1000_READ_REG(hw, MGTPRC);
4420 temp = E1000_READ_REG(hw, MGTPDC);
4421 temp = E1000_READ_REG(hw, MGTPTC);
4424 /******************************************************************************
4425 * Resets Adaptive IFS to its default state.
4427 * hw - Struct containing variables accessed by shared code
4429 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4430 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4431 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4432 * before calling this function.
4433 *****************************************************************************/
4435 e1000_reset_adaptive(struct e1000_hw *hw)
4437 DEBUGFUNC("e1000_reset_adaptive");
4439 if(hw->adaptive_ifs) {
4440 if(!hw->ifs_params_forced) {
4441 hw->current_ifs_val = 0;
4442 hw->ifs_min_val = IFS_MIN;
4443 hw->ifs_max_val = IFS_MAX;
4444 hw->ifs_step_size = IFS_STEP;
4445 hw->ifs_ratio = IFS_RATIO;
4447 hw->in_ifs_mode = FALSE;
4448 E1000_WRITE_REG(hw, AIT, 0);
4450 DEBUGOUT("Not in Adaptive IFS mode!\n");
4454 /******************************************************************************
4455 * Called during the callback/watchdog routine to update IFS value based on
4456 * the ratio of transmits to collisions.
4458 * hw - Struct containing variables accessed by shared code
4459 * tx_packets - Number of transmits since last callback
4460 * total_collisions - Number of collisions since last callback
4461 *****************************************************************************/
4463 e1000_update_adaptive(struct e1000_hw *hw)
4465 DEBUGFUNC("e1000_update_adaptive");
4467 if(hw->adaptive_ifs) {
4468 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4469 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
4470 hw->in_ifs_mode = TRUE;
4471 if(hw->current_ifs_val < hw->ifs_max_val) {
4472 if(hw->current_ifs_val == 0)
4473 hw->current_ifs_val = hw->ifs_min_val;
4475 hw->current_ifs_val += hw->ifs_step_size;
4476 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
4480 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4481 hw->current_ifs_val = 0;
4482 hw->in_ifs_mode = FALSE;
4483 E1000_WRITE_REG(hw, AIT, 0);
4487 DEBUGOUT("Not in Adaptive IFS mode!\n");
4491 /******************************************************************************
4492 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4494 * hw - Struct containing variables accessed by shared code
4495 * frame_len - The length of the frame in question
4496 * mac_addr - The Ethernet destination address of the frame in question
4497 *****************************************************************************/
4499 e1000_tbi_adjust_stats(struct e1000_hw *hw,
4500 struct e1000_hw_stats *stats,
4506 /* First adjust the frame length. */
4508 /* We need to adjust the statistics counters, since the hardware
4509 * counters overcount this packet as a CRC error and undercount
4510 * the packet as a good packet
4512 /* This packet should not be counted as a CRC error. */
4514 /* This packet does count as a Good Packet Received. */
4517 /* Adjust the Good Octets received counters */
4518 carry_bit = 0x80000000 & stats->gorcl;
4519 stats->gorcl += frame_len;
4520 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4521 * Received Count) was one before the addition,
4522 * AND it is zero after, then we lost the carry out,
4523 * need to add one to Gorch (Good Octets Received Count High).
4524 * This could be simplified if all environments supported
4527 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
4529 /* Is this a broadcast or multicast? Check broadcast first,
4530 * since the test for a multicast frame will test positive on
4531 * a broadcast frame.
4533 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
4534 /* Broadcast packet */
4536 else if(*mac_addr & 0x01)
4537 /* Multicast packet */
4540 if(frame_len == hw->max_frame_size) {
4541 /* In this case, the hardware has overcounted the number of
4548 /* Adjust the bin counters when the extra byte put the frame in the
4549 * wrong bin. Remember that the frame_len was adjusted above.
4551 if(frame_len == 64) {
4554 } else if(frame_len == 127) {
4557 } else if(frame_len == 255) {
4560 } else if(frame_len == 511) {
4563 } else if(frame_len == 1023) {
4566 } else if(frame_len == 1522) {
4571 /******************************************************************************
4572 * Gets the current PCI bus type, speed, and width of the hardware
4574 * hw - Struct containing variables accessed by shared code
4575 *****************************************************************************/
4577 e1000_get_bus_info(struct e1000_hw *hw)
4581 if(hw->mac_type < e1000_82543) {
4582 hw->bus_type = e1000_bus_type_unknown;
4583 hw->bus_speed = e1000_bus_speed_unknown;
4584 hw->bus_width = e1000_bus_width_unknown;
4588 status = E1000_READ_REG(hw, STATUS);
4589 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4590 e1000_bus_type_pcix : e1000_bus_type_pci;
4592 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4593 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4594 e1000_bus_speed_66 : e1000_bus_speed_120;
4595 } else if(hw->bus_type == e1000_bus_type_pci) {
4596 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4597 e1000_bus_speed_66 : e1000_bus_speed_33;
4599 switch (status & E1000_STATUS_PCIX_SPEED) {
4600 case E1000_STATUS_PCIX_SPEED_66:
4601 hw->bus_speed = e1000_bus_speed_66;
4603 case E1000_STATUS_PCIX_SPEED_100:
4604 hw->bus_speed = e1000_bus_speed_100;
4606 case E1000_STATUS_PCIX_SPEED_133:
4607 hw->bus_speed = e1000_bus_speed_133;
4610 hw->bus_speed = e1000_bus_speed_reserved;
4614 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4615 e1000_bus_width_64 : e1000_bus_width_32;
4617 /******************************************************************************
4618 * Reads a value from one of the devices registers using port I/O (as opposed
4619 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4621 * hw - Struct containing variables accessed by shared code
4622 * offset - offset to read from
4623 *****************************************************************************/
4625 e1000_read_reg_io(struct e1000_hw *hw,
4628 unsigned long io_addr = hw->io_base;
4629 unsigned long io_data = hw->io_base + 4;
4631 e1000_io_write(hw, io_addr, offset);
4632 return e1000_io_read(hw, io_data);
4635 /******************************************************************************
4636 * Writes a value to one of the devices registers using port I/O (as opposed to
4637 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4639 * hw - Struct containing variables accessed by shared code
4640 * offset - offset to write to
4641 * value - value to write
4642 *****************************************************************************/
4644 e1000_write_reg_io(struct e1000_hw *hw,
4648 unsigned long io_addr = hw->io_base;
4649 unsigned long io_data = hw->io_base + 4;
4651 e1000_io_write(hw, io_addr, offset);
4652 e1000_io_write(hw, io_data, value);
4656 /******************************************************************************
4657 * Estimates the cable length.
4659 * hw - Struct containing variables accessed by shared code
4660 * min_length - The estimated minimum length
4661 * max_length - The estimated maximum length
4663 * returns: - E1000_ERR_XXX
4666 * This function always returns a ranged length (minimum & maximum).
4667 * So for M88 phy's, this function interprets the one value returned from the
4668 * register to the minimum and maximum range.
4669 * For IGP phy's, the function calculates the range by the AGC registers.
4670 *****************************************************************************/
4672 e1000_get_cable_length(struct e1000_hw *hw,
4673 uint16_t *min_length,
4674 uint16_t *max_length)
4677 uint16_t agc_value = 0;
4678 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4679 uint16_t i, phy_data;
4681 DEBUGFUNC("e1000_get_cable_length");
4683 *min_length = *max_length = 0;
4685 /* Use old method for Phy older than IGP */
4686 if(hw->phy_type == e1000_phy_m88) {
4687 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4692 /* Convert the enum value to ranged values */
4693 switch((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4694 M88E1000_PSSR_CABLE_LENGTH_SHIFT) {
4695 case e1000_cable_length_50:
4697 *max_length = e1000_igp_cable_length_50;
4699 case e1000_cable_length_50_80:
4700 *min_length = e1000_igp_cable_length_50;
4701 *max_length = e1000_igp_cable_length_80;
4703 case e1000_cable_length_80_110:
4704 *min_length = e1000_igp_cable_length_80;
4705 *max_length = e1000_igp_cable_length_110;
4707 case e1000_cable_length_110_140:
4708 *min_length = e1000_igp_cable_length_110;
4709 *max_length = e1000_igp_cable_length_140;
4711 case e1000_cable_length_140:
4712 *min_length = e1000_igp_cable_length_140;
4713 *max_length = e1000_igp_cable_length_170;
4716 return -E1000_ERR_PHY;
4719 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4720 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4721 {IGP01E1000_PHY_AGC_A,
4722 IGP01E1000_PHY_AGC_B,
4723 IGP01E1000_PHY_AGC_C,
4724 IGP01E1000_PHY_AGC_D};
4725 /* Read the AGC registers for all channels */
4726 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4728 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4732 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4734 /* Array bound check. */
4735 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4737 return -E1000_ERR_PHY;
4739 agc_value += cur_agc;
4741 /* Update minimal AGC value. */
4742 if(min_agc > cur_agc)
4746 /* Remove the minimal AGC result for length < 50m */
4747 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4748 agc_value -= min_agc;
4750 /* Get the average length of the remaining 3 channels */
4751 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4753 /* Get the average length of all the 4 channels. */
4754 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4757 /* Set the range of the calculated length. */
4758 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4759 IGP01E1000_AGC_RANGE) > 0) ?
4760 (e1000_igp_cable_length_table[agc_value] -
4761 IGP01E1000_AGC_RANGE) : 0;
4762 *max_length = e1000_igp_cable_length_table[agc_value] +
4763 IGP01E1000_AGC_RANGE;
4766 return E1000_SUCCESS;
4769 /******************************************************************************
4770 * Check the cable polarity
4772 * hw - Struct containing variables accessed by shared code
4773 * polarity - output parameter : 0 - Polarity is not reversed
4774 * 1 - Polarity is reversed.
4776 * returns: - E1000_ERR_XXX
4779 * For phy's older then IGP, this function simply reads the polarity bit in the
4780 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4781 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4782 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4783 * IGP01E1000_PHY_PCS_INIT_REG.
4784 *****************************************************************************/
4786 e1000_check_polarity(struct e1000_hw *hw,
4792 DEBUGFUNC("e1000_check_polarity");
4794 if(hw->phy_type == e1000_phy_m88) {
4795 /* return the Polarity bit in the Status register. */
4796 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4800 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
4801 M88E1000_PSSR_REV_POLARITY_SHIFT;
4802 } else if(hw->phy_type == e1000_phy_igp) {
4803 /* Read the Status register to check the speed */
4804 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4809 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4810 * find the polarity status */
4811 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4812 IGP01E1000_PSSR_SPEED_1000MBPS) {
4814 /* Read the GIG initialization PCS register (0x00B4) */
4815 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4820 /* Check the polarity bits */
4821 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
4823 /* For 10 Mbps, read the polarity bit in the status register. (for
4824 * 100 Mbps this bit is always 0) */
4825 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
4828 return E1000_SUCCESS;
4831 /******************************************************************************
4832 * Check if Downshift occured
4834 * hw - Struct containing variables accessed by shared code
4835 * downshift - output parameter : 0 - No Downshift ocured.
4836 * 1 - Downshift ocured.
4838 * returns: - E1000_ERR_XXX
4841 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4842 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
4843 * Link Health register. In IGP this bit is latched high, so the driver must
4844 * read it immediately after link is established.
4845 *****************************************************************************/
4847 e1000_check_downshift(struct e1000_hw *hw)
4852 DEBUGFUNC("e1000_check_downshift");
4854 if(hw->phy_type == e1000_phy_igp) {
4855 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
4860 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
4862 else if(hw->phy_type == e1000_phy_m88) {
4863 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4868 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
4869 M88E1000_PSSR_DOWNSHIFT_SHIFT;
4871 return E1000_SUCCESS;
4874 /*****************************************************************************
4876 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4877 * gigabit link is achieved to improve link quality.
4879 * hw: Struct containing variables accessed by shared code
4881 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4882 * E1000_SUCCESS at any other case.
4884 ****************************************************************************/
4887 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
4891 uint16_t phy_data, speed, duplex, i;
4892 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4893 {IGP01E1000_PHY_AGC_PARAM_A,
4894 IGP01E1000_PHY_AGC_PARAM_B,
4895 IGP01E1000_PHY_AGC_PARAM_C,
4896 IGP01E1000_PHY_AGC_PARAM_D};
4897 uint16_t min_length, max_length;
4899 DEBUGFUNC("e1000_config_dsp_after_link_change");
4901 if(hw->phy_type != e1000_phy_igp)
4902 return E1000_SUCCESS;
4905 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
4907 DEBUGOUT("Error getting link speed and duplex\n");
4911 if(speed == SPEED_1000) {
4913 e1000_get_cable_length(hw, &min_length, &max_length);
4915 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
4916 min_length >= e1000_igp_cable_length_50) {
4918 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4919 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4924 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4926 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
4931 hw->dsp_config_state = e1000_dsp_config_activated;
4934 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
4935 (min_length < e1000_igp_cable_length_50)) {
4937 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
4938 uint32_t idle_errs = 0;
4940 /* clear previous idle error counts */
4941 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4946 for(i = 0; i < ffe_idle_err_timeout; i++) {
4948 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4953 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
4954 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
4955 hw->ffe_config_state = e1000_ffe_config_active;
4957 ret_val = e1000_write_phy_reg(hw,
4958 IGP01E1000_PHY_DSP_FFE,
4959 IGP01E1000_PHY_DSP_FFE_CM_CP);
4966 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
4971 if(hw->dsp_config_state == e1000_dsp_config_activated) {
4972 ret_val = e1000_write_phy_reg(hw, 0x0000,
4973 IGP01E1000_IEEE_FORCE_GIGA);
4976 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4977 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
4981 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4982 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
4984 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
4989 ret_val = e1000_write_phy_reg(hw, 0x0000,
4990 IGP01E1000_IEEE_RESTART_AUTONEG);
4994 hw->dsp_config_state = e1000_dsp_config_enabled;
4997 if(hw->ffe_config_state == e1000_ffe_config_active) {
4998 ret_val = e1000_write_phy_reg(hw, 0x0000,
4999 IGP01E1000_IEEE_FORCE_GIGA);
5002 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5003 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5007 ret_val = e1000_write_phy_reg(hw, 0x0000,
5008 IGP01E1000_IEEE_RESTART_AUTONEG);
5011 hw->ffe_config_state = e1000_ffe_config_enabled;
5014 return E1000_SUCCESS;
5017 /*****************************************************************************
5018 * Set PHY to class A mode
5019 * Assumes the following operations will follow to enable the new class mode.
5020 * 1. Do a PHY soft reset
5021 * 2. Restart auto-negotiation or force link.
5023 * hw - Struct containing variables accessed by shared code
5024 ****************************************************************************/
5026 e1000_set_phy_mode(struct e1000_hw *hw)
5029 uint16_t eeprom_data;
5031 DEBUGFUNC("e1000_set_phy_mode");
5033 if((hw->mac_type == e1000_82545_rev_3) &&
5034 (hw->media_type == e1000_media_type_copper)) {
5035 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5040 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5041 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5042 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5045 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5049 hw->phy_reset_disable = FALSE;
5053 return E1000_SUCCESS;
5056 /*****************************************************************************
5058 * This function sets the lplu state according to the active flag. When
5059 * activating lplu this function also disables smart speed and vise versa.
5060 * lplu will not be activated unless the device autonegotiation advertisment
5061 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5062 * hw: Struct containing variables accessed by shared code
5063 * active - true to enable lplu false to disable lplu.
5065 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5066 * E1000_SUCCESS at any other case.
5068 ****************************************************************************/
5071 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5076 DEBUGFUNC("e1000_set_d3_lplu_state");
5078 if(!((hw->mac_type == e1000_82541_rev_2) ||
5079 (hw->mac_type == e1000_82547_rev_2)))
5080 return E1000_SUCCESS;
5082 /* During driver activity LPLU should not be used or it will attain link
5083 * from the lowest speeds starting from 10Mbps. The capability is used for
5084 * Dx transitions and states */
5085 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5090 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5091 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5095 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5096 * Dx states where the power conservation is most important. During
5097 * driver activity we should enable SmartSpeed, so performance is
5099 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5103 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5104 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5108 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5109 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5110 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5112 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5113 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5117 /* When LPLU is enabled we should disable SmartSpeed */
5118 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5122 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5123 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5128 return E1000_SUCCESS;
5131 /******************************************************************************
5132 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5134 * hw - Struct containing variables accessed by shared code
5135 *****************************************************************************/
5137 e1000_set_vco_speed(struct e1000_hw *hw)
5140 uint16_t default_page = 0;
5143 DEBUGFUNC("e1000_set_vco_speed");
5145 switch(hw->mac_type) {
5146 case e1000_82545_rev_3:
5147 case e1000_82546_rev_3:
5150 return E1000_SUCCESS;
5153 /* Set PHY register 30, page 5, bit 8 to 0 */
5155 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5159 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5163 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5167 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5168 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5172 /* Set PHY register 30, page 4, bit 11 to 1 */
5174 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5178 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5182 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5183 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5187 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5191 return E1000_SUCCESS;
5194 /******************************************************************************
5195 * Verifies the hardware needs to allow ARPs to be processed by the host
5197 * hw - Struct containing variables accessed by shared code
5199 * returns: - TRUE/FALSE
5201 *****************************************************************************/
5203 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
5207 if (hw->asf_firmware_present) {
5208 manc = E1000_READ_REG(hw, MANC);
5210 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
5211 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
5213 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))