1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_id_led_init(struct e1000_hw * hw);
67 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
69 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
71 /* IGP cable length table */
73 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
74 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
75 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
76 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
77 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
78 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
79 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
80 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
81 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
84 /******************************************************************************
85 * Set the phy type member in the hw struct.
87 * hw - Struct containing variables accessed by shared code
88 *****************************************************************************/
90 e1000_set_phy_type(struct e1000_hw *hw)
92 DEBUGFUNC("e1000_set_phy_type");
95 case M88E1000_E_PHY_ID:
96 case M88E1000_I_PHY_ID:
97 case M88E1011_I_PHY_ID:
98 hw->phy_type = e1000_phy_m88;
100 case IGP01E1000_I_PHY_ID:
101 if(hw->mac_type == e1000_82541 ||
102 hw->mac_type == e1000_82541_rev_2 ||
103 hw->mac_type == e1000_82547 ||
104 hw->mac_type == e1000_82547_rev_2) {
105 hw->phy_type = e1000_phy_igp;
110 /* Should never have loaded on this device */
111 hw->phy_type = e1000_phy_undefined;
112 return -E1000_ERR_PHY_TYPE;
115 return E1000_SUCCESS;
118 /******************************************************************************
119 * IGP phy init script - initializes the GbE PHY
121 * hw - Struct containing variables accessed by shared code
122 *****************************************************************************/
124 e1000_phy_init_script(struct e1000_hw *hw)
126 DEBUGFUNC("e1000_phy_init_script");
128 if(hw->phy_init_script) {
131 e1000_write_phy_reg(hw,0x0000,0x0140);
135 if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
136 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
138 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
140 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
142 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
144 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
146 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
148 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
150 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
152 e1000_write_phy_reg(hw, 0x2010, 0x0008);
154 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
157 e1000_write_phy_reg(hw, 0x0000, 0x3300);
159 if(hw->mac_type == e1000_82547) {
160 uint16_t fused, fine, coarse;
162 /* Move to analog registers page */
163 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
165 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
166 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
168 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
169 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
171 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
172 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
173 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
174 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
175 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
177 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
178 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
179 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
181 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
182 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
183 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
189 /******************************************************************************
190 * Set the mac type member in the hw struct.
192 * hw - Struct containing variables accessed by shared code
193 *****************************************************************************/
195 e1000_set_mac_type(struct e1000_hw *hw)
197 DEBUGFUNC("e1000_set_mac_type");
199 switch (hw->device_id) {
200 case E1000_DEV_ID_82542:
201 switch (hw->revision_id) {
202 case E1000_82542_2_0_REV_ID:
203 hw->mac_type = e1000_82542_rev2_0;
205 case E1000_82542_2_1_REV_ID:
206 hw->mac_type = e1000_82542_rev2_1;
209 /* Invalid 82542 revision ID */
210 return -E1000_ERR_MAC_TYPE;
213 case E1000_DEV_ID_82543GC_FIBER:
214 case E1000_DEV_ID_82543GC_COPPER:
215 hw->mac_type = e1000_82543;
217 case E1000_DEV_ID_82544EI_COPPER:
218 case E1000_DEV_ID_82544EI_FIBER:
219 case E1000_DEV_ID_82544GC_COPPER:
220 case E1000_DEV_ID_82544GC_LOM:
221 hw->mac_type = e1000_82544;
223 case E1000_DEV_ID_82540EM:
224 case E1000_DEV_ID_82540EM_LOM:
225 case E1000_DEV_ID_82540EP:
226 case E1000_DEV_ID_82540EP_LOM:
227 case E1000_DEV_ID_82540EP_LP:
228 hw->mac_type = e1000_82540;
230 case E1000_DEV_ID_82545EM_COPPER:
231 case E1000_DEV_ID_82545EM_FIBER:
232 hw->mac_type = e1000_82545;
234 case E1000_DEV_ID_82545GM_COPPER:
235 case E1000_DEV_ID_82545GM_FIBER:
236 case E1000_DEV_ID_82545GM_SERDES:
237 hw->mac_type = e1000_82545_rev_3;
239 case E1000_DEV_ID_82546EB_COPPER:
240 case E1000_DEV_ID_82546EB_FIBER:
241 case E1000_DEV_ID_82546EB_QUAD_COPPER:
242 hw->mac_type = e1000_82546;
244 case E1000_DEV_ID_82546GB_COPPER:
245 case E1000_DEV_ID_82546GB_FIBER:
246 case E1000_DEV_ID_82546GB_SERDES:
247 hw->mac_type = e1000_82546_rev_3;
249 case E1000_DEV_ID_82541EI:
250 case E1000_DEV_ID_82541EI_MOBILE:
251 hw->mac_type = e1000_82541;
253 case E1000_DEV_ID_82541ER:
254 case E1000_DEV_ID_82541GI:
255 case E1000_DEV_ID_82541GI_LF:
256 case E1000_DEV_ID_82541GI_MOBILE:
257 hw->mac_type = e1000_82541_rev_2;
259 case E1000_DEV_ID_82547EI:
260 hw->mac_type = e1000_82547;
262 case E1000_DEV_ID_82547GI:
263 hw->mac_type = e1000_82547_rev_2;
266 /* Should never have loaded on this device */
267 return -E1000_ERR_MAC_TYPE;
270 switch(hw->mac_type) {
273 case e1000_82541_rev_2:
274 case e1000_82547_rev_2:
275 hw->asf_firmware_present = TRUE;
281 return E1000_SUCCESS;
284 /*****************************************************************************
285 * Set media type and TBI compatibility.
287 * hw - Struct containing variables accessed by shared code
288 * **************************************************************************/
290 e1000_set_media_type(struct e1000_hw *hw)
294 DEBUGFUNC("e1000_set_media_type");
296 if(hw->mac_type != e1000_82543) {
297 /* tbi_compatibility is only valid on 82543 */
298 hw->tbi_compatibility_en = FALSE;
301 switch (hw->device_id) {
302 case E1000_DEV_ID_82545GM_SERDES:
303 case E1000_DEV_ID_82546GB_SERDES:
304 hw->media_type = e1000_media_type_internal_serdes;
307 if(hw->mac_type >= e1000_82543) {
308 status = E1000_READ_REG(hw, STATUS);
309 if(status & E1000_STATUS_TBIMODE) {
310 hw->media_type = e1000_media_type_fiber;
311 /* tbi_compatibility not valid on fiber */
312 hw->tbi_compatibility_en = FALSE;
314 hw->media_type = e1000_media_type_copper;
317 /* This is an 82542 (fiber only) */
318 hw->media_type = e1000_media_type_fiber;
323 /******************************************************************************
324 * Reset the transmit and receive units; mask and clear all interrupts.
326 * hw - Struct containing variables accessed by shared code
327 *****************************************************************************/
329 e1000_reset_hw(struct e1000_hw *hw)
337 DEBUGFUNC("e1000_reset_hw");
339 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
340 if(hw->mac_type == e1000_82542_rev2_0) {
341 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
342 e1000_pci_clear_mwi(hw);
345 /* Clear interrupt mask to stop board from generating interrupts */
346 DEBUGOUT("Masking off all interrupts\n");
347 E1000_WRITE_REG(hw, IMC, 0xffffffff);
349 /* Disable the Transmit and Receive units. Then delay to allow
350 * any pending transactions to complete before we hit the MAC with
353 E1000_WRITE_REG(hw, RCTL, 0);
354 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
355 E1000_WRITE_FLUSH(hw);
357 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
358 hw->tbi_compatibility_on = FALSE;
360 /* Delay to allow any outstanding PCI transactions to complete before
361 * resetting the device
365 ctrl = E1000_READ_REG(hw, CTRL);
367 /* Must reset the PHY before resetting the MAC */
368 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
369 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
373 /* Issue a global reset to the MAC. This will reset the chip's
374 * transmit, receive, DMA, and link units. It will not effect
375 * the current PCI configuration. The global reset bit is self-
376 * clearing, and should clear within a microsecond.
378 DEBUGOUT("Issuing a global reset to MAC\n");
380 switch(hw->mac_type) {
386 case e1000_82541_rev_2:
387 /* These controllers can't ack the 64-bit write when issuing the
388 * reset, so use IO-mapping as a workaround to issue the reset */
389 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
391 case e1000_82545_rev_3:
392 case e1000_82546_rev_3:
393 /* Reset is performed on a shadow of the control register */
394 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
397 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
401 /* After MAC reset, force reload of EEPROM to restore power-on settings to
402 * device. Later controllers reload the EEPROM automatically, so just wait
403 * for reload to complete.
405 switch(hw->mac_type) {
406 case e1000_82542_rev2_0:
407 case e1000_82542_rev2_1:
410 /* Wait for reset to complete */
412 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
413 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
414 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
415 E1000_WRITE_FLUSH(hw);
416 /* Wait for EEPROM reload */
420 case e1000_82541_rev_2:
422 case e1000_82547_rev_2:
423 /* Wait for EEPROM reload */
427 /* Wait for EEPROM reload (it happens automatically) */
432 /* Disable HW ARPs on ASF enabled adapters */
433 if(hw->mac_type >= e1000_82540) {
434 manc = E1000_READ_REG(hw, MANC);
435 manc &= ~(E1000_MANC_ARP_EN);
436 E1000_WRITE_REG(hw, MANC, manc);
439 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
440 e1000_phy_init_script(hw);
442 /* Configure activity LED after PHY reset */
443 led_ctrl = E1000_READ_REG(hw, LEDCTL);
444 led_ctrl &= IGP_ACTIVITY_LED_MASK;
445 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
446 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
449 /* Clear interrupt mask to stop board from generating interrupts */
450 DEBUGOUT("Masking off all interrupts\n");
451 E1000_WRITE_REG(hw, IMC, 0xffffffff);
453 /* Clear any pending interrupt events. */
454 icr = E1000_READ_REG(hw, ICR);
456 /* If MWI was previously enabled, reenable it. */
457 if(hw->mac_type == e1000_82542_rev2_0) {
458 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
459 e1000_pci_set_mwi(hw);
462 return E1000_SUCCESS;
465 /******************************************************************************
466 * Performs basic configuration of the adapter.
468 * hw - Struct containing variables accessed by shared code
470 * Assumes that the controller has previously been reset and is in a
471 * post-reset uninitialized state. Initializes the receive address registers,
472 * multicast table, and VLAN filter table. Calls routines to setup link
473 * configuration and flow control settings. Clears all on-chip counters. Leaves
474 * the transmit and receive units disabled and uninitialized.
475 *****************************************************************************/
477 e1000_init_hw(struct e1000_hw *hw)
482 uint16_t pcix_cmd_word;
483 uint16_t pcix_stat_hi_word;
486 DEBUGFUNC("e1000_init_hw");
488 /* Initialize Identification LED */
489 ret_val = e1000_id_led_init(hw);
491 DEBUGOUT("Error Initializing Identification LED\n");
495 /* Set the media type and TBI compatibility */
496 e1000_set_media_type(hw);
498 /* Disabling VLAN filtering. */
499 DEBUGOUT("Initializing the IEEE VLAN\n");
500 E1000_WRITE_REG(hw, VET, 0);
502 e1000_clear_vfta(hw);
504 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
505 if(hw->mac_type == e1000_82542_rev2_0) {
506 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
507 e1000_pci_clear_mwi(hw);
508 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
509 E1000_WRITE_FLUSH(hw);
513 /* Setup the receive address. This involves initializing all of the Receive
514 * Address Registers (RARs 0 - 15).
516 e1000_init_rx_addrs(hw);
518 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
519 if(hw->mac_type == e1000_82542_rev2_0) {
520 E1000_WRITE_REG(hw, RCTL, 0);
521 E1000_WRITE_FLUSH(hw);
523 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
524 e1000_pci_set_mwi(hw);
527 /* Zero out the Multicast HASH table */
528 DEBUGOUT("Zeroing the MTA\n");
529 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
530 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
532 /* Set the PCI priority bit correctly in the CTRL register. This
533 * determines if the adapter gives priority to receives, or if it
534 * gives equal priority to transmits and receives.
536 if(hw->dma_fairness) {
537 ctrl = E1000_READ_REG(hw, CTRL);
538 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
541 switch(hw->mac_type) {
542 case e1000_82545_rev_3:
543 case e1000_82546_rev_3:
546 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
547 if(hw->bus_type == e1000_bus_type_pcix) {
548 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
549 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
551 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
552 PCIX_COMMAND_MMRBC_SHIFT;
553 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
554 PCIX_STATUS_HI_MMRBC_SHIFT;
555 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
556 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
557 if(cmd_mmrbc > stat_mmrbc) {
558 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
559 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
560 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
567 /* Call a subroutine to configure the link and setup flow control. */
568 ret_val = e1000_setup_link(hw);
570 /* Set the transmit descriptor write-back policy */
571 if(hw->mac_type > e1000_82544) {
572 ctrl = E1000_READ_REG(hw, TXDCTL);
573 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
574 E1000_WRITE_REG(hw, TXDCTL, ctrl);
577 /* Clear all of the statistics registers (clear on read). It is
578 * important that we do this after we have tried to establish link
579 * because the symbol error count will increment wildly if there
582 e1000_clear_hw_cntrs(hw);
587 /******************************************************************************
588 * Adjust SERDES output amplitude based on EEPROM setting.
590 * hw - Struct containing variables accessed by shared code.
591 *****************************************************************************/
593 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
595 uint16_t eeprom_data;
598 DEBUGFUNC("e1000_adjust_serdes_amplitude");
600 if(hw->media_type != e1000_media_type_internal_serdes)
601 return E1000_SUCCESS;
603 switch(hw->mac_type) {
604 case e1000_82545_rev_3:
605 case e1000_82546_rev_3:
608 return E1000_SUCCESS;
611 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
616 if(eeprom_data != EEPROM_RESERVED_WORD) {
617 /* Adjust SERDES output amplitude only. */
618 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
619 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
624 return E1000_SUCCESS;
627 /******************************************************************************
628 * Configures flow control and link settings.
630 * hw - Struct containing variables accessed by shared code
632 * Determines which flow control settings to use. Calls the apropriate media-
633 * specific link configuration function. Configures the flow control settings.
634 * Assuming the adapter has a valid link partner, a valid link should be
635 * established. Assumes the hardware has previously been reset and the
636 * transmitter and receiver are not enabled.
637 *****************************************************************************/
639 e1000_setup_link(struct e1000_hw *hw)
643 uint16_t eeprom_data;
645 DEBUGFUNC("e1000_setup_link");
647 /* Read and store word 0x0F of the EEPROM. This word contains bits
648 * that determine the hardware's default PAUSE (flow control) mode,
649 * a bit that determines whether the HW defaults to enabling or
650 * disabling auto-negotiation, and the direction of the
651 * SW defined pins. If there is no SW over-ride of the flow
652 * control setting, then the variable hw->fc will
653 * be initialized based on a value in the EEPROM.
655 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
656 DEBUGOUT("EEPROM Read Error\n");
657 return -E1000_ERR_EEPROM;
660 if(hw->fc == e1000_fc_default) {
661 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
662 hw->fc = e1000_fc_none;
663 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
664 EEPROM_WORD0F_ASM_DIR)
665 hw->fc = e1000_fc_tx_pause;
667 hw->fc = e1000_fc_full;
670 /* We want to save off the original Flow Control configuration just
671 * in case we get disconnected and then reconnected into a different
672 * hub or switch with different Flow Control capabilities.
674 if(hw->mac_type == e1000_82542_rev2_0)
675 hw->fc &= (~e1000_fc_tx_pause);
677 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
678 hw->fc &= (~e1000_fc_rx_pause);
680 hw->original_fc = hw->fc;
682 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
684 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
685 * polarity value for the SW controlled pins, and setup the
686 * Extended Device Control reg with that info.
687 * This is needed because one of the SW controlled pins is used for
688 * signal detection. So this should be done before e1000_setup_pcs_link()
689 * or e1000_phy_setup() is called.
691 if(hw->mac_type == e1000_82543) {
692 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
694 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
697 /* Call the necessary subroutine to configure the link. */
698 ret_val = (hw->media_type == e1000_media_type_copper) ?
699 e1000_setup_copper_link(hw) :
700 e1000_setup_fiber_serdes_link(hw);
702 /* Initialize the flow control address, type, and PAUSE timer
703 * registers to their default values. This is done even if flow
704 * control is disabled, because it does not hurt anything to
705 * initialize these registers.
707 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
709 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
710 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
711 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
712 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
714 /* Set the flow control receive threshold registers. Normally,
715 * these registers will be set to a default threshold that may be
716 * adjusted later by the driver's runtime code. However, if the
717 * ability to transmit pause frames in not enabled, then these
718 * registers will be set to 0.
720 if(!(hw->fc & e1000_fc_tx_pause)) {
721 E1000_WRITE_REG(hw, FCRTL, 0);
722 E1000_WRITE_REG(hw, FCRTH, 0);
724 /* We need to set up the Receive Threshold high and low water marks
725 * as well as (optionally) enabling the transmission of XON frames.
727 if(hw->fc_send_xon) {
728 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
729 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
731 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
732 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
738 /******************************************************************************
739 * Sets up link for a fiber based or serdes based adapter
741 * hw - Struct containing variables accessed by shared code
743 * Manipulates Physical Coding Sublayer functions in order to configure
744 * link. Assumes the hardware has been previously reset and the transmitter
745 * and receiver are not enabled.
746 *****************************************************************************/
748 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
757 DEBUGFUNC("e1000_setup_fiber_serdes_link");
759 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
760 * set when the optics detect a signal. On older adapters, it will be
761 * cleared when there is a signal. This applies to fiber media only.
762 * If we're on serdes media, adjust the output amplitude to value set in
765 ctrl = E1000_READ_REG(hw, CTRL);
766 if(hw->media_type == e1000_media_type_fiber)
767 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
769 ret_val = e1000_adjust_serdes_amplitude(hw);
773 /* Take the link out of reset */
774 ctrl &= ~(E1000_CTRL_LRST);
776 /* Adjust VCO speed to improve BER performance */
777 ret_val = e1000_set_vco_speed(hw);
781 e1000_config_collision_dist(hw);
783 /* Check for a software override of the flow control settings, and setup
784 * the device accordingly. If auto-negotiation is enabled, then software
785 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
786 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
787 * auto-negotiation is disabled, then software will have to manually
788 * configure the two flow control enable bits in the CTRL register.
790 * The possible values of the "fc" parameter are:
791 * 0: Flow control is completely disabled
792 * 1: Rx flow control is enabled (we can receive pause frames, but
793 * not send pause frames).
794 * 2: Tx flow control is enabled (we can send pause frames but we do
795 * not support receiving pause frames).
796 * 3: Both Rx and TX flow control (symmetric) are enabled.
800 /* Flow control is completely disabled by a software over-ride. */
801 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
803 case e1000_fc_rx_pause:
804 /* RX Flow control is enabled and TX Flow control is disabled by a
805 * software over-ride. Since there really isn't a way to advertise
806 * that we are capable of RX Pause ONLY, we will advertise that we
807 * support both symmetric and asymmetric RX PAUSE. Later, we will
808 * disable the adapter's ability to send PAUSE frames.
810 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
812 case e1000_fc_tx_pause:
813 /* TX Flow control is enabled, and RX Flow control is disabled, by a
814 * software over-ride.
816 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
819 /* Flow control (both RX and TX) is enabled by a software over-ride. */
820 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
823 DEBUGOUT("Flow control param set incorrectly\n");
824 return -E1000_ERR_CONFIG;
828 /* Since auto-negotiation is enabled, take the link out of reset (the link
829 * will be in reset, because we previously reset the chip). This will
830 * restart auto-negotiation. If auto-neogtiation is successful then the
831 * link-up status bit will be set and the flow control enable bits (RFCE
832 * and TFCE) will be set according to their negotiated value.
834 DEBUGOUT("Auto-negotiation enabled\n");
836 E1000_WRITE_REG(hw, TXCW, txcw);
837 E1000_WRITE_REG(hw, CTRL, ctrl);
838 E1000_WRITE_FLUSH(hw);
843 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
844 * indication in the Device Status Register. Time-out if a link isn't
845 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
846 * less than 500 milliseconds even if the other end is doing it in SW).
847 * For internal serdes, we just assume a signal is present, then poll.
849 if(hw->media_type == e1000_media_type_internal_serdes ||
850 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
851 DEBUGOUT("Looking for Link\n");
852 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
854 status = E1000_READ_REG(hw, STATUS);
855 if(status & E1000_STATUS_LU) break;
857 if(i == (LINK_UP_TIMEOUT / 10)) {
858 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
859 hw->autoneg_failed = 1;
860 /* AutoNeg failed to achieve a link, so we'll call
861 * e1000_check_for_link. This routine will force the link up if
862 * we detect a signal. This will allow us to communicate with
863 * non-autonegotiating link partners.
865 ret_val = e1000_check_for_link(hw);
867 DEBUGOUT("Error while checking for link\n");
870 hw->autoneg_failed = 0;
872 hw->autoneg_failed = 0;
873 DEBUGOUT("Valid Link Found\n");
876 DEBUGOUT("No Signal Detected\n");
878 return E1000_SUCCESS;
881 /******************************************************************************
882 * Detects which PHY is present and the speed and duplex
884 * hw - Struct containing variables accessed by shared code
885 ******************************************************************************/
887 e1000_setup_copper_link(struct e1000_hw *hw)
895 DEBUGFUNC("e1000_setup_copper_link");
897 ctrl = E1000_READ_REG(hw, CTRL);
898 /* With 82543, we need to force speed and duplex on the MAC equal to what
899 * the PHY speed and duplex configuration is. In addition, we need to
900 * perform a hardware reset on the PHY to take it out of reset.
902 if(hw->mac_type > e1000_82543) {
903 ctrl |= E1000_CTRL_SLU;
904 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
905 E1000_WRITE_REG(hw, CTRL, ctrl);
907 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
908 E1000_WRITE_REG(hw, CTRL, ctrl);
909 e1000_phy_hw_reset(hw);
912 /* Make sure we have a valid PHY */
913 ret_val = e1000_detect_gig_phy(hw);
915 DEBUGOUT("Error, did not detect valid phy.\n");
918 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
920 /* Set PHY to class A mode (if necessary) */
921 ret_val = e1000_set_phy_mode(hw);
925 if((hw->mac_type == e1000_82545_rev_3) ||
926 (hw->mac_type == e1000_82546_rev_3)) {
927 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
928 phy_data |= 0x00000008;
929 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
932 if(hw->mac_type <= e1000_82543 ||
933 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
934 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
935 hw->phy_reset_disable = FALSE;
937 if(!hw->phy_reset_disable) {
938 if (hw->phy_type == e1000_phy_igp) {
940 ret_val = e1000_phy_reset(hw);
942 DEBUGOUT("Error Resetting the PHY\n");
946 /* Wait 10ms for MAC to configure PHY from eeprom settings */
949 /* Configure activity LED after PHY reset */
950 led_ctrl = E1000_READ_REG(hw, LEDCTL);
951 led_ctrl &= IGP_ACTIVITY_LED_MASK;
952 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
953 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
955 /* disable lplu d3 during driver init */
956 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
958 DEBUGOUT("Error Disabling LPLU D3\n");
962 /* Configure mdi-mdix settings */
963 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
968 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
969 hw->dsp_config_state = e1000_dsp_config_disabled;
970 /* Force MDI for IGP B-0 PHY */
971 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
972 IGP01E1000_PSCR_FORCE_MDI_MDIX);
976 hw->dsp_config_state = e1000_dsp_config_enabled;
977 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
981 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
984 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
988 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
992 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
997 /* set auto-master slave resolution settings */
999 e1000_ms_type phy_ms_setting = hw->master_slave;
1001 if(hw->ffe_config_state == e1000_ffe_config_active)
1002 hw->ffe_config_state = e1000_ffe_config_enabled;
1004 if(hw->dsp_config_state == e1000_dsp_config_activated)
1005 hw->dsp_config_state = e1000_dsp_config_enabled;
1007 /* when autonegotiation advertisment is only 1000Mbps then we
1008 * should disable SmartSpeed and enable Auto MasterSlave
1009 * resolution as hardware default. */
1010 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1011 /* Disable SmartSpeed */
1012 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1016 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1017 ret_val = e1000_write_phy_reg(hw,
1018 IGP01E1000_PHY_PORT_CONFIG,
1022 /* Set auto Master/Slave resolution process */
1023 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1026 phy_data &= ~CR_1000T_MS_ENABLE;
1027 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1032 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1036 /* load defaults for future use */
1037 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1038 ((phy_data & CR_1000T_MS_VALUE) ?
1039 e1000_ms_force_master :
1040 e1000_ms_force_slave) :
1043 switch (phy_ms_setting) {
1044 case e1000_ms_force_master:
1045 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1047 case e1000_ms_force_slave:
1048 phy_data |= CR_1000T_MS_ENABLE;
1049 phy_data &= ~(CR_1000T_MS_VALUE);
1052 phy_data &= ~CR_1000T_MS_ENABLE;
1056 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1061 /* Enable CRS on TX. This must be set for half-duplex operation. */
1062 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1067 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1070 * MDI/MDI-X = 0 (default)
1071 * 0 - Auto for all speeds
1074 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1076 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1080 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1083 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1086 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1090 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1095 * disable_polarity_correction = 0 (default)
1096 * Automatic Correction for Reversed Cable Polarity
1100 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1101 if(hw->disable_polarity_correction == 1)
1102 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1103 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1108 /* Force TX_CLK in the Extended PHY Specific Control Register
1111 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1116 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1118 if (hw->phy_revision < M88E1011_I_REV_4) {
1119 /* Configure Master and Slave downshift values */
1120 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1121 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1122 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1123 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1124 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1130 /* SW Reset the PHY so all changes take effect */
1131 ret_val = e1000_phy_reset(hw);
1133 DEBUGOUT("Error Resetting the PHY\n");
1139 * autoneg = 1 (default)
1140 * PHY will advertise value(s) parsed from
1141 * autoneg_advertised and fc
1143 * PHY will be set to 10H, 10F, 100H, or 100F
1144 * depending on value parsed from forced_speed_duplex.
1147 /* Is autoneg enabled? This is enabled by default or by software
1148 * override. If so, call e1000_phy_setup_autoneg routine to parse the
1149 * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1150 * the user should have provided a speed/duplex override. If so, then
1151 * call e1000_phy_force_speed_duplex to parse and set this up.
1154 /* Perform some bounds checking on the hw->autoneg_advertised
1155 * parameter. If this variable is zero, then set it to the default.
1157 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1159 /* If autoneg_advertised is zero, we assume it was not defaulted
1160 * by the calling code so we set to advertise full capability.
1162 if(hw->autoneg_advertised == 0)
1163 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1165 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1166 ret_val = e1000_phy_setup_autoneg(hw);
1168 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1171 DEBUGOUT("Restarting Auto-Neg\n");
1173 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1174 * the Auto Neg Restart bit in the PHY control register.
1176 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1180 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1181 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1185 /* Does the user want to wait for Auto-Neg to complete here, or
1186 * check at a later time (for example, callback routine).
1188 if(hw->wait_autoneg_complete) {
1189 ret_val = e1000_wait_autoneg(hw);
1191 DEBUGOUT("Error while waiting for autoneg to complete\n");
1195 hw->get_link_status = TRUE;
1197 DEBUGOUT("Forcing speed and duplex\n");
1198 ret_val = e1000_phy_force_speed_duplex(hw);
1200 DEBUGOUT("Error Forcing Speed and Duplex\n");
1204 } /* !hw->phy_reset_disable */
1206 /* Check link status. Wait up to 100 microseconds for link to become
1209 for(i = 0; i < 10; i++) {
1210 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1213 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1217 if(phy_data & MII_SR_LINK_STATUS) {
1218 /* We have link, so we need to finish the config process:
1219 * 1) Set up the MAC to the current PHY speed/duplex
1220 * if we are on 82543. If we
1221 * are on newer silicon, we only need to configure
1222 * collision distance in the Transmit Control Register.
1223 * 2) Set up flow control on the MAC to that established with
1226 if(hw->mac_type >= e1000_82544) {
1227 e1000_config_collision_dist(hw);
1229 ret_val = e1000_config_mac_to_phy(hw);
1231 DEBUGOUT("Error configuring MAC to PHY settings\n");
1235 ret_val = e1000_config_fc_after_link_up(hw);
1237 DEBUGOUT("Error Configuring Flow Control\n");
1240 DEBUGOUT("Valid link established!!!\n");
1242 if(hw->phy_type == e1000_phy_igp) {
1243 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1245 DEBUGOUT("Error Configuring DSP after link up\n");
1249 DEBUGOUT("Valid link established!!!\n");
1250 return E1000_SUCCESS;
1255 DEBUGOUT("Unable to establish link!!!\n");
1256 return E1000_SUCCESS;
1259 /******************************************************************************
1260 * Configures PHY autoneg and flow control advertisement settings
1262 * hw - Struct containing variables accessed by shared code
1263 ******************************************************************************/
1265 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1268 uint16_t mii_autoneg_adv_reg;
1269 uint16_t mii_1000t_ctrl_reg;
1271 DEBUGFUNC("e1000_phy_setup_autoneg");
1273 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1274 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1278 /* Read the MII 1000Base-T Control Register (Address 9). */
1279 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1283 /* Need to parse both autoneg_advertised and fc and set up
1284 * the appropriate PHY registers. First we will parse for
1285 * autoneg_advertised software override. Since we can advertise
1286 * a plethora of combinations, we need to check each bit
1290 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1291 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1292 * the 1000Base-T Control Register (Address 9).
1294 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1295 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1297 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1299 /* Do we want to advertise 10 Mb Half Duplex? */
1300 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1301 DEBUGOUT("Advertise 10mb Half duplex\n");
1302 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1305 /* Do we want to advertise 10 Mb Full Duplex? */
1306 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1307 DEBUGOUT("Advertise 10mb Full duplex\n");
1308 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1311 /* Do we want to advertise 100 Mb Half Duplex? */
1312 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1313 DEBUGOUT("Advertise 100mb Half duplex\n");
1314 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1317 /* Do we want to advertise 100 Mb Full Duplex? */
1318 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1319 DEBUGOUT("Advertise 100mb Full duplex\n");
1320 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1323 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1324 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1325 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1328 /* Do we want to advertise 1000 Mb Full Duplex? */
1329 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1330 DEBUGOUT("Advertise 1000mb Full duplex\n");
1331 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1334 /* Check for a software override of the flow control settings, and
1335 * setup the PHY advertisement registers accordingly. If
1336 * auto-negotiation is enabled, then software will have to set the
1337 * "PAUSE" bits to the correct value in the Auto-Negotiation
1338 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1340 * The possible values of the "fc" parameter are:
1341 * 0: Flow control is completely disabled
1342 * 1: Rx flow control is enabled (we can receive pause frames
1343 * but not send pause frames).
1344 * 2: Tx flow control is enabled (we can send pause frames
1345 * but we do not support receiving pause frames).
1346 * 3: Both Rx and TX flow control (symmetric) are enabled.
1347 * other: No software override. The flow control configuration
1348 * in the EEPROM is used.
1351 case e1000_fc_none: /* 0 */
1352 /* Flow control (RX & TX) is completely disabled by a
1353 * software over-ride.
1355 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1357 case e1000_fc_rx_pause: /* 1 */
1358 /* RX Flow control is enabled, and TX Flow control is
1359 * disabled, by a software over-ride.
1361 /* Since there really isn't a way to advertise that we are
1362 * capable of RX Pause ONLY, we will advertise that we
1363 * support both symmetric and asymmetric RX PAUSE. Later
1364 * (in e1000_config_fc_after_link_up) we will disable the
1365 *hw's ability to send PAUSE frames.
1367 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1369 case e1000_fc_tx_pause: /* 2 */
1370 /* TX Flow control is enabled, and RX Flow control is
1371 * disabled, by a software over-ride.
1373 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1374 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1376 case e1000_fc_full: /* 3 */
1377 /* Flow control (both RX and TX) is enabled by a software
1380 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1383 DEBUGOUT("Flow control param set incorrectly\n");
1384 return -E1000_ERR_CONFIG;
1387 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1391 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1393 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1397 return E1000_SUCCESS;
1400 /******************************************************************************
1401 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1403 * hw - Struct containing variables accessed by shared code
1404 ******************************************************************************/
1406 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1410 uint16_t mii_ctrl_reg;
1411 uint16_t mii_status_reg;
1415 DEBUGFUNC("e1000_phy_force_speed_duplex");
1417 /* Turn off Flow control if we are forcing speed and duplex. */
1418 hw->fc = e1000_fc_none;
1420 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1422 /* Read the Device Control Register. */
1423 ctrl = E1000_READ_REG(hw, CTRL);
1425 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1426 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1427 ctrl &= ~(DEVICE_SPEED_MASK);
1429 /* Clear the Auto Speed Detect Enable bit. */
1430 ctrl &= ~E1000_CTRL_ASDE;
1432 /* Read the MII Control Register. */
1433 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1437 /* We need to disable autoneg in order to force link and duplex. */
1439 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1441 /* Are we forcing Full or Half Duplex? */
1442 if(hw->forced_speed_duplex == e1000_100_full ||
1443 hw->forced_speed_duplex == e1000_10_full) {
1444 /* We want to force full duplex so we SET the full duplex bits in the
1445 * Device and MII Control Registers.
1447 ctrl |= E1000_CTRL_FD;
1448 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1449 DEBUGOUT("Full Duplex\n");
1451 /* We want to force half duplex so we CLEAR the full duplex bits in
1452 * the Device and MII Control Registers.
1454 ctrl &= ~E1000_CTRL_FD;
1455 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1456 DEBUGOUT("Half Duplex\n");
1459 /* Are we forcing 100Mbps??? */
1460 if(hw->forced_speed_duplex == e1000_100_full ||
1461 hw->forced_speed_duplex == e1000_100_half) {
1462 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1463 ctrl |= E1000_CTRL_SPD_100;
1464 mii_ctrl_reg |= MII_CR_SPEED_100;
1465 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1466 DEBUGOUT("Forcing 100mb ");
1468 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1469 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1470 mii_ctrl_reg |= MII_CR_SPEED_10;
1471 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1472 DEBUGOUT("Forcing 10mb ");
1475 e1000_config_collision_dist(hw);
1477 /* Write the configured values back to the Device Control Reg. */
1478 E1000_WRITE_REG(hw, CTRL, ctrl);
1480 if (hw->phy_type == e1000_phy_m88) {
1481 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1485 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1486 * forced whenever speed are duplex are forced.
1488 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1489 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1493 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1495 /* Need to reset the PHY or these changes will be ignored */
1496 mii_ctrl_reg |= MII_CR_RESET;
1498 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1499 * forced whenever speed or duplex are forced.
1501 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1505 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1506 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1508 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1513 /* Write back the modified PHY MII control register. */
1514 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1520 /* The wait_autoneg_complete flag may be a little misleading here.
1521 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1522 * But we do want to delay for a period while forcing only so we
1523 * don't generate false No Link messages. So we will wait here
1524 * only if the user has set wait_autoneg_complete to 1, which is
1527 if(hw->wait_autoneg_complete) {
1528 /* We will wait for autoneg to complete. */
1529 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1532 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1533 for(i = PHY_FORCE_TIME; i > 0; i--) {
1534 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1537 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1541 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1545 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1548 if((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1549 /* We didn't get link. Reset the DSP and wait again for link. */
1550 ret_val = e1000_phy_reset_dsp(hw);
1552 DEBUGOUT("Error Resetting PHY DSP\n");
1556 /* This loop will early-out if the link condition has been met. */
1557 for(i = PHY_FORCE_TIME; i > 0; i--) {
1558 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1560 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1563 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1567 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1573 if (hw->phy_type == e1000_phy_m88) {
1574 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1575 * Extended PHY Specific Control Register to 25MHz clock. This value
1576 * defaults back to a 2.5MHz clock when the PHY is reset.
1578 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1582 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1583 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1587 /* In addition, because of the s/w reset above, we need to enable CRS on
1588 * TX. This must be set for both full and half duplex operation.
1590 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1594 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1595 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1599 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1601 (hw->forced_speed_duplex == e1000_10_full ||
1602 hw->forced_speed_duplex == e1000_10_half)) {
1603 ret_val = e1000_polarity_reversal_workaround(hw);
1608 return E1000_SUCCESS;
1611 /******************************************************************************
1612 * Sets the collision distance in the Transmit Control register
1614 * hw - Struct containing variables accessed by shared code
1616 * Link should have been established previously. Reads the speed and duplex
1617 * information from the Device Status register.
1618 ******************************************************************************/
1620 e1000_config_collision_dist(struct e1000_hw *hw)
1624 DEBUGFUNC("e1000_config_collision_dist");
1626 tctl = E1000_READ_REG(hw, TCTL);
1628 tctl &= ~E1000_TCTL_COLD;
1629 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1631 E1000_WRITE_REG(hw, TCTL, tctl);
1632 E1000_WRITE_FLUSH(hw);
1635 /******************************************************************************
1636 * Sets MAC speed and duplex settings to reflect the those in the PHY
1638 * hw - Struct containing variables accessed by shared code
1639 * mii_reg - data to write to the MII control register
1641 * The contents of the PHY register containing the needed information need to
1643 ******************************************************************************/
1645 e1000_config_mac_to_phy(struct e1000_hw *hw)
1651 DEBUGFUNC("e1000_config_mac_to_phy");
1653 /* Read the Device Control Register and set the bits to Force Speed
1656 ctrl = E1000_READ_REG(hw, CTRL);
1657 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1658 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1660 /* Set up duplex in the Device Control and Transmit Control
1661 * registers depending on negotiated values.
1663 if (hw->phy_type == e1000_phy_igp) {
1664 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
1669 if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
1670 else ctrl &= ~E1000_CTRL_FD;
1672 e1000_config_collision_dist(hw);
1674 /* Set up speed in the Device Control register depending on
1675 * negotiated values.
1677 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1678 IGP01E1000_PSSR_SPEED_1000MBPS)
1679 ctrl |= E1000_CTRL_SPD_1000;
1680 else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1681 IGP01E1000_PSSR_SPEED_100MBPS)
1682 ctrl |= E1000_CTRL_SPD_100;
1684 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
1689 if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1690 else ctrl &= ~E1000_CTRL_FD;
1692 e1000_config_collision_dist(hw);
1694 /* Set up speed in the Device Control register depending on
1695 * negotiated values.
1697 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1698 ctrl |= E1000_CTRL_SPD_1000;
1699 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1700 ctrl |= E1000_CTRL_SPD_100;
1702 /* Write the configured values back to the Device Control Reg. */
1703 E1000_WRITE_REG(hw, CTRL, ctrl);
1704 return E1000_SUCCESS;
1707 /******************************************************************************
1708 * Forces the MAC's flow control settings.
1710 * hw - Struct containing variables accessed by shared code
1712 * Sets the TFCE and RFCE bits in the device control register to reflect
1713 * the adapter settings. TFCE and RFCE need to be explicitly set by
1714 * software when a Copper PHY is used because autonegotiation is managed
1715 * by the PHY rather than the MAC. Software must also configure these
1716 * bits when link is forced on a fiber connection.
1717 *****************************************************************************/
1719 e1000_force_mac_fc(struct e1000_hw *hw)
1723 DEBUGFUNC("e1000_force_mac_fc");
1725 /* Get the current configuration of the Device Control Register */
1726 ctrl = E1000_READ_REG(hw, CTRL);
1728 /* Because we didn't get link via the internal auto-negotiation
1729 * mechanism (we either forced link or we got link via PHY
1730 * auto-neg), we have to manually enable/disable transmit an
1731 * receive flow control.
1733 * The "Case" statement below enables/disable flow control
1734 * according to the "hw->fc" parameter.
1736 * The possible values of the "fc" parameter are:
1737 * 0: Flow control is completely disabled
1738 * 1: Rx flow control is enabled (we can receive pause
1739 * frames but not send pause frames).
1740 * 2: Tx flow control is enabled (we can send pause frames
1741 * frames but we do not receive pause frames).
1742 * 3: Both Rx and TX flow control (symmetric) is enabled.
1743 * other: No other values should be possible at this point.
1748 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1750 case e1000_fc_rx_pause:
1751 ctrl &= (~E1000_CTRL_TFCE);
1752 ctrl |= E1000_CTRL_RFCE;
1754 case e1000_fc_tx_pause:
1755 ctrl &= (~E1000_CTRL_RFCE);
1756 ctrl |= E1000_CTRL_TFCE;
1759 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1762 DEBUGOUT("Flow control param set incorrectly\n");
1763 return -E1000_ERR_CONFIG;
1766 /* Disable TX Flow Control for 82542 (rev 2.0) */
1767 if(hw->mac_type == e1000_82542_rev2_0)
1768 ctrl &= (~E1000_CTRL_TFCE);
1770 E1000_WRITE_REG(hw, CTRL, ctrl);
1771 return E1000_SUCCESS;
1774 /******************************************************************************
1775 * Configures flow control settings after link is established
1777 * hw - Struct containing variables accessed by shared code
1779 * Should be called immediately after a valid link has been established.
1780 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1781 * and autonegotiation is enabled, the MAC flow control settings will be set
1782 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1783 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1784 *****************************************************************************/
1786 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1789 uint16_t mii_status_reg;
1790 uint16_t mii_nway_adv_reg;
1791 uint16_t mii_nway_lp_ability_reg;
1795 DEBUGFUNC("e1000_config_fc_after_link_up");
1797 /* Check for the case where we have fiber media and auto-neg failed
1798 * so we had to force link. In this case, we need to force the
1799 * configuration of the MAC to match the "fc" parameter.
1801 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1802 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
1803 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1804 ret_val = e1000_force_mac_fc(hw);
1806 DEBUGOUT("Error forcing flow control settings\n");
1811 /* Check for the case where we have copper media and auto-neg is
1812 * enabled. In this case, we need to check and see if Auto-Neg
1813 * has completed, and if so, how the PHY and link partner has
1814 * flow control configured.
1816 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1817 /* Read the MII Status Register and check to see if AutoNeg
1818 * has completed. We read this twice because this reg has
1819 * some "sticky" (latched) bits.
1821 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1824 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1828 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1829 /* The AutoNeg process has completed, so we now need to
1830 * read both the Auto Negotiation Advertisement Register
1831 * (Address 4) and the Auto_Negotiation Base Page Ability
1832 * Register (Address 5) to determine how flow control was
1835 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1839 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1840 &mii_nway_lp_ability_reg);
1844 /* Two bits in the Auto Negotiation Advertisement Register
1845 * (Address 4) and two bits in the Auto Negotiation Base
1846 * Page Ability Register (Address 5) determine flow control
1847 * for both the PHY and the link partner. The following
1848 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1849 * 1999, describes these PAUSE resolution bits and how flow
1850 * control is determined based upon these settings.
1851 * NOTE: DC = Don't Care
1853 * LOCAL DEVICE | LINK PARTNER
1854 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1855 *-------|---------|-------|---------|--------------------
1856 * 0 | 0 | DC | DC | e1000_fc_none
1857 * 0 | 1 | 0 | DC | e1000_fc_none
1858 * 0 | 1 | 1 | 0 | e1000_fc_none
1859 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1860 * 1 | 0 | 0 | DC | e1000_fc_none
1861 * 1 | DC | 1 | DC | e1000_fc_full
1862 * 1 | 1 | 0 | 0 | e1000_fc_none
1863 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1866 /* Are both PAUSE bits set to 1? If so, this implies
1867 * Symmetric Flow Control is enabled at both ends. The
1868 * ASM_DIR bits are irrelevant per the spec.
1870 * For Symmetric Flow Control:
1872 * LOCAL DEVICE | LINK PARTNER
1873 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1874 *-------|---------|-------|---------|--------------------
1875 * 1 | DC | 1 | DC | e1000_fc_full
1878 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1879 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1880 /* Now we need to check if the user selected RX ONLY
1881 * of pause frames. In this case, we had to advertise
1882 * FULL flow control because we could not advertise RX
1883 * ONLY. Hence, we must now check to see if we need to
1884 * turn OFF the TRANSMISSION of PAUSE frames.
1886 if(hw->original_fc == e1000_fc_full) {
1887 hw->fc = e1000_fc_full;
1888 DEBUGOUT("Flow Control = FULL.\r\n");
1890 hw->fc = e1000_fc_rx_pause;
1891 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1894 /* For receiving PAUSE frames ONLY.
1896 * LOCAL DEVICE | LINK PARTNER
1897 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1898 *-------|---------|-------|---------|--------------------
1899 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1902 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1903 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1904 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1905 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1906 hw->fc = e1000_fc_tx_pause;
1907 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1909 /* For transmitting PAUSE frames ONLY.
1911 * LOCAL DEVICE | LINK PARTNER
1912 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1913 *-------|---------|-------|---------|--------------------
1914 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1917 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1918 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1919 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1920 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1921 hw->fc = e1000_fc_rx_pause;
1922 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1924 /* Per the IEEE spec, at this point flow control should be
1925 * disabled. However, we want to consider that we could
1926 * be connected to a legacy switch that doesn't advertise
1927 * desired flow control, but can be forced on the link
1928 * partner. So if we advertised no flow control, that is
1929 * what we will resolve to. If we advertised some kind of
1930 * receive capability (Rx Pause Only or Full Flow Control)
1931 * and the link partner advertised none, we will configure
1932 * ourselves to enable Rx Flow Control only. We can do
1933 * this safely for two reasons: If the link partner really
1934 * didn't want flow control enabled, and we enable Rx, no
1935 * harm done since we won't be receiving any PAUSE frames
1936 * anyway. If the intent on the link partner was to have
1937 * flow control enabled, then by us enabling RX only, we
1938 * can at least receive pause frames and process them.
1939 * This is a good idea because in most cases, since we are
1940 * predominantly a server NIC, more times than not we will
1941 * be asked to delay transmission of packets than asking
1942 * our link partner to pause transmission of frames.
1944 else if((hw->original_fc == e1000_fc_none ||
1945 hw->original_fc == e1000_fc_tx_pause) ||
1946 hw->fc_strict_ieee) {
1947 hw->fc = e1000_fc_none;
1948 DEBUGOUT("Flow Control = NONE.\r\n");
1950 hw->fc = e1000_fc_rx_pause;
1951 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1954 /* Now we need to do one last check... If we auto-
1955 * negotiated to HALF DUPLEX, flow control should not be
1956 * enabled per IEEE 802.3 spec.
1958 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
1960 DEBUGOUT("Error getting link speed and duplex\n");
1964 if(duplex == HALF_DUPLEX)
1965 hw->fc = e1000_fc_none;
1967 /* Now we call a subroutine to actually force the MAC
1968 * controller to use the correct flow control settings.
1970 ret_val = e1000_force_mac_fc(hw);
1972 DEBUGOUT("Error forcing flow control settings\n");
1976 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
1979 return E1000_SUCCESS;
1982 /******************************************************************************
1983 * Checks to see if the link status of the hardware has changed.
1985 * hw - Struct containing variables accessed by shared code
1987 * Called by any function that needs to check the link status of the adapter.
1988 *****************************************************************************/
1990 e1000_check_for_link(struct e1000_hw *hw)
1997 uint32_t signal = 0;
2001 DEBUGFUNC("e1000_check_for_link");
2003 ctrl = E1000_READ_REG(hw, CTRL);
2004 status = E1000_READ_REG(hw, STATUS);
2006 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2007 * set when the optics detect a signal. On older adapters, it will be
2008 * cleared when there is a signal. This applies to fiber media only.
2010 if((hw->media_type == e1000_media_type_fiber) ||
2011 (hw->media_type == e1000_media_type_internal_serdes)) {
2012 rxcw = E1000_READ_REG(hw, RXCW);
2014 if(hw->media_type == e1000_media_type_fiber) {
2015 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2016 if(status & E1000_STATUS_LU)
2017 hw->get_link_status = FALSE;
2021 /* If we have a copper PHY then we only want to go out to the PHY
2022 * registers to see if Auto-Neg has completed and/or if our link
2023 * status has changed. The get_link_status flag will be set if we
2024 * receive a Link Status Change interrupt or we have Rx Sequence
2027 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2028 /* First we want to see if the MII Status Register reports
2029 * link. If so, then we want to get the current speed/duplex
2031 * Read the register twice since the link bit is sticky.
2033 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2036 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2040 if(phy_data & MII_SR_LINK_STATUS) {
2041 hw->get_link_status = FALSE;
2042 /* Check if there was DownShift, must be checked immediately after
2044 e1000_check_downshift(hw);
2046 /* If we are on 82544 or 82543 silicon and speed/duplex
2047 * are forced to 10H or 10F, then we will implement the polarity
2048 * reversal workaround. We disable interrupts first, and upon
2049 * returning, place the devices interrupt state to its previous
2050 * value except for the link status change interrupt which will
2051 * happen due to the execution of this workaround.
2054 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2056 (hw->forced_speed_duplex == e1000_10_full ||
2057 hw->forced_speed_duplex == e1000_10_half)) {
2058 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2059 ret_val = e1000_polarity_reversal_workaround(hw);
2060 icr = E1000_READ_REG(hw, ICR);
2061 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2062 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2066 /* No link detected */
2067 e1000_config_dsp_after_link_change(hw, FALSE);
2071 /* If we are forcing speed/duplex, then we simply return since
2072 * we have already determined whether we have link or not.
2074 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2076 /* optimize the dsp settings for the igp phy */
2077 e1000_config_dsp_after_link_change(hw, TRUE);
2079 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2080 * have Si on board that is 82544 or newer, Auto
2081 * Speed Detection takes care of MAC speed/duplex
2082 * configuration. So we only need to configure Collision
2083 * Distance in the MAC. Otherwise, we need to force
2084 * speed/duplex on the MAC to the current PHY speed/duplex
2087 if(hw->mac_type >= e1000_82544)
2088 e1000_config_collision_dist(hw);
2090 ret_val = e1000_config_mac_to_phy(hw);
2092 DEBUGOUT("Error configuring MAC to PHY settings\n");
2097 /* Configure Flow Control now that Auto-Neg has completed. First, we
2098 * need to restore the desired flow control settings because we may
2099 * have had to re-autoneg with a different link partner.
2101 ret_val = e1000_config_fc_after_link_up(hw);
2103 DEBUGOUT("Error configuring flow control\n");
2107 /* At this point we know that we are on copper and we have
2108 * auto-negotiated link. These are conditions for checking the link
2109 * partner capability register. We use the link speed to determine if
2110 * TBI compatibility needs to be turned on or off. If the link is not
2111 * at gigabit speed, then TBI compatibility is not needed. If we are
2112 * at gigabit speed, we turn on TBI compatibility.
2114 if(hw->tbi_compatibility_en) {
2115 uint16_t speed, duplex;
2116 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2117 if(speed != SPEED_1000) {
2118 /* If link speed is not set to gigabit speed, we do not need
2119 * to enable TBI compatibility.
2121 if(hw->tbi_compatibility_on) {
2122 /* If we previously were in the mode, turn it off. */
2123 rctl = E1000_READ_REG(hw, RCTL);
2124 rctl &= ~E1000_RCTL_SBP;
2125 E1000_WRITE_REG(hw, RCTL, rctl);
2126 hw->tbi_compatibility_on = FALSE;
2129 /* If TBI compatibility is was previously off, turn it on. For
2130 * compatibility with a TBI link partner, we will store bad
2131 * packets. Some frames have an additional byte on the end and
2132 * will look like CRC errors to to the hardware.
2134 if(!hw->tbi_compatibility_on) {
2135 hw->tbi_compatibility_on = TRUE;
2136 rctl = E1000_READ_REG(hw, RCTL);
2137 rctl |= E1000_RCTL_SBP;
2138 E1000_WRITE_REG(hw, RCTL, rctl);
2143 /* If we don't have link (auto-negotiation failed or link partner cannot
2144 * auto-negotiate), the cable is plugged in (we have signal), and our
2145 * link partner is not trying to auto-negotiate with us (we are receiving
2146 * idles or data), we need to force link up. We also need to give
2147 * auto-negotiation time to complete, in case the cable was just plugged
2148 * in. The autoneg_failed flag does this.
2150 else if((((hw->media_type == e1000_media_type_fiber) &&
2151 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2152 (hw->media_type == e1000_media_type_internal_serdes)) &&
2153 (!(status & E1000_STATUS_LU)) &&
2154 (!(rxcw & E1000_RXCW_C))) {
2155 if(hw->autoneg_failed == 0) {
2156 hw->autoneg_failed = 1;
2159 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2161 /* Disable auto-negotiation in the TXCW register */
2162 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2164 /* Force link-up and also force full-duplex. */
2165 ctrl = E1000_READ_REG(hw, CTRL);
2166 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2167 E1000_WRITE_REG(hw, CTRL, ctrl);
2169 /* Configure Flow Control after forcing link up. */
2170 ret_val = e1000_config_fc_after_link_up(hw);
2172 DEBUGOUT("Error configuring flow control\n");
2176 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2177 * auto-negotiation in the TXCW register and disable forced link in the
2178 * Device Control register in an attempt to auto-negotiate with our link
2181 else if(((hw->media_type == e1000_media_type_fiber) ||
2182 (hw->media_type == e1000_media_type_internal_serdes)) &&
2183 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2184 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2185 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2186 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2188 hw->serdes_link_down = FALSE;
2190 /* If we force link for non-auto-negotiation switch, check link status
2191 * based on MAC synchronization for internal serdes media type.
2193 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2194 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2195 /* SYNCH bit and IV bit are sticky. */
2197 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2198 if(!(rxcw & E1000_RXCW_IV)) {
2199 hw->serdes_link_down = FALSE;
2200 DEBUGOUT("SERDES: Link is up.\n");
2203 hw->serdes_link_down = TRUE;
2204 DEBUGOUT("SERDES: Link is down.\n");
2207 if((hw->media_type == e1000_media_type_internal_serdes) &&
2208 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2209 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2211 return E1000_SUCCESS;
2214 /******************************************************************************
2215 * Detects the current speed and duplex settings of the hardware.
2217 * hw - Struct containing variables accessed by shared code
2218 * speed - Speed of the connection
2219 * duplex - Duplex setting of the connection
2220 *****************************************************************************/
2222 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2230 DEBUGFUNC("e1000_get_speed_and_duplex");
2232 if(hw->mac_type >= e1000_82543) {
2233 status = E1000_READ_REG(hw, STATUS);
2234 if(status & E1000_STATUS_SPEED_1000) {
2235 *speed = SPEED_1000;
2236 DEBUGOUT("1000 Mbs, ");
2237 } else if(status & E1000_STATUS_SPEED_100) {
2239 DEBUGOUT("100 Mbs, ");
2242 DEBUGOUT("10 Mbs, ");
2245 if(status & E1000_STATUS_FD) {
2246 *duplex = FULL_DUPLEX;
2247 DEBUGOUT("Full Duplex\r\n");
2249 *duplex = HALF_DUPLEX;
2250 DEBUGOUT(" Half Duplex\r\n");
2253 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2254 *speed = SPEED_1000;
2255 *duplex = FULL_DUPLEX;
2258 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2259 * if it is operating at half duplex. Here we set the duplex settings to
2260 * match the duplex in the link partner's capabilities.
2262 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2263 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2267 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2268 *duplex = HALF_DUPLEX;
2270 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2273 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2274 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2275 *duplex = HALF_DUPLEX;
2279 return E1000_SUCCESS;
2282 /******************************************************************************
2283 * Blocks until autoneg completes or times out (~4.5 seconds)
2285 * hw - Struct containing variables accessed by shared code
2286 ******************************************************************************/
2288 e1000_wait_autoneg(struct e1000_hw *hw)
2294 DEBUGFUNC("e1000_wait_autoneg");
2295 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2297 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2298 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2299 /* Read the MII Status Register and wait for Auto-Neg
2300 * Complete bit to be set.
2302 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2305 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2308 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2309 return E1000_SUCCESS;
2313 return E1000_SUCCESS;
2316 /******************************************************************************
2317 * Raises the Management Data Clock
2319 * hw - Struct containing variables accessed by shared code
2320 * ctrl - Device control register's current value
2321 ******************************************************************************/
2323 e1000_raise_mdi_clk(struct e1000_hw *hw,
2326 /* Raise the clock input to the Management Data Clock (by setting the MDC
2327 * bit), and then delay 10 microseconds.
2329 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2330 E1000_WRITE_FLUSH(hw);
2334 /******************************************************************************
2335 * Lowers the Management Data Clock
2337 * hw - Struct containing variables accessed by shared code
2338 * ctrl - Device control register's current value
2339 ******************************************************************************/
2341 e1000_lower_mdi_clk(struct e1000_hw *hw,
2344 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2345 * bit), and then delay 10 microseconds.
2347 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2348 E1000_WRITE_FLUSH(hw);
2352 /******************************************************************************
2353 * Shifts data bits out to the PHY
2355 * hw - Struct containing variables accessed by shared code
2356 * data - Data to send out to the PHY
2357 * count - Number of bits to shift out
2359 * Bits are shifted out in MSB to LSB order.
2360 ******************************************************************************/
2362 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2369 /* We need to shift "count" number of bits out to the PHY. So, the value
2370 * in the "data" parameter will be shifted out to the PHY one bit at a
2371 * time. In order to do this, "data" must be broken down into bits.
2374 mask <<= (count - 1);
2376 ctrl = E1000_READ_REG(hw, CTRL);
2378 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2379 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2382 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2383 * then raising and lowering the Management Data Clock. A "0" is
2384 * shifted out to the PHY by setting the MDIO bit to "0" and then
2385 * raising and lowering the clock.
2387 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2388 else ctrl &= ~E1000_CTRL_MDIO;
2390 E1000_WRITE_REG(hw, CTRL, ctrl);
2391 E1000_WRITE_FLUSH(hw);
2395 e1000_raise_mdi_clk(hw, &ctrl);
2396 e1000_lower_mdi_clk(hw, &ctrl);
2402 /******************************************************************************
2403 * Shifts data bits in from the PHY
2405 * hw - Struct containing variables accessed by shared code
2407 * Bits are shifted in in MSB to LSB order.
2408 ******************************************************************************/
2410 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2416 /* In order to read a register from the PHY, we need to shift in a total
2417 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2418 * to avoid contention on the MDIO pin when a read operation is performed.
2419 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2420 * by raising the input to the Management Data Clock (setting the MDC bit),
2421 * and then reading the value of the MDIO bit.
2423 ctrl = E1000_READ_REG(hw, CTRL);
2425 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2426 ctrl &= ~E1000_CTRL_MDIO_DIR;
2427 ctrl &= ~E1000_CTRL_MDIO;
2429 E1000_WRITE_REG(hw, CTRL, ctrl);
2430 E1000_WRITE_FLUSH(hw);
2432 /* Raise and Lower the clock before reading in the data. This accounts for
2433 * the turnaround bits. The first clock occurred when we clocked out the
2434 * last bit of the Register Address.
2436 e1000_raise_mdi_clk(hw, &ctrl);
2437 e1000_lower_mdi_clk(hw, &ctrl);
2439 for(data = 0, i = 0; i < 16; i++) {
2441 e1000_raise_mdi_clk(hw, &ctrl);
2442 ctrl = E1000_READ_REG(hw, CTRL);
2443 /* Check to see if we shifted in a "1". */
2444 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2445 e1000_lower_mdi_clk(hw, &ctrl);
2448 e1000_raise_mdi_clk(hw, &ctrl);
2449 e1000_lower_mdi_clk(hw, &ctrl);
2454 /*****************************************************************************
2455 * Reads the value from a PHY register, if the value is on a specific non zero
2456 * page, sets the page first.
2457 * hw - Struct containing variables accessed by shared code
2458 * reg_addr - address of the PHY register to read
2459 ******************************************************************************/
2461 e1000_read_phy_reg(struct e1000_hw *hw,
2467 DEBUGFUNC("e1000_read_phy_reg");
2469 if(hw->phy_type == e1000_phy_igp &&
2470 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2471 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2472 (uint16_t)reg_addr);
2477 ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2484 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2490 const uint32_t phy_addr = 1;
2492 DEBUGFUNC("e1000_read_phy_reg_ex");
2494 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2495 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2496 return -E1000_ERR_PARAM;
2499 if(hw->mac_type > e1000_82543) {
2500 /* Set up Op-code, Phy Address, and register address in the MDI
2501 * Control register. The MAC will take care of interfacing with the
2502 * PHY to retrieve the desired data.
2504 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2505 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2506 (E1000_MDIC_OP_READ));
2508 E1000_WRITE_REG(hw, MDIC, mdic);
2510 /* Poll the ready bit to see if the MDI read completed */
2511 for(i = 0; i < 64; i++) {
2513 mdic = E1000_READ_REG(hw, MDIC);
2514 if(mdic & E1000_MDIC_READY) break;
2516 if(!(mdic & E1000_MDIC_READY)) {
2517 DEBUGOUT("MDI Read did not complete\n");
2518 return -E1000_ERR_PHY;
2520 if(mdic & E1000_MDIC_ERROR) {
2521 DEBUGOUT("MDI Error\n");
2522 return -E1000_ERR_PHY;
2524 *phy_data = (uint16_t) mdic;
2526 /* We must first send a preamble through the MDIO pin to signal the
2527 * beginning of an MII instruction. This is done by sending 32
2528 * consecutive "1" bits.
2530 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2532 /* Now combine the next few fields that are required for a read
2533 * operation. We use this method instead of calling the
2534 * e1000_shift_out_mdi_bits routine five different times. The format of
2535 * a MII read instruction consists of a shift out of 14 bits and is
2536 * defined as follows:
2537 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2538 * followed by a shift in of 18 bits. This first two bits shifted in
2539 * are TurnAround bits used to avoid contention on the MDIO pin when a
2540 * READ operation is performed. These two bits are thrown away
2541 * followed by a shift in of 16 bits which contains the desired data.
2543 mdic = ((reg_addr) | (phy_addr << 5) |
2544 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2546 e1000_shift_out_mdi_bits(hw, mdic, 14);
2548 /* Now that we've shifted out the read command to the MII, we need to
2549 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2552 *phy_data = e1000_shift_in_mdi_bits(hw);
2554 return E1000_SUCCESS;
2557 /******************************************************************************
2558 * Writes a value to a PHY register
2560 * hw - Struct containing variables accessed by shared code
2561 * reg_addr - address of the PHY register to write
2562 * data - data to write to the PHY
2563 ******************************************************************************/
2565 e1000_write_phy_reg(struct e1000_hw *hw,
2571 DEBUGFUNC("e1000_write_phy_reg");
2573 if(hw->phy_type == e1000_phy_igp &&
2574 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2575 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2576 (uint16_t)reg_addr);
2581 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2588 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2594 const uint32_t phy_addr = 1;
2596 DEBUGFUNC("e1000_write_phy_reg_ex");
2598 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2599 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2600 return -E1000_ERR_PARAM;
2603 if(hw->mac_type > e1000_82543) {
2604 /* Set up Op-code, Phy Address, register address, and data intended
2605 * for the PHY register in the MDI Control register. The MAC will take
2606 * care of interfacing with the PHY to send the desired data.
2608 mdic = (((uint32_t) phy_data) |
2609 (reg_addr << E1000_MDIC_REG_SHIFT) |
2610 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2611 (E1000_MDIC_OP_WRITE));
2613 E1000_WRITE_REG(hw, MDIC, mdic);
2615 /* Poll the ready bit to see if the MDI read completed */
2616 for(i = 0; i < 640; i++) {
2618 mdic = E1000_READ_REG(hw, MDIC);
2619 if(mdic & E1000_MDIC_READY) break;
2621 if(!(mdic & E1000_MDIC_READY)) {
2622 DEBUGOUT("MDI Write did not complete\n");
2623 return -E1000_ERR_PHY;
2626 /* We'll need to use the SW defined pins to shift the write command
2627 * out to the PHY. We first send a preamble to the PHY to signal the
2628 * beginning of the MII instruction. This is done by sending 32
2629 * consecutive "1" bits.
2631 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2633 /* Now combine the remaining required fields that will indicate a
2634 * write operation. We use this method instead of calling the
2635 * e1000_shift_out_mdi_bits routine for each field in the command. The
2636 * format of a MII write instruction is as follows:
2637 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2639 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2640 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2642 mdic |= (uint32_t) phy_data;
2644 e1000_shift_out_mdi_bits(hw, mdic, 32);
2647 return E1000_SUCCESS;
2650 /******************************************************************************
2651 * Returns the PHY to the power-on reset state
2653 * hw - Struct containing variables accessed by shared code
2654 ******************************************************************************/
2656 e1000_phy_hw_reset(struct e1000_hw *hw)
2658 uint32_t ctrl, ctrl_ext;
2661 DEBUGFUNC("e1000_phy_hw_reset");
2663 DEBUGOUT("Resetting Phy...\n");
2665 if(hw->mac_type > e1000_82543) {
2666 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2667 * bit. Then, take it out of reset.
2669 ctrl = E1000_READ_REG(hw, CTRL);
2670 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2671 E1000_WRITE_FLUSH(hw);
2673 E1000_WRITE_REG(hw, CTRL, ctrl);
2674 E1000_WRITE_FLUSH(hw);
2676 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2677 * bit to put the PHY into reset. Then, take it out of reset.
2679 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2680 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2681 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2682 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2683 E1000_WRITE_FLUSH(hw);
2685 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2686 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2687 E1000_WRITE_FLUSH(hw);
2691 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2692 /* Configure activity LED after PHY reset */
2693 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2694 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2695 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2696 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2700 /******************************************************************************
2703 * hw - Struct containing variables accessed by shared code
2705 * Sets bit 15 of the MII Control regiser
2706 ******************************************************************************/
2708 e1000_phy_reset(struct e1000_hw *hw)
2713 DEBUGFUNC("e1000_phy_reset");
2715 if(hw->mac_type != e1000_82541_rev_2) {
2716 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2720 phy_data |= MII_CR_RESET;
2721 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2726 } else e1000_phy_hw_reset(hw);
2728 if(hw->phy_type == e1000_phy_igp)
2729 e1000_phy_init_script(hw);
2731 return E1000_SUCCESS;
2734 /******************************************************************************
2735 * Probes the expected PHY address for known PHY IDs
2737 * hw - Struct containing variables accessed by shared code
2738 ******************************************************************************/
2740 e1000_detect_gig_phy(struct e1000_hw *hw)
2742 int32_t phy_init_status, ret_val;
2743 uint16_t phy_id_high, phy_id_low;
2744 boolean_t match = FALSE;
2746 DEBUGFUNC("e1000_detect_gig_phy");
2748 /* Read the PHY ID Registers to identify which PHY is onboard. */
2749 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2753 hw->phy_id = (uint32_t) (phy_id_high << 16);
2755 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2759 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2760 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2762 switch(hw->mac_type) {
2764 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2767 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2771 case e1000_82545_rev_3:
2773 case e1000_82546_rev_3:
2774 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2777 case e1000_82541_rev_2:
2779 case e1000_82547_rev_2:
2780 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
2783 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2784 return -E1000_ERR_CONFIG;
2786 phy_init_status = e1000_set_phy_type(hw);
2788 if ((match) && (phy_init_status == E1000_SUCCESS)) {
2789 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2790 return E1000_SUCCESS;
2792 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2793 return -E1000_ERR_PHY;
2796 /******************************************************************************
2797 * Resets the PHY's DSP
2799 * hw - Struct containing variables accessed by shared code
2800 ******************************************************************************/
2802 e1000_phy_reset_dsp(struct e1000_hw *hw)
2805 DEBUGFUNC("e1000_phy_reset_dsp");
2808 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
2810 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
2812 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
2814 ret_val = E1000_SUCCESS;
2820 /******************************************************************************
2821 * Get PHY information from various PHY registers for igp PHY only.
2823 * hw - Struct containing variables accessed by shared code
2824 * phy_info - PHY information structure
2825 ******************************************************************************/
2827 e1000_phy_igp_get_info(struct e1000_hw *hw,
2828 struct e1000_phy_info *phy_info)
2831 uint16_t phy_data, polarity, min_length, max_length, average;
2833 DEBUGFUNC("e1000_phy_igp_get_info");
2835 /* The downshift status is checked only once, after link is established,
2836 * and it stored in the hw->speed_downgraded parameter. */
2837 phy_info->downshift = hw->speed_downgraded;
2839 /* IGP01E1000 does not need to support it. */
2840 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2842 /* IGP01E1000 always correct polarity reversal */
2843 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
2845 /* Check polarity status */
2846 ret_val = e1000_check_polarity(hw, &polarity);
2850 phy_info->cable_polarity = polarity;
2852 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
2856 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
2857 IGP01E1000_PSSR_MDIX_SHIFT;
2859 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
2860 IGP01E1000_PSSR_SPEED_1000MBPS) {
2861 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2862 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2866 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2867 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2868 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2869 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2871 /* Get cable length */
2872 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
2876 /* transalte to old method */
2877 average = (max_length + min_length) / 2;
2879 if(average <= e1000_igp_cable_length_50)
2880 phy_info->cable_length = e1000_cable_length_50;
2881 else if(average <= e1000_igp_cable_length_80)
2882 phy_info->cable_length = e1000_cable_length_50_80;
2883 else if(average <= e1000_igp_cable_length_110)
2884 phy_info->cable_length = e1000_cable_length_80_110;
2885 else if(average <= e1000_igp_cable_length_140)
2886 phy_info->cable_length = e1000_cable_length_110_140;
2888 phy_info->cable_length = e1000_cable_length_140;
2891 return E1000_SUCCESS;
2894 /******************************************************************************
2895 * Get PHY information from various PHY registers fot m88 PHY only.
2897 * hw - Struct containing variables accessed by shared code
2898 * phy_info - PHY information structure
2899 ******************************************************************************/
2901 e1000_phy_m88_get_info(struct e1000_hw *hw,
2902 struct e1000_phy_info *phy_info)
2905 uint16_t phy_data, polarity;
2907 DEBUGFUNC("e1000_phy_m88_get_info");
2909 /* The downshift status is checked only once, after link is established,
2910 * and it stored in the hw->speed_downgraded parameter. */
2911 phy_info->downshift = hw->speed_downgraded;
2913 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2917 phy_info->extended_10bt_distance =
2918 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2919 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2920 phy_info->polarity_correction =
2921 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2922 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2924 /* Check polarity status */
2925 ret_val = e1000_check_polarity(hw, &polarity);
2929 phy_info->cable_polarity = polarity;
2931 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2935 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2936 M88E1000_PSSR_MDIX_SHIFT;
2938 if(phy_data & M88E1000_PSSR_1000MBS) {
2939 /* Cable Length Estimation and Local/Remote Receiver Informatoion
2940 * are only valid at 1000 Mbps
2942 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2943 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2945 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
2949 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2950 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2952 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2953 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2956 return E1000_SUCCESS;
2959 /******************************************************************************
2960 * Get PHY information from various PHY registers
2962 * hw - Struct containing variables accessed by shared code
2963 * phy_info - PHY information structure
2964 ******************************************************************************/
2966 e1000_phy_get_info(struct e1000_hw *hw,
2967 struct e1000_phy_info *phy_info)
2972 DEBUGFUNC("e1000_phy_get_info");
2974 phy_info->cable_length = e1000_cable_length_undefined;
2975 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
2976 phy_info->cable_polarity = e1000_rev_polarity_undefined;
2977 phy_info->downshift = e1000_downshift_undefined;
2978 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
2979 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
2980 phy_info->local_rx = e1000_1000t_rx_status_undefined;
2981 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
2983 if(hw->media_type != e1000_media_type_copper) {
2984 DEBUGOUT("PHY info is only valid for copper media\n");
2985 return -E1000_ERR_CONFIG;
2988 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2992 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2996 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
2997 DEBUGOUT("PHY info is only valid if link is up\n");
2998 return -E1000_ERR_CONFIG;
3001 if(hw->phy_type == e1000_phy_igp)
3002 return e1000_phy_igp_get_info(hw, phy_info);
3004 return e1000_phy_m88_get_info(hw, phy_info);
3008 e1000_validate_mdi_setting(struct e1000_hw *hw)
3010 DEBUGFUNC("e1000_validate_mdi_settings");
3012 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3013 DEBUGOUT("Invalid MDI setting detected\n");
3015 return -E1000_ERR_CONFIG;
3017 return E1000_SUCCESS;
3021 /******************************************************************************
3022 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3025 * hw - Struct containing variables accessed by shared code
3026 *****************************************************************************/
3028 e1000_init_eeprom_params(struct e1000_hw *hw)
3030 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3031 uint32_t eecd = E1000_READ_REG(hw, EECD);
3032 uint16_t eeprom_size;
3034 DEBUGFUNC("e1000_init_eeprom_params");
3036 switch (hw->mac_type) {
3037 case e1000_82542_rev2_0:
3038 case e1000_82542_rev2_1:
3041 eeprom->type = e1000_eeprom_microwire;
3042 eeprom->word_size = 64;
3043 eeprom->opcode_bits = 3;
3044 eeprom->address_bits = 6;
3045 eeprom->delay_usec = 50;
3049 case e1000_82545_rev_3:
3051 case e1000_82546_rev_3:
3052 eeprom->type = e1000_eeprom_microwire;
3053 eeprom->opcode_bits = 3;
3054 eeprom->delay_usec = 50;
3055 if(eecd & E1000_EECD_SIZE) {
3056 eeprom->word_size = 256;
3057 eeprom->address_bits = 8;
3059 eeprom->word_size = 64;
3060 eeprom->address_bits = 6;
3064 case e1000_82541_rev_2:
3066 case e1000_82547_rev_2:
3067 if (eecd & E1000_EECD_TYPE) {
3068 eeprom->type = e1000_eeprom_spi;
3069 eeprom->opcode_bits = 8;
3070 eeprom->delay_usec = 1;
3071 if (eecd & E1000_EECD_ADDR_BITS) {
3072 eeprom->page_size = 32;
3073 eeprom->address_bits = 16;
3075 eeprom->page_size = 8;
3076 eeprom->address_bits = 8;
3079 eeprom->type = e1000_eeprom_microwire;
3080 eeprom->opcode_bits = 3;
3081 eeprom->delay_usec = 50;
3082 if (eecd & E1000_EECD_ADDR_BITS) {
3083 eeprom->word_size = 256;
3084 eeprom->address_bits = 8;
3086 eeprom->word_size = 64;
3087 eeprom->address_bits = 6;
3095 if (eeprom->type == e1000_eeprom_spi) {
3096 eeprom->word_size = 64;
3097 if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
3098 eeprom_size &= EEPROM_SIZE_MASK;
3100 switch (eeprom_size) {
3101 case EEPROM_SIZE_16KB:
3102 eeprom->word_size = 8192;
3104 case EEPROM_SIZE_8KB:
3105 eeprom->word_size = 4096;
3107 case EEPROM_SIZE_4KB:
3108 eeprom->word_size = 2048;
3110 case EEPROM_SIZE_2KB:
3111 eeprom->word_size = 1024;
3113 case EEPROM_SIZE_1KB:
3114 eeprom->word_size = 512;
3116 case EEPROM_SIZE_512B:
3117 eeprom->word_size = 256;
3119 case EEPROM_SIZE_128B:
3121 eeprom->word_size = 64;
3128 /******************************************************************************
3129 * Raises the EEPROM's clock input.
3131 * hw - Struct containing variables accessed by shared code
3132 * eecd - EECD's current value
3133 *****************************************************************************/
3135 e1000_raise_ee_clk(struct e1000_hw *hw,
3138 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3139 * wait <delay> microseconds.
3141 *eecd = *eecd | E1000_EECD_SK;
3142 E1000_WRITE_REG(hw, EECD, *eecd);
3143 E1000_WRITE_FLUSH(hw);
3144 udelay(hw->eeprom.delay_usec);
3147 /******************************************************************************
3148 * Lowers the EEPROM's clock input.
3150 * hw - Struct containing variables accessed by shared code
3151 * eecd - EECD's current value
3152 *****************************************************************************/
3154 e1000_lower_ee_clk(struct e1000_hw *hw,
3157 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3158 * wait 50 microseconds.
3160 *eecd = *eecd & ~E1000_EECD_SK;
3161 E1000_WRITE_REG(hw, EECD, *eecd);
3162 E1000_WRITE_FLUSH(hw);
3163 udelay(hw->eeprom.delay_usec);
3166 /******************************************************************************
3167 * Shift data bits out to the EEPROM.
3169 * hw - Struct containing variables accessed by shared code
3170 * data - data to send to the EEPROM
3171 * count - number of bits to shift out
3172 *****************************************************************************/
3174 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3178 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3182 /* We need to shift "count" bits out to the EEPROM. So, value in the
3183 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3184 * In order to do this, "data" must be broken down into bits.
3186 mask = 0x01 << (count - 1);
3187 eecd = E1000_READ_REG(hw, EECD);
3188 if (eeprom->type == e1000_eeprom_microwire) {
3189 eecd &= ~E1000_EECD_DO;
3190 } else if (eeprom->type == e1000_eeprom_spi) {
3191 eecd |= E1000_EECD_DO;
3194 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3195 * and then raising and then lowering the clock (the SK bit controls
3196 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3197 * by setting "DI" to "0" and then raising and then lowering the clock.
3199 eecd &= ~E1000_EECD_DI;
3202 eecd |= E1000_EECD_DI;
3204 E1000_WRITE_REG(hw, EECD, eecd);
3205 E1000_WRITE_FLUSH(hw);
3207 udelay(eeprom->delay_usec);
3209 e1000_raise_ee_clk(hw, &eecd);
3210 e1000_lower_ee_clk(hw, &eecd);
3216 /* We leave the "DI" bit set to "0" when we leave this routine. */
3217 eecd &= ~E1000_EECD_DI;
3218 E1000_WRITE_REG(hw, EECD, eecd);
3221 /******************************************************************************
3222 * Shift data bits in from the EEPROM
3224 * hw - Struct containing variables accessed by shared code
3225 *****************************************************************************/
3227 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3234 /* In order to read a register from the EEPROM, we need to shift 'count'
3235 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3236 * input to the EEPROM (setting the SK bit), and then reading the value of
3237 * the "DO" bit. During this "shifting in" process the "DI" bit should
3241 eecd = E1000_READ_REG(hw, EECD);
3243 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3246 for(i = 0; i < count; i++) {
3248 e1000_raise_ee_clk(hw, &eecd);
3250 eecd = E1000_READ_REG(hw, EECD);
3252 eecd &= ~(E1000_EECD_DI);
3253 if(eecd & E1000_EECD_DO)
3256 e1000_lower_ee_clk(hw, &eecd);
3262 /******************************************************************************
3263 * Prepares EEPROM for access
3265 * hw - Struct containing variables accessed by shared code
3267 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3268 * function should be called before issuing a command to the EEPROM.
3269 *****************************************************************************/
3271 e1000_acquire_eeprom(struct e1000_hw *hw)
3273 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3276 DEBUGFUNC("e1000_acquire_eeprom");
3278 eecd = E1000_READ_REG(hw, EECD);
3280 /* Request EEPROM Access */
3281 if(hw->mac_type > e1000_82544) {
3282 eecd |= E1000_EECD_REQ;
3283 E1000_WRITE_REG(hw, EECD, eecd);
3284 eecd = E1000_READ_REG(hw, EECD);
3285 while((!(eecd & E1000_EECD_GNT)) &&
3286 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3289 eecd = E1000_READ_REG(hw, EECD);
3291 if(!(eecd & E1000_EECD_GNT)) {
3292 eecd &= ~E1000_EECD_REQ;
3293 E1000_WRITE_REG(hw, EECD, eecd);
3294 DEBUGOUT("Could not acquire EEPROM grant\n");
3295 return -E1000_ERR_EEPROM;
3299 /* Setup EEPROM for Read/Write */
3301 if (eeprom->type == e1000_eeprom_microwire) {
3302 /* Clear SK and DI */
3303 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3304 E1000_WRITE_REG(hw, EECD, eecd);
3307 eecd |= E1000_EECD_CS;
3308 E1000_WRITE_REG(hw, EECD, eecd);
3309 } else if (eeprom->type == e1000_eeprom_spi) {
3310 /* Clear SK and CS */
3311 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3312 E1000_WRITE_REG(hw, EECD, eecd);
3316 return E1000_SUCCESS;
3319 /******************************************************************************
3320 * Returns EEPROM to a "standby" state
3322 * hw - Struct containing variables accessed by shared code
3323 *****************************************************************************/
3325 e1000_standby_eeprom(struct e1000_hw *hw)
3327 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3330 eecd = E1000_READ_REG(hw, EECD);
3332 if(eeprom->type == e1000_eeprom_microwire) {
3333 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3334 E1000_WRITE_REG(hw, EECD, eecd);
3335 E1000_WRITE_FLUSH(hw);
3336 udelay(eeprom->delay_usec);
3339 eecd |= E1000_EECD_SK;
3340 E1000_WRITE_REG(hw, EECD, eecd);
3341 E1000_WRITE_FLUSH(hw);
3342 udelay(eeprom->delay_usec);
3345 eecd |= E1000_EECD_CS;
3346 E1000_WRITE_REG(hw, EECD, eecd);
3347 E1000_WRITE_FLUSH(hw);
3348 udelay(eeprom->delay_usec);
3351 eecd &= ~E1000_EECD_SK;
3352 E1000_WRITE_REG(hw, EECD, eecd);
3353 E1000_WRITE_FLUSH(hw);
3354 udelay(eeprom->delay_usec);
3355 } else if(eeprom->type == e1000_eeprom_spi) {
3356 /* Toggle CS to flush commands */
3357 eecd |= E1000_EECD_CS;
3358 E1000_WRITE_REG(hw, EECD, eecd);
3359 E1000_WRITE_FLUSH(hw);
3360 udelay(eeprom->delay_usec);
3361 eecd &= ~E1000_EECD_CS;
3362 E1000_WRITE_REG(hw, EECD, eecd);
3363 E1000_WRITE_FLUSH(hw);
3364 udelay(eeprom->delay_usec);
3368 /******************************************************************************
3369 * Terminates a command by inverting the EEPROM's chip select pin
3371 * hw - Struct containing variables accessed by shared code
3372 *****************************************************************************/
3374 e1000_release_eeprom(struct e1000_hw *hw)
3378 DEBUGFUNC("e1000_release_eeprom");
3380 eecd = E1000_READ_REG(hw, EECD);
3382 if (hw->eeprom.type == e1000_eeprom_spi) {
3383 eecd |= E1000_EECD_CS; /* Pull CS high */
3384 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3386 E1000_WRITE_REG(hw, EECD, eecd);
3388 udelay(hw->eeprom.delay_usec);
3389 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3390 /* cleanup eeprom */
3392 /* CS on Microwire is active-high */
3393 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3395 E1000_WRITE_REG(hw, EECD, eecd);
3397 /* Rising edge of clock */
3398 eecd |= E1000_EECD_SK;
3399 E1000_WRITE_REG(hw, EECD, eecd);
3400 E1000_WRITE_FLUSH(hw);
3401 udelay(hw->eeprom.delay_usec);
3403 /* Falling edge of clock */
3404 eecd &= ~E1000_EECD_SK;
3405 E1000_WRITE_REG(hw, EECD, eecd);
3406 E1000_WRITE_FLUSH(hw);
3407 udelay(hw->eeprom.delay_usec);
3410 /* Stop requesting EEPROM access */
3411 if(hw->mac_type > e1000_82544) {
3412 eecd &= ~E1000_EECD_REQ;
3413 E1000_WRITE_REG(hw, EECD, eecd);
3417 /******************************************************************************
3418 * Reads a 16 bit word from the EEPROM.
3420 * hw - Struct containing variables accessed by shared code
3421 *****************************************************************************/
3423 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3425 uint16_t retry_count = 0;
3426 uint8_t spi_stat_reg;
3428 DEBUGFUNC("e1000_spi_eeprom_ready");
3430 /* Read "Status Register" repeatedly until the LSB is cleared. The
3431 * EEPROM will signal that the command has been completed by clearing
3432 * bit 0 of the internal status register. If it's not cleared within
3433 * 5 milliseconds, then error out.
3437 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3438 hw->eeprom.opcode_bits);
3439 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3440 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3446 e1000_standby_eeprom(hw);
3447 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3449 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3450 * only 0-5mSec on 5V devices)
3452 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3453 DEBUGOUT("SPI EEPROM Status error\n");
3454 return -E1000_ERR_EEPROM;
3457 return E1000_SUCCESS;
3460 /******************************************************************************
3461 * Reads a 16 bit word from the EEPROM.
3463 * hw - Struct containing variables accessed by shared code
3464 * offset - offset of word in the EEPROM to read
3465 * data - word read from the EEPROM
3466 * words - number of words to read
3467 *****************************************************************************/
3469 e1000_read_eeprom(struct e1000_hw *hw,
3474 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3477 DEBUGFUNC("e1000_read_eeprom");
3478 /* A check for invalid values: offset too large, too many words, and not
3481 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3483 DEBUGOUT("\"words\" parameter out of bounds\n");
3484 return -E1000_ERR_EEPROM;
3487 /* Prepare the EEPROM for reading */
3488 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3489 return -E1000_ERR_EEPROM;
3491 if(eeprom->type == e1000_eeprom_spi) {
3493 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3495 if(e1000_spi_eeprom_ready(hw)) {
3496 e1000_release_eeprom(hw);
3497 return -E1000_ERR_EEPROM;
3500 e1000_standby_eeprom(hw);
3502 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3503 if((eeprom->address_bits == 8) && (offset >= 128))
3504 read_opcode |= EEPROM_A8_OPCODE_SPI;
3506 /* Send the READ command (opcode + addr) */
3507 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3508 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3510 /* Read the data. The address of the eeprom internally increments with
3511 * each byte (spi) being read, saving on the overhead of eeprom setup
3512 * and tear-down. The address counter will roll over if reading beyond
3513 * the size of the eeprom, thus allowing the entire memory to be read
3514 * starting from any offset. */
3515 for (i = 0; i < words; i++) {
3516 word_in = e1000_shift_in_ee_bits(hw, 16);
3517 data[i] = (word_in >> 8) | (word_in << 8);
3519 } else if(eeprom->type == e1000_eeprom_microwire) {
3520 for (i = 0; i < words; i++) {
3521 /* Send the READ command (opcode + addr) */
3522 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3523 eeprom->opcode_bits);
3524 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3525 eeprom->address_bits);
3527 /* Read the data. For microwire, each word requires the overhead
3528 * of eeprom setup and tear-down. */
3529 data[i] = e1000_shift_in_ee_bits(hw, 16);
3530 e1000_standby_eeprom(hw);
3534 /* End this read operation */
3535 e1000_release_eeprom(hw);
3537 return E1000_SUCCESS;
3540 /******************************************************************************
3541 * Verifies that the EEPROM has a valid checksum
3543 * hw - Struct containing variables accessed by shared code
3545 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3546 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3548 *****************************************************************************/
3550 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3552 uint16_t checksum = 0;
3553 uint16_t i, eeprom_data;
3555 DEBUGFUNC("e1000_validate_eeprom_checksum");
3557 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3558 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3559 DEBUGOUT("EEPROM Read Error\n");
3560 return -E1000_ERR_EEPROM;
3562 checksum += eeprom_data;
3565 if(checksum == (uint16_t) EEPROM_SUM)
3566 return E1000_SUCCESS;
3568 DEBUGOUT("EEPROM Checksum Invalid\n");
3569 return -E1000_ERR_EEPROM;
3573 /******************************************************************************
3574 * Calculates the EEPROM checksum and writes it to the EEPROM
3576 * hw - Struct containing variables accessed by shared code
3578 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3579 * Writes the difference to word offset 63 of the EEPROM.
3580 *****************************************************************************/
3582 e1000_update_eeprom_checksum(struct e1000_hw *hw)
3584 uint16_t checksum = 0;
3585 uint16_t i, eeprom_data;
3587 DEBUGFUNC("e1000_update_eeprom_checksum");
3589 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3590 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3591 DEBUGOUT("EEPROM Read Error\n");
3592 return -E1000_ERR_EEPROM;
3594 checksum += eeprom_data;
3596 checksum = (uint16_t) EEPROM_SUM - checksum;
3597 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3598 DEBUGOUT("EEPROM Write Error\n");
3599 return -E1000_ERR_EEPROM;
3601 return E1000_SUCCESS;
3604 /******************************************************************************
3605 * Parent function for writing words to the different EEPROM types.
3607 * hw - Struct containing variables accessed by shared code
3608 * offset - offset within the EEPROM to be written to
3609 * words - number of words to write
3610 * data - 16 bit word to be written to the EEPROM
3612 * If e1000_update_eeprom_checksum is not called after this function, the
3613 * EEPROM will most likely contain an invalid checksum.
3614 *****************************************************************************/
3616 e1000_write_eeprom(struct e1000_hw *hw,
3621 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3624 DEBUGFUNC("e1000_write_eeprom");
3626 /* A check for invalid values: offset too large, too many words, and not
3629 if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3631 DEBUGOUT("\"words\" parameter out of bounds\n");
3632 return -E1000_ERR_EEPROM;
3635 /* Prepare the EEPROM for writing */
3636 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3637 return -E1000_ERR_EEPROM;
3639 if(eeprom->type == e1000_eeprom_microwire) {
3640 status = e1000_write_eeprom_microwire(hw, offset, words, data);
3642 status = e1000_write_eeprom_spi(hw, offset, words, data);
3646 /* Done with writing */
3647 e1000_release_eeprom(hw);
3652 /******************************************************************************
3653 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3655 * hw - Struct containing variables accessed by shared code
3656 * offset - offset within the EEPROM to be written to
3657 * words - number of words to write
3658 * data - pointer to array of 8 bit words to be written to the EEPROM
3660 *****************************************************************************/
3662 e1000_write_eeprom_spi(struct e1000_hw *hw,
3667 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3670 DEBUGFUNC("e1000_write_eeprom_spi");
3672 while (widx < words) {
3673 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
3675 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3677 e1000_standby_eeprom(hw);
3679 /* Send the WRITE ENABLE command (8 bit opcode ) */
3680 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3681 eeprom->opcode_bits);
3683 e1000_standby_eeprom(hw);
3685 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3686 if((eeprom->address_bits == 8) && (offset >= 128))
3687 write_opcode |= EEPROM_A8_OPCODE_SPI;
3689 /* Send the Write command (8-bit opcode + addr) */
3690 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3692 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
3693 eeprom->address_bits);
3697 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3698 while (widx < words) {
3699 uint16_t word_out = data[widx];
3700 word_out = (word_out >> 8) | (word_out << 8);
3701 e1000_shift_out_ee_bits(hw, word_out, 16);
3704 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3705 * operation, while the smaller eeproms are capable of an 8-byte
3706 * PAGE WRITE operation. Break the inner loop to pass new address
3708 if((((offset + widx)*2) % eeprom->page_size) == 0) {
3709 e1000_standby_eeprom(hw);
3715 return E1000_SUCCESS;
3718 /******************************************************************************
3719 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3721 * hw - Struct containing variables accessed by shared code
3722 * offset - offset within the EEPROM to be written to
3723 * words - number of words to write
3724 * data - pointer to array of 16 bit words to be written to the EEPROM
3726 *****************************************************************************/
3728 e1000_write_eeprom_microwire(struct e1000_hw *hw,
3733 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3735 uint16_t words_written = 0;
3738 DEBUGFUNC("e1000_write_eeprom_microwire");
3740 /* Send the write enable command to the EEPROM (3-bit opcode plus
3741 * 6/8-bit dummy address beginning with 11). It's less work to include
3742 * the 11 of the dummy address as part of the opcode than it is to shift
3743 * it over the correct number of bits for the address. This puts the
3744 * EEPROM into write/erase mode.
3746 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
3747 (uint16_t)(eeprom->opcode_bits + 2));
3749 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3751 /* Prepare the EEPROM */
3752 e1000_standby_eeprom(hw);
3754 while (words_written < words) {
3755 /* Send the Write command (3-bit opcode + addr) */
3756 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
3757 eeprom->opcode_bits);
3759 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
3760 eeprom->address_bits);
3763 e1000_shift_out_ee_bits(hw, data[words_written], 16);
3765 /* Toggle the CS line. This in effect tells the EEPROM to execute
3766 * the previous command.
3768 e1000_standby_eeprom(hw);
3770 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
3771 * signal that the command has been completed by raising the DO signal.
3772 * If DO does not go high in 10 milliseconds, then error out.
3774 for(i = 0; i < 200; i++) {
3775 eecd = E1000_READ_REG(hw, EECD);
3776 if(eecd & E1000_EECD_DO) break;
3780 DEBUGOUT("EEPROM Write did not complete\n");
3781 return -E1000_ERR_EEPROM;
3784 /* Recover from write */
3785 e1000_standby_eeprom(hw);
3790 /* Send the write disable command to the EEPROM (3-bit opcode plus
3791 * 6/8-bit dummy address beginning with 10). It's less work to include
3792 * the 10 of the dummy address as part of the opcode than it is to shift
3793 * it over the correct number of bits for the address. This takes the
3794 * EEPROM out of write/erase mode.
3796 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
3797 (uint16_t)(eeprom->opcode_bits + 2));
3799 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3801 return E1000_SUCCESS;
3804 /******************************************************************************
3805 * Reads the adapter's part number from the EEPROM
3807 * hw - Struct containing variables accessed by shared code
3808 * part_num - Adapter's part number
3809 *****************************************************************************/
3811 e1000_read_part_num(struct e1000_hw *hw,
3814 uint16_t offset = EEPROM_PBA_BYTE_1;
3815 uint16_t eeprom_data;
3817 DEBUGFUNC("e1000_read_part_num");
3819 /* Get word 0 from EEPROM */
3820 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3821 DEBUGOUT("EEPROM Read Error\n");
3822 return -E1000_ERR_EEPROM;
3824 /* Save word 0 in upper half of part_num */
3825 *part_num = (uint32_t) (eeprom_data << 16);
3827 /* Get word 1 from EEPROM */
3828 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
3829 DEBUGOUT("EEPROM Read Error\n");
3830 return -E1000_ERR_EEPROM;
3832 /* Save word 1 in lower half of part_num */
3833 *part_num |= eeprom_data;
3835 return E1000_SUCCESS;
3838 /******************************************************************************
3839 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3840 * second function of dual function devices
3842 * hw - Struct containing variables accessed by shared code
3843 *****************************************************************************/
3845 e1000_read_mac_addr(struct e1000_hw * hw)
3848 uint16_t eeprom_data, i;
3850 DEBUGFUNC("e1000_read_mac_addr");
3852 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
3854 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3855 DEBUGOUT("EEPROM Read Error\n");
3856 return -E1000_ERR_EEPROM;
3858 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
3859 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
3861 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
3862 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
3863 hw->perm_mac_addr[5] ^= 0x01;
3865 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
3866 hw->mac_addr[i] = hw->perm_mac_addr[i];
3867 return E1000_SUCCESS;
3870 /******************************************************************************
3871 * Initializes receive address filters.
3873 * hw - Struct containing variables accessed by shared code
3875 * Places the MAC address in receive address register 0 and clears the rest
3876 * of the receive addresss registers. Clears the multicast table. Assumes
3877 * the receiver is in reset when the routine is called.
3878 *****************************************************************************/
3880 e1000_init_rx_addrs(struct e1000_hw *hw)
3884 DEBUGFUNC("e1000_init_rx_addrs");
3886 /* Setup the receive address. */
3887 DEBUGOUT("Programming MAC Address into RAR[0]\n");
3889 e1000_rar_set(hw, hw->mac_addr, 0);
3891 /* Zero out the other 15 receive addresses. */
3892 DEBUGOUT("Clearing RAR[1-15]\n");
3893 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
3894 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3895 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3899 /******************************************************************************
3900 * Updates the MAC's list of multicast addresses.
3902 * hw - Struct containing variables accessed by shared code
3903 * mc_addr_list - the list of new multicast addresses
3904 * mc_addr_count - number of addresses
3905 * pad - number of bytes between addresses in the list
3906 * rar_used_count - offset where to start adding mc addresses into the RAR's
3908 * The given list replaces any existing list. Clears the last 15 receive
3909 * address registers and the multicast table. Uses receive address registers
3910 * for the first 15 multicast addresses, and hashes the rest into the
3912 *****************************************************************************/
3914 e1000_mc_addr_list_update(struct e1000_hw *hw,
3915 uint8_t *mc_addr_list,
3916 uint32_t mc_addr_count,
3918 uint32_t rar_used_count)
3920 uint32_t hash_value;
3923 DEBUGFUNC("e1000_mc_addr_list_update");
3925 /* Set the new number of MC addresses that we are being requested to use. */
3926 hw->num_mc_addrs = mc_addr_count;
3928 /* Clear RAR[1-15] */
3929 DEBUGOUT(" Clearing RAR[1-15]\n");
3930 for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
3931 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3932 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3936 DEBUGOUT(" Clearing MTA\n");
3937 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
3938 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
3941 /* Add the new addresses */
3942 for(i = 0; i < mc_addr_count; i++) {
3943 DEBUGOUT(" Adding the multicast addresses:\n");
3944 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
3945 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
3946 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
3947 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
3948 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
3949 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
3950 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
3952 hash_value = e1000_hash_mc_addr(hw,
3954 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
3956 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
3958 /* Place this multicast address in the RAR if there is room, *
3959 * else put it in the MTA
3961 if(rar_used_count < E1000_RAR_ENTRIES) {
3963 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
3967 e1000_mta_set(hw, hash_value);
3970 DEBUGOUT("MC Update Complete\n");
3973 /******************************************************************************
3974 * Hashes an address to determine its location in the multicast table
3976 * hw - Struct containing variables accessed by shared code
3977 * mc_addr - the multicast address to hash
3978 *****************************************************************************/
3980 e1000_hash_mc_addr(struct e1000_hw *hw,
3983 uint32_t hash_value = 0;
3985 /* The portion of the address that is used for the hash table is
3986 * determined by the mc_filter_type setting.
3988 switch (hw->mc_filter_type) {
3989 /* [0] [1] [2] [3] [4] [5]
3994 /* [47:36] i.e. 0x563 for above example address */
3995 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
3998 /* [46:35] i.e. 0xAC6 for above example address */
3999 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4002 /* [45:34] i.e. 0x5D8 for above example address */
4003 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4006 /* [43:32] i.e. 0x634 for above example address */
4007 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4011 hash_value &= 0xFFF;
4015 /******************************************************************************
4016 * Sets the bit in the multicast table corresponding to the hash value.
4018 * hw - Struct containing variables accessed by shared code
4019 * hash_value - Multicast address hash value
4020 *****************************************************************************/
4022 e1000_mta_set(struct e1000_hw *hw,
4023 uint32_t hash_value)
4025 uint32_t hash_bit, hash_reg;
4029 /* The MTA is a register array of 128 32-bit registers.
4030 * It is treated like an array of 4096 bits. We want to set
4031 * bit BitArray[hash_value]. So we figure out what register
4032 * the bit is in, read it, OR in the new bit, then write
4033 * back the new value. The register is determined by the
4034 * upper 7 bits of the hash value and the bit within that
4035 * register are determined by the lower 5 bits of the value.
4037 hash_reg = (hash_value >> 5) & 0x7F;
4038 hash_bit = hash_value & 0x1F;
4040 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4042 mta |= (1 << hash_bit);
4044 /* If we are on an 82544 and we are trying to write an odd offset
4045 * in the MTA, save off the previous entry before writing and
4046 * restore the old value after writing.
4048 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4049 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4050 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4051 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4053 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4057 /******************************************************************************
4058 * Puts an ethernet address into a receive address register.
4060 * hw - Struct containing variables accessed by shared code
4061 * addr - Address to put into receive address register
4062 * index - Receive address register to write
4063 *****************************************************************************/
4065 e1000_rar_set(struct e1000_hw *hw,
4069 uint32_t rar_low, rar_high;
4071 /* HW expects these in little endian so we reverse the byte order
4072 * from network order (big endian) to little endian
4074 rar_low = ((uint32_t) addr[0] |
4075 ((uint32_t) addr[1] << 8) |
4076 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4078 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4080 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4081 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4084 /******************************************************************************
4085 * Writes a value to the specified offset in the VLAN filter table.
4087 * hw - Struct containing variables accessed by shared code
4088 * offset - Offset in VLAN filer table to write
4089 * value - Value to write into VLAN filter table
4090 *****************************************************************************/
4092 e1000_write_vfta(struct e1000_hw *hw,
4098 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4099 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4100 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4101 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4103 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4107 /******************************************************************************
4108 * Clears the VLAN filer table
4110 * hw - Struct containing variables accessed by shared code
4111 *****************************************************************************/
4113 e1000_clear_vfta(struct e1000_hw *hw)
4117 for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
4118 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
4122 e1000_id_led_init(struct e1000_hw * hw)
4125 const uint32_t ledctl_mask = 0x000000FF;
4126 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4127 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4128 uint16_t eeprom_data, i, temp;
4129 const uint16_t led_mask = 0x0F;
4131 DEBUGFUNC("e1000_id_led_init");
4133 if(hw->mac_type < e1000_82540) {
4135 return E1000_SUCCESS;
4138 ledctl = E1000_READ_REG(hw, LEDCTL);
4139 hw->ledctl_default = ledctl;
4140 hw->ledctl_mode1 = hw->ledctl_default;
4141 hw->ledctl_mode2 = hw->ledctl_default;
4143 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4144 DEBUGOUT("EEPROM Read Error\n");
4145 return -E1000_ERR_EEPROM;
4147 if((eeprom_data== ID_LED_RESERVED_0000) ||
4148 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4149 for(i = 0; i < 4; i++) {
4150 temp = (eeprom_data >> (i << 2)) & led_mask;
4152 case ID_LED_ON1_DEF2:
4153 case ID_LED_ON1_ON2:
4154 case ID_LED_ON1_OFF2:
4155 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4156 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4158 case ID_LED_OFF1_DEF2:
4159 case ID_LED_OFF1_ON2:
4160 case ID_LED_OFF1_OFF2:
4161 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4162 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4169 case ID_LED_DEF1_ON2:
4170 case ID_LED_ON1_ON2:
4171 case ID_LED_OFF1_ON2:
4172 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4173 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4175 case ID_LED_DEF1_OFF2:
4176 case ID_LED_ON1_OFF2:
4177 case ID_LED_OFF1_OFF2:
4178 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4179 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4186 return E1000_SUCCESS;
4189 /******************************************************************************
4190 * Prepares SW controlable LED for use and saves the current state of the LED.
4192 * hw - Struct containing variables accessed by shared code
4193 *****************************************************************************/
4195 e1000_setup_led(struct e1000_hw *hw)
4198 int32_t ret_val = E1000_SUCCESS;
4200 DEBUGFUNC("e1000_setup_led");
4202 switch(hw->mac_type) {
4203 case e1000_82542_rev2_0:
4204 case e1000_82542_rev2_1:
4207 /* No setup necessary */
4211 case e1000_82541_rev_2:
4212 case e1000_82547_rev_2:
4213 /* Turn off PHY Smart Power Down (if enabled) */
4214 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4215 &hw->phy_spd_default);
4218 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4219 (uint16_t)(hw->phy_spd_default &
4220 ~IGP01E1000_GMII_SPD));
4225 if(hw->media_type == e1000_media_type_fiber) {
4226 ledctl = E1000_READ_REG(hw, LEDCTL);
4227 /* Save current LEDCTL settings */
4228 hw->ledctl_default = ledctl;
4230 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4231 E1000_LEDCTL_LED0_BLINK |
4232 E1000_LEDCTL_LED0_MODE_MASK);
4233 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4234 E1000_LEDCTL_LED0_MODE_SHIFT);
4235 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4236 } else if(hw->media_type == e1000_media_type_copper)
4237 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4241 return E1000_SUCCESS;
4244 /******************************************************************************
4245 * Restores the saved state of the SW controlable LED.
4247 * hw - Struct containing variables accessed by shared code
4248 *****************************************************************************/
4250 e1000_cleanup_led(struct e1000_hw *hw)
4252 int32_t ret_val = E1000_SUCCESS;
4254 DEBUGFUNC("e1000_cleanup_led");
4256 switch(hw->mac_type) {
4257 case e1000_82542_rev2_0:
4258 case e1000_82542_rev2_1:
4261 /* No cleanup necessary */
4265 case e1000_82541_rev_2:
4266 case e1000_82547_rev_2:
4267 /* Turn on PHY Smart Power Down (if previously enabled) */
4268 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4269 hw->phy_spd_default);
4274 /* Restore LEDCTL settings */
4275 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4279 return E1000_SUCCESS;
4282 /******************************************************************************
4283 * Turns on the software controllable LED
4285 * hw - Struct containing variables accessed by shared code
4286 *****************************************************************************/
4288 e1000_led_on(struct e1000_hw *hw)
4290 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4292 DEBUGFUNC("e1000_led_on");
4294 switch(hw->mac_type) {
4295 case e1000_82542_rev2_0:
4296 case e1000_82542_rev2_1:
4298 /* Set SW Defineable Pin 0 to turn on the LED */
4299 ctrl |= E1000_CTRL_SWDPIN0;
4300 ctrl |= E1000_CTRL_SWDPIO0;
4303 if(hw->media_type == e1000_media_type_fiber) {
4304 /* Set SW Defineable Pin 0 to turn on the LED */
4305 ctrl |= E1000_CTRL_SWDPIN0;
4306 ctrl |= E1000_CTRL_SWDPIO0;
4308 /* Clear SW Defineable Pin 0 to turn on the LED */
4309 ctrl &= ~E1000_CTRL_SWDPIN0;
4310 ctrl |= E1000_CTRL_SWDPIO0;
4314 if(hw->media_type == e1000_media_type_fiber) {
4315 /* Clear SW Defineable Pin 0 to turn on the LED */
4316 ctrl &= ~E1000_CTRL_SWDPIN0;
4317 ctrl |= E1000_CTRL_SWDPIO0;
4318 } else if(hw->media_type == e1000_media_type_copper) {
4319 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4320 return E1000_SUCCESS;
4325 E1000_WRITE_REG(hw, CTRL, ctrl);
4327 return E1000_SUCCESS;
4330 /******************************************************************************
4331 * Turns off the software controllable LED
4333 * hw - Struct containing variables accessed by shared code
4334 *****************************************************************************/
4336 e1000_led_off(struct e1000_hw *hw)
4338 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4340 DEBUGFUNC("e1000_led_off");
4342 switch(hw->mac_type) {
4343 case e1000_82542_rev2_0:
4344 case e1000_82542_rev2_1:
4346 /* Clear SW Defineable Pin 0 to turn off the LED */
4347 ctrl &= ~E1000_CTRL_SWDPIN0;
4348 ctrl |= E1000_CTRL_SWDPIO0;
4351 if(hw->media_type == e1000_media_type_fiber) {
4352 /* Clear SW Defineable Pin 0 to turn off the LED */
4353 ctrl &= ~E1000_CTRL_SWDPIN0;
4354 ctrl |= E1000_CTRL_SWDPIO0;
4356 /* Set SW Defineable Pin 0 to turn off the LED */
4357 ctrl |= E1000_CTRL_SWDPIN0;
4358 ctrl |= E1000_CTRL_SWDPIO0;
4362 if(hw->media_type == e1000_media_type_fiber) {
4363 /* Set SW Defineable Pin 0 to turn off the LED */
4364 ctrl |= E1000_CTRL_SWDPIN0;
4365 ctrl |= E1000_CTRL_SWDPIO0;
4366 } else if(hw->media_type == e1000_media_type_copper) {
4367 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4368 return E1000_SUCCESS;
4373 E1000_WRITE_REG(hw, CTRL, ctrl);
4375 return E1000_SUCCESS;
4378 /******************************************************************************
4379 * Clears all hardware statistics counters.
4381 * hw - Struct containing variables accessed by shared code
4382 *****************************************************************************/
4384 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4386 volatile uint32_t temp;
4388 temp = E1000_READ_REG(hw, CRCERRS);
4389 temp = E1000_READ_REG(hw, SYMERRS);
4390 temp = E1000_READ_REG(hw, MPC);
4391 temp = E1000_READ_REG(hw, SCC);
4392 temp = E1000_READ_REG(hw, ECOL);
4393 temp = E1000_READ_REG(hw, MCC);
4394 temp = E1000_READ_REG(hw, LATECOL);
4395 temp = E1000_READ_REG(hw, COLC);
4396 temp = E1000_READ_REG(hw, DC);
4397 temp = E1000_READ_REG(hw, SEC);
4398 temp = E1000_READ_REG(hw, RLEC);
4399 temp = E1000_READ_REG(hw, XONRXC);
4400 temp = E1000_READ_REG(hw, XONTXC);
4401 temp = E1000_READ_REG(hw, XOFFRXC);
4402 temp = E1000_READ_REG(hw, XOFFTXC);
4403 temp = E1000_READ_REG(hw, FCRUC);
4404 temp = E1000_READ_REG(hw, PRC64);
4405 temp = E1000_READ_REG(hw, PRC127);
4406 temp = E1000_READ_REG(hw, PRC255);
4407 temp = E1000_READ_REG(hw, PRC511);
4408 temp = E1000_READ_REG(hw, PRC1023);
4409 temp = E1000_READ_REG(hw, PRC1522);
4410 temp = E1000_READ_REG(hw, GPRC);
4411 temp = E1000_READ_REG(hw, BPRC);
4412 temp = E1000_READ_REG(hw, MPRC);
4413 temp = E1000_READ_REG(hw, GPTC);
4414 temp = E1000_READ_REG(hw, GORCL);
4415 temp = E1000_READ_REG(hw, GORCH);
4416 temp = E1000_READ_REG(hw, GOTCL);
4417 temp = E1000_READ_REG(hw, GOTCH);
4418 temp = E1000_READ_REG(hw, RNBC);
4419 temp = E1000_READ_REG(hw, RUC);
4420 temp = E1000_READ_REG(hw, RFC);
4421 temp = E1000_READ_REG(hw, ROC);
4422 temp = E1000_READ_REG(hw, RJC);
4423 temp = E1000_READ_REG(hw, TORL);
4424 temp = E1000_READ_REG(hw, TORH);
4425 temp = E1000_READ_REG(hw, TOTL);
4426 temp = E1000_READ_REG(hw, TOTH);
4427 temp = E1000_READ_REG(hw, TPR);
4428 temp = E1000_READ_REG(hw, TPT);
4429 temp = E1000_READ_REG(hw, PTC64);
4430 temp = E1000_READ_REG(hw, PTC127);
4431 temp = E1000_READ_REG(hw, PTC255);
4432 temp = E1000_READ_REG(hw, PTC511);
4433 temp = E1000_READ_REG(hw, PTC1023);
4434 temp = E1000_READ_REG(hw, PTC1522);
4435 temp = E1000_READ_REG(hw, MPTC);
4436 temp = E1000_READ_REG(hw, BPTC);
4438 if(hw->mac_type < e1000_82543) return;
4440 temp = E1000_READ_REG(hw, ALGNERRC);
4441 temp = E1000_READ_REG(hw, RXERRC);
4442 temp = E1000_READ_REG(hw, TNCRS);
4443 temp = E1000_READ_REG(hw, CEXTERR);
4444 temp = E1000_READ_REG(hw, TSCTC);
4445 temp = E1000_READ_REG(hw, TSCTFC);
4447 if(hw->mac_type <= e1000_82544) return;
4449 temp = E1000_READ_REG(hw, MGTPRC);
4450 temp = E1000_READ_REG(hw, MGTPDC);
4451 temp = E1000_READ_REG(hw, MGTPTC);
4454 /******************************************************************************
4455 * Resets Adaptive IFS to its default state.
4457 * hw - Struct containing variables accessed by shared code
4459 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4460 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4461 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4462 * before calling this function.
4463 *****************************************************************************/
4465 e1000_reset_adaptive(struct e1000_hw *hw)
4467 DEBUGFUNC("e1000_reset_adaptive");
4469 if(hw->adaptive_ifs) {
4470 if(!hw->ifs_params_forced) {
4471 hw->current_ifs_val = 0;
4472 hw->ifs_min_val = IFS_MIN;
4473 hw->ifs_max_val = IFS_MAX;
4474 hw->ifs_step_size = IFS_STEP;
4475 hw->ifs_ratio = IFS_RATIO;
4477 hw->in_ifs_mode = FALSE;
4478 E1000_WRITE_REG(hw, AIT, 0);
4480 DEBUGOUT("Not in Adaptive IFS mode!\n");
4484 /******************************************************************************
4485 * Called during the callback/watchdog routine to update IFS value based on
4486 * the ratio of transmits to collisions.
4488 * hw - Struct containing variables accessed by shared code
4489 * tx_packets - Number of transmits since last callback
4490 * total_collisions - Number of collisions since last callback
4491 *****************************************************************************/
4493 e1000_update_adaptive(struct e1000_hw *hw)
4495 DEBUGFUNC("e1000_update_adaptive");
4497 if(hw->adaptive_ifs) {
4498 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4499 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
4500 hw->in_ifs_mode = TRUE;
4501 if(hw->current_ifs_val < hw->ifs_max_val) {
4502 if(hw->current_ifs_val == 0)
4503 hw->current_ifs_val = hw->ifs_min_val;
4505 hw->current_ifs_val += hw->ifs_step_size;
4506 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
4510 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4511 hw->current_ifs_val = 0;
4512 hw->in_ifs_mode = FALSE;
4513 E1000_WRITE_REG(hw, AIT, 0);
4517 DEBUGOUT("Not in Adaptive IFS mode!\n");
4521 /******************************************************************************
4522 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4524 * hw - Struct containing variables accessed by shared code
4525 * frame_len - The length of the frame in question
4526 * mac_addr - The Ethernet destination address of the frame in question
4527 *****************************************************************************/
4529 e1000_tbi_adjust_stats(struct e1000_hw *hw,
4530 struct e1000_hw_stats *stats,
4536 /* First adjust the frame length. */
4538 /* We need to adjust the statistics counters, since the hardware
4539 * counters overcount this packet as a CRC error and undercount
4540 * the packet as a good packet
4542 /* This packet should not be counted as a CRC error. */
4544 /* This packet does count as a Good Packet Received. */
4547 /* Adjust the Good Octets received counters */
4548 carry_bit = 0x80000000 & stats->gorcl;
4549 stats->gorcl += frame_len;
4550 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4551 * Received Count) was one before the addition,
4552 * AND it is zero after, then we lost the carry out,
4553 * need to add one to Gorch (Good Octets Received Count High).
4554 * This could be simplified if all environments supported
4557 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
4559 /* Is this a broadcast or multicast? Check broadcast first,
4560 * since the test for a multicast frame will test positive on
4561 * a broadcast frame.
4563 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
4564 /* Broadcast packet */
4566 else if(*mac_addr & 0x01)
4567 /* Multicast packet */
4570 if(frame_len == hw->max_frame_size) {
4571 /* In this case, the hardware has overcounted the number of
4578 /* Adjust the bin counters when the extra byte put the frame in the
4579 * wrong bin. Remember that the frame_len was adjusted above.
4581 if(frame_len == 64) {
4584 } else if(frame_len == 127) {
4587 } else if(frame_len == 255) {
4590 } else if(frame_len == 511) {
4593 } else if(frame_len == 1023) {
4596 } else if(frame_len == 1522) {
4601 /******************************************************************************
4602 * Gets the current PCI bus type, speed, and width of the hardware
4604 * hw - Struct containing variables accessed by shared code
4605 *****************************************************************************/
4607 e1000_get_bus_info(struct e1000_hw *hw)
4611 if(hw->mac_type < e1000_82543) {
4612 hw->bus_type = e1000_bus_type_unknown;
4613 hw->bus_speed = e1000_bus_speed_unknown;
4614 hw->bus_width = e1000_bus_width_unknown;
4618 status = E1000_READ_REG(hw, STATUS);
4619 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4620 e1000_bus_type_pcix : e1000_bus_type_pci;
4622 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4623 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4624 e1000_bus_speed_66 : e1000_bus_speed_120;
4625 } else if(hw->bus_type == e1000_bus_type_pci) {
4626 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4627 e1000_bus_speed_66 : e1000_bus_speed_33;
4629 switch (status & E1000_STATUS_PCIX_SPEED) {
4630 case E1000_STATUS_PCIX_SPEED_66:
4631 hw->bus_speed = e1000_bus_speed_66;
4633 case E1000_STATUS_PCIX_SPEED_100:
4634 hw->bus_speed = e1000_bus_speed_100;
4636 case E1000_STATUS_PCIX_SPEED_133:
4637 hw->bus_speed = e1000_bus_speed_133;
4640 hw->bus_speed = e1000_bus_speed_reserved;
4644 hw->bus_width = (status & E1000_STATUS_BUS64) ?
4645 e1000_bus_width_64 : e1000_bus_width_32;
4647 /******************************************************************************
4648 * Reads a value from one of the devices registers using port I/O (as opposed
4649 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4651 * hw - Struct containing variables accessed by shared code
4652 * offset - offset to read from
4653 *****************************************************************************/
4655 e1000_read_reg_io(struct e1000_hw *hw,
4658 unsigned long io_addr = hw->io_base;
4659 unsigned long io_data = hw->io_base + 4;
4661 e1000_io_write(hw, io_addr, offset);
4662 return e1000_io_read(hw, io_data);
4665 /******************************************************************************
4666 * Writes a value to one of the devices registers using port I/O (as opposed to
4667 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4669 * hw - Struct containing variables accessed by shared code
4670 * offset - offset to write to
4671 * value - value to write
4672 *****************************************************************************/
4674 e1000_write_reg_io(struct e1000_hw *hw,
4678 unsigned long io_addr = hw->io_base;
4679 unsigned long io_data = hw->io_base + 4;
4681 e1000_io_write(hw, io_addr, offset);
4682 e1000_io_write(hw, io_data, value);
4686 /******************************************************************************
4687 * Estimates the cable length.
4689 * hw - Struct containing variables accessed by shared code
4690 * min_length - The estimated minimum length
4691 * max_length - The estimated maximum length
4693 * returns: - E1000_ERR_XXX
4696 * This function always returns a ranged length (minimum & maximum).
4697 * So for M88 phy's, this function interprets the one value returned from the
4698 * register to the minimum and maximum range.
4699 * For IGP phy's, the function calculates the range by the AGC registers.
4700 *****************************************************************************/
4702 e1000_get_cable_length(struct e1000_hw *hw,
4703 uint16_t *min_length,
4704 uint16_t *max_length)
4707 uint16_t agc_value = 0;
4708 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4709 uint16_t i, phy_data;
4711 DEBUGFUNC("e1000_get_cable_length");
4713 *min_length = *max_length = 0;
4715 /* Use old method for Phy older than IGP */
4716 if(hw->phy_type == e1000_phy_m88) {
4717 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4722 /* Convert the enum value to ranged values */
4723 switch((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4724 M88E1000_PSSR_CABLE_LENGTH_SHIFT) {
4725 case e1000_cable_length_50:
4727 *max_length = e1000_igp_cable_length_50;
4729 case e1000_cable_length_50_80:
4730 *min_length = e1000_igp_cable_length_50;
4731 *max_length = e1000_igp_cable_length_80;
4733 case e1000_cable_length_80_110:
4734 *min_length = e1000_igp_cable_length_80;
4735 *max_length = e1000_igp_cable_length_110;
4737 case e1000_cable_length_110_140:
4738 *min_length = e1000_igp_cable_length_110;
4739 *max_length = e1000_igp_cable_length_140;
4741 case e1000_cable_length_140:
4742 *min_length = e1000_igp_cable_length_140;
4743 *max_length = e1000_igp_cable_length_170;
4746 return -E1000_ERR_PHY;
4749 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4750 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4751 {IGP01E1000_PHY_AGC_A,
4752 IGP01E1000_PHY_AGC_B,
4753 IGP01E1000_PHY_AGC_C,
4754 IGP01E1000_PHY_AGC_D};
4755 /* Read the AGC registers for all channels */
4756 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4758 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
4762 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4764 /* Array bound check. */
4765 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4767 return -E1000_ERR_PHY;
4769 agc_value += cur_agc;
4771 /* Update minimal AGC value. */
4772 if(min_agc > cur_agc)
4776 /* Remove the minimal AGC result for length < 50m */
4777 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4778 agc_value -= min_agc;
4780 /* Get the average length of the remaining 3 channels */
4781 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4783 /* Get the average length of all the 4 channels. */
4784 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4787 /* Set the range of the calculated length. */
4788 *min_length = ((e1000_igp_cable_length_table[agc_value] -
4789 IGP01E1000_AGC_RANGE) > 0) ?
4790 (e1000_igp_cable_length_table[agc_value] -
4791 IGP01E1000_AGC_RANGE) : 0;
4792 *max_length = e1000_igp_cable_length_table[agc_value] +
4793 IGP01E1000_AGC_RANGE;
4796 return E1000_SUCCESS;
4799 /******************************************************************************
4800 * Check the cable polarity
4802 * hw - Struct containing variables accessed by shared code
4803 * polarity - output parameter : 0 - Polarity is not reversed
4804 * 1 - Polarity is reversed.
4806 * returns: - E1000_ERR_XXX
4809 * For phy's older then IGP, this function simply reads the polarity bit in the
4810 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
4811 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
4812 * return 0. If the link speed is 1000 Mbps the polarity status is in the
4813 * IGP01E1000_PHY_PCS_INIT_REG.
4814 *****************************************************************************/
4816 e1000_check_polarity(struct e1000_hw *hw,
4822 DEBUGFUNC("e1000_check_polarity");
4824 if(hw->phy_type == e1000_phy_m88) {
4825 /* return the Polarity bit in the Status register. */
4826 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4830 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
4831 M88E1000_PSSR_REV_POLARITY_SHIFT;
4832 } else if(hw->phy_type == e1000_phy_igp) {
4833 /* Read the Status register to check the speed */
4834 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4839 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4840 * find the polarity status */
4841 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4842 IGP01E1000_PSSR_SPEED_1000MBPS) {
4844 /* Read the GIG initialization PCS register (0x00B4) */
4845 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4850 /* Check the polarity bits */
4851 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
4853 /* For 10 Mbps, read the polarity bit in the status register. (for
4854 * 100 Mbps this bit is always 0) */
4855 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
4858 return E1000_SUCCESS;
4861 /******************************************************************************
4862 * Check if Downshift occured
4864 * hw - Struct containing variables accessed by shared code
4865 * downshift - output parameter : 0 - No Downshift ocured.
4866 * 1 - Downshift ocured.
4868 * returns: - E1000_ERR_XXX
4871 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4872 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
4873 * Link Health register. In IGP this bit is latched high, so the driver must
4874 * read it immediately after link is established.
4875 *****************************************************************************/
4877 e1000_check_downshift(struct e1000_hw *hw)
4882 DEBUGFUNC("e1000_check_downshift");
4884 if(hw->phy_type == e1000_phy_igp) {
4885 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
4890 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
4892 else if(hw->phy_type == e1000_phy_m88) {
4893 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4898 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
4899 M88E1000_PSSR_DOWNSHIFT_SHIFT;
4901 return E1000_SUCCESS;
4904 /*****************************************************************************
4906 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4907 * gigabit link is achieved to improve link quality.
4909 * hw: Struct containing variables accessed by shared code
4911 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4912 * E1000_SUCCESS at any other case.
4914 ****************************************************************************/
4917 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
4921 uint16_t phy_data, speed, duplex, i;
4922 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4923 {IGP01E1000_PHY_AGC_PARAM_A,
4924 IGP01E1000_PHY_AGC_PARAM_B,
4925 IGP01E1000_PHY_AGC_PARAM_C,
4926 IGP01E1000_PHY_AGC_PARAM_D};
4927 uint16_t min_length, max_length;
4929 DEBUGFUNC("e1000_config_dsp_after_link_change");
4931 if(hw->phy_type != e1000_phy_igp)
4932 return E1000_SUCCESS;
4935 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
4937 DEBUGOUT("Error getting link speed and duplex\n");
4941 if(speed == SPEED_1000) {
4943 e1000_get_cable_length(hw, &min_length, &max_length);
4945 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
4946 min_length >= e1000_igp_cable_length_50) {
4948 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4949 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4954 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4956 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
4961 hw->dsp_config_state = e1000_dsp_config_activated;
4964 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
4965 (min_length < e1000_igp_cable_length_50)) {
4967 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
4968 uint32_t idle_errs = 0;
4970 /* clear previous idle error counts */
4971 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4976 for(i = 0; i < ffe_idle_err_timeout; i++) {
4978 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4983 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
4984 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
4985 hw->ffe_config_state = e1000_ffe_config_active;
4987 ret_val = e1000_write_phy_reg(hw,
4988 IGP01E1000_PHY_DSP_FFE,
4989 IGP01E1000_PHY_DSP_FFE_CM_CP);
4996 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5001 if(hw->dsp_config_state == e1000_dsp_config_activated) {
5002 ret_val = e1000_write_phy_reg(hw, 0x0000,
5003 IGP01E1000_IEEE_FORCE_GIGA);
5006 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5007 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5011 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5012 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5014 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5019 ret_val = e1000_write_phy_reg(hw, 0x0000,
5020 IGP01E1000_IEEE_RESTART_AUTONEG);
5024 hw->dsp_config_state = e1000_dsp_config_enabled;
5027 if(hw->ffe_config_state == e1000_ffe_config_active) {
5028 ret_val = e1000_write_phy_reg(hw, 0x0000,
5029 IGP01E1000_IEEE_FORCE_GIGA);
5032 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5033 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5037 ret_val = e1000_write_phy_reg(hw, 0x0000,
5038 IGP01E1000_IEEE_RESTART_AUTONEG);
5041 hw->ffe_config_state = e1000_ffe_config_enabled;
5044 return E1000_SUCCESS;
5047 /*****************************************************************************
5048 * Set PHY to class A mode
5049 * Assumes the following operations will follow to enable the new class mode.
5050 * 1. Do a PHY soft reset
5051 * 2. Restart auto-negotiation or force link.
5053 * hw - Struct containing variables accessed by shared code
5054 ****************************************************************************/
5056 e1000_set_phy_mode(struct e1000_hw *hw)
5059 uint16_t eeprom_data;
5061 DEBUGFUNC("e1000_set_phy_mode");
5063 if((hw->mac_type == e1000_82545_rev_3) &&
5064 (hw->media_type == e1000_media_type_copper)) {
5065 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5070 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5071 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5072 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5075 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5079 hw->phy_reset_disable = FALSE;
5083 return E1000_SUCCESS;
5086 /*****************************************************************************
5088 * This function sets the lplu state according to the active flag. When
5089 * activating lplu this function also disables smart speed and vise versa.
5090 * lplu will not be activated unless the device autonegotiation advertisment
5091 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5092 * hw: Struct containing variables accessed by shared code
5093 * active - true to enable lplu false to disable lplu.
5095 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5096 * E1000_SUCCESS at any other case.
5098 ****************************************************************************/
5101 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5106 DEBUGFUNC("e1000_set_d3_lplu_state");
5108 if(!((hw->mac_type == e1000_82541_rev_2) ||
5109 (hw->mac_type == e1000_82547_rev_2)))
5110 return E1000_SUCCESS;
5112 /* During driver activity LPLU should not be used or it will attain link
5113 * from the lowest speeds starting from 10Mbps. The capability is used for
5114 * Dx transitions and states */
5115 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5120 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5121 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5125 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5126 * Dx states where the power conservation is most important. During
5127 * driver activity we should enable SmartSpeed, so performance is
5129 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5133 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5134 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5138 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5139 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5140 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5142 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5143 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5147 /* When LPLU is enabled we should disable SmartSpeed */
5148 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5152 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5153 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5158 return E1000_SUCCESS;
5161 /******************************************************************************
5162 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5164 * hw - Struct containing variables accessed by shared code
5165 *****************************************************************************/
5167 e1000_set_vco_speed(struct e1000_hw *hw)
5170 uint16_t default_page = 0;
5173 DEBUGFUNC("e1000_set_vco_speed");
5175 switch(hw->mac_type) {
5176 case e1000_82545_rev_3:
5177 case e1000_82546_rev_3:
5180 return E1000_SUCCESS;
5183 /* Set PHY register 30, page 5, bit 8 to 0 */
5185 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5189 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5193 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5197 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5198 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5202 /* Set PHY register 30, page 4, bit 11 to 1 */
5204 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5208 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5212 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5213 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5217 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5221 return E1000_SUCCESS;
5225 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
5228 uint16_t mii_status_reg;
5231 /* Polarity reversal workaround for forced 10F/10H links. */
5233 /* Disable the transmitter on the PHY */
5235 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5238 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
5242 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5246 /* This loop will early-out if the NO link condition has been met. */
5247 for(i = PHY_FORCE_TIME; i > 0; i--) {
5248 /* Read the MII Status Register and wait for Link Status bit
5252 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5256 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5260 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
5261 msec_delay_irq(100);
5264 /* Recommended delay time after link has been lost */
5265 msec_delay_irq(1000);
5267 /* Now we will re-enable th transmitter on the PHY */
5269 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
5273 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
5277 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
5281 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
5285 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
5289 /* This loop will early-out if the link condition has been met. */
5290 for(i = PHY_FORCE_TIME; i > 0; i--) {
5291 /* Read the MII Status Register and wait for Link Status bit
5295 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5299 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
5303 if(mii_status_reg & MII_SR_LINK_STATUS) break;
5304 msec_delay_irq(100);
5306 return E1000_SUCCESS;