1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 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");
147 if(hw->phy_init_script) {
150 /* Save off the current value of register 0x2F5B to be restored at
151 * the end of this routine. */
152 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
154 /* Disabled the PHY transmitter */
155 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
159 e1000_write_phy_reg(hw,0x0000,0x0140);
163 switch(hw->mac_type) {
166 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
168 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
170 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
172 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
174 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
176 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
178 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
180 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
182 e1000_write_phy_reg(hw, 0x2010, 0x0008);
185 case e1000_82541_rev_2:
186 case e1000_82547_rev_2:
187 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
193 e1000_write_phy_reg(hw, 0x0000, 0x3300);
197 /* Now enable the transmitter */
198 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
200 if(hw->mac_type == e1000_82547) {
201 uint16_t fused, fine, coarse;
203 /* Move to analog registers page */
204 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
206 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
207 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
209 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
210 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
212 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
213 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
214 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
215 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
216 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
218 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
219 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
220 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
222 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
223 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
224 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
230 /******************************************************************************
231 * Set the mac type member in the hw struct.
233 * hw - Struct containing variables accessed by shared code
234 *****************************************************************************/
236 e1000_set_mac_type(struct e1000_hw *hw)
238 DEBUGFUNC("e1000_set_mac_type");
240 switch (hw->device_id) {
241 case E1000_DEV_ID_82542:
242 switch (hw->revision_id) {
243 case E1000_82542_2_0_REV_ID:
244 hw->mac_type = e1000_82542_rev2_0;
246 case E1000_82542_2_1_REV_ID:
247 hw->mac_type = e1000_82542_rev2_1;
250 /* Invalid 82542 revision ID */
251 return -E1000_ERR_MAC_TYPE;
254 case E1000_DEV_ID_82543GC_FIBER:
255 case E1000_DEV_ID_82543GC_COPPER:
256 hw->mac_type = e1000_82543;
258 case E1000_DEV_ID_82544EI_COPPER:
259 case E1000_DEV_ID_82544EI_FIBER:
260 case E1000_DEV_ID_82544GC_COPPER:
261 case E1000_DEV_ID_82544GC_LOM:
262 hw->mac_type = e1000_82544;
264 case E1000_DEV_ID_82540EM:
265 case E1000_DEV_ID_82540EM_LOM:
266 case E1000_DEV_ID_82540EP:
267 case E1000_DEV_ID_82540EP_LOM:
268 case E1000_DEV_ID_82540EP_LP:
269 hw->mac_type = e1000_82540;
271 case E1000_DEV_ID_82545EM_COPPER:
272 case E1000_DEV_ID_82545EM_FIBER:
273 hw->mac_type = e1000_82545;
275 case E1000_DEV_ID_82545GM_COPPER:
276 case E1000_DEV_ID_82545GM_FIBER:
277 case E1000_DEV_ID_82545GM_SERDES:
278 hw->mac_type = e1000_82545_rev_3;
280 case E1000_DEV_ID_82546EB_COPPER:
281 case E1000_DEV_ID_82546EB_FIBER:
282 case E1000_DEV_ID_82546EB_QUAD_COPPER:
283 hw->mac_type = e1000_82546;
285 case E1000_DEV_ID_82546GB_COPPER:
286 case E1000_DEV_ID_82546GB_FIBER:
287 case E1000_DEV_ID_82546GB_SERDES:
288 case E1000_DEV_ID_82546GB_PCIE:
289 case E1000_DEV_ID_82546GB_QUAD_COPPER:
290 hw->mac_type = e1000_82546_rev_3;
292 case E1000_DEV_ID_82541EI:
293 case E1000_DEV_ID_82541EI_MOBILE:
294 hw->mac_type = e1000_82541;
296 case E1000_DEV_ID_82541ER:
297 case E1000_DEV_ID_82541GI:
298 case E1000_DEV_ID_82541GI_LF:
299 case E1000_DEV_ID_82541GI_MOBILE:
300 hw->mac_type = e1000_82541_rev_2;
302 case E1000_DEV_ID_82547EI:
303 hw->mac_type = e1000_82547;
305 case E1000_DEV_ID_82547GI:
306 hw->mac_type = e1000_82547_rev_2;
308 case E1000_DEV_ID_82573E:
309 case E1000_DEV_ID_82573E_IAMT:
310 hw->mac_type = e1000_82573;
313 /* Should never have loaded on this device */
314 return -E1000_ERR_MAC_TYPE;
317 switch(hw->mac_type) {
319 hw->eeprom_semaphore_present = TRUE;
323 case e1000_82541_rev_2:
324 case e1000_82547_rev_2:
325 hw->asf_firmware_present = TRUE;
331 return E1000_SUCCESS;
334 /*****************************************************************************
335 * Set media type and TBI compatibility.
337 * hw - Struct containing variables accessed by shared code
338 * **************************************************************************/
340 e1000_set_media_type(struct e1000_hw *hw)
344 DEBUGFUNC("e1000_set_media_type");
346 if(hw->mac_type != e1000_82543) {
347 /* tbi_compatibility is only valid on 82543 */
348 hw->tbi_compatibility_en = FALSE;
351 switch (hw->device_id) {
352 case E1000_DEV_ID_82545GM_SERDES:
353 case E1000_DEV_ID_82546GB_SERDES:
354 hw->media_type = e1000_media_type_internal_serdes;
357 if(hw->mac_type >= e1000_82543) {
358 status = E1000_READ_REG(hw, STATUS);
359 if(status & E1000_STATUS_TBIMODE) {
360 hw->media_type = e1000_media_type_fiber;
361 /* tbi_compatibility not valid on fiber */
362 hw->tbi_compatibility_en = FALSE;
364 hw->media_type = e1000_media_type_copper;
367 /* This is an 82542 (fiber only) */
368 hw->media_type = e1000_media_type_fiber;
373 /******************************************************************************
374 * Reset the transmit and receive units; mask and clear all interrupts.
376 * hw - Struct containing variables accessed by shared code
377 *****************************************************************************/
379 e1000_reset_hw(struct e1000_hw *hw)
387 uint32_t extcnf_ctrl;
390 DEBUGFUNC("e1000_reset_hw");
392 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
393 if(hw->mac_type == e1000_82542_rev2_0) {
394 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
395 e1000_pci_clear_mwi(hw);
398 if(hw->bus_type == e1000_bus_type_pci_express) {
399 /* Prevent the PCI-E bus from sticking if there is no TLP connection
400 * on the last TLP read/write transaction when MAC is reset.
402 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
403 DEBUGOUT("PCI-E Master disable polling has failed.\n");
407 /* Clear interrupt mask to stop board from generating interrupts */
408 DEBUGOUT("Masking off all interrupts\n");
409 E1000_WRITE_REG(hw, IMC, 0xffffffff);
411 /* Disable the Transmit and Receive units. Then delay to allow
412 * any pending transactions to complete before we hit the MAC with
415 E1000_WRITE_REG(hw, RCTL, 0);
416 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
417 E1000_WRITE_FLUSH(hw);
419 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
420 hw->tbi_compatibility_on = FALSE;
422 /* Delay to allow any outstanding PCI transactions to complete before
423 * resetting the device
427 ctrl = E1000_READ_REG(hw, CTRL);
429 /* Must reset the PHY before resetting the MAC */
430 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
431 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
435 /* Must acquire the MDIO ownership before MAC reset.
436 * Ownership defaults to firmware after a reset. */
437 if(hw->mac_type == e1000_82573) {
440 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
441 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
444 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
445 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
447 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
450 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
457 /* Issue a global reset to the MAC. This will reset the chip's
458 * transmit, receive, DMA, and link units. It will not effect
459 * the current PCI configuration. The global reset bit is self-
460 * clearing, and should clear within a microsecond.
462 DEBUGOUT("Issuing a global reset to MAC\n");
464 switch(hw->mac_type) {
470 case e1000_82541_rev_2:
471 /* These controllers can't ack the 64-bit write when issuing the
472 * reset, so use IO-mapping as a workaround to issue the reset */
473 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
475 case e1000_82545_rev_3:
476 case e1000_82546_rev_3:
477 /* Reset is performed on a shadow of the control register */
478 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
481 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
485 /* After MAC reset, force reload of EEPROM to restore power-on settings to
486 * device. Later controllers reload the EEPROM automatically, so just wait
487 * for reload to complete.
489 switch(hw->mac_type) {
490 case e1000_82542_rev2_0:
491 case e1000_82542_rev2_1:
494 /* Wait for reset to complete */
496 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
497 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
498 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
499 E1000_WRITE_FLUSH(hw);
500 /* Wait for EEPROM reload */
504 case e1000_82541_rev_2:
506 case e1000_82547_rev_2:
507 /* Wait for EEPROM reload */
512 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
513 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
514 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
515 E1000_WRITE_FLUSH(hw);
517 ret_val = e1000_get_auto_rd_done(hw);
519 /* We don't want to continue accessing MAC registers. */
523 /* Wait for EEPROM reload (it happens automatically) */
528 /* Disable HW ARPs on ASF enabled adapters */
529 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
530 manc = E1000_READ_REG(hw, MANC);
531 manc &= ~(E1000_MANC_ARP_EN);
532 E1000_WRITE_REG(hw, MANC, manc);
535 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
536 e1000_phy_init_script(hw);
538 /* Configure activity LED after PHY reset */
539 led_ctrl = E1000_READ_REG(hw, LEDCTL);
540 led_ctrl &= IGP_ACTIVITY_LED_MASK;
541 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
542 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
545 /* Clear interrupt mask to stop board from generating interrupts */
546 DEBUGOUT("Masking off all interrupts\n");
547 E1000_WRITE_REG(hw, IMC, 0xffffffff);
549 /* Clear any pending interrupt events. */
550 icr = E1000_READ_REG(hw, ICR);
552 /* If MWI was previously enabled, reenable it. */
553 if(hw->mac_type == e1000_82542_rev2_0) {
554 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
555 e1000_pci_set_mwi(hw);
558 return E1000_SUCCESS;
561 /******************************************************************************
562 * Performs basic configuration of the adapter.
564 * hw - Struct containing variables accessed by shared code
566 * Assumes that the controller has previously been reset and is in a
567 * post-reset uninitialized state. Initializes the receive address registers,
568 * multicast table, and VLAN filter table. Calls routines to setup link
569 * configuration and flow control settings. Clears all on-chip counters. Leaves
570 * the transmit and receive units disabled and uninitialized.
571 *****************************************************************************/
573 e1000_init_hw(struct e1000_hw *hw)
578 uint16_t pcix_cmd_word;
579 uint16_t pcix_stat_hi_word;
584 DEBUGFUNC("e1000_init_hw");
586 /* Initialize Identification LED */
587 ret_val = e1000_id_led_init(hw);
589 DEBUGOUT("Error Initializing Identification LED\n");
593 /* Set the media type and TBI compatibility */
594 e1000_set_media_type(hw);
596 /* Disabling VLAN filtering. */
597 DEBUGOUT("Initializing the IEEE VLAN\n");
598 if (hw->mac_type < e1000_82545_rev_3)
599 E1000_WRITE_REG(hw, VET, 0);
600 e1000_clear_vfta(hw);
602 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
603 if(hw->mac_type == e1000_82542_rev2_0) {
604 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
605 e1000_pci_clear_mwi(hw);
606 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
607 E1000_WRITE_FLUSH(hw);
611 /* Setup the receive address. This involves initializing all of the Receive
612 * Address Registers (RARs 0 - 15).
614 e1000_init_rx_addrs(hw);
616 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
617 if(hw->mac_type == e1000_82542_rev2_0) {
618 E1000_WRITE_REG(hw, RCTL, 0);
619 E1000_WRITE_FLUSH(hw);
621 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
622 e1000_pci_set_mwi(hw);
625 /* Zero out the Multicast HASH table */
626 DEBUGOUT("Zeroing the MTA\n");
627 mta_size = E1000_MC_TBL_SIZE;
628 for(i = 0; i < mta_size; i++)
629 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
631 /* Set the PCI priority bit correctly in the CTRL register. This
632 * determines if the adapter gives priority to receives, or if it
633 * gives equal priority to transmits and receives. Valid only on
634 * 82542 and 82543 silicon.
636 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
637 ctrl = E1000_READ_REG(hw, CTRL);
638 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
641 switch(hw->mac_type) {
642 case e1000_82545_rev_3:
643 case e1000_82546_rev_3:
646 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
647 if(hw->bus_type == e1000_bus_type_pcix) {
648 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
649 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
651 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
652 PCIX_COMMAND_MMRBC_SHIFT;
653 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
654 PCIX_STATUS_HI_MMRBC_SHIFT;
655 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
656 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
657 if(cmd_mmrbc > stat_mmrbc) {
658 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
659 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
660 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
667 /* Call a subroutine to configure the link and setup flow control. */
668 ret_val = e1000_setup_link(hw);
670 /* Set the transmit descriptor write-back policy */
671 if(hw->mac_type > e1000_82544) {
672 ctrl = E1000_READ_REG(hw, TXDCTL);
673 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
674 switch (hw->mac_type) {
678 ctrl |= E1000_TXDCTL_COUNT_DESC;
681 E1000_WRITE_REG(hw, TXDCTL, ctrl);
684 if (hw->mac_type == e1000_82573) {
685 e1000_enable_tx_pkt_filtering(hw);
689 /* Clear all of the statistics registers (clear on read). It is
690 * important that we do this after we have tried to establish link
691 * because the symbol error count will increment wildly if there
694 e1000_clear_hw_cntrs(hw);
699 /******************************************************************************
700 * Adjust SERDES output amplitude based on EEPROM setting.
702 * hw - Struct containing variables accessed by shared code.
703 *****************************************************************************/
705 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
707 uint16_t eeprom_data;
710 DEBUGFUNC("e1000_adjust_serdes_amplitude");
712 if(hw->media_type != e1000_media_type_internal_serdes)
713 return E1000_SUCCESS;
715 switch(hw->mac_type) {
716 case e1000_82545_rev_3:
717 case e1000_82546_rev_3:
720 return E1000_SUCCESS;
723 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
728 if(eeprom_data != EEPROM_RESERVED_WORD) {
729 /* Adjust SERDES output amplitude only. */
730 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
731 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
736 return E1000_SUCCESS;
739 /******************************************************************************
740 * Configures flow control and link settings.
742 * hw - Struct containing variables accessed by shared code
744 * Determines which flow control settings to use. Calls the apropriate media-
745 * specific link configuration function. Configures the flow control settings.
746 * Assuming the adapter has a valid link partner, a valid link should be
747 * established. Assumes the hardware has previously been reset and the
748 * transmitter and receiver are not enabled.
749 *****************************************************************************/
751 e1000_setup_link(struct e1000_hw *hw)
755 uint16_t eeprom_data;
757 DEBUGFUNC("e1000_setup_link");
759 /* Read and store word 0x0F of the EEPROM. This word contains bits
760 * that determine the hardware's default PAUSE (flow control) mode,
761 * a bit that determines whether the HW defaults to enabling or
762 * disabling auto-negotiation, and the direction of the
763 * SW defined pins. If there is no SW over-ride of the flow
764 * control setting, then the variable hw->fc will
765 * be initialized based on a value in the EEPROM.
767 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
768 DEBUGOUT("EEPROM Read Error\n");
769 return -E1000_ERR_EEPROM;
772 if(hw->fc == e1000_fc_default) {
773 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
774 hw->fc = e1000_fc_none;
775 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
776 EEPROM_WORD0F_ASM_DIR)
777 hw->fc = e1000_fc_tx_pause;
779 hw->fc = e1000_fc_full;
782 /* We want to save off the original Flow Control configuration just
783 * in case we get disconnected and then reconnected into a different
784 * hub or switch with different Flow Control capabilities.
786 if(hw->mac_type == e1000_82542_rev2_0)
787 hw->fc &= (~e1000_fc_tx_pause);
789 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
790 hw->fc &= (~e1000_fc_rx_pause);
792 hw->original_fc = hw->fc;
794 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
796 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
797 * polarity value for the SW controlled pins, and setup the
798 * Extended Device Control reg with that info.
799 * This is needed because one of the SW controlled pins is used for
800 * signal detection. So this should be done before e1000_setup_pcs_link()
801 * or e1000_phy_setup() is called.
803 if(hw->mac_type == e1000_82543) {
804 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
806 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
809 /* Call the necessary subroutine to configure the link. */
810 ret_val = (hw->media_type == e1000_media_type_copper) ?
811 e1000_setup_copper_link(hw) :
812 e1000_setup_fiber_serdes_link(hw);
814 /* Initialize the flow control address, type, and PAUSE timer
815 * registers to their default values. This is done even if flow
816 * control is disabled, because it does not hurt anything to
817 * initialize these registers.
819 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
821 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
822 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
823 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
825 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
827 /* Set the flow control receive threshold registers. Normally,
828 * these registers will be set to a default threshold that may be
829 * adjusted later by the driver's runtime code. However, if the
830 * ability to transmit pause frames in not enabled, then these
831 * registers will be set to 0.
833 if(!(hw->fc & e1000_fc_tx_pause)) {
834 E1000_WRITE_REG(hw, FCRTL, 0);
835 E1000_WRITE_REG(hw, FCRTH, 0);
837 /* We need to set up the Receive Threshold high and low water marks
838 * as well as (optionally) enabling the transmission of XON frames.
840 if(hw->fc_send_xon) {
841 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
842 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
844 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
845 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
851 /******************************************************************************
852 * Sets up link for a fiber based or serdes based adapter
854 * hw - Struct containing variables accessed by shared code
856 * Manipulates Physical Coding Sublayer functions in order to configure
857 * link. Assumes the hardware has been previously reset and the transmitter
858 * and receiver are not enabled.
859 *****************************************************************************/
861 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
870 DEBUGFUNC("e1000_setup_fiber_serdes_link");
872 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
873 * set when the optics detect a signal. On older adapters, it will be
874 * cleared when there is a signal. This applies to fiber media only.
875 * If we're on serdes media, adjust the output amplitude to value set in
878 ctrl = E1000_READ_REG(hw, CTRL);
879 if(hw->media_type == e1000_media_type_fiber)
880 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
882 ret_val = e1000_adjust_serdes_amplitude(hw);
886 /* Take the link out of reset */
887 ctrl &= ~(E1000_CTRL_LRST);
889 /* Adjust VCO speed to improve BER performance */
890 ret_val = e1000_set_vco_speed(hw);
894 e1000_config_collision_dist(hw);
896 /* Check for a software override of the flow control settings, and setup
897 * the device accordingly. If auto-negotiation is enabled, then software
898 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
899 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
900 * auto-negotiation is disabled, then software will have to manually
901 * configure the two flow control enable bits in the CTRL register.
903 * The possible values of the "fc" parameter are:
904 * 0: Flow control is completely disabled
905 * 1: Rx flow control is enabled (we can receive pause frames, but
906 * not send pause frames).
907 * 2: Tx flow control is enabled (we can send pause frames but we do
908 * not support receiving pause frames).
909 * 3: Both Rx and TX flow control (symmetric) are enabled.
913 /* Flow control is completely disabled by a software over-ride. */
914 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
916 case e1000_fc_rx_pause:
917 /* RX Flow control is enabled and TX Flow control is disabled by a
918 * software over-ride. Since there really isn't a way to advertise
919 * that we are capable of RX Pause ONLY, we will advertise that we
920 * support both symmetric and asymmetric RX PAUSE. Later, we will
921 * disable the adapter's ability to send PAUSE frames.
923 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
925 case e1000_fc_tx_pause:
926 /* TX Flow control is enabled, and RX Flow control is disabled, by a
927 * software over-ride.
929 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
932 /* Flow control (both RX and TX) is enabled by a software over-ride. */
933 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
936 DEBUGOUT("Flow control param set incorrectly\n");
937 return -E1000_ERR_CONFIG;
941 /* Since auto-negotiation is enabled, take the link out of reset (the link
942 * will be in reset, because we previously reset the chip). This will
943 * restart auto-negotiation. If auto-neogtiation is successful then the
944 * link-up status bit will be set and the flow control enable bits (RFCE
945 * and TFCE) will be set according to their negotiated value.
947 DEBUGOUT("Auto-negotiation enabled\n");
949 E1000_WRITE_REG(hw, TXCW, txcw);
950 E1000_WRITE_REG(hw, CTRL, ctrl);
951 E1000_WRITE_FLUSH(hw);
956 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
957 * indication in the Device Status Register. Time-out if a link isn't
958 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
959 * less than 500 milliseconds even if the other end is doing it in SW).
960 * For internal serdes, we just assume a signal is present, then poll.
962 if(hw->media_type == e1000_media_type_internal_serdes ||
963 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
964 DEBUGOUT("Looking for Link\n");
965 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
967 status = E1000_READ_REG(hw, STATUS);
968 if(status & E1000_STATUS_LU) break;
970 if(i == (LINK_UP_TIMEOUT / 10)) {
971 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
972 hw->autoneg_failed = 1;
973 /* AutoNeg failed to achieve a link, so we'll call
974 * e1000_check_for_link. This routine will force the link up if
975 * we detect a signal. This will allow us to communicate with
976 * non-autonegotiating link partners.
978 ret_val = e1000_check_for_link(hw);
980 DEBUGOUT("Error while checking for link\n");
983 hw->autoneg_failed = 0;
985 hw->autoneg_failed = 0;
986 DEBUGOUT("Valid Link Found\n");
989 DEBUGOUT("No Signal Detected\n");
991 return E1000_SUCCESS;
994 /******************************************************************************
995 * Make sure we have a valid PHY and change PHY mode before link setup.
997 * hw - Struct containing variables accessed by shared code
998 ******************************************************************************/
1000 e1000_copper_link_preconfig(struct e1000_hw *hw)
1006 DEBUGFUNC("e1000_copper_link_preconfig");
1008 ctrl = E1000_READ_REG(hw, CTRL);
1009 /* With 82543, we need to force speed and duplex on the MAC equal to what
1010 * the PHY speed and duplex configuration is. In addition, we need to
1011 * perform a hardware reset on the PHY to take it out of reset.
1013 if(hw->mac_type > e1000_82543) {
1014 ctrl |= E1000_CTRL_SLU;
1015 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1016 E1000_WRITE_REG(hw, CTRL, ctrl);
1018 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1019 E1000_WRITE_REG(hw, CTRL, ctrl);
1020 ret_val = e1000_phy_hw_reset(hw);
1025 /* Make sure we have a valid PHY */
1026 ret_val = e1000_detect_gig_phy(hw);
1028 DEBUGOUT("Error, did not detect valid phy.\n");
1031 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1033 /* Set PHY to class A mode (if necessary) */
1034 ret_val = e1000_set_phy_mode(hw);
1038 if((hw->mac_type == e1000_82545_rev_3) ||
1039 (hw->mac_type == e1000_82546_rev_3)) {
1040 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1041 phy_data |= 0x00000008;
1042 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1045 if(hw->mac_type <= e1000_82543 ||
1046 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1047 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1048 hw->phy_reset_disable = FALSE;
1050 return E1000_SUCCESS;
1054 /********************************************************************
1055 * Copper link setup for e1000_phy_igp series.
1057 * hw - Struct containing variables accessed by shared code
1058 *********************************************************************/
1060 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1066 DEBUGFUNC("e1000_copper_link_igp_setup");
1068 if (hw->phy_reset_disable)
1069 return E1000_SUCCESS;
1071 ret_val = e1000_phy_reset(hw);
1073 DEBUGOUT("Error Resetting the PHY\n");
1077 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1080 /* Configure activity LED after PHY reset */
1081 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1082 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1083 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1084 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1086 /* disable lplu d3 during driver init */
1087 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1089 DEBUGOUT("Error Disabling LPLU D3\n");
1093 /* disable lplu d0 during driver init */
1094 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1096 DEBUGOUT("Error Disabling LPLU D0\n");
1099 /* Configure mdi-mdix settings */
1100 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1104 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1105 hw->dsp_config_state = e1000_dsp_config_disabled;
1106 /* Force MDI for earlier revs of the IGP PHY */
1107 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1111 hw->dsp_config_state = e1000_dsp_config_enabled;
1112 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1116 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1119 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1123 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1127 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1131 /* set auto-master slave resolution settings */
1133 e1000_ms_type phy_ms_setting = hw->master_slave;
1135 if(hw->ffe_config_state == e1000_ffe_config_active)
1136 hw->ffe_config_state = e1000_ffe_config_enabled;
1138 if(hw->dsp_config_state == e1000_dsp_config_activated)
1139 hw->dsp_config_state = e1000_dsp_config_enabled;
1141 /* when autonegotiation advertisment is only 1000Mbps then we
1142 * should disable SmartSpeed and enable Auto MasterSlave
1143 * resolution as hardware default. */
1144 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1145 /* Disable SmartSpeed */
1146 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1149 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1150 ret_val = e1000_write_phy_reg(hw,
1151 IGP01E1000_PHY_PORT_CONFIG,
1155 /* Set auto Master/Slave resolution process */
1156 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1159 phy_data &= ~CR_1000T_MS_ENABLE;
1160 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1165 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1169 /* load defaults for future use */
1170 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1171 ((phy_data & CR_1000T_MS_VALUE) ?
1172 e1000_ms_force_master :
1173 e1000_ms_force_slave) :
1176 switch (phy_ms_setting) {
1177 case e1000_ms_force_master:
1178 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1180 case e1000_ms_force_slave:
1181 phy_data |= CR_1000T_MS_ENABLE;
1182 phy_data &= ~(CR_1000T_MS_VALUE);
1185 phy_data &= ~CR_1000T_MS_ENABLE;
1189 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1194 return E1000_SUCCESS;
1198 /********************************************************************
1199 * Copper link setup for e1000_phy_m88 series.
1201 * hw - Struct containing variables accessed by shared code
1202 *********************************************************************/
1204 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1209 DEBUGFUNC("e1000_copper_link_mgp_setup");
1211 if(hw->phy_reset_disable)
1212 return E1000_SUCCESS;
1214 /* Enable CRS on TX. This must be set for half-duplex operation. */
1215 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1219 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1222 * MDI/MDI-X = 0 (default)
1223 * 0 - Auto for all speeds
1226 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1228 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1232 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1235 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1238 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1242 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1247 * disable_polarity_correction = 0 (default)
1248 * Automatic Correction for Reversed Cable Polarity
1252 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1253 if(hw->disable_polarity_correction == 1)
1254 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1255 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1259 /* Force TX_CLK in the Extended PHY Specific Control Register
1262 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1266 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1268 if (hw->phy_revision < M88E1011_I_REV_4) {
1269 /* Configure Master and Slave downshift values */
1270 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1271 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1272 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1273 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1274 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1279 /* SW Reset the PHY so all changes take effect */
1280 ret_val = e1000_phy_reset(hw);
1282 DEBUGOUT("Error Resetting the PHY\n");
1286 return E1000_SUCCESS;
1289 /********************************************************************
1290 * Setup auto-negotiation and flow control advertisements,
1291 * and then perform auto-negotiation.
1293 * hw - Struct containing variables accessed by shared code
1294 *********************************************************************/
1296 e1000_copper_link_autoneg(struct e1000_hw *hw)
1301 DEBUGFUNC("e1000_copper_link_autoneg");
1303 /* Perform some bounds checking on the hw->autoneg_advertised
1304 * parameter. If this variable is zero, then set it to the default.
1306 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1308 /* If autoneg_advertised is zero, we assume it was not defaulted
1309 * by the calling code so we set to advertise full capability.
1311 if(hw->autoneg_advertised == 0)
1312 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1314 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1315 ret_val = e1000_phy_setup_autoneg(hw);
1317 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1320 DEBUGOUT("Restarting Auto-Neg\n");
1322 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1323 * the Auto Neg Restart bit in the PHY control register.
1325 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1329 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1330 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1334 /* Does the user want to wait for Auto-Neg to complete here, or
1335 * check at a later time (for example, callback routine).
1337 if(hw->wait_autoneg_complete) {
1338 ret_val = e1000_wait_autoneg(hw);
1340 DEBUGOUT("Error while waiting for autoneg to complete\n");
1345 hw->get_link_status = TRUE;
1347 return E1000_SUCCESS;
1351 /******************************************************************************
1352 * Config the MAC and the PHY after link is up.
1353 * 1) Set up the MAC to the current PHY speed/duplex
1354 * if we are on 82543. If we
1355 * are on newer silicon, we only need to configure
1356 * collision distance in the Transmit Control Register.
1357 * 2) Set up flow control on the MAC to that established with
1359 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1361 * hw - Struct containing variables accessed by shared code
1362 ******************************************************************************/
1364 e1000_copper_link_postconfig(struct e1000_hw *hw)
1367 DEBUGFUNC("e1000_copper_link_postconfig");
1369 if(hw->mac_type >= e1000_82544) {
1370 e1000_config_collision_dist(hw);
1372 ret_val = e1000_config_mac_to_phy(hw);
1374 DEBUGOUT("Error configuring MAC to PHY settings\n");
1378 ret_val = e1000_config_fc_after_link_up(hw);
1380 DEBUGOUT("Error Configuring Flow Control\n");
1384 /* Config DSP to improve Giga link quality */
1385 if(hw->phy_type == e1000_phy_igp) {
1386 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1388 DEBUGOUT("Error Configuring DSP after link up\n");
1393 return E1000_SUCCESS;
1396 /******************************************************************************
1397 * Detects which PHY is present and setup the speed and duplex
1399 * hw - Struct containing variables accessed by shared code
1400 ******************************************************************************/
1402 e1000_setup_copper_link(struct e1000_hw *hw)
1408 DEBUGFUNC("e1000_setup_copper_link");
1410 /* Check if it is a valid PHY and set PHY mode if necessary. */
1411 ret_val = e1000_copper_link_preconfig(hw);
1415 if (hw->phy_type == e1000_phy_igp ||
1416 hw->phy_type == e1000_phy_igp_2) {
1417 ret_val = e1000_copper_link_igp_setup(hw);
1420 } else if (hw->phy_type == e1000_phy_m88) {
1421 ret_val = e1000_copper_link_mgp_setup(hw);
1427 /* Setup autoneg and flow control advertisement
1428 * and perform autonegotiation */
1429 ret_val = e1000_copper_link_autoneg(hw);
1433 /* PHY will be set to 10H, 10F, 100H,or 100F
1434 * depending on value from forced_speed_duplex. */
1435 DEBUGOUT("Forcing speed and duplex\n");
1436 ret_val = e1000_phy_force_speed_duplex(hw);
1438 DEBUGOUT("Error Forcing Speed and Duplex\n");
1443 /* Check link status. Wait up to 100 microseconds for link to become
1446 for(i = 0; i < 10; i++) {
1447 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1450 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1454 if(phy_data & MII_SR_LINK_STATUS) {
1455 /* Config the MAC and PHY after link is up */
1456 ret_val = e1000_copper_link_postconfig(hw);
1460 DEBUGOUT("Valid link established!!!\n");
1461 return E1000_SUCCESS;
1466 DEBUGOUT("Unable to establish link!!!\n");
1467 return E1000_SUCCESS;
1470 /******************************************************************************
1471 * Configures PHY autoneg and flow control advertisement settings
1473 * hw - Struct containing variables accessed by shared code
1474 ******************************************************************************/
1476 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1479 uint16_t mii_autoneg_adv_reg;
1480 uint16_t mii_1000t_ctrl_reg;
1482 DEBUGFUNC("e1000_phy_setup_autoneg");
1484 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1485 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1489 /* Read the MII 1000Base-T Control Register (Address 9). */
1490 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1494 /* Need to parse both autoneg_advertised and fc and set up
1495 * the appropriate PHY registers. First we will parse for
1496 * autoneg_advertised software override. Since we can advertise
1497 * a plethora of combinations, we need to check each bit
1501 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1502 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1503 * the 1000Base-T Control Register (Address 9).
1505 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1506 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1508 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1510 /* Do we want to advertise 10 Mb Half Duplex? */
1511 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1512 DEBUGOUT("Advertise 10mb Half duplex\n");
1513 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1516 /* Do we want to advertise 10 Mb Full Duplex? */
1517 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1518 DEBUGOUT("Advertise 10mb Full duplex\n");
1519 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1522 /* Do we want to advertise 100 Mb Half Duplex? */
1523 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1524 DEBUGOUT("Advertise 100mb Half duplex\n");
1525 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1528 /* Do we want to advertise 100 Mb Full Duplex? */
1529 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1530 DEBUGOUT("Advertise 100mb Full duplex\n");
1531 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1534 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1535 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1536 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1539 /* Do we want to advertise 1000 Mb Full Duplex? */
1540 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1541 DEBUGOUT("Advertise 1000mb Full duplex\n");
1542 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1545 /* Check for a software override of the flow control settings, and
1546 * setup the PHY advertisement registers accordingly. If
1547 * auto-negotiation is enabled, then software will have to set the
1548 * "PAUSE" bits to the correct value in the Auto-Negotiation
1549 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1551 * The possible values of the "fc" parameter are:
1552 * 0: Flow control is completely disabled
1553 * 1: Rx flow control is enabled (we can receive pause frames
1554 * but not send pause frames).
1555 * 2: Tx flow control is enabled (we can send pause frames
1556 * but we do not support receiving pause frames).
1557 * 3: Both Rx and TX flow control (symmetric) are enabled.
1558 * other: No software override. The flow control configuration
1559 * in the EEPROM is used.
1562 case e1000_fc_none: /* 0 */
1563 /* Flow control (RX & TX) is completely disabled by a
1564 * software over-ride.
1566 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1568 case e1000_fc_rx_pause: /* 1 */
1569 /* RX Flow control is enabled, and TX Flow control is
1570 * disabled, by a software over-ride.
1572 /* Since there really isn't a way to advertise that we are
1573 * capable of RX Pause ONLY, we will advertise that we
1574 * support both symmetric and asymmetric RX PAUSE. Later
1575 * (in e1000_config_fc_after_link_up) we will disable the
1576 *hw's ability to send PAUSE frames.
1578 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1580 case e1000_fc_tx_pause: /* 2 */
1581 /* TX Flow control is enabled, and RX Flow control is
1582 * disabled, by a software over-ride.
1584 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1585 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1587 case e1000_fc_full: /* 3 */
1588 /* Flow control (both RX and TX) is enabled by a software
1591 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1594 DEBUGOUT("Flow control param set incorrectly\n");
1595 return -E1000_ERR_CONFIG;
1598 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1602 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1604 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1608 return E1000_SUCCESS;
1611 /******************************************************************************
1612 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1614 * hw - Struct containing variables accessed by shared code
1615 ******************************************************************************/
1617 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1621 uint16_t mii_ctrl_reg;
1622 uint16_t mii_status_reg;
1626 DEBUGFUNC("e1000_phy_force_speed_duplex");
1628 /* Turn off Flow control if we are forcing speed and duplex. */
1629 hw->fc = e1000_fc_none;
1631 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1633 /* Read the Device Control Register. */
1634 ctrl = E1000_READ_REG(hw, CTRL);
1636 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1637 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1638 ctrl &= ~(DEVICE_SPEED_MASK);
1640 /* Clear the Auto Speed Detect Enable bit. */
1641 ctrl &= ~E1000_CTRL_ASDE;
1643 /* Read the MII Control Register. */
1644 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1648 /* We need to disable autoneg in order to force link and duplex. */
1650 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1652 /* Are we forcing Full or Half Duplex? */
1653 if(hw->forced_speed_duplex == e1000_100_full ||
1654 hw->forced_speed_duplex == e1000_10_full) {
1655 /* We want to force full duplex so we SET the full duplex bits in the
1656 * Device and MII Control Registers.
1658 ctrl |= E1000_CTRL_FD;
1659 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1660 DEBUGOUT("Full Duplex\n");
1662 /* We want to force half duplex so we CLEAR the full duplex bits in
1663 * the Device and MII Control Registers.
1665 ctrl &= ~E1000_CTRL_FD;
1666 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1667 DEBUGOUT("Half Duplex\n");
1670 /* Are we forcing 100Mbps??? */
1671 if(hw->forced_speed_duplex == e1000_100_full ||
1672 hw->forced_speed_duplex == e1000_100_half) {
1673 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1674 ctrl |= E1000_CTRL_SPD_100;
1675 mii_ctrl_reg |= MII_CR_SPEED_100;
1676 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1677 DEBUGOUT("Forcing 100mb ");
1679 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1680 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1681 mii_ctrl_reg |= MII_CR_SPEED_10;
1682 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1683 DEBUGOUT("Forcing 10mb ");
1686 e1000_config_collision_dist(hw);
1688 /* Write the configured values back to the Device Control Reg. */
1689 E1000_WRITE_REG(hw, CTRL, ctrl);
1691 if (hw->phy_type == e1000_phy_m88) {
1692 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1696 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1697 * forced whenever speed are duplex are forced.
1699 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1700 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1704 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1706 /* Need to reset the PHY or these changes will be ignored */
1707 mii_ctrl_reg |= MII_CR_RESET;
1709 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1710 * forced whenever speed or duplex are forced.
1712 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1716 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1717 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1719 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1724 /* Write back the modified PHY MII control register. */
1725 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1731 /* The wait_autoneg_complete flag may be a little misleading here.
1732 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1733 * But we do want to delay for a period while forcing only so we
1734 * don't generate false No Link messages. So we will wait here
1735 * only if the user has set wait_autoneg_complete to 1, which is
1738 if(hw->wait_autoneg_complete) {
1739 /* We will wait for autoneg to complete. */
1740 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1743 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1744 for(i = PHY_FORCE_TIME; i > 0; i--) {
1745 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1748 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1752 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1756 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1760 (hw->phy_type == e1000_phy_m88)) {
1761 /* We didn't get link. Reset the DSP and wait again for link. */
1762 ret_val = e1000_phy_reset_dsp(hw);
1764 DEBUGOUT("Error Resetting PHY DSP\n");
1768 /* This loop will early-out if the link condition has been met. */
1769 for(i = PHY_FORCE_TIME; i > 0; i--) {
1770 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1772 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1775 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1779 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1785 if (hw->phy_type == e1000_phy_m88) {
1786 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1787 * Extended PHY Specific Control Register to 25MHz clock. This value
1788 * defaults back to a 2.5MHz clock when the PHY is reset.
1790 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1794 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1795 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1799 /* In addition, because of the s/w reset above, we need to enable CRS on
1800 * TX. This must be set for both full and half duplex operation.
1802 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1806 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1807 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1811 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1813 (hw->forced_speed_duplex == e1000_10_full ||
1814 hw->forced_speed_duplex == e1000_10_half)) {
1815 ret_val = e1000_polarity_reversal_workaround(hw);
1820 return E1000_SUCCESS;
1823 /******************************************************************************
1824 * Sets the collision distance in the Transmit Control register
1826 * hw - Struct containing variables accessed by shared code
1828 * Link should have been established previously. Reads the speed and duplex
1829 * information from the Device Status register.
1830 ******************************************************************************/
1832 e1000_config_collision_dist(struct e1000_hw *hw)
1836 DEBUGFUNC("e1000_config_collision_dist");
1838 tctl = E1000_READ_REG(hw, TCTL);
1840 tctl &= ~E1000_TCTL_COLD;
1841 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1843 E1000_WRITE_REG(hw, TCTL, tctl);
1844 E1000_WRITE_FLUSH(hw);
1847 /******************************************************************************
1848 * Sets MAC speed and duplex settings to reflect the those in the PHY
1850 * hw - Struct containing variables accessed by shared code
1851 * mii_reg - data to write to the MII control register
1853 * The contents of the PHY register containing the needed information need to
1855 ******************************************************************************/
1857 e1000_config_mac_to_phy(struct e1000_hw *hw)
1863 DEBUGFUNC("e1000_config_mac_to_phy");
1865 /* 82544 or newer MAC, Auto Speed Detection takes care of
1866 * MAC speed/duplex configuration.*/
1867 if (hw->mac_type >= e1000_82544)
1868 return E1000_SUCCESS;
1870 /* Read the Device Control Register and set the bits to Force Speed
1873 ctrl = E1000_READ_REG(hw, CTRL);
1874 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1875 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1877 /* Set up duplex in the Device Control and Transmit Control
1878 * registers depending on negotiated values.
1880 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1884 if(phy_data & M88E1000_PSSR_DPLX)
1885 ctrl |= E1000_CTRL_FD;
1887 ctrl &= ~E1000_CTRL_FD;
1889 e1000_config_collision_dist(hw);
1891 /* Set up speed in the Device Control register depending on
1892 * negotiated values.
1894 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1895 ctrl |= E1000_CTRL_SPD_1000;
1896 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1897 ctrl |= E1000_CTRL_SPD_100;
1899 /* Write the configured values back to the Device Control Reg. */
1900 E1000_WRITE_REG(hw, CTRL, ctrl);
1901 return E1000_SUCCESS;
1904 /******************************************************************************
1905 * Forces the MAC's flow control settings.
1907 * hw - Struct containing variables accessed by shared code
1909 * Sets the TFCE and RFCE bits in the device control register to reflect
1910 * the adapter settings. TFCE and RFCE need to be explicitly set by
1911 * software when a Copper PHY is used because autonegotiation is managed
1912 * by the PHY rather than the MAC. Software must also configure these
1913 * bits when link is forced on a fiber connection.
1914 *****************************************************************************/
1916 e1000_force_mac_fc(struct e1000_hw *hw)
1920 DEBUGFUNC("e1000_force_mac_fc");
1922 /* Get the current configuration of the Device Control Register */
1923 ctrl = E1000_READ_REG(hw, CTRL);
1925 /* Because we didn't get link via the internal auto-negotiation
1926 * mechanism (we either forced link or we got link via PHY
1927 * auto-neg), we have to manually enable/disable transmit an
1928 * receive flow control.
1930 * The "Case" statement below enables/disable flow control
1931 * according to the "hw->fc" parameter.
1933 * The possible values of the "fc" parameter are:
1934 * 0: Flow control is completely disabled
1935 * 1: Rx flow control is enabled (we can receive pause
1936 * frames but not send pause frames).
1937 * 2: Tx flow control is enabled (we can send pause frames
1938 * frames but we do not receive pause frames).
1939 * 3: Both Rx and TX flow control (symmetric) is enabled.
1940 * other: No other values should be possible at this point.
1945 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1947 case e1000_fc_rx_pause:
1948 ctrl &= (~E1000_CTRL_TFCE);
1949 ctrl |= E1000_CTRL_RFCE;
1951 case e1000_fc_tx_pause:
1952 ctrl &= (~E1000_CTRL_RFCE);
1953 ctrl |= E1000_CTRL_TFCE;
1956 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1959 DEBUGOUT("Flow control param set incorrectly\n");
1960 return -E1000_ERR_CONFIG;
1963 /* Disable TX Flow Control for 82542 (rev 2.0) */
1964 if(hw->mac_type == e1000_82542_rev2_0)
1965 ctrl &= (~E1000_CTRL_TFCE);
1967 E1000_WRITE_REG(hw, CTRL, ctrl);
1968 return E1000_SUCCESS;
1971 /******************************************************************************
1972 * Configures flow control settings after link is established
1974 * hw - Struct containing variables accessed by shared code
1976 * Should be called immediately after a valid link has been established.
1977 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1978 * and autonegotiation is enabled, the MAC flow control settings will be set
1979 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1980 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1981 *****************************************************************************/
1983 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1986 uint16_t mii_status_reg;
1987 uint16_t mii_nway_adv_reg;
1988 uint16_t mii_nway_lp_ability_reg;
1992 DEBUGFUNC("e1000_config_fc_after_link_up");
1994 /* Check for the case where we have fiber media and auto-neg failed
1995 * so we had to force link. In this case, we need to force the
1996 * configuration of the MAC to match the "fc" parameter.
1998 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1999 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2000 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2001 ret_val = e1000_force_mac_fc(hw);
2003 DEBUGOUT("Error forcing flow control settings\n");
2008 /* Check for the case where we have copper media and auto-neg is
2009 * enabled. In this case, we need to check and see if Auto-Neg
2010 * has completed, and if so, how the PHY and link partner has
2011 * flow control configured.
2013 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2014 /* Read the MII Status Register and check to see if AutoNeg
2015 * has completed. We read this twice because this reg has
2016 * some "sticky" (latched) bits.
2018 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2021 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2025 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2026 /* The AutoNeg process has completed, so we now need to
2027 * read both the Auto Negotiation Advertisement Register
2028 * (Address 4) and the Auto_Negotiation Base Page Ability
2029 * Register (Address 5) to determine how flow control was
2032 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2036 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2037 &mii_nway_lp_ability_reg);
2041 /* Two bits in the Auto Negotiation Advertisement Register
2042 * (Address 4) and two bits in the Auto Negotiation Base
2043 * Page Ability Register (Address 5) determine flow control
2044 * for both the PHY and the link partner. The following
2045 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2046 * 1999, describes these PAUSE resolution bits and how flow
2047 * control is determined based upon these settings.
2048 * NOTE: DC = Don't Care
2050 * LOCAL DEVICE | LINK PARTNER
2051 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2052 *-------|---------|-------|---------|--------------------
2053 * 0 | 0 | DC | DC | e1000_fc_none
2054 * 0 | 1 | 0 | DC | e1000_fc_none
2055 * 0 | 1 | 1 | 0 | e1000_fc_none
2056 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2057 * 1 | 0 | 0 | DC | e1000_fc_none
2058 * 1 | DC | 1 | DC | e1000_fc_full
2059 * 1 | 1 | 0 | 0 | e1000_fc_none
2060 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2063 /* Are both PAUSE bits set to 1? If so, this implies
2064 * Symmetric Flow Control is enabled at both ends. The
2065 * ASM_DIR bits are irrelevant per the spec.
2067 * For Symmetric Flow Control:
2069 * LOCAL DEVICE | LINK PARTNER
2070 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2071 *-------|---------|-------|---------|--------------------
2072 * 1 | DC | 1 | DC | e1000_fc_full
2075 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2076 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2077 /* Now we need to check if the user selected RX ONLY
2078 * of pause frames. In this case, we had to advertise
2079 * FULL flow control because we could not advertise RX
2080 * ONLY. Hence, we must now check to see if we need to
2081 * turn OFF the TRANSMISSION of PAUSE frames.
2083 if(hw->original_fc == e1000_fc_full) {
2084 hw->fc = e1000_fc_full;
2085 DEBUGOUT("Flow Control = FULL.\r\n");
2087 hw->fc = e1000_fc_rx_pause;
2088 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2091 /* For receiving PAUSE frames ONLY.
2093 * LOCAL DEVICE | LINK PARTNER
2094 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2095 *-------|---------|-------|---------|--------------------
2096 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2099 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2100 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2101 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2102 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2103 hw->fc = e1000_fc_tx_pause;
2104 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2106 /* For transmitting PAUSE frames ONLY.
2108 * LOCAL DEVICE | LINK PARTNER
2109 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2110 *-------|---------|-------|---------|--------------------
2111 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2114 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2115 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2116 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2117 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2118 hw->fc = e1000_fc_rx_pause;
2119 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2121 /* Per the IEEE spec, at this point flow control should be
2122 * disabled. However, we want to consider that we could
2123 * be connected to a legacy switch that doesn't advertise
2124 * desired flow control, but can be forced on the link
2125 * partner. So if we advertised no flow control, that is
2126 * what we will resolve to. If we advertised some kind of
2127 * receive capability (Rx Pause Only or Full Flow Control)
2128 * and the link partner advertised none, we will configure
2129 * ourselves to enable Rx Flow Control only. We can do
2130 * this safely for two reasons: If the link partner really
2131 * didn't want flow control enabled, and we enable Rx, no
2132 * harm done since we won't be receiving any PAUSE frames
2133 * anyway. If the intent on the link partner was to have
2134 * flow control enabled, then by us enabling RX only, we
2135 * can at least receive pause frames and process them.
2136 * This is a good idea because in most cases, since we are
2137 * predominantly a server NIC, more times than not we will
2138 * be asked to delay transmission of packets than asking
2139 * our link partner to pause transmission of frames.
2141 else if((hw->original_fc == e1000_fc_none ||
2142 hw->original_fc == e1000_fc_tx_pause) ||
2143 hw->fc_strict_ieee) {
2144 hw->fc = e1000_fc_none;
2145 DEBUGOUT("Flow Control = NONE.\r\n");
2147 hw->fc = e1000_fc_rx_pause;
2148 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2151 /* Now we need to do one last check... If we auto-
2152 * negotiated to HALF DUPLEX, flow control should not be
2153 * enabled per IEEE 802.3 spec.
2155 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2157 DEBUGOUT("Error getting link speed and duplex\n");
2161 if(duplex == HALF_DUPLEX)
2162 hw->fc = e1000_fc_none;
2164 /* Now we call a subroutine to actually force the MAC
2165 * controller to use the correct flow control settings.
2167 ret_val = e1000_force_mac_fc(hw);
2169 DEBUGOUT("Error forcing flow control settings\n");
2173 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2176 return E1000_SUCCESS;
2179 /******************************************************************************
2180 * Checks to see if the link status of the hardware has changed.
2182 * hw - Struct containing variables accessed by shared code
2184 * Called by any function that needs to check the link status of the adapter.
2185 *****************************************************************************/
2187 e1000_check_for_link(struct e1000_hw *hw)
2194 uint32_t signal = 0;
2198 DEBUGFUNC("e1000_check_for_link");
2200 ctrl = E1000_READ_REG(hw, CTRL);
2201 status = E1000_READ_REG(hw, STATUS);
2203 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2204 * set when the optics detect a signal. On older adapters, it will be
2205 * cleared when there is a signal. This applies to fiber media only.
2207 if((hw->media_type == e1000_media_type_fiber) ||
2208 (hw->media_type == e1000_media_type_internal_serdes)) {
2209 rxcw = E1000_READ_REG(hw, RXCW);
2211 if(hw->media_type == e1000_media_type_fiber) {
2212 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2213 if(status & E1000_STATUS_LU)
2214 hw->get_link_status = FALSE;
2218 /* If we have a copper PHY then we only want to go out to the PHY
2219 * registers to see if Auto-Neg has completed and/or if our link
2220 * status has changed. The get_link_status flag will be set if we
2221 * receive a Link Status Change interrupt or we have Rx Sequence
2224 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2225 /* First we want to see if the MII Status Register reports
2226 * link. If so, then we want to get the current speed/duplex
2228 * Read the register twice since the link bit is sticky.
2230 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2233 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2237 if(phy_data & MII_SR_LINK_STATUS) {
2238 hw->get_link_status = FALSE;
2239 /* Check if there was DownShift, must be checked immediately after
2241 e1000_check_downshift(hw);
2243 /* If we are on 82544 or 82543 silicon and speed/duplex
2244 * are forced to 10H or 10F, then we will implement the polarity
2245 * reversal workaround. We disable interrupts first, and upon
2246 * returning, place the devices interrupt state to its previous
2247 * value except for the link status change interrupt which will
2248 * happen due to the execution of this workaround.
2251 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2253 (hw->forced_speed_duplex == e1000_10_full ||
2254 hw->forced_speed_duplex == e1000_10_half)) {
2255 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2256 ret_val = e1000_polarity_reversal_workaround(hw);
2257 icr = E1000_READ_REG(hw, ICR);
2258 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2259 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2263 /* No link detected */
2264 e1000_config_dsp_after_link_change(hw, FALSE);
2268 /* If we are forcing speed/duplex, then we simply return since
2269 * we have already determined whether we have link or not.
2271 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2273 /* optimize the dsp settings for the igp phy */
2274 e1000_config_dsp_after_link_change(hw, TRUE);
2276 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2277 * have Si on board that is 82544 or newer, Auto
2278 * Speed Detection takes care of MAC speed/duplex
2279 * configuration. So we only need to configure Collision
2280 * Distance in the MAC. Otherwise, we need to force
2281 * speed/duplex on the MAC to the current PHY speed/duplex
2284 if(hw->mac_type >= e1000_82544)
2285 e1000_config_collision_dist(hw);
2287 ret_val = e1000_config_mac_to_phy(hw);
2289 DEBUGOUT("Error configuring MAC to PHY settings\n");
2294 /* Configure Flow Control now that Auto-Neg has completed. First, we
2295 * need to restore the desired flow control settings because we may
2296 * have had to re-autoneg with a different link partner.
2298 ret_val = e1000_config_fc_after_link_up(hw);
2300 DEBUGOUT("Error configuring flow control\n");
2304 /* At this point we know that we are on copper and we have
2305 * auto-negotiated link. These are conditions for checking the link
2306 * partner capability register. We use the link speed to determine if
2307 * TBI compatibility needs to be turned on or off. If the link is not
2308 * at gigabit speed, then TBI compatibility is not needed. If we are
2309 * at gigabit speed, we turn on TBI compatibility.
2311 if(hw->tbi_compatibility_en) {
2312 uint16_t speed, duplex;
2313 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2314 if(speed != SPEED_1000) {
2315 /* If link speed is not set to gigabit speed, we do not need
2316 * to enable TBI compatibility.
2318 if(hw->tbi_compatibility_on) {
2319 /* If we previously were in the mode, turn it off. */
2320 rctl = E1000_READ_REG(hw, RCTL);
2321 rctl &= ~E1000_RCTL_SBP;
2322 E1000_WRITE_REG(hw, RCTL, rctl);
2323 hw->tbi_compatibility_on = FALSE;
2326 /* If TBI compatibility is was previously off, turn it on. For
2327 * compatibility with a TBI link partner, we will store bad
2328 * packets. Some frames have an additional byte on the end and
2329 * will look like CRC errors to to the hardware.
2331 if(!hw->tbi_compatibility_on) {
2332 hw->tbi_compatibility_on = TRUE;
2333 rctl = E1000_READ_REG(hw, RCTL);
2334 rctl |= E1000_RCTL_SBP;
2335 E1000_WRITE_REG(hw, RCTL, rctl);
2340 /* If we don't have link (auto-negotiation failed or link partner cannot
2341 * auto-negotiate), the cable is plugged in (we have signal), and our
2342 * link partner is not trying to auto-negotiate with us (we are receiving
2343 * idles or data), we need to force link up. We also need to give
2344 * auto-negotiation time to complete, in case the cable was just plugged
2345 * in. The autoneg_failed flag does this.
2347 else if((((hw->media_type == e1000_media_type_fiber) &&
2348 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2349 (hw->media_type == e1000_media_type_internal_serdes)) &&
2350 (!(status & E1000_STATUS_LU)) &&
2351 (!(rxcw & E1000_RXCW_C))) {
2352 if(hw->autoneg_failed == 0) {
2353 hw->autoneg_failed = 1;
2356 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2358 /* Disable auto-negotiation in the TXCW register */
2359 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2361 /* Force link-up and also force full-duplex. */
2362 ctrl = E1000_READ_REG(hw, CTRL);
2363 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2364 E1000_WRITE_REG(hw, CTRL, ctrl);
2366 /* Configure Flow Control after forcing link up. */
2367 ret_val = e1000_config_fc_after_link_up(hw);
2369 DEBUGOUT("Error configuring flow control\n");
2373 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2374 * auto-negotiation in the TXCW register and disable forced link in the
2375 * Device Control register in an attempt to auto-negotiate with our link
2378 else if(((hw->media_type == e1000_media_type_fiber) ||
2379 (hw->media_type == e1000_media_type_internal_serdes)) &&
2380 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2381 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2382 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2383 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2385 hw->serdes_link_down = FALSE;
2387 /* If we force link for non-auto-negotiation switch, check link status
2388 * based on MAC synchronization for internal serdes media type.
2390 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2391 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2392 /* SYNCH bit and IV bit are sticky. */
2394 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2395 if(!(rxcw & E1000_RXCW_IV)) {
2396 hw->serdes_link_down = FALSE;
2397 DEBUGOUT("SERDES: Link is up.\n");
2400 hw->serdes_link_down = TRUE;
2401 DEBUGOUT("SERDES: Link is down.\n");
2404 if((hw->media_type == e1000_media_type_internal_serdes) &&
2405 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2406 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2408 return E1000_SUCCESS;
2411 /******************************************************************************
2412 * Detects the current speed and duplex settings of the hardware.
2414 * hw - Struct containing variables accessed by shared code
2415 * speed - Speed of the connection
2416 * duplex - Duplex setting of the connection
2417 *****************************************************************************/
2419 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2427 DEBUGFUNC("e1000_get_speed_and_duplex");
2429 if(hw->mac_type >= e1000_82543) {
2430 status = E1000_READ_REG(hw, STATUS);
2431 if(status & E1000_STATUS_SPEED_1000) {
2432 *speed = SPEED_1000;
2433 DEBUGOUT("1000 Mbs, ");
2434 } else if(status & E1000_STATUS_SPEED_100) {
2436 DEBUGOUT("100 Mbs, ");
2439 DEBUGOUT("10 Mbs, ");
2442 if(status & E1000_STATUS_FD) {
2443 *duplex = FULL_DUPLEX;
2444 DEBUGOUT("Full Duplex\r\n");
2446 *duplex = HALF_DUPLEX;
2447 DEBUGOUT(" Half Duplex\r\n");
2450 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2451 *speed = SPEED_1000;
2452 *duplex = FULL_DUPLEX;
2455 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2456 * if it is operating at half duplex. Here we set the duplex settings to
2457 * match the duplex in the link partner's capabilities.
2459 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2460 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2464 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2465 *duplex = HALF_DUPLEX;
2467 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2470 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2471 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2472 *duplex = HALF_DUPLEX;
2476 return E1000_SUCCESS;
2479 /******************************************************************************
2480 * Blocks until autoneg completes or times out (~4.5 seconds)
2482 * hw - Struct containing variables accessed by shared code
2483 ******************************************************************************/
2485 e1000_wait_autoneg(struct e1000_hw *hw)
2491 DEBUGFUNC("e1000_wait_autoneg");
2492 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2494 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2495 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2496 /* Read the MII Status Register and wait for Auto-Neg
2497 * Complete bit to be set.
2499 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2502 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2505 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2506 return E1000_SUCCESS;
2510 return E1000_SUCCESS;
2513 /******************************************************************************
2514 * Raises the Management Data Clock
2516 * hw - Struct containing variables accessed by shared code
2517 * ctrl - Device control register's current value
2518 ******************************************************************************/
2520 e1000_raise_mdi_clk(struct e1000_hw *hw,
2523 /* Raise the clock input to the Management Data Clock (by setting the MDC
2524 * bit), and then delay 10 microseconds.
2526 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2527 E1000_WRITE_FLUSH(hw);
2531 /******************************************************************************
2532 * Lowers the Management Data Clock
2534 * hw - Struct containing variables accessed by shared code
2535 * ctrl - Device control register's current value
2536 ******************************************************************************/
2538 e1000_lower_mdi_clk(struct e1000_hw *hw,
2541 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2542 * bit), and then delay 10 microseconds.
2544 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2545 E1000_WRITE_FLUSH(hw);
2549 /******************************************************************************
2550 * Shifts data bits out to the PHY
2552 * hw - Struct containing variables accessed by shared code
2553 * data - Data to send out to the PHY
2554 * count - Number of bits to shift out
2556 * Bits are shifted out in MSB to LSB order.
2557 ******************************************************************************/
2559 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2566 /* We need to shift "count" number of bits out to the PHY. So, the value
2567 * in the "data" parameter will be shifted out to the PHY one bit at a
2568 * time. In order to do this, "data" must be broken down into bits.
2571 mask <<= (count - 1);
2573 ctrl = E1000_READ_REG(hw, CTRL);
2575 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2576 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2579 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2580 * then raising and lowering the Management Data Clock. A "0" is
2581 * shifted out to the PHY by setting the MDIO bit to "0" and then
2582 * raising and lowering the clock.
2584 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2585 else ctrl &= ~E1000_CTRL_MDIO;
2587 E1000_WRITE_REG(hw, CTRL, ctrl);
2588 E1000_WRITE_FLUSH(hw);
2592 e1000_raise_mdi_clk(hw, &ctrl);
2593 e1000_lower_mdi_clk(hw, &ctrl);
2599 /******************************************************************************
2600 * Shifts data bits in from the PHY
2602 * hw - Struct containing variables accessed by shared code
2604 * Bits are shifted in in MSB to LSB order.
2605 ******************************************************************************/
2607 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2613 /* In order to read a register from the PHY, we need to shift in a total
2614 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2615 * to avoid contention on the MDIO pin when a read operation is performed.
2616 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2617 * by raising the input to the Management Data Clock (setting the MDC bit),
2618 * and then reading the value of the MDIO bit.
2620 ctrl = E1000_READ_REG(hw, CTRL);
2622 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2623 ctrl &= ~E1000_CTRL_MDIO_DIR;
2624 ctrl &= ~E1000_CTRL_MDIO;
2626 E1000_WRITE_REG(hw, CTRL, ctrl);
2627 E1000_WRITE_FLUSH(hw);
2629 /* Raise and Lower the clock before reading in the data. This accounts for
2630 * the turnaround bits. The first clock occurred when we clocked out the
2631 * last bit of the Register Address.
2633 e1000_raise_mdi_clk(hw, &ctrl);
2634 e1000_lower_mdi_clk(hw, &ctrl);
2636 for(data = 0, i = 0; i < 16; i++) {
2638 e1000_raise_mdi_clk(hw, &ctrl);
2639 ctrl = E1000_READ_REG(hw, CTRL);
2640 /* Check to see if we shifted in a "1". */
2641 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2642 e1000_lower_mdi_clk(hw, &ctrl);
2645 e1000_raise_mdi_clk(hw, &ctrl);
2646 e1000_lower_mdi_clk(hw, &ctrl);
2651 /*****************************************************************************
2652 * Reads the value from a PHY register, if the value is on a specific non zero
2653 * page, sets the page first.
2654 * hw - Struct containing variables accessed by shared code
2655 * reg_addr - address of the PHY register to read
2656 ******************************************************************************/
2658 e1000_read_phy_reg(struct e1000_hw *hw,
2664 DEBUGFUNC("e1000_read_phy_reg");
2666 if((hw->phy_type == e1000_phy_igp ||
2667 hw->phy_type == e1000_phy_igp_2) &&
2668 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2669 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2670 (uint16_t)reg_addr);
2676 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2683 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2689 const uint32_t phy_addr = 1;
2691 DEBUGFUNC("e1000_read_phy_reg_ex");
2693 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2694 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2695 return -E1000_ERR_PARAM;
2698 if(hw->mac_type > e1000_82543) {
2699 /* Set up Op-code, Phy Address, and register address in the MDI
2700 * Control register. The MAC will take care of interfacing with the
2701 * PHY to retrieve the desired data.
2703 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2704 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2705 (E1000_MDIC_OP_READ));
2707 E1000_WRITE_REG(hw, MDIC, mdic);
2709 /* Poll the ready bit to see if the MDI read completed */
2710 for(i = 0; i < 64; i++) {
2712 mdic = E1000_READ_REG(hw, MDIC);
2713 if(mdic & E1000_MDIC_READY) break;
2715 if(!(mdic & E1000_MDIC_READY)) {
2716 DEBUGOUT("MDI Read did not complete\n");
2717 return -E1000_ERR_PHY;
2719 if(mdic & E1000_MDIC_ERROR) {
2720 DEBUGOUT("MDI Error\n");
2721 return -E1000_ERR_PHY;
2723 *phy_data = (uint16_t) mdic;
2725 /* We must first send a preamble through the MDIO pin to signal the
2726 * beginning of an MII instruction. This is done by sending 32
2727 * consecutive "1" bits.
2729 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2731 /* Now combine the next few fields that are required for a read
2732 * operation. We use this method instead of calling the
2733 * e1000_shift_out_mdi_bits routine five different times. The format of
2734 * a MII read instruction consists of a shift out of 14 bits and is
2735 * defined as follows:
2736 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2737 * followed by a shift in of 18 bits. This first two bits shifted in
2738 * are TurnAround bits used to avoid contention on the MDIO pin when a
2739 * READ operation is performed. These two bits are thrown away
2740 * followed by a shift in of 16 bits which contains the desired data.
2742 mdic = ((reg_addr) | (phy_addr << 5) |
2743 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2745 e1000_shift_out_mdi_bits(hw, mdic, 14);
2747 /* Now that we've shifted out the read command to the MII, we need to
2748 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2751 *phy_data = e1000_shift_in_mdi_bits(hw);
2753 return E1000_SUCCESS;
2756 /******************************************************************************
2757 * Writes a value to a PHY register
2759 * hw - Struct containing variables accessed by shared code
2760 * reg_addr - address of the PHY register to write
2761 * data - data to write to the PHY
2762 ******************************************************************************/
2764 e1000_write_phy_reg(struct e1000_hw *hw,
2770 DEBUGFUNC("e1000_write_phy_reg");
2772 if((hw->phy_type == e1000_phy_igp ||
2773 hw->phy_type == e1000_phy_igp_2) &&
2774 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2775 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2776 (uint16_t)reg_addr);
2782 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2789 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2795 const uint32_t phy_addr = 1;
2797 DEBUGFUNC("e1000_write_phy_reg_ex");
2799 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2800 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2801 return -E1000_ERR_PARAM;
2804 if(hw->mac_type > e1000_82543) {
2805 /* Set up Op-code, Phy Address, register address, and data intended
2806 * for the PHY register in the MDI Control register. The MAC will take
2807 * care of interfacing with the PHY to send the desired data.
2809 mdic = (((uint32_t) phy_data) |
2810 (reg_addr << E1000_MDIC_REG_SHIFT) |
2811 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2812 (E1000_MDIC_OP_WRITE));
2814 E1000_WRITE_REG(hw, MDIC, mdic);
2816 /* Poll the ready bit to see if the MDI read completed */
2817 for(i = 0; i < 640; i++) {
2819 mdic = E1000_READ_REG(hw, MDIC);
2820 if(mdic & E1000_MDIC_READY) break;
2822 if(!(mdic & E1000_MDIC_READY)) {
2823 DEBUGOUT("MDI Write did not complete\n");
2824 return -E1000_ERR_PHY;
2827 /* We'll need to use the SW defined pins to shift the write command
2828 * out to the PHY. We first send a preamble to the PHY to signal the
2829 * beginning of the MII instruction. This is done by sending 32
2830 * consecutive "1" bits.
2832 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2834 /* Now combine the remaining required fields that will indicate a
2835 * write operation. We use this method instead of calling the
2836 * e1000_shift_out_mdi_bits routine for each field in the command. The
2837 * format of a MII write instruction is as follows:
2838 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2840 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2841 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2843 mdic |= (uint32_t) phy_data;
2845 e1000_shift_out_mdi_bits(hw, mdic, 32);
2848 return E1000_SUCCESS;
2852 /******************************************************************************
2853 * Returns the PHY to the power-on reset state
2855 * hw - Struct containing variables accessed by shared code
2856 ******************************************************************************/
2858 e1000_phy_hw_reset(struct e1000_hw *hw)
2860 uint32_t ctrl, ctrl_ext;
2864 DEBUGFUNC("e1000_phy_hw_reset");
2866 /* In the case of the phy reset being blocked, it's not an error, we
2867 * simply return success without performing the reset. */
2868 ret_val = e1000_check_phy_reset_block(hw);
2870 return E1000_SUCCESS;
2872 DEBUGOUT("Resetting Phy...\n");
2874 if(hw->mac_type > e1000_82543) {
2875 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2876 * bit. Then, take it out of reset.
2878 ctrl = E1000_READ_REG(hw, CTRL);
2879 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2880 E1000_WRITE_FLUSH(hw);
2882 E1000_WRITE_REG(hw, CTRL, ctrl);
2883 E1000_WRITE_FLUSH(hw);
2885 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2886 * bit to put the PHY into reset. Then, take it out of reset.
2888 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2889 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2890 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2891 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2892 E1000_WRITE_FLUSH(hw);
2894 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2895 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2896 E1000_WRITE_FLUSH(hw);
2900 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2901 /* Configure activity LED after PHY reset */
2902 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2903 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2904 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2905 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2908 /* Wait for FW to finish PHY configuration. */
2909 ret_val = e1000_get_phy_cfg_done(hw);
2914 /******************************************************************************
2917 * hw - Struct containing variables accessed by shared code
2919 * Sets bit 15 of the MII Control regiser
2920 ******************************************************************************/
2922 e1000_phy_reset(struct e1000_hw *hw)
2927 DEBUGFUNC("e1000_phy_reset");
2929 /* In the case of the phy reset being blocked, it's not an error, we
2930 * simply return success without performing the reset. */
2931 ret_val = e1000_check_phy_reset_block(hw);
2933 return E1000_SUCCESS;
2935 switch (hw->mac_type) {
2936 case e1000_82541_rev_2:
2937 ret_val = e1000_phy_hw_reset(hw);
2942 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2946 phy_data |= MII_CR_RESET;
2947 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2955 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
2956 e1000_phy_init_script(hw);
2958 return E1000_SUCCESS;
2961 /******************************************************************************
2962 * Probes the expected PHY address for known PHY IDs
2964 * hw - Struct containing variables accessed by shared code
2965 ******************************************************************************/
2967 e1000_detect_gig_phy(struct e1000_hw *hw)
2969 int32_t phy_init_status, ret_val;
2970 uint16_t phy_id_high, phy_id_low;
2971 boolean_t match = FALSE;
2973 DEBUGFUNC("e1000_detect_gig_phy");
2975 /* Read the PHY ID Registers to identify which PHY is onboard. */
2976 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2980 hw->phy_id = (uint32_t) (phy_id_high << 16);
2982 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2986 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2987 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2989 switch(hw->mac_type) {
2991 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2994 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2998 case e1000_82545_rev_3:
3000 case e1000_82546_rev_3:
3001 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3004 case e1000_82541_rev_2:
3006 case e1000_82547_rev_2:
3007 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3010 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3013 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3014 return -E1000_ERR_CONFIG;
3016 phy_init_status = e1000_set_phy_type(hw);
3018 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3019 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3020 return E1000_SUCCESS;
3022 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3023 return -E1000_ERR_PHY;
3026 /******************************************************************************
3027 * Resets the PHY's DSP
3029 * hw - Struct containing variables accessed by shared code
3030 ******************************************************************************/
3032 e1000_phy_reset_dsp(struct e1000_hw *hw)
3035 DEBUGFUNC("e1000_phy_reset_dsp");
3038 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3040 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3042 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3044 ret_val = E1000_SUCCESS;
3050 /******************************************************************************
3051 * Get PHY information from various PHY registers for igp PHY only.
3053 * hw - Struct containing variables accessed by shared code
3054 * phy_info - PHY information structure
3055 ******************************************************************************/
3057 e1000_phy_igp_get_info(struct e1000_hw *hw,
3058 struct e1000_phy_info *phy_info)
3061 uint16_t phy_data, polarity, min_length, max_length, average;
3063 DEBUGFUNC("e1000_phy_igp_get_info");
3065 /* The downshift status is checked only once, after link is established,
3066 * and it stored in the hw->speed_downgraded parameter. */
3067 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3069 /* IGP01E1000 does not need to support it. */
3070 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3072 /* IGP01E1000 always correct polarity reversal */
3073 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3075 /* Check polarity status */
3076 ret_val = e1000_check_polarity(hw, &polarity);
3080 phy_info->cable_polarity = polarity;
3082 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3086 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3087 IGP01E1000_PSSR_MDIX_SHIFT;
3089 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3090 IGP01E1000_PSSR_SPEED_1000MBPS) {
3091 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3092 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3096 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3097 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3098 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3099 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3101 /* Get cable length */
3102 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3106 /* Translate to old method */
3107 average = (max_length + min_length) / 2;
3109 if(average <= e1000_igp_cable_length_50)
3110 phy_info->cable_length = e1000_cable_length_50;
3111 else if(average <= e1000_igp_cable_length_80)
3112 phy_info->cable_length = e1000_cable_length_50_80;
3113 else if(average <= e1000_igp_cable_length_110)
3114 phy_info->cable_length = e1000_cable_length_80_110;
3115 else if(average <= e1000_igp_cable_length_140)
3116 phy_info->cable_length = e1000_cable_length_110_140;
3118 phy_info->cable_length = e1000_cable_length_140;
3121 return E1000_SUCCESS;
3124 /******************************************************************************
3125 * Get PHY information from various PHY registers fot m88 PHY only.
3127 * hw - Struct containing variables accessed by shared code
3128 * phy_info - PHY information structure
3129 ******************************************************************************/
3131 e1000_phy_m88_get_info(struct e1000_hw *hw,
3132 struct e1000_phy_info *phy_info)
3135 uint16_t phy_data, polarity;
3137 DEBUGFUNC("e1000_phy_m88_get_info");
3139 /* The downshift status is checked only once, after link is established,
3140 * and it stored in the hw->speed_downgraded parameter. */
3141 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3143 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3147 phy_info->extended_10bt_distance =
3148 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3149 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3150 phy_info->polarity_correction =
3151 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3152 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3154 /* Check polarity status */
3155 ret_val = e1000_check_polarity(hw, &polarity);
3158 phy_info->cable_polarity = polarity;
3160 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3164 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3165 M88E1000_PSSR_MDIX_SHIFT;
3167 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3168 /* Cable Length Estimation and Local/Remote Receiver Information
3169 * are only valid at 1000 Mbps.
3171 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3172 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3174 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3178 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3179 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3181 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3182 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3185 return E1000_SUCCESS;
3188 /******************************************************************************
3189 * Get PHY information from various PHY registers
3191 * hw - Struct containing variables accessed by shared code
3192 * phy_info - PHY information structure
3193 ******************************************************************************/
3195 e1000_phy_get_info(struct e1000_hw *hw,
3196 struct e1000_phy_info *phy_info)
3201 DEBUGFUNC("e1000_phy_get_info");
3203 phy_info->cable_length = e1000_cable_length_undefined;
3204 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3205 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3206 phy_info->downshift = e1000_downshift_undefined;
3207 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3208 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3209 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3210 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3212 if(hw->media_type != e1000_media_type_copper) {
3213 DEBUGOUT("PHY info is only valid for copper media\n");
3214 return -E1000_ERR_CONFIG;
3217 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3221 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3225 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3226 DEBUGOUT("PHY info is only valid if link is up\n");
3227 return -E1000_ERR_CONFIG;
3230 if(hw->phy_type == e1000_phy_igp ||
3231 hw->phy_type == e1000_phy_igp_2)
3232 return e1000_phy_igp_get_info(hw, phy_info);
3234 return e1000_phy_m88_get_info(hw, phy_info);
3238 e1000_validate_mdi_setting(struct e1000_hw *hw)
3240 DEBUGFUNC("e1000_validate_mdi_settings");
3242 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3243 DEBUGOUT("Invalid MDI setting detected\n");
3245 return -E1000_ERR_CONFIG;
3247 return E1000_SUCCESS;
3251 /******************************************************************************
3252 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3255 * hw - Struct containing variables accessed by shared code
3256 *****************************************************************************/
3258 e1000_init_eeprom_params(struct e1000_hw *hw)
3260 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3261 uint32_t eecd = E1000_READ_REG(hw, EECD);
3262 int32_t ret_val = E1000_SUCCESS;
3263 uint16_t eeprom_size;
3265 DEBUGFUNC("e1000_init_eeprom_params");
3267 switch (hw->mac_type) {
3268 case e1000_82542_rev2_0:
3269 case e1000_82542_rev2_1:
3272 eeprom->type = e1000_eeprom_microwire;
3273 eeprom->word_size = 64;
3274 eeprom->opcode_bits = 3;
3275 eeprom->address_bits = 6;
3276 eeprom->delay_usec = 50;
3277 eeprom->use_eerd = FALSE;
3278 eeprom->use_eewr = FALSE;
3282 case e1000_82545_rev_3:
3284 case e1000_82546_rev_3:
3285 eeprom->type = e1000_eeprom_microwire;
3286 eeprom->opcode_bits = 3;
3287 eeprom->delay_usec = 50;
3288 if(eecd & E1000_EECD_SIZE) {
3289 eeprom->word_size = 256;
3290 eeprom->address_bits = 8;
3292 eeprom->word_size = 64;
3293 eeprom->address_bits = 6;
3295 eeprom->use_eerd = FALSE;
3296 eeprom->use_eewr = FALSE;
3299 case e1000_82541_rev_2:
3301 case e1000_82547_rev_2:
3302 if (eecd & E1000_EECD_TYPE) {
3303 eeprom->type = e1000_eeprom_spi;
3304 eeprom->opcode_bits = 8;
3305 eeprom->delay_usec = 1;
3306 if (eecd & E1000_EECD_ADDR_BITS) {
3307 eeprom->page_size = 32;
3308 eeprom->address_bits = 16;
3310 eeprom->page_size = 8;
3311 eeprom->address_bits = 8;
3314 eeprom->type = e1000_eeprom_microwire;
3315 eeprom->opcode_bits = 3;
3316 eeprom->delay_usec = 50;
3317 if (eecd & E1000_EECD_ADDR_BITS) {
3318 eeprom->word_size = 256;
3319 eeprom->address_bits = 8;
3321 eeprom->word_size = 64;
3322 eeprom->address_bits = 6;
3325 eeprom->use_eerd = FALSE;
3326 eeprom->use_eewr = FALSE;
3329 eeprom->type = e1000_eeprom_spi;
3330 eeprom->opcode_bits = 8;
3331 eeprom->delay_usec = 1;
3332 if (eecd & E1000_EECD_ADDR_BITS) {
3333 eeprom->page_size = 32;
3334 eeprom->address_bits = 16;
3336 eeprom->page_size = 8;
3337 eeprom->address_bits = 8;
3339 eeprom->use_eerd = TRUE;
3340 eeprom->use_eewr = TRUE;
3341 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
3342 eeprom->type = e1000_eeprom_flash;
3343 eeprom->word_size = 2048;
3345 /* Ensure that the Autonomous FLASH update bit is cleared due to
3346 * Flash update issue on parts which use a FLASH for NVM. */
3347 eecd &= ~E1000_EECD_AUPDEN;
3348 E1000_WRITE_REG(hw, EECD, eecd);
3355 if (eeprom->type == e1000_eeprom_spi) {
3356 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3357 * 32KB (incremented by powers of 2).
3359 if(hw->mac_type <= e1000_82547_rev_2) {
3360 /* Set to default value for initial eeprom read. */
3361 eeprom->word_size = 64;
3362 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3365 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3366 /* 256B eeprom size was not supported in earlier hardware, so we
3367 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3368 * is never the result used in the shifting logic below. */
3372 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3373 E1000_EECD_SIZE_EX_SHIFT);
3376 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3381 /******************************************************************************
3382 * Raises the EEPROM's clock input.
3384 * hw - Struct containing variables accessed by shared code
3385 * eecd - EECD's current value
3386 *****************************************************************************/
3388 e1000_raise_ee_clk(struct e1000_hw *hw,
3391 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3392 * wait <delay> microseconds.
3394 *eecd = *eecd | E1000_EECD_SK;
3395 E1000_WRITE_REG(hw, EECD, *eecd);
3396 E1000_WRITE_FLUSH(hw);
3397 udelay(hw->eeprom.delay_usec);
3400 /******************************************************************************
3401 * Lowers the EEPROM's clock input.
3403 * hw - Struct containing variables accessed by shared code
3404 * eecd - EECD's current value
3405 *****************************************************************************/
3407 e1000_lower_ee_clk(struct e1000_hw *hw,
3410 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3411 * wait 50 microseconds.
3413 *eecd = *eecd & ~E1000_EECD_SK;
3414 E1000_WRITE_REG(hw, EECD, *eecd);
3415 E1000_WRITE_FLUSH(hw);
3416 udelay(hw->eeprom.delay_usec);
3419 /******************************************************************************
3420 * Shift data bits out to the EEPROM.
3422 * hw - Struct containing variables accessed by shared code
3423 * data - data to send to the EEPROM
3424 * count - number of bits to shift out
3425 *****************************************************************************/
3427 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3431 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3435 /* We need to shift "count" bits out to the EEPROM. So, value in the
3436 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3437 * In order to do this, "data" must be broken down into bits.
3439 mask = 0x01 << (count - 1);
3440 eecd = E1000_READ_REG(hw, EECD);
3441 if (eeprom->type == e1000_eeprom_microwire) {
3442 eecd &= ~E1000_EECD_DO;
3443 } else if (eeprom->type == e1000_eeprom_spi) {
3444 eecd |= E1000_EECD_DO;
3447 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3448 * and then raising and then lowering the clock (the SK bit controls
3449 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3450 * by setting "DI" to "0" and then raising and then lowering the clock.
3452 eecd &= ~E1000_EECD_DI;
3455 eecd |= E1000_EECD_DI;
3457 E1000_WRITE_REG(hw, EECD, eecd);
3458 E1000_WRITE_FLUSH(hw);
3460 udelay(eeprom->delay_usec);
3462 e1000_raise_ee_clk(hw, &eecd);
3463 e1000_lower_ee_clk(hw, &eecd);
3469 /* We leave the "DI" bit set to "0" when we leave this routine. */
3470 eecd &= ~E1000_EECD_DI;
3471 E1000_WRITE_REG(hw, EECD, eecd);
3474 /******************************************************************************
3475 * Shift data bits in from the EEPROM
3477 * hw - Struct containing variables accessed by shared code
3478 *****************************************************************************/
3480 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3487 /* In order to read a register from the EEPROM, we need to shift 'count'
3488 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3489 * input to the EEPROM (setting the SK bit), and then reading the value of
3490 * the "DO" bit. During this "shifting in" process the "DI" bit should
3494 eecd = E1000_READ_REG(hw, EECD);
3496 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3499 for(i = 0; i < count; i++) {
3501 e1000_raise_ee_clk(hw, &eecd);
3503 eecd = E1000_READ_REG(hw, EECD);
3505 eecd &= ~(E1000_EECD_DI);
3506 if(eecd & E1000_EECD_DO)
3509 e1000_lower_ee_clk(hw, &eecd);
3515 /******************************************************************************
3516 * Prepares EEPROM for access
3518 * hw - Struct containing variables accessed by shared code
3520 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3521 * function should be called before issuing a command to the EEPROM.
3522 *****************************************************************************/
3524 e1000_acquire_eeprom(struct e1000_hw *hw)
3526 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3529 DEBUGFUNC("e1000_acquire_eeprom");
3531 if(e1000_get_hw_eeprom_semaphore(hw))
3532 return -E1000_ERR_EEPROM;
3534 eecd = E1000_READ_REG(hw, EECD);
3536 if (hw->mac_type != e1000_82573) {
3537 /* Request EEPROM Access */
3538 if(hw->mac_type > e1000_82544) {
3539 eecd |= E1000_EECD_REQ;
3540 E1000_WRITE_REG(hw, EECD, eecd);
3541 eecd = E1000_READ_REG(hw, EECD);
3542 while((!(eecd & E1000_EECD_GNT)) &&
3543 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3546 eecd = E1000_READ_REG(hw, EECD);
3548 if(!(eecd & E1000_EECD_GNT)) {
3549 eecd &= ~E1000_EECD_REQ;
3550 E1000_WRITE_REG(hw, EECD, eecd);
3551 DEBUGOUT("Could not acquire EEPROM grant\n");
3552 return -E1000_ERR_EEPROM;
3557 /* Setup EEPROM for Read/Write */
3559 if (eeprom->type == e1000_eeprom_microwire) {
3560 /* Clear SK and DI */
3561 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3562 E1000_WRITE_REG(hw, EECD, eecd);
3565 eecd |= E1000_EECD_CS;
3566 E1000_WRITE_REG(hw, EECD, eecd);
3567 } else if (eeprom->type == e1000_eeprom_spi) {
3568 /* Clear SK and CS */
3569 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3570 E1000_WRITE_REG(hw, EECD, eecd);
3574 return E1000_SUCCESS;
3577 /******************************************************************************
3578 * Returns EEPROM to a "standby" state
3580 * hw - Struct containing variables accessed by shared code
3581 *****************************************************************************/
3583 e1000_standby_eeprom(struct e1000_hw *hw)
3585 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3588 eecd = E1000_READ_REG(hw, EECD);
3590 if(eeprom->type == e1000_eeprom_microwire) {
3591 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3592 E1000_WRITE_REG(hw, EECD, eecd);
3593 E1000_WRITE_FLUSH(hw);
3594 udelay(eeprom->delay_usec);
3597 eecd |= E1000_EECD_SK;
3598 E1000_WRITE_REG(hw, EECD, eecd);
3599 E1000_WRITE_FLUSH(hw);
3600 udelay(eeprom->delay_usec);
3603 eecd |= E1000_EECD_CS;
3604 E1000_WRITE_REG(hw, EECD, eecd);
3605 E1000_WRITE_FLUSH(hw);
3606 udelay(eeprom->delay_usec);
3609 eecd &= ~E1000_EECD_SK;
3610 E1000_WRITE_REG(hw, EECD, eecd);
3611 E1000_WRITE_FLUSH(hw);
3612 udelay(eeprom->delay_usec);
3613 } else if(eeprom->type == e1000_eeprom_spi) {
3614 /* Toggle CS to flush commands */
3615 eecd |= E1000_EECD_CS;
3616 E1000_WRITE_REG(hw, EECD, eecd);
3617 E1000_WRITE_FLUSH(hw);
3618 udelay(eeprom->delay_usec);
3619 eecd &= ~E1000_EECD_CS;
3620 E1000_WRITE_REG(hw, EECD, eecd);
3621 E1000_WRITE_FLUSH(hw);
3622 udelay(eeprom->delay_usec);
3626 /******************************************************************************
3627 * Terminates a command by inverting the EEPROM's chip select pin
3629 * hw - Struct containing variables accessed by shared code
3630 *****************************************************************************/
3632 e1000_release_eeprom(struct e1000_hw *hw)
3636 DEBUGFUNC("e1000_release_eeprom");
3638 eecd = E1000_READ_REG(hw, EECD);
3640 if (hw->eeprom.type == e1000_eeprom_spi) {
3641 eecd |= E1000_EECD_CS; /* Pull CS high */
3642 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3644 E1000_WRITE_REG(hw, EECD, eecd);
3646 udelay(hw->eeprom.delay_usec);
3647 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3648 /* cleanup eeprom */
3650 /* CS on Microwire is active-high */
3651 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3653 E1000_WRITE_REG(hw, EECD, eecd);
3655 /* Rising edge of clock */
3656 eecd |= E1000_EECD_SK;
3657 E1000_WRITE_REG(hw, EECD, eecd);
3658 E1000_WRITE_FLUSH(hw);
3659 udelay(hw->eeprom.delay_usec);
3661 /* Falling edge of clock */
3662 eecd &= ~E1000_EECD_SK;
3663 E1000_WRITE_REG(hw, EECD, eecd);
3664 E1000_WRITE_FLUSH(hw);
3665 udelay(hw->eeprom.delay_usec);
3668 /* Stop requesting EEPROM access */
3669 if(hw->mac_type > e1000_82544) {
3670 eecd &= ~E1000_EECD_REQ;
3671 E1000_WRITE_REG(hw, EECD, eecd);
3674 e1000_put_hw_eeprom_semaphore(hw);
3677 /******************************************************************************
3678 * Reads a 16 bit word from the EEPROM.
3680 * hw - Struct containing variables accessed by shared code
3681 *****************************************************************************/
3683 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3685 uint16_t retry_count = 0;
3686 uint8_t spi_stat_reg;
3688 DEBUGFUNC("e1000_spi_eeprom_ready");
3690 /* Read "Status Register" repeatedly until the LSB is cleared. The
3691 * EEPROM will signal that the command has been completed by clearing
3692 * bit 0 of the internal status register. If it's not cleared within
3693 * 5 milliseconds, then error out.
3697 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3698 hw->eeprom.opcode_bits);
3699 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3700 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3706 e1000_standby_eeprom(hw);
3707 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3709 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3710 * only 0-5mSec on 5V devices)
3712 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3713 DEBUGOUT("SPI EEPROM Status error\n");
3714 return -E1000_ERR_EEPROM;
3717 return E1000_SUCCESS;
3720 /******************************************************************************
3721 * Reads a 16 bit word from the EEPROM.
3723 * hw - Struct containing variables accessed by shared code
3724 * offset - offset of word in the EEPROM to read
3725 * data - word read from the EEPROM
3726 * words - number of words to read
3727 *****************************************************************************/
3729 e1000_read_eeprom(struct e1000_hw *hw,
3734 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3738 DEBUGFUNC("e1000_read_eeprom");
3740 /* A check for invalid values: offset too large, too many words, and not
3743 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3745 DEBUGOUT("\"words\" parameter out of bounds\n");
3746 return -E1000_ERR_EEPROM;
3749 /* FLASH reads without acquiring the semaphore are safe in 82573-based
3752 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3753 (hw->mac_type != e1000_82573)) {
3754 /* Prepare the EEPROM for reading */
3755 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3756 return -E1000_ERR_EEPROM;
3759 if(eeprom->use_eerd == TRUE) {
3760 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
3761 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3762 (hw->mac_type != e1000_82573))
3763 e1000_release_eeprom(hw);
3767 if(eeprom->type == e1000_eeprom_spi) {
3769 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3771 if(e1000_spi_eeprom_ready(hw)) {
3772 e1000_release_eeprom(hw);
3773 return -E1000_ERR_EEPROM;
3776 e1000_standby_eeprom(hw);
3778 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3779 if((eeprom->address_bits == 8) && (offset >= 128))
3780 read_opcode |= EEPROM_A8_OPCODE_SPI;
3782 /* Send the READ command (opcode + addr) */
3783 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3784 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3786 /* Read the data. The address of the eeprom internally increments with
3787 * each byte (spi) being read, saving on the overhead of eeprom setup
3788 * and tear-down. The address counter will roll over if reading beyond
3789 * the size of the eeprom, thus allowing the entire memory to be read
3790 * starting from any offset. */
3791 for (i = 0; i < words; i++) {
3792 word_in = e1000_shift_in_ee_bits(hw, 16);
3793 data[i] = (word_in >> 8) | (word_in << 8);
3795 } else if(eeprom->type == e1000_eeprom_microwire) {
3796 for (i = 0; i < words; i++) {
3797 /* Send the READ command (opcode + addr) */
3798 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3799 eeprom->opcode_bits);
3800 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3801 eeprom->address_bits);
3803 /* Read the data. For microwire, each word requires the overhead
3804 * of eeprom setup and tear-down. */
3805 data[i] = e1000_shift_in_ee_bits(hw, 16);
3806 e1000_standby_eeprom(hw);
3810 /* End this read operation */
3811 e1000_release_eeprom(hw);
3813 return E1000_SUCCESS;
3816 /******************************************************************************
3817 * Reads a 16 bit word from the EEPROM using the EERD register.
3819 * hw - Struct containing variables accessed by shared code
3820 * offset - offset of word in the EEPROM to read
3821 * data - word read from the EEPROM
3822 * words - number of words to read
3823 *****************************************************************************/
3825 e1000_read_eeprom_eerd(struct e1000_hw *hw,
3830 uint32_t i, eerd = 0;
3833 for (i = 0; i < words; i++) {
3834 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3835 E1000_EEPROM_RW_REG_START;
3837 E1000_WRITE_REG(hw, EERD, eerd);
3838 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3843 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
3850 /******************************************************************************
3851 * Writes a 16 bit word from the EEPROM using the EEWR register.
3853 * hw - Struct containing variables accessed by shared code
3854 * offset - offset of word in the EEPROM to read
3855 * data - word read from the EEPROM
3856 * words - number of words to read
3857 *****************************************************************************/
3859 e1000_write_eeprom_eewr(struct e1000_hw *hw,
3864 uint32_t register_value = 0;
3868 for (i = 0; i < words; i++) {
3869 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3870 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3871 E1000_EEPROM_RW_REG_START;
3873 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3878 E1000_WRITE_REG(hw, EEWR, register_value);
3880 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3890 /******************************************************************************
3891 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3893 * hw - Struct containing variables accessed by shared code
3894 *****************************************************************************/
3896 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
3898 uint32_t attempts = 100000;
3899 uint32_t i, reg = 0;
3900 int32_t done = E1000_ERR_EEPROM;
3902 for(i = 0; i < attempts; i++) {
3903 if(eerd == E1000_EEPROM_POLL_READ)
3904 reg = E1000_READ_REG(hw, EERD);
3906 reg = E1000_READ_REG(hw, EEWR);
3908 if(reg & E1000_EEPROM_RW_REG_DONE) {
3909 done = E1000_SUCCESS;
3918 /***************************************************************************
3919 * Description: Determines if the onboard NVM is FLASH or EEPROM.
3921 * hw - Struct containing variables accessed by shared code
3922 ****************************************************************************/
3924 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
3928 if(hw->mac_type == e1000_82573) {
3929 eecd = E1000_READ_REG(hw, EECD);
3931 /* Isolate bits 15 & 16 */
3932 eecd = ((eecd >> 15) & 0x03);
3934 /* If both bits are set, device is Flash type */
3942 /******************************************************************************
3943 * Verifies that the EEPROM has a valid checksum
3945 * hw - Struct containing variables accessed by shared code
3947 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3948 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3950 *****************************************************************************/
3952 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3954 uint16_t checksum = 0;
3955 uint16_t i, eeprom_data;
3957 DEBUGFUNC("e1000_validate_eeprom_checksum");
3959 if ((hw->mac_type == e1000_82573) &&
3960 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
3961 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
3962 * 10h-12h. Checksum may need to be fixed. */
3963 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
3964 if ((eeprom_data & 0x10) == 0) {
3965 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
3966 * has already been fixed. If the checksum is still wrong and this
3967 * bit is a 1, we need to return bad checksum. Otherwise, we need
3968 * to set this bit to a 1 and update the checksum. */
3969 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
3970 if ((eeprom_data & 0x8000) == 0) {
3971 eeprom_data |= 0x8000;
3972 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
3973 e1000_update_eeprom_checksum(hw);
3978 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3979 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3980 DEBUGOUT("EEPROM Read Error\n");
3981 return -E1000_ERR_EEPROM;
3983 checksum += eeprom_data;
3986 if(checksum == (uint16_t) EEPROM_SUM)
3987 return E1000_SUCCESS;
3989 DEBUGOUT("EEPROM Checksum Invalid\n");
3990 return -E1000_ERR_EEPROM;
3994 /******************************************************************************
3995 * Calculates the EEPROM checksum and writes it to the EEPROM
3997 * hw - Struct containing variables accessed by shared code
3999 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4000 * Writes the difference to word offset 63 of the EEPROM.
4001 *****************************************************************************/
4003 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4005 uint16_t checksum = 0;
4006 uint16_t i, eeprom_data;
4008 DEBUGFUNC("e1000_update_eeprom_checksum");
4010 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4011 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4012 DEBUGOUT("EEPROM Read Error\n");
4013 return -E1000_ERR_EEPROM;
4015 checksum += eeprom_data;
4017 checksum = (uint16_t) EEPROM_SUM - checksum;
4018 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4019 DEBUGOUT("EEPROM Write Error\n");
4020 return -E1000_ERR_EEPROM;
4021 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4022 e1000_commit_shadow_ram(hw);
4024 return E1000_SUCCESS;
4027 /******************************************************************************
4028 * Parent function for writing words to the different EEPROM types.
4030 * hw - Struct containing variables accessed by shared code
4031 * offset - offset within the EEPROM to be written to
4032 * words - number of words to write
4033 * data - 16 bit word to be written to the EEPROM
4035 * If e1000_update_eeprom_checksum is not called after this function, the
4036 * EEPROM will most likely contain an invalid checksum.
4037 *****************************************************************************/
4039 e1000_write_eeprom(struct e1000_hw *hw,
4044 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4047 DEBUGFUNC("e1000_write_eeprom");
4049 /* A check for invalid values: offset too large, too many words, and not
4052 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4054 DEBUGOUT("\"words\" parameter out of bounds\n");
4055 return -E1000_ERR_EEPROM;
4058 /* 82573 reads only through eerd */
4059 if(eeprom->use_eewr == TRUE)
4060 return e1000_write_eeprom_eewr(hw, offset, words, data);
4062 /* Prepare the EEPROM for writing */
4063 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4064 return -E1000_ERR_EEPROM;
4066 if(eeprom->type == e1000_eeprom_microwire) {
4067 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4069 status = e1000_write_eeprom_spi(hw, offset, words, data);
4073 /* Done with writing */
4074 e1000_release_eeprom(hw);
4079 /******************************************************************************
4080 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4082 * hw - Struct containing variables accessed by shared code
4083 * offset - offset within the EEPROM to be written to
4084 * words - number of words to write
4085 * data - pointer to array of 8 bit words to be written to the EEPROM
4087 *****************************************************************************/
4089 e1000_write_eeprom_spi(struct e1000_hw *hw,
4094 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4097 DEBUGFUNC("e1000_write_eeprom_spi");
4099 while (widx < words) {
4100 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4102 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4104 e1000_standby_eeprom(hw);
4106 /* Send the WRITE ENABLE command (8 bit opcode ) */
4107 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4108 eeprom->opcode_bits);
4110 e1000_standby_eeprom(hw);
4112 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4113 if((eeprom->address_bits == 8) && (offset >= 128))
4114 write_opcode |= EEPROM_A8_OPCODE_SPI;
4116 /* Send the Write command (8-bit opcode + addr) */
4117 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4119 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4120 eeprom->address_bits);
4124 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4125 while (widx < words) {
4126 uint16_t word_out = data[widx];
4127 word_out = (word_out >> 8) | (word_out << 8);
4128 e1000_shift_out_ee_bits(hw, word_out, 16);
4131 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4132 * operation, while the smaller eeproms are capable of an 8-byte
4133 * PAGE WRITE operation. Break the inner loop to pass new address
4135 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4136 e1000_standby_eeprom(hw);
4142 return E1000_SUCCESS;
4145 /******************************************************************************
4146 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4148 * hw - Struct containing variables accessed by shared code
4149 * offset - offset within the EEPROM to be written to
4150 * words - number of words to write
4151 * data - pointer to array of 16 bit words to be written to the EEPROM
4153 *****************************************************************************/
4155 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4160 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4162 uint16_t words_written = 0;
4165 DEBUGFUNC("e1000_write_eeprom_microwire");
4167 /* Send the write enable command to the EEPROM (3-bit opcode plus
4168 * 6/8-bit dummy address beginning with 11). It's less work to include
4169 * the 11 of the dummy address as part of the opcode than it is to shift
4170 * it over the correct number of bits for the address. This puts the
4171 * EEPROM into write/erase mode.
4173 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4174 (uint16_t)(eeprom->opcode_bits + 2));
4176 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4178 /* Prepare the EEPROM */
4179 e1000_standby_eeprom(hw);
4181 while (words_written < words) {
4182 /* Send the Write command (3-bit opcode + addr) */
4183 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4184 eeprom->opcode_bits);
4186 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4187 eeprom->address_bits);
4190 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4192 /* Toggle the CS line. This in effect tells the EEPROM to execute
4193 * the previous command.
4195 e1000_standby_eeprom(hw);
4197 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4198 * signal that the command has been completed by raising the DO signal.
4199 * If DO does not go high in 10 milliseconds, then error out.
4201 for(i = 0; i < 200; i++) {
4202 eecd = E1000_READ_REG(hw, EECD);
4203 if(eecd & E1000_EECD_DO) break;
4207 DEBUGOUT("EEPROM Write did not complete\n");
4208 return -E1000_ERR_EEPROM;
4211 /* Recover from write */
4212 e1000_standby_eeprom(hw);
4217 /* Send the write disable command to the EEPROM (3-bit opcode plus
4218 * 6/8-bit dummy address beginning with 10). It's less work to include
4219 * the 10 of the dummy address as part of the opcode than it is to shift
4220 * it over the correct number of bits for the address. This takes the
4221 * EEPROM out of write/erase mode.
4223 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4224 (uint16_t)(eeprom->opcode_bits + 2));
4226 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4228 return E1000_SUCCESS;
4231 /******************************************************************************
4232 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4233 * in the eeprom cache and the non modified values in the currently active bank
4236 * hw - Struct containing variables accessed by shared code
4237 * offset - offset of word in the EEPROM to read
4238 * data - word read from the EEPROM
4239 * words - number of words to read
4240 *****************************************************************************/
4242 e1000_commit_shadow_ram(struct e1000_hw *hw)
4244 uint32_t attempts = 100000;
4248 int32_t error = E1000_SUCCESS;
4250 /* The flop register will be used to determine if flash type is STM */
4251 flop = E1000_READ_REG(hw, FLOP);
4253 if (hw->mac_type == e1000_82573) {
4254 for (i=0; i < attempts; i++) {
4255 eecd = E1000_READ_REG(hw, EECD);
4256 if ((eecd & E1000_EECD_FLUPD) == 0) {
4262 if (i == attempts) {
4263 return -E1000_ERR_EEPROM;
4266 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4267 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4268 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4271 /* Perform the flash update */
4272 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4274 for (i=0; i < attempts; i++) {
4275 eecd = E1000_READ_REG(hw, EECD);
4276 if ((eecd & E1000_EECD_FLUPD) == 0) {
4282 if (i == attempts) {
4283 return -E1000_ERR_EEPROM;
4290 /******************************************************************************
4291 * Reads the adapter's part number from the EEPROM
4293 * hw - Struct containing variables accessed by shared code
4294 * part_num - Adapter's part number
4295 *****************************************************************************/
4297 e1000_read_part_num(struct e1000_hw *hw,
4300 uint16_t offset = EEPROM_PBA_BYTE_1;
4301 uint16_t eeprom_data;
4303 DEBUGFUNC("e1000_read_part_num");
4305 /* Get word 0 from EEPROM */
4306 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4307 DEBUGOUT("EEPROM Read Error\n");
4308 return -E1000_ERR_EEPROM;
4310 /* Save word 0 in upper half of part_num */
4311 *part_num = (uint32_t) (eeprom_data << 16);
4313 /* Get word 1 from EEPROM */
4314 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
4315 DEBUGOUT("EEPROM Read Error\n");
4316 return -E1000_ERR_EEPROM;
4318 /* Save word 1 in lower half of part_num */
4319 *part_num |= eeprom_data;
4321 return E1000_SUCCESS;
4324 /******************************************************************************
4325 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4326 * second function of dual function devices
4328 * hw - Struct containing variables accessed by shared code
4329 *****************************************************************************/
4331 e1000_read_mac_addr(struct e1000_hw * hw)
4334 uint16_t eeprom_data, i;
4336 DEBUGFUNC("e1000_read_mac_addr");
4338 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4340 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4341 DEBUGOUT("EEPROM Read Error\n");
4342 return -E1000_ERR_EEPROM;
4344 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
4345 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
4347 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
4348 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
4349 hw->perm_mac_addr[5] ^= 0x01;
4351 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
4352 hw->mac_addr[i] = hw->perm_mac_addr[i];
4353 return E1000_SUCCESS;
4356 /******************************************************************************
4357 * Initializes receive address filters.
4359 * hw - Struct containing variables accessed by shared code
4361 * Places the MAC address in receive address register 0 and clears the rest
4362 * of the receive addresss registers. Clears the multicast table. Assumes
4363 * the receiver is in reset when the routine is called.
4364 *****************************************************************************/
4366 e1000_init_rx_addrs(struct e1000_hw *hw)
4371 DEBUGFUNC("e1000_init_rx_addrs");
4373 /* Setup the receive address. */
4374 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4376 e1000_rar_set(hw, hw->mac_addr, 0);
4378 rar_num = E1000_RAR_ENTRIES;
4379 /* Zero out the other 15 receive addresses. */
4380 DEBUGOUT("Clearing RAR[1-15]\n");
4381 for(i = 1; i < rar_num; i++) {
4382 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4383 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4387 /******************************************************************************
4388 * Updates the MAC's list of multicast addresses.
4390 * hw - Struct containing variables accessed by shared code
4391 * mc_addr_list - the list of new multicast addresses
4392 * mc_addr_count - number of addresses
4393 * pad - number of bytes between addresses in the list
4394 * rar_used_count - offset where to start adding mc addresses into the RAR's
4396 * The given list replaces any existing list. Clears the last 15 receive
4397 * address registers and the multicast table. Uses receive address registers
4398 * for the first 15 multicast addresses, and hashes the rest into the
4400 *****************************************************************************/
4402 e1000_mc_addr_list_update(struct e1000_hw *hw,
4403 uint8_t *mc_addr_list,
4404 uint32_t mc_addr_count,
4406 uint32_t rar_used_count)
4408 uint32_t hash_value;
4410 uint32_t num_rar_entry;
4411 uint32_t num_mta_entry;
4413 DEBUGFUNC("e1000_mc_addr_list_update");
4415 /* Set the new number of MC addresses that we are being requested to use. */
4416 hw->num_mc_addrs = mc_addr_count;
4418 /* Clear RAR[1-15] */
4419 DEBUGOUT(" Clearing RAR[1-15]\n");
4420 num_rar_entry = E1000_RAR_ENTRIES;
4421 for(i = rar_used_count; i < num_rar_entry; i++) {
4422 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4423 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4427 DEBUGOUT(" Clearing MTA\n");
4428 num_mta_entry = E1000_NUM_MTA_REGISTERS;
4429 for(i = 0; i < num_mta_entry; i++) {
4430 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
4433 /* Add the new addresses */
4434 for(i = 0; i < mc_addr_count; i++) {
4435 DEBUGOUT(" Adding the multicast addresses:\n");
4436 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
4437 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
4438 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
4439 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
4440 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
4441 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
4442 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
4444 hash_value = e1000_hash_mc_addr(hw,
4446 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
4448 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
4450 /* Place this multicast address in the RAR if there is room, *
4451 * else put it in the MTA
4453 if (rar_used_count < num_rar_entry) {
4455 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
4459 e1000_mta_set(hw, hash_value);
4462 DEBUGOUT("MC Update Complete\n");
4465 /******************************************************************************
4466 * Hashes an address to determine its location in the multicast table
4468 * hw - Struct containing variables accessed by shared code
4469 * mc_addr - the multicast address to hash
4470 *****************************************************************************/
4472 e1000_hash_mc_addr(struct e1000_hw *hw,
4475 uint32_t hash_value = 0;
4477 /* The portion of the address that is used for the hash table is
4478 * determined by the mc_filter_type setting.
4480 switch (hw->mc_filter_type) {
4481 /* [0] [1] [2] [3] [4] [5]
4486 /* [47:36] i.e. 0x563 for above example address */
4487 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
4490 /* [46:35] i.e. 0xAC6 for above example address */
4491 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4494 /* [45:34] i.e. 0x5D8 for above example address */
4495 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4498 /* [43:32] i.e. 0x634 for above example address */
4499 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4503 hash_value &= 0xFFF;
4508 /******************************************************************************
4509 * Sets the bit in the multicast table corresponding to the hash value.
4511 * hw - Struct containing variables accessed by shared code
4512 * hash_value - Multicast address hash value
4513 *****************************************************************************/
4515 e1000_mta_set(struct e1000_hw *hw,
4516 uint32_t hash_value)
4518 uint32_t hash_bit, hash_reg;
4522 /* The MTA is a register array of 128 32-bit registers.
4523 * It is treated like an array of 4096 bits. We want to set
4524 * bit BitArray[hash_value]. So we figure out what register
4525 * the bit is in, read it, OR in the new bit, then write
4526 * back the new value. The register is determined by the
4527 * upper 7 bits of the hash value and the bit within that
4528 * register are determined by the lower 5 bits of the value.
4530 hash_reg = (hash_value >> 5) & 0x7F;
4531 hash_bit = hash_value & 0x1F;
4533 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4535 mta |= (1 << hash_bit);
4537 /* If we are on an 82544 and we are trying to write an odd offset
4538 * in the MTA, save off the previous entry before writing and
4539 * restore the old value after writing.
4541 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4542 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4543 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4544 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4546 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4550 /******************************************************************************
4551 * Puts an ethernet address into a receive address register.
4553 * hw - Struct containing variables accessed by shared code
4554 * addr - Address to put into receive address register
4555 * index - Receive address register to write
4556 *****************************************************************************/
4558 e1000_rar_set(struct e1000_hw *hw,
4562 uint32_t rar_low, rar_high;
4564 /* HW expects these in little endian so we reverse the byte order
4565 * from network order (big endian) to little endian
4567 rar_low = ((uint32_t) addr[0] |
4568 ((uint32_t) addr[1] << 8) |
4569 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4571 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4573 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4574 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4577 /******************************************************************************
4578 * Writes a value to the specified offset in the VLAN filter table.
4580 * hw - Struct containing variables accessed by shared code
4581 * offset - Offset in VLAN filer table to write
4582 * value - Value to write into VLAN filter table
4583 *****************************************************************************/
4585 e1000_write_vfta(struct e1000_hw *hw,
4591 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4592 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4593 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4594 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4596 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4600 /******************************************************************************
4601 * Clears the VLAN filer table
4603 * hw - Struct containing variables accessed by shared code
4604 *****************************************************************************/
4606 e1000_clear_vfta(struct e1000_hw *hw)
4609 uint32_t vfta_value = 0;
4610 uint32_t vfta_offset = 0;
4611 uint32_t vfta_bit_in_reg = 0;
4613 if (hw->mac_type == e1000_82573) {
4614 if (hw->mng_cookie.vlan_id != 0) {
4615 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
4616 * ID. The following operations determine which 32b entry
4617 * (i.e. offset) into the array we want to set the VLAN ID
4618 * (i.e. bit) of the manageability unit. */
4619 vfta_offset = (hw->mng_cookie.vlan_id >>
4620 E1000_VFTA_ENTRY_SHIFT) &
4621 E1000_VFTA_ENTRY_MASK;
4622 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
4623 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
4626 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4627 /* If the offset we want to clear is the same offset of the
4628 * manageability VLAN ID, then clear all bits except that of the
4629 * manageability unit */
4630 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4631 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4636 e1000_id_led_init(struct e1000_hw * hw)
4639 const uint32_t ledctl_mask = 0x000000FF;
4640 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4641 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4642 uint16_t eeprom_data, i, temp;
4643 const uint16_t led_mask = 0x0F;
4645 DEBUGFUNC("e1000_id_led_init");
4647 if(hw->mac_type < e1000_82540) {
4649 return E1000_SUCCESS;
4652 ledctl = E1000_READ_REG(hw, LEDCTL);
4653 hw->ledctl_default = ledctl;
4654 hw->ledctl_mode1 = hw->ledctl_default;
4655 hw->ledctl_mode2 = hw->ledctl_default;
4657 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4658 DEBUGOUT("EEPROM Read Error\n");
4659 return -E1000_ERR_EEPROM;
4661 if((eeprom_data== ID_LED_RESERVED_0000) ||
4662 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4663 for(i = 0; i < 4; i++) {
4664 temp = (eeprom_data >> (i << 2)) & led_mask;
4666 case ID_LED_ON1_DEF2:
4667 case ID_LED_ON1_ON2:
4668 case ID_LED_ON1_OFF2:
4669 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4670 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4672 case ID_LED_OFF1_DEF2:
4673 case ID_LED_OFF1_ON2:
4674 case ID_LED_OFF1_OFF2:
4675 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4676 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4683 case ID_LED_DEF1_ON2:
4684 case ID_LED_ON1_ON2:
4685 case ID_LED_OFF1_ON2:
4686 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4687 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4689 case ID_LED_DEF1_OFF2:
4690 case ID_LED_ON1_OFF2:
4691 case ID_LED_OFF1_OFF2:
4692 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4693 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4700 return E1000_SUCCESS;
4703 /******************************************************************************
4704 * Prepares SW controlable LED for use and saves the current state of the LED.
4706 * hw - Struct containing variables accessed by shared code
4707 *****************************************************************************/
4709 e1000_setup_led(struct e1000_hw *hw)
4712 int32_t ret_val = E1000_SUCCESS;
4714 DEBUGFUNC("e1000_setup_led");
4716 switch(hw->mac_type) {
4717 case e1000_82542_rev2_0:
4718 case e1000_82542_rev2_1:
4721 /* No setup necessary */
4725 case e1000_82541_rev_2:
4726 case e1000_82547_rev_2:
4727 /* Turn off PHY Smart Power Down (if enabled) */
4728 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4729 &hw->phy_spd_default);
4732 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4733 (uint16_t)(hw->phy_spd_default &
4734 ~IGP01E1000_GMII_SPD));
4739 if(hw->media_type == e1000_media_type_fiber) {
4740 ledctl = E1000_READ_REG(hw, LEDCTL);
4741 /* Save current LEDCTL settings */
4742 hw->ledctl_default = ledctl;
4744 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4745 E1000_LEDCTL_LED0_BLINK |
4746 E1000_LEDCTL_LED0_MODE_MASK);
4747 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4748 E1000_LEDCTL_LED0_MODE_SHIFT);
4749 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4750 } else if(hw->media_type == e1000_media_type_copper)
4751 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4755 return E1000_SUCCESS;
4758 /******************************************************************************
4759 * Restores the saved state of the SW controlable LED.
4761 * hw - Struct containing variables accessed by shared code
4762 *****************************************************************************/
4764 e1000_cleanup_led(struct e1000_hw *hw)
4766 int32_t ret_val = E1000_SUCCESS;
4768 DEBUGFUNC("e1000_cleanup_led");
4770 switch(hw->mac_type) {
4771 case e1000_82542_rev2_0:
4772 case e1000_82542_rev2_1:
4775 /* No cleanup necessary */
4779 case e1000_82541_rev_2:
4780 case e1000_82547_rev_2:
4781 /* Turn on PHY Smart Power Down (if previously enabled) */
4782 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4783 hw->phy_spd_default);
4788 /* Restore LEDCTL settings */
4789 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4793 return E1000_SUCCESS;
4796 /******************************************************************************
4797 * Turns on the software controllable LED
4799 * hw - Struct containing variables accessed by shared code
4800 *****************************************************************************/
4802 e1000_led_on(struct e1000_hw *hw)
4804 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4806 DEBUGFUNC("e1000_led_on");
4808 switch(hw->mac_type) {
4809 case e1000_82542_rev2_0:
4810 case e1000_82542_rev2_1:
4812 /* Set SW Defineable Pin 0 to turn on the LED */
4813 ctrl |= E1000_CTRL_SWDPIN0;
4814 ctrl |= E1000_CTRL_SWDPIO0;
4817 if(hw->media_type == e1000_media_type_fiber) {
4818 /* Set SW Defineable Pin 0 to turn on the LED */
4819 ctrl |= E1000_CTRL_SWDPIN0;
4820 ctrl |= E1000_CTRL_SWDPIO0;
4822 /* Clear SW Defineable Pin 0 to turn on the LED */
4823 ctrl &= ~E1000_CTRL_SWDPIN0;
4824 ctrl |= E1000_CTRL_SWDPIO0;
4828 if(hw->media_type == e1000_media_type_fiber) {
4829 /* Clear SW Defineable Pin 0 to turn on the LED */
4830 ctrl &= ~E1000_CTRL_SWDPIN0;
4831 ctrl |= E1000_CTRL_SWDPIO0;
4832 } else if(hw->media_type == e1000_media_type_copper) {
4833 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4834 return E1000_SUCCESS;
4839 E1000_WRITE_REG(hw, CTRL, ctrl);
4841 return E1000_SUCCESS;
4844 /******************************************************************************
4845 * Turns off the software controllable LED
4847 * hw - Struct containing variables accessed by shared code
4848 *****************************************************************************/
4850 e1000_led_off(struct e1000_hw *hw)
4852 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4854 DEBUGFUNC("e1000_led_off");
4856 switch(hw->mac_type) {
4857 case e1000_82542_rev2_0:
4858 case e1000_82542_rev2_1:
4860 /* Clear SW Defineable Pin 0 to turn off the LED */
4861 ctrl &= ~E1000_CTRL_SWDPIN0;
4862 ctrl |= E1000_CTRL_SWDPIO0;
4865 if(hw->media_type == e1000_media_type_fiber) {
4866 /* Clear SW Defineable Pin 0 to turn off the LED */
4867 ctrl &= ~E1000_CTRL_SWDPIN0;
4868 ctrl |= E1000_CTRL_SWDPIO0;
4870 /* Set SW Defineable Pin 0 to turn off the LED */
4871 ctrl |= E1000_CTRL_SWDPIN0;
4872 ctrl |= E1000_CTRL_SWDPIO0;
4876 if(hw->media_type == e1000_media_type_fiber) {
4877 /* Set SW Defineable Pin 0 to turn off the LED */
4878 ctrl |= E1000_CTRL_SWDPIN0;
4879 ctrl |= E1000_CTRL_SWDPIO0;
4880 } else if(hw->media_type == e1000_media_type_copper) {
4881 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4882 return E1000_SUCCESS;
4887 E1000_WRITE_REG(hw, CTRL, ctrl);
4889 return E1000_SUCCESS;
4892 /******************************************************************************
4893 * Clears all hardware statistics counters.
4895 * hw - Struct containing variables accessed by shared code
4896 *****************************************************************************/
4898 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4900 volatile uint32_t temp;
4902 temp = E1000_READ_REG(hw, CRCERRS);
4903 temp = E1000_READ_REG(hw, SYMERRS);
4904 temp = E1000_READ_REG(hw, MPC);
4905 temp = E1000_READ_REG(hw, SCC);
4906 temp = E1000_READ_REG(hw, ECOL);
4907 temp = E1000_READ_REG(hw, MCC);
4908 temp = E1000_READ_REG(hw, LATECOL);
4909 temp = E1000_READ_REG(hw, COLC);
4910 temp = E1000_READ_REG(hw, DC);
4911 temp = E1000_READ_REG(hw, SEC);
4912 temp = E1000_READ_REG(hw, RLEC);
4913 temp = E1000_READ_REG(hw, XONRXC);
4914 temp = E1000_READ_REG(hw, XONTXC);
4915 temp = E1000_READ_REG(hw, XOFFRXC);
4916 temp = E1000_READ_REG(hw, XOFFTXC);
4917 temp = E1000_READ_REG(hw, FCRUC);
4918 temp = E1000_READ_REG(hw, PRC64);
4919 temp = E1000_READ_REG(hw, PRC127);
4920 temp = E1000_READ_REG(hw, PRC255);
4921 temp = E1000_READ_REG(hw, PRC511);
4922 temp = E1000_READ_REG(hw, PRC1023);
4923 temp = E1000_READ_REG(hw, PRC1522);
4924 temp = E1000_READ_REG(hw, GPRC);
4925 temp = E1000_READ_REG(hw, BPRC);
4926 temp = E1000_READ_REG(hw, MPRC);
4927 temp = E1000_READ_REG(hw, GPTC);
4928 temp = E1000_READ_REG(hw, GORCL);
4929 temp = E1000_READ_REG(hw, GORCH);
4930 temp = E1000_READ_REG(hw, GOTCL);
4931 temp = E1000_READ_REG(hw, GOTCH);
4932 temp = E1000_READ_REG(hw, RNBC);
4933 temp = E1000_READ_REG(hw, RUC);
4934 temp = E1000_READ_REG(hw, RFC);
4935 temp = E1000_READ_REG(hw, ROC);
4936 temp = E1000_READ_REG(hw, RJC);
4937 temp = E1000_READ_REG(hw, TORL);
4938 temp = E1000_READ_REG(hw, TORH);
4939 temp = E1000_READ_REG(hw, TOTL);
4940 temp = E1000_READ_REG(hw, TOTH);
4941 temp = E1000_READ_REG(hw, TPR);
4942 temp = E1000_READ_REG(hw, TPT);
4943 temp = E1000_READ_REG(hw, PTC64);
4944 temp = E1000_READ_REG(hw, PTC127);
4945 temp = E1000_READ_REG(hw, PTC255);
4946 temp = E1000_READ_REG(hw, PTC511);
4947 temp = E1000_READ_REG(hw, PTC1023);
4948 temp = E1000_READ_REG(hw, PTC1522);
4949 temp = E1000_READ_REG(hw, MPTC);
4950 temp = E1000_READ_REG(hw, BPTC);
4952 if(hw->mac_type < e1000_82543) return;
4954 temp = E1000_READ_REG(hw, ALGNERRC);
4955 temp = E1000_READ_REG(hw, RXERRC);
4956 temp = E1000_READ_REG(hw, TNCRS);
4957 temp = E1000_READ_REG(hw, CEXTERR);
4958 temp = E1000_READ_REG(hw, TSCTC);
4959 temp = E1000_READ_REG(hw, TSCTFC);
4961 if(hw->mac_type <= e1000_82544) return;
4963 temp = E1000_READ_REG(hw, MGTPRC);
4964 temp = E1000_READ_REG(hw, MGTPDC);
4965 temp = E1000_READ_REG(hw, MGTPTC);
4967 if(hw->mac_type <= e1000_82547_rev_2) return;
4969 temp = E1000_READ_REG(hw, IAC);
4970 temp = E1000_READ_REG(hw, ICRXOC);
4971 temp = E1000_READ_REG(hw, ICRXPTC);
4972 temp = E1000_READ_REG(hw, ICRXATC);
4973 temp = E1000_READ_REG(hw, ICTXPTC);
4974 temp = E1000_READ_REG(hw, ICTXATC);
4975 temp = E1000_READ_REG(hw, ICTXQEC);
4976 temp = E1000_READ_REG(hw, ICTXQMTC);
4977 temp = E1000_READ_REG(hw, ICRXDMTC);
4981 /******************************************************************************
4982 * Resets Adaptive IFS to its default state.
4984 * hw - Struct containing variables accessed by shared code
4986 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4987 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4988 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4989 * before calling this function.
4990 *****************************************************************************/
4992 e1000_reset_adaptive(struct e1000_hw *hw)
4994 DEBUGFUNC("e1000_reset_adaptive");
4996 if(hw->adaptive_ifs) {
4997 if(!hw->ifs_params_forced) {
4998 hw->current_ifs_val = 0;
4999 hw->ifs_min_val = IFS_MIN;
5000 hw->ifs_max_val = IFS_MAX;
5001 hw->ifs_step_size = IFS_STEP;
5002 hw->ifs_ratio = IFS_RATIO;
5004 hw->in_ifs_mode = FALSE;
5005 E1000_WRITE_REG(hw, AIT, 0);
5007 DEBUGOUT("Not in Adaptive IFS mode!\n");
5011 /******************************************************************************
5012 * Called during the callback/watchdog routine to update IFS value based on
5013 * the ratio of transmits to collisions.
5015 * hw - Struct containing variables accessed by shared code
5016 * tx_packets - Number of transmits since last callback
5017 * total_collisions - Number of collisions since last callback
5018 *****************************************************************************/
5020 e1000_update_adaptive(struct e1000_hw *hw)
5022 DEBUGFUNC("e1000_update_adaptive");
5024 if(hw->adaptive_ifs) {
5025 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5026 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5027 hw->in_ifs_mode = TRUE;
5028 if(hw->current_ifs_val < hw->ifs_max_val) {
5029 if(hw->current_ifs_val == 0)
5030 hw->current_ifs_val = hw->ifs_min_val;
5032 hw->current_ifs_val += hw->ifs_step_size;
5033 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5037 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5038 hw->current_ifs_val = 0;
5039 hw->in_ifs_mode = FALSE;
5040 E1000_WRITE_REG(hw, AIT, 0);
5044 DEBUGOUT("Not in Adaptive IFS mode!\n");
5048 /******************************************************************************
5049 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5051 * hw - Struct containing variables accessed by shared code
5052 * frame_len - The length of the frame in question
5053 * mac_addr - The Ethernet destination address of the frame in question
5054 *****************************************************************************/
5056 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5057 struct e1000_hw_stats *stats,
5063 /* First adjust the frame length. */
5065 /* We need to adjust the statistics counters, since the hardware
5066 * counters overcount this packet as a CRC error and undercount
5067 * the packet as a good packet
5069 /* This packet should not be counted as a CRC error. */
5071 /* This packet does count as a Good Packet Received. */
5074 /* Adjust the Good Octets received counters */
5075 carry_bit = 0x80000000 & stats->gorcl;
5076 stats->gorcl += frame_len;
5077 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5078 * Received Count) was one before the addition,
5079 * AND it is zero after, then we lost the carry out,
5080 * need to add one to Gorch (Good Octets Received Count High).
5081 * This could be simplified if all environments supported
5084 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5086 /* Is this a broadcast or multicast? Check broadcast first,
5087 * since the test for a multicast frame will test positive on
5088 * a broadcast frame.
5090 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5091 /* Broadcast packet */
5093 else if(*mac_addr & 0x01)
5094 /* Multicast packet */
5097 if(frame_len == hw->max_frame_size) {
5098 /* In this case, the hardware has overcounted the number of
5105 /* Adjust the bin counters when the extra byte put the frame in the
5106 * wrong bin. Remember that the frame_len was adjusted above.
5108 if(frame_len == 64) {
5111 } else if(frame_len == 127) {
5114 } else if(frame_len == 255) {
5117 } else if(frame_len == 511) {
5120 } else if(frame_len == 1023) {
5123 } else if(frame_len == 1522) {
5128 /******************************************************************************
5129 * Gets the current PCI bus type, speed, and width of the hardware
5131 * hw - Struct containing variables accessed by shared code
5132 *****************************************************************************/
5134 e1000_get_bus_info(struct e1000_hw *hw)
5138 switch (hw->mac_type) {
5139 case e1000_82542_rev2_0:
5140 case e1000_82542_rev2_1:
5141 hw->bus_type = e1000_bus_type_unknown;
5142 hw->bus_speed = e1000_bus_speed_unknown;
5143 hw->bus_width = e1000_bus_width_unknown;
5146 hw->bus_type = e1000_bus_type_pci_express;
5147 hw->bus_speed = e1000_bus_speed_2500;
5148 hw->bus_width = e1000_bus_width_pciex_4;
5151 status = E1000_READ_REG(hw, STATUS);
5152 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5153 e1000_bus_type_pcix : e1000_bus_type_pci;
5155 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5156 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5157 e1000_bus_speed_66 : e1000_bus_speed_120;
5158 } else if(hw->bus_type == e1000_bus_type_pci) {
5159 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5160 e1000_bus_speed_66 : e1000_bus_speed_33;
5162 switch (status & E1000_STATUS_PCIX_SPEED) {
5163 case E1000_STATUS_PCIX_SPEED_66:
5164 hw->bus_speed = e1000_bus_speed_66;
5166 case E1000_STATUS_PCIX_SPEED_100:
5167 hw->bus_speed = e1000_bus_speed_100;
5169 case E1000_STATUS_PCIX_SPEED_133:
5170 hw->bus_speed = e1000_bus_speed_133;
5173 hw->bus_speed = e1000_bus_speed_reserved;
5177 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5178 e1000_bus_width_64 : e1000_bus_width_32;
5182 /******************************************************************************
5183 * Reads a value from one of the devices registers using port I/O (as opposed
5184 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5186 * hw - Struct containing variables accessed by shared code
5187 * offset - offset to read from
5188 *****************************************************************************/
5190 e1000_read_reg_io(struct e1000_hw *hw,
5193 unsigned long io_addr = hw->io_base;
5194 unsigned long io_data = hw->io_base + 4;
5196 e1000_io_write(hw, io_addr, offset);
5197 return e1000_io_read(hw, io_data);
5200 /******************************************************************************
5201 * Writes a value to one of the devices registers using port I/O (as opposed to
5202 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5204 * hw - Struct containing variables accessed by shared code
5205 * offset - offset to write to
5206 * value - value to write
5207 *****************************************************************************/
5209 e1000_write_reg_io(struct e1000_hw *hw,
5213 unsigned long io_addr = hw->io_base;
5214 unsigned long io_data = hw->io_base + 4;
5216 e1000_io_write(hw, io_addr, offset);
5217 e1000_io_write(hw, io_data, value);
5221 /******************************************************************************
5222 * Estimates the cable length.
5224 * hw - Struct containing variables accessed by shared code
5225 * min_length - The estimated minimum length
5226 * max_length - The estimated maximum length
5228 * returns: - E1000_ERR_XXX
5231 * This function always returns a ranged length (minimum & maximum).
5232 * So for M88 phy's, this function interprets the one value returned from the
5233 * register to the minimum and maximum range.
5234 * For IGP phy's, the function calculates the range by the AGC registers.
5235 *****************************************************************************/
5237 e1000_get_cable_length(struct e1000_hw *hw,
5238 uint16_t *min_length,
5239 uint16_t *max_length)
5242 uint16_t agc_value = 0;
5243 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5244 uint16_t i, phy_data;
5245 uint16_t cable_length;
5247 DEBUGFUNC("e1000_get_cable_length");
5249 *min_length = *max_length = 0;
5251 /* Use old method for Phy older than IGP */
5252 if(hw->phy_type == e1000_phy_m88) {
5254 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5258 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5259 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
5261 /* Convert the enum value to ranged values */
5262 switch (cable_length) {
5263 case e1000_cable_length_50:
5265 *max_length = e1000_igp_cable_length_50;
5267 case e1000_cable_length_50_80:
5268 *min_length = e1000_igp_cable_length_50;
5269 *max_length = e1000_igp_cable_length_80;
5271 case e1000_cable_length_80_110:
5272 *min_length = e1000_igp_cable_length_80;
5273 *max_length = e1000_igp_cable_length_110;
5275 case e1000_cable_length_110_140:
5276 *min_length = e1000_igp_cable_length_110;
5277 *max_length = e1000_igp_cable_length_140;
5279 case e1000_cable_length_140:
5280 *min_length = e1000_igp_cable_length_140;
5281 *max_length = e1000_igp_cable_length_170;
5284 return -E1000_ERR_PHY;
5287 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5288 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5289 {IGP01E1000_PHY_AGC_A,
5290 IGP01E1000_PHY_AGC_B,
5291 IGP01E1000_PHY_AGC_C,
5292 IGP01E1000_PHY_AGC_D};
5293 /* Read the AGC registers for all channels */
5294 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5296 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5300 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5302 /* Array bound check. */
5303 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5305 return -E1000_ERR_PHY;
5307 agc_value += cur_agc;
5309 /* Update minimal AGC value. */
5310 if(min_agc > cur_agc)
5314 /* Remove the minimal AGC result for length < 50m */
5315 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5316 agc_value -= min_agc;
5318 /* Get the average length of the remaining 3 channels */
5319 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5321 /* Get the average length of all the 4 channels. */
5322 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5325 /* Set the range of the calculated length. */
5326 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5327 IGP01E1000_AGC_RANGE) > 0) ?
5328 (e1000_igp_cable_length_table[agc_value] -
5329 IGP01E1000_AGC_RANGE) : 0;
5330 *max_length = e1000_igp_cable_length_table[agc_value] +
5331 IGP01E1000_AGC_RANGE;
5334 return E1000_SUCCESS;
5337 /******************************************************************************
5338 * Check the cable polarity
5340 * hw - Struct containing variables accessed by shared code
5341 * polarity - output parameter : 0 - Polarity is not reversed
5342 * 1 - Polarity is reversed.
5344 * returns: - E1000_ERR_XXX
5347 * For phy's older then IGP, this function simply reads the polarity bit in the
5348 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5349 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5350 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5351 * IGP01E1000_PHY_PCS_INIT_REG.
5352 *****************************************************************************/
5354 e1000_check_polarity(struct e1000_hw *hw,
5360 DEBUGFUNC("e1000_check_polarity");
5362 if(hw->phy_type == e1000_phy_m88) {
5363 /* return the Polarity bit in the Status register. */
5364 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5368 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
5369 M88E1000_PSSR_REV_POLARITY_SHIFT;
5370 } else if(hw->phy_type == e1000_phy_igp ||
5371 hw->phy_type == e1000_phy_igp_2) {
5372 /* Read the Status register to check the speed */
5373 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5378 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5379 * find the polarity status */
5380 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5381 IGP01E1000_PSSR_SPEED_1000MBPS) {
5383 /* Read the GIG initialization PCS register (0x00B4) */
5384 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5389 /* Check the polarity bits */
5390 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
5392 /* For 10 Mbps, read the polarity bit in the status register. (for
5393 * 100 Mbps this bit is always 0) */
5394 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
5397 return E1000_SUCCESS;
5400 /******************************************************************************
5401 * Check if Downshift occured
5403 * hw - Struct containing variables accessed by shared code
5404 * downshift - output parameter : 0 - No Downshift ocured.
5405 * 1 - Downshift ocured.
5407 * returns: - E1000_ERR_XXX
5410 * For phy's older then IGP, this function reads the Downshift bit in the Phy
5411 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5412 * Link Health register. In IGP this bit is latched high, so the driver must
5413 * read it immediately after link is established.
5414 *****************************************************************************/
5416 e1000_check_downshift(struct e1000_hw *hw)
5421 DEBUGFUNC("e1000_check_downshift");
5423 if(hw->phy_type == e1000_phy_igp ||
5424 hw->phy_type == e1000_phy_igp_2) {
5425 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5430 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5431 } else if(hw->phy_type == e1000_phy_m88) {
5432 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5437 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5438 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5441 return E1000_SUCCESS;
5444 /*****************************************************************************
5446 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5447 * gigabit link is achieved to improve link quality.
5449 * hw: Struct containing variables accessed by shared code
5451 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5452 * E1000_SUCCESS at any other case.
5454 ****************************************************************************/
5457 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
5461 uint16_t phy_data, phy_saved_data, speed, duplex, i;
5462 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5463 {IGP01E1000_PHY_AGC_PARAM_A,
5464 IGP01E1000_PHY_AGC_PARAM_B,
5465 IGP01E1000_PHY_AGC_PARAM_C,
5466 IGP01E1000_PHY_AGC_PARAM_D};
5467 uint16_t min_length, max_length;
5469 DEBUGFUNC("e1000_config_dsp_after_link_change");
5471 if(hw->phy_type != e1000_phy_igp)
5472 return E1000_SUCCESS;
5475 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5477 DEBUGOUT("Error getting link speed and duplex\n");
5481 if(speed == SPEED_1000) {
5483 e1000_get_cable_length(hw, &min_length, &max_length);
5485 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
5486 min_length >= e1000_igp_cable_length_50) {
5488 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5489 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5494 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5496 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5501 hw->dsp_config_state = e1000_dsp_config_activated;
5504 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
5505 (min_length < e1000_igp_cable_length_50)) {
5507 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5508 uint32_t idle_errs = 0;
5510 /* clear previous idle error counts */
5511 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5516 for(i = 0; i < ffe_idle_err_timeout; i++) {
5518 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5523 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5524 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5525 hw->ffe_config_state = e1000_ffe_config_active;
5527 ret_val = e1000_write_phy_reg(hw,
5528 IGP01E1000_PHY_DSP_FFE,
5529 IGP01E1000_PHY_DSP_FFE_CM_CP);
5536 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5541 if(hw->dsp_config_state == e1000_dsp_config_activated) {
5542 /* Save off the current value of register 0x2F5B to be restored at
5543 * the end of the routines. */
5544 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5549 /* Disable the PHY transmitter */
5550 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5557 ret_val = e1000_write_phy_reg(hw, 0x0000,
5558 IGP01E1000_IEEE_FORCE_GIGA);
5561 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5562 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5566 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5567 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5569 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5574 ret_val = e1000_write_phy_reg(hw, 0x0000,
5575 IGP01E1000_IEEE_RESTART_AUTONEG);
5581 /* Now enable the transmitter */
5582 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5587 hw->dsp_config_state = e1000_dsp_config_enabled;
5590 if(hw->ffe_config_state == e1000_ffe_config_active) {
5591 /* Save off the current value of register 0x2F5B to be restored at
5592 * the end of the routines. */
5593 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5598 /* Disable the PHY transmitter */
5599 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5606 ret_val = e1000_write_phy_reg(hw, 0x0000,
5607 IGP01E1000_IEEE_FORCE_GIGA);
5610 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5611 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5615 ret_val = e1000_write_phy_reg(hw, 0x0000,
5616 IGP01E1000_IEEE_RESTART_AUTONEG);
5622 /* Now enable the transmitter */
5623 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5628 hw->ffe_config_state = e1000_ffe_config_enabled;
5631 return E1000_SUCCESS;
5634 /*****************************************************************************
5635 * Set PHY to class A mode
5636 * Assumes the following operations will follow to enable the new class mode.
5637 * 1. Do a PHY soft reset
5638 * 2. Restart auto-negotiation or force link.
5640 * hw - Struct containing variables accessed by shared code
5641 ****************************************************************************/
5643 e1000_set_phy_mode(struct e1000_hw *hw)
5646 uint16_t eeprom_data;
5648 DEBUGFUNC("e1000_set_phy_mode");
5650 if((hw->mac_type == e1000_82545_rev_3) &&
5651 (hw->media_type == e1000_media_type_copper)) {
5652 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5657 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5658 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5659 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5662 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5666 hw->phy_reset_disable = FALSE;
5670 return E1000_SUCCESS;
5673 /*****************************************************************************
5675 * This function sets the lplu state according to the active flag. When
5676 * activating lplu this function also disables smart speed and vise versa.
5677 * lplu will not be activated unless the device autonegotiation advertisment
5678 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5679 * hw: Struct containing variables accessed by shared code
5680 * active - true to enable lplu false to disable lplu.
5682 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5683 * E1000_SUCCESS at any other case.
5685 ****************************************************************************/
5688 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5693 DEBUGFUNC("e1000_set_d3_lplu_state");
5695 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
5696 return E1000_SUCCESS;
5698 /* During driver activity LPLU should not be used or it will attain link
5699 * from the lowest speeds starting from 10Mbps. The capability is used for
5700 * Dx transitions and states */
5701 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
5702 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5706 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5712 if(hw->mac_type == e1000_82541_rev_2 ||
5713 hw->mac_type == e1000_82547_rev_2) {
5714 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5715 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5719 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5720 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5726 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5727 * Dx states where the power conservation is most important. During
5728 * driver activity we should enable SmartSpeed, so performance is
5730 if (hw->smart_speed == e1000_smart_speed_on) {
5731 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5736 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5737 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5741 } else if (hw->smart_speed == e1000_smart_speed_off) {
5742 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5747 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5748 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5754 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5755 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5756 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5758 if(hw->mac_type == e1000_82541_rev_2 ||
5759 hw->mac_type == e1000_82547_rev_2) {
5760 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5761 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5765 phy_data |= IGP02E1000_PM_D3_LPLU;
5766 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5772 /* When LPLU is enabled we should disable SmartSpeed */
5773 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5777 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5778 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5783 return E1000_SUCCESS;
5786 /*****************************************************************************
5788 * This function sets the lplu d0 state according to the active flag. When
5789 * activating lplu this function also disables smart speed and vise versa.
5790 * lplu will not be activated unless the device autonegotiation advertisment
5791 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5792 * hw: Struct containing variables accessed by shared code
5793 * active - true to enable lplu false to disable lplu.
5795 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5796 * E1000_SUCCESS at any other case.
5798 ****************************************************************************/
5801 e1000_set_d0_lplu_state(struct e1000_hw *hw,
5806 DEBUGFUNC("e1000_set_d0_lplu_state");
5808 if(hw->mac_type <= e1000_82547_rev_2)
5809 return E1000_SUCCESS;
5811 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5816 phy_data &= ~IGP02E1000_PM_D0_LPLU;
5817 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
5821 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5822 * Dx states where the power conservation is most important. During
5823 * driver activity we should enable SmartSpeed, so performance is
5825 if (hw->smart_speed == e1000_smart_speed_on) {
5826 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5831 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5832 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5836 } else if (hw->smart_speed == e1000_smart_speed_off) {
5837 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5842 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5843 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5852 phy_data |= IGP02E1000_PM_D0_LPLU;
5853 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
5857 /* When LPLU is enabled we should disable SmartSpeed */
5858 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5862 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5863 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5868 return E1000_SUCCESS;
5871 /******************************************************************************
5872 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5874 * hw - Struct containing variables accessed by shared code
5875 *****************************************************************************/
5877 e1000_set_vco_speed(struct e1000_hw *hw)
5880 uint16_t default_page = 0;
5883 DEBUGFUNC("e1000_set_vco_speed");
5885 switch(hw->mac_type) {
5886 case e1000_82545_rev_3:
5887 case e1000_82546_rev_3:
5890 return E1000_SUCCESS;
5893 /* Set PHY register 30, page 5, bit 8 to 0 */
5895 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5899 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5903 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5907 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5908 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5912 /* Set PHY register 30, page 4, bit 11 to 1 */
5914 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5918 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5922 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5923 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5927 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5931 return E1000_SUCCESS;
5935 /*****************************************************************************
5936 * This function reads the cookie from ARC ram.
5938 * returns: - E1000_SUCCESS .
5939 ****************************************************************************/
5941 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
5944 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
5945 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
5947 length = (length >> 2);
5948 offset = (offset >> 2);
5950 for (i = 0; i < length; i++) {
5951 *((uint32_t *) buffer + i) =
5952 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
5954 return E1000_SUCCESS;
5958 /*****************************************************************************
5959 * This function checks whether the HOST IF is enabled for command operaton
5960 * and also checks whether the previous command is completed.
5961 * It busy waits in case of previous command is not completed.
5963 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
5965 * - E1000_SUCCESS for success.
5966 ****************************************************************************/
5968 e1000_mng_enable_host_if(struct e1000_hw * hw)
5973 /* Check that the host interface is enabled. */
5974 hicr = E1000_READ_REG(hw, HICR);
5975 if ((hicr & E1000_HICR_EN) == 0) {
5976 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
5977 return -E1000_ERR_HOST_INTERFACE_COMMAND;
5979 /* check the previous command is completed */
5980 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
5981 hicr = E1000_READ_REG(hw, HICR);
5982 if (!(hicr & E1000_HICR_C))
5987 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
5988 DEBUGOUT("Previous command timeout failed .\n");
5989 return -E1000_ERR_HOST_INTERFACE_COMMAND;
5991 return E1000_SUCCESS;
5994 /*****************************************************************************
5995 * This function writes the buffer content at the offset given on the host if.
5996 * It also does alignment considerations to do the writes in most efficient way.
5997 * Also fills up the sum of the buffer in *buffer parameter.
5999 * returns - E1000_SUCCESS for success.
6000 ****************************************************************************/
6002 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6003 uint16_t length, uint16_t offset, uint8_t *sum)
6006 uint8_t *bufptr = buffer;
6008 uint16_t remaining, i, j, prev_bytes;
6010 /* sum = only sum of the data and it is not checksum */
6012 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6013 return -E1000_ERR_PARAM;
6016 tmp = (uint8_t *)&data;
6017 prev_bytes = offset & 0x3;
6022 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6023 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6024 *(tmp + j) = *bufptr++;
6027 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6028 length -= j - prev_bytes;
6032 remaining = length & 0x3;
6033 length -= remaining;
6035 /* Calculate length in DWORDs */
6038 /* The device driver writes the relevant command block into the
6040 for (i = 0; i < length; i++) {
6041 for (j = 0; j < sizeof(uint32_t); j++) {
6042 *(tmp + j) = *bufptr++;
6046 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6049 for (j = 0; j < sizeof(uint32_t); j++) {
6051 *(tmp + j) = *bufptr++;
6057 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6060 return E1000_SUCCESS;
6064 /*****************************************************************************
6065 * This function writes the command header after does the checksum calculation.
6067 * returns - E1000_SUCCESS for success.
6068 ****************************************************************************/
6070 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6071 struct e1000_host_mng_command_header * hdr)
6077 /* Write the whole command header structure which includes sum of
6080 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6082 sum = hdr->checksum;
6085 buffer = (uint8_t *) hdr;
6090 hdr->checksum = 0 - sum;
6093 /* The device driver writes the relevant command block into the ram area. */
6094 for (i = 0; i < length; i++)
6095 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6097 return E1000_SUCCESS;
6101 /*****************************************************************************
6102 * This function indicates to ARC that a new command is pending which completes
6103 * one write operation by the driver.
6105 * returns - E1000_SUCCESS for success.
6106 ****************************************************************************/
6108 e1000_mng_write_commit(
6109 struct e1000_hw * hw)
6113 hicr = E1000_READ_REG(hw, HICR);
6114 /* Setting this bit tells the ARC that a new command is pending. */
6115 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6117 return E1000_SUCCESS;
6121 /*****************************************************************************
6122 * This function checks the mode of the firmware.
6124 * returns - TRUE when the mode is IAMT or FALSE.
6125 ****************************************************************************/
6127 e1000_check_mng_mode(
6128 struct e1000_hw *hw)
6132 fwsm = E1000_READ_REG(hw, FWSM);
6134 if((fwsm & E1000_FWSM_MODE_MASK) ==
6135 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6142 /*****************************************************************************
6143 * This function writes the dhcp info .
6144 ****************************************************************************/
6146 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
6150 struct e1000_host_mng_command_header hdr;
6152 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6153 hdr.command_length = length;
6158 ret_val = e1000_mng_enable_host_if(hw);
6159 if (ret_val == E1000_SUCCESS) {
6160 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6162 if (ret_val == E1000_SUCCESS) {
6163 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
6164 if (ret_val == E1000_SUCCESS)
6165 ret_val = e1000_mng_write_commit(hw);
6172 /*****************************************************************************
6173 * This function calculates the checksum.
6175 * returns - checksum of buffer contents.
6176 ****************************************************************************/
6178 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
6186 for (i=0; i < length; i++)
6189 return (uint8_t) (0 - sum);
6192 /*****************************************************************************
6193 * This function checks whether tx pkt filtering needs to be enabled or not.
6195 * returns - TRUE for packet filtering or FALSE.
6196 ****************************************************************************/
6198 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
6200 /* called in init as well as watchdog timer functions */
6202 int32_t ret_val, checksum;
6203 boolean_t tx_filter = FALSE;
6204 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
6205 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
6207 if (e1000_check_mng_mode(hw)) {
6208 ret_val = e1000_mng_enable_host_if(hw);
6209 if (ret_val == E1000_SUCCESS) {
6210 ret_val = e1000_host_if_read_cookie(hw, buffer);
6211 if (ret_val == E1000_SUCCESS) {
6212 checksum = hdr->checksum;
6214 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
6215 checksum == e1000_calculate_mng_checksum((char *)buffer,
6216 E1000_MNG_DHCP_COOKIE_LENGTH)) {
6218 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
6227 hw->tx_pkt_filtering = tx_filter;
6231 /******************************************************************************
6232 * Verifies the hardware needs to allow ARPs to be processed by the host
6234 * hw - Struct containing variables accessed by shared code
6236 * returns: - TRUE/FALSE
6238 *****************************************************************************/
6240 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
6243 uint32_t fwsm, factps;
6245 if (hw->asf_firmware_present) {
6246 manc = E1000_READ_REG(hw, MANC);
6248 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
6249 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
6251 if (e1000_arc_subsystem_valid(hw) == TRUE) {
6252 fwsm = E1000_READ_REG(hw, FWSM);
6253 factps = E1000_READ_REG(hw, FACTPS);
6255 if (((fwsm & E1000_FWSM_MODE_MASK) ==
6256 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
6257 (factps & E1000_FACTPS_MNGCG))
6260 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
6267 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
6270 uint16_t mii_status_reg;
6273 /* Polarity reversal workaround for forced 10F/10H links. */
6275 /* Disable the transmitter on the PHY */
6277 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6280 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
6284 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6288 /* This loop will early-out if the NO link condition has been met. */
6289 for(i = PHY_FORCE_TIME; i > 0; i--) {
6290 /* Read the MII Status Register and wait for Link Status bit
6294 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6298 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6302 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
6303 msec_delay_irq(100);
6306 /* Recommended delay time after link has been lost */
6307 msec_delay_irq(1000);
6309 /* Now we will re-enable th transmitter on the PHY */
6311 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6315 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
6319 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
6323 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
6327 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6331 /* This loop will early-out if the link condition has been met. */
6332 for(i = PHY_FORCE_TIME; i > 0; i--) {
6333 /* Read the MII Status Register and wait for Link Status bit
6337 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6341 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6345 if(mii_status_reg & MII_SR_LINK_STATUS) break;
6346 msec_delay_irq(100);
6348 return E1000_SUCCESS;
6351 /***************************************************************************
6353 * Disables PCI-Express master access.
6355 * hw: Struct containing variables accessed by shared code
6359 ***************************************************************************/
6361 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
6365 DEBUGFUNC("e1000_set_pci_express_master_disable");
6367 if (hw->bus_type != e1000_bus_type_pci_express)
6370 ctrl = E1000_READ_REG(hw, CTRL);
6371 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
6372 E1000_WRITE_REG(hw, CTRL, ctrl);
6375 /***************************************************************************
6377 * Enables PCI-Express master access.
6379 * hw: Struct containing variables accessed by shared code
6383 ***************************************************************************/
6385 e1000_enable_pciex_master(struct e1000_hw *hw)
6389 DEBUGFUNC("e1000_enable_pciex_master");
6391 if (hw->bus_type != e1000_bus_type_pci_express)
6394 ctrl = E1000_READ_REG(hw, CTRL);
6395 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
6396 E1000_WRITE_REG(hw, CTRL, ctrl);
6399 /*******************************************************************************
6401 * Disables PCI-Express master access and verifies there are no pending requests
6403 * hw: Struct containing variables accessed by shared code
6405 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
6406 * caused the master requests to be disabled.
6407 * E1000_SUCCESS master requests disabled.
6409 ******************************************************************************/
6411 e1000_disable_pciex_master(struct e1000_hw *hw)
6413 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
6415 DEBUGFUNC("e1000_disable_pciex_master");
6417 if (hw->bus_type != e1000_bus_type_pci_express)
6418 return E1000_SUCCESS;
6420 e1000_set_pci_express_master_disable(hw);
6423 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
6431 DEBUGOUT("Master requests are pending.\n");
6432 return -E1000_ERR_MASTER_REQUESTS_PENDING;
6435 return E1000_SUCCESS;
6438 /*******************************************************************************
6440 * Check for EEPROM Auto Read bit done.
6442 * hw: Struct containing variables accessed by shared code
6444 * returns: - E1000_ERR_RESET if fail to reset MAC
6445 * E1000_SUCCESS at any other case.
6447 ******************************************************************************/
6449 e1000_get_auto_rd_done(struct e1000_hw *hw)
6451 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
6453 DEBUGFUNC("e1000_get_auto_rd_done");
6455 switch (hw->mac_type) {
6461 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
6467 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
6468 return -E1000_ERR_RESET;
6473 return E1000_SUCCESS;
6476 /***************************************************************************
6477 * Checks if the PHY configuration is done
6479 * hw: Struct containing variables accessed by shared code
6481 * returns: - E1000_ERR_RESET if fail to reset MAC
6482 * E1000_SUCCESS at any other case.
6484 ***************************************************************************/
6486 e1000_get_phy_cfg_done(struct e1000_hw *hw)
6488 DEBUGFUNC("e1000_get_phy_cfg_done");
6490 /* Simply wait for 10ms */
6493 return E1000_SUCCESS;
6496 /***************************************************************************
6498 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
6499 * adapter or Eeprom access.
6501 * hw: Struct containing variables accessed by shared code
6503 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
6504 * E1000_SUCCESS at any other case.
6506 ***************************************************************************/
6508 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
6513 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
6515 if(!hw->eeprom_semaphore_present)
6516 return E1000_SUCCESS;
6519 /* Get the FW semaphore. */
6520 timeout = hw->eeprom.word_size + 1;
6522 swsm = E1000_READ_REG(hw, SWSM);
6523 swsm |= E1000_SWSM_SWESMBI;
6524 E1000_WRITE_REG(hw, SWSM, swsm);
6525 /* if we managed to set the bit we got the semaphore. */
6526 swsm = E1000_READ_REG(hw, SWSM);
6527 if(swsm & E1000_SWSM_SWESMBI)
6535 /* Release semaphores */
6536 e1000_put_hw_eeprom_semaphore(hw);
6537 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
6538 return -E1000_ERR_EEPROM;
6541 return E1000_SUCCESS;
6544 /***************************************************************************
6545 * This function clears HW semaphore bits.
6547 * hw: Struct containing variables accessed by shared code
6551 ***************************************************************************/
6553 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
6557 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
6559 if(!hw->eeprom_semaphore_present)
6562 swsm = E1000_READ_REG(hw, SWSM);
6563 /* Release both semaphores. */
6564 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
6565 E1000_WRITE_REG(hw, SWSM, swsm);
6568 /******************************************************************************
6569 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
6570 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
6571 * the caller to figure out how to deal with it.
6573 * hw - Struct containing variables accessed by shared code
6575 * returns: - E1000_BLK_PHY_RESET
6578 *****************************************************************************/
6580 e1000_check_phy_reset_block(struct e1000_hw *hw)
6583 if(hw->mac_type > e1000_82547_rev_2)
6584 manc = E1000_READ_REG(hw, MANC);
6585 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
6586 E1000_BLK_PHY_RESET : E1000_SUCCESS;
6590 e1000_arc_subsystem_valid(struct e1000_hw *hw)
6594 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
6595 * may not be provided a DMA clock when no manageability features are
6596 * enabled. We do not want to perform any reads/writes to these registers
6597 * if this is the case. We read FWSM to determine the manageability mode.
6599 switch (hw->mac_type) {
6601 fwsm = E1000_READ_REG(hw, FWSM);
6602 if((fwsm & E1000_FWSM_MODE_MASK) != 0)