1 /*******************************************************************************
3 Copyright (c) 2001-2005, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 *******************************************************************************/
35 * Shared functions for accessing and configuring the MAC
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <dev/em/if_em_hw.h>
43 static int32_t em_set_phy_type(struct em_hw *hw);
44 static void em_phy_init_script(struct em_hw *hw);
45 static int32_t em_setup_copper_link(struct em_hw *hw);
46 static int32_t em_setup_fiber_serdes_link(struct em_hw *hw);
47 static int32_t em_adjust_serdes_amplitude(struct em_hw *hw);
48 static int32_t em_phy_force_speed_duplex(struct em_hw *hw);
49 static int32_t em_config_mac_to_phy(struct em_hw *hw);
50 static void em_raise_mdi_clk(struct em_hw *hw, uint32_t *ctrl);
51 static void em_lower_mdi_clk(struct em_hw *hw, uint32_t *ctrl);
52 static void em_shift_out_mdi_bits(struct em_hw *hw, uint32_t data,
54 static uint16_t em_shift_in_mdi_bits(struct em_hw *hw);
55 static int32_t em_phy_reset_dsp(struct em_hw *hw);
56 static int32_t em_write_eeprom_spi(struct em_hw *hw, uint16_t offset,
57 uint16_t words, uint16_t *data);
58 static int32_t em_write_eeprom_microwire(struct em_hw *hw,
59 uint16_t offset, uint16_t words,
61 static int32_t em_spi_eeprom_ready(struct em_hw *hw);
62 static void em_raise_ee_clk(struct em_hw *hw, uint32_t *eecd);
63 static void em_lower_ee_clk(struct em_hw *hw, uint32_t *eecd);
64 static void em_shift_out_ee_bits(struct em_hw *hw, uint16_t data,
66 static int32_t em_write_phy_reg_ex(struct em_hw *hw, uint32_t reg_addr,
68 static int32_t em_read_phy_reg_ex(struct em_hw *hw,uint32_t reg_addr,
70 static uint16_t em_shift_in_ee_bits(struct em_hw *hw, uint16_t count);
71 static int32_t em_acquire_eeprom(struct em_hw *hw);
72 static void em_release_eeprom(struct em_hw *hw);
73 static void em_standby_eeprom(struct em_hw *hw);
74 static int32_t em_set_vco_speed(struct em_hw *hw);
75 static int32_t em_polarity_reversal_workaround(struct em_hw *hw);
76 static int32_t em_set_phy_mode(struct em_hw *hw);
77 static int32_t em_host_if_read_cookie(struct em_hw *hw, uint8_t *buffer);
78 static uint8_t em_calculate_mng_checksum(char *buffer, uint32_t length);
80 /* IGP cable length table */
82 uint16_t em_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
83 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
84 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
85 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
86 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
87 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
88 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
89 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
90 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
93 uint16_t em_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
94 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
95 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
96 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
97 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
98 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
99 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
100 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
101 104, 109, 114, 118, 121, 124};
103 /******************************************************************************
104 * Set the phy type member in the hw struct.
106 * hw - Struct containing variables accessed by shared code
107 *****************************************************************************/
109 em_set_phy_type(struct em_hw *hw)
111 DEBUGFUNC("em_set_phy_type");
113 if(hw->mac_type == em_undefined)
114 return -E1000_ERR_PHY_TYPE;
117 case M88E1000_E_PHY_ID:
118 case M88E1000_I_PHY_ID:
119 case M88E1011_I_PHY_ID:
120 case M88E1111_I_PHY_ID:
121 hw->phy_type = em_phy_m88;
123 case IGP01E1000_I_PHY_ID:
124 if(hw->mac_type == em_82541 ||
125 hw->mac_type == em_82541_rev_2 ||
126 hw->mac_type == em_82547 ||
127 hw->mac_type == em_82547_rev_2) {
128 hw->phy_type = em_phy_igp;
133 /* Should never have loaded on this device */
134 hw->phy_type = em_phy_undefined;
135 return -E1000_ERR_PHY_TYPE;
138 return E1000_SUCCESS;
141 /******************************************************************************
142 * IGP phy init script - initializes the GbE PHY
144 * hw - Struct containing variables accessed by shared code
145 *****************************************************************************/
147 em_phy_init_script(struct em_hw *hw)
150 uint16_t phy_saved_data;
152 DEBUGFUNC("em_phy_init_script");
154 if(hw->phy_init_script) {
157 /* Save off the current value of register 0x2F5B to be restored at
158 * the end of this routine. */
159 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
161 /* Disabled the PHY transmitter */
162 em_write_phy_reg(hw, 0x2F5B, 0x0003);
166 em_write_phy_reg(hw,0x0000,0x0140);
170 switch(hw->mac_type) {
173 em_write_phy_reg(hw, 0x1F95, 0x0001);
175 em_write_phy_reg(hw, 0x1F71, 0xBD21);
177 em_write_phy_reg(hw, 0x1F79, 0x0018);
179 em_write_phy_reg(hw, 0x1F30, 0x1600);
181 em_write_phy_reg(hw, 0x1F31, 0x0014);
183 em_write_phy_reg(hw, 0x1F32, 0x161C);
185 em_write_phy_reg(hw, 0x1F94, 0x0003);
187 em_write_phy_reg(hw, 0x1F96, 0x003F);
189 em_write_phy_reg(hw, 0x2010, 0x0008);
194 em_write_phy_reg(hw, 0x1F73, 0x0099);
200 em_write_phy_reg(hw, 0x0000, 0x3300);
204 /* Now enable the transmitter */
205 em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
207 if(hw->mac_type == em_82547) {
208 uint16_t fused, fine, coarse;
210 /* Move to analog registers page */
211 em_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
213 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
214 em_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
216 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
217 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
219 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
220 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
221 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
222 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
223 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
225 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
226 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
227 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
229 em_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
230 em_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
231 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
237 /******************************************************************************
238 * Set the mac type member in the hw struct.
240 * hw - Struct containing variables accessed by shared code
241 *****************************************************************************/
243 em_set_mac_type(struct em_hw *hw)
245 DEBUGFUNC("em_set_mac_type");
247 switch (hw->device_id) {
248 case E1000_DEV_ID_82542:
249 switch (hw->revision_id) {
250 case E1000_82542_2_0_REV_ID:
251 hw->mac_type = em_82542_rev2_0;
253 case E1000_82542_2_1_REV_ID:
254 hw->mac_type = em_82542_rev2_1;
257 /* Invalid 82542 revision ID */
258 return -E1000_ERR_MAC_TYPE;
261 case E1000_DEV_ID_82543GC_FIBER:
262 case E1000_DEV_ID_82543GC_COPPER:
263 hw->mac_type = em_82543;
265 case E1000_DEV_ID_82544EI_COPPER:
266 case E1000_DEV_ID_82544EI_FIBER:
267 case E1000_DEV_ID_82544GC_COPPER:
268 case E1000_DEV_ID_82544GC_LOM:
269 hw->mac_type = em_82544;
271 case E1000_DEV_ID_82540EM:
272 case E1000_DEV_ID_82540EM_LOM:
273 case E1000_DEV_ID_82540EP:
274 case E1000_DEV_ID_82540EP_LOM:
275 case E1000_DEV_ID_82540EP_LP:
276 hw->mac_type = em_82540;
278 case E1000_DEV_ID_82545EM_COPPER:
279 case E1000_DEV_ID_82545EM_FIBER:
280 hw->mac_type = em_82545;
282 case E1000_DEV_ID_82545GM_COPPER:
283 case E1000_DEV_ID_82545GM_FIBER:
284 case E1000_DEV_ID_82545GM_SERDES:
285 hw->mac_type = em_82545_rev_3;
287 case E1000_DEV_ID_82546EB_COPPER:
288 case E1000_DEV_ID_82546EB_FIBER:
289 case E1000_DEV_ID_82546EB_QUAD_COPPER:
290 hw->mac_type = em_82546;
292 case E1000_DEV_ID_82546GB_COPPER:
293 case E1000_DEV_ID_82546GB_FIBER:
294 case E1000_DEV_ID_82546GB_SERDES:
295 case E1000_DEV_ID_82546GB_PCIE:
296 case E1000_DEV_ID_82546GB_QUAD_COPPER:
297 hw->mac_type = em_82546_rev_3;
299 case E1000_DEV_ID_82541EI:
300 case E1000_DEV_ID_82541ER_LOM:
301 case E1000_DEV_ID_82541EI_MOBILE:
302 hw->mac_type = em_82541;
304 case E1000_DEV_ID_82541ER:
305 case E1000_DEV_ID_82541GI:
306 case E1000_DEV_ID_82541GI_LF:
307 case E1000_DEV_ID_82541GI_MOBILE:
308 hw->mac_type = em_82541_rev_2;
310 case E1000_DEV_ID_82547EI:
311 case E1000_DEV_ID_82547EI_MOBILE:
312 hw->mac_type = em_82547;
314 case E1000_DEV_ID_82547GI:
315 hw->mac_type = em_82547_rev_2;
317 case E1000_DEV_ID_82571EB_COPPER:
318 case E1000_DEV_ID_82571EB_FIBER:
319 case E1000_DEV_ID_82571EB_SERDES:
320 hw->mac_type = em_82571;
322 case E1000_DEV_ID_82572EI_COPPER:
323 case E1000_DEV_ID_82572EI_FIBER:
324 case E1000_DEV_ID_82572EI_SERDES:
325 hw->mac_type = em_82572;
327 case E1000_DEV_ID_82573E:
328 case E1000_DEV_ID_82573E_IAMT:
329 case E1000_DEV_ID_82573L:
330 hw->mac_type = em_82573;
333 /* Should never have loaded on this device */
334 return -E1000_ERR_MAC_TYPE;
337 switch(hw->mac_type) {
341 hw->eeprom_semaphore_present = TRUE;
347 hw->asf_firmware_present = TRUE;
352 return E1000_SUCCESS;
355 /*****************************************************************************
356 * Set media type and TBI compatibility.
358 * hw - Struct containing variables accessed by shared code
359 * **************************************************************************/
361 em_set_media_type(struct em_hw *hw)
365 DEBUGFUNC("em_set_media_type");
367 if(hw->mac_type != em_82543) {
368 /* tbi_compatibility is only valid on 82543 */
369 hw->tbi_compatibility_en = FALSE;
372 switch (hw->device_id) {
373 case E1000_DEV_ID_82545GM_SERDES:
374 case E1000_DEV_ID_82546GB_SERDES:
375 case E1000_DEV_ID_82571EB_SERDES:
376 case E1000_DEV_ID_82572EI_SERDES:
377 hw->media_type = em_media_type_internal_serdes;
380 switch (hw->mac_type) {
381 case em_82542_rev2_0:
382 case em_82542_rev2_1:
383 hw->media_type = em_media_type_fiber;
387 * The STATUS_TBIMODE bit is reserved or reused for
390 hw->media_type = em_media_type_copper;
393 status = E1000_READ_REG(hw, STATUS);
394 if (status & E1000_STATUS_TBIMODE) {
395 hw->media_type = em_media_type_fiber;
396 /* tbi_compatibility not valid on fiber */
397 hw->tbi_compatibility_en = FALSE;
399 hw->media_type = em_media_type_copper;
404 /******************************************************************************
405 * Reset the transmit and receive units; mask and clear all interrupts.
407 * hw - Struct containing variables accessed by shared code
408 *****************************************************************************/
410 em_reset_hw(struct em_hw *hw)
418 uint32_t extcnf_ctrl;
421 DEBUGFUNC("em_reset_hw");
423 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
424 if(hw->mac_type == em_82542_rev2_0) {
425 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
426 em_pci_clear_mwi(hw);
429 if(hw->bus_type == em_bus_type_pci_express) {
430 /* Prevent the PCI-E bus from sticking if there is no TLP connection
431 * on the last TLP read/write transaction when MAC is reset.
433 if(em_disable_pciex_master(hw) != E1000_SUCCESS) {
434 DEBUGOUT("PCI-E Master disable polling has failed.\n");
438 /* Clear interrupt mask to stop board from generating interrupts */
439 DEBUGOUT("Masking off all interrupts\n");
440 E1000_WRITE_REG(hw, IMC, 0xffffffff);
442 /* Disable the Transmit and Receive units. Then delay to allow
443 * any pending transactions to complete before we hit the MAC with
446 E1000_WRITE_REG(hw, RCTL, 0);
447 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
448 E1000_WRITE_FLUSH(hw);
450 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
451 hw->tbi_compatibility_on = FALSE;
453 /* Delay to allow any outstanding PCI transactions to complete before
454 * resetting the device
458 ctrl = E1000_READ_REG(hw, CTRL);
460 /* Must reset the PHY before resetting the MAC */
461 if((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
462 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
466 /* Must acquire the MDIO ownership before MAC reset.
467 * Ownership defaults to firmware after a reset. */
468 if(hw->mac_type == em_82573) {
471 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
472 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
475 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
476 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
478 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
481 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
488 /* Issue a global reset to the MAC. This will reset the chip's
489 * transmit, receive, DMA, and link units. It will not effect
490 * the current PCI configuration. The global reset bit is self-
491 * clearing, and should clear within a microsecond.
493 DEBUGOUT("Issuing a global reset to MAC\n");
495 switch(hw->mac_type) {
504 /* These controllers can't ack the 64-bit write when issuing the
505 * reset, so use IO-mapping as a workaround to issue the reset */
506 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
510 /* Reset is performed on a shadow of the control register */
511 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
514 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
518 /* After MAC reset, force reload of EEPROM to restore power-on settings to
519 * device. Later controllers reload the EEPROM automatically, so just wait
520 * for reload to complete.
522 switch(hw->mac_type) {
523 case em_82542_rev2_0:
524 case em_82542_rev2_1:
527 /* Wait for reset to complete */
529 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
530 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
531 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
532 E1000_WRITE_FLUSH(hw);
533 /* Wait for EEPROM reload */
540 /* Wait for EEPROM reload */
544 if (em_is_onboard_nvm_eeprom(hw) == FALSE) {
546 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
547 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
548 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
549 E1000_WRITE_FLUSH(hw);
554 ret_val = em_get_auto_rd_done(hw);
556 /* We don't want to continue accessing MAC registers. */
560 /* Wait for EEPROM reload (it happens automatically) */
565 /* Disable HW ARPs on ASF enabled adapters */
566 if(hw->mac_type >= em_82540 && hw->mac_type <= em_82547_rev_2) {
567 manc = E1000_READ_REG(hw, MANC);
568 manc &= ~(E1000_MANC_ARP_EN);
569 E1000_WRITE_REG(hw, MANC, manc);
572 if((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
573 em_phy_init_script(hw);
575 /* Configure activity LED after PHY reset */
576 led_ctrl = E1000_READ_REG(hw, LEDCTL);
577 led_ctrl &= IGP_ACTIVITY_LED_MASK;
578 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
579 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
582 /* Clear interrupt mask to stop board from generating interrupts */
583 DEBUGOUT("Masking off all interrupts\n");
584 E1000_WRITE_REG(hw, IMC, 0xffffffff);
586 /* Clear any pending interrupt events. */
587 icr = E1000_READ_REG(hw, ICR);
589 /* If MWI was previously enabled, reenable it. */
590 if(hw->mac_type == em_82542_rev2_0) {
591 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
595 return E1000_SUCCESS;
598 /******************************************************************************
599 * Performs basic configuration of the adapter.
601 * hw - Struct containing variables accessed by shared code
603 * Assumes that the controller has previously been reset and is in a
604 * post-reset uninitialized state. Initializes the receive address registers,
605 * multicast table, and VLAN filter table. Calls routines to setup link
606 * configuration and flow control settings. Clears all on-chip counters. Leaves
607 * the transmit and receive units disabled and uninitialized.
608 *****************************************************************************/
610 em_init_hw(struct em_hw *hw)
615 uint16_t pcix_cmd_word;
616 uint16_t pcix_stat_hi_word;
621 DEBUGFUNC("em_init_hw");
623 /* Initialize Identification LED */
624 ret_val = em_id_led_init(hw);
626 DEBUGOUT("Error Initializing Identification LED\n");
630 /* Set the media type and TBI compatibility */
631 em_set_media_type(hw);
633 /* Disabling VLAN filtering. */
634 DEBUGOUT("Initializing the IEEE VLAN\n");
635 if (hw->mac_type < em_82545_rev_3)
636 E1000_WRITE_REG(hw, VET, 0);
639 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
640 if(hw->mac_type == em_82542_rev2_0) {
641 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
642 em_pci_clear_mwi(hw);
643 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
644 E1000_WRITE_FLUSH(hw);
648 /* Setup the receive address. This involves initializing all of the Receive
649 * Address Registers (RARs 0 - 15).
651 em_init_rx_addrs(hw);
653 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
654 if(hw->mac_type == em_82542_rev2_0) {
655 E1000_WRITE_REG(hw, RCTL, 0);
656 E1000_WRITE_FLUSH(hw);
658 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
662 /* Zero out the Multicast HASH table */
663 DEBUGOUT("Zeroing the MTA\n");
664 mta_size = E1000_MC_TBL_SIZE;
665 for(i = 0; i < mta_size; i++)
666 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
668 /* Set the PCI priority bit correctly in the CTRL register. This
669 * determines if the adapter gives priority to receives, or if it
670 * gives equal priority to transmits and receives. Valid only on
671 * 82542 and 82543 silicon.
673 if(hw->dma_fairness && hw->mac_type <= em_82543) {
674 ctrl = E1000_READ_REG(hw, CTRL);
675 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
678 switch(hw->mac_type) {
683 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
684 if(hw->bus_type == em_bus_type_pcix) {
685 em_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
686 em_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
688 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
689 PCIX_COMMAND_MMRBC_SHIFT;
690 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
691 PCIX_STATUS_HI_MMRBC_SHIFT;
692 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
693 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
694 if(cmd_mmrbc > stat_mmrbc) {
695 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
696 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
697 em_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
704 /* Call a subroutine to configure the link and setup flow control. */
705 ret_val = em_setup_link(hw);
707 /* Set the transmit descriptor write-back policy */
708 if(hw->mac_type > em_82544) {
709 ctrl = E1000_READ_REG(hw, TXDCTL);
710 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
711 switch (hw->mac_type) {
716 ctrl |= E1000_TXDCTL_COUNT_DESC;
720 E1000_WRITE_REG(hw, TXDCTL, ctrl);
723 if (hw->mac_type == em_82573) {
724 em_enable_tx_pkt_filtering(hw);
727 switch (hw->mac_type) {
730 ctrl = E1000_READ_REG(hw, TXDCTL1);
731 ctrl &= ~E1000_TXDCTL_WTHRESH;
732 ctrl |= E1000_TXDCTL_COUNT_DESC | E1000_TXDCTL_FULL_TX_DESC_WB;
734 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
739 if (hw->mac_type == em_82573) {
740 uint32_t gcr = E1000_READ_REG(hw, GCR);
741 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
742 E1000_WRITE_REG(hw, GCR, gcr);
745 /* Clear all of the statistics registers (clear on read). It is
746 * important that we do this after we have tried to establish link
747 * because the symbol error count will increment wildly if there
750 em_clear_hw_cntrs(hw);
755 /******************************************************************************
756 * Adjust SERDES output amplitude based on EEPROM setting.
758 * hw - Struct containing variables accessed by shared code.
759 *****************************************************************************/
761 em_adjust_serdes_amplitude(struct em_hw *hw)
763 uint16_t eeprom_data;
766 DEBUGFUNC("em_adjust_serdes_amplitude");
768 if(hw->media_type != em_media_type_internal_serdes)
769 return E1000_SUCCESS;
771 switch(hw->mac_type) {
776 return E1000_SUCCESS;
779 ret_val = em_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
784 if(eeprom_data != EEPROM_RESERVED_WORD) {
785 /* Adjust SERDES output amplitude only. */
786 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
787 ret_val = em_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
792 return E1000_SUCCESS;
795 /******************************************************************************
796 * Configures flow control and link settings.
798 * hw - Struct containing variables accessed by shared code
800 * Determines which flow control settings to use. Calls the apropriate media-
801 * specific link configuration function. Configures the flow control settings.
802 * Assuming the adapter has a valid link partner, a valid link should be
803 * established. Assumes the hardware has previously been reset and the
804 * transmitter and receiver are not enabled.
805 *****************************************************************************/
807 em_setup_link(struct em_hw *hw)
811 uint16_t eeprom_data;
813 DEBUGFUNC("em_setup_link");
815 /* In the case of the phy reset being blocked, we already have a link.
816 * We do not have to set it up again. */
817 if (em_check_phy_reset_block(hw))
818 return E1000_SUCCESS;
820 /* Read and store word 0x0F of the EEPROM. This word contains bits
821 * that determine the hardware's default PAUSE (flow control) mode,
822 * a bit that determines whether the HW defaults to enabling or
823 * disabling auto-negotiation, and the direction of the
824 * SW defined pins. If there is no SW over-ride of the flow
825 * control setting, then the variable hw->fc will
826 * be initialized based on a value in the EEPROM.
828 if (hw->fc == em_fc_default) {
829 switch (hw->mac_type) {
834 ret_val = em_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
837 DEBUGOUT("EEPROM Read Error\n");
838 return -E1000_ERR_EEPROM;
841 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
843 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
844 EEPROM_WORD0F_ASM_DIR)
845 hw->fc = em_fc_tx_pause;
851 /* We want to save off the original Flow Control configuration just
852 * in case we get disconnected and then reconnected into a different
853 * hub or switch with different Flow Control capabilities.
855 if(hw->mac_type == em_82542_rev2_0)
856 hw->fc &= (~em_fc_tx_pause);
858 if((hw->mac_type < em_82543) && (hw->report_tx_early == 1))
859 hw->fc &= (~em_fc_rx_pause);
861 hw->original_fc = hw->fc;
863 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
865 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
866 * polarity value for the SW controlled pins, and setup the
867 * Extended Device Control reg with that info.
868 * This is needed because one of the SW controlled pins is used for
869 * signal detection. So this should be done before em_setup_pcs_link()
870 * or em_phy_setup() is called.
872 if(hw->mac_type == em_82543) {
873 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
875 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
878 /* Call the necessary subroutine to configure the link. */
879 ret_val = (hw->media_type == em_media_type_copper) ?
880 em_setup_copper_link(hw) :
881 em_setup_fiber_serdes_link(hw);
883 /* Initialize the flow control address, type, and PAUSE timer
884 * registers to their default values. This is done even if flow
885 * control is disabled, because it does not hurt anything to
886 * initialize these registers.
888 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
890 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
891 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
892 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
894 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
896 /* Set the flow control receive threshold registers. Normally,
897 * these registers will be set to a default threshold that may be
898 * adjusted later by the driver's runtime code. However, if the
899 * ability to transmit pause frames in not enabled, then these
900 * registers will be set to 0.
902 if(!(hw->fc & em_fc_tx_pause)) {
903 E1000_WRITE_REG(hw, FCRTL, 0);
904 E1000_WRITE_REG(hw, FCRTH, 0);
906 /* We need to set up the Receive Threshold high and low water marks
907 * as well as (optionally) enabling the transmission of XON frames.
909 if(hw->fc_send_xon) {
910 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
911 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
913 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
914 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
920 /******************************************************************************
921 * Sets up link for a fiber based or serdes based adapter
923 * hw - Struct containing variables accessed by shared code
925 * Manipulates Physical Coding Sublayer functions in order to configure
926 * link. Assumes the hardware has been previously reset and the transmitter
927 * and receiver are not enabled.
928 *****************************************************************************/
930 em_setup_fiber_serdes_link(struct em_hw *hw)
939 DEBUGFUNC("em_setup_fiber_serdes_link");
941 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
942 * until explicitly turned off or a power cycle is performed. A read to
943 * the register does not indicate its status. Therefore, we ensure
944 * loopback mode is disabled during initialization.
946 if (hw->mac_type == em_82571 || hw->mac_type == em_82572)
947 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
949 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
950 * set when the optics detect a signal. On older adapters, it will be
951 * cleared when there is a signal. This applies to fiber media only.
952 * If we're on serdes media, adjust the output amplitude to value set in
955 ctrl = E1000_READ_REG(hw, CTRL);
956 if(hw->media_type == em_media_type_fiber)
957 signal = (hw->mac_type > em_82544) ? E1000_CTRL_SWDPIN1 : 0;
959 ret_val = em_adjust_serdes_amplitude(hw);
963 /* Take the link out of reset */
964 ctrl &= ~(E1000_CTRL_LRST);
966 /* Adjust VCO speed to improve BER performance */
967 ret_val = em_set_vco_speed(hw);
971 em_config_collision_dist(hw);
973 /* Check for a software override of the flow control settings, and setup
974 * the device accordingly. If auto-negotiation is enabled, then software
975 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
976 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
977 * auto-negotiation is disabled, then software will have to manually
978 * configure the two flow control enable bits in the CTRL register.
980 * The possible values of the "fc" parameter are:
981 * 0: Flow control is completely disabled
982 * 1: Rx flow control is enabled (we can receive pause frames, but
983 * not send pause frames).
984 * 2: Tx flow control is enabled (we can send pause frames but we do
985 * not support receiving pause frames).
986 * 3: Both Rx and TX flow control (symmetric) are enabled.
990 /* Flow control is completely disabled by a software over-ride. */
991 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
994 /* RX Flow control is enabled and TX Flow control is disabled by a
995 * software over-ride. Since there really isn't a way to advertise
996 * that we are capable of RX Pause ONLY, we will advertise that we
997 * support both symmetric and asymmetric RX PAUSE. Later, we will
998 * disable the adapter's ability to send PAUSE frames.
1000 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1002 case em_fc_tx_pause:
1003 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1004 * software over-ride.
1006 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1009 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1010 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1013 DEBUGOUT("Flow control param set incorrectly\n");
1014 return -E1000_ERR_CONFIG;
1018 /* Since auto-negotiation is enabled, take the link out of reset (the link
1019 * will be in reset, because we previously reset the chip). This will
1020 * restart auto-negotiation. If auto-neogtiation is successful then the
1021 * link-up status bit will be set and the flow control enable bits (RFCE
1022 * and TFCE) will be set according to their negotiated value.
1024 DEBUGOUT("Auto-negotiation enabled\n");
1026 E1000_WRITE_REG(hw, TXCW, txcw);
1027 E1000_WRITE_REG(hw, CTRL, ctrl);
1028 E1000_WRITE_FLUSH(hw);
1033 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1034 * indication in the Device Status Register. Time-out if a link isn't
1035 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1036 * less than 500 milliseconds even if the other end is doing it in SW).
1037 * For internal serdes, we just assume a signal is present, then poll.
1039 if(hw->media_type == em_media_type_internal_serdes ||
1040 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1041 DEBUGOUT("Looking for Link\n");
1042 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1044 status = E1000_READ_REG(hw, STATUS);
1045 if(status & E1000_STATUS_LU) break;
1047 if(i == (LINK_UP_TIMEOUT / 10)) {
1048 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1049 hw->autoneg_failed = 1;
1050 /* AutoNeg failed to achieve a link, so we'll call
1051 * em_check_for_link. This routine will force the link up if
1052 * we detect a signal. This will allow us to communicate with
1053 * non-autonegotiating link partners.
1055 ret_val = em_check_for_link(hw);
1057 DEBUGOUT("Error while checking for link\n");
1060 hw->autoneg_failed = 0;
1062 hw->autoneg_failed = 0;
1063 DEBUGOUT("Valid Link Found\n");
1066 DEBUGOUT("No Signal Detected\n");
1068 return E1000_SUCCESS;
1071 /******************************************************************************
1072 * Make sure we have a valid PHY and change PHY mode before link setup.
1074 * hw - Struct containing variables accessed by shared code
1075 ******************************************************************************/
1077 em_copper_link_preconfig(struct em_hw *hw)
1083 DEBUGFUNC("em_copper_link_preconfig");
1085 ctrl = E1000_READ_REG(hw, CTRL);
1086 /* With 82543, we need to force speed and duplex on the MAC equal to what
1087 * the PHY speed and duplex configuration is. In addition, we need to
1088 * perform a hardware reset on the PHY to take it out of reset.
1090 if(hw->mac_type > em_82543) {
1091 ctrl |= E1000_CTRL_SLU;
1092 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1093 E1000_WRITE_REG(hw, CTRL, ctrl);
1095 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1096 E1000_WRITE_REG(hw, CTRL, ctrl);
1097 ret_val = em_phy_hw_reset(hw);
1102 /* Make sure we have a valid PHY */
1103 ret_val = em_detect_gig_phy(hw);
1105 DEBUGOUT("Error, did not detect valid phy.\n");
1108 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1110 /* Set PHY to class A mode (if necessary) */
1111 ret_val = em_set_phy_mode(hw);
1115 if((hw->mac_type == em_82545_rev_3) ||
1116 (hw->mac_type == em_82546_rev_3)) {
1117 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1118 phy_data |= 0x00000008;
1119 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1122 if(hw->mac_type <= em_82543 ||
1123 hw->mac_type == em_82541 || hw->mac_type == em_82547 ||
1124 hw->mac_type == em_82541_rev_2 || hw->mac_type == em_82547_rev_2)
1125 hw->phy_reset_disable = FALSE;
1127 return E1000_SUCCESS;
1131 /********************************************************************
1132 * Copper link setup for em_phy_igp series.
1134 * hw - Struct containing variables accessed by shared code
1135 *********************************************************************/
1137 em_copper_link_igp_setup(struct em_hw *hw)
1143 DEBUGFUNC("em_copper_link_igp_setup");
1145 if (hw->phy_reset_disable)
1146 return E1000_SUCCESS;
1148 ret_val = em_phy_reset(hw);
1150 DEBUGOUT("Error Resetting the PHY\n");
1154 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1157 /* Configure activity LED after PHY reset */
1158 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1159 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1160 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1161 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1163 /* disable lplu d3 during driver init */
1164 ret_val = em_set_d3_lplu_state(hw, FALSE);
1166 DEBUGOUT("Error Disabling LPLU D3\n");
1170 /* disable lplu d0 during driver init */
1171 ret_val = em_set_d0_lplu_state(hw, FALSE);
1173 DEBUGOUT("Error Disabling LPLU D0\n");
1176 /* Configure mdi-mdix settings */
1177 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1181 if ((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
1182 hw->dsp_config_state = em_dsp_config_disabled;
1183 /* Force MDI for earlier revs of the IGP PHY */
1184 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1188 hw->dsp_config_state = em_dsp_config_enabled;
1189 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1193 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1196 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1200 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1204 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1208 /* set auto-master slave resolution settings */
1210 em_ms_type phy_ms_setting = hw->master_slave;
1212 if(hw->ffe_config_state == em_ffe_config_active)
1213 hw->ffe_config_state = em_ffe_config_enabled;
1215 if(hw->dsp_config_state == em_dsp_config_activated)
1216 hw->dsp_config_state = em_dsp_config_enabled;
1218 /* when autonegotiation advertisment is only 1000Mbps then we
1219 * should disable SmartSpeed and enable Auto MasterSlave
1220 * resolution as hardware default. */
1221 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1222 /* Disable SmartSpeed */
1223 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1226 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1227 ret_val = em_write_phy_reg(hw,
1228 IGP01E1000_PHY_PORT_CONFIG,
1232 /* Set auto Master/Slave resolution process */
1233 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1236 phy_data &= ~CR_1000T_MS_ENABLE;
1237 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1242 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1246 /* load defaults for future use */
1247 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1248 ((phy_data & CR_1000T_MS_VALUE) ?
1249 em_ms_force_master :
1250 em_ms_force_slave) :
1253 switch (phy_ms_setting) {
1254 case em_ms_force_master:
1255 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1257 case em_ms_force_slave:
1258 phy_data |= CR_1000T_MS_ENABLE;
1259 phy_data &= ~(CR_1000T_MS_VALUE);
1262 phy_data &= ~CR_1000T_MS_ENABLE;
1266 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1271 return E1000_SUCCESS;
1275 /********************************************************************
1276 * Copper link setup for em_phy_m88 series.
1278 * hw - Struct containing variables accessed by shared code
1279 *********************************************************************/
1281 em_copper_link_mgp_setup(struct em_hw *hw)
1286 DEBUGFUNC("em_copper_link_mgp_setup");
1288 if(hw->phy_reset_disable)
1289 return E1000_SUCCESS;
1291 /* Enable CRS on TX. This must be set for half-duplex operation. */
1292 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1296 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1299 * MDI/MDI-X = 0 (default)
1300 * 0 - Auto for all speeds
1303 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1305 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1309 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1312 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1315 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1319 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1324 * disable_polarity_correction = 0 (default)
1325 * Automatic Correction for Reversed Cable Polarity
1329 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1330 if(hw->disable_polarity_correction == 1)
1331 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1332 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1336 /* Force TX_CLK in the Extended PHY Specific Control Register
1339 ret_val = em_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1343 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1345 if (hw->phy_revision < M88E1011_I_REV_4) {
1346 /* Configure Master and Slave downshift values */
1347 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1348 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1349 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1350 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1351 ret_val = em_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1356 /* SW Reset the PHY so all changes take effect */
1357 ret_val = em_phy_reset(hw);
1359 DEBUGOUT("Error Resetting the PHY\n");
1363 return E1000_SUCCESS;
1366 /********************************************************************
1367 * Setup auto-negotiation and flow control advertisements,
1368 * and then perform auto-negotiation.
1370 * hw - Struct containing variables accessed by shared code
1371 *********************************************************************/
1373 em_copper_link_autoneg(struct em_hw *hw)
1378 DEBUGFUNC("em_copper_link_autoneg");
1380 /* Perform some bounds checking on the hw->autoneg_advertised
1381 * parameter. If this variable is zero, then set it to the default.
1383 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1385 /* If autoneg_advertised is zero, we assume it was not defaulted
1386 * by the calling code so we set to advertise full capability.
1388 if(hw->autoneg_advertised == 0)
1389 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1391 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1392 ret_val = em_phy_setup_autoneg(hw);
1394 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1397 DEBUGOUT("Restarting Auto-Neg\n");
1399 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1400 * the Auto Neg Restart bit in the PHY control register.
1402 ret_val = em_read_phy_reg(hw, PHY_CTRL, &phy_data);
1406 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1407 ret_val = em_write_phy_reg(hw, PHY_CTRL, phy_data);
1411 /* Does the user want to wait for Auto-Neg to complete here, or
1412 * check at a later time (for example, callback routine).
1414 if(hw->wait_autoneg_complete) {
1415 ret_val = em_wait_autoneg(hw);
1417 DEBUGOUT("Error while waiting for autoneg to complete\n");
1422 hw->get_link_status = TRUE;
1424 return E1000_SUCCESS;
1428 /******************************************************************************
1429 * Config the MAC and the PHY after link is up.
1430 * 1) Set up the MAC to the current PHY speed/duplex
1431 * if we are on 82543. If we
1432 * are on newer silicon, we only need to configure
1433 * collision distance in the Transmit Control Register.
1434 * 2) Set up flow control on the MAC to that established with
1436 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1438 * hw - Struct containing variables accessed by shared code
1439 ******************************************************************************/
1441 em_copper_link_postconfig(struct em_hw *hw)
1444 DEBUGFUNC("em_copper_link_postconfig");
1446 if(hw->mac_type >= em_82544) {
1447 em_config_collision_dist(hw);
1449 ret_val = em_config_mac_to_phy(hw);
1451 DEBUGOUT("Error configuring MAC to PHY settings\n");
1455 ret_val = em_config_fc_after_link_up(hw);
1457 DEBUGOUT("Error Configuring Flow Control\n");
1461 /* Config DSP to improve Giga link quality */
1462 if(hw->phy_type == em_phy_igp) {
1463 ret_val = em_config_dsp_after_link_change(hw, TRUE);
1465 DEBUGOUT("Error Configuring DSP after link up\n");
1470 return E1000_SUCCESS;
1473 /******************************************************************************
1474 * Detects which PHY is present and setup the speed and duplex
1476 * hw - Struct containing variables accessed by shared code
1477 ******************************************************************************/
1479 em_setup_copper_link(struct em_hw *hw)
1485 DEBUGFUNC("em_setup_copper_link");
1487 /* Check if it is a valid PHY and set PHY mode if necessary. */
1488 ret_val = em_copper_link_preconfig(hw);
1492 if (hw->phy_type == em_phy_igp ||
1493 hw->phy_type == em_phy_igp_2) {
1494 ret_val = em_copper_link_igp_setup(hw);
1497 } else if (hw->phy_type == em_phy_m88) {
1498 ret_val = em_copper_link_mgp_setup(hw);
1504 /* Setup autoneg and flow control advertisement
1505 * and perform autonegotiation */
1506 ret_val = em_copper_link_autoneg(hw);
1510 /* PHY will be set to 10H, 10F, 100H,or 100F
1511 * depending on value from forced_speed_duplex. */
1512 DEBUGOUT("Forcing speed and duplex\n");
1513 ret_val = em_phy_force_speed_duplex(hw);
1515 DEBUGOUT("Error Forcing Speed and Duplex\n");
1520 /* Check link status. Wait up to 100 microseconds for link to become
1523 for(i = 0; i < 10; i++) {
1524 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
1527 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
1531 if(phy_data & MII_SR_LINK_STATUS) {
1532 /* Config the MAC and PHY after link is up */
1533 ret_val = em_copper_link_postconfig(hw);
1537 DEBUGOUT("Valid link established!!!\n");
1538 return E1000_SUCCESS;
1543 DEBUGOUT("Unable to establish link!!!\n");
1544 return E1000_SUCCESS;
1547 /******************************************************************************
1548 * Configures PHY autoneg and flow control advertisement settings
1550 * hw - Struct containing variables accessed by shared code
1551 ******************************************************************************/
1553 em_phy_setup_autoneg(struct em_hw *hw)
1556 uint16_t mii_autoneg_adv_reg;
1557 uint16_t mii_1000t_ctrl_reg;
1559 DEBUGFUNC("em_phy_setup_autoneg");
1561 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1562 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1566 /* Read the MII 1000Base-T Control Register (Address 9). */
1567 ret_val = em_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1571 /* Need to parse both autoneg_advertised and fc and set up
1572 * the appropriate PHY registers. First we will parse for
1573 * autoneg_advertised software override. Since we can advertise
1574 * a plethora of combinations, we need to check each bit
1578 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1579 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1580 * the 1000Base-T Control Register (Address 9).
1582 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1583 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1585 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1587 /* Do we want to advertise 10 Mb Half Duplex? */
1588 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1589 DEBUGOUT("Advertise 10mb Half duplex\n");
1590 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1593 /* Do we want to advertise 10 Mb Full Duplex? */
1594 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1595 DEBUGOUT("Advertise 10mb Full duplex\n");
1596 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1599 /* Do we want to advertise 100 Mb Half Duplex? */
1600 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1601 DEBUGOUT("Advertise 100mb Half duplex\n");
1602 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1605 /* Do we want to advertise 100 Mb Full Duplex? */
1606 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1607 DEBUGOUT("Advertise 100mb Full duplex\n");
1608 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1611 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1612 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1613 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1616 /* Do we want to advertise 1000 Mb Full Duplex? */
1617 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1618 DEBUGOUT("Advertise 1000mb Full duplex\n");
1619 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1622 /* Check for a software override of the flow control settings, and
1623 * setup the PHY advertisement registers accordingly. If
1624 * auto-negotiation is enabled, then software will have to set the
1625 * "PAUSE" bits to the correct value in the Auto-Negotiation
1626 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1628 * The possible values of the "fc" parameter are:
1629 * 0: Flow control is completely disabled
1630 * 1: Rx flow control is enabled (we can receive pause frames
1631 * but not send pause frames).
1632 * 2: Tx flow control is enabled (we can send pause frames
1633 * but we do not support receiving pause frames).
1634 * 3: Both Rx and TX flow control (symmetric) are enabled.
1635 * other: No software override. The flow control configuration
1636 * in the EEPROM is used.
1639 case em_fc_none: /* 0 */
1640 /* Flow control (RX & TX) is completely disabled by a
1641 * software over-ride.
1643 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1645 case em_fc_rx_pause: /* 1 */
1646 /* RX Flow control is enabled, and TX Flow control is
1647 * disabled, by a software over-ride.
1649 /* Since there really isn't a way to advertise that we are
1650 * capable of RX Pause ONLY, we will advertise that we
1651 * support both symmetric and asymmetric RX PAUSE. Later
1652 * (in em_config_fc_after_link_up) we will disable the
1653 *hw's ability to send PAUSE frames.
1655 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1657 case em_fc_tx_pause: /* 2 */
1658 /* TX Flow control is enabled, and RX Flow control is
1659 * disabled, by a software over-ride.
1661 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1662 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1664 case em_fc_full: /* 3 */
1665 /* Flow control (both RX and TX) is enabled by a software
1668 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1671 DEBUGOUT("Flow control param set incorrectly\n");
1672 return -E1000_ERR_CONFIG;
1675 ret_val = em_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1679 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1681 ret_val = em_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1685 return E1000_SUCCESS;
1688 /******************************************************************************
1689 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1691 * hw - Struct containing variables accessed by shared code
1692 ******************************************************************************/
1694 em_phy_force_speed_duplex(struct em_hw *hw)
1698 uint16_t mii_ctrl_reg;
1699 uint16_t mii_status_reg;
1703 DEBUGFUNC("em_phy_force_speed_duplex");
1705 /* Turn off Flow control if we are forcing speed and duplex. */
1706 hw->fc = em_fc_none;
1708 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1710 /* Read the Device Control Register. */
1711 ctrl = E1000_READ_REG(hw, CTRL);
1713 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1714 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1715 ctrl &= ~(DEVICE_SPEED_MASK);
1717 /* Clear the Auto Speed Detect Enable bit. */
1718 ctrl &= ~E1000_CTRL_ASDE;
1720 /* Read the MII Control Register. */
1721 ret_val = em_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1725 /* We need to disable autoneg in order to force link and duplex. */
1727 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1729 /* Are we forcing Full or Half Duplex? */
1730 if(hw->forced_speed_duplex == em_100_full ||
1731 hw->forced_speed_duplex == em_10_full) {
1732 /* We want to force full duplex so we SET the full duplex bits in the
1733 * Device and MII Control Registers.
1735 ctrl |= E1000_CTRL_FD;
1736 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1737 DEBUGOUT("Full Duplex\n");
1739 /* We want to force half duplex so we CLEAR the full duplex bits in
1740 * the Device and MII Control Registers.
1742 ctrl &= ~E1000_CTRL_FD;
1743 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1744 DEBUGOUT("Half Duplex\n");
1747 /* Are we forcing 100Mbps??? */
1748 if(hw->forced_speed_duplex == em_100_full ||
1749 hw->forced_speed_duplex == em_100_half) {
1750 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1751 ctrl |= E1000_CTRL_SPD_100;
1752 mii_ctrl_reg |= MII_CR_SPEED_100;
1753 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1754 DEBUGOUT("Forcing 100mb ");
1756 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1757 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1758 mii_ctrl_reg |= MII_CR_SPEED_10;
1759 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1760 DEBUGOUT("Forcing 10mb ");
1763 em_config_collision_dist(hw);
1765 /* Write the configured values back to the Device Control Reg. */
1766 E1000_WRITE_REG(hw, CTRL, ctrl);
1768 if (hw->phy_type == em_phy_m88) {
1769 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1773 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1774 * forced whenever speed are duplex are forced.
1776 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1777 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1781 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1783 /* Need to reset the PHY or these changes will be ignored */
1784 mii_ctrl_reg |= MII_CR_RESET;
1786 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1787 * forced whenever speed or duplex are forced.
1789 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1793 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1794 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1796 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1801 /* Write back the modified PHY MII control register. */
1802 ret_val = em_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1808 /* The wait_autoneg_complete flag may be a little misleading here.
1809 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1810 * But we do want to delay for a period while forcing only so we
1811 * don't generate false No Link messages. So we will wait here
1812 * only if the user has set wait_autoneg_complete to 1, which is
1815 if(hw->wait_autoneg_complete) {
1816 /* We will wait for autoneg to complete. */
1817 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1820 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1821 for(i = PHY_FORCE_TIME; i > 0; i--) {
1822 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1825 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1829 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1833 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1837 (hw->phy_type == em_phy_m88)) {
1838 /* We didn't get link. Reset the DSP and wait again for link. */
1839 ret_val = em_phy_reset_dsp(hw);
1841 DEBUGOUT("Error Resetting PHY DSP\n");
1845 /* This loop will early-out if the link condition has been met. */
1846 for(i = PHY_FORCE_TIME; i > 0; i--) {
1847 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1849 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1852 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1856 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1862 if (hw->phy_type == em_phy_m88) {
1863 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1864 * Extended PHY Specific Control Register to 25MHz clock. This value
1865 * defaults back to a 2.5MHz clock when the PHY is reset.
1867 ret_val = em_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1871 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1872 ret_val = em_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1876 /* In addition, because of the s/w reset above, we need to enable CRS on
1877 * TX. This must be set for both full and half duplex operation.
1879 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1883 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1884 ret_val = em_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1888 if((hw->mac_type == em_82544 || hw->mac_type == em_82543) &&
1890 (hw->forced_speed_duplex == em_10_full ||
1891 hw->forced_speed_duplex == em_10_half)) {
1892 ret_val = em_polarity_reversal_workaround(hw);
1897 return E1000_SUCCESS;
1900 /******************************************************************************
1901 * Sets the collision distance in the Transmit Control register
1903 * hw - Struct containing variables accessed by shared code
1905 * Link should have been established previously. Reads the speed and duplex
1906 * information from the Device Status register.
1907 ******************************************************************************/
1909 em_config_collision_dist(struct em_hw *hw)
1913 DEBUGFUNC("em_config_collision_dist");
1915 tctl = E1000_READ_REG(hw, TCTL);
1917 tctl &= ~E1000_TCTL_COLD;
1918 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1920 E1000_WRITE_REG(hw, TCTL, tctl);
1921 E1000_WRITE_FLUSH(hw);
1924 /******************************************************************************
1925 * Sets MAC speed and duplex settings to reflect the those in the PHY
1927 * hw - Struct containing variables accessed by shared code
1928 * mii_reg - data to write to the MII control register
1930 * The contents of the PHY register containing the needed information need to
1932 ******************************************************************************/
1934 em_config_mac_to_phy(struct em_hw *hw)
1940 DEBUGFUNC("em_config_mac_to_phy");
1942 /* 82544 or newer MAC, Auto Speed Detection takes care of
1943 * MAC speed/duplex configuration.*/
1944 if (hw->mac_type >= em_82544)
1945 return E1000_SUCCESS;
1947 /* Read the Device Control Register and set the bits to Force Speed
1950 ctrl = E1000_READ_REG(hw, CTRL);
1951 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1952 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1954 /* Set up duplex in the Device Control and Transmit Control
1955 * registers depending on negotiated values.
1957 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1961 if(phy_data & M88E1000_PSSR_DPLX)
1962 ctrl |= E1000_CTRL_FD;
1964 ctrl &= ~E1000_CTRL_FD;
1966 em_config_collision_dist(hw);
1968 /* Set up speed in the Device Control register depending on
1969 * negotiated values.
1971 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1972 ctrl |= E1000_CTRL_SPD_1000;
1973 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1974 ctrl |= E1000_CTRL_SPD_100;
1976 /* Write the configured values back to the Device Control Reg. */
1977 E1000_WRITE_REG(hw, CTRL, ctrl);
1978 return E1000_SUCCESS;
1981 /******************************************************************************
1982 * Forces the MAC's flow control settings.
1984 * hw - Struct containing variables accessed by shared code
1986 * Sets the TFCE and RFCE bits in the device control register to reflect
1987 * the adapter settings. TFCE and RFCE need to be explicitly set by
1988 * software when a Copper PHY is used because autonegotiation is managed
1989 * by the PHY rather than the MAC. Software must also configure these
1990 * bits when link is forced on a fiber connection.
1991 *****************************************************************************/
1993 em_force_mac_fc(struct em_hw *hw)
1997 DEBUGFUNC("em_force_mac_fc");
1999 /* Get the current configuration of the Device Control Register */
2000 ctrl = E1000_READ_REG(hw, CTRL);
2002 /* Because we didn't get link via the internal auto-negotiation
2003 * mechanism (we either forced link or we got link via PHY
2004 * auto-neg), we have to manually enable/disable transmit an
2005 * receive flow control.
2007 * The "Case" statement below enables/disable flow control
2008 * according to the "hw->fc" parameter.
2010 * The possible values of the "fc" parameter are:
2011 * 0: Flow control is completely disabled
2012 * 1: Rx flow control is enabled (we can receive pause
2013 * frames but not send pause frames).
2014 * 2: Tx flow control is enabled (we can send pause frames
2015 * frames but we do not receive pause frames).
2016 * 3: Both Rx and TX flow control (symmetric) is enabled.
2017 * other: No other values should be possible at this point.
2022 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2024 case em_fc_rx_pause:
2025 ctrl &= (~E1000_CTRL_TFCE);
2026 ctrl |= E1000_CTRL_RFCE;
2028 case em_fc_tx_pause:
2029 ctrl &= (~E1000_CTRL_RFCE);
2030 ctrl |= E1000_CTRL_TFCE;
2033 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2036 DEBUGOUT("Flow control param set incorrectly\n");
2037 return -E1000_ERR_CONFIG;
2040 /* Disable TX Flow Control for 82542 (rev 2.0) */
2041 if(hw->mac_type == em_82542_rev2_0)
2042 ctrl &= (~E1000_CTRL_TFCE);
2044 E1000_WRITE_REG(hw, CTRL, ctrl);
2045 return E1000_SUCCESS;
2048 /******************************************************************************
2049 * Configures flow control settings after link is established
2051 * hw - Struct containing variables accessed by shared code
2053 * Should be called immediately after a valid link has been established.
2054 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2055 * and autonegotiation is enabled, the MAC flow control settings will be set
2056 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2057 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2058 *****************************************************************************/
2060 em_config_fc_after_link_up(struct em_hw *hw)
2063 uint16_t mii_status_reg;
2064 uint16_t mii_nway_adv_reg;
2065 uint16_t mii_nway_lp_ability_reg;
2069 DEBUGFUNC("em_config_fc_after_link_up");
2071 /* Check for the case where we have fiber media and auto-neg failed
2072 * so we had to force link. In this case, we need to force the
2073 * configuration of the MAC to match the "fc" parameter.
2075 if(((hw->media_type == em_media_type_fiber) && (hw->autoneg_failed)) ||
2076 ((hw->media_type == em_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2077 ((hw->media_type == em_media_type_copper) && (!hw->autoneg))) {
2078 ret_val = em_force_mac_fc(hw);
2080 DEBUGOUT("Error forcing flow control settings\n");
2085 /* Check for the case where we have copper media and auto-neg is
2086 * enabled. In this case, we need to check and see if Auto-Neg
2087 * has completed, and if so, how the PHY and link partner has
2088 * flow control configured.
2090 if((hw->media_type == em_media_type_copper) && hw->autoneg) {
2091 /* Read the MII Status Register and check to see if AutoNeg
2092 * has completed. We read this twice because this reg has
2093 * some "sticky" (latched) bits.
2095 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2098 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2102 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2103 /* The AutoNeg process has completed, so we now need to
2104 * read both the Auto Negotiation Advertisement Register
2105 * (Address 4) and the Auto_Negotiation Base Page Ability
2106 * Register (Address 5) to determine how flow control was
2109 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_ADV,
2113 ret_val = em_read_phy_reg(hw, PHY_LP_ABILITY,
2114 &mii_nway_lp_ability_reg);
2118 /* Two bits in the Auto Negotiation Advertisement Register
2119 * (Address 4) and two bits in the Auto Negotiation Base
2120 * Page Ability Register (Address 5) determine flow control
2121 * for both the PHY and the link partner. The following
2122 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2123 * 1999, describes these PAUSE resolution bits and how flow
2124 * control is determined based upon these settings.
2125 * NOTE: DC = Don't Care
2127 * LOCAL DEVICE | LINK PARTNER
2128 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2129 *-------|---------|-------|---------|--------------------
2130 * 0 | 0 | DC | DC | em_fc_none
2131 * 0 | 1 | 0 | DC | em_fc_none
2132 * 0 | 1 | 1 | 0 | em_fc_none
2133 * 0 | 1 | 1 | 1 | em_fc_tx_pause
2134 * 1 | 0 | 0 | DC | em_fc_none
2135 * 1 | DC | 1 | DC | em_fc_full
2136 * 1 | 1 | 0 | 0 | em_fc_none
2137 * 1 | 1 | 0 | 1 | em_fc_rx_pause
2140 /* Are both PAUSE bits set to 1? If so, this implies
2141 * Symmetric Flow Control is enabled at both ends. The
2142 * ASM_DIR bits are irrelevant per the spec.
2144 * For Symmetric Flow Control:
2146 * LOCAL DEVICE | LINK PARTNER
2147 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2148 *-------|---------|-------|---------|--------------------
2149 * 1 | DC | 1 | DC | em_fc_full
2152 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2153 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2154 /* Now we need to check if the user selected RX ONLY
2155 * of pause frames. In this case, we had to advertise
2156 * FULL flow control because we could not advertise RX
2157 * ONLY. Hence, we must now check to see if we need to
2158 * turn OFF the TRANSMISSION of PAUSE frames.
2160 if(hw->original_fc == em_fc_full) {
2161 hw->fc = em_fc_full;
2162 DEBUGOUT("Flow Control = FULL.\r\n");
2164 hw->fc = em_fc_rx_pause;
2165 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2168 /* For receiving PAUSE frames ONLY.
2170 * LOCAL DEVICE | LINK PARTNER
2171 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2172 *-------|---------|-------|---------|--------------------
2173 * 0 | 1 | 1 | 1 | em_fc_tx_pause
2176 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2177 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2178 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2179 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2180 hw->fc = em_fc_tx_pause;
2181 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2183 /* For transmitting PAUSE frames ONLY.
2185 * LOCAL DEVICE | LINK PARTNER
2186 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2187 *-------|---------|-------|---------|--------------------
2188 * 1 | 1 | 0 | 1 | em_fc_rx_pause
2191 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2192 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2193 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2194 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2195 hw->fc = em_fc_rx_pause;
2196 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2198 /* Per the IEEE spec, at this point flow control should be
2199 * disabled. However, we want to consider that we could
2200 * be connected to a legacy switch that doesn't advertise
2201 * desired flow control, but can be forced on the link
2202 * partner. So if we advertised no flow control, that is
2203 * what we will resolve to. If we advertised some kind of
2204 * receive capability (Rx Pause Only or Full Flow Control)
2205 * and the link partner advertised none, we will configure
2206 * ourselves to enable Rx Flow Control only. We can do
2207 * this safely for two reasons: If the link partner really
2208 * didn't want flow control enabled, and we enable Rx, no
2209 * harm done since we won't be receiving any PAUSE frames
2210 * anyway. If the intent on the link partner was to have
2211 * flow control enabled, then by us enabling RX only, we
2212 * can at least receive pause frames and process them.
2213 * This is a good idea because in most cases, since we are
2214 * predominantly a server NIC, more times than not we will
2215 * be asked to delay transmission of packets than asking
2216 * our link partner to pause transmission of frames.
2218 else if((hw->original_fc == em_fc_none ||
2219 hw->original_fc == em_fc_tx_pause) ||
2220 hw->fc_strict_ieee) {
2221 hw->fc = em_fc_none;
2222 DEBUGOUT("Flow Control = NONE.\r\n");
2224 hw->fc = em_fc_rx_pause;
2225 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2228 /* Now we need to do one last check... If we auto-
2229 * negotiated to HALF DUPLEX, flow control should not be
2230 * enabled per IEEE 802.3 spec.
2232 ret_val = em_get_speed_and_duplex(hw, &speed, &duplex);
2234 DEBUGOUT("Error getting link speed and duplex\n");
2238 if(duplex == HALF_DUPLEX)
2239 hw->fc = em_fc_none;
2241 /* Now we call a subroutine to actually force the MAC
2242 * controller to use the correct flow control settings.
2244 ret_val = em_force_mac_fc(hw);
2246 DEBUGOUT("Error forcing flow control settings\n");
2250 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2253 return E1000_SUCCESS;
2256 /******************************************************************************
2257 * Checks to see if the link status of the hardware has changed.
2259 * hw - Struct containing variables accessed by shared code
2261 * Called by any function that needs to check the link status of the adapter.
2262 *****************************************************************************/
2264 em_check_for_link(struct em_hw *hw)
2271 uint32_t signal = 0;
2275 DEBUGFUNC("em_check_for_link");
2277 ctrl = E1000_READ_REG(hw, CTRL);
2278 status = E1000_READ_REG(hw, STATUS);
2280 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2281 * set when the optics detect a signal. On older adapters, it will be
2282 * cleared when there is a signal. This applies to fiber media only.
2284 if((hw->media_type == em_media_type_fiber) ||
2285 (hw->media_type == em_media_type_internal_serdes)) {
2286 rxcw = E1000_READ_REG(hw, RXCW);
2288 if(hw->media_type == em_media_type_fiber) {
2289 signal = (hw->mac_type > em_82544) ? E1000_CTRL_SWDPIN1 : 0;
2290 if(status & E1000_STATUS_LU)
2291 hw->get_link_status = FALSE;
2295 /* If we have a copper PHY then we only want to go out to the PHY
2296 * registers to see if Auto-Neg has completed and/or if our link
2297 * status has changed. The get_link_status flag will be set if we
2298 * receive a Link Status Change interrupt or we have Rx Sequence
2301 if((hw->media_type == em_media_type_copper) && hw->get_link_status) {
2302 /* First we want to see if the MII Status Register reports
2303 * link. If so, then we want to get the current speed/duplex
2305 * Read the register twice since the link bit is sticky.
2307 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2310 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2314 if(phy_data & MII_SR_LINK_STATUS) {
2315 hw->get_link_status = FALSE;
2316 /* Check if there was DownShift, must be checked immediately after
2318 em_check_downshift(hw);
2320 /* If we are on 82544 or 82543 silicon and speed/duplex
2321 * are forced to 10H or 10F, then we will implement the polarity
2322 * reversal workaround. We disable interrupts first, and upon
2323 * returning, place the devices interrupt state to its previous
2324 * value except for the link status change interrupt which will
2325 * happen due to the execution of this workaround.
2328 if((hw->mac_type == em_82544 || hw->mac_type == em_82543) &&
2330 (hw->forced_speed_duplex == em_10_full ||
2331 hw->forced_speed_duplex == em_10_half)) {
2332 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2333 ret_val = em_polarity_reversal_workaround(hw);
2334 icr = E1000_READ_REG(hw, ICR);
2335 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2336 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2340 /* No link detected */
2341 em_config_dsp_after_link_change(hw, FALSE);
2345 /* If we are forcing speed/duplex, then we simply return since
2346 * we have already determined whether we have link or not.
2348 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2350 /* optimize the dsp settings for the igp phy */
2351 em_config_dsp_after_link_change(hw, TRUE);
2353 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2354 * have Si on board that is 82544 or newer, Auto
2355 * Speed Detection takes care of MAC speed/duplex
2356 * configuration. So we only need to configure Collision
2357 * Distance in the MAC. Otherwise, we need to force
2358 * speed/duplex on the MAC to the current PHY speed/duplex
2361 if(hw->mac_type >= em_82544)
2362 em_config_collision_dist(hw);
2364 ret_val = em_config_mac_to_phy(hw);
2366 DEBUGOUT("Error configuring MAC to PHY settings\n");
2371 /* Configure Flow Control now that Auto-Neg has completed. First, we
2372 * need to restore the desired flow control settings because we may
2373 * have had to re-autoneg with a different link partner.
2375 ret_val = em_config_fc_after_link_up(hw);
2377 DEBUGOUT("Error configuring flow control\n");
2381 /* At this point we know that we are on copper and we have
2382 * auto-negotiated link. These are conditions for checking the link
2383 * partner capability register. We use the link speed to determine if
2384 * TBI compatibility needs to be turned on or off. If the link is not
2385 * at gigabit speed, then TBI compatibility is not needed. If we are
2386 * at gigabit speed, we turn on TBI compatibility.
2388 if(hw->tbi_compatibility_en) {
2389 uint16_t speed, duplex;
2390 em_get_speed_and_duplex(hw, &speed, &duplex);
2391 if(speed != SPEED_1000) {
2392 /* If link speed is not set to gigabit speed, we do not need
2393 * to enable TBI compatibility.
2395 if(hw->tbi_compatibility_on) {
2396 /* If we previously were in the mode, turn it off. */
2397 rctl = E1000_READ_REG(hw, RCTL);
2398 rctl &= ~E1000_RCTL_SBP;
2399 E1000_WRITE_REG(hw, RCTL, rctl);
2400 hw->tbi_compatibility_on = FALSE;
2403 /* If TBI compatibility is was previously off, turn it on. For
2404 * compatibility with a TBI link partner, we will store bad
2405 * packets. Some frames have an additional byte on the end and
2406 * will look like CRC errors to to the hardware.
2408 if(!hw->tbi_compatibility_on) {
2409 hw->tbi_compatibility_on = TRUE;
2410 rctl = E1000_READ_REG(hw, RCTL);
2411 rctl |= E1000_RCTL_SBP;
2412 E1000_WRITE_REG(hw, RCTL, rctl);
2417 /* If we don't have link (auto-negotiation failed or link partner cannot
2418 * auto-negotiate), the cable is plugged in (we have signal), and our
2419 * link partner is not trying to auto-negotiate with us (we are receiving
2420 * idles or data), we need to force link up. We also need to give
2421 * auto-negotiation time to complete, in case the cable was just plugged
2422 * in. The autoneg_failed flag does this.
2424 else if((((hw->media_type == em_media_type_fiber) &&
2425 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2426 (hw->media_type == em_media_type_internal_serdes)) &&
2427 (!(status & E1000_STATUS_LU)) &&
2428 (!(rxcw & E1000_RXCW_C))) {
2429 if(hw->autoneg_failed == 0) {
2430 hw->autoneg_failed = 1;
2433 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2435 /* Disable auto-negotiation in the TXCW register */
2436 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2438 /* Force link-up and also force full-duplex. */
2439 ctrl = E1000_READ_REG(hw, CTRL);
2440 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2441 E1000_WRITE_REG(hw, CTRL, ctrl);
2443 /* Configure Flow Control after forcing link up. */
2444 ret_val = em_config_fc_after_link_up(hw);
2446 DEBUGOUT("Error configuring flow control\n");
2450 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2451 * auto-negotiation in the TXCW register and disable forced link in the
2452 * Device Control register in an attempt to auto-negotiate with our link
2455 else if(((hw->media_type == em_media_type_fiber) ||
2456 (hw->media_type == em_media_type_internal_serdes)) &&
2457 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2458 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2459 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2460 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2462 hw->serdes_link_down = FALSE;
2464 /* If we force link for non-auto-negotiation switch, check link status
2465 * based on MAC synchronization for internal serdes media type.
2467 else if((hw->media_type == em_media_type_internal_serdes) &&
2468 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2469 /* SYNCH bit and IV bit are sticky. */
2471 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2472 if(!(rxcw & E1000_RXCW_IV)) {
2473 hw->serdes_link_down = FALSE;
2474 DEBUGOUT("SERDES: Link is up.\n");
2477 hw->serdes_link_down = TRUE;
2478 DEBUGOUT("SERDES: Link is down.\n");
2481 if((hw->media_type == em_media_type_internal_serdes) &&
2482 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2483 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2485 return E1000_SUCCESS;
2488 /******************************************************************************
2489 * Detects the current speed and duplex settings of the hardware.
2491 * hw - Struct containing variables accessed by shared code
2492 * speed - Speed of the connection
2493 * duplex - Duplex setting of the connection
2494 *****************************************************************************/
2496 em_get_speed_and_duplex(struct em_hw *hw,
2504 DEBUGFUNC("em_get_speed_and_duplex");
2506 if(hw->mac_type >= em_82543) {
2507 status = E1000_READ_REG(hw, STATUS);
2508 if(status & E1000_STATUS_SPEED_1000) {
2509 *speed = SPEED_1000;
2510 DEBUGOUT("1000 Mbs, ");
2511 } else if(status & E1000_STATUS_SPEED_100) {
2513 DEBUGOUT("100 Mbs, ");
2516 DEBUGOUT("10 Mbs, ");
2519 if(status & E1000_STATUS_FD) {
2520 *duplex = FULL_DUPLEX;
2521 DEBUGOUT("Full Duplex\r\n");
2523 *duplex = HALF_DUPLEX;
2524 DEBUGOUT(" Half Duplex\r\n");
2527 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2528 *speed = SPEED_1000;
2529 *duplex = FULL_DUPLEX;
2532 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2533 * if it is operating at half duplex. Here we set the duplex settings to
2534 * match the duplex in the link partner's capabilities.
2536 if(hw->phy_type == em_phy_igp && hw->speed_downgraded) {
2537 ret_val = em_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2541 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2542 *duplex = HALF_DUPLEX;
2544 ret_val = em_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2547 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2548 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2549 *duplex = HALF_DUPLEX;
2553 return E1000_SUCCESS;
2556 /******************************************************************************
2557 * Blocks until autoneg completes or times out (~4.5 seconds)
2559 * hw - Struct containing variables accessed by shared code
2560 ******************************************************************************/
2562 em_wait_autoneg(struct em_hw *hw)
2568 DEBUGFUNC("em_wait_autoneg");
2569 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2571 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2572 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2573 /* Read the MII Status Register and wait for Auto-Neg
2574 * Complete bit to be set.
2576 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2579 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
2582 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2583 return E1000_SUCCESS;
2587 return E1000_SUCCESS;
2590 /******************************************************************************
2591 * Raises the Management Data Clock
2593 * hw - Struct containing variables accessed by shared code
2594 * ctrl - Device control register's current value
2595 ******************************************************************************/
2597 em_raise_mdi_clk(struct em_hw *hw,
2600 /* Raise the clock input to the Management Data Clock (by setting the MDC
2601 * bit), and then delay 10 microseconds.
2603 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2604 E1000_WRITE_FLUSH(hw);
2608 /******************************************************************************
2609 * Lowers the Management Data Clock
2611 * hw - Struct containing variables accessed by shared code
2612 * ctrl - Device control register's current value
2613 ******************************************************************************/
2615 em_lower_mdi_clk(struct em_hw *hw,
2618 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2619 * bit), and then delay 10 microseconds.
2621 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2622 E1000_WRITE_FLUSH(hw);
2626 /******************************************************************************
2627 * Shifts data bits out to the PHY
2629 * hw - Struct containing variables accessed by shared code
2630 * data - Data to send out to the PHY
2631 * count - Number of bits to shift out
2633 * Bits are shifted out in MSB to LSB order.
2634 ******************************************************************************/
2636 em_shift_out_mdi_bits(struct em_hw *hw,
2643 /* We need to shift "count" number of bits out to the PHY. So, the value
2644 * in the "data" parameter will be shifted out to the PHY one bit at a
2645 * time. In order to do this, "data" must be broken down into bits.
2648 mask <<= (count - 1);
2650 ctrl = E1000_READ_REG(hw, CTRL);
2652 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2653 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2656 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2657 * then raising and lowering the Management Data Clock. A "0" is
2658 * shifted out to the PHY by setting the MDIO bit to "0" and then
2659 * raising and lowering the clock.
2661 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2662 else ctrl &= ~E1000_CTRL_MDIO;
2664 E1000_WRITE_REG(hw, CTRL, ctrl);
2665 E1000_WRITE_FLUSH(hw);
2669 em_raise_mdi_clk(hw, &ctrl);
2670 em_lower_mdi_clk(hw, &ctrl);
2676 /******************************************************************************
2677 * Shifts data bits in from the PHY
2679 * hw - Struct containing variables accessed by shared code
2681 * Bits are shifted in in MSB to LSB order.
2682 ******************************************************************************/
2684 em_shift_in_mdi_bits(struct em_hw *hw)
2690 /* In order to read a register from the PHY, we need to shift in a total
2691 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2692 * to avoid contention on the MDIO pin when a read operation is performed.
2693 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2694 * by raising the input to the Management Data Clock (setting the MDC bit),
2695 * and then reading the value of the MDIO bit.
2697 ctrl = E1000_READ_REG(hw, CTRL);
2699 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2700 ctrl &= ~E1000_CTRL_MDIO_DIR;
2701 ctrl &= ~E1000_CTRL_MDIO;
2703 E1000_WRITE_REG(hw, CTRL, ctrl);
2704 E1000_WRITE_FLUSH(hw);
2706 /* Raise and Lower the clock before reading in the data. This accounts for
2707 * the turnaround bits. The first clock occurred when we clocked out the
2708 * last bit of the Register Address.
2710 em_raise_mdi_clk(hw, &ctrl);
2711 em_lower_mdi_clk(hw, &ctrl);
2713 for(data = 0, i = 0; i < 16; i++) {
2715 em_raise_mdi_clk(hw, &ctrl);
2716 ctrl = E1000_READ_REG(hw, CTRL);
2717 /* Check to see if we shifted in a "1". */
2718 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2719 em_lower_mdi_clk(hw, &ctrl);
2722 em_raise_mdi_clk(hw, &ctrl);
2723 em_lower_mdi_clk(hw, &ctrl);
2728 /*****************************************************************************
2729 * Reads the value from a PHY register, if the value is on a specific non zero
2730 * page, sets the page first.
2731 * hw - Struct containing variables accessed by shared code
2732 * reg_addr - address of the PHY register to read
2733 ******************************************************************************/
2735 em_read_phy_reg(struct em_hw *hw,
2741 DEBUGFUNC("em_read_phy_reg");
2743 if((hw->phy_type == em_phy_igp ||
2744 hw->phy_type == em_phy_igp_2) &&
2745 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2746 ret_val = em_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2747 (uint16_t)reg_addr);
2753 ret_val = em_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2760 em_read_phy_reg_ex(struct em_hw *hw,
2766 const uint32_t phy_addr = 1;
2768 DEBUGFUNC("em_read_phy_reg_ex");
2770 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2771 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2772 return -E1000_ERR_PARAM;
2775 if(hw->mac_type > em_82543) {
2776 /* Set up Op-code, Phy Address, and register address in the MDI
2777 * Control register. The MAC will take care of interfacing with the
2778 * PHY to retrieve the desired data.
2780 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2781 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2782 (E1000_MDIC_OP_READ));
2784 E1000_WRITE_REG(hw, MDIC, mdic);
2786 /* Poll the ready bit to see if the MDI read completed */
2787 for(i = 0; i < 64; i++) {
2789 mdic = E1000_READ_REG(hw, MDIC);
2790 if(mdic & E1000_MDIC_READY) break;
2792 if(!(mdic & E1000_MDIC_READY)) {
2793 DEBUGOUT("MDI Read did not complete\n");
2794 return -E1000_ERR_PHY;
2796 if(mdic & E1000_MDIC_ERROR) {
2797 DEBUGOUT("MDI Error\n");
2798 return -E1000_ERR_PHY;
2800 *phy_data = (uint16_t) mdic;
2802 /* We must first send a preamble through the MDIO pin to signal the
2803 * beginning of an MII instruction. This is done by sending 32
2804 * consecutive "1" bits.
2806 em_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2808 /* Now combine the next few fields that are required for a read
2809 * operation. We use this method instead of calling the
2810 * em_shift_out_mdi_bits routine five different times. The format of
2811 * a MII read instruction consists of a shift out of 14 bits and is
2812 * defined as follows:
2813 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2814 * followed by a shift in of 18 bits. This first two bits shifted in
2815 * are TurnAround bits used to avoid contention on the MDIO pin when a
2816 * READ operation is performed. These two bits are thrown away
2817 * followed by a shift in of 16 bits which contains the desired data.
2819 mdic = ((reg_addr) | (phy_addr << 5) |
2820 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2822 em_shift_out_mdi_bits(hw, mdic, 14);
2824 /* Now that we've shifted out the read command to the MII, we need to
2825 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2828 *phy_data = em_shift_in_mdi_bits(hw);
2830 return E1000_SUCCESS;
2833 /******************************************************************************
2834 * Writes a value to a PHY register
2836 * hw - Struct containing variables accessed by shared code
2837 * reg_addr - address of the PHY register to write
2838 * data - data to write to the PHY
2839 ******************************************************************************/
2841 em_write_phy_reg(struct em_hw *hw,
2847 DEBUGFUNC("em_write_phy_reg");
2849 if((hw->phy_type == em_phy_igp ||
2850 hw->phy_type == em_phy_igp_2) &&
2851 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2852 ret_val = em_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2853 (uint16_t)reg_addr);
2859 ret_val = em_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2866 em_write_phy_reg_ex(struct em_hw *hw,
2872 const uint32_t phy_addr = 1;
2874 DEBUGFUNC("em_write_phy_reg_ex");
2876 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2877 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2878 return -E1000_ERR_PARAM;
2881 if(hw->mac_type > em_82543) {
2882 /* Set up Op-code, Phy Address, register address, and data intended
2883 * for the PHY register in the MDI Control register. The MAC will take
2884 * care of interfacing with the PHY to send the desired data.
2886 mdic = (((uint32_t) phy_data) |
2887 (reg_addr << E1000_MDIC_REG_SHIFT) |
2888 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2889 (E1000_MDIC_OP_WRITE));
2891 E1000_WRITE_REG(hw, MDIC, mdic);
2893 /* Poll the ready bit to see if the MDI read completed */
2894 for(i = 0; i < 640; i++) {
2896 mdic = E1000_READ_REG(hw, MDIC);
2897 if(mdic & E1000_MDIC_READY) break;
2899 if(!(mdic & E1000_MDIC_READY)) {
2900 DEBUGOUT("MDI Write did not complete\n");
2901 return -E1000_ERR_PHY;
2904 /* We'll need to use the SW defined pins to shift the write command
2905 * out to the PHY. We first send a preamble to the PHY to signal the
2906 * beginning of the MII instruction. This is done by sending 32
2907 * consecutive "1" bits.
2909 em_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2911 /* Now combine the remaining required fields that will indicate a
2912 * write operation. We use this method instead of calling the
2913 * em_shift_out_mdi_bits routine for each field in the command. The
2914 * format of a MII write instruction is as follows:
2915 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2917 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2918 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2920 mdic |= (uint32_t) phy_data;
2922 em_shift_out_mdi_bits(hw, mdic, 32);
2925 return E1000_SUCCESS;
2929 /******************************************************************************
2930 * Returns the PHY to the power-on reset state
2932 * hw - Struct containing variables accessed by shared code
2933 ******************************************************************************/
2935 em_phy_hw_reset(struct em_hw *hw)
2937 uint32_t ctrl, ctrl_ext;
2941 DEBUGFUNC("em_phy_hw_reset");
2943 /* In the case of the phy reset being blocked, it's not an error, we
2944 * simply return success without performing the reset. */
2945 ret_val = em_check_phy_reset_block(hw);
2947 return E1000_SUCCESS;
2949 DEBUGOUT("Resetting Phy...\n");
2951 if(hw->mac_type > em_82543) {
2953 * Read the device control register and assert the E1000_CTRL_PHY_RST
2954 * bit. Then, take it out of reset.
2955 * For pre-em_82571 hardware, we delay for 10ms between the assert
2956 * and deassert. For em_82571 hardware and later, we instead delay
2957 * for 10ms after the deassertion.
2959 ctrl = E1000_READ_REG(hw, CTRL);
2960 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2961 E1000_WRITE_FLUSH(hw);
2962 if (hw->mac_type < em_82571)
2964 E1000_WRITE_REG(hw, CTRL, ctrl);
2965 E1000_WRITE_FLUSH(hw);
2966 if (hw->mac_type >= em_82571)
2969 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2970 * bit to put the PHY into reset. Then, take it out of reset.
2972 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2973 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2974 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2975 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2976 E1000_WRITE_FLUSH(hw);
2978 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2979 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2980 E1000_WRITE_FLUSH(hw);
2984 if((hw->mac_type == em_82541) || (hw->mac_type == em_82547)) {
2985 /* Configure activity LED after PHY reset */
2986 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2987 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2988 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2989 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2992 /* Wait for FW to finish PHY configuration. */
2993 ret_val = em_get_phy_cfg_done(hw);
2998 /******************************************************************************
3001 * hw - Struct containing variables accessed by shared code
3003 * Sets bit 15 of the MII Control regiser
3004 ******************************************************************************/
3006 em_phy_reset(struct em_hw *hw)
3011 DEBUGFUNC("em_phy_reset");
3013 /* In the case of the phy reset being blocked, it's not an error, we
3014 * simply return success without performing the reset. */
3015 ret_val = em_check_phy_reset_block(hw);
3017 return E1000_SUCCESS;
3019 switch (hw->mac_type) {
3020 case em_82541_rev_2:
3023 ret_val = em_phy_hw_reset(hw);
3028 ret_val = em_read_phy_reg(hw, PHY_CTRL, &phy_data);
3032 phy_data |= MII_CR_RESET;
3033 ret_val = em_write_phy_reg(hw, PHY_CTRL, phy_data);
3041 if(hw->phy_type == em_phy_igp || hw->phy_type == em_phy_igp_2)
3042 em_phy_init_script(hw);
3044 return E1000_SUCCESS;
3047 /******************************************************************************
3048 * Probes the expected PHY address for known PHY IDs
3050 * hw - Struct containing variables accessed by shared code
3051 ******************************************************************************/
3053 em_detect_gig_phy(struct em_hw *hw)
3055 int32_t phy_init_status, ret_val;
3056 uint16_t phy_id_high, phy_id_low;
3057 boolean_t match = FALSE;
3059 DEBUGFUNC("em_detect_gig_phy");
3061 /* The 82571 firmware may still be configuring the PHY. In this
3062 * case, we cannot access the PHY until the configuration is done. So
3063 * we explicitly set the PHY values. */
3064 if(hw->mac_type == em_82571 || hw->mac_type == em_82572) {
3065 hw->phy_id = IGP01E1000_I_PHY_ID;
3066 hw->phy_type = em_phy_igp_2;
3067 return E1000_SUCCESS;
3070 /* Read the PHY ID Registers to identify which PHY is onboard. */
3071 ret_val = em_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3075 hw->phy_id = (uint32_t) (phy_id_high << 16);
3077 ret_val = em_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3081 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3082 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3084 switch(hw->mac_type) {
3086 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3089 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3093 case em_82545_rev_3:
3095 case em_82546_rev_3:
3096 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3099 case em_82541_rev_2:
3101 case em_82547_rev_2:
3102 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3105 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3108 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3109 return -E1000_ERR_CONFIG;
3111 phy_init_status = em_set_phy_type(hw);
3113 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3114 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3115 return E1000_SUCCESS;
3117 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3118 return -E1000_ERR_PHY;
3121 /******************************************************************************
3122 * Resets the PHY's DSP
3124 * hw - Struct containing variables accessed by shared code
3125 ******************************************************************************/
3127 em_phy_reset_dsp(struct em_hw *hw)
3130 DEBUGFUNC("em_phy_reset_dsp");
3133 ret_val = em_write_phy_reg(hw, 29, 0x001d);
3135 ret_val = em_write_phy_reg(hw, 30, 0x00c1);
3137 ret_val = em_write_phy_reg(hw, 30, 0x0000);
3139 ret_val = E1000_SUCCESS;
3145 /******************************************************************************
3146 * Get PHY information from various PHY registers for igp PHY only.
3148 * hw - Struct containing variables accessed by shared code
3149 * phy_info - PHY information structure
3150 ******************************************************************************/
3152 em_phy_igp_get_info(struct em_hw *hw,
3153 struct em_phy_info *phy_info)
3156 uint16_t phy_data, polarity, min_length, max_length, average;
3158 DEBUGFUNC("em_phy_igp_get_info");
3160 /* The downshift status is checked only once, after link is established,
3161 * and it stored in the hw->speed_downgraded parameter. */
3162 phy_info->downshift = (em_downshift)hw->speed_downgraded;
3164 /* IGP01E1000 does not need to support it. */
3165 phy_info->extended_10bt_distance = em_10bt_ext_dist_enable_normal;
3167 /* IGP01E1000 always correct polarity reversal */
3168 phy_info->polarity_correction = em_polarity_reversal_enabled;
3170 /* Check polarity status */
3171 ret_val = em_check_polarity(hw, &polarity);
3175 phy_info->cable_polarity = polarity;
3177 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3181 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3182 IGP01E1000_PSSR_MDIX_SHIFT;
3184 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3185 IGP01E1000_PSSR_SPEED_1000MBPS) {
3186 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3187 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3191 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3192 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3193 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3194 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3196 /* Get cable length */
3197 ret_val = em_get_cable_length(hw, &min_length, &max_length);
3201 /* Translate to old method */
3202 average = (max_length + min_length) / 2;
3204 if(average <= em_igp_cable_length_50)
3205 phy_info->cable_length = em_cable_length_50;
3206 else if(average <= em_igp_cable_length_80)
3207 phy_info->cable_length = em_cable_length_50_80;
3208 else if(average <= em_igp_cable_length_110)
3209 phy_info->cable_length = em_cable_length_80_110;
3210 else if(average <= em_igp_cable_length_140)
3211 phy_info->cable_length = em_cable_length_110_140;
3213 phy_info->cable_length = em_cable_length_140;
3216 return E1000_SUCCESS;
3219 /******************************************************************************
3220 * Get PHY information from various PHY registers fot m88 PHY only.
3222 * hw - Struct containing variables accessed by shared code
3223 * phy_info - PHY information structure
3224 ******************************************************************************/
3226 em_phy_m88_get_info(struct em_hw *hw,
3227 struct em_phy_info *phy_info)
3230 uint16_t phy_data, polarity;
3232 DEBUGFUNC("em_phy_m88_get_info");
3234 /* The downshift status is checked only once, after link is established,
3235 * and it stored in the hw->speed_downgraded parameter. */
3236 phy_info->downshift = (em_downshift)hw->speed_downgraded;
3238 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3242 phy_info->extended_10bt_distance =
3243 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3244 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3245 phy_info->polarity_correction =
3246 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3247 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3249 /* Check polarity status */
3250 ret_val = em_check_polarity(hw, &polarity);
3253 phy_info->cable_polarity = polarity;
3255 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3259 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3260 M88E1000_PSSR_MDIX_SHIFT;
3262 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3263 /* Cable Length Estimation and Local/Remote Receiver Information
3264 * are only valid at 1000 Mbps.
3266 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3267 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3269 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3273 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3274 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3276 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3277 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3280 return E1000_SUCCESS;
3283 /******************************************************************************
3284 * Get PHY information from various PHY registers
3286 * hw - Struct containing variables accessed by shared code
3287 * phy_info - PHY information structure
3288 ******************************************************************************/
3290 em_phy_get_info(struct em_hw *hw,
3291 struct em_phy_info *phy_info)
3296 DEBUGFUNC("em_phy_get_info");
3298 phy_info->cable_length = em_cable_length_undefined;
3299 phy_info->extended_10bt_distance = em_10bt_ext_dist_enable_undefined;
3300 phy_info->cable_polarity = em_rev_polarity_undefined;
3301 phy_info->downshift = em_downshift_undefined;
3302 phy_info->polarity_correction = em_polarity_reversal_undefined;
3303 phy_info->mdix_mode = em_auto_x_mode_undefined;
3304 phy_info->local_rx = em_1000t_rx_status_undefined;
3305 phy_info->remote_rx = em_1000t_rx_status_undefined;
3307 if(hw->media_type != em_media_type_copper) {
3308 DEBUGOUT("PHY info is only valid for copper media\n");
3309 return -E1000_ERR_CONFIG;
3312 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3316 ret_val = em_read_phy_reg(hw, PHY_STATUS, &phy_data);
3320 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3321 DEBUGOUT("PHY info is only valid if link is up\n");
3322 return -E1000_ERR_CONFIG;
3325 if(hw->phy_type == em_phy_igp ||
3326 hw->phy_type == em_phy_igp_2)
3327 return em_phy_igp_get_info(hw, phy_info);
3329 return em_phy_m88_get_info(hw, phy_info);
3333 em_validate_mdi_setting(struct em_hw *hw)
3335 DEBUGFUNC("em_validate_mdi_settings");
3337 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3338 DEBUGOUT("Invalid MDI setting detected\n");
3340 return -E1000_ERR_CONFIG;
3342 return E1000_SUCCESS;
3346 /******************************************************************************
3347 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3350 * hw - Struct containing variables accessed by shared code
3351 *****************************************************************************/
3353 em_init_eeprom_params(struct em_hw *hw)
3355 struct em_eeprom_info *eeprom = &hw->eeprom;
3356 uint32_t eecd = E1000_READ_REG(hw, EECD);
3357 int32_t ret_val = E1000_SUCCESS;
3358 uint16_t eeprom_size;
3360 DEBUGFUNC("em_init_eeprom_params");
3362 switch (hw->mac_type) {
3363 case em_82542_rev2_0:
3364 case em_82542_rev2_1:
3367 eeprom->type = em_eeprom_microwire;
3368 eeprom->word_size = 64;
3369 eeprom->opcode_bits = 3;
3370 eeprom->address_bits = 6;
3371 eeprom->delay_usec = 50;
3372 eeprom->use_eerd = FALSE;
3373 eeprom->use_eewr = FALSE;
3377 case em_82545_rev_3:
3379 case em_82546_rev_3:
3380 eeprom->type = em_eeprom_microwire;
3381 eeprom->opcode_bits = 3;
3382 eeprom->delay_usec = 50;
3383 if(eecd & E1000_EECD_SIZE) {
3384 eeprom->word_size = 256;
3385 eeprom->address_bits = 8;
3387 eeprom->word_size = 64;
3388 eeprom->address_bits = 6;
3390 eeprom->use_eerd = FALSE;
3391 eeprom->use_eewr = FALSE;
3394 case em_82541_rev_2:
3396 case em_82547_rev_2:
3397 if (eecd & E1000_EECD_TYPE) {
3398 eeprom->type = em_eeprom_spi;
3399 eeprom->opcode_bits = 8;
3400 eeprom->delay_usec = 1;
3401 if (eecd & E1000_EECD_ADDR_BITS) {
3402 eeprom->page_size = 32;
3403 eeprom->address_bits = 16;
3405 eeprom->page_size = 8;
3406 eeprom->address_bits = 8;
3409 eeprom->type = em_eeprom_microwire;
3410 eeprom->opcode_bits = 3;
3411 eeprom->delay_usec = 50;
3412 if (eecd & E1000_EECD_ADDR_BITS) {
3413 eeprom->word_size = 256;
3414 eeprom->address_bits = 8;
3416 eeprom->word_size = 64;
3417 eeprom->address_bits = 6;
3420 eeprom->use_eerd = FALSE;
3421 eeprom->use_eewr = FALSE;
3425 eeprom->type = em_eeprom_spi;
3426 eeprom->opcode_bits = 8;
3427 eeprom->delay_usec = 1;
3428 if (eecd & E1000_EECD_ADDR_BITS) {
3429 eeprom->page_size = 32;
3430 eeprom->address_bits = 16;
3432 eeprom->page_size = 8;
3433 eeprom->address_bits = 8;
3435 eeprom->use_eerd = FALSE;
3436 eeprom->use_eewr = FALSE;
3439 eeprom->type = em_eeprom_spi;
3440 eeprom->opcode_bits = 8;
3441 eeprom->delay_usec = 1;
3442 if (eecd & E1000_EECD_ADDR_BITS) {
3443 eeprom->page_size = 32;
3444 eeprom->address_bits = 16;
3446 eeprom->page_size = 8;
3447 eeprom->address_bits = 8;
3449 eeprom->use_eerd = TRUE;
3450 eeprom->use_eewr = TRUE;
3451 if(em_is_onboard_nvm_eeprom(hw) == FALSE) {
3452 eeprom->type = em_eeprom_flash;
3453 eeprom->word_size = 2048;
3455 /* Ensure that the Autonomous FLASH update bit is cleared due to
3456 * Flash update issue on parts which use a FLASH for NVM. */
3457 eecd &= ~E1000_EECD_AUPDEN;
3458 E1000_WRITE_REG(hw, EECD, eecd);
3465 if (eeprom->type == em_eeprom_spi) {
3466 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3467 * 32KB (incremented by powers of 2).
3469 if(hw->mac_type <= em_82547_rev_2) {
3470 /* Set to default value for initial eeprom read. */
3471 eeprom->word_size = 64;
3472 ret_val = em_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3475 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3476 /* 256B eeprom size was not supported in earlier hardware, so we
3477 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3478 * is never the result used in the shifting logic below. */
3482 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3483 E1000_EECD_SIZE_EX_SHIFT);
3486 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3491 /******************************************************************************
3492 * Raises the EEPROM's clock input.
3494 * hw - Struct containing variables accessed by shared code
3495 * eecd - EECD's current value
3496 *****************************************************************************/
3498 em_raise_ee_clk(struct em_hw *hw,
3501 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3502 * wait <delay> microseconds.
3504 *eecd = *eecd | E1000_EECD_SK;
3505 E1000_WRITE_REG(hw, EECD, *eecd);
3506 E1000_WRITE_FLUSH(hw);
3507 usec_delay(hw->eeprom.delay_usec);
3510 /******************************************************************************
3511 * Lowers the EEPROM's clock input.
3513 * hw - Struct containing variables accessed by shared code
3514 * eecd - EECD's current value
3515 *****************************************************************************/
3517 em_lower_ee_clk(struct em_hw *hw,
3520 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3521 * wait 50 microseconds.
3523 *eecd = *eecd & ~E1000_EECD_SK;
3524 E1000_WRITE_REG(hw, EECD, *eecd);
3525 E1000_WRITE_FLUSH(hw);
3526 usec_delay(hw->eeprom.delay_usec);
3529 /******************************************************************************
3530 * Shift data bits out to the EEPROM.
3532 * hw - Struct containing variables accessed by shared code
3533 * data - data to send to the EEPROM
3534 * count - number of bits to shift out
3535 *****************************************************************************/
3537 em_shift_out_ee_bits(struct em_hw *hw,
3541 struct em_eeprom_info *eeprom = &hw->eeprom;
3545 /* We need to shift "count" bits out to the EEPROM. So, value in the
3546 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3547 * In order to do this, "data" must be broken down into bits.
3549 mask = 0x01 << (count - 1);
3550 eecd = E1000_READ_REG(hw, EECD);
3551 if (eeprom->type == em_eeprom_microwire) {
3552 eecd &= ~E1000_EECD_DO;
3553 } else if (eeprom->type == em_eeprom_spi) {
3554 eecd |= E1000_EECD_DO;
3557 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3558 * and then raising and then lowering the clock (the SK bit controls
3559 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3560 * by setting "DI" to "0" and then raising and then lowering the clock.
3562 eecd &= ~E1000_EECD_DI;
3565 eecd |= E1000_EECD_DI;
3567 E1000_WRITE_REG(hw, EECD, eecd);
3568 E1000_WRITE_FLUSH(hw);
3570 usec_delay(eeprom->delay_usec);
3572 em_raise_ee_clk(hw, &eecd);
3573 em_lower_ee_clk(hw, &eecd);
3579 /* We leave the "DI" bit set to "0" when we leave this routine. */
3580 eecd &= ~E1000_EECD_DI;
3581 E1000_WRITE_REG(hw, EECD, eecd);
3584 /******************************************************************************
3585 * Shift data bits in from the EEPROM
3587 * hw - Struct containing variables accessed by shared code
3588 *****************************************************************************/
3590 em_shift_in_ee_bits(struct em_hw *hw,
3597 /* In order to read a register from the EEPROM, we need to shift 'count'
3598 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3599 * input to the EEPROM (setting the SK bit), and then reading the value of
3600 * the "DO" bit. During this "shifting in" process the "DI" bit should
3604 eecd = E1000_READ_REG(hw, EECD);
3606 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3609 for(i = 0; i < count; i++) {
3611 em_raise_ee_clk(hw, &eecd);
3613 eecd = E1000_READ_REG(hw, EECD);
3615 eecd &= ~(E1000_EECD_DI);
3616 if(eecd & E1000_EECD_DO)
3619 em_lower_ee_clk(hw, &eecd);
3625 /******************************************************************************
3626 * Prepares EEPROM for access
3628 * hw - Struct containing variables accessed by shared code
3630 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3631 * function should be called before issuing a command to the EEPROM.
3632 *****************************************************************************/
3634 em_acquire_eeprom(struct em_hw *hw)
3636 struct em_eeprom_info *eeprom = &hw->eeprom;
3639 DEBUGFUNC("em_acquire_eeprom");
3641 if(em_get_hw_eeprom_semaphore(hw))
3642 return -E1000_ERR_EEPROM;
3644 eecd = E1000_READ_REG(hw, EECD);
3646 if (hw->mac_type != em_82573) {
3647 /* Request EEPROM Access */
3648 if(hw->mac_type > em_82544) {
3649 eecd |= E1000_EECD_REQ;
3650 E1000_WRITE_REG(hw, EECD, eecd);
3651 eecd = E1000_READ_REG(hw, EECD);
3652 while((!(eecd & E1000_EECD_GNT)) &&
3653 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3656 eecd = E1000_READ_REG(hw, EECD);
3658 if(!(eecd & E1000_EECD_GNT)) {
3659 eecd &= ~E1000_EECD_REQ;
3660 E1000_WRITE_REG(hw, EECD, eecd);
3661 DEBUGOUT("Could not acquire EEPROM grant\n");
3662 em_put_hw_eeprom_semaphore(hw);
3663 return -E1000_ERR_EEPROM;
3668 /* Setup EEPROM for Read/Write */
3670 if (eeprom->type == em_eeprom_microwire) {
3671 /* Clear SK and DI */
3672 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3673 E1000_WRITE_REG(hw, EECD, eecd);
3676 eecd |= E1000_EECD_CS;
3677 E1000_WRITE_REG(hw, EECD, eecd);
3678 } else if (eeprom->type == em_eeprom_spi) {
3679 /* Clear SK and CS */
3680 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3681 E1000_WRITE_REG(hw, EECD, eecd);
3685 return E1000_SUCCESS;
3688 /******************************************************************************
3689 * Returns EEPROM to a "standby" state
3691 * hw - Struct containing variables accessed by shared code
3692 *****************************************************************************/
3694 em_standby_eeprom(struct em_hw *hw)
3696 struct em_eeprom_info *eeprom = &hw->eeprom;
3699 eecd = E1000_READ_REG(hw, EECD);
3701 if(eeprom->type == em_eeprom_microwire) {
3702 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3703 E1000_WRITE_REG(hw, EECD, eecd);
3704 E1000_WRITE_FLUSH(hw);
3705 usec_delay(eeprom->delay_usec);
3708 eecd |= E1000_EECD_SK;
3709 E1000_WRITE_REG(hw, EECD, eecd);
3710 E1000_WRITE_FLUSH(hw);
3711 usec_delay(eeprom->delay_usec);
3714 eecd |= E1000_EECD_CS;
3715 E1000_WRITE_REG(hw, EECD, eecd);
3716 E1000_WRITE_FLUSH(hw);
3717 usec_delay(eeprom->delay_usec);
3720 eecd &= ~E1000_EECD_SK;
3721 E1000_WRITE_REG(hw, EECD, eecd);
3722 E1000_WRITE_FLUSH(hw);
3723 usec_delay(eeprom->delay_usec);
3724 } else if(eeprom->type == em_eeprom_spi) {
3725 /* Toggle CS to flush commands */
3726 eecd |= E1000_EECD_CS;
3727 E1000_WRITE_REG(hw, EECD, eecd);
3728 E1000_WRITE_FLUSH(hw);
3729 usec_delay(eeprom->delay_usec);
3730 eecd &= ~E1000_EECD_CS;
3731 E1000_WRITE_REG(hw, EECD, eecd);
3732 E1000_WRITE_FLUSH(hw);
3733 usec_delay(eeprom->delay_usec);
3737 /******************************************************************************
3738 * Terminates a command by inverting the EEPROM's chip select pin
3740 * hw - Struct containing variables accessed by shared code
3741 *****************************************************************************/
3743 em_release_eeprom(struct em_hw *hw)
3747 DEBUGFUNC("em_release_eeprom");
3749 eecd = E1000_READ_REG(hw, EECD);
3751 if (hw->eeprom.type == em_eeprom_spi) {
3752 eecd |= E1000_EECD_CS; /* Pull CS high */
3753 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3755 E1000_WRITE_REG(hw, EECD, eecd);
3757 usec_delay(hw->eeprom.delay_usec);
3758 } else if(hw->eeprom.type == em_eeprom_microwire) {
3759 /* cleanup eeprom */
3761 /* CS on Microwire is active-high */
3762 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3764 E1000_WRITE_REG(hw, EECD, eecd);
3766 /* Rising edge of clock */
3767 eecd |= E1000_EECD_SK;
3768 E1000_WRITE_REG(hw, EECD, eecd);
3769 E1000_WRITE_FLUSH(hw);
3770 usec_delay(hw->eeprom.delay_usec);
3772 /* Falling edge of clock */
3773 eecd &= ~E1000_EECD_SK;
3774 E1000_WRITE_REG(hw, EECD, eecd);
3775 E1000_WRITE_FLUSH(hw);
3776 usec_delay(hw->eeprom.delay_usec);
3779 /* Stop requesting EEPROM access */
3780 if(hw->mac_type > em_82544) {
3781 eecd &= ~E1000_EECD_REQ;
3782 E1000_WRITE_REG(hw, EECD, eecd);
3785 em_put_hw_eeprom_semaphore(hw);
3788 /******************************************************************************
3789 * Reads a 16 bit word from the EEPROM.
3791 * hw - Struct containing variables accessed by shared code
3792 *****************************************************************************/
3794 em_spi_eeprom_ready(struct em_hw *hw)
3796 uint16_t retry_count = 0;
3797 uint8_t spi_stat_reg;
3799 DEBUGFUNC("em_spi_eeprom_ready");
3801 /* Read "Status Register" repeatedly until the LSB is cleared. The
3802 * EEPROM will signal that the command has been completed by clearing
3803 * bit 0 of the internal status register. If it's not cleared within
3804 * 5 milliseconds, then error out.
3808 em_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3809 hw->eeprom.opcode_bits);
3810 spi_stat_reg = (uint8_t)em_shift_in_ee_bits(hw, 8);
3811 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3817 em_standby_eeprom(hw);
3818 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3820 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3821 * only 0-5mSec on 5V devices)
3823 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3824 DEBUGOUT("SPI EEPROM Status error\n");
3825 return -E1000_ERR_EEPROM;
3828 return E1000_SUCCESS;
3831 /******************************************************************************
3832 * Reads a 16 bit word from the EEPROM.
3834 * hw - Struct containing variables accessed by shared code
3835 * offset - offset of word in the EEPROM to read
3836 * data - word read from the EEPROM
3837 * words - number of words to read
3838 *****************************************************************************/
3840 em_read_eeprom(struct em_hw *hw,
3845 struct em_eeprom_info *eeprom = &hw->eeprom;
3849 DEBUGFUNC("em_read_eeprom");
3851 /* A check for invalid values: offset too large, too many words, and not
3854 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3856 DEBUGOUT("\"words\" parameter out of bounds\n");
3857 return -E1000_ERR_EEPROM;
3860 /* FLASH reads without acquiring the semaphore are safe in 82573-based
3863 if ((em_is_onboard_nvm_eeprom(hw) == TRUE) ||
3864 (hw->mac_type != em_82573)) {
3865 /* Prepare the EEPROM for reading */
3866 if(em_acquire_eeprom(hw) != E1000_SUCCESS)
3867 return -E1000_ERR_EEPROM;
3870 if(eeprom->use_eerd == TRUE) {
3871 ret_val = em_read_eeprom_eerd(hw, offset, words, data);
3872 if ((em_is_onboard_nvm_eeprom(hw) == TRUE) ||
3873 (hw->mac_type != em_82573))
3874 em_release_eeprom(hw);
3878 if(eeprom->type == em_eeprom_spi) {
3880 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3882 if(em_spi_eeprom_ready(hw)) {
3883 em_release_eeprom(hw);
3884 return -E1000_ERR_EEPROM;
3887 em_standby_eeprom(hw);
3889 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3890 if((eeprom->address_bits == 8) && (offset >= 128))
3891 read_opcode |= EEPROM_A8_OPCODE_SPI;
3893 /* Send the READ command (opcode + addr) */
3894 em_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3895 em_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3897 /* Read the data. The address of the eeprom internally increments with
3898 * each byte (spi) being read, saving on the overhead of eeprom setup
3899 * and tear-down. The address counter will roll over if reading beyond
3900 * the size of the eeprom, thus allowing the entire memory to be read
3901 * starting from any offset. */
3902 for (i = 0; i < words; i++) {
3903 word_in = em_shift_in_ee_bits(hw, 16);
3904 data[i] = (word_in >> 8) | (word_in << 8);
3906 } else if(eeprom->type == em_eeprom_microwire) {
3907 for (i = 0; i < words; i++) {
3908 /* Send the READ command (opcode + addr) */
3909 em_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3910 eeprom->opcode_bits);
3911 em_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3912 eeprom->address_bits);
3914 /* Read the data. For microwire, each word requires the overhead
3915 * of eeprom setup and tear-down. */
3916 data[i] = em_shift_in_ee_bits(hw, 16);
3917 em_standby_eeprom(hw);
3921 /* End this read operation */
3922 em_release_eeprom(hw);
3924 return E1000_SUCCESS;
3927 /******************************************************************************
3928 * Reads a 16 bit word from the EEPROM using the EERD register.
3930 * hw - Struct containing variables accessed by shared code
3931 * offset - offset of word in the EEPROM to read
3932 * data - word read from the EEPROM
3933 * words - number of words to read
3934 *****************************************************************************/
3936 em_read_eeprom_eerd(struct em_hw *hw,
3941 uint32_t i, eerd = 0;
3944 for (i = 0; i < words; i++) {
3945 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3946 E1000_EEPROM_RW_REG_START;
3948 E1000_WRITE_REG(hw, EERD, eerd);
3949 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3954 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
3961 /******************************************************************************
3962 * Writes a 16 bit word from the EEPROM using the EEWR register.
3964 * hw - Struct containing variables accessed by shared code
3965 * offset - offset of word in the EEPROM to read
3966 * data - word read from the EEPROM
3967 * words - number of words to read
3968 *****************************************************************************/
3970 em_write_eeprom_eewr(struct em_hw *hw,
3975 uint32_t register_value = 0;
3979 for (i = 0; i < words; i++) {
3980 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
3981 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
3982 E1000_EEPROM_RW_REG_START;
3984 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
3989 E1000_WRITE_REG(hw, EEWR, register_value);
3991 error = em_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4001 /******************************************************************************
4002 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4004 * hw - Struct containing variables accessed by shared code
4005 *****************************************************************************/
4007 em_poll_eerd_eewr_done(struct em_hw *hw, int eerd)
4009 uint32_t attempts = 100000;
4010 uint32_t i, reg = 0;
4011 int32_t done = E1000_ERR_EEPROM;
4013 for(i = 0; i < attempts; i++) {
4014 if(eerd == E1000_EEPROM_POLL_READ)
4015 reg = E1000_READ_REG(hw, EERD);
4017 reg = E1000_READ_REG(hw, EEWR);
4019 if(reg & E1000_EEPROM_RW_REG_DONE) {
4020 done = E1000_SUCCESS;
4029 /***************************************************************************
4030 * Description: Determines if the onboard NVM is FLASH or EEPROM.
4032 * hw - Struct containing variables accessed by shared code
4033 ****************************************************************************/
4035 em_is_onboard_nvm_eeprom(struct em_hw *hw)
4039 if(hw->mac_type == em_82573) {
4040 eecd = E1000_READ_REG(hw, EECD);
4042 /* Isolate bits 15 & 16 */
4043 eecd = ((eecd >> 15) & 0x03);
4045 /* If both bits are set, device is Flash type */
4053 /******************************************************************************
4054 * Verifies that the EEPROM has a valid checksum
4056 * hw - Struct containing variables accessed by shared code
4058 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4059 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4061 *****************************************************************************/
4063 em_validate_eeprom_checksum(struct em_hw *hw)
4065 uint16_t checksum = 0;
4066 uint16_t i, eeprom_data;
4068 DEBUGFUNC("em_validate_eeprom_checksum");
4070 if ((hw->mac_type == em_82573) &&
4071 (em_is_onboard_nvm_eeprom(hw) == FALSE)) {
4072 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4073 * 10h-12h. Checksum may need to be fixed. */
4074 em_read_eeprom(hw, 0x10, 1, &eeprom_data);
4075 if ((eeprom_data & 0x10) == 0) {
4076 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4077 * has already been fixed. If the checksum is still wrong and this
4078 * bit is a 1, we need to return bad checksum. Otherwise, we need
4079 * to set this bit to a 1 and update the checksum. */
4080 em_read_eeprom(hw, 0x23, 1, &eeprom_data);
4081 if ((eeprom_data & 0x8000) == 0) {
4082 eeprom_data |= 0x8000;
4083 em_write_eeprom(hw, 0x23, 1, &eeprom_data);
4084 em_update_eeprom_checksum(hw);
4089 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4090 if(em_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4091 DEBUGOUT("EEPROM Read Error\n");
4092 return -E1000_ERR_EEPROM;
4094 checksum += eeprom_data;
4097 if(checksum == (uint16_t) EEPROM_SUM)
4098 return E1000_SUCCESS;
4100 DEBUGOUT("EEPROM Checksum Invalid\n");
4101 return -E1000_ERR_EEPROM;
4105 /******************************************************************************
4106 * Calculates the EEPROM checksum and writes it to the EEPROM
4108 * hw - Struct containing variables accessed by shared code
4110 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4111 * Writes the difference to word offset 63 of the EEPROM.
4112 *****************************************************************************/
4114 em_update_eeprom_checksum(struct em_hw *hw)
4116 uint16_t checksum = 0;
4117 uint16_t i, eeprom_data;
4119 DEBUGFUNC("em_update_eeprom_checksum");
4121 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4122 if(em_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4123 DEBUGOUT("EEPROM Read Error\n");
4124 return -E1000_ERR_EEPROM;
4126 checksum += eeprom_data;
4128 checksum = (uint16_t) EEPROM_SUM - checksum;
4129 if(em_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4130 DEBUGOUT("EEPROM Write Error\n");
4131 return -E1000_ERR_EEPROM;
4132 } else if (hw->eeprom.type == em_eeprom_flash) {
4133 em_commit_shadow_ram(hw);
4135 return E1000_SUCCESS;
4138 /******************************************************************************
4139 * Parent function for writing words to the different EEPROM types.
4141 * hw - Struct containing variables accessed by shared code
4142 * offset - offset within the EEPROM to be written to
4143 * words - number of words to write
4144 * data - 16 bit word to be written to the EEPROM
4146 * If em_update_eeprom_checksum is not called after this function, the
4147 * EEPROM will most likely contain an invalid checksum.
4148 *****************************************************************************/
4150 em_write_eeprom(struct em_hw *hw,
4155 struct em_eeprom_info *eeprom = &hw->eeprom;
4158 DEBUGFUNC("em_write_eeprom");
4160 /* A check for invalid values: offset too large, too many words, and not
4163 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4165 DEBUGOUT("\"words\" parameter out of bounds\n");
4166 return -E1000_ERR_EEPROM;
4169 /* 82573 writes only through eewr */
4170 if(eeprom->use_eewr == TRUE)
4171 return em_write_eeprom_eewr(hw, offset, words, data);
4173 /* Prepare the EEPROM for writing */
4174 if (em_acquire_eeprom(hw) != E1000_SUCCESS)
4175 return -E1000_ERR_EEPROM;
4177 if(eeprom->type == em_eeprom_microwire) {
4178 status = em_write_eeprom_microwire(hw, offset, words, data);
4180 status = em_write_eeprom_spi(hw, offset, words, data);
4184 /* Done with writing */
4185 em_release_eeprom(hw);
4190 /******************************************************************************
4191 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4193 * hw - Struct containing variables accessed by shared code
4194 * offset - offset within the EEPROM to be written to
4195 * words - number of words to write
4196 * data - pointer to array of 8 bit words to be written to the EEPROM
4198 *****************************************************************************/
4200 em_write_eeprom_spi(struct em_hw *hw,
4205 struct em_eeprom_info *eeprom = &hw->eeprom;
4208 DEBUGFUNC("em_write_eeprom_spi");
4210 while (widx < words) {
4211 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4213 if(em_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4215 em_standby_eeprom(hw);
4217 /* Send the WRITE ENABLE command (8 bit opcode ) */
4218 em_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4219 eeprom->opcode_bits);
4221 em_standby_eeprom(hw);
4223 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4224 if((eeprom->address_bits == 8) && (offset >= 128))
4225 write_opcode |= EEPROM_A8_OPCODE_SPI;
4227 /* Send the Write command (8-bit opcode + addr) */
4228 em_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4230 em_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4231 eeprom->address_bits);
4235 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4236 while (widx < words) {
4237 uint16_t word_out = data[widx];
4238 word_out = (word_out >> 8) | (word_out << 8);
4239 em_shift_out_ee_bits(hw, word_out, 16);
4242 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4243 * operation, while the smaller eeproms are capable of an 8-byte
4244 * PAGE WRITE operation. Break the inner loop to pass new address
4246 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4247 em_standby_eeprom(hw);
4253 return E1000_SUCCESS;
4256 /******************************************************************************
4257 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4259 * hw - Struct containing variables accessed by shared code
4260 * offset - offset within the EEPROM to be written to
4261 * words - number of words to write
4262 * data - pointer to array of 16 bit words to be written to the EEPROM
4264 *****************************************************************************/
4266 em_write_eeprom_microwire(struct em_hw *hw,
4271 struct em_eeprom_info *eeprom = &hw->eeprom;
4273 uint16_t words_written = 0;
4276 DEBUGFUNC("em_write_eeprom_microwire");
4278 /* Send the write enable command to the EEPROM (3-bit opcode plus
4279 * 6/8-bit dummy address beginning with 11). It's less work to include
4280 * the 11 of the dummy address as part of the opcode than it is to shift
4281 * it over the correct number of bits for the address. This puts the
4282 * EEPROM into write/erase mode.
4284 em_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4285 (uint16_t)(eeprom->opcode_bits + 2));
4287 em_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4289 /* Prepare the EEPROM */
4290 em_standby_eeprom(hw);
4292 while (words_written < words) {
4293 /* Send the Write command (3-bit opcode + addr) */
4294 em_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4295 eeprom->opcode_bits);
4297 em_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4298 eeprom->address_bits);
4301 em_shift_out_ee_bits(hw, data[words_written], 16);
4303 /* Toggle the CS line. This in effect tells the EEPROM to execute
4304 * the previous command.
4306 em_standby_eeprom(hw);
4308 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4309 * signal that the command has been completed by raising the DO signal.
4310 * If DO does not go high in 10 milliseconds, then error out.
4312 for(i = 0; i < 200; i++) {
4313 eecd = E1000_READ_REG(hw, EECD);
4314 if(eecd & E1000_EECD_DO) break;
4318 DEBUGOUT("EEPROM Write did not complete\n");
4319 return -E1000_ERR_EEPROM;
4322 /* Recover from write */
4323 em_standby_eeprom(hw);
4328 /* Send the write disable command to the EEPROM (3-bit opcode plus
4329 * 6/8-bit dummy address beginning with 10). It's less work to include
4330 * the 10 of the dummy address as part of the opcode than it is to shift
4331 * it over the correct number of bits for the address. This takes the
4332 * EEPROM out of write/erase mode.
4334 em_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4335 (uint16_t)(eeprom->opcode_bits + 2));
4337 em_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4339 return E1000_SUCCESS;
4342 /******************************************************************************
4343 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4344 * in the eeprom cache and the non modified values in the currently active bank
4347 * hw - Struct containing variables accessed by shared code
4348 * offset - offset of word in the EEPROM to read
4349 * data - word read from the EEPROM
4350 * words - number of words to read
4351 *****************************************************************************/
4353 em_commit_shadow_ram(struct em_hw *hw)
4355 uint32_t attempts = 100000;
4359 int32_t error = E1000_SUCCESS;
4361 /* The flop register will be used to determine if flash type is STM */
4362 flop = E1000_READ_REG(hw, FLOP);
4364 if (hw->mac_type == em_82573) {
4365 for (i=0; i < attempts; i++) {
4366 eecd = E1000_READ_REG(hw, EECD);
4367 if ((eecd & E1000_EECD_FLUPD) == 0) {
4373 if (i == attempts) {
4374 return -E1000_ERR_EEPROM;
4377 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4378 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4379 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4382 /* Perform the flash update */
4383 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4385 for (i=0; i < attempts; i++) {
4386 eecd = E1000_READ_REG(hw, EECD);
4387 if ((eecd & E1000_EECD_FLUPD) == 0) {
4393 if (i == attempts) {
4394 return -E1000_ERR_EEPROM;
4401 /******************************************************************************
4402 * Reads the adapter's part number from the EEPROM
4404 * hw - Struct containing variables accessed by shared code
4405 * part_num - Adapter's part number
4406 *****************************************************************************/
4408 em_read_part_num(struct em_hw *hw,
4411 uint16_t offset = EEPROM_PBA_BYTE_1;
4412 uint16_t eeprom_data;
4414 DEBUGFUNC("em_read_part_num");
4416 /* Get word 0 from EEPROM */
4417 if(em_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4418 DEBUGOUT("EEPROM Read Error\n");
4419 return -E1000_ERR_EEPROM;
4421 /* Save word 0 in upper half of part_num */
4422 *part_num = (uint32_t) (eeprom_data << 16);
4424 /* Get word 1 from EEPROM */
4425 if(em_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
4426 DEBUGOUT("EEPROM Read Error\n");
4427 return -E1000_ERR_EEPROM;
4429 /* Save word 1 in lower half of part_num */
4430 *part_num |= eeprom_data;
4432 return E1000_SUCCESS;
4435 /******************************************************************************
4436 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4437 * second function of dual function devices
4439 * hw - Struct containing variables accessed by shared code
4440 *****************************************************************************/
4442 em_read_mac_addr(struct em_hw * hw)
4445 uint16_t eeprom_data, i;
4447 DEBUGFUNC("em_read_mac_addr");
4449 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4451 if(em_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4452 DEBUGOUT("EEPROM Read Error\n");
4453 return -E1000_ERR_EEPROM;
4455 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
4456 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
4458 switch (hw->mac_type) {
4460 case em_82546_rev_3:
4462 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
4463 hw->perm_mac_addr[5] ^= 0x01;
4468 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
4469 hw->mac_addr[i] = hw->perm_mac_addr[i];
4470 return E1000_SUCCESS;
4473 /******************************************************************************
4474 * Initializes receive address filters.
4476 * hw - Struct containing variables accessed by shared code
4478 * Places the MAC address in receive address register 0 and clears the rest
4479 * of the receive addresss registers. Clears the multicast table. Assumes
4480 * the receiver is in reset when the routine is called.
4481 *****************************************************************************/
4483 em_init_rx_addrs(struct em_hw *hw)
4488 DEBUGFUNC("em_init_rx_addrs");
4490 /* Setup the receive address. */
4491 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4493 em_rar_set(hw, hw->mac_addr, 0);
4495 rar_num = E1000_RAR_ENTRIES;
4497 /* Reserve a spot for the Locally Administered Address to work around
4498 * an 82571 issue in which a reset on one port will reload the MAC on
4499 * the other port. */
4500 if ((hw->mac_type == em_82571) && (hw->laa_is_present == TRUE))
4502 /* Zero out the other 15 receive addresses. */
4503 DEBUGOUT("Clearing RAR[1-15]\n");
4504 for(i = 1; i < rar_num; i++) {
4505 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4506 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4510 /******************************************************************************
4511 * Updates the MAC's list of multicast addresses.
4513 * hw - Struct containing variables accessed by shared code
4514 * mc_addr_list - the list of new multicast addresses
4515 * mc_addr_count - number of addresses
4516 * pad - number of bytes between addresses in the list
4517 * rar_used_count - offset where to start adding mc addresses into the RAR's
4519 * The given list replaces any existing list. Clears the last 15 receive
4520 * address registers and the multicast table. Uses receive address registers
4521 * for the first 15 multicast addresses, and hashes the rest into the
4523 *****************************************************************************/
4525 em_mc_addr_list_update(struct em_hw *hw,
4526 uint8_t *mc_addr_list,
4527 uint32_t mc_addr_count,
4529 uint32_t rar_used_count)
4531 uint32_t hash_value;
4533 uint32_t num_rar_entry;
4534 uint32_t num_mta_entry;
4536 DEBUGFUNC("em_mc_addr_list_update");
4538 /* Set the new number of MC addresses that we are being requested to use. */
4539 hw->num_mc_addrs = mc_addr_count;
4541 /* Clear RAR[1-15] */
4542 DEBUGOUT(" Clearing RAR[1-15]\n");
4543 num_rar_entry = E1000_RAR_ENTRIES;
4544 /* Reserve a spot for the Locally Administered Address to work around
4545 * an 82571 issue in which a reset on one port will reload the MAC on
4546 * the other port. */
4547 if ((hw->mac_type == em_82571) && (hw->laa_is_present == TRUE))
4550 for(i = rar_used_count; i < num_rar_entry; i++) {
4551 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4552 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4556 DEBUGOUT(" Clearing MTA\n");
4557 num_mta_entry = E1000_NUM_MTA_REGISTERS;
4558 for(i = 0; i < num_mta_entry; i++) {
4559 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
4562 /* Add the new addresses */
4563 for(i = 0; i < mc_addr_count; i++) {
4564 DEBUGOUT(" Adding the multicast addresses:\n");
4565 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
4566 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
4567 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
4568 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
4569 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
4570 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
4571 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
4573 hash_value = em_hash_mc_addr(hw,
4575 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
4577 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
4579 /* Place this multicast address in the RAR if there is room, *
4580 * else put it in the MTA
4582 if (rar_used_count < num_rar_entry) {
4584 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
4588 em_mta_set(hw, hash_value);
4591 DEBUGOUT("MC Update Complete\n");
4594 /******************************************************************************
4595 * Hashes an address to determine its location in the multicast table
4597 * hw - Struct containing variables accessed by shared code
4598 * mc_addr - the multicast address to hash
4599 *****************************************************************************/
4601 em_hash_mc_addr(struct em_hw *hw,
4604 uint32_t hash_value = 0;
4606 /* The portion of the address that is used for the hash table is
4607 * determined by the mc_filter_type setting.
4609 switch (hw->mc_filter_type) {
4610 /* [0] [1] [2] [3] [4] [5]
4615 /* [47:36] i.e. 0x563 for above example address */
4616 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
4619 /* [46:35] i.e. 0xAC6 for above example address */
4620 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4623 /* [45:34] i.e. 0x5D8 for above example address */
4624 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4627 /* [43:32] i.e. 0x634 for above example address */
4628 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4632 hash_value &= 0xFFF;
4637 /******************************************************************************
4638 * Sets the bit in the multicast table corresponding to the hash value.
4640 * hw - Struct containing variables accessed by shared code
4641 * hash_value - Multicast address hash value
4642 *****************************************************************************/
4644 em_mta_set(struct em_hw *hw,
4645 uint32_t hash_value)
4647 uint32_t hash_bit, hash_reg;
4651 /* The MTA is a register array of 128 32-bit registers.
4652 * It is treated like an array of 4096 bits. We want to set
4653 * bit BitArray[hash_value]. So we figure out what register
4654 * the bit is in, read it, OR in the new bit, then write
4655 * back the new value. The register is determined by the
4656 * upper 7 bits of the hash value and the bit within that
4657 * register are determined by the lower 5 bits of the value.
4659 hash_reg = (hash_value >> 5) & 0x7F;
4660 hash_bit = hash_value & 0x1F;
4662 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4664 mta |= (1 << hash_bit);
4666 /* If we are on an 82544 and we are trying to write an odd offset
4667 * in the MTA, save off the previous entry before writing and
4668 * restore the old value after writing.
4670 if((hw->mac_type == em_82544) && ((hash_reg & 0x1) == 1)) {
4671 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4672 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4673 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4675 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4679 /******************************************************************************
4680 * Puts an ethernet address into a receive address register.
4682 * hw - Struct containing variables accessed by shared code
4683 * addr - Address to put into receive address register
4684 * index - Receive address register to write
4685 *****************************************************************************/
4687 em_rar_set(struct em_hw *hw,
4691 uint32_t rar_low, rar_high;
4693 /* HW expects these in little endian so we reverse the byte order
4694 * from network order (big endian) to little endian
4696 rar_low = ((uint32_t) addr[0] |
4697 ((uint32_t) addr[1] << 8) |
4698 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4700 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4702 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4703 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4706 /******************************************************************************
4707 * Writes a value to the specified offset in the VLAN filter table.
4709 * hw - Struct containing variables accessed by shared code
4710 * offset - Offset in VLAN filer table to write
4711 * value - Value to write into VLAN filter table
4712 *****************************************************************************/
4714 em_write_vfta(struct em_hw *hw,
4720 if((hw->mac_type == em_82544) && ((offset & 0x1) == 1)) {
4721 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4722 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4723 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4725 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4729 /******************************************************************************
4730 * Clears the VLAN filer table
4732 * hw - Struct containing variables accessed by shared code
4733 *****************************************************************************/
4735 em_clear_vfta(struct em_hw *hw)
4738 uint32_t vfta_value = 0;
4739 uint32_t vfta_offset = 0;
4740 uint32_t vfta_bit_in_reg = 0;
4742 if (hw->mac_type == em_82573) {
4743 if (hw->mng_cookie.vlan_id != 0) {
4744 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
4745 * ID. The following operations determine which 32b entry
4746 * (i.e. offset) into the array we want to set the VLAN ID
4747 * (i.e. bit) of the manageability unit. */
4748 vfta_offset = (hw->mng_cookie.vlan_id >>
4749 E1000_VFTA_ENTRY_SHIFT) &
4750 E1000_VFTA_ENTRY_MASK;
4751 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
4752 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
4755 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4756 /* If the offset we want to clear is the same offset of the
4757 * manageability VLAN ID, then clear all bits except that of the
4758 * manageability unit */
4759 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4760 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4765 em_id_led_init(struct em_hw * hw)
4768 const uint32_t ledctl_mask = 0x000000FF;
4769 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4770 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4771 uint16_t eeprom_data, i, temp;
4772 const uint16_t led_mask = 0x0F;
4774 DEBUGFUNC("em_id_led_init");
4776 if(hw->mac_type < em_82540) {
4778 return E1000_SUCCESS;
4781 ledctl = E1000_READ_REG(hw, LEDCTL);
4782 hw->ledctl_default = ledctl;
4783 hw->ledctl_mode1 = hw->ledctl_default;
4784 hw->ledctl_mode2 = hw->ledctl_default;
4786 if(em_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4787 DEBUGOUT("EEPROM Read Error\n");
4788 return -E1000_ERR_EEPROM;
4790 if((eeprom_data== ID_LED_RESERVED_0000) ||
4791 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4792 for(i = 0; i < 4; i++) {
4793 temp = (eeprom_data >> (i << 2)) & led_mask;
4795 case ID_LED_ON1_DEF2:
4796 case ID_LED_ON1_ON2:
4797 case ID_LED_ON1_OFF2:
4798 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4799 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4801 case ID_LED_OFF1_DEF2:
4802 case ID_LED_OFF1_ON2:
4803 case ID_LED_OFF1_OFF2:
4804 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4805 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4812 case ID_LED_DEF1_ON2:
4813 case ID_LED_ON1_ON2:
4814 case ID_LED_OFF1_ON2:
4815 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4816 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4818 case ID_LED_DEF1_OFF2:
4819 case ID_LED_ON1_OFF2:
4820 case ID_LED_OFF1_OFF2:
4821 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4822 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4829 return E1000_SUCCESS;
4832 /******************************************************************************
4833 * Prepares SW controlable LED for use and saves the current state of the LED.
4835 * hw - Struct containing variables accessed by shared code
4836 *****************************************************************************/
4838 em_setup_led(struct em_hw *hw)
4841 int32_t ret_val = E1000_SUCCESS;
4843 DEBUGFUNC("em_setup_led");
4845 switch(hw->mac_type) {
4846 case em_82542_rev2_0:
4847 case em_82542_rev2_1:
4850 /* No setup necessary */
4854 case em_82541_rev_2:
4855 case em_82547_rev_2:
4856 /* Turn off PHY Smart Power Down (if enabled) */
4857 ret_val = em_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4858 &hw->phy_spd_default);
4861 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4862 (uint16_t)(hw->phy_spd_default &
4863 ~IGP01E1000_GMII_SPD));
4868 if(hw->media_type == em_media_type_fiber) {
4869 ledctl = E1000_READ_REG(hw, LEDCTL);
4870 /* Save current LEDCTL settings */
4871 hw->ledctl_default = ledctl;
4873 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4874 E1000_LEDCTL_LED0_BLINK |
4875 E1000_LEDCTL_LED0_MODE_MASK);
4876 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4877 E1000_LEDCTL_LED0_MODE_SHIFT);
4878 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4879 } else if(hw->media_type == em_media_type_copper)
4880 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4884 return E1000_SUCCESS;
4887 /******************************************************************************
4888 * Restores the saved state of the SW controlable LED.
4890 * hw - Struct containing variables accessed by shared code
4891 *****************************************************************************/
4893 em_cleanup_led(struct em_hw *hw)
4895 int32_t ret_val = E1000_SUCCESS;
4897 DEBUGFUNC("em_cleanup_led");
4899 switch(hw->mac_type) {
4900 case em_82542_rev2_0:
4901 case em_82542_rev2_1:
4904 /* No cleanup necessary */
4908 case em_82541_rev_2:
4909 case em_82547_rev_2:
4910 /* Turn on PHY Smart Power Down (if previously enabled) */
4911 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4912 hw->phy_spd_default);
4917 /* Restore LEDCTL settings */
4918 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4922 return E1000_SUCCESS;
4925 /******************************************************************************
4926 * Turns on the software controllable LED
4928 * hw - Struct containing variables accessed by shared code
4929 *****************************************************************************/
4931 em_led_on(struct em_hw *hw)
4933 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4935 DEBUGFUNC("em_led_on");
4937 switch(hw->mac_type) {
4938 case em_82542_rev2_0:
4939 case em_82542_rev2_1:
4941 /* Set SW Defineable Pin 0 to turn on the LED */
4942 ctrl |= E1000_CTRL_SWDPIN0;
4943 ctrl |= E1000_CTRL_SWDPIO0;
4946 if(hw->media_type == em_media_type_fiber) {
4947 /* Set SW Defineable Pin 0 to turn on the LED */
4948 ctrl |= E1000_CTRL_SWDPIN0;
4949 ctrl |= E1000_CTRL_SWDPIO0;
4951 /* Clear SW Defineable Pin 0 to turn on the LED */
4952 ctrl &= ~E1000_CTRL_SWDPIN0;
4953 ctrl |= E1000_CTRL_SWDPIO0;
4957 if(hw->media_type == em_media_type_fiber) {
4958 /* Clear SW Defineable Pin 0 to turn on the LED */
4959 ctrl &= ~E1000_CTRL_SWDPIN0;
4960 ctrl |= E1000_CTRL_SWDPIO0;
4961 } else if(hw->media_type == em_media_type_copper) {
4962 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4963 return E1000_SUCCESS;
4968 E1000_WRITE_REG(hw, CTRL, ctrl);
4970 return E1000_SUCCESS;
4973 /******************************************************************************
4974 * Turns off the software controllable LED
4976 * hw - Struct containing variables accessed by shared code
4977 *****************************************************************************/
4979 em_led_off(struct em_hw *hw)
4981 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4983 DEBUGFUNC("em_led_off");
4985 switch(hw->mac_type) {
4986 case em_82542_rev2_0:
4987 case em_82542_rev2_1:
4989 /* Clear SW Defineable Pin 0 to turn off the LED */
4990 ctrl &= ~E1000_CTRL_SWDPIN0;
4991 ctrl |= E1000_CTRL_SWDPIO0;
4994 if(hw->media_type == em_media_type_fiber) {
4995 /* Clear SW Defineable Pin 0 to turn off the LED */
4996 ctrl &= ~E1000_CTRL_SWDPIN0;
4997 ctrl |= E1000_CTRL_SWDPIO0;
4999 /* Set SW Defineable Pin 0 to turn off the LED */
5000 ctrl |= E1000_CTRL_SWDPIN0;
5001 ctrl |= E1000_CTRL_SWDPIO0;
5005 if(hw->media_type == em_media_type_fiber) {
5006 /* Set SW Defineable Pin 0 to turn off the LED */
5007 ctrl |= E1000_CTRL_SWDPIN0;
5008 ctrl |= E1000_CTRL_SWDPIO0;
5009 } else if(hw->media_type == em_media_type_copper) {
5010 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5011 return E1000_SUCCESS;
5016 E1000_WRITE_REG(hw, CTRL, ctrl);
5018 return E1000_SUCCESS;
5021 /******************************************************************************
5022 * Clears all hardware statistics counters.
5024 * hw - Struct containing variables accessed by shared code
5025 *****************************************************************************/
5027 em_clear_hw_cntrs(struct em_hw *hw)
5029 volatile uint32_t temp;
5031 temp = E1000_READ_REG(hw, CRCERRS);
5032 temp = E1000_READ_REG(hw, SYMERRS);
5033 temp = E1000_READ_REG(hw, MPC);
5034 temp = E1000_READ_REG(hw, SCC);
5035 temp = E1000_READ_REG(hw, ECOL);
5036 temp = E1000_READ_REG(hw, MCC);
5037 temp = E1000_READ_REG(hw, LATECOL);
5038 temp = E1000_READ_REG(hw, COLC);
5039 temp = E1000_READ_REG(hw, DC);
5040 temp = E1000_READ_REG(hw, SEC);
5041 temp = E1000_READ_REG(hw, RLEC);
5042 temp = E1000_READ_REG(hw, XONRXC);
5043 temp = E1000_READ_REG(hw, XONTXC);
5044 temp = E1000_READ_REG(hw, XOFFRXC);
5045 temp = E1000_READ_REG(hw, XOFFTXC);
5046 temp = E1000_READ_REG(hw, FCRUC);
5047 temp = E1000_READ_REG(hw, PRC64);
5048 temp = E1000_READ_REG(hw, PRC127);
5049 temp = E1000_READ_REG(hw, PRC255);
5050 temp = E1000_READ_REG(hw, PRC511);
5051 temp = E1000_READ_REG(hw, PRC1023);
5052 temp = E1000_READ_REG(hw, PRC1522);
5053 temp = E1000_READ_REG(hw, GPRC);
5054 temp = E1000_READ_REG(hw, BPRC);
5055 temp = E1000_READ_REG(hw, MPRC);
5056 temp = E1000_READ_REG(hw, GPTC);
5057 temp = E1000_READ_REG(hw, GORCL);
5058 temp = E1000_READ_REG(hw, GORCH);
5059 temp = E1000_READ_REG(hw, GOTCL);
5060 temp = E1000_READ_REG(hw, GOTCH);
5061 temp = E1000_READ_REG(hw, RNBC);
5062 temp = E1000_READ_REG(hw, RUC);
5063 temp = E1000_READ_REG(hw, RFC);
5064 temp = E1000_READ_REG(hw, ROC);
5065 temp = E1000_READ_REG(hw, RJC);
5066 temp = E1000_READ_REG(hw, TORL);
5067 temp = E1000_READ_REG(hw, TORH);
5068 temp = E1000_READ_REG(hw, TOTL);
5069 temp = E1000_READ_REG(hw, TOTH);
5070 temp = E1000_READ_REG(hw, TPR);
5071 temp = E1000_READ_REG(hw, TPT);
5072 temp = E1000_READ_REG(hw, PTC64);
5073 temp = E1000_READ_REG(hw, PTC127);
5074 temp = E1000_READ_REG(hw, PTC255);
5075 temp = E1000_READ_REG(hw, PTC511);
5076 temp = E1000_READ_REG(hw, PTC1023);
5077 temp = E1000_READ_REG(hw, PTC1522);
5078 temp = E1000_READ_REG(hw, MPTC);
5079 temp = E1000_READ_REG(hw, BPTC);
5081 if(hw->mac_type < em_82543) return;
5083 temp = E1000_READ_REG(hw, ALGNERRC);
5084 temp = E1000_READ_REG(hw, RXERRC);
5085 temp = E1000_READ_REG(hw, TNCRS);
5086 temp = E1000_READ_REG(hw, CEXTERR);
5087 temp = E1000_READ_REG(hw, TSCTC);
5088 temp = E1000_READ_REG(hw, TSCTFC);
5090 if(hw->mac_type <= em_82544) return;
5092 temp = E1000_READ_REG(hw, MGTPRC);
5093 temp = E1000_READ_REG(hw, MGTPDC);
5094 temp = E1000_READ_REG(hw, MGTPTC);
5096 if(hw->mac_type <= em_82547_rev_2) return;
5098 temp = E1000_READ_REG(hw, IAC);
5099 temp = E1000_READ_REG(hw, ICRXOC);
5100 temp = E1000_READ_REG(hw, ICRXPTC);
5101 temp = E1000_READ_REG(hw, ICRXATC);
5102 temp = E1000_READ_REG(hw, ICTXPTC);
5103 temp = E1000_READ_REG(hw, ICTXATC);
5104 temp = E1000_READ_REG(hw, ICTXQEC);
5105 temp = E1000_READ_REG(hw, ICTXQMTC);
5106 temp = E1000_READ_REG(hw, ICRXDMTC);
5110 /******************************************************************************
5111 * Resets Adaptive IFS to its default state.
5113 * hw - Struct containing variables accessed by shared code
5115 * Call this after em_init_hw. You may override the IFS defaults by setting
5116 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5117 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5118 * before calling this function.
5119 *****************************************************************************/
5121 em_reset_adaptive(struct em_hw *hw)
5123 DEBUGFUNC("em_reset_adaptive");
5125 if(hw->adaptive_ifs) {
5126 if(!hw->ifs_params_forced) {
5127 hw->current_ifs_val = 0;
5128 hw->ifs_min_val = IFS_MIN;
5129 hw->ifs_max_val = IFS_MAX;
5130 hw->ifs_step_size = IFS_STEP;
5131 hw->ifs_ratio = IFS_RATIO;
5133 hw->in_ifs_mode = FALSE;
5134 E1000_WRITE_REG(hw, AIT, 0);
5136 DEBUGOUT("Not in Adaptive IFS mode!\n");
5140 /******************************************************************************
5141 * Called during the callback/watchdog routine to update IFS value based on
5142 * the ratio of transmits to collisions.
5144 * hw - Struct containing variables accessed by shared code
5145 * tx_packets - Number of transmits since last callback
5146 * total_collisions - Number of collisions since last callback
5147 *****************************************************************************/
5149 em_update_adaptive(struct em_hw *hw)
5151 DEBUGFUNC("em_update_adaptive");
5153 if(hw->adaptive_ifs) {
5154 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5155 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5156 hw->in_ifs_mode = TRUE;
5157 if(hw->current_ifs_val < hw->ifs_max_val) {
5158 if(hw->current_ifs_val == 0)
5159 hw->current_ifs_val = hw->ifs_min_val;
5161 hw->current_ifs_val += hw->ifs_step_size;
5162 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5166 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5167 hw->current_ifs_val = 0;
5168 hw->in_ifs_mode = FALSE;
5169 E1000_WRITE_REG(hw, AIT, 0);
5173 DEBUGOUT("Not in Adaptive IFS mode!\n");
5177 /******************************************************************************
5178 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5180 * hw - Struct containing variables accessed by shared code
5181 * frame_len - The length of the frame in question
5182 * mac_addr - The Ethernet destination address of the frame in question
5183 *****************************************************************************/
5185 em_tbi_adjust_stats(struct em_hw *hw,
5186 struct em_hw_stats *stats,
5192 /* First adjust the frame length. */
5194 /* We need to adjust the statistics counters, since the hardware
5195 * counters overcount this packet as a CRC error and undercount
5196 * the packet as a good packet
5198 /* This packet should not be counted as a CRC error. */
5200 /* This packet does count as a Good Packet Received. */
5203 /* Adjust the Good Octets received counters */
5204 carry_bit = 0x80000000 & stats->gorcl;
5205 stats->gorcl += frame_len;
5206 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5207 * Received Count) was one before the addition,
5208 * AND it is zero after, then we lost the carry out,
5209 * need to add one to Gorch (Good Octets Received Count High).
5210 * This could be simplified if all environments supported
5213 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5215 /* Is this a broadcast or multicast? Check broadcast first,
5216 * since the test for a multicast frame will test positive on
5217 * a broadcast frame.
5219 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5220 /* Broadcast packet */
5222 else if(*mac_addr & 0x01)
5223 /* Multicast packet */
5226 if(frame_len == hw->max_frame_size) {
5227 /* In this case, the hardware has overcounted the number of
5234 /* Adjust the bin counters when the extra byte put the frame in the
5235 * wrong bin. Remember that the frame_len was adjusted above.
5237 if(frame_len == 64) {
5240 } else if(frame_len == 127) {
5243 } else if(frame_len == 255) {
5246 } else if(frame_len == 511) {
5249 } else if(frame_len == 1023) {
5252 } else if(frame_len == 1522) {
5257 /******************************************************************************
5258 * Gets the current PCI bus type, speed, and width of the hardware
5260 * hw - Struct containing variables accessed by shared code
5261 *****************************************************************************/
5263 em_get_bus_info(struct em_hw *hw)
5267 switch (hw->mac_type) {
5268 case em_82542_rev2_0:
5269 case em_82542_rev2_1:
5270 hw->bus_type = em_bus_type_unknown;
5271 hw->bus_speed = em_bus_speed_unknown;
5272 hw->bus_width = em_bus_width_unknown;
5276 hw->bus_type = em_bus_type_pci_express;
5277 hw->bus_speed = em_bus_speed_2500;
5278 hw->bus_width = em_bus_width_pciex_1;
5281 hw->bus_type = em_bus_type_pci_express;
5282 hw->bus_speed = em_bus_speed_2500;
5283 hw->bus_width = em_bus_width_pciex_4;
5286 status = E1000_READ_REG(hw, STATUS);
5287 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5288 em_bus_type_pcix : em_bus_type_pci;
5290 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5291 hw->bus_speed = (hw->bus_type == em_bus_type_pci) ?
5292 em_bus_speed_66 : em_bus_speed_120;
5293 } else if(hw->bus_type == em_bus_type_pci) {
5294 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5295 em_bus_speed_66 : em_bus_speed_33;
5297 switch (status & E1000_STATUS_PCIX_SPEED) {
5298 case E1000_STATUS_PCIX_SPEED_66:
5299 hw->bus_speed = em_bus_speed_66;
5301 case E1000_STATUS_PCIX_SPEED_100:
5302 hw->bus_speed = em_bus_speed_100;
5304 case E1000_STATUS_PCIX_SPEED_133:
5305 hw->bus_speed = em_bus_speed_133;
5308 hw->bus_speed = em_bus_speed_reserved;
5312 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5313 em_bus_width_64 : em_bus_width_32;
5317 /******************************************************************************
5318 * Reads a value from one of the devices registers using port I/O (as opposed
5319 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5321 * hw - Struct containing variables accessed by shared code
5322 * offset - offset to read from
5323 *****************************************************************************/
5325 em_read_reg_io(struct em_hw *hw,
5328 unsigned long io_addr = hw->io_base;
5329 unsigned long io_data = hw->io_base + 4;
5331 em_io_write(hw, io_addr, offset);
5332 return em_io_read(hw, io_data);
5335 /******************************************************************************
5336 * Writes a value to one of the devices registers using port I/O (as opposed to
5337 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5339 * hw - Struct containing variables accessed by shared code
5340 * offset - offset to write to
5341 * value - value to write
5342 *****************************************************************************/
5344 em_write_reg_io(struct em_hw *hw,
5348 unsigned long io_addr = hw->io_base;
5349 unsigned long io_data = hw->io_base + 4;
5351 em_io_write(hw, io_addr, offset);
5352 em_io_write(hw, io_data, value);
5356 /******************************************************************************
5357 * Estimates the cable length.
5359 * hw - Struct containing variables accessed by shared code
5360 * min_length - The estimated minimum length
5361 * max_length - The estimated maximum length
5363 * returns: - E1000_ERR_XXX
5366 * This function always returns a ranged length (minimum & maximum).
5367 * So for M88 phy's, this function interprets the one value returned from the
5368 * register to the minimum and maximum range.
5369 * For IGP phy's, the function calculates the range by the AGC registers.
5370 *****************************************************************************/
5372 em_get_cable_length(struct em_hw *hw,
5373 uint16_t *min_length,
5374 uint16_t *max_length)
5377 uint16_t agc_value = 0;
5378 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5379 uint16_t max_agc = 0;
5380 uint16_t i, phy_data;
5381 uint16_t cable_length;
5383 DEBUGFUNC("em_get_cable_length");
5385 *min_length = *max_length = 0;
5387 /* Use old method for Phy older than IGP */
5388 if(hw->phy_type == em_phy_m88) {
5390 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5394 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5395 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
5397 /* Convert the enum value to ranged values */
5398 switch (cable_length) {
5399 case em_cable_length_50:
5401 *max_length = em_igp_cable_length_50;
5403 case em_cable_length_50_80:
5404 *min_length = em_igp_cable_length_50;
5405 *max_length = em_igp_cable_length_80;
5407 case em_cable_length_80_110:
5408 *min_length = em_igp_cable_length_80;
5409 *max_length = em_igp_cable_length_110;
5411 case em_cable_length_110_140:
5412 *min_length = em_igp_cable_length_110;
5413 *max_length = em_igp_cable_length_140;
5415 case em_cable_length_140:
5416 *min_length = em_igp_cable_length_140;
5417 *max_length = em_igp_cable_length_170;
5420 return -E1000_ERR_PHY;
5423 } else if(hw->phy_type == em_phy_igp) { /* For IGP PHY */
5424 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5425 {IGP01E1000_PHY_AGC_A,
5426 IGP01E1000_PHY_AGC_B,
5427 IGP01E1000_PHY_AGC_C,
5428 IGP01E1000_PHY_AGC_D};
5429 /* Read the AGC registers for all channels */
5430 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5432 ret_val = em_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5436 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5438 /* Array bound check. */
5439 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5441 return -E1000_ERR_PHY;
5443 agc_value += cur_agc;
5445 /* Update minimal AGC value. */
5446 if(min_agc > cur_agc)
5450 /* Remove the minimal AGC result for length < 50m */
5451 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * em_igp_cable_length_50) {
5452 agc_value -= min_agc;
5454 /* Get the average length of the remaining 3 channels */
5455 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5457 /* Get the average length of all the 4 channels. */
5458 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5461 /* Set the range of the calculated length. */
5462 *min_length = ((em_igp_cable_length_table[agc_value] -
5463 IGP01E1000_AGC_RANGE) > 0) ?
5464 (em_igp_cable_length_table[agc_value] -
5465 IGP01E1000_AGC_RANGE) : 0;
5466 *max_length = em_igp_cable_length_table[agc_value] +
5467 IGP01E1000_AGC_RANGE;
5468 } else if (hw->phy_type == em_phy_igp_2) {
5469 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
5470 {IGP02E1000_PHY_AGC_A,
5471 IGP02E1000_PHY_AGC_B,
5472 IGP02E1000_PHY_AGC_C,
5473 IGP02E1000_PHY_AGC_D};
5475 /* Read the AGC registers for all channels */
5476 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
5477 ret_val = em_read_phy_reg(hw, agc_reg_array[i],
5483 * Getting bits 15:9, which represent the combination
5484 * of course and fine gain values. The result is a
5485 * number that can be put into the lookup table to
5486 * obtain the approximate cable length.
5488 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
5489 IGP02E1000_AGC_LENGTH_MASK;
5491 /* Remove min & max AGC values from calculation. */
5492 if (em_igp_2_cable_length_table[min_agc] >
5493 em_igp_2_cable_length_table[cur_agc])
5495 if (em_igp_2_cable_length_table[max_agc] <
5496 em_igp_2_cable_length_table[cur_agc])
5499 agc_value += em_igp_2_cable_length_table[cur_agc];
5502 agc_value -= (em_igp_2_cable_length_table[min_agc] +
5503 em_igp_2_cable_length_table[max_agc]);
5504 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
5507 * Calculate cable length with the error range
5510 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
5511 (agc_value - IGP02E1000_AGC_RANGE) : 0;
5512 *max_length = agc_value + IGP02E1000_AGC_RANGE;
5515 return E1000_SUCCESS;
5518 /******************************************************************************
5519 * Check the cable polarity
5521 * hw - Struct containing variables accessed by shared code
5522 * polarity - output parameter : 0 - Polarity is not reversed
5523 * 1 - Polarity is reversed.
5525 * returns: - E1000_ERR_XXX
5528 * For phy's older then IGP, this function simply reads the polarity bit in the
5529 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5530 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5531 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5532 * IGP01E1000_PHY_PCS_INIT_REG.
5533 *****************************************************************************/
5535 em_check_polarity(struct em_hw *hw,
5541 DEBUGFUNC("em_check_polarity");
5543 if(hw->phy_type == em_phy_m88) {
5544 /* return the Polarity bit in the Status register. */
5545 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5549 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
5550 M88E1000_PSSR_REV_POLARITY_SHIFT;
5551 } else if(hw->phy_type == em_phy_igp ||
5552 hw->phy_type == em_phy_igp_2) {
5553 /* Read the Status register to check the speed */
5554 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5559 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5560 * find the polarity status */
5561 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5562 IGP01E1000_PSSR_SPEED_1000MBPS) {
5564 /* Read the GIG initialization PCS register (0x00B4) */
5565 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5570 /* Check the polarity bits */
5571 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
5573 /* For 10 Mbps, read the polarity bit in the status register. (for
5574 * 100 Mbps this bit is always 0) */
5575 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
5578 return E1000_SUCCESS;
5581 /******************************************************************************
5582 * Check if Downshift occured
5584 * hw - Struct containing variables accessed by shared code
5585 * downshift - output parameter : 0 - No Downshift ocured.
5586 * 1 - Downshift ocured.
5588 * returns: - E1000_ERR_XXX
5591 * For phy's older then IGP, this function reads the Downshift bit in the Phy
5592 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5593 * Link Health register. In IGP this bit is latched high, so the driver must
5594 * read it immediately after link is established.
5595 *****************************************************************************/
5597 em_check_downshift(struct em_hw *hw)
5602 DEBUGFUNC("em_check_downshift");
5604 if(hw->phy_type == em_phy_igp ||
5605 hw->phy_type == em_phy_igp_2) {
5606 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5611 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5612 } else if(hw->phy_type == em_phy_m88) {
5613 ret_val = em_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5618 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5619 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5622 return E1000_SUCCESS;
5625 /*****************************************************************************
5627 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5628 * gigabit link is achieved to improve link quality.
5630 * hw: Struct containing variables accessed by shared code
5632 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5633 * E1000_SUCCESS at any other case.
5635 ****************************************************************************/
5638 em_config_dsp_after_link_change(struct em_hw *hw,
5642 uint16_t phy_data, phy_saved_data, speed, duplex, i;
5643 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5644 {IGP01E1000_PHY_AGC_PARAM_A,
5645 IGP01E1000_PHY_AGC_PARAM_B,
5646 IGP01E1000_PHY_AGC_PARAM_C,
5647 IGP01E1000_PHY_AGC_PARAM_D};
5648 uint16_t min_length, max_length;
5650 DEBUGFUNC("em_config_dsp_after_link_change");
5652 if(hw->phy_type != em_phy_igp)
5653 return E1000_SUCCESS;
5656 ret_val = em_get_speed_and_duplex(hw, &speed, &duplex);
5658 DEBUGOUT("Error getting link speed and duplex\n");
5662 if(speed == SPEED_1000) {
5664 em_get_cable_length(hw, &min_length, &max_length);
5666 if((hw->dsp_config_state == em_dsp_config_enabled) &&
5667 min_length >= em_igp_cable_length_50) {
5669 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5670 ret_val = em_read_phy_reg(hw, dsp_reg_array[i],
5675 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5677 ret_val = em_write_phy_reg(hw, dsp_reg_array[i],
5682 hw->dsp_config_state = em_dsp_config_activated;
5685 if((hw->ffe_config_state == em_ffe_config_enabled) &&
5686 (min_length < em_igp_cable_length_50)) {
5688 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5689 uint32_t idle_errs = 0;
5691 /* clear previous idle error counts */
5692 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS,
5697 for(i = 0; i < ffe_idle_err_timeout; i++) {
5699 ret_val = em_read_phy_reg(hw, PHY_1000T_STATUS,
5704 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5705 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5706 hw->ffe_config_state = em_ffe_config_active;
5708 ret_val = em_write_phy_reg(hw,
5709 IGP01E1000_PHY_DSP_FFE,
5710 IGP01E1000_PHY_DSP_FFE_CM_CP);
5717 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5722 if(hw->dsp_config_state == em_dsp_config_activated) {
5723 /* Save off the current value of register 0x2F5B to be restored at
5724 * the end of the routines. */
5725 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5730 /* Disable the PHY transmitter */
5731 ret_val = em_write_phy_reg(hw, 0x2F5B, 0x0003);
5738 ret_val = em_write_phy_reg(hw, 0x0000,
5739 IGP01E1000_IEEE_FORCE_GIGA);
5742 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5743 ret_val = em_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5747 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5748 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5750 ret_val = em_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5755 ret_val = em_write_phy_reg(hw, 0x0000,
5756 IGP01E1000_IEEE_RESTART_AUTONEG);
5762 /* Now enable the transmitter */
5763 ret_val = em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5768 hw->dsp_config_state = em_dsp_config_enabled;
5771 if(hw->ffe_config_state == em_ffe_config_active) {
5772 /* Save off the current value of register 0x2F5B to be restored at
5773 * the end of the routines. */
5774 ret_val = em_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5779 /* Disable the PHY transmitter */
5780 ret_val = em_write_phy_reg(hw, 0x2F5B, 0x0003);
5787 ret_val = em_write_phy_reg(hw, 0x0000,
5788 IGP01E1000_IEEE_FORCE_GIGA);
5791 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5792 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5796 ret_val = em_write_phy_reg(hw, 0x0000,
5797 IGP01E1000_IEEE_RESTART_AUTONEG);
5803 /* Now enable the transmitter */
5804 ret_val = em_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5809 hw->ffe_config_state = em_ffe_config_enabled;
5812 return E1000_SUCCESS;
5815 /*****************************************************************************
5816 * Set PHY to class A mode
5817 * Assumes the following operations will follow to enable the new class mode.
5818 * 1. Do a PHY soft reset
5819 * 2. Restart auto-negotiation or force link.
5821 * hw - Struct containing variables accessed by shared code
5822 ****************************************************************************/
5824 em_set_phy_mode(struct em_hw *hw)
5827 uint16_t eeprom_data;
5829 DEBUGFUNC("em_set_phy_mode");
5831 if((hw->mac_type == em_82545_rev_3) &&
5832 (hw->media_type == em_media_type_copper)) {
5833 ret_val = em_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5838 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5839 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5840 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5843 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5847 hw->phy_reset_disable = FALSE;
5851 return E1000_SUCCESS;
5854 /*****************************************************************************
5856 * This function sets the lplu state according to the active flag. When
5857 * activating lplu this function also disables smart speed and vise versa.
5858 * lplu will not be activated unless the device autonegotiation advertisment
5859 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5860 * hw: Struct containing variables accessed by shared code
5861 * active - true to enable lplu false to disable lplu.
5863 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5864 * E1000_SUCCESS at any other case.
5866 ****************************************************************************/
5869 em_set_d3_lplu_state(struct em_hw *hw,
5874 DEBUGFUNC("em_set_d3_lplu_state");
5876 if(hw->phy_type != em_phy_igp && hw->phy_type != em_phy_igp_2)
5877 return E1000_SUCCESS;
5879 /* During driver activity LPLU should not be used or it will attain link
5880 * from the lowest speeds starting from 10Mbps. The capability is used for
5881 * Dx transitions and states */
5882 if(hw->mac_type == em_82541_rev_2 || hw->mac_type == em_82547_rev_2) {
5883 ret_val = em_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5887 ret_val = em_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5893 if(hw->mac_type == em_82541_rev_2 ||
5894 hw->mac_type == em_82547_rev_2) {
5895 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5896 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5900 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5901 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5907 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5908 * Dx states where the power conservation is most important. During
5909 * driver activity we should enable SmartSpeed, so performance is
5911 if (hw->smart_speed == em_smart_speed_on) {
5912 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5917 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5918 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5922 } else if (hw->smart_speed == em_smart_speed_off) {
5923 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5928 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5929 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5935 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5936 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5937 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5939 if(hw->mac_type == em_82541_rev_2 ||
5940 hw->mac_type == em_82547_rev_2) {
5941 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5942 ret_val = em_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5946 phy_data |= IGP02E1000_PM_D3_LPLU;
5947 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5953 /* When LPLU is enabled we should disable SmartSpeed */
5954 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5958 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5959 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5964 return E1000_SUCCESS;
5967 /*****************************************************************************
5969 * This function sets the lplu d0 state according to the active flag. When
5970 * activating lplu this function also disables smart speed and vise versa.
5971 * lplu will not be activated unless the device autonegotiation advertisment
5972 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5973 * hw: Struct containing variables accessed by shared code
5974 * active - true to enable lplu false to disable lplu.
5976 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5977 * E1000_SUCCESS at any other case.
5979 ****************************************************************************/
5982 em_set_d0_lplu_state(struct em_hw *hw,
5987 DEBUGFUNC("em_set_d0_lplu_state");
5989 if(hw->mac_type <= em_82547_rev_2)
5990 return E1000_SUCCESS;
5992 ret_val = em_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5997 phy_data &= ~IGP02E1000_PM_D0_LPLU;
5998 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6002 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6003 * Dx states where the power conservation is most important. During
6004 * driver activity we should enable SmartSpeed, so performance is
6006 if (hw->smart_speed == em_smart_speed_on) {
6007 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6012 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6013 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6017 } else if (hw->smart_speed == em_smart_speed_off) {
6018 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6023 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6024 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6033 phy_data |= IGP02E1000_PM_D0_LPLU;
6034 ret_val = em_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6038 /* When LPLU is enabled we should disable SmartSpeed */
6039 ret_val = em_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6043 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6044 ret_val = em_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6049 return E1000_SUCCESS;
6052 /******************************************************************************
6053 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6055 * hw - Struct containing variables accessed by shared code
6056 *****************************************************************************/
6058 em_set_vco_speed(struct em_hw *hw)
6061 uint16_t default_page = 0;
6064 DEBUGFUNC("em_set_vco_speed");
6066 switch(hw->mac_type) {
6067 case em_82545_rev_3:
6068 case em_82546_rev_3:
6071 return E1000_SUCCESS;
6074 /* Set PHY register 30, page 5, bit 8 to 0 */
6076 ret_val = em_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6080 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6084 ret_val = em_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6088 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6089 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6093 /* Set PHY register 30, page 4, bit 11 to 1 */
6095 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6099 ret_val = em_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6103 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6104 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6108 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6112 return E1000_SUCCESS;
6116 /*****************************************************************************
6117 * This function reads the cookie from ARC ram.
6119 * returns: - E1000_SUCCESS .
6120 ****************************************************************************/
6122 em_host_if_read_cookie(struct em_hw * hw, uint8_t *buffer)
6125 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6126 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6128 length = (length >> 2);
6129 offset = (offset >> 2);
6131 for (i = 0; i < length; i++) {
6132 *((uint32_t *) buffer + i) =
6133 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6135 return E1000_SUCCESS;
6139 /*****************************************************************************
6140 * This function checks whether the HOST IF is enabled for command operaton
6141 * and also checks whether the previous command is completed.
6142 * It busy waits in case of previous command is not completed.
6144 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
6146 * - E1000_SUCCESS for success.
6147 ****************************************************************************/
6149 em_mng_enable_host_if(struct em_hw * hw)
6154 /* Check that the host interface is enabled. */
6155 hicr = E1000_READ_REG(hw, HICR);
6156 if ((hicr & E1000_HICR_EN) == 0) {
6157 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6158 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6160 /* check the previous command is completed */
6161 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6162 hicr = E1000_READ_REG(hw, HICR);
6163 if (!(hicr & E1000_HICR_C))
6168 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6169 DEBUGOUT("Previous command timeout failed .\n");
6170 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6172 return E1000_SUCCESS;
6175 /*****************************************************************************
6176 * This function writes the buffer content at the offset given on the host if.
6177 * It also does alignment considerations to do the writes in most efficient way.
6178 * Also fills up the sum of the buffer in *buffer parameter.
6180 * returns - E1000_SUCCESS for success.
6181 ****************************************************************************/
6183 em_mng_host_if_write(struct em_hw * hw, uint8_t *buffer,
6184 uint16_t length, uint16_t offset, uint8_t *sum)
6187 uint8_t *bufptr = buffer;
6189 uint16_t remaining, i, j, prev_bytes;
6191 /* sum = only sum of the data and it is not checksum */
6193 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6194 return -E1000_ERR_PARAM;
6197 tmp = (uint8_t *)&data;
6198 prev_bytes = offset & 0x3;
6203 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6204 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6205 *(tmp + j) = *bufptr++;
6208 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6209 length -= j - prev_bytes;
6213 remaining = length & 0x3;
6214 length -= remaining;
6216 /* Calculate length in DWORDs */
6219 /* The device driver writes the relevant command block into the
6221 for (i = 0; i < length; i++) {
6222 for (j = 0; j < sizeof(uint32_t); j++) {
6223 *(tmp + j) = *bufptr++;
6227 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6230 for (j = 0; j < sizeof(uint32_t); j++) {
6232 *(tmp + j) = *bufptr++;
6238 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6241 return E1000_SUCCESS;
6245 /*****************************************************************************
6246 * This function writes the command header after does the checksum calculation.
6248 * returns - E1000_SUCCESS for success.
6249 ****************************************************************************/
6251 em_mng_write_cmd_header(struct em_hw * hw,
6252 struct em_host_mng_command_header * hdr)
6258 /* Write the whole command header structure which includes sum of
6261 uint16_t length = sizeof(struct em_host_mng_command_header);
6263 sum = hdr->checksum;
6266 buffer = (uint8_t *) hdr;
6271 hdr->checksum = 0 - sum;
6274 /* The device driver writes the relevant command block into the ram area. */
6275 for (i = 0; i < length; i++)
6276 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6278 return E1000_SUCCESS;
6282 /*****************************************************************************
6283 * This function indicates to ARC that a new command is pending which completes
6284 * one write operation by the driver.
6286 * returns - E1000_SUCCESS for success.
6287 ****************************************************************************/
6289 em_mng_write_commit(
6294 hicr = E1000_READ_REG(hw, HICR);
6295 /* Setting this bit tells the ARC that a new command is pending. */
6296 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6298 return E1000_SUCCESS;
6302 /*****************************************************************************
6303 * This function checks the mode of the firmware.
6305 * returns - TRUE when the mode is IAMT or FALSE.
6306 ****************************************************************************/
6313 fwsm = E1000_READ_REG(hw, FWSM);
6315 if((fwsm & E1000_FWSM_MODE_MASK) ==
6316 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6323 /*****************************************************************************
6324 * This function writes the dhcp info .
6325 ****************************************************************************/
6327 em_mng_write_dhcp_info(struct em_hw * hw, uint8_t *buffer,
6331 struct em_host_mng_command_header hdr;
6333 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6334 hdr.command_length = length;
6339 ret_val = em_mng_enable_host_if(hw);
6340 if (ret_val == E1000_SUCCESS) {
6341 ret_val = em_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6343 if (ret_val == E1000_SUCCESS) {
6344 ret_val = em_mng_write_cmd_header(hw, &hdr);
6345 if (ret_val == E1000_SUCCESS)
6346 ret_val = em_mng_write_commit(hw);
6353 /*****************************************************************************
6354 * This function calculates the checksum.
6356 * returns - checksum of buffer contents.
6357 ****************************************************************************/
6359 em_calculate_mng_checksum(char *buffer, uint32_t length)
6367 for (i=0; i < length; i++)
6370 return (uint8_t) (0 - sum);
6373 /*****************************************************************************
6374 * This function checks whether tx pkt filtering needs to be enabled or not.
6376 * returns - TRUE for packet filtering or FALSE.
6377 ****************************************************************************/
6379 em_enable_tx_pkt_filtering(struct em_hw *hw)
6381 /* called in init as well as watchdog timer functions */
6383 int32_t ret_val, checksum;
6384 boolean_t tx_filter = FALSE;
6385 struct em_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
6386 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
6388 if (em_check_mng_mode(hw)) {
6389 ret_val = em_mng_enable_host_if(hw);
6390 if (ret_val == E1000_SUCCESS) {
6391 ret_val = em_host_if_read_cookie(hw, buffer);
6392 if (ret_val == E1000_SUCCESS) {
6393 checksum = hdr->checksum;
6395 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
6396 checksum == em_calculate_mng_checksum((char *)buffer,
6397 E1000_MNG_DHCP_COOKIE_LENGTH)) {
6399 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
6408 hw->tx_pkt_filtering = tx_filter;
6412 /******************************************************************************
6413 * Verifies the hardware needs to allow ARPs to be processed by the host
6415 * hw - Struct containing variables accessed by shared code
6417 * returns: - TRUE/FALSE
6419 *****************************************************************************/
6421 em_enable_mng_pass_thru(struct em_hw *hw)
6424 uint32_t fwsm, factps;
6426 if (hw->asf_firmware_present) {
6427 manc = E1000_READ_REG(hw, MANC);
6429 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
6430 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
6432 if (em_arc_subsystem_valid(hw) == TRUE) {
6433 fwsm = E1000_READ_REG(hw, FWSM);
6434 factps = E1000_READ_REG(hw, FACTPS);
6436 if (((fwsm & E1000_FWSM_MODE_MASK) ==
6437 (em_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
6438 (factps & E1000_FACTPS_MNGCG))
6441 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
6448 em_polarity_reversal_workaround(struct em_hw *hw)
6451 uint16_t mii_status_reg;
6454 /* Polarity reversal workaround for forced 10F/10H links. */
6456 /* Disable the transmitter on the PHY */
6458 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6461 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
6465 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6469 /* This loop will early-out if the NO link condition has been met. */
6470 for(i = PHY_FORCE_TIME; i > 0; i--) {
6471 /* Read the MII Status Register and wait for Link Status bit
6475 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6479 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6483 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
6484 msec_delay_irq(100);
6487 /* Recommended delay time after link has been lost */
6488 msec_delay_irq(1000);
6490 /* Now we will re-enable th transmitter on the PHY */
6492 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6496 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
6500 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
6504 ret_val = em_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
6508 ret_val = em_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6512 /* This loop will early-out if the link condition has been met. */
6513 for(i = PHY_FORCE_TIME; i > 0; i--) {
6514 /* Read the MII Status Register and wait for Link Status bit
6518 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6522 ret_val = em_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6526 if(mii_status_reg & MII_SR_LINK_STATUS) break;
6527 msec_delay_irq(100);
6529 return E1000_SUCCESS;
6532 /***************************************************************************
6534 * Disables PCI-Express master access.
6536 * hw: Struct containing variables accessed by shared code
6540 ***************************************************************************/
6542 em_set_pci_express_master_disable(struct em_hw *hw)
6546 DEBUGFUNC("em_set_pci_express_master_disable");
6548 if (hw->bus_type != em_bus_type_pci_express)
6551 ctrl = E1000_READ_REG(hw, CTRL);
6552 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
6553 E1000_WRITE_REG(hw, CTRL, ctrl);
6556 /***************************************************************************
6558 * Enables PCI-Express master access.
6560 * hw: Struct containing variables accessed by shared code
6564 ***************************************************************************/
6566 em_enable_pciex_master(struct em_hw *hw)
6570 DEBUGFUNC("em_enable_pciex_master");
6572 if (hw->bus_type != em_bus_type_pci_express)
6575 ctrl = E1000_READ_REG(hw, CTRL);
6576 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
6577 E1000_WRITE_REG(hw, CTRL, ctrl);
6580 /*******************************************************************************
6582 * Disables PCI-Express master access and verifies there are no pending requests
6584 * hw: Struct containing variables accessed by shared code
6586 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
6587 * caused the master requests to be disabled.
6588 * E1000_SUCCESS master requests disabled.
6590 ******************************************************************************/
6592 em_disable_pciex_master(struct em_hw *hw)
6594 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
6596 DEBUGFUNC("em_disable_pciex_master");
6598 if (hw->bus_type != em_bus_type_pci_express)
6599 return E1000_SUCCESS;
6601 em_set_pci_express_master_disable(hw);
6604 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
6612 DEBUGOUT("Master requests are pending.\n");
6613 return -E1000_ERR_MASTER_REQUESTS_PENDING;
6616 return E1000_SUCCESS;
6619 /*******************************************************************************
6621 * Check for EEPROM Auto Read bit done.
6623 * hw: Struct containing variables accessed by shared code
6625 * returns: - E1000_ERR_RESET if fail to reset MAC
6626 * E1000_SUCCESS at any other case.
6628 ******************************************************************************/
6630 em_get_auto_rd_done(struct em_hw *hw)
6632 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
6634 DEBUGFUNC("em_get_auto_rd_done");
6636 switch (hw->mac_type) {
6641 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
6647 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
6648 return -E1000_ERR_RESET;
6655 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
6656 * Need to wait for PHY configuration completion before accessing NVM
6658 if (hw->mac_type == em_82573)
6661 return E1000_SUCCESS;
6664 /***************************************************************************
6665 * Checks if the PHY configuration is done
6667 * hw: Struct containing variables accessed by shared code
6669 * returns: - E1000_ERR_RESET if fail to reset MAC
6670 * E1000_SUCCESS at any other case.
6672 ***************************************************************************/
6674 em_get_phy_cfg_done(struct em_hw *hw)
6676 int32_t timeout = PHY_CFG_TIMEOUT;
6677 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
6679 DEBUGFUNC("em_get_phy_cfg_done");
6681 switch (hw->mac_type) {
6685 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
6693 DEBUGOUT("MNG configuration cycle has not completed.\n");
6694 return -E1000_ERR_RESET;
6701 return E1000_SUCCESS;
6704 /***************************************************************************
6706 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
6707 * adapter or Eeprom access.
6709 * hw: Struct containing variables accessed by shared code
6711 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
6712 * E1000_SUCCESS at any other case.
6714 ***************************************************************************/
6716 em_get_hw_eeprom_semaphore(struct em_hw *hw)
6721 DEBUGFUNC("em_get_hw_eeprom_semaphore");
6723 if(!hw->eeprom_semaphore_present)
6724 return E1000_SUCCESS;
6727 /* Get the FW semaphore. */
6728 timeout = hw->eeprom.word_size + 1;
6730 swsm = E1000_READ_REG(hw, SWSM);
6731 swsm |= E1000_SWSM_SWESMBI;
6732 E1000_WRITE_REG(hw, SWSM, swsm);
6733 /* if we managed to set the bit we got the semaphore. */
6734 swsm = E1000_READ_REG(hw, SWSM);
6735 if(swsm & E1000_SWSM_SWESMBI)
6743 /* Release semaphores */
6744 em_put_hw_eeprom_semaphore(hw);
6745 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
6746 return -E1000_ERR_EEPROM;
6749 return E1000_SUCCESS;
6752 /***************************************************************************
6753 * This function clears HW semaphore bits.
6755 * hw: Struct containing variables accessed by shared code
6759 ***************************************************************************/
6761 em_put_hw_eeprom_semaphore(struct em_hw *hw)
6765 DEBUGFUNC("em_put_hw_eeprom_semaphore");
6767 if(!hw->eeprom_semaphore_present)
6770 swsm = E1000_READ_REG(hw, SWSM);
6771 swsm &= ~(E1000_SWSM_SWESMBI);
6772 E1000_WRITE_REG(hw, SWSM, swsm);
6775 /******************************************************************************
6776 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
6777 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
6778 * the caller to figure out how to deal with it.
6780 * hw - Struct containing variables accessed by shared code
6782 * returns: - E1000_BLK_PHY_RESET
6785 *****************************************************************************/
6787 em_check_phy_reset_block(struct em_hw *hw)
6790 if (hw->mac_type > em_82547_rev_2)
6791 manc = E1000_READ_REG(hw, MANC);
6792 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
6793 E1000_BLK_PHY_RESET : E1000_SUCCESS;
6797 em_arc_subsystem_valid(struct em_hw *hw)
6801 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
6802 * may not be provided a DMA clock when no manageability features are
6803 * enabled. We do not want to perform any reads/writes to these registers
6804 * if this is the case. We read FWSM to determine the manageability mode.
6806 switch (hw->mac_type) {
6810 fwsm = E1000_READ_REG(hw, FWSM);
6811 if((fwsm & E1000_FWSM_MODE_MASK) != 0)