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_set_vco_speed(struct e1000_hw *hw);
67 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
69 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
70 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
72 /* IGP cable length table */
74 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
75 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
76 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
77 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
78 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
79 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
80 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
81 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
82 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
85 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
86 { 8, 13, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43,
87 22, 24, 27, 30, 32, 35, 37, 40, 42, 44, 47, 49, 51, 54, 56, 58,
88 32, 35, 38, 41, 44, 47, 50, 53, 55, 58, 61, 63, 66, 69, 71, 74,
89 43, 47, 51, 54, 58, 61, 64, 67, 71, 74, 77, 80, 82, 85, 88, 90,
90 57, 62, 66, 70, 74, 77, 81, 85, 88, 91, 94, 97, 100, 103, 106, 108,
91 73, 78, 82, 87, 91, 95, 98, 102, 105, 109, 112, 114, 117, 119, 122, 124,
92 91, 96, 101, 105, 109, 113, 116, 119, 122, 125, 127, 128, 128, 128, 128, 128,
93 108, 113, 117, 121, 124, 127, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128};
96 /******************************************************************************
97 * Set the phy type member in the hw struct.
99 * hw - Struct containing variables accessed by shared code
100 *****************************************************************************/
102 e1000_set_phy_type(struct e1000_hw *hw)
104 DEBUGFUNC("e1000_set_phy_type");
106 if(hw->mac_type == e1000_undefined)
107 return -E1000_ERR_PHY_TYPE;
110 case M88E1000_E_PHY_ID:
111 case M88E1000_I_PHY_ID:
112 case M88E1011_I_PHY_ID:
113 case M88E1111_I_PHY_ID:
114 hw->phy_type = e1000_phy_m88;
116 case IGP01E1000_I_PHY_ID:
117 if(hw->mac_type == e1000_82541 ||
118 hw->mac_type == e1000_82541_rev_2 ||
119 hw->mac_type == e1000_82547 ||
120 hw->mac_type == e1000_82547_rev_2) {
121 hw->phy_type = e1000_phy_igp;
126 /* Should never have loaded on this device */
127 hw->phy_type = e1000_phy_undefined;
128 return -E1000_ERR_PHY_TYPE;
131 return E1000_SUCCESS;
134 /******************************************************************************
135 * IGP phy init script - initializes the GbE PHY
137 * hw - Struct containing variables accessed by shared code
138 *****************************************************************************/
140 e1000_phy_init_script(struct e1000_hw *hw)
143 uint16_t phy_saved_data;
145 DEBUGFUNC("e1000_phy_init_script");
148 if(hw->phy_init_script) {
151 /* Save off the current value of register 0x2F5B to be restored at
152 * the end of this routine. */
153 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
155 /* Disabled the PHY transmitter */
156 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
160 e1000_write_phy_reg(hw,0x0000,0x0140);
164 switch(hw->mac_type) {
167 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
169 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
171 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
173 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
175 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
177 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
179 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
181 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
183 e1000_write_phy_reg(hw, 0x2010, 0x0008);
186 case e1000_82541_rev_2:
187 case e1000_82547_rev_2:
188 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
194 e1000_write_phy_reg(hw, 0x0000, 0x3300);
198 /* Now enable the transmitter */
199 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
201 if(hw->mac_type == e1000_82547) {
202 uint16_t fused, fine, coarse;
204 /* Move to analog registers page */
205 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
207 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
208 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
210 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
211 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
213 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
214 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
215 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
216 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
217 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
219 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
220 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
221 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
223 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
224 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
225 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
231 /******************************************************************************
232 * Set the mac type member in the hw struct.
234 * hw - Struct containing variables accessed by shared code
235 *****************************************************************************/
237 e1000_set_mac_type(struct e1000_hw *hw)
239 DEBUGFUNC("e1000_set_mac_type");
241 switch (hw->device_id) {
242 case E1000_DEV_ID_82542:
243 switch (hw->revision_id) {
244 case E1000_82542_2_0_REV_ID:
245 hw->mac_type = e1000_82542_rev2_0;
247 case E1000_82542_2_1_REV_ID:
248 hw->mac_type = e1000_82542_rev2_1;
251 /* Invalid 82542 revision ID */
252 return -E1000_ERR_MAC_TYPE;
255 case E1000_DEV_ID_82543GC_FIBER:
256 case E1000_DEV_ID_82543GC_COPPER:
257 hw->mac_type = e1000_82543;
259 case E1000_DEV_ID_82544EI_COPPER:
260 case E1000_DEV_ID_82544EI_FIBER:
261 case E1000_DEV_ID_82544GC_COPPER:
262 case E1000_DEV_ID_82544GC_LOM:
263 hw->mac_type = e1000_82544;
265 case E1000_DEV_ID_82540EM:
266 case E1000_DEV_ID_82540EM_LOM:
267 case E1000_DEV_ID_82540EP:
268 case E1000_DEV_ID_82540EP_LOM:
269 case E1000_DEV_ID_82540EP_LP:
270 hw->mac_type = e1000_82540;
272 case E1000_DEV_ID_82545EM_COPPER:
273 case E1000_DEV_ID_82545EM_FIBER:
274 hw->mac_type = e1000_82545;
276 case E1000_DEV_ID_82545GM_COPPER:
277 case E1000_DEV_ID_82545GM_FIBER:
278 case E1000_DEV_ID_82545GM_SERDES:
279 hw->mac_type = e1000_82545_rev_3;
281 case E1000_DEV_ID_82546EB_COPPER:
282 case E1000_DEV_ID_82546EB_FIBER:
283 case E1000_DEV_ID_82546EB_QUAD_COPPER:
284 hw->mac_type = e1000_82546;
286 case E1000_DEV_ID_82546GB_COPPER:
287 case E1000_DEV_ID_82546GB_FIBER:
288 case E1000_DEV_ID_82546GB_SERDES:
289 case E1000_DEV_ID_82546GB_PCIE:
290 case E1000_DEV_ID_82546GB_QUAD_COPPER:
291 hw->mac_type = e1000_82546_rev_3;
293 case E1000_DEV_ID_82541EI:
294 case E1000_DEV_ID_82541EI_MOBILE:
295 hw->mac_type = e1000_82541;
297 case E1000_DEV_ID_82541ER:
298 case E1000_DEV_ID_82541GI:
299 case E1000_DEV_ID_82541GI_LF:
300 case E1000_DEV_ID_82541GI_MOBILE:
301 hw->mac_type = e1000_82541_rev_2;
303 case E1000_DEV_ID_82547EI:
304 hw->mac_type = e1000_82547;
306 case E1000_DEV_ID_82547GI:
307 hw->mac_type = e1000_82547_rev_2;
309 case E1000_DEV_ID_82573E:
310 case E1000_DEV_ID_82573E_IAMT:
311 hw->mac_type = e1000_82573;
314 /* Should never have loaded on this device */
315 return -E1000_ERR_MAC_TYPE;
318 switch(hw->mac_type) {
320 hw->eeprom_semaphore_present = TRUE;
324 case e1000_82541_rev_2:
325 case e1000_82547_rev_2:
326 hw->asf_firmware_present = TRUE;
332 return E1000_SUCCESS;
335 /*****************************************************************************
336 * Set media type and TBI compatibility.
338 * hw - Struct containing variables accessed by shared code
339 * **************************************************************************/
341 e1000_set_media_type(struct e1000_hw *hw)
345 DEBUGFUNC("e1000_set_media_type");
347 if(hw->mac_type != e1000_82543) {
348 /* tbi_compatibility is only valid on 82543 */
349 hw->tbi_compatibility_en = FALSE;
352 switch (hw->device_id) {
353 case E1000_DEV_ID_82545GM_SERDES:
354 case E1000_DEV_ID_82546GB_SERDES:
355 hw->media_type = e1000_media_type_internal_serdes;
358 if(hw->mac_type >= e1000_82543) {
359 status = E1000_READ_REG(hw, STATUS);
360 if(status & E1000_STATUS_TBIMODE) {
361 hw->media_type = e1000_media_type_fiber;
362 /* tbi_compatibility not valid on fiber */
363 hw->tbi_compatibility_en = FALSE;
365 hw->media_type = e1000_media_type_copper;
368 /* This is an 82542 (fiber only) */
369 hw->media_type = e1000_media_type_fiber;
374 /******************************************************************************
375 * Reset the transmit and receive units; mask and clear all interrupts.
377 * hw - Struct containing variables accessed by shared code
378 *****************************************************************************/
380 e1000_reset_hw(struct e1000_hw *hw)
388 uint32_t extcnf_ctrl;
391 DEBUGFUNC("e1000_reset_hw");
393 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
394 if(hw->mac_type == e1000_82542_rev2_0) {
395 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
396 e1000_pci_clear_mwi(hw);
399 if(hw->bus_type == e1000_bus_type_pci_express) {
400 /* Prevent the PCI-E bus from sticking if there is no TLP connection
401 * on the last TLP read/write transaction when MAC is reset.
403 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
404 DEBUGOUT("PCI-E Master disable polling has failed.\n");
408 /* Clear interrupt mask to stop board from generating interrupts */
409 DEBUGOUT("Masking off all interrupts\n");
410 E1000_WRITE_REG(hw, IMC, 0xffffffff);
412 /* Disable the Transmit and Receive units. Then delay to allow
413 * any pending transactions to complete before we hit the MAC with
416 E1000_WRITE_REG(hw, RCTL, 0);
417 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
418 E1000_WRITE_FLUSH(hw);
420 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
421 hw->tbi_compatibility_on = FALSE;
423 /* Delay to allow any outstanding PCI transactions to complete before
424 * resetting the device
428 ctrl = E1000_READ_REG(hw, CTRL);
430 /* Must reset the PHY before resetting the MAC */
431 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
432 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
436 /* Must acquire the MDIO ownership before MAC reset.
437 * Ownership defaults to firmware after a reset. */
438 if(hw->mac_type == e1000_82573) {
441 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
442 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
445 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
446 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
448 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
451 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
458 /* Issue a global reset to the MAC. This will reset the chip's
459 * transmit, receive, DMA, and link units. It will not effect
460 * the current PCI configuration. The global reset bit is self-
461 * clearing, and should clear within a microsecond.
463 DEBUGOUT("Issuing a global reset to MAC\n");
465 switch(hw->mac_type) {
471 case e1000_82541_rev_2:
472 /* These controllers can't ack the 64-bit write when issuing the
473 * reset, so use IO-mapping as a workaround to issue the reset */
474 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
476 case e1000_82545_rev_3:
477 case e1000_82546_rev_3:
478 /* Reset is performed on a shadow of the control register */
479 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
482 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
486 /* After MAC reset, force reload of EEPROM to restore power-on settings to
487 * device. Later controllers reload the EEPROM automatically, so just wait
488 * for reload to complete.
490 switch(hw->mac_type) {
491 case e1000_82542_rev2_0:
492 case e1000_82542_rev2_1:
495 /* Wait for reset to complete */
497 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
498 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
499 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
500 E1000_WRITE_FLUSH(hw);
501 /* Wait for EEPROM reload */
505 case e1000_82541_rev_2:
507 case e1000_82547_rev_2:
508 /* Wait for EEPROM reload */
513 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
514 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
515 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
516 E1000_WRITE_FLUSH(hw);
518 ret_val = e1000_get_auto_rd_done(hw);
520 /* We don't want to continue accessing MAC registers. */
524 /* Wait for EEPROM reload (it happens automatically) */
529 /* Disable HW ARPs on ASF enabled adapters */
530 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
531 manc = E1000_READ_REG(hw, MANC);
532 manc &= ~(E1000_MANC_ARP_EN);
533 E1000_WRITE_REG(hw, MANC, manc);
536 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
537 e1000_phy_init_script(hw);
539 /* Configure activity LED after PHY reset */
540 led_ctrl = E1000_READ_REG(hw, LEDCTL);
541 led_ctrl &= IGP_ACTIVITY_LED_MASK;
542 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
543 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
546 /* Clear interrupt mask to stop board from generating interrupts */
547 DEBUGOUT("Masking off all interrupts\n");
548 E1000_WRITE_REG(hw, IMC, 0xffffffff);
550 /* Clear any pending interrupt events. */
551 icr = E1000_READ_REG(hw, ICR);
553 /* If MWI was previously enabled, reenable it. */
554 if(hw->mac_type == e1000_82542_rev2_0) {
555 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
556 e1000_pci_set_mwi(hw);
559 return E1000_SUCCESS;
562 /******************************************************************************
563 * Performs basic configuration of the adapter.
565 * hw - Struct containing variables accessed by shared code
567 * Assumes that the controller has previously been reset and is in a
568 * post-reset uninitialized state. Initializes the receive address registers,
569 * multicast table, and VLAN filter table. Calls routines to setup link
570 * configuration and flow control settings. Clears all on-chip counters. Leaves
571 * the transmit and receive units disabled and uninitialized.
572 *****************************************************************************/
574 e1000_init_hw(struct e1000_hw *hw)
579 uint16_t pcix_cmd_word;
580 uint16_t pcix_stat_hi_word;
585 DEBUGFUNC("e1000_init_hw");
587 /* Initialize Identification LED */
588 ret_val = e1000_id_led_init(hw);
590 DEBUGOUT("Error Initializing Identification LED\n");
594 /* Set the media type and TBI compatibility */
595 e1000_set_media_type(hw);
597 /* Disabling VLAN filtering. */
598 DEBUGOUT("Initializing the IEEE VLAN\n");
599 if (hw->mac_type < e1000_82545_rev_3)
600 E1000_WRITE_REG(hw, VET, 0);
601 e1000_clear_vfta(hw);
603 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
604 if(hw->mac_type == e1000_82542_rev2_0) {
605 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
606 e1000_pci_clear_mwi(hw);
607 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
608 E1000_WRITE_FLUSH(hw);
612 /* Setup the receive address. This involves initializing all of the Receive
613 * Address Registers (RARs 0 - 15).
615 e1000_init_rx_addrs(hw);
617 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
618 if(hw->mac_type == e1000_82542_rev2_0) {
619 E1000_WRITE_REG(hw, RCTL, 0);
620 E1000_WRITE_FLUSH(hw);
622 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
623 e1000_pci_set_mwi(hw);
626 /* Zero out the Multicast HASH table */
627 DEBUGOUT("Zeroing the MTA\n");
628 mta_size = E1000_MC_TBL_SIZE;
629 for(i = 0; i < mta_size; i++)
630 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
632 /* Set the PCI priority bit correctly in the CTRL register. This
633 * determines if the adapter gives priority to receives, or if it
634 * gives equal priority to transmits and receives. Valid only on
635 * 82542 and 82543 silicon.
637 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
638 ctrl = E1000_READ_REG(hw, CTRL);
639 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
642 switch(hw->mac_type) {
643 case e1000_82545_rev_3:
644 case e1000_82546_rev_3:
647 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
648 if(hw->bus_type == e1000_bus_type_pcix) {
649 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
650 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
652 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
653 PCIX_COMMAND_MMRBC_SHIFT;
654 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
655 PCIX_STATUS_HI_MMRBC_SHIFT;
656 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
657 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
658 if(cmd_mmrbc > stat_mmrbc) {
659 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
660 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
661 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
668 /* Call a subroutine to configure the link and setup flow control. */
669 ret_val = e1000_setup_link(hw);
671 /* Set the transmit descriptor write-back policy */
672 if(hw->mac_type > e1000_82544) {
673 ctrl = E1000_READ_REG(hw, TXDCTL);
674 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
675 switch (hw->mac_type) {
679 ctrl |= E1000_TXDCTL_COUNT_DESC;
682 E1000_WRITE_REG(hw, TXDCTL, ctrl);
685 if (hw->mac_type == e1000_82573) {
686 e1000_enable_tx_pkt_filtering(hw);
690 /* Clear all of the statistics registers (clear on read). It is
691 * important that we do this after we have tried to establish link
692 * because the symbol error count will increment wildly if there
695 e1000_clear_hw_cntrs(hw);
700 /******************************************************************************
701 * Adjust SERDES output amplitude based on EEPROM setting.
703 * hw - Struct containing variables accessed by shared code.
704 *****************************************************************************/
706 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
708 uint16_t eeprom_data;
711 DEBUGFUNC("e1000_adjust_serdes_amplitude");
713 if(hw->media_type != e1000_media_type_internal_serdes)
714 return E1000_SUCCESS;
716 switch(hw->mac_type) {
717 case e1000_82545_rev_3:
718 case e1000_82546_rev_3:
721 return E1000_SUCCESS;
724 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
729 if(eeprom_data != EEPROM_RESERVED_WORD) {
730 /* Adjust SERDES output amplitude only. */
731 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
732 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
737 return E1000_SUCCESS;
740 /******************************************************************************
741 * Configures flow control and link settings.
743 * hw - Struct containing variables accessed by shared code
745 * Determines which flow control settings to use. Calls the apropriate media-
746 * specific link configuration function. Configures the flow control settings.
747 * Assuming the adapter has a valid link partner, a valid link should be
748 * established. Assumes the hardware has previously been reset and the
749 * transmitter and receiver are not enabled.
750 *****************************************************************************/
752 e1000_setup_link(struct e1000_hw *hw)
756 uint16_t eeprom_data;
758 DEBUGFUNC("e1000_setup_link");
760 /* Read and store word 0x0F of the EEPROM. This word contains bits
761 * that determine the hardware's default PAUSE (flow control) mode,
762 * a bit that determines whether the HW defaults to enabling or
763 * disabling auto-negotiation, and the direction of the
764 * SW defined pins. If there is no SW over-ride of the flow
765 * control setting, then the variable hw->fc will
766 * be initialized based on a value in the EEPROM.
768 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
769 DEBUGOUT("EEPROM Read Error\n");
770 return -E1000_ERR_EEPROM;
773 if(hw->fc == e1000_fc_default) {
774 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
775 hw->fc = e1000_fc_none;
776 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
777 EEPROM_WORD0F_ASM_DIR)
778 hw->fc = e1000_fc_tx_pause;
780 hw->fc = e1000_fc_full;
783 /* We want to save off the original Flow Control configuration just
784 * in case we get disconnected and then reconnected into a different
785 * hub or switch with different Flow Control capabilities.
787 if(hw->mac_type == e1000_82542_rev2_0)
788 hw->fc &= (~e1000_fc_tx_pause);
790 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
791 hw->fc &= (~e1000_fc_rx_pause);
793 hw->original_fc = hw->fc;
795 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
797 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
798 * polarity value for the SW controlled pins, and setup the
799 * Extended Device Control reg with that info.
800 * This is needed because one of the SW controlled pins is used for
801 * signal detection. So this should be done before e1000_setup_pcs_link()
802 * or e1000_phy_setup() is called.
804 if(hw->mac_type == e1000_82543) {
805 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
807 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
810 /* Call the necessary subroutine to configure the link. */
811 ret_val = (hw->media_type == e1000_media_type_copper) ?
812 e1000_setup_copper_link(hw) :
813 e1000_setup_fiber_serdes_link(hw);
815 /* Initialize the flow control address, type, and PAUSE timer
816 * registers to their default values. This is done even if flow
817 * control is disabled, because it does not hurt anything to
818 * initialize these registers.
820 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
822 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
823 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
824 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
826 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
828 /* Set the flow control receive threshold registers. Normally,
829 * these registers will be set to a default threshold that may be
830 * adjusted later by the driver's runtime code. However, if the
831 * ability to transmit pause frames in not enabled, then these
832 * registers will be set to 0.
834 if(!(hw->fc & e1000_fc_tx_pause)) {
835 E1000_WRITE_REG(hw, FCRTL, 0);
836 E1000_WRITE_REG(hw, FCRTH, 0);
838 /* We need to set up the Receive Threshold high and low water marks
839 * as well as (optionally) enabling the transmission of XON frames.
841 if(hw->fc_send_xon) {
842 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
843 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
845 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
846 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
852 /******************************************************************************
853 * Sets up link for a fiber based or serdes based adapter
855 * hw - Struct containing variables accessed by shared code
857 * Manipulates Physical Coding Sublayer functions in order to configure
858 * link. Assumes the hardware has been previously reset and the transmitter
859 * and receiver are not enabled.
860 *****************************************************************************/
862 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
871 DEBUGFUNC("e1000_setup_fiber_serdes_link");
873 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
874 * set when the optics detect a signal. On older adapters, it will be
875 * cleared when there is a signal. This applies to fiber media only.
876 * If we're on serdes media, adjust the output amplitude to value set in
879 ctrl = E1000_READ_REG(hw, CTRL);
880 if(hw->media_type == e1000_media_type_fiber)
881 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
883 ret_val = e1000_adjust_serdes_amplitude(hw);
887 /* Take the link out of reset */
888 ctrl &= ~(E1000_CTRL_LRST);
890 /* Adjust VCO speed to improve BER performance */
891 ret_val = e1000_set_vco_speed(hw);
895 e1000_config_collision_dist(hw);
897 /* Check for a software override of the flow control settings, and setup
898 * the device accordingly. If auto-negotiation is enabled, then software
899 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
900 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
901 * auto-negotiation is disabled, then software will have to manually
902 * configure the two flow control enable bits in the CTRL register.
904 * The possible values of the "fc" parameter are:
905 * 0: Flow control is completely disabled
906 * 1: Rx flow control is enabled (we can receive pause frames, but
907 * not send pause frames).
908 * 2: Tx flow control is enabled (we can send pause frames but we do
909 * not support receiving pause frames).
910 * 3: Both Rx and TX flow control (symmetric) are enabled.
914 /* Flow control is completely disabled by a software over-ride. */
915 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
917 case e1000_fc_rx_pause:
918 /* RX Flow control is enabled and TX Flow control is disabled by a
919 * software over-ride. Since there really isn't a way to advertise
920 * that we are capable of RX Pause ONLY, we will advertise that we
921 * support both symmetric and asymmetric RX PAUSE. Later, we will
922 * disable the adapter's ability to send PAUSE frames.
924 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
926 case e1000_fc_tx_pause:
927 /* TX Flow control is enabled, and RX Flow control is disabled, by a
928 * software over-ride.
930 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
933 /* Flow control (both RX and TX) is enabled by a software over-ride. */
934 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
937 DEBUGOUT("Flow control param set incorrectly\n");
938 return -E1000_ERR_CONFIG;
942 /* Since auto-negotiation is enabled, take the link out of reset (the link
943 * will be in reset, because we previously reset the chip). This will
944 * restart auto-negotiation. If auto-neogtiation is successful then the
945 * link-up status bit will be set and the flow control enable bits (RFCE
946 * and TFCE) will be set according to their negotiated value.
948 DEBUGOUT("Auto-negotiation enabled\n");
950 E1000_WRITE_REG(hw, TXCW, txcw);
951 E1000_WRITE_REG(hw, CTRL, ctrl);
952 E1000_WRITE_FLUSH(hw);
957 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
958 * indication in the Device Status Register. Time-out if a link isn't
959 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
960 * less than 500 milliseconds even if the other end is doing it in SW).
961 * For internal serdes, we just assume a signal is present, then poll.
963 if(hw->media_type == e1000_media_type_internal_serdes ||
964 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
965 DEBUGOUT("Looking for Link\n");
966 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
968 status = E1000_READ_REG(hw, STATUS);
969 if(status & E1000_STATUS_LU) break;
971 if(i == (LINK_UP_TIMEOUT / 10)) {
972 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
973 hw->autoneg_failed = 1;
974 /* AutoNeg failed to achieve a link, so we'll call
975 * e1000_check_for_link. This routine will force the link up if
976 * we detect a signal. This will allow us to communicate with
977 * non-autonegotiating link partners.
979 ret_val = e1000_check_for_link(hw);
981 DEBUGOUT("Error while checking for link\n");
984 hw->autoneg_failed = 0;
986 hw->autoneg_failed = 0;
987 DEBUGOUT("Valid Link Found\n");
990 DEBUGOUT("No Signal Detected\n");
992 return E1000_SUCCESS;
995 /******************************************************************************
996 * Make sure we have a valid PHY and change PHY mode before link setup.
998 * hw - Struct containing variables accessed by shared code
999 ******************************************************************************/
1001 e1000_copper_link_preconfig(struct e1000_hw *hw)
1007 DEBUGFUNC("e1000_copper_link_preconfig");
1009 ctrl = E1000_READ_REG(hw, CTRL);
1010 /* With 82543, we need to force speed and duplex on the MAC equal to what
1011 * the PHY speed and duplex configuration is. In addition, we need to
1012 * perform a hardware reset on the PHY to take it out of reset.
1014 if(hw->mac_type > e1000_82543) {
1015 ctrl |= E1000_CTRL_SLU;
1016 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1017 E1000_WRITE_REG(hw, CTRL, ctrl);
1019 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1020 E1000_WRITE_REG(hw, CTRL, ctrl);
1021 ret_val = e1000_phy_hw_reset(hw);
1026 /* Make sure we have a valid PHY */
1027 ret_val = e1000_detect_gig_phy(hw);
1029 DEBUGOUT("Error, did not detect valid phy.\n");
1032 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1034 /* Set PHY to class A mode (if necessary) */
1035 ret_val = e1000_set_phy_mode(hw);
1039 if((hw->mac_type == e1000_82545_rev_3) ||
1040 (hw->mac_type == e1000_82546_rev_3)) {
1041 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1042 phy_data |= 0x00000008;
1043 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1046 if(hw->mac_type <= e1000_82543 ||
1047 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1048 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1049 hw->phy_reset_disable = FALSE;
1051 return E1000_SUCCESS;
1055 /********************************************************************
1056 * Copper link setup for e1000_phy_igp series.
1058 * hw - Struct containing variables accessed by shared code
1059 *********************************************************************/
1061 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1067 DEBUGFUNC("e1000_copper_link_igp_setup");
1069 if (hw->phy_reset_disable)
1070 return E1000_SUCCESS;
1072 ret_val = e1000_phy_reset(hw);
1074 DEBUGOUT("Error Resetting the PHY\n");
1078 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1081 /* Configure activity LED after PHY reset */
1082 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1083 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1084 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1085 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1087 /* disable lplu d3 during driver init */
1088 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1090 DEBUGOUT("Error Disabling LPLU D3\n");
1094 /* disable lplu d0 during driver init */
1095 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1097 DEBUGOUT("Error Disabling LPLU D0\n");
1100 /* Configure mdi-mdix settings */
1101 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1105 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1106 hw->dsp_config_state = e1000_dsp_config_disabled;
1107 /* Force MDI for earlier revs of the IGP PHY */
1108 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1112 hw->dsp_config_state = e1000_dsp_config_enabled;
1113 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1117 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1120 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1124 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1128 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1132 /* set auto-master slave resolution settings */
1134 e1000_ms_type phy_ms_setting = hw->master_slave;
1136 if(hw->ffe_config_state == e1000_ffe_config_active)
1137 hw->ffe_config_state = e1000_ffe_config_enabled;
1139 if(hw->dsp_config_state == e1000_dsp_config_activated)
1140 hw->dsp_config_state = e1000_dsp_config_enabled;
1142 /* when autonegotiation advertisment is only 1000Mbps then we
1143 * should disable SmartSpeed and enable Auto MasterSlave
1144 * resolution as hardware default. */
1145 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1146 /* Disable SmartSpeed */
1147 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1150 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1151 ret_val = e1000_write_phy_reg(hw,
1152 IGP01E1000_PHY_PORT_CONFIG,
1156 /* Set auto Master/Slave resolution process */
1157 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1160 phy_data &= ~CR_1000T_MS_ENABLE;
1161 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1166 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1170 /* load defaults for future use */
1171 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1172 ((phy_data & CR_1000T_MS_VALUE) ?
1173 e1000_ms_force_master :
1174 e1000_ms_force_slave) :
1177 switch (phy_ms_setting) {
1178 case e1000_ms_force_master:
1179 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1181 case e1000_ms_force_slave:
1182 phy_data |= CR_1000T_MS_ENABLE;
1183 phy_data &= ~(CR_1000T_MS_VALUE);
1186 phy_data &= ~CR_1000T_MS_ENABLE;
1190 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1195 return E1000_SUCCESS;
1199 /********************************************************************
1200 * Copper link setup for e1000_phy_m88 series.
1202 * hw - Struct containing variables accessed by shared code
1203 *********************************************************************/
1205 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1210 DEBUGFUNC("e1000_copper_link_mgp_setup");
1212 if(hw->phy_reset_disable)
1213 return E1000_SUCCESS;
1215 /* Enable CRS on TX. This must be set for half-duplex operation. */
1216 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1220 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1223 * MDI/MDI-X = 0 (default)
1224 * 0 - Auto for all speeds
1227 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1229 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1233 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1236 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1239 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1243 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1248 * disable_polarity_correction = 0 (default)
1249 * Automatic Correction for Reversed Cable Polarity
1253 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1254 if(hw->disable_polarity_correction == 1)
1255 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1256 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1260 /* Force TX_CLK in the Extended PHY Specific Control Register
1263 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1267 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1269 if (hw->phy_revision < M88E1011_I_REV_4) {
1270 /* Configure Master and Slave downshift values */
1271 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1272 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1273 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1274 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1275 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1280 /* SW Reset the PHY so all changes take effect */
1281 ret_val = e1000_phy_reset(hw);
1283 DEBUGOUT("Error Resetting the PHY\n");
1287 return E1000_SUCCESS;
1290 /********************************************************************
1291 * Setup auto-negotiation and flow control advertisements,
1292 * and then perform auto-negotiation.
1294 * hw - Struct containing variables accessed by shared code
1295 *********************************************************************/
1297 e1000_copper_link_autoneg(struct e1000_hw *hw)
1302 DEBUGFUNC("e1000_copper_link_autoneg");
1304 /* Perform some bounds checking on the hw->autoneg_advertised
1305 * parameter. If this variable is zero, then set it to the default.
1307 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1309 /* If autoneg_advertised is zero, we assume it was not defaulted
1310 * by the calling code so we set to advertise full capability.
1312 if(hw->autoneg_advertised == 0)
1313 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1315 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1316 ret_val = e1000_phy_setup_autoneg(hw);
1318 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1321 DEBUGOUT("Restarting Auto-Neg\n");
1323 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1324 * the Auto Neg Restart bit in the PHY control register.
1326 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1330 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1331 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1335 /* Does the user want to wait for Auto-Neg to complete here, or
1336 * check at a later time (for example, callback routine).
1338 if(hw->wait_autoneg_complete) {
1339 ret_val = e1000_wait_autoneg(hw);
1341 DEBUGOUT("Error while waiting for autoneg to complete\n");
1346 hw->get_link_status = TRUE;
1348 return E1000_SUCCESS;
1352 /******************************************************************************
1353 * Config the MAC and the PHY after link is up.
1354 * 1) Set up the MAC to the current PHY speed/duplex
1355 * if we are on 82543. If we
1356 * are on newer silicon, we only need to configure
1357 * collision distance in the Transmit Control Register.
1358 * 2) Set up flow control on the MAC to that established with
1360 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1362 * hw - Struct containing variables accessed by shared code
1363 ******************************************************************************/
1365 e1000_copper_link_postconfig(struct e1000_hw *hw)
1368 DEBUGFUNC("e1000_copper_link_postconfig");
1370 if(hw->mac_type >= e1000_82544) {
1371 e1000_config_collision_dist(hw);
1373 ret_val = e1000_config_mac_to_phy(hw);
1375 DEBUGOUT("Error configuring MAC to PHY settings\n");
1379 ret_val = e1000_config_fc_after_link_up(hw);
1381 DEBUGOUT("Error Configuring Flow Control\n");
1385 /* Config DSP to improve Giga link quality */
1386 if(hw->phy_type == e1000_phy_igp) {
1387 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1389 DEBUGOUT("Error Configuring DSP after link up\n");
1394 return E1000_SUCCESS;
1397 /******************************************************************************
1398 * Detects which PHY is present and setup the speed and duplex
1400 * hw - Struct containing variables accessed by shared code
1401 ******************************************************************************/
1403 e1000_setup_copper_link(struct e1000_hw *hw)
1409 DEBUGFUNC("e1000_setup_copper_link");
1411 /* Check if it is a valid PHY and set PHY mode if necessary. */
1412 ret_val = e1000_copper_link_preconfig(hw);
1416 if (hw->phy_type == e1000_phy_igp ||
1417 hw->phy_type == e1000_phy_igp_2) {
1418 ret_val = e1000_copper_link_igp_setup(hw);
1421 } else if (hw->phy_type == e1000_phy_m88) {
1422 ret_val = e1000_copper_link_mgp_setup(hw);
1428 /* Setup autoneg and flow control advertisement
1429 * and perform autonegotiation */
1430 ret_val = e1000_copper_link_autoneg(hw);
1434 /* PHY will be set to 10H, 10F, 100H,or 100F
1435 * depending on value from forced_speed_duplex. */
1436 DEBUGOUT("Forcing speed and duplex\n");
1437 ret_val = e1000_phy_force_speed_duplex(hw);
1439 DEBUGOUT("Error Forcing Speed and Duplex\n");
1444 /* Check link status. Wait up to 100 microseconds for link to become
1447 for(i = 0; i < 10; i++) {
1448 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1451 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1455 if(phy_data & MII_SR_LINK_STATUS) {
1456 /* Config the MAC and PHY after link is up */
1457 ret_val = e1000_copper_link_postconfig(hw);
1461 DEBUGOUT("Valid link established!!!\n");
1462 return E1000_SUCCESS;
1467 DEBUGOUT("Unable to establish link!!!\n");
1468 return E1000_SUCCESS;
1471 /******************************************************************************
1472 * Configures PHY autoneg and flow control advertisement settings
1474 * hw - Struct containing variables accessed by shared code
1475 ******************************************************************************/
1477 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1480 uint16_t mii_autoneg_adv_reg;
1481 uint16_t mii_1000t_ctrl_reg;
1483 DEBUGFUNC("e1000_phy_setup_autoneg");
1485 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1486 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1490 /* Read the MII 1000Base-T Control Register (Address 9). */
1491 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1495 /* Need to parse both autoneg_advertised and fc and set up
1496 * the appropriate PHY registers. First we will parse for
1497 * autoneg_advertised software override. Since we can advertise
1498 * a plethora of combinations, we need to check each bit
1502 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1503 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1504 * the 1000Base-T Control Register (Address 9).
1506 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1507 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1509 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1511 /* Do we want to advertise 10 Mb Half Duplex? */
1512 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1513 DEBUGOUT("Advertise 10mb Half duplex\n");
1514 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1517 /* Do we want to advertise 10 Mb Full Duplex? */
1518 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1519 DEBUGOUT("Advertise 10mb Full duplex\n");
1520 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1523 /* Do we want to advertise 100 Mb Half Duplex? */
1524 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1525 DEBUGOUT("Advertise 100mb Half duplex\n");
1526 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1529 /* Do we want to advertise 100 Mb Full Duplex? */
1530 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1531 DEBUGOUT("Advertise 100mb Full duplex\n");
1532 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1535 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1536 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1537 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1540 /* Do we want to advertise 1000 Mb Full Duplex? */
1541 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1542 DEBUGOUT("Advertise 1000mb Full duplex\n");
1543 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1546 /* Check for a software override of the flow control settings, and
1547 * setup the PHY advertisement registers accordingly. If
1548 * auto-negotiation is enabled, then software will have to set the
1549 * "PAUSE" bits to the correct value in the Auto-Negotiation
1550 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1552 * The possible values of the "fc" parameter are:
1553 * 0: Flow control is completely disabled
1554 * 1: Rx flow control is enabled (we can receive pause frames
1555 * but not send pause frames).
1556 * 2: Tx flow control is enabled (we can send pause frames
1557 * but we do not support receiving pause frames).
1558 * 3: Both Rx and TX flow control (symmetric) are enabled.
1559 * other: No software override. The flow control configuration
1560 * in the EEPROM is used.
1563 case e1000_fc_none: /* 0 */
1564 /* Flow control (RX & TX) is completely disabled by a
1565 * software over-ride.
1567 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1569 case e1000_fc_rx_pause: /* 1 */
1570 /* RX Flow control is enabled, and TX Flow control is
1571 * disabled, by a software over-ride.
1573 /* Since there really isn't a way to advertise that we are
1574 * capable of RX Pause ONLY, we will advertise that we
1575 * support both symmetric and asymmetric RX PAUSE. Later
1576 * (in e1000_config_fc_after_link_up) we will disable the
1577 *hw's ability to send PAUSE frames.
1579 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1581 case e1000_fc_tx_pause: /* 2 */
1582 /* TX Flow control is enabled, and RX Flow control is
1583 * disabled, by a software over-ride.
1585 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1586 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1588 case e1000_fc_full: /* 3 */
1589 /* Flow control (both RX and TX) is enabled by a software
1592 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1595 DEBUGOUT("Flow control param set incorrectly\n");
1596 return -E1000_ERR_CONFIG;
1599 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1603 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1605 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1609 return E1000_SUCCESS;
1612 /******************************************************************************
1613 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1615 * hw - Struct containing variables accessed by shared code
1616 ******************************************************************************/
1618 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1622 uint16_t mii_ctrl_reg;
1623 uint16_t mii_status_reg;
1627 DEBUGFUNC("e1000_phy_force_speed_duplex");
1629 /* Turn off Flow control if we are forcing speed and duplex. */
1630 hw->fc = e1000_fc_none;
1632 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1634 /* Read the Device Control Register. */
1635 ctrl = E1000_READ_REG(hw, CTRL);
1637 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1638 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1639 ctrl &= ~(DEVICE_SPEED_MASK);
1641 /* Clear the Auto Speed Detect Enable bit. */
1642 ctrl &= ~E1000_CTRL_ASDE;
1644 /* Read the MII Control Register. */
1645 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1649 /* We need to disable autoneg in order to force link and duplex. */
1651 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1653 /* Are we forcing Full or Half Duplex? */
1654 if(hw->forced_speed_duplex == e1000_100_full ||
1655 hw->forced_speed_duplex == e1000_10_full) {
1656 /* We want to force full duplex so we SET the full duplex bits in the
1657 * Device and MII Control Registers.
1659 ctrl |= E1000_CTRL_FD;
1660 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1661 DEBUGOUT("Full Duplex\n");
1663 /* We want to force half duplex so we CLEAR the full duplex bits in
1664 * the Device and MII Control Registers.
1666 ctrl &= ~E1000_CTRL_FD;
1667 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1668 DEBUGOUT("Half Duplex\n");
1671 /* Are we forcing 100Mbps??? */
1672 if(hw->forced_speed_duplex == e1000_100_full ||
1673 hw->forced_speed_duplex == e1000_100_half) {
1674 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1675 ctrl |= E1000_CTRL_SPD_100;
1676 mii_ctrl_reg |= MII_CR_SPEED_100;
1677 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1678 DEBUGOUT("Forcing 100mb ");
1680 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1681 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1682 mii_ctrl_reg |= MII_CR_SPEED_10;
1683 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1684 DEBUGOUT("Forcing 10mb ");
1687 e1000_config_collision_dist(hw);
1689 /* Write the configured values back to the Device Control Reg. */
1690 E1000_WRITE_REG(hw, CTRL, ctrl);
1692 if (hw->phy_type == e1000_phy_m88) {
1693 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1697 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1698 * forced whenever speed are duplex are forced.
1700 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1701 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1705 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1707 /* Need to reset the PHY or these changes will be ignored */
1708 mii_ctrl_reg |= MII_CR_RESET;
1710 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1711 * forced whenever speed or duplex are forced.
1713 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1717 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1718 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1720 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1725 /* Write back the modified PHY MII control register. */
1726 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1732 /* The wait_autoneg_complete flag may be a little misleading here.
1733 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1734 * But we do want to delay for a period while forcing only so we
1735 * don't generate false No Link messages. So we will wait here
1736 * only if the user has set wait_autoneg_complete to 1, which is
1739 if(hw->wait_autoneg_complete) {
1740 /* We will wait for autoneg to complete. */
1741 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1744 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1745 for(i = PHY_FORCE_TIME; i > 0; i--) {
1746 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1749 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1753 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1757 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1761 (hw->phy_type == e1000_phy_m88)) {
1762 /* We didn't get link. Reset the DSP and wait again for link. */
1763 ret_val = e1000_phy_reset_dsp(hw);
1765 DEBUGOUT("Error Resetting PHY DSP\n");
1769 /* This loop will early-out if the link condition has been met. */
1770 for(i = PHY_FORCE_TIME; i > 0; i--) {
1771 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1773 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1776 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1780 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1786 if (hw->phy_type == e1000_phy_m88) {
1787 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1788 * Extended PHY Specific Control Register to 25MHz clock. This value
1789 * defaults back to a 2.5MHz clock when the PHY is reset.
1791 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1795 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1796 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1800 /* In addition, because of the s/w reset above, we need to enable CRS on
1801 * TX. This must be set for both full and half duplex operation.
1803 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1807 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1812 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1814 (hw->forced_speed_duplex == e1000_10_full ||
1815 hw->forced_speed_duplex == e1000_10_half)) {
1816 ret_val = e1000_polarity_reversal_workaround(hw);
1821 return E1000_SUCCESS;
1824 /******************************************************************************
1825 * Sets the collision distance in the Transmit Control register
1827 * hw - Struct containing variables accessed by shared code
1829 * Link should have been established previously. Reads the speed and duplex
1830 * information from the Device Status register.
1831 ******************************************************************************/
1833 e1000_config_collision_dist(struct e1000_hw *hw)
1837 DEBUGFUNC("e1000_config_collision_dist");
1839 tctl = E1000_READ_REG(hw, TCTL);
1841 tctl &= ~E1000_TCTL_COLD;
1842 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1844 E1000_WRITE_REG(hw, TCTL, tctl);
1845 E1000_WRITE_FLUSH(hw);
1848 /******************************************************************************
1849 * Sets MAC speed and duplex settings to reflect the those in the PHY
1851 * hw - Struct containing variables accessed by shared code
1852 * mii_reg - data to write to the MII control register
1854 * The contents of the PHY register containing the needed information need to
1856 ******************************************************************************/
1858 e1000_config_mac_to_phy(struct e1000_hw *hw)
1864 DEBUGFUNC("e1000_config_mac_to_phy");
1866 /* 82544 or newer MAC, Auto Speed Detection takes care of
1867 * MAC speed/duplex configuration.*/
1868 if (hw->mac_type >= e1000_82544)
1869 return E1000_SUCCESS;
1871 /* Read the Device Control Register and set the bits to Force Speed
1874 ctrl = E1000_READ_REG(hw, CTRL);
1875 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1876 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1878 /* Set up duplex in the Device Control and Transmit Control
1879 * registers depending on negotiated values.
1881 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1885 if(phy_data & M88E1000_PSSR_DPLX)
1886 ctrl |= E1000_CTRL_FD;
1888 ctrl &= ~E1000_CTRL_FD;
1890 e1000_config_collision_dist(hw);
1892 /* Set up speed in the Device Control register depending on
1893 * negotiated values.
1895 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1896 ctrl |= E1000_CTRL_SPD_1000;
1897 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1898 ctrl |= E1000_CTRL_SPD_100;
1900 /* Write the configured values back to the Device Control Reg. */
1901 E1000_WRITE_REG(hw, CTRL, ctrl);
1902 return E1000_SUCCESS;
1905 /******************************************************************************
1906 * Forces the MAC's flow control settings.
1908 * hw - Struct containing variables accessed by shared code
1910 * Sets the TFCE and RFCE bits in the device control register to reflect
1911 * the adapter settings. TFCE and RFCE need to be explicitly set by
1912 * software when a Copper PHY is used because autonegotiation is managed
1913 * by the PHY rather than the MAC. Software must also configure these
1914 * bits when link is forced on a fiber connection.
1915 *****************************************************************************/
1917 e1000_force_mac_fc(struct e1000_hw *hw)
1921 DEBUGFUNC("e1000_force_mac_fc");
1923 /* Get the current configuration of the Device Control Register */
1924 ctrl = E1000_READ_REG(hw, CTRL);
1926 /* Because we didn't get link via the internal auto-negotiation
1927 * mechanism (we either forced link or we got link via PHY
1928 * auto-neg), we have to manually enable/disable transmit an
1929 * receive flow control.
1931 * The "Case" statement below enables/disable flow control
1932 * according to the "hw->fc" parameter.
1934 * The possible values of the "fc" parameter are:
1935 * 0: Flow control is completely disabled
1936 * 1: Rx flow control is enabled (we can receive pause
1937 * frames but not send pause frames).
1938 * 2: Tx flow control is enabled (we can send pause frames
1939 * frames but we do not receive pause frames).
1940 * 3: Both Rx and TX flow control (symmetric) is enabled.
1941 * other: No other values should be possible at this point.
1946 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1948 case e1000_fc_rx_pause:
1949 ctrl &= (~E1000_CTRL_TFCE);
1950 ctrl |= E1000_CTRL_RFCE;
1952 case e1000_fc_tx_pause:
1953 ctrl &= (~E1000_CTRL_RFCE);
1954 ctrl |= E1000_CTRL_TFCE;
1957 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1960 DEBUGOUT("Flow control param set incorrectly\n");
1961 return -E1000_ERR_CONFIG;
1964 /* Disable TX Flow Control for 82542 (rev 2.0) */
1965 if(hw->mac_type == e1000_82542_rev2_0)
1966 ctrl &= (~E1000_CTRL_TFCE);
1968 E1000_WRITE_REG(hw, CTRL, ctrl);
1969 return E1000_SUCCESS;
1972 /******************************************************************************
1973 * Configures flow control settings after link is established
1975 * hw - Struct containing variables accessed by shared code
1977 * Should be called immediately after a valid link has been established.
1978 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1979 * and autonegotiation is enabled, the MAC flow control settings will be set
1980 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1981 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1982 *****************************************************************************/
1984 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1987 uint16_t mii_status_reg;
1988 uint16_t mii_nway_adv_reg;
1989 uint16_t mii_nway_lp_ability_reg;
1993 DEBUGFUNC("e1000_config_fc_after_link_up");
1995 /* Check for the case where we have fiber media and auto-neg failed
1996 * so we had to force link. In this case, we need to force the
1997 * configuration of the MAC to match the "fc" parameter.
1999 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2000 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2001 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2002 ret_val = e1000_force_mac_fc(hw);
2004 DEBUGOUT("Error forcing flow control settings\n");
2009 /* Check for the case where we have copper media and auto-neg is
2010 * enabled. In this case, we need to check and see if Auto-Neg
2011 * has completed, and if so, how the PHY and link partner has
2012 * flow control configured.
2014 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2015 /* Read the MII Status Register and check to see if AutoNeg
2016 * has completed. We read this twice because this reg has
2017 * some "sticky" (latched) bits.
2019 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2026 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2027 /* The AutoNeg process has completed, so we now need to
2028 * read both the Auto Negotiation Advertisement Register
2029 * (Address 4) and the Auto_Negotiation Base Page Ability
2030 * Register (Address 5) to determine how flow control was
2033 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2037 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2038 &mii_nway_lp_ability_reg);
2042 /* Two bits in the Auto Negotiation Advertisement Register
2043 * (Address 4) and two bits in the Auto Negotiation Base
2044 * Page Ability Register (Address 5) determine flow control
2045 * for both the PHY and the link partner. The following
2046 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2047 * 1999, describes these PAUSE resolution bits and how flow
2048 * control is determined based upon these settings.
2049 * NOTE: DC = Don't Care
2051 * LOCAL DEVICE | LINK PARTNER
2052 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2053 *-------|---------|-------|---------|--------------------
2054 * 0 | 0 | DC | DC | e1000_fc_none
2055 * 0 | 1 | 0 | DC | e1000_fc_none
2056 * 0 | 1 | 1 | 0 | e1000_fc_none
2057 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2058 * 1 | 0 | 0 | DC | e1000_fc_none
2059 * 1 | DC | 1 | DC | e1000_fc_full
2060 * 1 | 1 | 0 | 0 | e1000_fc_none
2061 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2064 /* Are both PAUSE bits set to 1? If so, this implies
2065 * Symmetric Flow Control is enabled at both ends. The
2066 * ASM_DIR bits are irrelevant per the spec.
2068 * For Symmetric Flow Control:
2070 * LOCAL DEVICE | LINK PARTNER
2071 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2072 *-------|---------|-------|---------|--------------------
2073 * 1 | DC | 1 | DC | e1000_fc_full
2076 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2077 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2078 /* Now we need to check if the user selected RX ONLY
2079 * of pause frames. In this case, we had to advertise
2080 * FULL flow control because we could not advertise RX
2081 * ONLY. Hence, we must now check to see if we need to
2082 * turn OFF the TRANSMISSION of PAUSE frames.
2084 if(hw->original_fc == e1000_fc_full) {
2085 hw->fc = e1000_fc_full;
2086 DEBUGOUT("Flow Control = FULL.\r\n");
2088 hw->fc = e1000_fc_rx_pause;
2089 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2092 /* For receiving PAUSE frames ONLY.
2094 * LOCAL DEVICE | LINK PARTNER
2095 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2096 *-------|---------|-------|---------|--------------------
2097 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2100 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2101 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2102 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2103 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2104 hw->fc = e1000_fc_tx_pause;
2105 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2107 /* For transmitting PAUSE frames ONLY.
2109 * LOCAL DEVICE | LINK PARTNER
2110 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2111 *-------|---------|-------|---------|--------------------
2112 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2115 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2116 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2117 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2118 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2119 hw->fc = e1000_fc_rx_pause;
2120 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2122 /* Per the IEEE spec, at this point flow control should be
2123 * disabled. However, we want to consider that we could
2124 * be connected to a legacy switch that doesn't advertise
2125 * desired flow control, but can be forced on the link
2126 * partner. So if we advertised no flow control, that is
2127 * what we will resolve to. If we advertised some kind of
2128 * receive capability (Rx Pause Only or Full Flow Control)
2129 * and the link partner advertised none, we will configure
2130 * ourselves to enable Rx Flow Control only. We can do
2131 * this safely for two reasons: If the link partner really
2132 * didn't want flow control enabled, and we enable Rx, no
2133 * harm done since we won't be receiving any PAUSE frames
2134 * anyway. If the intent on the link partner was to have
2135 * flow control enabled, then by us enabling RX only, we
2136 * can at least receive pause frames and process them.
2137 * This is a good idea because in most cases, since we are
2138 * predominantly a server NIC, more times than not we will
2139 * be asked to delay transmission of packets than asking
2140 * our link partner to pause transmission of frames.
2142 else if((hw->original_fc == e1000_fc_none ||
2143 hw->original_fc == e1000_fc_tx_pause) ||
2144 hw->fc_strict_ieee) {
2145 hw->fc = e1000_fc_none;
2146 DEBUGOUT("Flow Control = NONE.\r\n");
2148 hw->fc = e1000_fc_rx_pause;
2149 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2152 /* Now we need to do one last check... If we auto-
2153 * negotiated to HALF DUPLEX, flow control should not be
2154 * enabled per IEEE 802.3 spec.
2156 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2158 DEBUGOUT("Error getting link speed and duplex\n");
2162 if(duplex == HALF_DUPLEX)
2163 hw->fc = e1000_fc_none;
2165 /* Now we call a subroutine to actually force the MAC
2166 * controller to use the correct flow control settings.
2168 ret_val = e1000_force_mac_fc(hw);
2170 DEBUGOUT("Error forcing flow control settings\n");
2174 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2177 return E1000_SUCCESS;
2180 /******************************************************************************
2181 * Checks to see if the link status of the hardware has changed.
2183 * hw - Struct containing variables accessed by shared code
2185 * Called by any function that needs to check the link status of the adapter.
2186 *****************************************************************************/
2188 e1000_check_for_link(struct e1000_hw *hw)
2195 uint32_t signal = 0;
2199 DEBUGFUNC("e1000_check_for_link");
2201 ctrl = E1000_READ_REG(hw, CTRL);
2202 status = E1000_READ_REG(hw, STATUS);
2204 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2205 * set when the optics detect a signal. On older adapters, it will be
2206 * cleared when there is a signal. This applies to fiber media only.
2208 if((hw->media_type == e1000_media_type_fiber) ||
2209 (hw->media_type == e1000_media_type_internal_serdes)) {
2210 rxcw = E1000_READ_REG(hw, RXCW);
2212 if(hw->media_type == e1000_media_type_fiber) {
2213 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2214 if(status & E1000_STATUS_LU)
2215 hw->get_link_status = FALSE;
2219 /* If we have a copper PHY then we only want to go out to the PHY
2220 * registers to see if Auto-Neg has completed and/or if our link
2221 * status has changed. The get_link_status flag will be set if we
2222 * receive a Link Status Change interrupt or we have Rx Sequence
2225 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2226 /* First we want to see if the MII Status Register reports
2227 * link. If so, then we want to get the current speed/duplex
2229 * Read the register twice since the link bit is sticky.
2231 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2234 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2238 if(phy_data & MII_SR_LINK_STATUS) {
2239 hw->get_link_status = FALSE;
2240 /* Check if there was DownShift, must be checked immediately after
2242 e1000_check_downshift(hw);
2244 /* If we are on 82544 or 82543 silicon and speed/duplex
2245 * are forced to 10H or 10F, then we will implement the polarity
2246 * reversal workaround. We disable interrupts first, and upon
2247 * returning, place the devices interrupt state to its previous
2248 * value except for the link status change interrupt which will
2249 * happen due to the execution of this workaround.
2252 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2254 (hw->forced_speed_duplex == e1000_10_full ||
2255 hw->forced_speed_duplex == e1000_10_half)) {
2256 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2257 ret_val = e1000_polarity_reversal_workaround(hw);
2258 icr = E1000_READ_REG(hw, ICR);
2259 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2260 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2264 /* No link detected */
2265 e1000_config_dsp_after_link_change(hw, FALSE);
2269 /* If we are forcing speed/duplex, then we simply return since
2270 * we have already determined whether we have link or not.
2272 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2274 /* optimize the dsp settings for the igp phy */
2275 e1000_config_dsp_after_link_change(hw, TRUE);
2277 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2278 * have Si on board that is 82544 or newer, Auto
2279 * Speed Detection takes care of MAC speed/duplex
2280 * configuration. So we only need to configure Collision
2281 * Distance in the MAC. Otherwise, we need to force
2282 * speed/duplex on the MAC to the current PHY speed/duplex
2285 if(hw->mac_type >= e1000_82544)
2286 e1000_config_collision_dist(hw);
2288 ret_val = e1000_config_mac_to_phy(hw);
2290 DEBUGOUT("Error configuring MAC to PHY settings\n");
2295 /* Configure Flow Control now that Auto-Neg has completed. First, we
2296 * need to restore the desired flow control settings because we may
2297 * have had to re-autoneg with a different link partner.
2299 ret_val = e1000_config_fc_after_link_up(hw);
2301 DEBUGOUT("Error configuring flow control\n");
2305 /* At this point we know that we are on copper and we have
2306 * auto-negotiated link. These are conditions for checking the link
2307 * partner capability register. We use the link speed to determine if
2308 * TBI compatibility needs to be turned on or off. If the link is not
2309 * at gigabit speed, then TBI compatibility is not needed. If we are
2310 * at gigabit speed, we turn on TBI compatibility.
2312 if(hw->tbi_compatibility_en) {
2313 uint16_t speed, duplex;
2314 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2315 if(speed != SPEED_1000) {
2316 /* If link speed is not set to gigabit speed, we do not need
2317 * to enable TBI compatibility.
2319 if(hw->tbi_compatibility_on) {
2320 /* If we previously were in the mode, turn it off. */
2321 rctl = E1000_READ_REG(hw, RCTL);
2322 rctl &= ~E1000_RCTL_SBP;
2323 E1000_WRITE_REG(hw, RCTL, rctl);
2324 hw->tbi_compatibility_on = FALSE;
2327 /* If TBI compatibility is was previously off, turn it on. For
2328 * compatibility with a TBI link partner, we will store bad
2329 * packets. Some frames have an additional byte on the end and
2330 * will look like CRC errors to to the hardware.
2332 if(!hw->tbi_compatibility_on) {
2333 hw->tbi_compatibility_on = TRUE;
2334 rctl = E1000_READ_REG(hw, RCTL);
2335 rctl |= E1000_RCTL_SBP;
2336 E1000_WRITE_REG(hw, RCTL, rctl);
2341 /* If we don't have link (auto-negotiation failed or link partner cannot
2342 * auto-negotiate), the cable is plugged in (we have signal), and our
2343 * link partner is not trying to auto-negotiate with us (we are receiving
2344 * idles or data), we need to force link up. We also need to give
2345 * auto-negotiation time to complete, in case the cable was just plugged
2346 * in. The autoneg_failed flag does this.
2348 else if((((hw->media_type == e1000_media_type_fiber) &&
2349 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2350 (hw->media_type == e1000_media_type_internal_serdes)) &&
2351 (!(status & E1000_STATUS_LU)) &&
2352 (!(rxcw & E1000_RXCW_C))) {
2353 if(hw->autoneg_failed == 0) {
2354 hw->autoneg_failed = 1;
2357 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2359 /* Disable auto-negotiation in the TXCW register */
2360 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2362 /* Force link-up and also force full-duplex. */
2363 ctrl = E1000_READ_REG(hw, CTRL);
2364 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2365 E1000_WRITE_REG(hw, CTRL, ctrl);
2367 /* Configure Flow Control after forcing link up. */
2368 ret_val = e1000_config_fc_after_link_up(hw);
2370 DEBUGOUT("Error configuring flow control\n");
2374 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2375 * auto-negotiation in the TXCW register and disable forced link in the
2376 * Device Control register in an attempt to auto-negotiate with our link
2379 else if(((hw->media_type == e1000_media_type_fiber) ||
2380 (hw->media_type == e1000_media_type_internal_serdes)) &&
2381 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2382 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2383 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2384 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2386 hw->serdes_link_down = FALSE;
2388 /* If we force link for non-auto-negotiation switch, check link status
2389 * based on MAC synchronization for internal serdes media type.
2391 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2392 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2393 /* SYNCH bit and IV bit are sticky. */
2395 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2396 if(!(rxcw & E1000_RXCW_IV)) {
2397 hw->serdes_link_down = FALSE;
2398 DEBUGOUT("SERDES: Link is up.\n");
2401 hw->serdes_link_down = TRUE;
2402 DEBUGOUT("SERDES: Link is down.\n");
2405 if((hw->media_type == e1000_media_type_internal_serdes) &&
2406 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2407 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2409 return E1000_SUCCESS;
2412 /******************************************************************************
2413 * Detects the current speed and duplex settings of the hardware.
2415 * hw - Struct containing variables accessed by shared code
2416 * speed - Speed of the connection
2417 * duplex - Duplex setting of the connection
2418 *****************************************************************************/
2420 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2428 DEBUGFUNC("e1000_get_speed_and_duplex");
2430 if(hw->mac_type >= e1000_82543) {
2431 status = E1000_READ_REG(hw, STATUS);
2432 if(status & E1000_STATUS_SPEED_1000) {
2433 *speed = SPEED_1000;
2434 DEBUGOUT("1000 Mbs, ");
2435 } else if(status & E1000_STATUS_SPEED_100) {
2437 DEBUGOUT("100 Mbs, ");
2440 DEBUGOUT("10 Mbs, ");
2443 if(status & E1000_STATUS_FD) {
2444 *duplex = FULL_DUPLEX;
2445 DEBUGOUT("Full Duplex\r\n");
2447 *duplex = HALF_DUPLEX;
2448 DEBUGOUT(" Half Duplex\r\n");
2451 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2452 *speed = SPEED_1000;
2453 *duplex = FULL_DUPLEX;
2456 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2457 * if it is operating at half duplex. Here we set the duplex settings to
2458 * match the duplex in the link partner's capabilities.
2460 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2461 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2465 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2466 *duplex = HALF_DUPLEX;
2468 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2471 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2472 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2473 *duplex = HALF_DUPLEX;
2477 return E1000_SUCCESS;
2480 /******************************************************************************
2481 * Blocks until autoneg completes or times out (~4.5 seconds)
2483 * hw - Struct containing variables accessed by shared code
2484 ******************************************************************************/
2486 e1000_wait_autoneg(struct e1000_hw *hw)
2492 DEBUGFUNC("e1000_wait_autoneg");
2493 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2495 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2496 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2497 /* Read the MII Status Register and wait for Auto-Neg
2498 * Complete bit to be set.
2500 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2503 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2506 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2507 return E1000_SUCCESS;
2511 return E1000_SUCCESS;
2514 /******************************************************************************
2515 * Raises the Management Data Clock
2517 * hw - Struct containing variables accessed by shared code
2518 * ctrl - Device control register's current value
2519 ******************************************************************************/
2521 e1000_raise_mdi_clk(struct e1000_hw *hw,
2524 /* Raise the clock input to the Management Data Clock (by setting the MDC
2525 * bit), and then delay 10 microseconds.
2527 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2528 E1000_WRITE_FLUSH(hw);
2532 /******************************************************************************
2533 * Lowers the Management Data Clock
2535 * hw - Struct containing variables accessed by shared code
2536 * ctrl - Device control register's current value
2537 ******************************************************************************/
2539 e1000_lower_mdi_clk(struct e1000_hw *hw,
2542 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2543 * bit), and then delay 10 microseconds.
2545 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2546 E1000_WRITE_FLUSH(hw);
2550 /******************************************************************************
2551 * Shifts data bits out to the PHY
2553 * hw - Struct containing variables accessed by shared code
2554 * data - Data to send out to the PHY
2555 * count - Number of bits to shift out
2557 * Bits are shifted out in MSB to LSB order.
2558 ******************************************************************************/
2560 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2567 /* We need to shift "count" number of bits out to the PHY. So, the value
2568 * in the "data" parameter will be shifted out to the PHY one bit at a
2569 * time. In order to do this, "data" must be broken down into bits.
2572 mask <<= (count - 1);
2574 ctrl = E1000_READ_REG(hw, CTRL);
2576 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2577 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2580 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2581 * then raising and lowering the Management Data Clock. A "0" is
2582 * shifted out to the PHY by setting the MDIO bit to "0" and then
2583 * raising and lowering the clock.
2585 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2586 else ctrl &= ~E1000_CTRL_MDIO;
2588 E1000_WRITE_REG(hw, CTRL, ctrl);
2589 E1000_WRITE_FLUSH(hw);
2593 e1000_raise_mdi_clk(hw, &ctrl);
2594 e1000_lower_mdi_clk(hw, &ctrl);
2600 /******************************************************************************
2601 * Shifts data bits in from the PHY
2603 * hw - Struct containing variables accessed by shared code
2605 * Bits are shifted in in MSB to LSB order.
2606 ******************************************************************************/
2608 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2614 /* In order to read a register from the PHY, we need to shift in a total
2615 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2616 * to avoid contention on the MDIO pin when a read operation is performed.
2617 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2618 * by raising the input to the Management Data Clock (setting the MDC bit),
2619 * and then reading the value of the MDIO bit.
2621 ctrl = E1000_READ_REG(hw, CTRL);
2623 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2624 ctrl &= ~E1000_CTRL_MDIO_DIR;
2625 ctrl &= ~E1000_CTRL_MDIO;
2627 E1000_WRITE_REG(hw, CTRL, ctrl);
2628 E1000_WRITE_FLUSH(hw);
2630 /* Raise and Lower the clock before reading in the data. This accounts for
2631 * the turnaround bits. The first clock occurred when we clocked out the
2632 * last bit of the Register Address.
2634 e1000_raise_mdi_clk(hw, &ctrl);
2635 e1000_lower_mdi_clk(hw, &ctrl);
2637 for(data = 0, i = 0; i < 16; i++) {
2639 e1000_raise_mdi_clk(hw, &ctrl);
2640 ctrl = E1000_READ_REG(hw, CTRL);
2641 /* Check to see if we shifted in a "1". */
2642 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2643 e1000_lower_mdi_clk(hw, &ctrl);
2646 e1000_raise_mdi_clk(hw, &ctrl);
2647 e1000_lower_mdi_clk(hw, &ctrl);
2652 /*****************************************************************************
2653 * Reads the value from a PHY register, if the value is on a specific non zero
2654 * page, sets the page first.
2655 * hw - Struct containing variables accessed by shared code
2656 * reg_addr - address of the PHY register to read
2657 ******************************************************************************/
2659 e1000_read_phy_reg(struct e1000_hw *hw,
2665 DEBUGFUNC("e1000_read_phy_reg");
2667 if((hw->phy_type == e1000_phy_igp ||
2668 hw->phy_type == e1000_phy_igp_2) &&
2669 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2670 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2671 (uint16_t)reg_addr);
2677 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2684 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2690 const uint32_t phy_addr = 1;
2692 DEBUGFUNC("e1000_read_phy_reg_ex");
2694 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2695 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2696 return -E1000_ERR_PARAM;
2699 if(hw->mac_type > e1000_82543) {
2700 /* Set up Op-code, Phy Address, and register address in the MDI
2701 * Control register. The MAC will take care of interfacing with the
2702 * PHY to retrieve the desired data.
2704 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2705 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2706 (E1000_MDIC_OP_READ));
2708 E1000_WRITE_REG(hw, MDIC, mdic);
2710 /* Poll the ready bit to see if the MDI read completed */
2711 for(i = 0; i < 64; i++) {
2713 mdic = E1000_READ_REG(hw, MDIC);
2714 if(mdic & E1000_MDIC_READY) break;
2716 if(!(mdic & E1000_MDIC_READY)) {
2717 DEBUGOUT("MDI Read did not complete\n");
2718 return -E1000_ERR_PHY;
2720 if(mdic & E1000_MDIC_ERROR) {
2721 DEBUGOUT("MDI Error\n");
2722 return -E1000_ERR_PHY;
2724 *phy_data = (uint16_t) mdic;
2726 /* We must first send a preamble through the MDIO pin to signal the
2727 * beginning of an MII instruction. This is done by sending 32
2728 * consecutive "1" bits.
2730 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2732 /* Now combine the next few fields that are required for a read
2733 * operation. We use this method instead of calling the
2734 * e1000_shift_out_mdi_bits routine five different times. The format of
2735 * a MII read instruction consists of a shift out of 14 bits and is
2736 * defined as follows:
2737 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2738 * followed by a shift in of 18 bits. This first two bits shifted in
2739 * are TurnAround bits used to avoid contention on the MDIO pin when a
2740 * READ operation is performed. These two bits are thrown away
2741 * followed by a shift in of 16 bits which contains the desired data.
2743 mdic = ((reg_addr) | (phy_addr << 5) |
2744 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2746 e1000_shift_out_mdi_bits(hw, mdic, 14);
2748 /* Now that we've shifted out the read command to the MII, we need to
2749 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2752 *phy_data = e1000_shift_in_mdi_bits(hw);
2754 return E1000_SUCCESS;
2757 /******************************************************************************
2758 * Writes a value to a PHY register
2760 * hw - Struct containing variables accessed by shared code
2761 * reg_addr - address of the PHY register to write
2762 * data - data to write to the PHY
2763 ******************************************************************************/
2765 e1000_write_phy_reg(struct e1000_hw *hw,
2771 DEBUGFUNC("e1000_write_phy_reg");
2773 if((hw->phy_type == e1000_phy_igp ||
2774 hw->phy_type == e1000_phy_igp_2) &&
2775 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2776 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2777 (uint16_t)reg_addr);
2783 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2790 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2796 const uint32_t phy_addr = 1;
2798 DEBUGFUNC("e1000_write_phy_reg_ex");
2800 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2801 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2802 return -E1000_ERR_PARAM;
2805 if(hw->mac_type > e1000_82543) {
2806 /* Set up Op-code, Phy Address, register address, and data intended
2807 * for the PHY register in the MDI Control register. The MAC will take
2808 * care of interfacing with the PHY to send the desired data.
2810 mdic = (((uint32_t) phy_data) |
2811 (reg_addr << E1000_MDIC_REG_SHIFT) |
2812 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2813 (E1000_MDIC_OP_WRITE));
2815 E1000_WRITE_REG(hw, MDIC, mdic);
2817 /* Poll the ready bit to see if the MDI read completed */
2818 for(i = 0; i < 640; i++) {
2820 mdic = E1000_READ_REG(hw, MDIC);
2821 if(mdic & E1000_MDIC_READY) break;
2823 if(!(mdic & E1000_MDIC_READY)) {
2824 DEBUGOUT("MDI Write did not complete\n");
2825 return -E1000_ERR_PHY;
2828 /* We'll need to use the SW defined pins to shift the write command
2829 * out to the PHY. We first send a preamble to the PHY to signal the
2830 * beginning of the MII instruction. This is done by sending 32
2831 * consecutive "1" bits.
2833 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2835 /* Now combine the remaining required fields that will indicate a
2836 * write operation. We use this method instead of calling the
2837 * e1000_shift_out_mdi_bits routine for each field in the command. The
2838 * format of a MII write instruction is as follows:
2839 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2841 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2842 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2844 mdic |= (uint32_t) phy_data;
2846 e1000_shift_out_mdi_bits(hw, mdic, 32);
2849 return E1000_SUCCESS;
2853 /******************************************************************************
2854 * Returns the PHY to the power-on reset state
2856 * hw - Struct containing variables accessed by shared code
2857 ******************************************************************************/
2859 e1000_phy_hw_reset(struct e1000_hw *hw)
2861 uint32_t ctrl, ctrl_ext;
2865 DEBUGFUNC("e1000_phy_hw_reset");
2867 /* In the case of the phy reset being blocked, it's not an error, we
2868 * simply return success without performing the reset. */
2869 ret_val = e1000_check_phy_reset_block(hw);
2871 return E1000_SUCCESS;
2873 DEBUGOUT("Resetting Phy...\n");
2875 if(hw->mac_type > e1000_82543) {
2876 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2877 * bit. Then, take it out of reset.
2879 ctrl = E1000_READ_REG(hw, CTRL);
2880 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2881 E1000_WRITE_FLUSH(hw);
2883 E1000_WRITE_REG(hw, CTRL, ctrl);
2884 E1000_WRITE_FLUSH(hw);
2886 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2887 * bit to put the PHY into reset. Then, take it out of reset.
2889 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2890 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2891 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2892 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2893 E1000_WRITE_FLUSH(hw);
2895 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2896 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2897 E1000_WRITE_FLUSH(hw);
2901 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2902 /* Configure activity LED after PHY reset */
2903 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2904 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2905 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2906 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2909 /* Wait for FW to finish PHY configuration. */
2910 ret_val = e1000_get_phy_cfg_done(hw);
2915 /******************************************************************************
2918 * hw - Struct containing variables accessed by shared code
2920 * Sets bit 15 of the MII Control regiser
2921 ******************************************************************************/
2923 e1000_phy_reset(struct e1000_hw *hw)
2928 DEBUGFUNC("e1000_phy_reset");
2930 /* In the case of the phy reset being blocked, it's not an error, we
2931 * simply return success without performing the reset. */
2932 ret_val = e1000_check_phy_reset_block(hw);
2934 return E1000_SUCCESS;
2936 switch (hw->mac_type) {
2937 case e1000_82541_rev_2:
2938 ret_val = e1000_phy_hw_reset(hw);
2943 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2947 phy_data |= MII_CR_RESET;
2948 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2956 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
2957 e1000_phy_init_script(hw);
2959 return E1000_SUCCESS;
2962 /******************************************************************************
2963 * Probes the expected PHY address for known PHY IDs
2965 * hw - Struct containing variables accessed by shared code
2966 ******************************************************************************/
2968 e1000_detect_gig_phy(struct e1000_hw *hw)
2970 int32_t phy_init_status, ret_val;
2971 uint16_t phy_id_high, phy_id_low;
2972 boolean_t match = FALSE;
2974 DEBUGFUNC("e1000_detect_gig_phy");
2976 /* Read the PHY ID Registers to identify which PHY is onboard. */
2977 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2981 hw->phy_id = (uint32_t) (phy_id_high << 16);
2983 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2987 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2988 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2990 switch(hw->mac_type) {
2992 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2995 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2999 case e1000_82545_rev_3:
3001 case e1000_82546_rev_3:
3002 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3005 case e1000_82541_rev_2:
3007 case e1000_82547_rev_2:
3008 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3011 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3014 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3015 return -E1000_ERR_CONFIG;
3017 phy_init_status = e1000_set_phy_type(hw);
3019 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3020 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3021 return E1000_SUCCESS;
3023 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3024 return -E1000_ERR_PHY;
3027 /******************************************************************************
3028 * Resets the PHY's DSP
3030 * hw - Struct containing variables accessed by shared code
3031 ******************************************************************************/
3033 e1000_phy_reset_dsp(struct e1000_hw *hw)
3036 DEBUGFUNC("e1000_phy_reset_dsp");
3039 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3041 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3043 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3045 ret_val = E1000_SUCCESS;
3051 /******************************************************************************
3052 * Get PHY information from various PHY registers for igp PHY only.
3054 * hw - Struct containing variables accessed by shared code
3055 * phy_info - PHY information structure
3056 ******************************************************************************/
3058 e1000_phy_igp_get_info(struct e1000_hw *hw,
3059 struct e1000_phy_info *phy_info)
3062 uint16_t phy_data, polarity, min_length, max_length, average;
3064 DEBUGFUNC("e1000_phy_igp_get_info");
3066 /* The downshift status is checked only once, after link is established,
3067 * and it stored in the hw->speed_downgraded parameter. */
3068 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3070 /* IGP01E1000 does not need to support it. */
3071 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3073 /* IGP01E1000 always correct polarity reversal */
3074 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3076 /* Check polarity status */
3077 ret_val = e1000_check_polarity(hw, &polarity);
3081 phy_info->cable_polarity = polarity;
3083 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3087 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3088 IGP01E1000_PSSR_MDIX_SHIFT;
3090 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3091 IGP01E1000_PSSR_SPEED_1000MBPS) {
3092 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3093 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3097 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3098 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3099 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3100 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3102 /* Get cable length */
3103 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3107 /* Translate to old method */
3108 average = (max_length + min_length) / 2;
3110 if(average <= e1000_igp_cable_length_50)
3111 phy_info->cable_length = e1000_cable_length_50;
3112 else if(average <= e1000_igp_cable_length_80)
3113 phy_info->cable_length = e1000_cable_length_50_80;
3114 else if(average <= e1000_igp_cable_length_110)
3115 phy_info->cable_length = e1000_cable_length_80_110;
3116 else if(average <= e1000_igp_cable_length_140)
3117 phy_info->cable_length = e1000_cable_length_110_140;
3119 phy_info->cable_length = e1000_cable_length_140;
3122 return E1000_SUCCESS;
3125 /******************************************************************************
3126 * Get PHY information from various PHY registers fot m88 PHY only.
3128 * hw - Struct containing variables accessed by shared code
3129 * phy_info - PHY information structure
3130 ******************************************************************************/
3132 e1000_phy_m88_get_info(struct e1000_hw *hw,
3133 struct e1000_phy_info *phy_info)
3136 uint16_t phy_data, polarity;
3138 DEBUGFUNC("e1000_phy_m88_get_info");
3140 /* The downshift status is checked only once, after link is established,
3141 * and it stored in the hw->speed_downgraded parameter. */
3142 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3144 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3148 phy_info->extended_10bt_distance =
3149 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3150 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3151 phy_info->polarity_correction =
3152 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3153 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3155 /* Check polarity status */
3156 ret_val = e1000_check_polarity(hw, &polarity);
3159 phy_info->cable_polarity = polarity;
3161 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3165 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3166 M88E1000_PSSR_MDIX_SHIFT;
3168 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3169 /* Cable Length Estimation and Local/Remote Receiver Information
3170 * are only valid at 1000 Mbps.
3172 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3173 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3175 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3179 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3180 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3182 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3183 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3186 return E1000_SUCCESS;
3189 /******************************************************************************
3190 * Get PHY information from various PHY registers
3192 * hw - Struct containing variables accessed by shared code
3193 * phy_info - PHY information structure
3194 ******************************************************************************/
3196 e1000_phy_get_info(struct e1000_hw *hw,
3197 struct e1000_phy_info *phy_info)
3202 DEBUGFUNC("e1000_phy_get_info");
3204 phy_info->cable_length = e1000_cable_length_undefined;
3205 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3206 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3207 phy_info->downshift = e1000_downshift_undefined;
3208 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3209 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3210 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3211 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3213 if(hw->media_type != e1000_media_type_copper) {
3214 DEBUGOUT("PHY info is only valid for copper media\n");
3215 return -E1000_ERR_CONFIG;
3218 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3222 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3226 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3227 DEBUGOUT("PHY info is only valid if link is up\n");
3228 return -E1000_ERR_CONFIG;
3231 if(hw->phy_type == e1000_phy_igp ||
3232 hw->phy_type == e1000_phy_igp_2)
3233 return e1000_phy_igp_get_info(hw, phy_info);
3235 return e1000_phy_m88_get_info(hw, phy_info);
3239 e1000_validate_mdi_setting(struct e1000_hw *hw)
3241 DEBUGFUNC("e1000_validate_mdi_settings");
3243 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3244 DEBUGOUT("Invalid MDI setting detected\n");
3246 return -E1000_ERR_CONFIG;
3248 return E1000_SUCCESS;
3252 /******************************************************************************
3253 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3256 * hw - Struct containing variables accessed by shared code
3257 *****************************************************************************/
3259 e1000_init_eeprom_params(struct e1000_hw *hw)
3261 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3262 uint32_t eecd = E1000_READ_REG(hw, EECD);
3263 int32_t ret_val = E1000_SUCCESS;
3264 uint16_t eeprom_size;
3266 DEBUGFUNC("e1000_init_eeprom_params");
3268 switch (hw->mac_type) {
3269 case e1000_82542_rev2_0:
3270 case e1000_82542_rev2_1:
3273 eeprom->type = e1000_eeprom_microwire;
3274 eeprom->word_size = 64;
3275 eeprom->opcode_bits = 3;
3276 eeprom->address_bits = 6;
3277 eeprom->delay_usec = 50;
3278 eeprom->use_eerd = FALSE;
3279 eeprom->use_eewr = FALSE;
3283 case e1000_82545_rev_3:
3285 case e1000_82546_rev_3:
3286 eeprom->type = e1000_eeprom_microwire;
3287 eeprom->opcode_bits = 3;
3288 eeprom->delay_usec = 50;
3289 if(eecd & E1000_EECD_SIZE) {
3290 eeprom->word_size = 256;
3291 eeprom->address_bits = 8;
3293 eeprom->word_size = 64;
3294 eeprom->address_bits = 6;
3296 eeprom->use_eerd = FALSE;
3297 eeprom->use_eewr = FALSE;
3300 case e1000_82541_rev_2:
3302 case e1000_82547_rev_2:
3303 if (eecd & E1000_EECD_TYPE) {
3304 eeprom->type = e1000_eeprom_spi;
3305 eeprom->opcode_bits = 8;
3306 eeprom->delay_usec = 1;
3307 if (eecd & E1000_EECD_ADDR_BITS) {
3308 eeprom->page_size = 32;
3309 eeprom->address_bits = 16;
3311 eeprom->page_size = 8;
3312 eeprom->address_bits = 8;
3315 eeprom->type = e1000_eeprom_microwire;
3316 eeprom->opcode_bits = 3;
3317 eeprom->delay_usec = 50;
3318 if (eecd & E1000_EECD_ADDR_BITS) {
3319 eeprom->word_size = 256;
3320 eeprom->address_bits = 8;
3322 eeprom->word_size = 64;
3323 eeprom->address_bits = 6;
3326 eeprom->use_eerd = FALSE;
3327 eeprom->use_eewr = FALSE;
3330 eeprom->type = e1000_eeprom_spi;
3331 eeprom->opcode_bits = 8;
3332 eeprom->delay_usec = 1;
3333 if (eecd & E1000_EECD_ADDR_BITS) {
3334 eeprom->page_size = 32;
3335 eeprom->address_bits = 16;
3337 eeprom->page_size = 8;
3338 eeprom->address_bits = 8;
3340 eeprom->use_eerd = TRUE;
3341 eeprom->use_eewr = TRUE;
3342 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
3343 eeprom->type = e1000_eeprom_flash;
3344 eeprom->word_size = 2048;
3346 /* Ensure that the Autonomous FLASH update bit is cleared due to
3347 * Flash update issue on parts which use a FLASH for NVM. */
3348 eecd &= ~E1000_EECD_AUPDEN;
3349 E1000_WRITE_REG(hw, EECD, eecd);
3356 if (eeprom->type == e1000_eeprom_spi) {
3357 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3358 * 32KB (incremented by powers of 2).
3360 if(hw->mac_type <= e1000_82547_rev_2) {
3361 /* Set to default value for initial eeprom read. */
3362 eeprom->word_size = 64;
3363 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3366 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3367 /* 256B eeprom size was not supported in earlier hardware, so we
3368 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3369 * is never the result used in the shifting logic below. */
3373 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3374 E1000_EECD_SIZE_EX_SHIFT);
3377 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3382 /******************************************************************************
3383 * Raises the EEPROM's clock input.
3385 * hw - Struct containing variables accessed by shared code
3386 * eecd - EECD's current value
3387 *****************************************************************************/
3389 e1000_raise_ee_clk(struct e1000_hw *hw,