1 /*******************************************************************************
4 Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
67 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
69 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
70 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
72 /* IGP cable length table */
74 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
75 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
76 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
77 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
78 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
79 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
80 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
81 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
82 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
85 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
86 { 8, 13, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43,
87 22, 24, 27, 30, 32, 35, 37, 40, 42, 44, 47, 49, 51, 54, 56, 58,
88 32, 35, 38, 41, 44, 47, 50, 53, 55, 58, 61, 63, 66, 69, 71, 74,
89 43, 47, 51, 54, 58, 61, 64, 67, 71, 74, 77, 80, 82, 85, 88, 90,
90 57, 62, 66, 70, 74, 77, 81, 85, 88, 91, 94, 97, 100, 103, 106, 108,
91 73, 78, 82, 87, 91, 95, 98, 102, 105, 109, 112, 114, 117, 119, 122, 124,
92 91, 96, 101, 105, 109, 113, 116, 119, 122, 125, 127, 128, 128, 128, 128, 128,
93 108, 113, 117, 121, 124, 127, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128};
96 /******************************************************************************
97 * Set the phy type member in the hw struct.
99 * hw - Struct containing variables accessed by shared code
100 *****************************************************************************/
102 e1000_set_phy_type(struct e1000_hw *hw)
104 DEBUGFUNC("e1000_set_phy_type");
106 if(hw->mac_type == e1000_undefined)
107 return -E1000_ERR_PHY_TYPE;
110 case M88E1000_E_PHY_ID:
111 case M88E1000_I_PHY_ID:
112 case M88E1011_I_PHY_ID:
113 case M88E1111_I_PHY_ID:
114 hw->phy_type = e1000_phy_m88;
116 case IGP01E1000_I_PHY_ID:
117 if(hw->mac_type == e1000_82541 ||
118 hw->mac_type == e1000_82541_rev_2 ||
119 hw->mac_type == e1000_82547 ||
120 hw->mac_type == e1000_82547_rev_2) {
121 hw->phy_type = e1000_phy_igp;
126 /* Should never have loaded on this device */
127 hw->phy_type = e1000_phy_undefined;
128 return -E1000_ERR_PHY_TYPE;
131 return E1000_SUCCESS;
134 /******************************************************************************
135 * IGP phy init script - initializes the GbE PHY
137 * hw - Struct containing variables accessed by shared code
138 *****************************************************************************/
140 e1000_phy_init_script(struct e1000_hw *hw)
143 uint16_t phy_saved_data;
145 DEBUGFUNC("e1000_phy_init_script");
148 if(hw->phy_init_script) {
151 /* Save off the current value of register 0x2F5B to be restored at
152 * the end of this routine. */
153 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
155 /* Disabled the PHY transmitter */
156 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
160 e1000_write_phy_reg(hw,0x0000,0x0140);
164 switch(hw->mac_type) {
167 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
169 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
171 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
173 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
175 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
177 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
179 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
181 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
183 e1000_write_phy_reg(hw, 0x2010, 0x0008);
186 case e1000_82541_rev_2:
187 case e1000_82547_rev_2:
188 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
194 e1000_write_phy_reg(hw, 0x0000, 0x3300);
198 /* Now enable the transmitter */
199 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
201 if(hw->mac_type == e1000_82547) {
202 uint16_t fused, fine, coarse;
204 /* Move to analog registers page */
205 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
207 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
208 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
210 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
211 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
213 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
214 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
215 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
216 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
217 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
219 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
220 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
221 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
223 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
224 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
225 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
231 /******************************************************************************
232 * Set the mac type member in the hw struct.
234 * hw - Struct containing variables accessed by shared code
235 *****************************************************************************/
237 e1000_set_mac_type(struct e1000_hw *hw)
239 DEBUGFUNC("e1000_set_mac_type");
241 switch (hw->device_id) {
242 case E1000_DEV_ID_82542:
243 switch (hw->revision_id) {
244 case E1000_82542_2_0_REV_ID:
245 hw->mac_type = e1000_82542_rev2_0;
247 case E1000_82542_2_1_REV_ID:
248 hw->mac_type = e1000_82542_rev2_1;
251 /* Invalid 82542 revision ID */
252 return -E1000_ERR_MAC_TYPE;
255 case E1000_DEV_ID_82543GC_FIBER:
256 case E1000_DEV_ID_82543GC_COPPER:
257 hw->mac_type = e1000_82543;
259 case E1000_DEV_ID_82544EI_COPPER:
260 case E1000_DEV_ID_82544EI_FIBER:
261 case E1000_DEV_ID_82544GC_COPPER:
262 case E1000_DEV_ID_82544GC_LOM:
263 hw->mac_type = e1000_82544;
265 case E1000_DEV_ID_82540EM:
266 case E1000_DEV_ID_82540EM_LOM:
267 case E1000_DEV_ID_82540EP:
268 case E1000_DEV_ID_82540EP_LOM:
269 case E1000_DEV_ID_82540EP_LP:
270 hw->mac_type = e1000_82540;
272 case E1000_DEV_ID_82545EM_COPPER:
273 case E1000_DEV_ID_82545EM_FIBER:
274 hw->mac_type = e1000_82545;
276 case E1000_DEV_ID_82545GM_COPPER:
277 case E1000_DEV_ID_82545GM_FIBER:
278 case E1000_DEV_ID_82545GM_SERDES:
279 hw->mac_type = e1000_82545_rev_3;
281 case E1000_DEV_ID_82546EB_COPPER:
282 case E1000_DEV_ID_82546EB_FIBER:
283 case E1000_DEV_ID_82546EB_QUAD_COPPER:
284 hw->mac_type = e1000_82546;
286 case E1000_DEV_ID_82546GB_COPPER:
287 case E1000_DEV_ID_82546GB_FIBER:
288 case E1000_DEV_ID_82546GB_SERDES:
289 case E1000_DEV_ID_82546GB_PCIE:
290 case E1000_DEV_ID_82546GB_QUAD_COPPER:
291 hw->mac_type = e1000_82546_rev_3;
293 case E1000_DEV_ID_82541EI:
294 case E1000_DEV_ID_82541EI_MOBILE:
295 hw->mac_type = e1000_82541;
297 case E1000_DEV_ID_82541ER:
298 case E1000_DEV_ID_82541GI:
299 case E1000_DEV_ID_82541GI_LF:
300 case E1000_DEV_ID_82541GI_MOBILE:
301 hw->mac_type = e1000_82541_rev_2;
303 case E1000_DEV_ID_82547EI:
304 hw->mac_type = e1000_82547;
306 case E1000_DEV_ID_82547GI:
307 hw->mac_type = e1000_82547_rev_2;
309 case E1000_DEV_ID_82573E:
310 case E1000_DEV_ID_82573E_IAMT:
311 hw->mac_type = e1000_82573;
314 /* Should never have loaded on this device */
315 return -E1000_ERR_MAC_TYPE;
318 switch(hw->mac_type) {
320 hw->eeprom_semaphore_present = TRUE;
324 case e1000_82541_rev_2:
325 case e1000_82547_rev_2:
326 hw->asf_firmware_present = TRUE;
332 return E1000_SUCCESS;
335 /*****************************************************************************
336 * Set media type and TBI compatibility.
338 * hw - Struct containing variables accessed by shared code
339 * **************************************************************************/
341 e1000_set_media_type(struct e1000_hw *hw)
345 DEBUGFUNC("e1000_set_media_type");
347 if(hw->mac_type != e1000_82543) {
348 /* tbi_compatibility is only valid on 82543 */
349 hw->tbi_compatibility_en = FALSE;
352 switch (hw->device_id) {
353 case E1000_DEV_ID_82545GM_SERDES:
354 case E1000_DEV_ID_82546GB_SERDES:
355 hw->media_type = e1000_media_type_internal_serdes;
358 if(hw->mac_type >= e1000_82543) {
359 status = E1000_READ_REG(hw, STATUS);
360 if(status & E1000_STATUS_TBIMODE) {
361 hw->media_type = e1000_media_type_fiber;
362 /* tbi_compatibility not valid on fiber */
363 hw->tbi_compatibility_en = FALSE;
365 hw->media_type = e1000_media_type_copper;
368 /* This is an 82542 (fiber only) */
369 hw->media_type = e1000_media_type_fiber;
374 /******************************************************************************
375 * Reset the transmit and receive units; mask and clear all interrupts.
377 * hw - Struct containing variables accessed by shared code
378 *****************************************************************************/
380 e1000_reset_hw(struct e1000_hw *hw)
388 uint32_t extcnf_ctrl;
391 DEBUGFUNC("e1000_reset_hw");
393 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
394 if(hw->mac_type == e1000_82542_rev2_0) {
395 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
396 e1000_pci_clear_mwi(hw);
399 if(hw->bus_type == e1000_bus_type_pci_express) {
400 /* Prevent the PCI-E bus from sticking if there is no TLP connection
401 * on the last TLP read/write transaction when MAC is reset.
403 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
404 DEBUGOUT("PCI-E Master disable polling has failed.\n");
408 /* Clear interrupt mask to stop board from generating interrupts */
409 DEBUGOUT("Masking off all interrupts\n");
410 E1000_WRITE_REG(hw, IMC, 0xffffffff);
412 /* Disable the Transmit and Receive units. Then delay to allow
413 * any pending transactions to complete before we hit the MAC with
416 E1000_WRITE_REG(hw, RCTL, 0);
417 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
418 E1000_WRITE_FLUSH(hw);
420 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
421 hw->tbi_compatibility_on = FALSE;
423 /* Delay to allow any outstanding PCI transactions to complete before
424 * resetting the device
428 ctrl = E1000_READ_REG(hw, CTRL);
430 /* Must reset the PHY before resetting the MAC */
431 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
432 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
436 /* Must acquire the MDIO ownership before MAC reset.
437 * Ownership defaults to firmware after a reset. */
438 if(hw->mac_type == e1000_82573) {
441 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
442 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
445 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
446 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
448 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
451 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
458 /* Issue a global reset to the MAC. This will reset the chip's
459 * transmit, receive, DMA, and link units. It will not effect
460 * the current PCI configuration. The global reset bit is self-
461 * clearing, and should clear within a microsecond.
463 DEBUGOUT("Issuing a global reset to MAC\n");
465 switch(hw->mac_type) {
471 case e1000_82541_rev_2:
472 /* These controllers can't ack the 64-bit write when issuing the
473 * reset, so use IO-mapping as a workaround to issue the reset */
474 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
476 case e1000_82545_rev_3:
477 case e1000_82546_rev_3:
478 /* Reset is performed on a shadow of the control register */
479 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
482 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
486 /* After MAC reset, force reload of EEPROM to restore power-on settings to
487 * device. Later controllers reload the EEPROM automatically, so just wait
488 * for reload to complete.
490 switch(hw->mac_type) {
491 case e1000_82542_rev2_0:
492 case e1000_82542_rev2_1:
495 /* Wait for reset to complete */
497 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
498 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
499 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
500 E1000_WRITE_FLUSH(hw);
501 /* Wait for EEPROM reload */
505 case e1000_82541_rev_2:
507 case e1000_82547_rev_2:
508 /* Wait for EEPROM reload */
513 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
514 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
515 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
516 E1000_WRITE_FLUSH(hw);
518 ret_val = e1000_get_auto_rd_done(hw);
520 /* We don't want to continue accessing MAC registers. */
524 /* Wait for EEPROM reload (it happens automatically) */
529 /* Disable HW ARPs on ASF enabled adapters */
530 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
531 manc = E1000_READ_REG(hw, MANC);
532 manc &= ~(E1000_MANC_ARP_EN);
533 E1000_WRITE_REG(hw, MANC, manc);
536 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
537 e1000_phy_init_script(hw);
539 /* Configure activity LED after PHY reset */
540 led_ctrl = E1000_READ_REG(hw, LEDCTL);
541 led_ctrl &= IGP_ACTIVITY_LED_MASK;
542 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
543 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
546 /* Clear interrupt mask to stop board from generating interrupts */
547 DEBUGOUT("Masking off all interrupts\n");
548 E1000_WRITE_REG(hw, IMC, 0xffffffff);
550 /* Clear any pending interrupt events. */
551 icr = E1000_READ_REG(hw, ICR);
553 /* If MWI was previously enabled, reenable it. */
554 if(hw->mac_type == e1000_82542_rev2_0) {
555 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
556 e1000_pci_set_mwi(hw);
559 return E1000_SUCCESS;
562 /******************************************************************************
563 * Performs basic configuration of the adapter.
565 * hw - Struct containing variables accessed by shared code
567 * Assumes that the controller has previously been reset and is in a
568 * post-reset uninitialized state. Initializes the receive address registers,
569 * multicast table, and VLAN filter table. Calls routines to setup link
570 * configuration and flow control settings. Clears all on-chip counters. Leaves
571 * the transmit and receive units disabled and uninitialized.
572 *****************************************************************************/
574 e1000_init_hw(struct e1000_hw *hw)
579 uint16_t pcix_cmd_word;
580 uint16_t pcix_stat_hi_word;
585 DEBUGFUNC("e1000_init_hw");
587 /* Initialize Identification LED */
588 ret_val = e1000_id_led_init(hw);
590 DEBUGOUT("Error Initializing Identification LED\n");
594 /* Set the media type and TBI compatibility */
595 e1000_set_media_type(hw);
597 /* Disabling VLAN filtering. */
598 DEBUGOUT("Initializing the IEEE VLAN\n");
599 if (hw->mac_type < e1000_82545_rev_3)
600 E1000_WRITE_REG(hw, VET, 0);
601 e1000_clear_vfta(hw);
603 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
604 if(hw->mac_type == e1000_82542_rev2_0) {
605 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
606 e1000_pci_clear_mwi(hw);
607 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
608 E1000_WRITE_FLUSH(hw);
612 /* Setup the receive address. This involves initializing all of the Receive
613 * Address Registers (RARs 0 - 15).
615 e1000_init_rx_addrs(hw);
617 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
618 if(hw->mac_type == e1000_82542_rev2_0) {
619 E1000_WRITE_REG(hw, RCTL, 0);
620 E1000_WRITE_FLUSH(hw);
622 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
623 e1000_pci_set_mwi(hw);
626 /* Zero out the Multicast HASH table */
627 DEBUGOUT("Zeroing the MTA\n");
628 mta_size = E1000_MC_TBL_SIZE;
629 for(i = 0; i < mta_size; i++)
630 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
632 /* Set the PCI priority bit correctly in the CTRL register. This
633 * determines if the adapter gives priority to receives, or if it
634 * gives equal priority to transmits and receives. Valid only on
635 * 82542 and 82543 silicon.
637 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
638 ctrl = E1000_READ_REG(hw, CTRL);
639 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
642 switch(hw->mac_type) {
643 case e1000_82545_rev_3:
644 case e1000_82546_rev_3:
647 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
648 if(hw->bus_type == e1000_bus_type_pcix) {
649 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
650 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
652 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
653 PCIX_COMMAND_MMRBC_SHIFT;
654 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
655 PCIX_STATUS_HI_MMRBC_SHIFT;
656 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
657 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
658 if(cmd_mmrbc > stat_mmrbc) {
659 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
660 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
661 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
668 /* Call a subroutine to configure the link and setup flow control. */
669 ret_val = e1000_setup_link(hw);
671 /* Set the transmit descriptor write-back policy */
672 if(hw->mac_type > e1000_82544) {
673 ctrl = E1000_READ_REG(hw, TXDCTL);
674 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
675 switch (hw->mac_type) {
679 ctrl |= E1000_TXDCTL_COUNT_DESC;
682 E1000_WRITE_REG(hw, TXDCTL, ctrl);
685 if (hw->mac_type == e1000_82573) {
686 e1000_enable_tx_pkt_filtering(hw);
690 /* Clear all of the statistics registers (clear on read). It is
691 * important that we do this after we have tried to establish link
692 * because the symbol error count will increment wildly if there
695 e1000_clear_hw_cntrs(hw);
700 /******************************************************************************
701 * Adjust SERDES output amplitude based on EEPROM setting.
703 * hw - Struct containing variables accessed by shared code.
704 *****************************************************************************/
706 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
708 uint16_t eeprom_data;
711 DEBUGFUNC("e1000_adjust_serdes_amplitude");
713 if(hw->media_type != e1000_media_type_internal_serdes)
714 return E1000_SUCCESS;
716 switch(hw->mac_type) {
717 case e1000_82545_rev_3:
718 case e1000_82546_rev_3:
721 return E1000_SUCCESS;
724 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
729 if(eeprom_data != EEPROM_RESERVED_WORD) {
730 /* Adjust SERDES output amplitude only. */
731 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
732 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
737 return E1000_SUCCESS;
740 /******************************************************************************
741 * Configures flow control and link settings.
743 * hw - Struct containing variables accessed by shared code
745 * Determines which flow control settings to use. Calls the apropriate media-
746 * specific link configuration function. Configures the flow control settings.
747 * Assuming the adapter has a valid link partner, a valid link should be
748 * established. Assumes the hardware has previously been reset and the
749 * transmitter and receiver are not enabled.
750 *****************************************************************************/
752 e1000_setup_link(struct e1000_hw *hw)
756 uint16_t eeprom_data;
758 DEBUGFUNC("e1000_setup_link");
760 /* Read and store word 0x0F of the EEPROM. This word contains bits
761 * that determine the hardware's default PAUSE (flow control) mode,
762 * a bit that determines whether the HW defaults to enabling or
763 * disabling auto-negotiation, and the direction of the
764 * SW defined pins. If there is no SW over-ride of the flow
765 * control setting, then the variable hw->fc will
766 * be initialized based on a value in the EEPROM.
768 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data)) {
769 DEBUGOUT("EEPROM Read Error\n");
770 return -E1000_ERR_EEPROM;
773 if(hw->fc == e1000_fc_default) {
774 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
775 hw->fc = e1000_fc_none;
776 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
777 EEPROM_WORD0F_ASM_DIR)
778 hw->fc = e1000_fc_tx_pause;
780 hw->fc = e1000_fc_full;
783 /* We want to save off the original Flow Control configuration just
784 * in case we get disconnected and then reconnected into a different
785 * hub or switch with different Flow Control capabilities.
787 if(hw->mac_type == e1000_82542_rev2_0)
788 hw->fc &= (~e1000_fc_tx_pause);
790 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
791 hw->fc &= (~e1000_fc_rx_pause);
793 hw->original_fc = hw->fc;
795 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
797 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
798 * polarity value for the SW controlled pins, and setup the
799 * Extended Device Control reg with that info.
800 * This is needed because one of the SW controlled pins is used for
801 * signal detection. So this should be done before e1000_setup_pcs_link()
802 * or e1000_phy_setup() is called.
804 if(hw->mac_type == e1000_82543) {
805 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
807 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
810 /* Call the necessary subroutine to configure the link. */
811 ret_val = (hw->media_type == e1000_media_type_copper) ?
812 e1000_setup_copper_link(hw) :
813 e1000_setup_fiber_serdes_link(hw);
815 /* Initialize the flow control address, type, and PAUSE timer
816 * registers to their default values. This is done even if flow
817 * control is disabled, because it does not hurt anything to
818 * initialize these registers.
820 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
822 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
823 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
824 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
826 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
828 /* Set the flow control receive threshold registers. Normally,
829 * these registers will be set to a default threshold that may be
830 * adjusted later by the driver's runtime code. However, if the
831 * ability to transmit pause frames in not enabled, then these
832 * registers will be set to 0.
834 if(!(hw->fc & e1000_fc_tx_pause)) {
835 E1000_WRITE_REG(hw, FCRTL, 0);
836 E1000_WRITE_REG(hw, FCRTH, 0);
838 /* We need to set up the Receive Threshold high and low water marks
839 * as well as (optionally) enabling the transmission of XON frames.
841 if(hw->fc_send_xon) {
842 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
843 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
845 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
846 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
852 /******************************************************************************
853 * Sets up link for a fiber based or serdes based adapter
855 * hw - Struct containing variables accessed by shared code
857 * Manipulates Physical Coding Sublayer functions in order to configure
858 * link. Assumes the hardware has been previously reset and the transmitter
859 * and receiver are not enabled.
860 *****************************************************************************/
862 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
871 DEBUGFUNC("e1000_setup_fiber_serdes_link");
873 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
874 * set when the optics detect a signal. On older adapters, it will be
875 * cleared when there is a signal. This applies to fiber media only.
876 * If we're on serdes media, adjust the output amplitude to value set in
879 ctrl = E1000_READ_REG(hw, CTRL);
880 if(hw->media_type == e1000_media_type_fiber)
881 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
883 ret_val = e1000_adjust_serdes_amplitude(hw);
887 /* Take the link out of reset */
888 ctrl &= ~(E1000_CTRL_LRST);
890 /* Adjust VCO speed to improve BER performance */
891 ret_val = e1000_set_vco_speed(hw);
895 e1000_config_collision_dist(hw);
897 /* Check for a software override of the flow control settings, and setup
898 * the device accordingly. If auto-negotiation is enabled, then software
899 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
900 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
901 * auto-negotiation is disabled, then software will have to manually
902 * configure the two flow control enable bits in the CTRL register.
904 * The possible values of the "fc" parameter are:
905 * 0: Flow control is completely disabled
906 * 1: Rx flow control is enabled (we can receive pause frames, but
907 * not send pause frames).
908 * 2: Tx flow control is enabled (we can send pause frames but we do
909 * not support receiving pause frames).
910 * 3: Both Rx and TX flow control (symmetric) are enabled.
914 /* Flow control is completely disabled by a software over-ride. */
915 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
917 case e1000_fc_rx_pause:
918 /* RX Flow control is enabled and TX Flow control is disabled by a
919 * software over-ride. Since there really isn't a way to advertise
920 * that we are capable of RX Pause ONLY, we will advertise that we
921 * support both symmetric and asymmetric RX PAUSE. Later, we will
922 * disable the adapter's ability to send PAUSE frames.
924 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
926 case e1000_fc_tx_pause:
927 /* TX Flow control is enabled, and RX Flow control is disabled, by a
928 * software over-ride.
930 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
933 /* Flow control (both RX and TX) is enabled by a software over-ride. */
934 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
937 DEBUGOUT("Flow control param set incorrectly\n");
938 return -E1000_ERR_CONFIG;
942 /* Since auto-negotiation is enabled, take the link out of reset (the link
943 * will be in reset, because we previously reset the chip). This will
944 * restart auto-negotiation. If auto-neogtiation is successful then the
945 * link-up status bit will be set and the flow control enable bits (RFCE
946 * and TFCE) will be set according to their negotiated value.
948 DEBUGOUT("Auto-negotiation enabled\n");
950 E1000_WRITE_REG(hw, TXCW, txcw);
951 E1000_WRITE_REG(hw, CTRL, ctrl);
952 E1000_WRITE_FLUSH(hw);
957 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
958 * indication in the Device Status Register. Time-out if a link isn't
959 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
960 * less than 500 milliseconds even if the other end is doing it in SW).
961 * For internal serdes, we just assume a signal is present, then poll.
963 if(hw->media_type == e1000_media_type_internal_serdes ||
964 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
965 DEBUGOUT("Looking for Link\n");
966 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
968 status = E1000_READ_REG(hw, STATUS);
969 if(status & E1000_STATUS_LU) break;
971 if(i == (LINK_UP_TIMEOUT / 10)) {
972 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
973 hw->autoneg_failed = 1;
974 /* AutoNeg failed to achieve a link, so we'll call
975 * e1000_check_for_link. This routine will force the link up if
976 * we detect a signal. This will allow us to communicate with
977 * non-autonegotiating link partners.
979 ret_val = e1000_check_for_link(hw);
981 DEBUGOUT("Error while checking for link\n");
984 hw->autoneg_failed = 0;
986 hw->autoneg_failed = 0;
987 DEBUGOUT("Valid Link Found\n");
990 DEBUGOUT("No Signal Detected\n");
992 return E1000_SUCCESS;
995 /******************************************************************************
996 * Make sure we have a valid PHY and change PHY mode before link setup.
998 * hw - Struct containing variables accessed by shared code
999 ******************************************************************************/
1001 e1000_copper_link_preconfig(struct e1000_hw *hw)
1007 DEBUGFUNC("e1000_copper_link_preconfig");
1009 ctrl = E1000_READ_REG(hw, CTRL);
1010 /* With 82543, we need to force speed and duplex on the MAC equal to what
1011 * the PHY speed and duplex configuration is. In addition, we need to
1012 * perform a hardware reset on the PHY to take it out of reset.
1014 if(hw->mac_type > e1000_82543) {
1015 ctrl |= E1000_CTRL_SLU;
1016 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1017 E1000_WRITE_REG(hw, CTRL, ctrl);
1019 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1020 E1000_WRITE_REG(hw, CTRL, ctrl);
1021 ret_val = e1000_phy_hw_reset(hw);
1026 /* Make sure we have a valid PHY */
1027 ret_val = e1000_detect_gig_phy(hw);
1029 DEBUGOUT("Error, did not detect valid phy.\n");
1032 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1034 /* Set PHY to class A mode (if necessary) */
1035 ret_val = e1000_set_phy_mode(hw);
1039 if((hw->mac_type == e1000_82545_rev_3) ||
1040 (hw->mac_type == e1000_82546_rev_3)) {
1041 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1042 phy_data |= 0x00000008;
1043 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1046 if(hw->mac_type <= e1000_82543 ||
1047 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1048 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1049 hw->phy_reset_disable = FALSE;
1051 return E1000_SUCCESS;
1055 /********************************************************************
1056 * Copper link setup for e1000_phy_igp series.
1058 * hw - Struct containing variables accessed by shared code
1059 *********************************************************************/
1061 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1067 DEBUGFUNC("e1000_copper_link_igp_setup");
1069 if (hw->phy_reset_disable)
1070 return E1000_SUCCESS;
1072 ret_val = e1000_phy_reset(hw);
1074 DEBUGOUT("Error Resetting the PHY\n");
1078 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1081 /* Configure activity LED after PHY reset */
1082 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1083 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1084 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1085 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1087 /* disable lplu d3 during driver init */
1088 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1090 DEBUGOUT("Error Disabling LPLU D3\n");
1094 /* disable lplu d0 during driver init */
1095 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1097 DEBUGOUT("Error Disabling LPLU D0\n");
1100 /* Configure mdi-mdix settings */
1101 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1105 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1106 hw->dsp_config_state = e1000_dsp_config_disabled;
1107 /* Force MDI for earlier revs of the IGP PHY */
1108 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1112 hw->dsp_config_state = e1000_dsp_config_enabled;
1113 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1117 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1120 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1124 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1128 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1132 /* set auto-master slave resolution settings */
1134 e1000_ms_type phy_ms_setting = hw->master_slave;
1136 if(hw->ffe_config_state == e1000_ffe_config_active)
1137 hw->ffe_config_state = e1000_ffe_config_enabled;
1139 if(hw->dsp_config_state == e1000_dsp_config_activated)
1140 hw->dsp_config_state = e1000_dsp_config_enabled;
1142 /* when autonegotiation advertisment is only 1000Mbps then we
1143 * should disable SmartSpeed and enable Auto MasterSlave
1144 * resolution as hardware default. */
1145 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1146 /* Disable SmartSpeed */
1147 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1150 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1151 ret_val = e1000_write_phy_reg(hw,
1152 IGP01E1000_PHY_PORT_CONFIG,
1156 /* Set auto Master/Slave resolution process */
1157 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1160 phy_data &= ~CR_1000T_MS_ENABLE;
1161 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1166 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1170 /* load defaults for future use */
1171 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1172 ((phy_data & CR_1000T_MS_VALUE) ?
1173 e1000_ms_force_master :
1174 e1000_ms_force_slave) :
1177 switch (phy_ms_setting) {
1178 case e1000_ms_force_master:
1179 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1181 case e1000_ms_force_slave:
1182 phy_data |= CR_1000T_MS_ENABLE;
1183 phy_data &= ~(CR_1000T_MS_VALUE);
1186 phy_data &= ~CR_1000T_MS_ENABLE;
1190 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1195 return E1000_SUCCESS;
1199 /********************************************************************
1200 * Copper link setup for e1000_phy_m88 series.
1202 * hw - Struct containing variables accessed by shared code
1203 *********************************************************************/
1205 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1210 DEBUGFUNC("e1000_copper_link_mgp_setup");
1212 if(hw->phy_reset_disable)
1213 return E1000_SUCCESS;
1215 /* Enable CRS on TX. This must be set for half-duplex operation. */
1216 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1220 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1223 * MDI/MDI-X = 0 (default)
1224 * 0 - Auto for all speeds
1227 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1229 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1233 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1236 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1239 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1243 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1248 * disable_polarity_correction = 0 (default)
1249 * Automatic Correction for Reversed Cable Polarity
1253 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1254 if(hw->disable_polarity_correction == 1)
1255 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1256 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1260 /* Force TX_CLK in the Extended PHY Specific Control Register
1263 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1267 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1269 if (hw->phy_revision < M88E1011_I_REV_4) {
1270 /* Configure Master and Slave downshift values */
1271 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1272 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1273 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1274 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1275 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1280 /* SW Reset the PHY so all changes take effect */
1281 ret_val = e1000_phy_reset(hw);
1283 DEBUGOUT("Error Resetting the PHY\n");
1287 return E1000_SUCCESS;
1290 /********************************************************************
1291 * Setup auto-negotiation and flow control advertisements,
1292 * and then perform auto-negotiation.
1294 * hw - Struct containing variables accessed by shared code
1295 *********************************************************************/
1297 e1000_copper_link_autoneg(struct e1000_hw *hw)
1302 DEBUGFUNC("e1000_copper_link_autoneg");
1304 /* Perform some bounds checking on the hw->autoneg_advertised
1305 * parameter. If this variable is zero, then set it to the default.
1307 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1309 /* If autoneg_advertised is zero, we assume it was not defaulted
1310 * by the calling code so we set to advertise full capability.
1312 if(hw->autoneg_advertised == 0)
1313 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1315 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1316 ret_val = e1000_phy_setup_autoneg(hw);
1318 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1321 DEBUGOUT("Restarting Auto-Neg\n");
1323 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1324 * the Auto Neg Restart bit in the PHY control register.
1326 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1330 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1331 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1335 /* Does the user want to wait for Auto-Neg to complete here, or
1336 * check at a later time (for example, callback routine).
1338 if(hw->wait_autoneg_complete) {
1339 ret_val = e1000_wait_autoneg(hw);
1341 DEBUGOUT("Error while waiting for autoneg to complete\n");
1346 hw->get_link_status = TRUE;
1348 return E1000_SUCCESS;
1352 /******************************************************************************
1353 * Config the MAC and the PHY after link is up.
1354 * 1) Set up the MAC to the current PHY speed/duplex
1355 * if we are on 82543. If we
1356 * are on newer silicon, we only need to configure
1357 * collision distance in the Transmit Control Register.
1358 * 2) Set up flow control on the MAC to that established with
1360 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1362 * hw - Struct containing variables accessed by shared code
1363 ******************************************************************************/
1365 e1000_copper_link_postconfig(struct e1000_hw *hw)
1368 DEBUGFUNC("e1000_copper_link_postconfig");
1370 if(hw->mac_type >= e1000_82544) {
1371 e1000_config_collision_dist(hw);
1373 ret_val = e1000_config_mac_to_phy(hw);
1375 DEBUGOUT("Error configuring MAC to PHY settings\n");
1379 ret_val = e1000_config_fc_after_link_up(hw);
1381 DEBUGOUT("Error Configuring Flow Control\n");
1385 /* Config DSP to improve Giga link quality */
1386 if(hw->phy_type == e1000_phy_igp) {
1387 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1389 DEBUGOUT("Error Configuring DSP after link up\n");
1394 return E1000_SUCCESS;
1397 /******************************************************************************
1398 * Detects which PHY is present and setup the speed and duplex
1400 * hw - Struct containing variables accessed by shared code
1401 ******************************************************************************/
1403 e1000_setup_copper_link(struct e1000_hw *hw)
1409 DEBUGFUNC("e1000_setup_copper_link");
1411 /* Check if it is a valid PHY and set PHY mode if necessary. */
1412 ret_val = e1000_copper_link_preconfig(hw);
1416 if (hw->phy_type == e1000_phy_igp ||
1417 hw->phy_type == e1000_phy_igp_2) {
1418 ret_val = e1000_copper_link_igp_setup(hw);
1421 } else if (hw->phy_type == e1000_phy_m88) {
1422 ret_val = e1000_copper_link_mgp_setup(hw);
1428 /* Setup autoneg and flow control advertisement
1429 * and perform autonegotiation */
1430 ret_val = e1000_copper_link_autoneg(hw);
1434 /* PHY will be set to 10H, 10F, 100H,or 100F
1435 * depending on value from forced_speed_duplex. */
1436 DEBUGOUT("Forcing speed and duplex\n");
1437 ret_val = e1000_phy_force_speed_duplex(hw);
1439 DEBUGOUT("Error Forcing Speed and Duplex\n");
1444 /* Check link status. Wait up to 100 microseconds for link to become
1447 for(i = 0; i < 10; i++) {
1448 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1451 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1455 if(phy_data & MII_SR_LINK_STATUS) {
1456 /* Config the MAC and PHY after link is up */
1457 ret_val = e1000_copper_link_postconfig(hw);
1461 DEBUGOUT("Valid link established!!!\n");
1462 return E1000_SUCCESS;
1467 DEBUGOUT("Unable to establish link!!!\n");
1468 return E1000_SUCCESS;
1471 /******************************************************************************
1472 * Configures PHY autoneg and flow control advertisement settings
1474 * hw - Struct containing variables accessed by shared code
1475 ******************************************************************************/
1477 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1480 uint16_t mii_autoneg_adv_reg;
1481 uint16_t mii_1000t_ctrl_reg;
1483 DEBUGFUNC("e1000_phy_setup_autoneg");
1485 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1486 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1490 /* Read the MII 1000Base-T Control Register (Address 9). */
1491 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1495 /* Need to parse both autoneg_advertised and fc and set up
1496 * the appropriate PHY registers. First we will parse for
1497 * autoneg_advertised software override. Since we can advertise
1498 * a plethora of combinations, we need to check each bit
1502 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1503 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1504 * the 1000Base-T Control Register (Address 9).
1506 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1507 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1509 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1511 /* Do we want to advertise 10 Mb Half Duplex? */
1512 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1513 DEBUGOUT("Advertise 10mb Half duplex\n");
1514 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1517 /* Do we want to advertise 10 Mb Full Duplex? */
1518 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1519 DEBUGOUT("Advertise 10mb Full duplex\n");
1520 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1523 /* Do we want to advertise 100 Mb Half Duplex? */
1524 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1525 DEBUGOUT("Advertise 100mb Half duplex\n");
1526 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1529 /* Do we want to advertise 100 Mb Full Duplex? */
1530 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1531 DEBUGOUT("Advertise 100mb Full duplex\n");
1532 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1535 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1536 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1537 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1540 /* Do we want to advertise 1000 Mb Full Duplex? */
1541 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1542 DEBUGOUT("Advertise 1000mb Full duplex\n");
1543 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1546 /* Check for a software override of the flow control settings, and
1547 * setup the PHY advertisement registers accordingly. If
1548 * auto-negotiation is enabled, then software will have to set the
1549 * "PAUSE" bits to the correct value in the Auto-Negotiation
1550 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1552 * The possible values of the "fc" parameter are:
1553 * 0: Flow control is completely disabled
1554 * 1: Rx flow control is enabled (we can receive pause frames
1555 * but not send pause frames).
1556 * 2: Tx flow control is enabled (we can send pause frames
1557 * but we do not support receiving pause frames).
1558 * 3: Both Rx and TX flow control (symmetric) are enabled.
1559 * other: No software override. The flow control configuration
1560 * in the EEPROM is used.
1563 case e1000_fc_none: /* 0 */
1564 /* Flow control (RX & TX) is completely disabled by a
1565 * software over-ride.
1567 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1569 case e1000_fc_rx_pause: /* 1 */
1570 /* RX Flow control is enabled, and TX Flow control is
1571 * disabled, by a software over-ride.
1573 /* Since there really isn't a way to advertise that we are
1574 * capable of RX Pause ONLY, we will advertise that we
1575 * support both symmetric and asymmetric RX PAUSE. Later
1576 * (in e1000_config_fc_after_link_up) we will disable the
1577 *hw's ability to send PAUSE frames.
1579 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1581 case e1000_fc_tx_pause: /* 2 */
1582 /* TX Flow control is enabled, and RX Flow control is
1583 * disabled, by a software over-ride.
1585 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1586 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1588 case e1000_fc_full: /* 3 */
1589 /* Flow control (both RX and TX) is enabled by a software
1592 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1595 DEBUGOUT("Flow control param set incorrectly\n");
1596 return -E1000_ERR_CONFIG;
1599 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1603 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1605 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1609 return E1000_SUCCESS;
1612 /******************************************************************************
1613 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1615 * hw - Struct containing variables accessed by shared code
1616 ******************************************************************************/
1618 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1622 uint16_t mii_ctrl_reg;
1623 uint16_t mii_status_reg;
1627 DEBUGFUNC("e1000_phy_force_speed_duplex");
1629 /* Turn off Flow control if we are forcing speed and duplex. */
1630 hw->fc = e1000_fc_none;
1632 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1634 /* Read the Device Control Register. */
1635 ctrl = E1000_READ_REG(hw, CTRL);
1637 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1638 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1639 ctrl &= ~(DEVICE_SPEED_MASK);
1641 /* Clear the Auto Speed Detect Enable bit. */
1642 ctrl &= ~E1000_CTRL_ASDE;
1644 /* Read the MII Control Register. */
1645 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1649 /* We need to disable autoneg in order to force link and duplex. */
1651 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1653 /* Are we forcing Full or Half Duplex? */
1654 if(hw->forced_speed_duplex == e1000_100_full ||
1655 hw->forced_speed_duplex == e1000_10_full) {
1656 /* We want to force full duplex so we SET the full duplex bits in the
1657 * Device and MII Control Registers.
1659 ctrl |= E1000_CTRL_FD;
1660 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1661 DEBUGOUT("Full Duplex\n");
1663 /* We want to force half duplex so we CLEAR the full duplex bits in
1664 * the Device and MII Control Registers.
1666 ctrl &= ~E1000_CTRL_FD;
1667 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1668 DEBUGOUT("Half Duplex\n");
1671 /* Are we forcing 100Mbps??? */
1672 if(hw->forced_speed_duplex == e1000_100_full ||
1673 hw->forced_speed_duplex == e1000_100_half) {
1674 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1675 ctrl |= E1000_CTRL_SPD_100;
1676 mii_ctrl_reg |= MII_CR_SPEED_100;
1677 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1678 DEBUGOUT("Forcing 100mb ");
1680 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1681 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1682 mii_ctrl_reg |= MII_CR_SPEED_10;
1683 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1684 DEBUGOUT("Forcing 10mb ");
1687 e1000_config_collision_dist(hw);
1689 /* Write the configured values back to the Device Control Reg. */
1690 E1000_WRITE_REG(hw, CTRL, ctrl);
1692 if (hw->phy_type == e1000_phy_m88) {
1693 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1697 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1698 * forced whenever speed are duplex are forced.
1700 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1701 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1705 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1707 /* Need to reset the PHY or these changes will be ignored */
1708 mii_ctrl_reg |= MII_CR_RESET;
1710 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1711 * forced whenever speed or duplex are forced.
1713 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1717 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1718 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1720 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1725 /* Write back the modified PHY MII control register. */
1726 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1732 /* The wait_autoneg_complete flag may be a little misleading here.
1733 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1734 * But we do want to delay for a period while forcing only so we
1735 * don't generate false No Link messages. So we will wait here
1736 * only if the user has set wait_autoneg_complete to 1, which is
1739 if(hw->wait_autoneg_complete) {
1740 /* We will wait for autoneg to complete. */
1741 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1744 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1745 for(i = PHY_FORCE_TIME; i > 0; i--) {
1746 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1749 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1753 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1757 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1761 (hw->phy_type == e1000_phy_m88)) {
1762 /* We didn't get link. Reset the DSP and wait again for link. */
1763 ret_val = e1000_phy_reset_dsp(hw);
1765 DEBUGOUT("Error Resetting PHY DSP\n");
1769 /* This loop will early-out if the link condition has been met. */
1770 for(i = PHY_FORCE_TIME; i > 0; i--) {
1771 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1773 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1776 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1780 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1786 if (hw->phy_type == e1000_phy_m88) {
1787 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1788 * Extended PHY Specific Control Register to 25MHz clock. This value
1789 * defaults back to a 2.5MHz clock when the PHY is reset.
1791 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1795 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1796 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1800 /* In addition, because of the s/w reset above, we need to enable CRS on
1801 * TX. This must be set for both full and half duplex operation.
1803 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1807 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1808 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1812 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1814 (hw->forced_speed_duplex == e1000_10_full ||
1815 hw->forced_speed_duplex == e1000_10_half)) {
1816 ret_val = e1000_polarity_reversal_workaround(hw);
1821 return E1000_SUCCESS;
1824 /******************************************************************************
1825 * Sets the collision distance in the Transmit Control register
1827 * hw - Struct containing variables accessed by shared code
1829 * Link should have been established previously. Reads the speed and duplex
1830 * information from the Device Status register.
1831 ******************************************************************************/
1833 e1000_config_collision_dist(struct e1000_hw *hw)
1837 DEBUGFUNC("e1000_config_collision_dist");
1839 tctl = E1000_READ_REG(hw, TCTL);
1841 tctl &= ~E1000_TCTL_COLD;
1842 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1844 E1000_WRITE_REG(hw, TCTL, tctl);
1845 E1000_WRITE_FLUSH(hw);
1848 /******************************************************************************
1849 * Sets MAC speed and duplex settings to reflect the those in the PHY
1851 * hw - Struct containing variables accessed by shared code
1852 * mii_reg - data to write to the MII control register
1854 * The contents of the PHY register containing the needed information need to
1856 ******************************************************************************/
1858 e1000_config_mac_to_phy(struct e1000_hw *hw)
1864 DEBUGFUNC("e1000_config_mac_to_phy");
1866 /* 82544 or newer MAC, Auto Speed Detection takes care of
1867 * MAC speed/duplex configuration.*/
1868 if (hw->mac_type >= e1000_82544)
1869 return E1000_SUCCESS;
1871 /* Read the Device Control Register and set the bits to Force Speed
1874 ctrl = E1000_READ_REG(hw, CTRL);
1875 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1876 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1878 /* Set up duplex in the Device Control and Transmit Control
1879 * registers depending on negotiated values.
1881 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1885 if(phy_data & M88E1000_PSSR_DPLX)
1886 ctrl |= E1000_CTRL_FD;
1888 ctrl &= ~E1000_CTRL_FD;
1890 e1000_config_collision_dist(hw);
1892 /* Set up speed in the Device Control register depending on
1893 * negotiated values.
1895 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1896 ctrl |= E1000_CTRL_SPD_1000;
1897 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1898 ctrl |= E1000_CTRL_SPD_100;
1900 /* Write the configured values back to the Device Control Reg. */
1901 E1000_WRITE_REG(hw, CTRL, ctrl);
1902 return E1000_SUCCESS;
1905 /******************************************************************************
1906 * Forces the MAC's flow control settings.
1908 * hw - Struct containing variables accessed by shared code
1910 * Sets the TFCE and RFCE bits in the device control register to reflect
1911 * the adapter settings. TFCE and RFCE need to be explicitly set by
1912 * software when a Copper PHY is used because autonegotiation is managed
1913 * by the PHY rather than the MAC. Software must also configure these
1914 * bits when link is forced on a fiber connection.
1915 *****************************************************************************/
1917 e1000_force_mac_fc(struct e1000_hw *hw)
1921 DEBUGFUNC("e1000_force_mac_fc");
1923 /* Get the current configuration of the Device Control Register */
1924 ctrl = E1000_READ_REG(hw, CTRL);
1926 /* Because we didn't get link via the internal auto-negotiation
1927 * mechanism (we either forced link or we got link via PHY
1928 * auto-neg), we have to manually enable/disable transmit an
1929 * receive flow control.
1931 * The "Case" statement below enables/disable flow control
1932 * according to the "hw->fc" parameter.
1934 * The possible values of the "fc" parameter are:
1935 * 0: Flow control is completely disabled
1936 * 1: Rx flow control is enabled (we can receive pause
1937 * frames but not send pause frames).
1938 * 2: Tx flow control is enabled (we can send pause frames
1939 * frames but we do not receive pause frames).
1940 * 3: Both Rx and TX flow control (symmetric) is enabled.
1941 * other: No other values should be possible at this point.
1946 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1948 case e1000_fc_rx_pause:
1949 ctrl &= (~E1000_CTRL_TFCE);
1950 ctrl |= E1000_CTRL_RFCE;
1952 case e1000_fc_tx_pause:
1953 ctrl &= (~E1000_CTRL_RFCE);
1954 ctrl |= E1000_CTRL_TFCE;
1957 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1960 DEBUGOUT("Flow control param set incorrectly\n");
1961 return -E1000_ERR_CONFIG;
1964 /* Disable TX Flow Control for 82542 (rev 2.0) */
1965 if(hw->mac_type == e1000_82542_rev2_0)
1966 ctrl &= (~E1000_CTRL_TFCE);
1968 E1000_WRITE_REG(hw, CTRL, ctrl);
1969 return E1000_SUCCESS;
1972 /******************************************************************************
1973 * Configures flow control settings after link is established
1975 * hw - Struct containing variables accessed by shared code
1977 * Should be called immediately after a valid link has been established.
1978 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1979 * and autonegotiation is enabled, the MAC flow control settings will be set
1980 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1981 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1982 *****************************************************************************/
1984 e1000_config_fc_after_link_up(struct e1000_hw *hw)
1987 uint16_t mii_status_reg;
1988 uint16_t mii_nway_adv_reg;
1989 uint16_t mii_nway_lp_ability_reg;
1993 DEBUGFUNC("e1000_config_fc_after_link_up");
1995 /* Check for the case where we have fiber media and auto-neg failed
1996 * so we had to force link. In this case, we need to force the
1997 * configuration of the MAC to match the "fc" parameter.
1999 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2000 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2001 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2002 ret_val = e1000_force_mac_fc(hw);
2004 DEBUGOUT("Error forcing flow control settings\n");
2009 /* Check for the case where we have copper media and auto-neg is
2010 * enabled. In this case, we need to check and see if Auto-Neg
2011 * has completed, and if so, how the PHY and link partner has
2012 * flow control configured.
2014 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2015 /* Read the MII Status Register and check to see if AutoNeg
2016 * has completed. We read this twice because this reg has
2017 * some "sticky" (latched) bits.
2019 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2022 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2026 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2027 /* The AutoNeg process has completed, so we now need to
2028 * read both the Auto Negotiation Advertisement Register
2029 * (Address 4) and the Auto_Negotiation Base Page Ability
2030 * Register (Address 5) to determine how flow control was
2033 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2037 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2038 &mii_nway_lp_ability_reg);
2042 /* Two bits in the Auto Negotiation Advertisement Register
2043 * (Address 4) and two bits in the Auto Negotiation Base
2044 * Page Ability Register (Address 5) determine flow control
2045 * for both the PHY and the link partner. The following
2046 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2047 * 1999, describes these PAUSE resolution bits and how flow
2048 * control is determined based upon these settings.
2049 * NOTE: DC = Don't Care
2051 * LOCAL DEVICE | LINK PARTNER
2052 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2053 *-------|---------|-------|---------|--------------------
2054 * 0 | 0 | DC | DC | e1000_fc_none
2055 * 0 | 1 | 0 | DC | e1000_fc_none
2056 * 0 | 1 | 1 | 0 | e1000_fc_none
2057 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2058 * 1 | 0 | 0 | DC | e1000_fc_none
2059 * 1 | DC | 1 | DC | e1000_fc_full
2060 * 1 | 1 | 0 | 0 | e1000_fc_none
2061 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2064 /* Are both PAUSE bits set to 1? If so, this implies
2065 * Symmetric Flow Control is enabled at both ends. The
2066 * ASM_DIR bits are irrelevant per the spec.
2068 * For Symmetric Flow Control:
2070 * LOCAL DEVICE | LINK PARTNER
2071 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2072 *-------|---------|-------|---------|--------------------
2073 * 1 | DC | 1 | DC | e1000_fc_full
2076 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2077 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2078 /* Now we need to check if the user selected RX ONLY
2079 * of pause frames. In this case, we had to advertise
2080 * FULL flow control because we could not advertise RX
2081 * ONLY. Hence, we must now check to see if we need to
2082 * turn OFF the TRANSMISSION of PAUSE frames.
2084 if(hw->original_fc == e1000_fc_full) {
2085 hw->fc = e1000_fc_full;
2086 DEBUGOUT("Flow Control = FULL.\r\n");
2088 hw->fc = e1000_fc_rx_pause;
2089 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2092 /* For receiving PAUSE frames ONLY.
2094 * LOCAL DEVICE | LINK PARTNER
2095 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2096 *-------|---------|-------|---------|--------------------
2097 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2100 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2101 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2102 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2103 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2104 hw->fc = e1000_fc_tx_pause;
2105 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2107 /* For transmitting PAUSE frames ONLY.
2109 * LOCAL DEVICE | LINK PARTNER
2110 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2111 *-------|---------|-------|---------|--------------------
2112 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2115 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2116 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2117 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2118 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2119 hw->fc = e1000_fc_rx_pause;
2120 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2122 /* Per the IEEE spec, at this point flow control should be
2123 * disabled. However, we want to consider that we could
2124 * be connected to a legacy switch that doesn't advertise
2125 * desired flow control, but can be forced on the link
2126 * partner. So if we advertised no flow control, that is
2127 * what we will resolve to. If we advertised some kind of
2128 * receive capability (Rx Pause Only or Full Flow Control)
2129 * and the link partner advertised none, we will configure
2130 * ourselves to enable Rx Flow Control only. We can do
2131 * this safely for two reasons: If the link partner really
2132 * didn't want flow control enabled, and we enable Rx, no
2133 * harm done since we won't be receiving any PAUSE frames
2134 * anyway. If the intent on the link partner was to have
2135 * flow control enabled, then by us enabling RX only, we
2136 * can at least receive pause frames and process them.
2137 * This is a good idea because in most cases, since we are
2138 * predominantly a server NIC, more times than not we will
2139 * be asked to delay transmission of packets than asking
2140 * our link partner to pause transmission of frames.
2142 else if((hw->original_fc == e1000_fc_none ||
2143 hw->original_fc == e1000_fc_tx_pause) ||
2144 hw->fc_strict_ieee) {
2145 hw->fc = e1000_fc_none;
2146 DEBUGOUT("Flow Control = NONE.\r\n");
2148 hw->fc = e1000_fc_rx_pause;
2149 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2152 /* Now we need to do one last check... If we auto-
2153 * negotiated to HALF DUPLEX, flow control should not be
2154 * enabled per IEEE 802.3 spec.
2156 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2158 DEBUGOUT("Error getting link speed and duplex\n");
2162 if(duplex == HALF_DUPLEX)
2163 hw->fc = e1000_fc_none;
2165 /* Now we call a subroutine to actually force the MAC
2166 * controller to use the correct flow control settings.
2168 ret_val = e1000_force_mac_fc(hw);
2170 DEBUGOUT("Error forcing flow control settings\n");
2174 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2177 return E1000_SUCCESS;
2180 /******************************************************************************
2181 * Checks to see if the link status of the hardware has changed.
2183 * hw - Struct containing variables accessed by shared code
2185 * Called by any function that needs to check the link status of the adapter.
2186 *****************************************************************************/
2188 e1000_check_for_link(struct e1000_hw *hw)
2195 uint32_t signal = 0;
2199 DEBUGFUNC("e1000_check_for_link");
2201 ctrl = E1000_READ_REG(hw, CTRL);
2202 status = E1000_READ_REG(hw, STATUS);
2204 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2205 * set when the optics detect a signal. On older adapters, it will be
2206 * cleared when there is a signal. This applies to fiber media only.
2208 if((hw->media_type == e1000_media_type_fiber) ||
2209 (hw->media_type == e1000_media_type_internal_serdes)) {
2210 rxcw = E1000_READ_REG(hw, RXCW);
2212 if(hw->media_type == e1000_media_type_fiber) {
2213 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2214 if(status & E1000_STATUS_LU)
2215 hw->get_link_status = FALSE;
2219 /* If we have a copper PHY then we only want to go out to the PHY
2220 * registers to see if Auto-Neg has completed and/or if our link
2221 * status has changed. The get_link_status flag will be set if we
2222 * receive a Link Status Change interrupt or we have Rx Sequence
2225 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2226 /* First we want to see if the MII Status Register reports
2227 * link. If so, then we want to get the current speed/duplex
2229 * Read the register twice since the link bit is sticky.
2231 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2234 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2238 if(phy_data & MII_SR_LINK_STATUS) {
2239 hw->get_link_status = FALSE;
2240 /* Check if there was DownShift, must be checked immediately after
2242 e1000_check_downshift(hw);
2244 /* If we are on 82544 or 82543 silicon and speed/duplex
2245 * are forced to 10H or 10F, then we will implement the polarity
2246 * reversal workaround. We disable interrupts first, and upon
2247 * returning, place the devices interrupt state to its previous
2248 * value except for the link status change interrupt which will
2249 * happen due to the execution of this workaround.
2252 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2254 (hw->forced_speed_duplex == e1000_10_full ||
2255 hw->forced_speed_duplex == e1000_10_half)) {
2256 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2257 ret_val = e1000_polarity_reversal_workaround(hw);
2258 icr = E1000_READ_REG(hw, ICR);
2259 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2260 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2264 /* No link detected */
2265 e1000_config_dsp_after_link_change(hw, FALSE);
2269 /* If we are forcing speed/duplex, then we simply return since
2270 * we have already determined whether we have link or not.
2272 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2274 /* optimize the dsp settings for the igp phy */
2275 e1000_config_dsp_after_link_change(hw, TRUE);
2277 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2278 * have Si on board that is 82544 or newer, Auto
2279 * Speed Detection takes care of MAC speed/duplex
2280 * configuration. So we only need to configure Collision
2281 * Distance in the MAC. Otherwise, we need to force
2282 * speed/duplex on the MAC to the current PHY speed/duplex
2285 if(hw->mac_type >= e1000_82544)
2286 e1000_config_collision_dist(hw);
2288 ret_val = e1000_config_mac_to_phy(hw);
2290 DEBUGOUT("Error configuring MAC to PHY settings\n");
2295 /* Configure Flow Control now that Auto-Neg has completed. First, we
2296 * need to restore the desired flow control settings because we may
2297 * have had to re-autoneg with a different link partner.
2299 ret_val = e1000_config_fc_after_link_up(hw);
2301 DEBUGOUT("Error configuring flow control\n");
2305 /* At this point we know that we are on copper and we have
2306 * auto-negotiated link. These are conditions for checking the link
2307 * partner capability register. We use the link speed to determine if
2308 * TBI compatibility needs to be turned on or off. If the link is not
2309 * at gigabit speed, then TBI compatibility is not needed. If we are
2310 * at gigabit speed, we turn on TBI compatibility.
2312 if(hw->tbi_compatibility_en) {
2313 uint16_t speed, duplex;
2314 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2315 if(speed != SPEED_1000) {
2316 /* If link speed is not set to gigabit speed, we do not need
2317 * to enable TBI compatibility.
2319 if(hw->tbi_compatibility_on) {
2320 /* If we previously were in the mode, turn it off. */
2321 rctl = E1000_READ_REG(hw, RCTL);
2322 rctl &= ~E1000_RCTL_SBP;
2323 E1000_WRITE_REG(hw, RCTL, rctl);
2324 hw->tbi_compatibility_on = FALSE;
2327 /* If TBI compatibility is was previously off, turn it on. For
2328 * compatibility with a TBI link partner, we will store bad
2329 * packets. Some frames have an additional byte on the end and
2330 * will look like CRC errors to to the hardware.
2332 if(!hw->tbi_compatibility_on) {
2333 hw->tbi_compatibility_on = TRUE;
2334 rctl = E1000_READ_REG(hw, RCTL);
2335 rctl |= E1000_RCTL_SBP;
2336 E1000_WRITE_REG(hw, RCTL, rctl);
2341 /* If we don't have link (auto-negotiation failed or link partner cannot
2342 * auto-negotiate), the cable is plugged in (we have signal), and our
2343 * link partner is not trying to auto-negotiate with us (we are receiving
2344 * idles or data), we need to force link up. We also need to give
2345 * auto-negotiation time to complete, in case the cable was just plugged
2346 * in. The autoneg_failed flag does this.
2348 else if((((hw->media_type == e1000_media_type_fiber) &&
2349 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2350 (hw->media_type == e1000_media_type_internal_serdes)) &&
2351 (!(status & E1000_STATUS_LU)) &&
2352 (!(rxcw & E1000_RXCW_C))) {
2353 if(hw->autoneg_failed == 0) {
2354 hw->autoneg_failed = 1;
2357 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2359 /* Disable auto-negotiation in the TXCW register */
2360 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2362 /* Force link-up and also force full-duplex. */
2363 ctrl = E1000_READ_REG(hw, CTRL);
2364 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2365 E1000_WRITE_REG(hw, CTRL, ctrl);
2367 /* Configure Flow Control after forcing link up. */
2368 ret_val = e1000_config_fc_after_link_up(hw);
2370 DEBUGOUT("Error configuring flow control\n");
2374 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2375 * auto-negotiation in the TXCW register and disable forced link in the
2376 * Device Control register in an attempt to auto-negotiate with our link
2379 else if(((hw->media_type == e1000_media_type_fiber) ||
2380 (hw->media_type == e1000_media_type_internal_serdes)) &&
2381 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2382 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2383 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2384 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2386 hw->serdes_link_down = FALSE;
2388 /* If we force link for non-auto-negotiation switch, check link status
2389 * based on MAC synchronization for internal serdes media type.
2391 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2392 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2393 /* SYNCH bit and IV bit are sticky. */
2395 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2396 if(!(rxcw & E1000_RXCW_IV)) {
2397 hw->serdes_link_down = FALSE;
2398 DEBUGOUT("SERDES: Link is up.\n");
2401 hw->serdes_link_down = TRUE;
2402 DEBUGOUT("SERDES: Link is down.\n");
2405 if((hw->media_type == e1000_media_type_internal_serdes) &&
2406 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2407 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2409 return E1000_SUCCESS;
2412 /******************************************************************************
2413 * Detects the current speed and duplex settings of the hardware.
2415 * hw - Struct containing variables accessed by shared code
2416 * speed - Speed of the connection
2417 * duplex - Duplex setting of the connection
2418 *****************************************************************************/
2420 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2428 DEBUGFUNC("e1000_get_speed_and_duplex");
2430 if(hw->mac_type >= e1000_82543) {
2431 status = E1000_READ_REG(hw, STATUS);
2432 if(status & E1000_STATUS_SPEED_1000) {
2433 *speed = SPEED_1000;
2434 DEBUGOUT("1000 Mbs, ");
2435 } else if(status & E1000_STATUS_SPEED_100) {
2437 DEBUGOUT("100 Mbs, ");
2440 DEBUGOUT("10 Mbs, ");
2443 if(status & E1000_STATUS_FD) {
2444 *duplex = FULL_DUPLEX;
2445 DEBUGOUT("Full Duplex\r\n");
2447 *duplex = HALF_DUPLEX;
2448 DEBUGOUT(" Half Duplex\r\n");
2451 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2452 *speed = SPEED_1000;
2453 *duplex = FULL_DUPLEX;
2456 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2457 * if it is operating at half duplex. Here we set the duplex settings to
2458 * match the duplex in the link partner's capabilities.
2460 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2461 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2465 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2466 *duplex = HALF_DUPLEX;
2468 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2471 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2472 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2473 *duplex = HALF_DUPLEX;
2477 return E1000_SUCCESS;
2480 /******************************************************************************
2481 * Blocks until autoneg completes or times out (~4.5 seconds)
2483 * hw - Struct containing variables accessed by shared code
2484 ******************************************************************************/
2486 e1000_wait_autoneg(struct e1000_hw *hw)
2492 DEBUGFUNC("e1000_wait_autoneg");
2493 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2495 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2496 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2497 /* Read the MII Status Register and wait for Auto-Neg
2498 * Complete bit to be set.
2500 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2503 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2506 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2507 return E1000_SUCCESS;
2511 return E1000_SUCCESS;
2514 /******************************************************************************
2515 * Raises the Management Data Clock
2517 * hw - Struct containing variables accessed by shared code
2518 * ctrl - Device control register's current value
2519 ******************************************************************************/
2521 e1000_raise_mdi_clk(struct e1000_hw *hw,
2524 /* Raise the clock input to the Management Data Clock (by setting the MDC
2525 * bit), and then delay 10 microseconds.
2527 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2528 E1000_WRITE_FLUSH(hw);
2532 /******************************************************************************
2533 * Lowers the Management Data Clock
2535 * hw - Struct containing variables accessed by shared code
2536 * ctrl - Device control register's current value
2537 ******************************************************************************/
2539 e1000_lower_mdi_clk(struct e1000_hw *hw,
2542 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2543 * bit), and then delay 10 microseconds.
2545 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2546 E1000_WRITE_FLUSH(hw);
2550 /******************************************************************************
2551 * Shifts data bits out to the PHY
2553 * hw - Struct containing variables accessed by shared code
2554 * data - Data to send out to the PHY
2555 * count - Number of bits to shift out
2557 * Bits are shifted out in MSB to LSB order.
2558 ******************************************************************************/
2560 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2567 /* We need to shift "count" number of bits out to the PHY. So, the value
2568 * in the "data" parameter will be shifted out to the PHY one bit at a
2569 * time. In order to do this, "data" must be broken down into bits.
2572 mask <<= (count - 1);
2574 ctrl = E1000_READ_REG(hw, CTRL);
2576 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2577 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2580 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2581 * then raising and lowering the Management Data Clock. A "0" is
2582 * shifted out to the PHY by setting the MDIO bit to "0" and then
2583 * raising and lowering the clock.
2585 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2586 else ctrl &= ~E1000_CTRL_MDIO;
2588 E1000_WRITE_REG(hw, CTRL, ctrl);
2589 E1000_WRITE_FLUSH(hw);
2593 e1000_raise_mdi_clk(hw, &ctrl);
2594 e1000_lower_mdi_clk(hw, &ctrl);
2600 /******************************************************************************
2601 * Shifts data bits in from the PHY
2603 * hw - Struct containing variables accessed by shared code
2605 * Bits are shifted in in MSB to LSB order.
2606 ******************************************************************************/
2608 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2614 /* In order to read a register from the PHY, we need to shift in a total
2615 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2616 * to avoid contention on the MDIO pin when a read operation is performed.
2617 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2618 * by raising the input to the Management Data Clock (setting the MDC bit),
2619 * and then reading the value of the MDIO bit.
2621 ctrl = E1000_READ_REG(hw, CTRL);
2623 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2624 ctrl &= ~E1000_CTRL_MDIO_DIR;
2625 ctrl &= ~E1000_CTRL_MDIO;
2627 E1000_WRITE_REG(hw, CTRL, ctrl);
2628 E1000_WRITE_FLUSH(hw);
2630 /* Raise and Lower the clock before reading in the data. This accounts for
2631 * the turnaround bits. The first clock occurred when we clocked out the
2632 * last bit of the Register Address.
2634 e1000_raise_mdi_clk(hw, &ctrl);
2635 e1000_lower_mdi_clk(hw, &ctrl);
2637 for(data = 0, i = 0; i < 16; i++) {
2639 e1000_raise_mdi_clk(hw, &ctrl);
2640 ctrl = E1000_READ_REG(hw, CTRL);
2641 /* Check to see if we shifted in a "1". */
2642 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2643 e1000_lower_mdi_clk(hw, &ctrl);
2646 e1000_raise_mdi_clk(hw, &ctrl);
2647 e1000_lower_mdi_clk(hw, &ctrl);
2652 /*****************************************************************************
2653 * Reads the value from a PHY register, if the value is on a specific non zero
2654 * page, sets the page first.
2655 * hw - Struct containing variables accessed by shared code
2656 * reg_addr - address of the PHY register to read
2657 ******************************************************************************/
2659 e1000_read_phy_reg(struct e1000_hw *hw,
2665 DEBUGFUNC("e1000_read_phy_reg");
2667 if((hw->phy_type == e1000_phy_igp ||
2668 hw->phy_type == e1000_phy_igp_2) &&
2669 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2670 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2671 (uint16_t)reg_addr);
2677 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2684 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2690 const uint32_t phy_addr = 1;
2692 DEBUGFUNC("e1000_read_phy_reg_ex");
2694 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2695 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2696 return -E1000_ERR_PARAM;
2699 if(hw->mac_type > e1000_82543) {
2700 /* Set up Op-code, Phy Address, and register address in the MDI
2701 * Control register. The MAC will take care of interfacing with the
2702 * PHY to retrieve the desired data.
2704 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2705 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2706 (E1000_MDIC_OP_READ));
2708 E1000_WRITE_REG(hw, MDIC, mdic);
2710 /* Poll the ready bit to see if the MDI read completed */
2711 for(i = 0; i < 64; i++) {
2713 mdic = E1000_READ_REG(hw, MDIC);
2714 if(mdic & E1000_MDIC_READY) break;
2716 if(!(mdic & E1000_MDIC_READY)) {
2717 DEBUGOUT("MDI Read did not complete\n");
2718 return -E1000_ERR_PHY;
2720 if(mdic & E1000_MDIC_ERROR) {
2721 DEBUGOUT("MDI Error\n");
2722 return -E1000_ERR_PHY;
2724 *phy_data = (uint16_t) mdic;
2726 /* We must first send a preamble through the MDIO pin to signal the
2727 * beginning of an MII instruction. This is done by sending 32
2728 * consecutive "1" bits.
2730 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2732 /* Now combine the next few fields that are required for a read
2733 * operation. We use this method instead of calling the
2734 * e1000_shift_out_mdi_bits routine five different times. The format of
2735 * a MII read instruction consists of a shift out of 14 bits and is
2736 * defined as follows:
2737 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2738 * followed by a shift in of 18 bits. This first two bits shifted in
2739 * are TurnAround bits used to avoid contention on the MDIO pin when a
2740 * READ operation is performed. These two bits are thrown away
2741 * followed by a shift in of 16 bits which contains the desired data.
2743 mdic = ((reg_addr) | (phy_addr << 5) |
2744 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2746 e1000_shift_out_mdi_bits(hw, mdic, 14);
2748 /* Now that we've shifted out the read command to the MII, we need to
2749 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2752 *phy_data = e1000_shift_in_mdi_bits(hw);
2754 return E1000_SUCCESS;
2757 /******************************************************************************
2758 * Writes a value to a PHY register
2760 * hw - Struct containing variables accessed by shared code
2761 * reg_addr - address of the PHY register to write
2762 * data - data to write to the PHY
2763 ******************************************************************************/
2765 e1000_write_phy_reg(struct e1000_hw *hw,
2771 DEBUGFUNC("e1000_write_phy_reg");
2773 if((hw->phy_type == e1000_phy_igp ||
2774 hw->phy_type == e1000_phy_igp_2) &&
2775 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2776 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2777 (uint16_t)reg_addr);
2783 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2790 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2796 const uint32_t phy_addr = 1;
2798 DEBUGFUNC("e1000_write_phy_reg_ex");
2800 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2801 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2802 return -E1000_ERR_PARAM;
2805 if(hw->mac_type > e1000_82543) {
2806 /* Set up Op-code, Phy Address, register address, and data intended
2807 * for the PHY register in the MDI Control register. The MAC will take
2808 * care of interfacing with the PHY to send the desired data.
2810 mdic = (((uint32_t) phy_data) |
2811 (reg_addr << E1000_MDIC_REG_SHIFT) |
2812 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2813 (E1000_MDIC_OP_WRITE));
2815 E1000_WRITE_REG(hw, MDIC, mdic);
2817 /* Poll the ready bit to see if the MDI read completed */
2818 for(i = 0; i < 640; i++) {
2820 mdic = E1000_READ_REG(hw, MDIC);
2821 if(mdic & E1000_MDIC_READY) break;
2823 if(!(mdic & E1000_MDIC_READY)) {
2824 DEBUGOUT("MDI Write did not complete\n");
2825 return -E1000_ERR_PHY;
2828 /* We'll need to use the SW defined pins to shift the write command
2829 * out to the PHY. We first send a preamble to the PHY to signal the
2830 * beginning of the MII instruction. This is done by sending 32
2831 * consecutive "1" bits.
2833 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2835 /* Now combine the remaining required fields that will indicate a
2836 * write operation. We use this method instead of calling the
2837 * e1000_shift_out_mdi_bits routine for each field in the command. The
2838 * format of a MII write instruction is as follows:
2839 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2841 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2842 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2844 mdic |= (uint32_t) phy_data;
2846 e1000_shift_out_mdi_bits(hw, mdic, 32);
2849 return E1000_SUCCESS;
2853 /******************************************************************************
2854 * Returns the PHY to the power-on reset state
2856 * hw - Struct containing variables accessed by shared code
2857 ******************************************************************************/
2859 e1000_phy_hw_reset(struct e1000_hw *hw)
2861 uint32_t ctrl, ctrl_ext;
2865 DEBUGFUNC("e1000_phy_hw_reset");
2867 /* In the case of the phy reset being blocked, it's not an error, we
2868 * simply return success without performing the reset. */
2869 ret_val = e1000_check_phy_reset_block(hw);
2871 return E1000_SUCCESS;
2873 DEBUGOUT("Resetting Phy...\n");
2875 if(hw->mac_type > e1000_82543) {
2876 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2877 * bit. Then, take it out of reset.
2879 ctrl = E1000_READ_REG(hw, CTRL);
2880 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2881 E1000_WRITE_FLUSH(hw);
2883 E1000_WRITE_REG(hw, CTRL, ctrl);
2884 E1000_WRITE_FLUSH(hw);
2886 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2887 * bit to put the PHY into reset. Then, take it out of reset.
2889 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2890 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2891 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2892 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2893 E1000_WRITE_FLUSH(hw);
2895 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2896 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2897 E1000_WRITE_FLUSH(hw);
2901 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2902 /* Configure activity LED after PHY reset */
2903 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2904 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2905 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2906 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2909 /* Wait for FW to finish PHY configuration. */
2910 ret_val = e1000_get_phy_cfg_done(hw);
2915 /******************************************************************************
2918 * hw - Struct containing variables accessed by shared code
2920 * Sets bit 15 of the MII Control regiser
2921 ******************************************************************************/
2923 e1000_phy_reset(struct e1000_hw *hw)
2928 DEBUGFUNC("e1000_phy_reset");
2930 /* In the case of the phy reset being blocked, it's not an error, we
2931 * simply return success without performing the reset. */
2932 ret_val = e1000_check_phy_reset_block(hw);
2934 return E1000_SUCCESS;
2936 switch (hw->mac_type) {
2937 case e1000_82541_rev_2:
2938 ret_val = e1000_phy_hw_reset(hw);
2943 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
2947 phy_data |= MII_CR_RESET;
2948 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
2956 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
2957 e1000_phy_init_script(hw);
2959 return E1000_SUCCESS;
2962 /******************************************************************************
2963 * Probes the expected PHY address for known PHY IDs
2965 * hw - Struct containing variables accessed by shared code
2966 ******************************************************************************/
2968 e1000_detect_gig_phy(struct e1000_hw *hw)
2970 int32_t phy_init_status, ret_val;
2971 uint16_t phy_id_high, phy_id_low;
2972 boolean_t match = FALSE;
2974 DEBUGFUNC("e1000_detect_gig_phy");
2976 /* Read the PHY ID Registers to identify which PHY is onboard. */
2977 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
2981 hw->phy_id = (uint32_t) (phy_id_high << 16);
2983 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
2987 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2988 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2990 switch(hw->mac_type) {
2992 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2995 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2999 case e1000_82545_rev_3:
3001 case e1000_82546_rev_3:
3002 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3005 case e1000_82541_rev_2:
3007 case e1000_82547_rev_2:
3008 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3011 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3014 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3015 return -E1000_ERR_CONFIG;
3017 phy_init_status = e1000_set_phy_type(hw);
3019 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3020 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3021 return E1000_SUCCESS;
3023 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3024 return -E1000_ERR_PHY;
3027 /******************************************************************************
3028 * Resets the PHY's DSP
3030 * hw - Struct containing variables accessed by shared code
3031 ******************************************************************************/
3033 e1000_phy_reset_dsp(struct e1000_hw *hw)
3036 DEBUGFUNC("e1000_phy_reset_dsp");
3039 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3041 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3043 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3045 ret_val = E1000_SUCCESS;
3051 /******************************************************************************
3052 * Get PHY information from various PHY registers for igp PHY only.
3054 * hw - Struct containing variables accessed by shared code
3055 * phy_info - PHY information structure
3056 ******************************************************************************/
3058 e1000_phy_igp_get_info(struct e1000_hw *hw,
3059 struct e1000_phy_info *phy_info)
3062 uint16_t phy_data, polarity, min_length, max_length, average;
3064 DEBUGFUNC("e1000_phy_igp_get_info");
3066 /* The downshift status is checked only once, after link is established,
3067 * and it stored in the hw->speed_downgraded parameter. */
3068 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3070 /* IGP01E1000 does not need to support it. */
3071 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3073 /* IGP01E1000 always correct polarity reversal */
3074 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3076 /* Check polarity status */
3077 ret_val = e1000_check_polarity(hw, &polarity);
3081 phy_info->cable_polarity = polarity;
3083 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3087 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3088 IGP01E1000_PSSR_MDIX_SHIFT;
3090 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3091 IGP01E1000_PSSR_SPEED_1000MBPS) {
3092 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3093 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3097 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3098 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3099 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3100 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3102 /* Get cable length */
3103 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3107 /* Translate to old method */
3108 average = (max_length + min_length) / 2;
3110 if(average <= e1000_igp_cable_length_50)
3111 phy_info->cable_length = e1000_cable_length_50;
3112 else if(average <= e1000_igp_cable_length_80)
3113 phy_info->cable_length = e1000_cable_length_50_80;
3114 else if(average <= e1000_igp_cable_length_110)
3115 phy_info->cable_length = e1000_cable_length_80_110;
3116 else if(average <= e1000_igp_cable_length_140)
3117 phy_info->cable_length = e1000_cable_length_110_140;
3119 phy_info->cable_length = e1000_cable_length_140;
3122 return E1000_SUCCESS;
3125 /******************************************************************************
3126 * Get PHY information from various PHY registers fot m88 PHY only.
3128 * hw - Struct containing variables accessed by shared code
3129 * phy_info - PHY information structure
3130 ******************************************************************************/
3132 e1000_phy_m88_get_info(struct e1000_hw *hw,
3133 struct e1000_phy_info *phy_info)
3136 uint16_t phy_data, polarity;
3138 DEBUGFUNC("e1000_phy_m88_get_info");
3140 /* The downshift status is checked only once, after link is established,
3141 * and it stored in the hw->speed_downgraded parameter. */
3142 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3144 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3148 phy_info->extended_10bt_distance =
3149 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3150 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3151 phy_info->polarity_correction =
3152 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3153 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3155 /* Check polarity status */
3156 ret_val = e1000_check_polarity(hw, &polarity);
3159 phy_info->cable_polarity = polarity;
3161 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3165 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3166 M88E1000_PSSR_MDIX_SHIFT;
3168 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3169 /* Cable Length Estimation and Local/Remote Receiver Information
3170 * are only valid at 1000 Mbps.
3172 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3173 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3175 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3179 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3180 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3182 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3183 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3186 return E1000_SUCCESS;
3189 /******************************************************************************
3190 * Get PHY information from various PHY registers
3192 * hw - Struct containing variables accessed by shared code
3193 * phy_info - PHY information structure
3194 ******************************************************************************/
3196 e1000_phy_get_info(struct e1000_hw *hw,
3197 struct e1000_phy_info *phy_info)
3202 DEBUGFUNC("e1000_phy_get_info");
3204 phy_info->cable_length = e1000_cable_length_undefined;
3205 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3206 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3207 phy_info->downshift = e1000_downshift_undefined;
3208 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3209 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3210 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3211 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3213 if(hw->media_type != e1000_media_type_copper) {
3214 DEBUGOUT("PHY info is only valid for copper media\n");
3215 return -E1000_ERR_CONFIG;
3218 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3222 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3226 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3227 DEBUGOUT("PHY info is only valid if link is up\n");
3228 return -E1000_ERR_CONFIG;
3231 if(hw->phy_type == e1000_phy_igp ||
3232 hw->phy_type == e1000_phy_igp_2)
3233 return e1000_phy_igp_get_info(hw, phy_info);
3235 return e1000_phy_m88_get_info(hw, phy_info);
3239 e1000_validate_mdi_setting(struct e1000_hw *hw)
3241 DEBUGFUNC("e1000_validate_mdi_settings");
3243 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3244 DEBUGOUT("Invalid MDI setting detected\n");
3246 return -E1000_ERR_CONFIG;
3248 return E1000_SUCCESS;
3252 /******************************************************************************
3253 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3256 * hw - Struct containing variables accessed by shared code
3257 *****************************************************************************/
3259 e1000_init_eeprom_params(struct e1000_hw *hw)
3261 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3262 uint32_t eecd = E1000_READ_REG(hw, EECD);
3263 int32_t ret_val = E1000_SUCCESS;
3264 uint16_t eeprom_size;
3266 DEBUGFUNC("e1000_init_eeprom_params");
3268 switch (hw->mac_type) {
3269 case e1000_82542_rev2_0:
3270 case e1000_82542_rev2_1:
3273 eeprom->type = e1000_eeprom_microwire;
3274 eeprom->word_size = 64;
3275 eeprom->opcode_bits = 3;
3276 eeprom->address_bits = 6;
3277 eeprom->delay_usec = 50;
3278 eeprom->use_eerd = FALSE;
3279 eeprom->use_eewr = FALSE;
3283 case e1000_82545_rev_3:
3285 case e1000_82546_rev_3:
3286 eeprom->type = e1000_eeprom_microwire;
3287 eeprom->opcode_bits = 3;
3288 eeprom->delay_usec = 50;
3289 if(eecd & E1000_EECD_SIZE) {
3290 eeprom->word_size = 256;
3291 eeprom->address_bits = 8;
3293 eeprom->word_size = 64;
3294 eeprom->address_bits = 6;
3296 eeprom->use_eerd = FALSE;
3297 eeprom->use_eewr = FALSE;
3300 case e1000_82541_rev_2:
3302 case e1000_82547_rev_2:
3303 if (eecd & E1000_EECD_TYPE) {
3304 eeprom->type = e1000_eeprom_spi;
3305 eeprom->opcode_bits = 8;
3306 eeprom->delay_usec = 1;
3307 if (eecd & E1000_EECD_ADDR_BITS) {
3308 eeprom->page_size = 32;
3309 eeprom->address_bits = 16;
3311 eeprom->page_size = 8;
3312 eeprom->address_bits = 8;
3315 eeprom->type = e1000_eeprom_microwire;
3316 eeprom->opcode_bits = 3;
3317 eeprom->delay_usec = 50;
3318 if (eecd & E1000_EECD_ADDR_BITS) {
3319 eeprom->word_size = 256;
3320 eeprom->address_bits = 8;
3322 eeprom->word_size = 64;
3323 eeprom->address_bits = 6;
3326 eeprom->use_eerd = FALSE;
3327 eeprom->use_eewr = FALSE;
3330 eeprom->type = e1000_eeprom_spi;
3331 eeprom->opcode_bits = 8;
3332 eeprom->delay_usec = 1;
3333 if (eecd & E1000_EECD_ADDR_BITS) {
3334 eeprom->page_size = 32;
3335 eeprom->address_bits = 16;
3337 eeprom->page_size = 8;
3338 eeprom->address_bits = 8;
3340 eeprom->use_eerd = TRUE;
3341 eeprom->use_eewr = TRUE;
3342 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
3343 eeprom->type = e1000_eeprom_flash;
3344 eeprom->word_size = 2048;
3346 /* Ensure that the Autonomous FLASH update bit is cleared due to
3347 * Flash update issue on parts which use a FLASH for NVM. */
3348 eecd &= ~E1000_EECD_AUPDEN;
3349 E1000_WRITE_REG(hw, EECD, eecd);
3356 if (eeprom->type == e1000_eeprom_spi) {
3357 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3358 * 32KB (incremented by powers of 2).
3360 if(hw->mac_type <= e1000_82547_rev_2) {
3361 /* Set to default value for initial eeprom read. */
3362 eeprom->word_size = 64;
3363 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3366 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3367 /* 256B eeprom size was not supported in earlier hardware, so we
3368 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3369 * is never the result used in the shifting logic below. */
3373 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3374 E1000_EECD_SIZE_EX_SHIFT);
3377 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3382 /******************************************************************************
3383 * Raises the EEPROM's clock input.
3385 * hw - Struct containing variables accessed by shared code
3386 * eecd - EECD's current value
3387 *****************************************************************************/
3389 e1000_raise_ee_clk(struct e1000_hw *hw,
3392 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3393 * wait <delay> microseconds.
3395 *eecd = *eecd | E1000_EECD_SK;
3396 E1000_WRITE_REG(hw, EECD, *eecd);
3397 E1000_WRITE_FLUSH(hw);
3398 udelay(hw->eeprom.delay_usec);
3401 /******************************************************************************
3402 * Lowers the EEPROM's clock input.
3404 * hw - Struct containing variables accessed by shared code
3405 * eecd - EECD's current value
3406 *****************************************************************************/
3408 e1000_lower_ee_clk(struct e1000_hw *hw,
3411 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3412 * wait 50 microseconds.
3414 *eecd = *eecd & ~E1000_EECD_SK;
3415 E1000_WRITE_REG(hw, EECD, *eecd);
3416 E1000_WRITE_FLUSH(hw);
3417 udelay(hw->eeprom.delay_usec);
3420 /******************************************************************************
3421 * Shift data bits out to the EEPROM.
3423 * hw - Struct containing variables accessed by shared code
3424 * data - data to send to the EEPROM
3425 * count - number of bits to shift out
3426 *****************************************************************************/
3428 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3432 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3436 /* We need to shift "count" bits out to the EEPROM. So, value in the
3437 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3438 * In order to do this, "data" must be broken down into bits.
3440 mask = 0x01 << (count - 1);
3441 eecd = E1000_READ_REG(hw, EECD);
3442 if (eeprom->type == e1000_eeprom_microwire) {
3443 eecd &= ~E1000_EECD_DO;
3444 } else if (eeprom->type == e1000_eeprom_spi) {
3445 eecd |= E1000_EECD_DO;
3448 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3449 * and then raising and then lowering the clock (the SK bit controls
3450 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3451 * by setting "DI" to "0" and then raising and then lowering the clock.
3453 eecd &= ~E1000_EECD_DI;
3456 eecd |= E1000_EECD_DI;
3458 E1000_WRITE_REG(hw, EECD, eecd);
3459 E1000_WRITE_FLUSH(hw);
3461 udelay(eeprom->delay_usec);
3463 e1000_raise_ee_clk(hw, &eecd);
3464 e1000_lower_ee_clk(hw, &eecd);
3470 /* We leave the "DI" bit set to "0" when we leave this routine. */
3471 eecd &= ~E1000_EECD_DI;
3472 E1000_WRITE_REG(hw, EECD, eecd);
3475 /******************************************************************************
3476 * Shift data bits in from the EEPROM
3478 * hw - Struct containing variables accessed by shared code
3479 *****************************************************************************/
3481 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3488 /* In order to read a register from the EEPROM, we need to shift 'count'
3489 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3490 * input to the EEPROM (setting the SK bit), and then reading the value of
3491 * the "DO" bit. During this "shifting in" process the "DI" bit should
3495 eecd = E1000_READ_REG(hw, EECD);
3497 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3500 for(i = 0; i < count; i++) {
3502 e1000_raise_ee_clk(hw, &eecd);
3504 eecd = E1000_READ_REG(hw, EECD);
3506 eecd &= ~(E1000_EECD_DI);
3507 if(eecd & E1000_EECD_DO)
3510 e1000_lower_ee_clk(hw, &eecd);
3516 /******************************************************************************
3517 * Prepares EEPROM for access
3519 * hw - Struct containing variables accessed by shared code
3521 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3522 * function should be called before issuing a command to the EEPROM.
3523 *****************************************************************************/
3525 e1000_acquire_eeprom(struct e1000_hw *hw)
3527 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3530 DEBUGFUNC("e1000_acquire_eeprom");
3532 if(e1000_get_hw_eeprom_semaphore(hw))
3533 return -E1000_ERR_EEPROM;
3535 eecd = E1000_READ_REG(hw, EECD);
3537 if (hw->mac_type != e1000_82573) {
3538 /* Request EEPROM Access */
3539 if(hw->mac_type > e1000_82544) {
3540 eecd |= E1000_EECD_REQ;
3541 E1000_WRITE_REG(hw, EECD, eecd);
3542 eecd = E1000_READ_REG(hw, EECD);
3543 while((!(eecd & E1000_EECD_GNT)) &&
3544 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3547 eecd = E1000_READ_REG(hw, EECD);
3549 if(!(eecd & E1000_EECD_GNT)) {
3550 eecd &= ~E1000_EECD_REQ;
3551 E1000_WRITE_REG(hw, EECD, eecd);
3552 DEBUGOUT("Could not acquire EEPROM grant\n");
3553 return -E1000_ERR_EEPROM;
3558 /* Setup EEPROM for Read/Write */
3560 if (eeprom->type == e1000_eeprom_microwire) {
3561 /* Clear SK and DI */
3562 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3563 E1000_WRITE_REG(hw, EECD, eecd);
3566 eecd |= E1000_EECD_CS;
3567 E1000_WRITE_REG(hw, EECD, eecd);
3568 } else if (eeprom->type == e1000_eeprom_spi) {
3569 /* Clear SK and CS */
3570 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3571 E1000_WRITE_REG(hw, EECD, eecd);
3575 return E1000_SUCCESS;
3578 /******************************************************************************
3579 * Returns EEPROM to a "standby" state
3581 * hw - Struct containing variables accessed by shared code
3582 *****************************************************************************/
3584 e1000_standby_eeprom(struct e1000_hw *hw)
3586 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3589 eecd = E1000_READ_REG(hw, EECD);
3591 if(eeprom->type == e1000_eeprom_microwire) {
3592 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3593 E1000_WRITE_REG(hw, EECD, eecd);
3594 E1000_WRITE_FLUSH(hw);
3595 udelay(eeprom->delay_usec);
3598 eecd |= E1000_EECD_SK;
3599 E1000_WRITE_REG(hw, EECD, eecd);
3600 E1000_WRITE_FLUSH(hw);
3601 udelay(eeprom->delay_usec);
3604 eecd |= E1000_EECD_CS;
3605 E1000_WRITE_REG(hw, EECD, eecd);
3606 E1000_WRITE_FLUSH(hw);
3607 udelay(eeprom->delay_usec);
3610 eecd &= ~E1000_EECD_SK;
3611 E1000_WRITE_REG(hw, EECD, eecd);
3612 E1000_WRITE_FLUSH(hw);
3613 udelay(eeprom->delay_usec);
3614 } else if(eeprom->type == e1000_eeprom_spi) {
3615 /* Toggle CS to flush commands */
3616 eecd |= E1000_EECD_CS;
3617 E1000_WRITE_REG(hw, EECD, eecd);
3618 E1000_WRITE_FLUSH(hw);
3619 udelay(eeprom->delay_usec);
3620 eecd &= ~E1000_EECD_CS;
3621 E1000_WRITE_REG(hw, EECD, eecd);
3622 E1000_WRITE_FLUSH(hw);
3623 udelay(eeprom->delay_usec);
3627 /******************************************************************************
3628 * Terminates a command by inverting the EEPROM's chip select pin
3630 * hw - Struct containing variables accessed by shared code
3631 *****************************************************************************/
3633 e1000_release_eeprom(struct e1000_hw *hw)
3637 DEBUGFUNC("e1000_release_eeprom");
3639 eecd = E1000_READ_REG(hw, EECD);
3641 if (hw->eeprom.type == e1000_eeprom_spi) {
3642 eecd |= E1000_EECD_CS; /* Pull CS high */
3643 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3645 E1000_WRITE_REG(hw, EECD, eecd);
3647 udelay(hw->eeprom.delay_usec);
3648 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3649 /* cleanup eeprom */
3651 /* CS on Microwire is active-high */
3652 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3654 E1000_WRITE_REG(hw, EECD, eecd);
3656 /* Rising edge of clock */
3657 eecd |= E1000_EECD_SK;
3658 E1000_WRITE_REG(hw, EECD, eecd);
3659 E1000_WRITE_FLUSH(hw);
3660 udelay(hw->eeprom.delay_usec);
3662 /* Falling edge of clock */
3663 eecd &= ~E1000_EECD_SK;
3664 E1000_WRITE_REG(hw, EECD, eecd);
3665 E1000_WRITE_FLUSH(hw);
3666 udelay(hw->eeprom.delay_usec);
3669 /* Stop requesting EEPROM access */
3670 if(hw->mac_type > e1000_82544) {
3671 eecd &= ~E1000_EECD_REQ;
3672 E1000_WRITE_REG(hw, EECD, eecd);
3675 e1000_put_hw_eeprom_semaphore(hw);
3678 /******************************************************************************
3679 * Reads a 16 bit word from the EEPROM.
3681 * hw - Struct containing variables accessed by shared code
3682 *****************************************************************************/
3684 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3686 uint16_t retry_count = 0;
3687 uint8_t spi_stat_reg;
3689 DEBUGFUNC("e1000_spi_eeprom_ready");
3691 /* Read "Status Register" repeatedly until the LSB is cleared. The
3692 * EEPROM will signal that the command has been completed by clearing
3693 * bit 0 of the internal status register. If it's not cleared within
3694 * 5 milliseconds, then error out.
3698 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3699 hw->eeprom.opcode_bits);
3700 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3701 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3707 e1000_standby_eeprom(hw);
3708 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3710 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3711 * only 0-5mSec on 5V devices)
3713 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3714 DEBUGOUT("SPI EEPROM Status error\n");
3715 return -E1000_ERR_EEPROM;
3718 return E1000_SUCCESS;
3721 /******************************************************************************
3722 * Reads a 16 bit word from the EEPROM.
3724 * hw - Struct containing variables accessed by shared code
3725 * offset - offset of word in the EEPROM to read
3726 * data - word read from the EEPROM
3727 * words - number of words to read
3728 *****************************************************************************/
3730 e1000_read_eeprom(struct e1000_hw *hw,
3735 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3739 DEBUGFUNC("e1000_read_eeprom");
3741 /* A check for invalid values: offset too large, too many words, and not
3744 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3746 DEBUGOUT("\"words\" parameter out of bounds\n");
3747 return -E1000_ERR_EEPROM;
3750 /* FLASH reads without acquiring the semaphore are safe in 82573-based
3753 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3754 (hw->mac_type != e1000_82573)) {
3755 /* Prepare the EEPROM for reading */
3756 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3757 return -E1000_ERR_EEPROM;
3760 if(eeprom->use_eerd == TRUE) {
3761 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
3762 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3763 (hw->mac_type != e1000_82573))
3764 e1000_release_eeprom(hw);
3768 if(eeprom->type == e1000_eeprom_spi) {
3770 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3772 if(e1000_spi_eeprom_ready(hw)) {
3773 e1000_release_eeprom(hw);
3774 return -E1000_ERR_EEPROM;
3777 e1000_standby_eeprom(hw);
3779 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3780 if((eeprom->address_bits == 8) && (offset >= 128))
3781 read_opcode |= EEPROM_A8_OPCODE_SPI;
3783 /* Send the READ command (opcode + addr) */
3784 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3785 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3787 /* Read the data. The address of the eeprom internally increments with
3788 * each byte (spi) being read, saving on the overhead of eeprom setup
3789 * and tear-down. The address counter will roll over if reading beyond
3790 * the size of the eeprom, thus allowing the entire memory to be read
3791 * starting from any offset. */
3792 for (i = 0; i < words; i++) {
3793 word_in = e1000_shift_in_ee_bits(hw, 16);
3794 data[i] = (word_in >> 8) | (word_in << 8);
3796 } else if(eeprom->type == e1000_eeprom_microwire) {
3797 for (i = 0; i < words; i++) {
3798 /* Send the READ command (opcode + addr) */
3799 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3800 eeprom->opcode_bits);
3801 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3802 eeprom->address_bits);
3804 /* Read the data. For microwire, each word requires the overhead
3805 * of eeprom setup and tear-down. */
3806 data[i] = e1000_shift_in_ee_bits(hw, 16);
3807 e1000_standby_eeprom(hw);
3811 /* End this read operation */
3812 e1000_release_eeprom(hw);
3814 return E1000_SUCCESS;
3817 /******************************************************************************
3818 * Reads a 16 bit word from the EEPROM using the EERD register.
3820 * hw - Struct containing variables accessed by shared code
3821 * offset - offset of word in the EEPROM to read
3822 * data - word read from the EEPROM
3823 * words - number of words to read
3824 *****************************************************************************/
3826 e1000_read_eeprom_eerd(struct e1000_hw *hw,
3831 uint32_t i, eerd = 0;
3834 for (i = 0; i < words; i++) {
3835 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3836 E1000_EEPROM_RW_REG_START;
3838 E1000_WRITE_REG(hw, EERD, eerd);
3839 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3844 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
3851 /******************************************************************************
3852 * Writes a 16 bit word from the EEPROM using the EEWR register.
3854 * hw - Struct containing variables accessed by shared code
3855 * offset - offset of word in the EEPROM to read
3856 * data - word read from the EEPROM
3857 * words - number of words to read
3858 *****************************************************************************/
3860 e1000_write_eeprom_eewr(struct e1000_hw *hw,
3865 uint32_t register_value = 0;
3869 for (i = 0; i < words; i++) {
3870 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3871 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3872 E1000_EEPROM_RW_REG_START;
3874 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3879 E1000_WRITE_REG(hw, EEWR, register_value);
3881 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3891 /******************************************************************************
3892 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
3894 * hw - Struct containing variables accessed by shared code
3895 *****************************************************************************/
3897 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
3899 uint32_t attempts = 100000;
3900 uint32_t i, reg = 0;
3901 int32_t done = E1000_ERR_EEPROM;
3903 for(i = 0; i < attempts; i++) {
3904 if(eerd == E1000_EEPROM_POLL_READ)
3905 reg = E1000_READ_REG(hw, EERD);
3907 reg = E1000_READ_REG(hw, EEWR);
3909 if(reg & E1000_EEPROM_RW_REG_DONE) {
3910 done = E1000_SUCCESS;
3919 /***************************************************************************
3920 * Description: Determines if the onboard NVM is FLASH or EEPROM.
3922 * hw - Struct containing variables accessed by shared code
3923 ****************************************************************************/
3925 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
3929 if(hw->mac_type == e1000_82573) {
3930 eecd = E1000_READ_REG(hw, EECD);
3932 /* Isolate bits 15 & 16 */
3933 eecd = ((eecd >> 15) & 0x03);
3935 /* If both bits are set, device is Flash type */
3943 /******************************************************************************
3944 * Verifies that the EEPROM has a valid checksum
3946 * hw - Struct containing variables accessed by shared code
3948 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3949 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3951 *****************************************************************************/
3953 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3955 uint16_t checksum = 0;
3956 uint16_t i, eeprom_data;
3958 DEBUGFUNC("e1000_validate_eeprom_checksum");
3960 if ((hw->mac_type == e1000_82573) &&
3961 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
3962 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
3963 * 10h-12h. Checksum may need to be fixed. */
3964 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
3965 if ((eeprom_data & 0x10) == 0) {
3966 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
3967 * has already been fixed. If the checksum is still wrong and this
3968 * bit is a 1, we need to return bad checksum. Otherwise, we need
3969 * to set this bit to a 1 and update the checksum. */
3970 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
3971 if ((eeprom_data & 0x8000) == 0) {
3972 eeprom_data |= 0x8000;
3973 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
3974 e1000_update_eeprom_checksum(hw);
3979 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3980 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3981 DEBUGOUT("EEPROM Read Error\n");
3982 return -E1000_ERR_EEPROM;
3984 checksum += eeprom_data;
3987 if(checksum == (uint16_t) EEPROM_SUM)
3988 return E1000_SUCCESS;
3990 DEBUGOUT("EEPROM Checksum Invalid\n");
3991 return -E1000_ERR_EEPROM;
3995 /******************************************************************************
3996 * Calculates the EEPROM checksum and writes it to the EEPROM
3998 * hw - Struct containing variables accessed by shared code
4000 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4001 * Writes the difference to word offset 63 of the EEPROM.
4002 *****************************************************************************/
4004 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4006 uint16_t checksum = 0;
4007 uint16_t i, eeprom_data;
4009 DEBUGFUNC("e1000_update_eeprom_checksum");
4011 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4012 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4013 DEBUGOUT("EEPROM Read Error\n");
4014 return -E1000_ERR_EEPROM;
4016 checksum += eeprom_data;
4018 checksum = (uint16_t) EEPROM_SUM - checksum;
4019 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4020 DEBUGOUT("EEPROM Write Error\n");
4021 return -E1000_ERR_EEPROM;
4022 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4023 e1000_commit_shadow_ram(hw);
4025 return E1000_SUCCESS;
4028 /******************************************************************************
4029 * Parent function for writing words to the different EEPROM types.
4031 * hw - Struct containing variables accessed by shared code
4032 * offset - offset within the EEPROM to be written to
4033 * words - number of words to write
4034 * data - 16 bit word to be written to the EEPROM
4036 * If e1000_update_eeprom_checksum is not called after this function, the
4037 * EEPROM will most likely contain an invalid checksum.
4038 *****************************************************************************/
4040 e1000_write_eeprom(struct e1000_hw *hw,
4045 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4048 DEBUGFUNC("e1000_write_eeprom");
4050 /* A check for invalid values: offset too large, too many words, and not
4053 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4055 DEBUGOUT("\"words\" parameter out of bounds\n");
4056 return -E1000_ERR_EEPROM;
4059 /* 82573 reads only through eerd */
4060 if(eeprom->use_eewr == TRUE)
4061 return e1000_write_eeprom_eewr(hw, offset, words, data);
4063 /* Prepare the EEPROM for writing */
4064 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4065 return -E1000_ERR_EEPROM;
4067 if(eeprom->type == e1000_eeprom_microwire) {
4068 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4070 status = e1000_write_eeprom_spi(hw, offset, words, data);
4074 /* Done with writing */
4075 e1000_release_eeprom(hw);
4080 /******************************************************************************
4081 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4083 * hw - Struct containing variables accessed by shared code
4084 * offset - offset within the EEPROM to be written to
4085 * words - number of words to write
4086 * data - pointer to array of 8 bit words to be written to the EEPROM
4088 *****************************************************************************/
4090 e1000_write_eeprom_spi(struct e1000_hw *hw,
4095 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4098 DEBUGFUNC("e1000_write_eeprom_spi");
4100 while (widx < words) {
4101 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4103 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4105 e1000_standby_eeprom(hw);
4107 /* Send the WRITE ENABLE command (8 bit opcode ) */
4108 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4109 eeprom->opcode_bits);
4111 e1000_standby_eeprom(hw);
4113 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4114 if((eeprom->address_bits == 8) && (offset >= 128))
4115 write_opcode |= EEPROM_A8_OPCODE_SPI;
4117 /* Send the Write command (8-bit opcode + addr) */
4118 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4120 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4121 eeprom->address_bits);
4125 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4126 while (widx < words) {
4127 uint16_t word_out = data[widx];
4128 word_out = (word_out >> 8) | (word_out << 8);
4129 e1000_shift_out_ee_bits(hw, word_out, 16);
4132 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4133 * operation, while the smaller eeproms are capable of an 8-byte
4134 * PAGE WRITE operation. Break the inner loop to pass new address
4136 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4137 e1000_standby_eeprom(hw);
4143 return E1000_SUCCESS;
4146 /******************************************************************************
4147 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4149 * hw - Struct containing variables accessed by shared code
4150 * offset - offset within the EEPROM to be written to
4151 * words - number of words to write
4152 * data - pointer to array of 16 bit words to be written to the EEPROM
4154 *****************************************************************************/
4156 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4161 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4163 uint16_t words_written = 0;
4166 DEBUGFUNC("e1000_write_eeprom_microwire");
4168 /* Send the write enable command to the EEPROM (3-bit opcode plus
4169 * 6/8-bit dummy address beginning with 11). It's less work to include
4170 * the 11 of the dummy address as part of the opcode than it is to shift
4171 * it over the correct number of bits for the address. This puts the
4172 * EEPROM into write/erase mode.
4174 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4175 (uint16_t)(eeprom->opcode_bits + 2));
4177 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4179 /* Prepare the EEPROM */
4180 e1000_standby_eeprom(hw);
4182 while (words_written < words) {
4183 /* Send the Write command (3-bit opcode + addr) */
4184 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4185 eeprom->opcode_bits);
4187 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4188 eeprom->address_bits);
4191 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4193 /* Toggle the CS line. This in effect tells the EEPROM to execute
4194 * the previous command.
4196 e1000_standby_eeprom(hw);
4198 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4199 * signal that the command has been completed by raising the DO signal.
4200 * If DO does not go high in 10 milliseconds, then error out.
4202 for(i = 0; i < 200; i++) {
4203 eecd = E1000_READ_REG(hw, EECD);
4204 if(eecd & E1000_EECD_DO) break;
4208 DEBUGOUT("EEPROM Write did not complete\n");
4209 return -E1000_ERR_EEPROM;
4212 /* Recover from write */
4213 e1000_standby_eeprom(hw);
4218 /* Send the write disable command to the EEPROM (3-bit opcode plus
4219 * 6/8-bit dummy address beginning with 10). It's less work to include
4220 * the 10 of the dummy address as part of the opcode than it is to shift
4221 * it over the correct number of bits for the address. This takes the
4222 * EEPROM out of write/erase mode.
4224 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4225 (uint16_t)(eeprom->opcode_bits + 2));
4227 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4229 return E1000_SUCCESS;
4232 /******************************************************************************
4233 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4234 * in the eeprom cache and the non modified values in the currently active bank
4237 * hw - Struct containing variables accessed by shared code
4238 * offset - offset of word in the EEPROM to read
4239 * data - word read from the EEPROM
4240 * words - number of words to read
4241 *****************************************************************************/
4243 e1000_commit_shadow_ram(struct e1000_hw *hw)
4245 uint32_t attempts = 100000;
4249 int32_t error = E1000_SUCCESS;
4251 /* The flop register will be used to determine if flash type is STM */
4252 flop = E1000_READ_REG(hw, FLOP);
4254 if (hw->mac_type == e1000_82573) {
4255 for (i=0; i < attempts; i++) {
4256 eecd = E1000_READ_REG(hw, EECD);
4257 if ((eecd & E1000_EECD_FLUPD) == 0) {
4263 if (i == attempts) {
4264 return -E1000_ERR_EEPROM;
4267 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4268 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4269 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4272 /* Perform the flash update */
4273 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4275 for (i=0; i < attempts; i++) {
4276 eecd = E1000_READ_REG(hw, EECD);
4277 if ((eecd & E1000_EECD_FLUPD) == 0) {
4283 if (i == attempts) {
4284 return -E1000_ERR_EEPROM;
4291 /******************************************************************************
4292 * Reads the adapter's part number from the EEPROM
4294 * hw - Struct containing variables accessed by shared code
4295 * part_num - Adapter's part number
4296 *****************************************************************************/
4298 e1000_read_part_num(struct e1000_hw *hw,
4301 uint16_t offset = EEPROM_PBA_BYTE_1;
4302 uint16_t eeprom_data;
4304 DEBUGFUNC("e1000_read_part_num");
4306 /* Get word 0 from EEPROM */
4307 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4308 DEBUGOUT("EEPROM Read Error\n");
4309 return -E1000_ERR_EEPROM;
4311 /* Save word 0 in upper half of part_num */
4312 *part_num = (uint32_t) (eeprom_data << 16);
4314 /* Get word 1 from EEPROM */
4315 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
4316 DEBUGOUT("EEPROM Read Error\n");
4317 return -E1000_ERR_EEPROM;
4319 /* Save word 1 in lower half of part_num */
4320 *part_num |= eeprom_data;
4322 return E1000_SUCCESS;
4325 /******************************************************************************
4326 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4327 * second function of dual function devices
4329 * hw - Struct containing variables accessed by shared code
4330 *****************************************************************************/
4332 e1000_read_mac_addr(struct e1000_hw * hw)
4335 uint16_t eeprom_data, i;
4337 DEBUGFUNC("e1000_read_mac_addr");
4339 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4341 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4342 DEBUGOUT("EEPROM Read Error\n");
4343 return -E1000_ERR_EEPROM;
4345 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
4346 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
4348 if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
4349 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
4350 hw->perm_mac_addr[5] ^= 0x01;
4352 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
4353 hw->mac_addr[i] = hw->perm_mac_addr[i];
4354 return E1000_SUCCESS;
4357 /******************************************************************************
4358 * Initializes receive address filters.
4360 * hw - Struct containing variables accessed by shared code
4362 * Places the MAC address in receive address register 0 and clears the rest
4363 * of the receive addresss registers. Clears the multicast table. Assumes
4364 * the receiver is in reset when the routine is called.
4365 *****************************************************************************/
4367 e1000_init_rx_addrs(struct e1000_hw *hw)
4372 DEBUGFUNC("e1000_init_rx_addrs");
4374 /* Setup the receive address. */
4375 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4377 e1000_rar_set(hw, hw->mac_addr, 0);
4379 rar_num = E1000_RAR_ENTRIES;
4380 /* Zero out the other 15 receive addresses. */
4381 DEBUGOUT("Clearing RAR[1-15]\n");
4382 for(i = 1; i < rar_num; i++) {
4383 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4384 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4388 /******************************************************************************
4389 * Updates the MAC's list of multicast addresses.
4391 * hw - Struct containing variables accessed by shared code
4392 * mc_addr_list - the list of new multicast addresses
4393 * mc_addr_count - number of addresses
4394 * pad - number of bytes between addresses in the list
4395 * rar_used_count - offset where to start adding mc addresses into the RAR's
4397 * The given list replaces any existing list. Clears the last 15 receive
4398 * address registers and the multicast table. Uses receive address registers
4399 * for the first 15 multicast addresses, and hashes the rest into the
4401 *****************************************************************************/
4403 e1000_mc_addr_list_update(struct e1000_hw *hw,
4404 uint8_t *mc_addr_list,
4405 uint32_t mc_addr_count,
4407 uint32_t rar_used_count)
4409 uint32_t hash_value;
4411 uint32_t num_rar_entry;
4412 uint32_t num_mta_entry;
4414 DEBUGFUNC("e1000_mc_addr_list_update");
4416 /* Set the new number of MC addresses that we are being requested to use. */
4417 hw->num_mc_addrs = mc_addr_count;
4419 /* Clear RAR[1-15] */
4420 DEBUGOUT(" Clearing RAR[1-15]\n");
4421 num_rar_entry = E1000_RAR_ENTRIES;
4422 for(i = rar_used_count; i < num_rar_entry; i++) {
4423 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4424 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4428 DEBUGOUT(" Clearing MTA\n");
4429 num_mta_entry = E1000_NUM_MTA_REGISTERS;
4430 for(i = 0; i < num_mta_entry; i++) {
4431 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
4434 /* Add the new addresses */
4435 for(i = 0; i < mc_addr_count; i++) {
4436 DEBUGOUT(" Adding the multicast addresses:\n");
4437 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
4438 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
4439 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
4440 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
4441 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
4442 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
4443 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
4445 hash_value = e1000_hash_mc_addr(hw,
4447 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
4449 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
4451 /* Place this multicast address in the RAR if there is room, *
4452 * else put it in the MTA
4454 if (rar_used_count < num_rar_entry) {
4456 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
4460 e1000_mta_set(hw, hash_value);
4463 DEBUGOUT("MC Update Complete\n");
4466 /******************************************************************************
4467 * Hashes an address to determine its location in the multicast table
4469 * hw - Struct containing variables accessed by shared code
4470 * mc_addr - the multicast address to hash
4471 *****************************************************************************/
4473 e1000_hash_mc_addr(struct e1000_hw *hw,
4476 uint32_t hash_value = 0;
4478 /* The portion of the address that is used for the hash table is
4479 * determined by the mc_filter_type setting.
4481 switch (hw->mc_filter_type) {
4482 /* [0] [1] [2] [3] [4] [5]
4487 /* [47:36] i.e. 0x563 for above example address */
4488 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
4491 /* [46:35] i.e. 0xAC6 for above example address */
4492 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4495 /* [45:34] i.e. 0x5D8 for above example address */
4496 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4499 /* [43:32] i.e. 0x634 for above example address */
4500 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4504 hash_value &= 0xFFF;
4509 /******************************************************************************
4510 * Sets the bit in the multicast table corresponding to the hash value.
4512 * hw - Struct containing variables accessed by shared code
4513 * hash_value - Multicast address hash value
4514 *****************************************************************************/
4516 e1000_mta_set(struct e1000_hw *hw,
4517 uint32_t hash_value)
4519 uint32_t hash_bit, hash_reg;
4523 /* The MTA is a register array of 128 32-bit registers.
4524 * It is treated like an array of 4096 bits. We want to set
4525 * bit BitArray[hash_value]. So we figure out what register
4526 * the bit is in, read it, OR in the new bit, then write
4527 * back the new value. The register is determined by the
4528 * upper 7 bits of the hash value and the bit within that
4529 * register are determined by the lower 5 bits of the value.
4531 hash_reg = (hash_value >> 5) & 0x7F;
4532 hash_bit = hash_value & 0x1F;
4534 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4536 mta |= (1 << hash_bit);
4538 /* If we are on an 82544 and we are trying to write an odd offset
4539 * in the MTA, save off the previous entry before writing and
4540 * restore the old value after writing.
4542 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4543 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4544 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4545 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4547 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4551 /******************************************************************************
4552 * Puts an ethernet address into a receive address register.
4554 * hw - Struct containing variables accessed by shared code
4555 * addr - Address to put into receive address register
4556 * index - Receive address register to write
4557 *****************************************************************************/
4559 e1000_rar_set(struct e1000_hw *hw,
4563 uint32_t rar_low, rar_high;
4565 /* HW expects these in little endian so we reverse the byte order
4566 * from network order (big endian) to little endian
4568 rar_low = ((uint32_t) addr[0] |
4569 ((uint32_t) addr[1] << 8) |
4570 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4572 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4574 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4575 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4578 /******************************************************************************
4579 * Writes a value to the specified offset in the VLAN filter table.
4581 * hw - Struct containing variables accessed by shared code
4582 * offset - Offset in VLAN filer table to write
4583 * value - Value to write into VLAN filter table
4584 *****************************************************************************/
4586 e1000_write_vfta(struct e1000_hw *hw,
4592 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4593 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4594 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4595 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4597 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4601 /******************************************************************************
4602 * Clears the VLAN filer table
4604 * hw - Struct containing variables accessed by shared code
4605 *****************************************************************************/
4607 e1000_clear_vfta(struct e1000_hw *hw)
4610 uint32_t vfta_value = 0;
4611 uint32_t vfta_offset = 0;
4612 uint32_t vfta_bit_in_reg = 0;
4614 if (hw->mac_type == e1000_82573) {
4615 if (hw->mng_cookie.vlan_id != 0) {
4616 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
4617 * ID. The following operations determine which 32b entry
4618 * (i.e. offset) into the array we want to set the VLAN ID
4619 * (i.e. bit) of the manageability unit. */
4620 vfta_offset = (hw->mng_cookie.vlan_id >>
4621 E1000_VFTA_ENTRY_SHIFT) &
4622 E1000_VFTA_ENTRY_MASK;
4623 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
4624 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
4627 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4628 /* If the offset we want to clear is the same offset of the
4629 * manageability VLAN ID, then clear all bits except that of the
4630 * manageability unit */
4631 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4632 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4637 e1000_id_led_init(struct e1000_hw * hw)
4640 const uint32_t ledctl_mask = 0x000000FF;
4641 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4642 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4643 uint16_t eeprom_data, i, temp;
4644 const uint16_t led_mask = 0x0F;
4646 DEBUGFUNC("e1000_id_led_init");
4648 if(hw->mac_type < e1000_82540) {
4650 return E1000_SUCCESS;
4653 ledctl = E1000_READ_REG(hw, LEDCTL);
4654 hw->ledctl_default = ledctl;
4655 hw->ledctl_mode1 = hw->ledctl_default;
4656 hw->ledctl_mode2 = hw->ledctl_default;
4658 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4659 DEBUGOUT("EEPROM Read Error\n");
4660 return -E1000_ERR_EEPROM;
4662 if((eeprom_data== ID_LED_RESERVED_0000) ||
4663 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4664 for(i = 0; i < 4; i++) {
4665 temp = (eeprom_data >> (i << 2)) & led_mask;
4667 case ID_LED_ON1_DEF2:
4668 case ID_LED_ON1_ON2:
4669 case ID_LED_ON1_OFF2:
4670 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4671 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4673 case ID_LED_OFF1_DEF2:
4674 case ID_LED_OFF1_ON2:
4675 case ID_LED_OFF1_OFF2:
4676 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4677 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4684 case ID_LED_DEF1_ON2:
4685 case ID_LED_ON1_ON2:
4686 case ID_LED_OFF1_ON2:
4687 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4688 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4690 case ID_LED_DEF1_OFF2:
4691 case ID_LED_ON1_OFF2:
4692 case ID_LED_OFF1_OFF2:
4693 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4694 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4701 return E1000_SUCCESS;
4704 /******************************************************************************
4705 * Prepares SW controlable LED for use and saves the current state of the LED.
4707 * hw - Struct containing variables accessed by shared code
4708 *****************************************************************************/
4710 e1000_setup_led(struct e1000_hw *hw)
4713 int32_t ret_val = E1000_SUCCESS;
4715 DEBUGFUNC("e1000_setup_led");
4717 switch(hw->mac_type) {
4718 case e1000_82542_rev2_0:
4719 case e1000_82542_rev2_1:
4722 /* No setup necessary */
4726 case e1000_82541_rev_2:
4727 case e1000_82547_rev_2:
4728 /* Turn off PHY Smart Power Down (if enabled) */
4729 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4730 &hw->phy_spd_default);
4733 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4734 (uint16_t)(hw->phy_spd_default &
4735 ~IGP01E1000_GMII_SPD));
4740 if(hw->media_type == e1000_media_type_fiber) {
4741 ledctl = E1000_READ_REG(hw, LEDCTL);
4742 /* Save current LEDCTL settings */
4743 hw->ledctl_default = ledctl;
4745 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4746 E1000_LEDCTL_LED0_BLINK |
4747 E1000_LEDCTL_LED0_MODE_MASK);
4748 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4749 E1000_LEDCTL_LED0_MODE_SHIFT);
4750 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4751 } else if(hw->media_type == e1000_media_type_copper)
4752 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4756 return E1000_SUCCESS;
4759 /******************************************************************************
4760 * Restores the saved state of the SW controlable LED.
4762 * hw - Struct containing variables accessed by shared code
4763 *****************************************************************************/
4765 e1000_cleanup_led(struct e1000_hw *hw)
4767 int32_t ret_val = E1000_SUCCESS;
4769 DEBUGFUNC("e1000_cleanup_led");
4771 switch(hw->mac_type) {
4772 case e1000_82542_rev2_0:
4773 case e1000_82542_rev2_1:
4776 /* No cleanup necessary */
4780 case e1000_82541_rev_2:
4781 case e1000_82547_rev_2:
4782 /* Turn on PHY Smart Power Down (if previously enabled) */
4783 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4784 hw->phy_spd_default);
4789 /* Restore LEDCTL settings */
4790 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4794 return E1000_SUCCESS;
4797 /******************************************************************************
4798 * Turns on the software controllable LED
4800 * hw - Struct containing variables accessed by shared code
4801 *****************************************************************************/
4803 e1000_led_on(struct e1000_hw *hw)
4805 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4807 DEBUGFUNC("e1000_led_on");
4809 switch(hw->mac_type) {
4810 case e1000_82542_rev2_0:
4811 case e1000_82542_rev2_1:
4813 /* Set SW Defineable Pin 0 to turn on the LED */
4814 ctrl |= E1000_CTRL_SWDPIN0;
4815 ctrl |= E1000_CTRL_SWDPIO0;
4818 if(hw->media_type == e1000_media_type_fiber) {
4819 /* Set SW Defineable Pin 0 to turn on the LED */
4820 ctrl |= E1000_CTRL_SWDPIN0;
4821 ctrl |= E1000_CTRL_SWDPIO0;
4823 /* Clear SW Defineable Pin 0 to turn on the LED */
4824 ctrl &= ~E1000_CTRL_SWDPIN0;
4825 ctrl |= E1000_CTRL_SWDPIO0;
4829 if(hw->media_type == e1000_media_type_fiber) {
4830 /* Clear SW Defineable Pin 0 to turn on the LED */
4831 ctrl &= ~E1000_CTRL_SWDPIN0;
4832 ctrl |= E1000_CTRL_SWDPIO0;
4833 } else if(hw->media_type == e1000_media_type_copper) {
4834 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4835 return E1000_SUCCESS;
4840 E1000_WRITE_REG(hw, CTRL, ctrl);
4842 return E1000_SUCCESS;
4845 /******************************************************************************
4846 * Turns off the software controllable LED
4848 * hw - Struct containing variables accessed by shared code
4849 *****************************************************************************/
4851 e1000_led_off(struct e1000_hw *hw)
4853 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4855 DEBUGFUNC("e1000_led_off");
4857 switch(hw->mac_type) {
4858 case e1000_82542_rev2_0:
4859 case e1000_82542_rev2_1:
4861 /* Clear SW Defineable Pin 0 to turn off the LED */
4862 ctrl &= ~E1000_CTRL_SWDPIN0;
4863 ctrl |= E1000_CTRL_SWDPIO0;
4866 if(hw->media_type == e1000_media_type_fiber) {
4867 /* Clear SW Defineable Pin 0 to turn off the LED */
4868 ctrl &= ~E1000_CTRL_SWDPIN0;
4869 ctrl |= E1000_CTRL_SWDPIO0;
4871 /* Set SW Defineable Pin 0 to turn off the LED */
4872 ctrl |= E1000_CTRL_SWDPIN0;
4873 ctrl |= E1000_CTRL_SWDPIO0;
4877 if(hw->media_type == e1000_media_type_fiber) {
4878 /* Set SW Defineable Pin 0 to turn off the LED */
4879 ctrl |= E1000_CTRL_SWDPIN0;
4880 ctrl |= E1000_CTRL_SWDPIO0;
4881 } else if(hw->media_type == e1000_media_type_copper) {
4882 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4883 return E1000_SUCCESS;
4888 E1000_WRITE_REG(hw, CTRL, ctrl);
4890 return E1000_SUCCESS;
4893 /******************************************************************************
4894 * Clears all hardware statistics counters.
4896 * hw - Struct containing variables accessed by shared code
4897 *****************************************************************************/
4899 e1000_clear_hw_cntrs(struct e1000_hw *hw)
4901 volatile uint32_t temp;
4903 temp = E1000_READ_REG(hw, CRCERRS);
4904 temp = E1000_READ_REG(hw, SYMERRS);
4905 temp = E1000_READ_REG(hw, MPC);
4906 temp = E1000_READ_REG(hw, SCC);
4907 temp = E1000_READ_REG(hw, ECOL);
4908 temp = E1000_READ_REG(hw, MCC);
4909 temp = E1000_READ_REG(hw, LATECOL);
4910 temp = E1000_READ_REG(hw, COLC);
4911 temp = E1000_READ_REG(hw, DC);
4912 temp = E1000_READ_REG(hw, SEC);
4913 temp = E1000_READ_REG(hw, RLEC);
4914 temp = E1000_READ_REG(hw, XONRXC);
4915 temp = E1000_READ_REG(hw, XONTXC);
4916 temp = E1000_READ_REG(hw, XOFFRXC);
4917 temp = E1000_READ_REG(hw, XOFFTXC);
4918 temp = E1000_READ_REG(hw, FCRUC);
4919 temp = E1000_READ_REG(hw, PRC64);
4920 temp = E1000_READ_REG(hw, PRC127);
4921 temp = E1000_READ_REG(hw, PRC255);
4922 temp = E1000_READ_REG(hw, PRC511);
4923 temp = E1000_READ_REG(hw, PRC1023);
4924 temp = E1000_READ_REG(hw, PRC1522);
4925 temp = E1000_READ_REG(hw, GPRC);
4926 temp = E1000_READ_REG(hw, BPRC);
4927 temp = E1000_READ_REG(hw, MPRC);
4928 temp = E1000_READ_REG(hw, GPTC);
4929 temp = E1000_READ_REG(hw, GORCL);
4930 temp = E1000_READ_REG(hw, GORCH);
4931 temp = E1000_READ_REG(hw, GOTCL);
4932 temp = E1000_READ_REG(hw, GOTCH);
4933 temp = E1000_READ_REG(hw, RNBC);
4934 temp = E1000_READ_REG(hw, RUC);
4935 temp = E1000_READ_REG(hw, RFC);
4936 temp = E1000_READ_REG(hw, ROC);
4937 temp = E1000_READ_REG(hw, RJC);
4938 temp = E1000_READ_REG(hw, TORL);
4939 temp = E1000_READ_REG(hw, TORH);
4940 temp = E1000_READ_REG(hw, TOTL);
4941 temp = E1000_READ_REG(hw, TOTH);
4942 temp = E1000_READ_REG(hw, TPR);
4943 temp = E1000_READ_REG(hw, TPT);
4944 temp = E1000_READ_REG(hw, PTC64);
4945 temp = E1000_READ_REG(hw, PTC127);
4946 temp = E1000_READ_REG(hw, PTC255);
4947 temp = E1000_READ_REG(hw, PTC511);
4948 temp = E1000_READ_REG(hw, PTC1023);
4949 temp = E1000_READ_REG(hw, PTC1522);
4950 temp = E1000_READ_REG(hw, MPTC);
4951 temp = E1000_READ_REG(hw, BPTC);
4953 if(hw->mac_type < e1000_82543) return;
4955 temp = E1000_READ_REG(hw, ALGNERRC);
4956 temp = E1000_READ_REG(hw, RXERRC);
4957 temp = E1000_READ_REG(hw, TNCRS);
4958 temp = E1000_READ_REG(hw, CEXTERR);
4959 temp = E1000_READ_REG(hw, TSCTC);
4960 temp = E1000_READ_REG(hw, TSCTFC);
4962 if(hw->mac_type <= e1000_82544) return;
4964 temp = E1000_READ_REG(hw, MGTPRC);
4965 temp = E1000_READ_REG(hw, MGTPDC);
4966 temp = E1000_READ_REG(hw, MGTPTC);
4968 if(hw->mac_type <= e1000_82547_rev_2) return;
4970 temp = E1000_READ_REG(hw, IAC);
4971 temp = E1000_READ_REG(hw, ICRXOC);
4972 temp = E1000_READ_REG(hw, ICRXPTC);
4973 temp = E1000_READ_REG(hw, ICRXATC);
4974 temp = E1000_READ_REG(hw, ICTXPTC);
4975 temp = E1000_READ_REG(hw, ICTXATC);
4976 temp = E1000_READ_REG(hw, ICTXQEC);
4977 temp = E1000_READ_REG(hw, ICTXQMTC);
4978 temp = E1000_READ_REG(hw, ICRXDMTC);
4982 /******************************************************************************
4983 * Resets Adaptive IFS to its default state.
4985 * hw - Struct containing variables accessed by shared code
4987 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4988 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4989 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4990 * before calling this function.
4991 *****************************************************************************/
4993 e1000_reset_adaptive(struct e1000_hw *hw)
4995 DEBUGFUNC("e1000_reset_adaptive");
4997 if(hw->adaptive_ifs) {
4998 if(!hw->ifs_params_forced) {
4999 hw->current_ifs_val = 0;
5000 hw->ifs_min_val = IFS_MIN;
5001 hw->ifs_max_val = IFS_MAX;
5002 hw->ifs_step_size = IFS_STEP;
5003 hw->ifs_ratio = IFS_RATIO;
5005 hw->in_ifs_mode = FALSE;
5006 E1000_WRITE_REG(hw, AIT, 0);
5008 DEBUGOUT("Not in Adaptive IFS mode!\n");
5012 /******************************************************************************
5013 * Called during the callback/watchdog routine to update IFS value based on
5014 * the ratio of transmits to collisions.
5016 * hw - Struct containing variables accessed by shared code
5017 * tx_packets - Number of transmits since last callback
5018 * total_collisions - Number of collisions since last callback
5019 *****************************************************************************/
5021 e1000_update_adaptive(struct e1000_hw *hw)
5023 DEBUGFUNC("e1000_update_adaptive");
5025 if(hw->adaptive_ifs) {
5026 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5027 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5028 hw->in_ifs_mode = TRUE;
5029 if(hw->current_ifs_val < hw->ifs_max_val) {
5030 if(hw->current_ifs_val == 0)
5031 hw->current_ifs_val = hw->ifs_min_val;
5033 hw->current_ifs_val += hw->ifs_step_size;
5034 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5038 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5039 hw->current_ifs_val = 0;
5040 hw->in_ifs_mode = FALSE;
5041 E1000_WRITE_REG(hw, AIT, 0);
5045 DEBUGOUT("Not in Adaptive IFS mode!\n");
5049 /******************************************************************************
5050 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5052 * hw - Struct containing variables accessed by shared code
5053 * frame_len - The length of the frame in question
5054 * mac_addr - The Ethernet destination address of the frame in question
5055 *****************************************************************************/
5057 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5058 struct e1000_hw_stats *stats,
5064 /* First adjust the frame length. */
5066 /* We need to adjust the statistics counters, since the hardware
5067 * counters overcount this packet as a CRC error and undercount
5068 * the packet as a good packet
5070 /* This packet should not be counted as a CRC error. */
5072 /* This packet does count as a Good Packet Received. */
5075 /* Adjust the Good Octets received counters */
5076 carry_bit = 0x80000000 & stats->gorcl;
5077 stats->gorcl += frame_len;
5078 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5079 * Received Count) was one before the addition,
5080 * AND it is zero after, then we lost the carry out,
5081 * need to add one to Gorch (Good Octets Received Count High).
5082 * This could be simplified if all environments supported
5085 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5087 /* Is this a broadcast or multicast? Check broadcast first,
5088 * since the test for a multicast frame will test positive on
5089 * a broadcast frame.
5091 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5092 /* Broadcast packet */
5094 else if(*mac_addr & 0x01)
5095 /* Multicast packet */
5098 if(frame_len == hw->max_frame_size) {
5099 /* In this case, the hardware has overcounted the number of
5106 /* Adjust the bin counters when the extra byte put the frame in the
5107 * wrong bin. Remember that the frame_len was adjusted above.
5109 if(frame_len == 64) {
5112 } else if(frame_len == 127) {
5115 } else if(frame_len == 255) {
5118 } else if(frame_len == 511) {
5121 } else if(frame_len == 1023) {
5124 } else if(frame_len == 1522) {
5129 /******************************************************************************
5130 * Gets the current PCI bus type, speed, and width of the hardware
5132 * hw - Struct containing variables accessed by shared code
5133 *****************************************************************************/
5135 e1000_get_bus_info(struct e1000_hw *hw)
5139 switch (hw->mac_type) {
5140 case e1000_82542_rev2_0:
5141 case e1000_82542_rev2_1:
5142 hw->bus_type = e1000_bus_type_unknown;
5143 hw->bus_speed = e1000_bus_speed_unknown;
5144 hw->bus_width = e1000_bus_width_unknown;
5147 hw->bus_type = e1000_bus_type_pci_express;
5148 hw->bus_speed = e1000_bus_speed_2500;
5149 hw->bus_width = e1000_bus_width_pciex_4;
5152 status = E1000_READ_REG(hw, STATUS);
5153 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5154 e1000_bus_type_pcix : e1000_bus_type_pci;
5156 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5157 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5158 e1000_bus_speed_66 : e1000_bus_speed_120;
5159 } else if(hw->bus_type == e1000_bus_type_pci) {
5160 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5161 e1000_bus_speed_66 : e1000_bus_speed_33;
5163 switch (status & E1000_STATUS_PCIX_SPEED) {
5164 case E1000_STATUS_PCIX_SPEED_66:
5165 hw->bus_speed = e1000_bus_speed_66;
5167 case E1000_STATUS_PCIX_SPEED_100:
5168 hw->bus_speed = e1000_bus_speed_100;
5170 case E1000_STATUS_PCIX_SPEED_133:
5171 hw->bus_speed = e1000_bus_speed_133;
5174 hw->bus_speed = e1000_bus_speed_reserved;
5178 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5179 e1000_bus_width_64 : e1000_bus_width_32;
5183 /******************************************************************************
5184 * Reads a value from one of the devices registers using port I/O (as opposed
5185 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5187 * hw - Struct containing variables accessed by shared code
5188 * offset - offset to read from
5189 *****************************************************************************/
5191 e1000_read_reg_io(struct e1000_hw *hw,
5194 unsigned long io_addr = hw->io_base;
5195 unsigned long io_data = hw->io_base + 4;
5197 e1000_io_write(hw, io_addr, offset);
5198 return e1000_io_read(hw, io_data);
5201 /******************************************************************************
5202 * Writes a value to one of the devices registers using port I/O (as opposed to
5203 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5205 * hw - Struct containing variables accessed by shared code
5206 * offset - offset to write to
5207 * value - value to write
5208 *****************************************************************************/
5210 e1000_write_reg_io(struct e1000_hw *hw,
5214 unsigned long io_addr = hw->io_base;
5215 unsigned long io_data = hw->io_base + 4;
5217 e1000_io_write(hw, io_addr, offset);
5218 e1000_io_write(hw, io_data, value);
5222 /******************************************************************************
5223 * Estimates the cable length.
5225 * hw - Struct containing variables accessed by shared code
5226 * min_length - The estimated minimum length
5227 * max_length - The estimated maximum length
5229 * returns: - E1000_ERR_XXX
5232 * This function always returns a ranged length (minimum & maximum).
5233 * So for M88 phy's, this function interprets the one value returned from the
5234 * register to the minimum and maximum range.
5235 * For IGP phy's, the function calculates the range by the AGC registers.
5236 *****************************************************************************/
5238 e1000_get_cable_length(struct e1000_hw *hw,
5239 uint16_t *min_length,
5240 uint16_t *max_length)
5243 uint16_t agc_value = 0;
5244 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5245 uint16_t i, phy_data;
5246 uint16_t cable_length;
5248 DEBUGFUNC("e1000_get_cable_length");
5250 *min_length = *max_length = 0;
5252 /* Use old method for Phy older than IGP */
5253 if(hw->phy_type == e1000_phy_m88) {
5255 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5259 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5260 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
5262 /* Convert the enum value to ranged values */
5263 switch (cable_length) {
5264 case e1000_cable_length_50:
5266 *max_length = e1000_igp_cable_length_50;
5268 case e1000_cable_length_50_80:
5269 *min_length = e1000_igp_cable_length_50;
5270 *max_length = e1000_igp_cable_length_80;
5272 case e1000_cable_length_80_110:
5273 *min_length = e1000_igp_cable_length_80;
5274 *max_length = e1000_igp_cable_length_110;
5276 case e1000_cable_length_110_140:
5277 *min_length = e1000_igp_cable_length_110;
5278 *max_length = e1000_igp_cable_length_140;
5280 case e1000_cable_length_140:
5281 *min_length = e1000_igp_cable_length_140;
5282 *max_length = e1000_igp_cable_length_170;
5285 return -E1000_ERR_PHY;
5288 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5289 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5290 {IGP01E1000_PHY_AGC_A,
5291 IGP01E1000_PHY_AGC_B,
5292 IGP01E1000_PHY_AGC_C,
5293 IGP01E1000_PHY_AGC_D};
5294 /* Read the AGC registers for all channels */
5295 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5297 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5301 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5303 /* Array bound check. */
5304 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5306 return -E1000_ERR_PHY;
5308 agc_value += cur_agc;
5310 /* Update minimal AGC value. */
5311 if(min_agc > cur_agc)
5315 /* Remove the minimal AGC result for length < 50m */
5316 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5317 agc_value -= min_agc;
5319 /* Get the average length of the remaining 3 channels */
5320 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5322 /* Get the average length of all the 4 channels. */
5323 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5326 /* Set the range of the calculated length. */
5327 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5328 IGP01E1000_AGC_RANGE) > 0) ?
5329 (e1000_igp_cable_length_table[agc_value] -
5330 IGP01E1000_AGC_RANGE) : 0;
5331 *max_length = e1000_igp_cable_length_table[agc_value] +
5332 IGP01E1000_AGC_RANGE;
5335 return E1000_SUCCESS;
5338 /******************************************************************************
5339 * Check the cable polarity
5341 * hw - Struct containing variables accessed by shared code
5342 * polarity - output parameter : 0 - Polarity is not reversed
5343 * 1 - Polarity is reversed.
5345 * returns: - E1000_ERR_XXX
5348 * For phy's older then IGP, this function simply reads the polarity bit in the
5349 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5350 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5351 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5352 * IGP01E1000_PHY_PCS_INIT_REG.
5353 *****************************************************************************/
5355 e1000_check_polarity(struct e1000_hw *hw,
5361 DEBUGFUNC("e1000_check_polarity");
5363 if(hw->phy_type == e1000_phy_m88) {
5364 /* return the Polarity bit in the Status register. */
5365 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5369 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
5370 M88E1000_PSSR_REV_POLARITY_SHIFT;
5371 } else if(hw->phy_type == e1000_phy_igp ||
5372 hw->phy_type == e1000_phy_igp_2) {
5373 /* Read the Status register to check the speed */
5374 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5379 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5380 * find the polarity status */
5381 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5382 IGP01E1000_PSSR_SPEED_1000MBPS) {
5384 /* Read the GIG initialization PCS register (0x00B4) */
5385 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5390 /* Check the polarity bits */
5391 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
5393 /* For 10 Mbps, read the polarity bit in the status register. (for
5394 * 100 Mbps this bit is always 0) */
5395 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
5398 return E1000_SUCCESS;
5401 /******************************************************************************
5402 * Check if Downshift occured
5404 * hw - Struct containing variables accessed by shared code
5405 * downshift - output parameter : 0 - No Downshift ocured.
5406 * 1 - Downshift ocured.
5408 * returns: - E1000_ERR_XXX
5411 * For phy's older then IGP, this function reads the Downshift bit in the Phy
5412 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5413 * Link Health register. In IGP this bit is latched high, so the driver must
5414 * read it immediately after link is established.
5415 *****************************************************************************/
5417 e1000_check_downshift(struct e1000_hw *hw)
5422 DEBUGFUNC("e1000_check_downshift");
5424 if(hw->phy_type == e1000_phy_igp ||
5425 hw->phy_type == e1000_phy_igp_2) {
5426 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5431 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5432 } else if(hw->phy_type == e1000_phy_m88) {
5433 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5438 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5439 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5442 return E1000_SUCCESS;
5445 /*****************************************************************************
5447 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5448 * gigabit link is achieved to improve link quality.
5450 * hw: Struct containing variables accessed by shared code
5452 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5453 * E1000_SUCCESS at any other case.
5455 ****************************************************************************/
5458 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
5462 uint16_t phy_data, phy_saved_data, speed, duplex, i;
5463 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5464 {IGP01E1000_PHY_AGC_PARAM_A,
5465 IGP01E1000_PHY_AGC_PARAM_B,
5466 IGP01E1000_PHY_AGC_PARAM_C,
5467 IGP01E1000_PHY_AGC_PARAM_D};
5468 uint16_t min_length, max_length;
5470 DEBUGFUNC("e1000_config_dsp_after_link_change");
5472 if(hw->phy_type != e1000_phy_igp)
5473 return E1000_SUCCESS;
5476 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5478 DEBUGOUT("Error getting link speed and duplex\n");
5482 if(speed == SPEED_1000) {
5484 e1000_get_cable_length(hw, &min_length, &max_length);
5486 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
5487 min_length >= e1000_igp_cable_length_50) {
5489 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5490 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5495 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5497 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5502 hw->dsp_config_state = e1000_dsp_config_activated;
5505 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
5506 (min_length < e1000_igp_cable_length_50)) {
5508 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5509 uint32_t idle_errs = 0;
5511 /* clear previous idle error counts */
5512 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5517 for(i = 0; i < ffe_idle_err_timeout; i++) {
5519 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5524 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5525 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5526 hw->ffe_config_state = e1000_ffe_config_active;
5528 ret_val = e1000_write_phy_reg(hw,
5529 IGP01E1000_PHY_DSP_FFE,
5530 IGP01E1000_PHY_DSP_FFE_CM_CP);
5537 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5542 if(hw->dsp_config_state == e1000_dsp_config_activated) {
5543 /* Save off the current value of register 0x2F5B to be restored at
5544 * the end of the routines. */
5545 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5550 /* Disable the PHY transmitter */
5551 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5558 ret_val = e1000_write_phy_reg(hw, 0x0000,
5559 IGP01E1000_IEEE_FORCE_GIGA);
5562 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5563 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5567 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5568 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5570 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5575 ret_val = e1000_write_phy_reg(hw, 0x0000,
5576 IGP01E1000_IEEE_RESTART_AUTONEG);
5582 /* Now enable the transmitter */
5583 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5588 hw->dsp_config_state = e1000_dsp_config_enabled;
5591 if(hw->ffe_config_state == e1000_ffe_config_active) {
5592 /* Save off the current value of register 0x2F5B to be restored at
5593 * the end of the routines. */
5594 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5599 /* Disable the PHY transmitter */
5600 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5607 ret_val = e1000_write_phy_reg(hw, 0x0000,
5608 IGP01E1000_IEEE_FORCE_GIGA);
5611 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5612 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5616 ret_val = e1000_write_phy_reg(hw, 0x0000,
5617 IGP01E1000_IEEE_RESTART_AUTONEG);
5623 /* Now enable the transmitter */
5624 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5629 hw->ffe_config_state = e1000_ffe_config_enabled;
5632 return E1000_SUCCESS;
5635 /*****************************************************************************
5636 * Set PHY to class A mode
5637 * Assumes the following operations will follow to enable the new class mode.
5638 * 1. Do a PHY soft reset
5639 * 2. Restart auto-negotiation or force link.
5641 * hw - Struct containing variables accessed by shared code
5642 ****************************************************************************/
5644 e1000_set_phy_mode(struct e1000_hw *hw)
5647 uint16_t eeprom_data;
5649 DEBUGFUNC("e1000_set_phy_mode");
5651 if((hw->mac_type == e1000_82545_rev_3) &&
5652 (hw->media_type == e1000_media_type_copper)) {
5653 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5658 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5659 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5660 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5663 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5667 hw->phy_reset_disable = FALSE;
5671 return E1000_SUCCESS;
5674 /*****************************************************************************
5676 * This function sets the lplu state according to the active flag. When
5677 * activating lplu this function also disables smart speed and vise versa.
5678 * lplu will not be activated unless the device autonegotiation advertisment
5679 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5680 * hw: Struct containing variables accessed by shared code
5681 * active - true to enable lplu false to disable lplu.
5683 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5684 * E1000_SUCCESS at any other case.
5686 ****************************************************************************/
5689 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5694 DEBUGFUNC("e1000_set_d3_lplu_state");
5696 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
5697 return E1000_SUCCESS;
5699 /* During driver activity LPLU should not be used or it will attain link
5700 * from the lowest speeds starting from 10Mbps. The capability is used for
5701 * Dx transitions and states */
5702 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
5703 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5707 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5713 if(hw->mac_type == e1000_82541_rev_2 ||
5714 hw->mac_type == e1000_82547_rev_2) {
5715 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5716 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5720 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5721 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5727 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5728 * Dx states where the power conservation is most important. During
5729 * driver activity we should enable SmartSpeed, so performance is
5731 if (hw->smart_speed == e1000_smart_speed_on) {
5732 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5737 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5738 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5742 } else if (hw->smart_speed == e1000_smart_speed_off) {
5743 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5748 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5749 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5755 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5756 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5757 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5759 if(hw->mac_type == e1000_82541_rev_2 ||
5760 hw->mac_type == e1000_82547_rev_2) {
5761 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5762 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5766 phy_data |= IGP02E1000_PM_D3_LPLU;
5767 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5773 /* When LPLU is enabled we should disable SmartSpeed */
5774 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5778 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5779 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5784 return E1000_SUCCESS;
5787 /*****************************************************************************
5789 * This function sets the lplu d0 state according to the active flag. When
5790 * activating lplu this function also disables smart speed and vise versa.
5791 * lplu will not be activated unless the device autonegotiation advertisment
5792 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5793 * hw: Struct containing variables accessed by shared code
5794 * active - true to enable lplu false to disable lplu.
5796 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5797 * E1000_SUCCESS at any other case.
5799 ****************************************************************************/
5802 e1000_set_d0_lplu_state(struct e1000_hw *hw,
5807 DEBUGFUNC("e1000_set_d0_lplu_state");
5809 if(hw->mac_type <= e1000_82547_rev_2)
5810 return E1000_SUCCESS;
5812 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5817 phy_data &= ~IGP02E1000_PM_D0_LPLU;
5818 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
5822 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5823 * Dx states where the power conservation is most important. During
5824 * driver activity we should enable SmartSpeed, so performance is
5826 if (hw->smart_speed == e1000_smart_speed_on) {
5827 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5832 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5833 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5837 } else if (hw->smart_speed == e1000_smart_speed_off) {
5838 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5843 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5844 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5853 phy_data |= IGP02E1000_PM_D0_LPLU;
5854 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
5858 /* When LPLU is enabled we should disable SmartSpeed */
5859 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5863 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5864 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5869 return E1000_SUCCESS;
5872 /******************************************************************************
5873 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5875 * hw - Struct containing variables accessed by shared code
5876 *****************************************************************************/
5878 e1000_set_vco_speed(struct e1000_hw *hw)
5881 uint16_t default_page = 0;
5884 DEBUGFUNC("e1000_set_vco_speed");
5886 switch(hw->mac_type) {
5887 case e1000_82545_rev_3:
5888 case e1000_82546_rev_3:
5891 return E1000_SUCCESS;
5894 /* Set PHY register 30, page 5, bit 8 to 0 */
5896 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
5900 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
5904 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5908 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5909 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5913 /* Set PHY register 30, page 4, bit 11 to 1 */
5915 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
5919 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
5923 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5924 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
5928 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
5932 return E1000_SUCCESS;
5936 /*****************************************************************************
5937 * This function reads the cookie from ARC ram.
5939 * returns: - E1000_SUCCESS .
5940 ****************************************************************************/
5942 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
5945 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
5946 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
5948 length = (length >> 2);
5949 offset = (offset >> 2);
5951 for (i = 0; i < length; i++) {
5952 *((uint32_t *) buffer + i) =
5953 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
5955 return E1000_SUCCESS;
5959 /*****************************************************************************
5960 * This function checks whether the HOST IF is enabled for command operaton
5961 * and also checks whether the previous command is completed.
5962 * It busy waits in case of previous command is not completed.
5964 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
5966 * - E1000_SUCCESS for success.
5967 ****************************************************************************/
5969 e1000_mng_enable_host_if(struct e1000_hw * hw)
5974 /* Check that the host interface is enabled. */
5975 hicr = E1000_READ_REG(hw, HICR);
5976 if ((hicr & E1000_HICR_EN) == 0) {
5977 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
5978 return -E1000_ERR_HOST_INTERFACE_COMMAND;
5980 /* check the previous command is completed */
5981 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
5982 hicr = E1000_READ_REG(hw, HICR);
5983 if (!(hicr & E1000_HICR_C))
5988 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
5989 DEBUGOUT("Previous command timeout failed .\n");
5990 return -E1000_ERR_HOST_INTERFACE_COMMAND;
5992 return E1000_SUCCESS;
5995 /*****************************************************************************
5996 * This function writes the buffer content at the offset given on the host if.
5997 * It also does alignment considerations to do the writes in most efficient way.
5998 * Also fills up the sum of the buffer in *buffer parameter.
6000 * returns - E1000_SUCCESS for success.
6001 ****************************************************************************/
6003 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6004 uint16_t length, uint16_t offset, uint8_t *sum)
6007 uint8_t *bufptr = buffer;
6009 uint16_t remaining, i, j, prev_bytes;
6011 /* sum = only sum of the data and it is not checksum */
6013 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6014 return -E1000_ERR_PARAM;
6017 tmp = (uint8_t *)&data;
6018 prev_bytes = offset & 0x3;
6023 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6024 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6025 *(tmp + j) = *bufptr++;
6028 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6029 length -= j - prev_bytes;
6033 remaining = length & 0x3;
6034 length -= remaining;
6036 /* Calculate length in DWORDs */
6039 /* The device driver writes the relevant command block into the
6041 for (i = 0; i < length; i++) {
6042 for (j = 0; j < sizeof(uint32_t); j++) {
6043 *(tmp + j) = *bufptr++;
6047 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6050 for (j = 0; j < sizeof(uint32_t); j++) {
6052 *(tmp + j) = *bufptr++;
6058 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6061 return E1000_SUCCESS;
6065 /*****************************************************************************
6066 * This function writes the command header after does the checksum calculation.
6068 * returns - E1000_SUCCESS for success.
6069 ****************************************************************************/
6071 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6072 struct e1000_host_mng_command_header * hdr)
6078 /* Write the whole command header structure which includes sum of
6081 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6083 sum = hdr->checksum;
6086 buffer = (uint8_t *) hdr;
6091 hdr->checksum = 0 - sum;
6094 /* The device driver writes the relevant command block into the ram area. */
6095 for (i = 0; i < length; i++)
6096 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6098 return E1000_SUCCESS;
6102 /*****************************************************************************
6103 * This function indicates to ARC that a new command is pending which completes
6104 * one write operation by the driver.
6106 * returns - E1000_SUCCESS for success.
6107 ****************************************************************************/
6109 e1000_mng_write_commit(
6110 struct e1000_hw * hw)
6114 hicr = E1000_READ_REG(hw, HICR);
6115 /* Setting this bit tells the ARC that a new command is pending. */
6116 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6118 return E1000_SUCCESS;
6122 /*****************************************************************************
6123 * This function checks the mode of the firmware.
6125 * returns - TRUE when the mode is IAMT or FALSE.
6126 ****************************************************************************/
6128 e1000_check_mng_mode(
6129 struct e1000_hw *hw)
6133 fwsm = E1000_READ_REG(hw, FWSM);
6135 if((fwsm & E1000_FWSM_MODE_MASK) ==
6136 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6143 /*****************************************************************************
6144 * This function writes the dhcp info .
6145 ****************************************************************************/
6147 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
6151 struct e1000_host_mng_command_header hdr;
6153 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6154 hdr.command_length = length;
6159 ret_val = e1000_mng_enable_host_if(hw);
6160 if (ret_val == E1000_SUCCESS) {
6161 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6163 if (ret_val == E1000_SUCCESS) {
6164 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
6165 if (ret_val == E1000_SUCCESS)
6166 ret_val = e1000_mng_write_commit(hw);
6173 /*****************************************************************************
6174 * This function calculates the checksum.
6176 * returns - checksum of buffer contents.
6177 ****************************************************************************/
6179 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
6187 for (i=0; i < length; i++)
6190 return (uint8_t) (0 - sum);
6193 /*****************************************************************************
6194 * This function checks whether tx pkt filtering needs to be enabled or not.
6196 * returns - TRUE for packet filtering or FALSE.
6197 ****************************************************************************/
6199 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
6201 /* called in init as well as watchdog timer functions */
6203 int32_t ret_val, checksum;
6204 boolean_t tx_filter = FALSE;
6205 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
6206 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
6208 if (e1000_check_mng_mode(hw)) {
6209 ret_val = e1000_mng_enable_host_if(hw);
6210 if (ret_val == E1000_SUCCESS) {
6211 ret_val = e1000_host_if_read_cookie(hw, buffer);
6212 if (ret_val == E1000_SUCCESS) {
6213 checksum = hdr->checksum;
6215 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
6216 checksum == e1000_calculate_mng_checksum((char *)buffer,
6217 E1000_MNG_DHCP_COOKIE_LENGTH)) {
6219 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
6228 hw->tx_pkt_filtering = tx_filter;
6232 /******************************************************************************
6233 * Verifies the hardware needs to allow ARPs to be processed by the host
6235 * hw - Struct containing variables accessed by shared code
6237 * returns: - TRUE/FALSE
6239 *****************************************************************************/
6241 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
6244 uint32_t fwsm, factps;
6246 if (hw->asf_firmware_present) {
6247 manc = E1000_READ_REG(hw, MANC);
6249 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
6250 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
6252 if (e1000_arc_subsystem_valid(hw) == TRUE) {
6253 fwsm = E1000_READ_REG(hw, FWSM);
6254 factps = E1000_READ_REG(hw, FACTPS);
6256 if (((fwsm & E1000_FWSM_MODE_MASK) ==
6257 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
6258 (factps & E1000_FACTPS_MNGCG))
6261 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
6268 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
6271 uint16_t mii_status_reg;
6274 /* Polarity reversal workaround for forced 10F/10H links. */
6276 /* Disable the transmitter on the PHY */
6278 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6281 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
6285 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6289 /* This loop will early-out if the NO link condition has been met. */
6290 for(i = PHY_FORCE_TIME; i > 0; i--) {
6291 /* Read the MII Status Register and wait for Link Status bit
6295 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6299 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6303 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
6304 msec_delay_irq(100);
6307 /* Recommended delay time after link has been lost */
6308 msec_delay_irq(1000);
6310 /* Now we will re-enable th transmitter on the PHY */
6312 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6316 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
6320 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
6324 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
6328 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6332 /* This loop will early-out if the link condition has been met. */
6333 for(i = PHY_FORCE_TIME; i > 0; i--) {
6334 /* Read the MII Status Register and wait for Link Status bit
6338 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6342 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6346 if(mii_status_reg & MII_SR_LINK_STATUS) break;
6347 msec_delay_irq(100);
6349 return E1000_SUCCESS;
6352 /***************************************************************************
6354 * Disables PCI-Express master access.
6356 * hw: Struct containing variables accessed by shared code
6360 ***************************************************************************/
6362 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
6366 DEBUGFUNC("e1000_set_pci_express_master_disable");
6368 if (hw->bus_type != e1000_bus_type_pci_express)
6371 ctrl = E1000_READ_REG(hw, CTRL);
6372 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
6373 E1000_WRITE_REG(hw, CTRL, ctrl);
6376 /***************************************************************************
6378 * Enables PCI-Express master access.
6380 * hw: Struct containing variables accessed by shared code
6384 ***************************************************************************/
6386 e1000_enable_pciex_master(struct e1000_hw *hw)
6390 DEBUGFUNC("e1000_enable_pciex_master");
6392 if (hw->bus_type != e1000_bus_type_pci_express)
6395 ctrl = E1000_READ_REG(hw, CTRL);
6396 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
6397 E1000_WRITE_REG(hw, CTRL, ctrl);
6400 /*******************************************************************************
6402 * Disables PCI-Express master access and verifies there are no pending requests
6404 * hw: Struct containing variables accessed by shared code
6406 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
6407 * caused the master requests to be disabled.
6408 * E1000_SUCCESS master requests disabled.
6410 ******************************************************************************/
6412 e1000_disable_pciex_master(struct e1000_hw *hw)
6414 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
6416 DEBUGFUNC("e1000_disable_pciex_master");
6418 if (hw->bus_type != e1000_bus_type_pci_express)
6419 return E1000_SUCCESS;
6421 e1000_set_pci_express_master_disable(hw);
6424 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
6432 DEBUGOUT("Master requests are pending.\n");
6433 return -E1000_ERR_MASTER_REQUESTS_PENDING;
6436 return E1000_SUCCESS;
6439 /*******************************************************************************
6441 * Check for EEPROM Auto Read bit done.
6443 * hw: Struct containing variables accessed by shared code
6445 * returns: - E1000_ERR_RESET if fail to reset MAC
6446 * E1000_SUCCESS at any other case.
6448 ******************************************************************************/
6450 e1000_get_auto_rd_done(struct e1000_hw *hw)
6452 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
6454 DEBUGFUNC("e1000_get_auto_rd_done");
6456 switch (hw->mac_type) {
6462 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
6468 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
6469 return -E1000_ERR_RESET;
6474 return E1000_SUCCESS;
6477 /***************************************************************************
6478 * Checks if the PHY configuration is done
6480 * hw: Struct containing variables accessed by shared code
6482 * returns: - E1000_ERR_RESET if fail to reset MAC
6483 * E1000_SUCCESS at any other case.
6485 ***************************************************************************/
6487 e1000_get_phy_cfg_done(struct e1000_hw *hw)
6489 DEBUGFUNC("e1000_get_phy_cfg_done");
6491 /* Simply wait for 10ms */
6494 return E1000_SUCCESS;
6497 /***************************************************************************
6499 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
6500 * adapter or Eeprom access.
6502 * hw: Struct containing variables accessed by shared code
6504 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
6505 * E1000_SUCCESS at any other case.
6507 ***************************************************************************/
6509 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
6514 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
6516 if(!hw->eeprom_semaphore_present)
6517 return E1000_SUCCESS;
6520 /* Get the FW semaphore. */
6521 timeout = hw->eeprom.word_size + 1;
6523 swsm = E1000_READ_REG(hw, SWSM);
6524 swsm |= E1000_SWSM_SWESMBI;
6525 E1000_WRITE_REG(hw, SWSM, swsm);
6526 /* if we managed to set the bit we got the semaphore. */
6527 swsm = E1000_READ_REG(hw, SWSM);
6528 if(swsm & E1000_SWSM_SWESMBI)
6536 /* Release semaphores */
6537 e1000_put_hw_eeprom_semaphore(hw);
6538 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
6539 return -E1000_ERR_EEPROM;
6542 return E1000_SUCCESS;
6545 /***************************************************************************
6546 * This function clears HW semaphore bits.
6548 * hw: Struct containing variables accessed by shared code
6552 ***************************************************************************/
6554 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
6558 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
6560 if(!hw->eeprom_semaphore_present)
6563 swsm = E1000_READ_REG(hw, SWSM);
6564 /* Release both semaphores. */
6565 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
6566 E1000_WRITE_REG(hw, SWSM, swsm);
6569 /******************************************************************************
6570 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
6571 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
6572 * the caller to figure out how to deal with it.
6574 * hw - Struct containing variables accessed by shared code
6576 * returns: - E1000_BLK_PHY_RESET
6579 *****************************************************************************/
6581 e1000_check_phy_reset_block(struct e1000_hw *hw)
6584 if(hw->mac_type > e1000_82547_rev_2)
6585 manc = E1000_READ_REG(hw, MANC);
6586 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
6587 E1000_BLK_PHY_RESET : E1000_SUCCESS;
6591 e1000_arc_subsystem_valid(struct e1000_hw *hw)
6595 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
6596 * may not be provided a DMA clock when no manageability features are
6597 * enabled. We do not want to perform any reads/writes to these registers
6598 * if this is the case. We read FWSM to determine the manageability mode.
6600 switch (hw->mac_type) {
6602 fwsm = E1000_READ_REG(hw, FWSM);
6603 if((fwsm & E1000_FWSM_MODE_MASK) != 0)