1 /*******************************************************************************
4 Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 You should have received a copy of the GNU General Public License along with
17 this program; if not, write to the Free Software Foundation, Inc., 59
18 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 The full GNU General Public License is included in this distribution in the
24 Linux NICS <linux.nics@intel.com>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 * Shared functions for accessing and configuring the MAC
35 static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36 static void e1000_phy_init_script(struct e1000_hw *hw);
37 static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38 static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39 static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40 static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41 static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42 static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43 static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44 static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
46 static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47 static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48 static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49 uint16_t words, uint16_t *data);
50 static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51 uint16_t offset, uint16_t words,
53 static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54 static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55 static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56 static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
58 static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
60 static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
62 static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63 static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64 static void e1000_release_eeprom(struct e1000_hw *hw);
65 static void e1000_standby_eeprom(struct e1000_hw *hw);
66 static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
67 static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
68 static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
69 static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
70 static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
71 static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
72 static int32_t e1000_check_downshift(struct e1000_hw *hw);
73 static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
74 static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
75 static void e1000_clear_vfta(struct e1000_hw *hw);
76 static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
77 static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
79 static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
80 static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
81 static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
82 static int32_t e1000_get_cable_length(struct e1000_hw *hw,
84 uint16_t *max_length);
85 static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
86 static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
87 static int32_t e1000_id_led_init(struct e1000_hw * hw);
88 static void e1000_init_rx_addrs(struct e1000_hw *hw);
89 static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
90 static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
91 static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
92 static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
93 uint16_t words, uint16_t *data);
94 static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
95 static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
96 static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
98 static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
101 #define E1000_WRITE_REG_IO(a, reg, val) \
102 e1000_write_reg_io((a), E1000_##reg, val)
104 /* IGP cable length table */
106 uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
107 { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
108 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
109 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
110 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
111 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
112 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
113 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
114 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
117 uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
118 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
119 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
120 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
121 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
122 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
123 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
124 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
125 104, 109, 114, 118, 121, 124};
128 /******************************************************************************
129 * Set the phy type member in the hw struct.
131 * hw - Struct containing variables accessed by shared code
132 *****************************************************************************/
134 e1000_set_phy_type(struct e1000_hw *hw)
136 DEBUGFUNC("e1000_set_phy_type");
138 if(hw->mac_type == e1000_undefined)
139 return -E1000_ERR_PHY_TYPE;
142 case M88E1000_E_PHY_ID:
143 case M88E1000_I_PHY_ID:
144 case M88E1011_I_PHY_ID:
145 case M88E1111_I_PHY_ID:
146 hw->phy_type = e1000_phy_m88;
148 case IGP01E1000_I_PHY_ID:
149 if(hw->mac_type == e1000_82541 ||
150 hw->mac_type == e1000_82541_rev_2 ||
151 hw->mac_type == e1000_82547 ||
152 hw->mac_type == e1000_82547_rev_2) {
153 hw->phy_type = e1000_phy_igp;
158 /* Should never have loaded on this device */
159 hw->phy_type = e1000_phy_undefined;
160 return -E1000_ERR_PHY_TYPE;
163 return E1000_SUCCESS;
166 /******************************************************************************
167 * IGP phy init script - initializes the GbE PHY
169 * hw - Struct containing variables accessed by shared code
170 *****************************************************************************/
172 e1000_phy_init_script(struct e1000_hw *hw)
175 uint16_t phy_saved_data;
177 DEBUGFUNC("e1000_phy_init_script");
179 if(hw->phy_init_script) {
182 /* Save off the current value of register 0x2F5B to be restored at
183 * the end of this routine. */
184 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
186 /* Disabled the PHY transmitter */
187 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
191 e1000_write_phy_reg(hw,0x0000,0x0140);
195 switch(hw->mac_type) {
198 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
200 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
202 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
204 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
206 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
208 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
210 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
212 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
214 e1000_write_phy_reg(hw, 0x2010, 0x0008);
217 case e1000_82541_rev_2:
218 case e1000_82547_rev_2:
219 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
225 e1000_write_phy_reg(hw, 0x0000, 0x3300);
229 /* Now enable the transmitter */
230 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
232 if(hw->mac_type == e1000_82547) {
233 uint16_t fused, fine, coarse;
235 /* Move to analog registers page */
236 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
238 if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
239 e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
241 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
242 coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
244 if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
245 coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
246 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
247 } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
248 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
250 fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
251 (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
252 (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
254 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
255 e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
256 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
262 /******************************************************************************
263 * Set the mac type member in the hw struct.
265 * hw - Struct containing variables accessed by shared code
266 *****************************************************************************/
268 e1000_set_mac_type(struct e1000_hw *hw)
270 DEBUGFUNC("e1000_set_mac_type");
272 switch (hw->device_id) {
273 case E1000_DEV_ID_82542:
274 switch (hw->revision_id) {
275 case E1000_82542_2_0_REV_ID:
276 hw->mac_type = e1000_82542_rev2_0;
278 case E1000_82542_2_1_REV_ID:
279 hw->mac_type = e1000_82542_rev2_1;
282 /* Invalid 82542 revision ID */
283 return -E1000_ERR_MAC_TYPE;
286 case E1000_DEV_ID_82543GC_FIBER:
287 case E1000_DEV_ID_82543GC_COPPER:
288 hw->mac_type = e1000_82543;
290 case E1000_DEV_ID_82544EI_COPPER:
291 case E1000_DEV_ID_82544EI_FIBER:
292 case E1000_DEV_ID_82544GC_COPPER:
293 case E1000_DEV_ID_82544GC_LOM:
294 hw->mac_type = e1000_82544;
296 case E1000_DEV_ID_82540EM:
297 case E1000_DEV_ID_82540EM_LOM:
298 case E1000_DEV_ID_82540EP:
299 case E1000_DEV_ID_82540EP_LOM:
300 case E1000_DEV_ID_82540EP_LP:
301 hw->mac_type = e1000_82540;
303 case E1000_DEV_ID_82545EM_COPPER:
304 case E1000_DEV_ID_82545EM_FIBER:
305 hw->mac_type = e1000_82545;
307 case E1000_DEV_ID_82545GM_COPPER:
308 case E1000_DEV_ID_82545GM_FIBER:
309 case E1000_DEV_ID_82545GM_SERDES:
310 hw->mac_type = e1000_82545_rev_3;
312 case E1000_DEV_ID_82546EB_COPPER:
313 case E1000_DEV_ID_82546EB_FIBER:
314 case E1000_DEV_ID_82546EB_QUAD_COPPER:
315 hw->mac_type = e1000_82546;
317 case E1000_DEV_ID_82546GB_COPPER:
318 case E1000_DEV_ID_82546GB_FIBER:
319 case E1000_DEV_ID_82546GB_SERDES:
320 case E1000_DEV_ID_82546GB_PCIE:
321 hw->mac_type = e1000_82546_rev_3;
323 case E1000_DEV_ID_82541EI:
324 case E1000_DEV_ID_82541EI_MOBILE:
325 hw->mac_type = e1000_82541;
327 case E1000_DEV_ID_82541ER:
328 case E1000_DEV_ID_82541GI:
329 case E1000_DEV_ID_82541GI_LF:
330 case E1000_DEV_ID_82541GI_MOBILE:
331 hw->mac_type = e1000_82541_rev_2;
333 case E1000_DEV_ID_82547EI:
334 hw->mac_type = e1000_82547;
336 case E1000_DEV_ID_82547GI:
337 hw->mac_type = e1000_82547_rev_2;
339 case E1000_DEV_ID_82571EB_COPPER:
340 case E1000_DEV_ID_82571EB_FIBER:
341 case E1000_DEV_ID_82571EB_SERDES:
342 hw->mac_type = e1000_82571;
344 case E1000_DEV_ID_82572EI_COPPER:
345 case E1000_DEV_ID_82572EI_FIBER:
346 case E1000_DEV_ID_82572EI_SERDES:
347 hw->mac_type = e1000_82572;
349 case E1000_DEV_ID_82573E:
350 case E1000_DEV_ID_82573E_IAMT:
351 case E1000_DEV_ID_82573L:
352 hw->mac_type = e1000_82573;
355 /* Should never have loaded on this device */
356 return -E1000_ERR_MAC_TYPE;
359 switch(hw->mac_type) {
363 hw->eeprom_semaphore_present = TRUE;
367 case e1000_82541_rev_2:
368 case e1000_82547_rev_2:
369 hw->asf_firmware_present = TRUE;
375 return E1000_SUCCESS;
378 /*****************************************************************************
379 * Set media type and TBI compatibility.
381 * hw - Struct containing variables accessed by shared code
382 * **************************************************************************/
384 e1000_set_media_type(struct e1000_hw *hw)
388 DEBUGFUNC("e1000_set_media_type");
390 if(hw->mac_type != e1000_82543) {
391 /* tbi_compatibility is only valid on 82543 */
392 hw->tbi_compatibility_en = FALSE;
395 switch (hw->device_id) {
396 case E1000_DEV_ID_82545GM_SERDES:
397 case E1000_DEV_ID_82546GB_SERDES:
398 case E1000_DEV_ID_82571EB_SERDES:
399 case E1000_DEV_ID_82572EI_SERDES:
400 hw->media_type = e1000_media_type_internal_serdes;
403 switch (hw->mac_type) {
404 case e1000_82542_rev2_0:
405 case e1000_82542_rev2_1:
406 hw->media_type = e1000_media_type_fiber;
409 /* The STATUS_TBIMODE bit is reserved or reused for the this
412 hw->media_type = e1000_media_type_copper;
415 status = E1000_READ_REG(hw, STATUS);
416 if (status & E1000_STATUS_TBIMODE) {
417 hw->media_type = e1000_media_type_fiber;
418 /* tbi_compatibility not valid on fiber */
419 hw->tbi_compatibility_en = FALSE;
421 hw->media_type = e1000_media_type_copper;
428 /******************************************************************************
429 * Reset the transmit and receive units; mask and clear all interrupts.
431 * hw - Struct containing variables accessed by shared code
432 *****************************************************************************/
434 e1000_reset_hw(struct e1000_hw *hw)
442 uint32_t extcnf_ctrl;
445 DEBUGFUNC("e1000_reset_hw");
447 /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
448 if(hw->mac_type == e1000_82542_rev2_0) {
449 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
450 e1000_pci_clear_mwi(hw);
453 if(hw->bus_type == e1000_bus_type_pci_express) {
454 /* Prevent the PCI-E bus from sticking if there is no TLP connection
455 * on the last TLP read/write transaction when MAC is reset.
457 if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
458 DEBUGOUT("PCI-E Master disable polling has failed.\n");
462 /* Clear interrupt mask to stop board from generating interrupts */
463 DEBUGOUT("Masking off all interrupts\n");
464 E1000_WRITE_REG(hw, IMC, 0xffffffff);
466 /* Disable the Transmit and Receive units. Then delay to allow
467 * any pending transactions to complete before we hit the MAC with
470 E1000_WRITE_REG(hw, RCTL, 0);
471 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
472 E1000_WRITE_FLUSH(hw);
474 /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
475 hw->tbi_compatibility_on = FALSE;
477 /* Delay to allow any outstanding PCI transactions to complete before
478 * resetting the device
482 ctrl = E1000_READ_REG(hw, CTRL);
484 /* Must reset the PHY before resetting the MAC */
485 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
486 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
490 /* Must acquire the MDIO ownership before MAC reset.
491 * Ownership defaults to firmware after a reset. */
492 if(hw->mac_type == e1000_82573) {
495 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
496 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
499 E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
500 extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
502 if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
505 extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
512 /* Issue a global reset to the MAC. This will reset the chip's
513 * transmit, receive, DMA, and link units. It will not effect
514 * the current PCI configuration. The global reset bit is self-
515 * clearing, and should clear within a microsecond.
517 DEBUGOUT("Issuing a global reset to MAC\n");
519 switch(hw->mac_type) {
525 case e1000_82541_rev_2:
526 /* These controllers can't ack the 64-bit write when issuing the
527 * reset, so use IO-mapping as a workaround to issue the reset */
528 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
530 case e1000_82545_rev_3:
531 case e1000_82546_rev_3:
532 /* Reset is performed on a shadow of the control register */
533 E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
536 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
540 /* After MAC reset, force reload of EEPROM to restore power-on settings to
541 * device. Later controllers reload the EEPROM automatically, so just wait
542 * for reload to complete.
544 switch(hw->mac_type) {
545 case e1000_82542_rev2_0:
546 case e1000_82542_rev2_1:
549 /* Wait for reset to complete */
551 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
552 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
553 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
554 E1000_WRITE_FLUSH(hw);
555 /* Wait for EEPROM reload */
559 case e1000_82541_rev_2:
561 case e1000_82547_rev_2:
562 /* Wait for EEPROM reload */
566 if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
568 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
569 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
570 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
571 E1000_WRITE_FLUSH(hw);
576 ret_val = e1000_get_auto_rd_done(hw);
578 /* We don't want to continue accessing MAC registers. */
582 /* Wait for EEPROM reload (it happens automatically) */
587 /* Disable HW ARPs on ASF enabled adapters */
588 if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
589 manc = E1000_READ_REG(hw, MANC);
590 manc &= ~(E1000_MANC_ARP_EN);
591 E1000_WRITE_REG(hw, MANC, manc);
594 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
595 e1000_phy_init_script(hw);
597 /* Configure activity LED after PHY reset */
598 led_ctrl = E1000_READ_REG(hw, LEDCTL);
599 led_ctrl &= IGP_ACTIVITY_LED_MASK;
600 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
601 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
604 /* Clear interrupt mask to stop board from generating interrupts */
605 DEBUGOUT("Masking off all interrupts\n");
606 E1000_WRITE_REG(hw, IMC, 0xffffffff);
608 /* Clear any pending interrupt events. */
609 icr = E1000_READ_REG(hw, ICR);
611 /* If MWI was previously enabled, reenable it. */
612 if(hw->mac_type == e1000_82542_rev2_0) {
613 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
614 e1000_pci_set_mwi(hw);
617 return E1000_SUCCESS;
620 /******************************************************************************
621 * Performs basic configuration of the adapter.
623 * hw - Struct containing variables accessed by shared code
625 * Assumes that the controller has previously been reset and is in a
626 * post-reset uninitialized state. Initializes the receive address registers,
627 * multicast table, and VLAN filter table. Calls routines to setup link
628 * configuration and flow control settings. Clears all on-chip counters. Leaves
629 * the transmit and receive units disabled and uninitialized.
630 *****************************************************************************/
632 e1000_init_hw(struct e1000_hw *hw)
637 uint16_t pcix_cmd_word;
638 uint16_t pcix_stat_hi_word;
643 DEBUGFUNC("e1000_init_hw");
645 /* Initialize Identification LED */
646 ret_val = e1000_id_led_init(hw);
648 DEBUGOUT("Error Initializing Identification LED\n");
652 /* Set the media type and TBI compatibility */
653 e1000_set_media_type(hw);
655 /* Disabling VLAN filtering. */
656 DEBUGOUT("Initializing the IEEE VLAN\n");
657 if (hw->mac_type < e1000_82545_rev_3)
658 E1000_WRITE_REG(hw, VET, 0);
659 e1000_clear_vfta(hw);
661 /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
662 if(hw->mac_type == e1000_82542_rev2_0) {
663 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
664 e1000_pci_clear_mwi(hw);
665 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
666 E1000_WRITE_FLUSH(hw);
670 /* Setup the receive address. This involves initializing all of the Receive
671 * Address Registers (RARs 0 - 15).
673 e1000_init_rx_addrs(hw);
675 /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
676 if(hw->mac_type == e1000_82542_rev2_0) {
677 E1000_WRITE_REG(hw, RCTL, 0);
678 E1000_WRITE_FLUSH(hw);
680 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
681 e1000_pci_set_mwi(hw);
684 /* Zero out the Multicast HASH table */
685 DEBUGOUT("Zeroing the MTA\n");
686 mta_size = E1000_MC_TBL_SIZE;
687 for(i = 0; i < mta_size; i++)
688 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
690 /* Set the PCI priority bit correctly in the CTRL register. This
691 * determines if the adapter gives priority to receives, or if it
692 * gives equal priority to transmits and receives. Valid only on
693 * 82542 and 82543 silicon.
695 if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
696 ctrl = E1000_READ_REG(hw, CTRL);
697 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
700 switch(hw->mac_type) {
701 case e1000_82545_rev_3:
702 case e1000_82546_rev_3:
705 /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
706 if(hw->bus_type == e1000_bus_type_pcix) {
707 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
708 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
710 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
711 PCIX_COMMAND_MMRBC_SHIFT;
712 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
713 PCIX_STATUS_HI_MMRBC_SHIFT;
714 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
715 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
716 if(cmd_mmrbc > stat_mmrbc) {
717 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
718 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
719 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
726 /* Call a subroutine to configure the link and setup flow control. */
727 ret_val = e1000_setup_link(hw);
729 /* Set the transmit descriptor write-back policy */
730 if(hw->mac_type > e1000_82544) {
731 ctrl = E1000_READ_REG(hw, TXDCTL);
732 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
733 switch (hw->mac_type) {
740 ctrl |= E1000_TXDCTL_COUNT_DESC;
743 E1000_WRITE_REG(hw, TXDCTL, ctrl);
746 if (hw->mac_type == e1000_82573) {
747 e1000_enable_tx_pkt_filtering(hw);
750 switch (hw->mac_type) {
755 ctrl = E1000_READ_REG(hw, TXDCTL1);
756 ctrl &= ~E1000_TXDCTL_WTHRESH;
757 ctrl |= E1000_TXDCTL_COUNT_DESC | E1000_TXDCTL_FULL_TX_DESC_WB;
759 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
765 if (hw->mac_type == e1000_82573) {
766 uint32_t gcr = E1000_READ_REG(hw, GCR);
767 gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
768 E1000_WRITE_REG(hw, GCR, gcr);
771 /* Clear all of the statistics registers (clear on read). It is
772 * important that we do this after we have tried to establish link
773 * because the symbol error count will increment wildly if there
776 e1000_clear_hw_cntrs(hw);
781 /******************************************************************************
782 * Adjust SERDES output amplitude based on EEPROM setting.
784 * hw - Struct containing variables accessed by shared code.
785 *****************************************************************************/
787 e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
789 uint16_t eeprom_data;
792 DEBUGFUNC("e1000_adjust_serdes_amplitude");
794 if(hw->media_type != e1000_media_type_internal_serdes)
795 return E1000_SUCCESS;
797 switch(hw->mac_type) {
798 case e1000_82545_rev_3:
799 case e1000_82546_rev_3:
802 return E1000_SUCCESS;
805 ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
810 if(eeprom_data != EEPROM_RESERVED_WORD) {
811 /* Adjust SERDES output amplitude only. */
812 eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
813 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
818 return E1000_SUCCESS;
821 /******************************************************************************
822 * Configures flow control and link settings.
824 * hw - Struct containing variables accessed by shared code
826 * Determines which flow control settings to use. Calls the apropriate media-
827 * specific link configuration function. Configures the flow control settings.
828 * Assuming the adapter has a valid link partner, a valid link should be
829 * established. Assumes the hardware has previously been reset and the
830 * transmitter and receiver are not enabled.
831 *****************************************************************************/
833 e1000_setup_link(struct e1000_hw *hw)
837 uint16_t eeprom_data;
839 DEBUGFUNC("e1000_setup_link");
841 /* Read and store word 0x0F of the EEPROM. This word contains bits
842 * that determine the hardware's default PAUSE (flow control) mode,
843 * a bit that determines whether the HW defaults to enabling or
844 * disabling auto-negotiation, and the direction of the
845 * SW defined pins. If there is no SW over-ride of the flow
846 * control setting, then the variable hw->fc will
847 * be initialized based on a value in the EEPROM.
849 if (hw->fc == e1000_fc_default) {
850 switch (hw->mac_type) {
852 hw->fc = e1000_fc_full;
855 ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
858 DEBUGOUT("EEPROM Read Error\n");
859 return -E1000_ERR_EEPROM;
861 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
862 hw->fc = e1000_fc_none;
863 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
864 EEPROM_WORD0F_ASM_DIR)
865 hw->fc = e1000_fc_tx_pause;
867 hw->fc = e1000_fc_full;
872 /* We want to save off the original Flow Control configuration just
873 * in case we get disconnected and then reconnected into a different
874 * hub or switch with different Flow Control capabilities.
876 if(hw->mac_type == e1000_82542_rev2_0)
877 hw->fc &= (~e1000_fc_tx_pause);
879 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
880 hw->fc &= (~e1000_fc_rx_pause);
882 hw->original_fc = hw->fc;
884 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
886 /* Take the 4 bits from EEPROM word 0x0F that determine the initial
887 * polarity value for the SW controlled pins, and setup the
888 * Extended Device Control reg with that info.
889 * This is needed because one of the SW controlled pins is used for
890 * signal detection. So this should be done before e1000_setup_pcs_link()
891 * or e1000_phy_setup() is called.
893 if(hw->mac_type == e1000_82543) {
894 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
896 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
899 /* Call the necessary subroutine to configure the link. */
900 ret_val = (hw->media_type == e1000_media_type_copper) ?
901 e1000_setup_copper_link(hw) :
902 e1000_setup_fiber_serdes_link(hw);
904 /* Initialize the flow control address, type, and PAUSE timer
905 * registers to their default values. This is done even if flow
906 * control is disabled, because it does not hurt anything to
907 * initialize these registers.
909 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
911 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
912 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
913 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
915 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
917 /* Set the flow control receive threshold registers. Normally,
918 * these registers will be set to a default threshold that may be
919 * adjusted later by the driver's runtime code. However, if the
920 * ability to transmit pause frames in not enabled, then these
921 * registers will be set to 0.
923 if(!(hw->fc & e1000_fc_tx_pause)) {
924 E1000_WRITE_REG(hw, FCRTL, 0);
925 E1000_WRITE_REG(hw, FCRTH, 0);
927 /* We need to set up the Receive Threshold high and low water marks
928 * as well as (optionally) enabling the transmission of XON frames.
930 if(hw->fc_send_xon) {
931 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
932 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
934 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
935 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
941 /******************************************************************************
942 * Sets up link for a fiber based or serdes based adapter
944 * hw - Struct containing variables accessed by shared code
946 * Manipulates Physical Coding Sublayer functions in order to configure
947 * link. Assumes the hardware has been previously reset and the transmitter
948 * and receiver are not enabled.
949 *****************************************************************************/
951 e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
960 DEBUGFUNC("e1000_setup_fiber_serdes_link");
962 /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
963 * until explicitly turned off or a power cycle is performed. A read to
964 * the register does not indicate its status. Therefore, we ensure
965 * loopback mode is disabled during initialization.
967 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
968 E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
970 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
971 * set when the optics detect a signal. On older adapters, it will be
972 * cleared when there is a signal. This applies to fiber media only.
973 * If we're on serdes media, adjust the output amplitude to value set in
976 ctrl = E1000_READ_REG(hw, CTRL);
977 if(hw->media_type == e1000_media_type_fiber)
978 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
980 ret_val = e1000_adjust_serdes_amplitude(hw);
984 /* Take the link out of reset */
985 ctrl &= ~(E1000_CTRL_LRST);
987 /* Adjust VCO speed to improve BER performance */
988 ret_val = e1000_set_vco_speed(hw);
992 e1000_config_collision_dist(hw);
994 /* Check for a software override of the flow control settings, and setup
995 * the device accordingly. If auto-negotiation is enabled, then software
996 * will have to set the "PAUSE" bits to the correct value in the Tranmsit
997 * Config Word Register (TXCW) and re-start auto-negotiation. However, if
998 * auto-negotiation is disabled, then software will have to manually
999 * configure the two flow control enable bits in the CTRL register.
1001 * The possible values of the "fc" parameter are:
1002 * 0: Flow control is completely disabled
1003 * 1: Rx flow control is enabled (we can receive pause frames, but
1004 * not send pause frames).
1005 * 2: Tx flow control is enabled (we can send pause frames but we do
1006 * not support receiving pause frames).
1007 * 3: Both Rx and TX flow control (symmetric) are enabled.
1011 /* Flow control is completely disabled by a software over-ride. */
1012 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
1014 case e1000_fc_rx_pause:
1015 /* RX Flow control is enabled and TX Flow control is disabled by a
1016 * software over-ride. Since there really isn't a way to advertise
1017 * that we are capable of RX Pause ONLY, we will advertise that we
1018 * support both symmetric and asymmetric RX PAUSE. Later, we will
1019 * disable the adapter's ability to send PAUSE frames.
1021 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1023 case e1000_fc_tx_pause:
1024 /* TX Flow control is enabled, and RX Flow control is disabled, by a
1025 * software over-ride.
1027 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
1030 /* Flow control (both RX and TX) is enabled by a software over-ride. */
1031 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
1034 DEBUGOUT("Flow control param set incorrectly\n");
1035 return -E1000_ERR_CONFIG;
1039 /* Since auto-negotiation is enabled, take the link out of reset (the link
1040 * will be in reset, because we previously reset the chip). This will
1041 * restart auto-negotiation. If auto-neogtiation is successful then the
1042 * link-up status bit will be set and the flow control enable bits (RFCE
1043 * and TFCE) will be set according to their negotiated value.
1045 DEBUGOUT("Auto-negotiation enabled\n");
1047 E1000_WRITE_REG(hw, TXCW, txcw);
1048 E1000_WRITE_REG(hw, CTRL, ctrl);
1049 E1000_WRITE_FLUSH(hw);
1054 /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
1055 * indication in the Device Status Register. Time-out if a link isn't
1056 * seen in 500 milliseconds seconds (Auto-negotiation should complete in
1057 * less than 500 milliseconds even if the other end is doing it in SW).
1058 * For internal serdes, we just assume a signal is present, then poll.
1060 if(hw->media_type == e1000_media_type_internal_serdes ||
1061 (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
1062 DEBUGOUT("Looking for Link\n");
1063 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
1065 status = E1000_READ_REG(hw, STATUS);
1066 if(status & E1000_STATUS_LU) break;
1068 if(i == (LINK_UP_TIMEOUT / 10)) {
1069 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
1070 hw->autoneg_failed = 1;
1071 /* AutoNeg failed to achieve a link, so we'll call
1072 * e1000_check_for_link. This routine will force the link up if
1073 * we detect a signal. This will allow us to communicate with
1074 * non-autonegotiating link partners.
1076 ret_val = e1000_check_for_link(hw);
1078 DEBUGOUT("Error while checking for link\n");
1081 hw->autoneg_failed = 0;
1083 hw->autoneg_failed = 0;
1084 DEBUGOUT("Valid Link Found\n");
1087 DEBUGOUT("No Signal Detected\n");
1089 return E1000_SUCCESS;
1092 /******************************************************************************
1093 * Make sure we have a valid PHY and change PHY mode before link setup.
1095 * hw - Struct containing variables accessed by shared code
1096 ******************************************************************************/
1098 e1000_copper_link_preconfig(struct e1000_hw *hw)
1104 DEBUGFUNC("e1000_copper_link_preconfig");
1106 ctrl = E1000_READ_REG(hw, CTRL);
1107 /* With 82543, we need to force speed and duplex on the MAC equal to what
1108 * the PHY speed and duplex configuration is. In addition, we need to
1109 * perform a hardware reset on the PHY to take it out of reset.
1111 if(hw->mac_type > e1000_82543) {
1112 ctrl |= E1000_CTRL_SLU;
1113 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1114 E1000_WRITE_REG(hw, CTRL, ctrl);
1116 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
1117 E1000_WRITE_REG(hw, CTRL, ctrl);
1118 ret_val = e1000_phy_hw_reset(hw);
1123 /* Make sure we have a valid PHY */
1124 ret_val = e1000_detect_gig_phy(hw);
1126 DEBUGOUT("Error, did not detect valid phy.\n");
1129 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
1131 /* Set PHY to class A mode (if necessary) */
1132 ret_val = e1000_set_phy_mode(hw);
1136 if((hw->mac_type == e1000_82545_rev_3) ||
1137 (hw->mac_type == e1000_82546_rev_3)) {
1138 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1139 phy_data |= 0x00000008;
1140 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1143 if(hw->mac_type <= e1000_82543 ||
1144 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
1145 hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
1146 hw->phy_reset_disable = FALSE;
1148 return E1000_SUCCESS;
1152 /********************************************************************
1153 * Copper link setup for e1000_phy_igp series.
1155 * hw - Struct containing variables accessed by shared code
1156 *********************************************************************/
1158 e1000_copper_link_igp_setup(struct e1000_hw *hw)
1164 DEBUGFUNC("e1000_copper_link_igp_setup");
1166 if (hw->phy_reset_disable)
1167 return E1000_SUCCESS;
1169 ret_val = e1000_phy_reset(hw);
1171 DEBUGOUT("Error Resetting the PHY\n");
1175 /* Wait 10ms for MAC to configure PHY from eeprom settings */
1178 /* Configure activity LED after PHY reset */
1179 led_ctrl = E1000_READ_REG(hw, LEDCTL);
1180 led_ctrl &= IGP_ACTIVITY_LED_MASK;
1181 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
1182 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
1184 /* disable lplu d3 during driver init */
1185 ret_val = e1000_set_d3_lplu_state(hw, FALSE);
1187 DEBUGOUT("Error Disabling LPLU D3\n");
1191 /* disable lplu d0 during driver init */
1192 ret_val = e1000_set_d0_lplu_state(hw, FALSE);
1194 DEBUGOUT("Error Disabling LPLU D0\n");
1197 /* Configure mdi-mdix settings */
1198 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1202 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
1203 hw->dsp_config_state = e1000_dsp_config_disabled;
1204 /* Force MDI for earlier revs of the IGP PHY */
1205 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
1209 hw->dsp_config_state = e1000_dsp_config_enabled;
1210 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1214 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1217 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
1221 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
1225 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1229 /* set auto-master slave resolution settings */
1231 e1000_ms_type phy_ms_setting = hw->master_slave;
1233 if(hw->ffe_config_state == e1000_ffe_config_active)
1234 hw->ffe_config_state = e1000_ffe_config_enabled;
1236 if(hw->dsp_config_state == e1000_dsp_config_activated)
1237 hw->dsp_config_state = e1000_dsp_config_enabled;
1239 /* when autonegotiation advertisment is only 1000Mbps then we
1240 * should disable SmartSpeed and enable Auto MasterSlave
1241 * resolution as hardware default. */
1242 if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
1243 /* Disable SmartSpeed */
1244 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
1247 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1248 ret_val = e1000_write_phy_reg(hw,
1249 IGP01E1000_PHY_PORT_CONFIG,
1253 /* Set auto Master/Slave resolution process */
1254 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1257 phy_data &= ~CR_1000T_MS_ENABLE;
1258 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1263 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
1267 /* load defaults for future use */
1268 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1269 ((phy_data & CR_1000T_MS_VALUE) ?
1270 e1000_ms_force_master :
1271 e1000_ms_force_slave) :
1274 switch (phy_ms_setting) {
1275 case e1000_ms_force_master:
1276 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1278 case e1000_ms_force_slave:
1279 phy_data |= CR_1000T_MS_ENABLE;
1280 phy_data &= ~(CR_1000T_MS_VALUE);
1283 phy_data &= ~CR_1000T_MS_ENABLE;
1287 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
1292 return E1000_SUCCESS;
1296 /********************************************************************
1297 * Copper link setup for e1000_phy_m88 series.
1299 * hw - Struct containing variables accessed by shared code
1300 *********************************************************************/
1302 e1000_copper_link_mgp_setup(struct e1000_hw *hw)
1307 DEBUGFUNC("e1000_copper_link_mgp_setup");
1309 if(hw->phy_reset_disable)
1310 return E1000_SUCCESS;
1312 /* Enable CRS on TX. This must be set for half-duplex operation. */
1313 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1317 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1320 * MDI/MDI-X = 0 (default)
1321 * 0 - Auto for all speeds
1324 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1326 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1330 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1333 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1336 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1340 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1345 * disable_polarity_correction = 0 (default)
1346 * Automatic Correction for Reversed Cable Polarity
1350 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1351 if(hw->disable_polarity_correction == 1)
1352 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1353 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1357 /* Force TX_CLK in the Extended PHY Specific Control Register
1360 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1364 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1366 if (hw->phy_revision < M88E1011_I_REV_4) {
1367 /* Configure Master and Slave downshift values */
1368 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1369 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1370 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1371 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1372 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1377 /* SW Reset the PHY so all changes take effect */
1378 ret_val = e1000_phy_reset(hw);
1380 DEBUGOUT("Error Resetting the PHY\n");
1384 return E1000_SUCCESS;
1387 /********************************************************************
1388 * Setup auto-negotiation and flow control advertisements,
1389 * and then perform auto-negotiation.
1391 * hw - Struct containing variables accessed by shared code
1392 *********************************************************************/
1394 e1000_copper_link_autoneg(struct e1000_hw *hw)
1399 DEBUGFUNC("e1000_copper_link_autoneg");
1401 /* Perform some bounds checking on the hw->autoneg_advertised
1402 * parameter. If this variable is zero, then set it to the default.
1404 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1406 /* If autoneg_advertised is zero, we assume it was not defaulted
1407 * by the calling code so we set to advertise full capability.
1409 if(hw->autoneg_advertised == 0)
1410 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1412 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1413 ret_val = e1000_phy_setup_autoneg(hw);
1415 DEBUGOUT("Error Setting up Auto-Negotiation\n");
1418 DEBUGOUT("Restarting Auto-Neg\n");
1420 /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1421 * the Auto Neg Restart bit in the PHY control register.
1423 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
1427 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1428 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
1432 /* Does the user want to wait for Auto-Neg to complete here, or
1433 * check at a later time (for example, callback routine).
1435 if(hw->wait_autoneg_complete) {
1436 ret_val = e1000_wait_autoneg(hw);
1438 DEBUGOUT("Error while waiting for autoneg to complete\n");
1443 hw->get_link_status = TRUE;
1445 return E1000_SUCCESS;
1449 /******************************************************************************
1450 * Config the MAC and the PHY after link is up.
1451 * 1) Set up the MAC to the current PHY speed/duplex
1452 * if we are on 82543. If we
1453 * are on newer silicon, we only need to configure
1454 * collision distance in the Transmit Control Register.
1455 * 2) Set up flow control on the MAC to that established with
1457 * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
1459 * hw - Struct containing variables accessed by shared code
1460 ******************************************************************************/
1462 e1000_copper_link_postconfig(struct e1000_hw *hw)
1465 DEBUGFUNC("e1000_copper_link_postconfig");
1467 if(hw->mac_type >= e1000_82544) {
1468 e1000_config_collision_dist(hw);
1470 ret_val = e1000_config_mac_to_phy(hw);
1472 DEBUGOUT("Error configuring MAC to PHY settings\n");
1476 ret_val = e1000_config_fc_after_link_up(hw);
1478 DEBUGOUT("Error Configuring Flow Control\n");
1482 /* Config DSP to improve Giga link quality */
1483 if(hw->phy_type == e1000_phy_igp) {
1484 ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
1486 DEBUGOUT("Error Configuring DSP after link up\n");
1491 return E1000_SUCCESS;
1494 /******************************************************************************
1495 * Detects which PHY is present and setup the speed and duplex
1497 * hw - Struct containing variables accessed by shared code
1498 ******************************************************************************/
1500 e1000_setup_copper_link(struct e1000_hw *hw)
1506 DEBUGFUNC("e1000_setup_copper_link");
1508 /* Check if it is a valid PHY and set PHY mode if necessary. */
1509 ret_val = e1000_copper_link_preconfig(hw);
1513 if (hw->phy_type == e1000_phy_igp ||
1514 hw->phy_type == e1000_phy_igp_2) {
1515 ret_val = e1000_copper_link_igp_setup(hw);
1518 } else if (hw->phy_type == e1000_phy_m88) {
1519 ret_val = e1000_copper_link_mgp_setup(hw);
1525 /* Setup autoneg and flow control advertisement
1526 * and perform autonegotiation */
1527 ret_val = e1000_copper_link_autoneg(hw);
1531 /* PHY will be set to 10H, 10F, 100H,or 100F
1532 * depending on value from forced_speed_duplex. */
1533 DEBUGOUT("Forcing speed and duplex\n");
1534 ret_val = e1000_phy_force_speed_duplex(hw);
1536 DEBUGOUT("Error Forcing Speed and Duplex\n");
1541 /* Check link status. Wait up to 100 microseconds for link to become
1544 for(i = 0; i < 10; i++) {
1545 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1548 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
1552 if(phy_data & MII_SR_LINK_STATUS) {
1553 /* Config the MAC and PHY after link is up */
1554 ret_val = e1000_copper_link_postconfig(hw);
1558 DEBUGOUT("Valid link established!!!\n");
1559 return E1000_SUCCESS;
1564 DEBUGOUT("Unable to establish link!!!\n");
1565 return E1000_SUCCESS;
1568 /******************************************************************************
1569 * Configures PHY autoneg and flow control advertisement settings
1571 * hw - Struct containing variables accessed by shared code
1572 ******************************************************************************/
1574 e1000_phy_setup_autoneg(struct e1000_hw *hw)
1577 uint16_t mii_autoneg_adv_reg;
1578 uint16_t mii_1000t_ctrl_reg;
1580 DEBUGFUNC("e1000_phy_setup_autoneg");
1582 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1583 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1587 /* Read the MII 1000Base-T Control Register (Address 9). */
1588 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
1592 /* Need to parse both autoneg_advertised and fc and set up
1593 * the appropriate PHY registers. First we will parse for
1594 * autoneg_advertised software override. Since we can advertise
1595 * a plethora of combinations, we need to check each bit
1599 /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1600 * Advertisement Register (Address 4) and the 1000 mb speed bits in
1601 * the 1000Base-T Control Register (Address 9).
1603 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1604 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1606 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1608 /* Do we want to advertise 10 Mb Half Duplex? */
1609 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1610 DEBUGOUT("Advertise 10mb Half duplex\n");
1611 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1614 /* Do we want to advertise 10 Mb Full Duplex? */
1615 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1616 DEBUGOUT("Advertise 10mb Full duplex\n");
1617 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1620 /* Do we want to advertise 100 Mb Half Duplex? */
1621 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1622 DEBUGOUT("Advertise 100mb Half duplex\n");
1623 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1626 /* Do we want to advertise 100 Mb Full Duplex? */
1627 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1628 DEBUGOUT("Advertise 100mb Full duplex\n");
1629 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1632 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1633 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1634 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1637 /* Do we want to advertise 1000 Mb Full Duplex? */
1638 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1639 DEBUGOUT("Advertise 1000mb Full duplex\n");
1640 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1643 /* Check for a software override of the flow control settings, and
1644 * setup the PHY advertisement registers accordingly. If
1645 * auto-negotiation is enabled, then software will have to set the
1646 * "PAUSE" bits to the correct value in the Auto-Negotiation
1647 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1649 * The possible values of the "fc" parameter are:
1650 * 0: Flow control is completely disabled
1651 * 1: Rx flow control is enabled (we can receive pause frames
1652 * but not send pause frames).
1653 * 2: Tx flow control is enabled (we can send pause frames
1654 * but we do not support receiving pause frames).
1655 * 3: Both Rx and TX flow control (symmetric) are enabled.
1656 * other: No software override. The flow control configuration
1657 * in the EEPROM is used.
1660 case e1000_fc_none: /* 0 */
1661 /* Flow control (RX & TX) is completely disabled by a
1662 * software over-ride.
1664 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1666 case e1000_fc_rx_pause: /* 1 */
1667 /* RX Flow control is enabled, and TX Flow control is
1668 * disabled, by a software over-ride.
1670 /* Since there really isn't a way to advertise that we are
1671 * capable of RX Pause ONLY, we will advertise that we
1672 * support both symmetric and asymmetric RX PAUSE. Later
1673 * (in e1000_config_fc_after_link_up) we will disable the
1674 *hw's ability to send PAUSE frames.
1676 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1678 case e1000_fc_tx_pause: /* 2 */
1679 /* TX Flow control is enabled, and RX Flow control is
1680 * disabled, by a software over-ride.
1682 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1683 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1685 case e1000_fc_full: /* 3 */
1686 /* Flow control (both RX and TX) is enabled by a software
1689 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1692 DEBUGOUT("Flow control param set incorrectly\n");
1693 return -E1000_ERR_CONFIG;
1696 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1700 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1702 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
1706 return E1000_SUCCESS;
1709 /******************************************************************************
1710 * Force PHY speed and duplex settings to hw->forced_speed_duplex
1712 * hw - Struct containing variables accessed by shared code
1713 ******************************************************************************/
1715 e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1719 uint16_t mii_ctrl_reg;
1720 uint16_t mii_status_reg;
1724 DEBUGFUNC("e1000_phy_force_speed_duplex");
1726 /* Turn off Flow control if we are forcing speed and duplex. */
1727 hw->fc = e1000_fc_none;
1729 DEBUGOUT1("hw->fc = %d\n", hw->fc);
1731 /* Read the Device Control Register. */
1732 ctrl = E1000_READ_REG(hw, CTRL);
1734 /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1735 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1736 ctrl &= ~(DEVICE_SPEED_MASK);
1738 /* Clear the Auto Speed Detect Enable bit. */
1739 ctrl &= ~E1000_CTRL_ASDE;
1741 /* Read the MII Control Register. */
1742 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
1746 /* We need to disable autoneg in order to force link and duplex. */
1748 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1750 /* Are we forcing Full or Half Duplex? */
1751 if(hw->forced_speed_duplex == e1000_100_full ||
1752 hw->forced_speed_duplex == e1000_10_full) {
1753 /* We want to force full duplex so we SET the full duplex bits in the
1754 * Device and MII Control Registers.
1756 ctrl |= E1000_CTRL_FD;
1757 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1758 DEBUGOUT("Full Duplex\n");
1760 /* We want to force half duplex so we CLEAR the full duplex bits in
1761 * the Device and MII Control Registers.
1763 ctrl &= ~E1000_CTRL_FD;
1764 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1765 DEBUGOUT("Half Duplex\n");
1768 /* Are we forcing 100Mbps??? */
1769 if(hw->forced_speed_duplex == e1000_100_full ||
1770 hw->forced_speed_duplex == e1000_100_half) {
1771 /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1772 ctrl |= E1000_CTRL_SPD_100;
1773 mii_ctrl_reg |= MII_CR_SPEED_100;
1774 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1775 DEBUGOUT("Forcing 100mb ");
1777 /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1778 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1779 mii_ctrl_reg |= MII_CR_SPEED_10;
1780 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1781 DEBUGOUT("Forcing 10mb ");
1784 e1000_config_collision_dist(hw);
1786 /* Write the configured values back to the Device Control Reg. */
1787 E1000_WRITE_REG(hw, CTRL, ctrl);
1789 if (hw->phy_type == e1000_phy_m88) {
1790 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1794 /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1795 * forced whenever speed are duplex are forced.
1797 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1798 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1802 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1804 /* Need to reset the PHY or these changes will be ignored */
1805 mii_ctrl_reg |= MII_CR_RESET;
1807 /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
1808 * forced whenever speed or duplex are forced.
1810 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1814 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1815 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1817 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1822 /* Write back the modified PHY MII control register. */
1823 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
1829 /* The wait_autoneg_complete flag may be a little misleading here.
1830 * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1831 * But we do want to delay for a period while forcing only so we
1832 * don't generate false No Link messages. So we will wait here
1833 * only if the user has set wait_autoneg_complete to 1, which is
1836 if(hw->wait_autoneg_complete) {
1837 /* We will wait for autoneg to complete. */
1838 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1841 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1842 for(i = PHY_FORCE_TIME; i > 0; i--) {
1843 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1846 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1850 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1854 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1858 (hw->phy_type == e1000_phy_m88)) {
1859 /* We didn't get link. Reset the DSP and wait again for link. */
1860 ret_val = e1000_phy_reset_dsp(hw);
1862 DEBUGOUT("Error Resetting PHY DSP\n");
1866 /* This loop will early-out if the link condition has been met. */
1867 for(i = PHY_FORCE_TIME; i > 0; i--) {
1868 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1870 /* Read the MII Status Register and wait for Auto-Neg Complete bit
1873 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1877 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
1883 if (hw->phy_type == e1000_phy_m88) {
1884 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1885 * Extended PHY Specific Control Register to 25MHz clock. This value
1886 * defaults back to a 2.5MHz clock when the PHY is reset.
1888 ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1892 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1893 ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1897 /* In addition, because of the s/w reset above, we need to enable CRS on
1898 * TX. This must be set for both full and half duplex operation.
1900 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1904 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1905 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1909 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
1911 (hw->forced_speed_duplex == e1000_10_full ||
1912 hw->forced_speed_duplex == e1000_10_half)) {
1913 ret_val = e1000_polarity_reversal_workaround(hw);
1918 return E1000_SUCCESS;
1921 /******************************************************************************
1922 * Sets the collision distance in the Transmit Control register
1924 * hw - Struct containing variables accessed by shared code
1926 * Link should have been established previously. Reads the speed and duplex
1927 * information from the Device Status register.
1928 ******************************************************************************/
1930 e1000_config_collision_dist(struct e1000_hw *hw)
1934 DEBUGFUNC("e1000_config_collision_dist");
1936 tctl = E1000_READ_REG(hw, TCTL);
1938 tctl &= ~E1000_TCTL_COLD;
1939 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1941 E1000_WRITE_REG(hw, TCTL, tctl);
1942 E1000_WRITE_FLUSH(hw);
1945 /******************************************************************************
1946 * Sets MAC speed and duplex settings to reflect the those in the PHY
1948 * hw - Struct containing variables accessed by shared code
1949 * mii_reg - data to write to the MII control register
1951 * The contents of the PHY register containing the needed information need to
1953 ******************************************************************************/
1955 e1000_config_mac_to_phy(struct e1000_hw *hw)
1961 DEBUGFUNC("e1000_config_mac_to_phy");
1963 /* 82544 or newer MAC, Auto Speed Detection takes care of
1964 * MAC speed/duplex configuration.*/
1965 if (hw->mac_type >= e1000_82544)
1966 return E1000_SUCCESS;
1968 /* Read the Device Control Register and set the bits to Force Speed
1971 ctrl = E1000_READ_REG(hw, CTRL);
1972 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1973 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1975 /* Set up duplex in the Device Control and Transmit Control
1976 * registers depending on negotiated values.
1978 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1982 if(phy_data & M88E1000_PSSR_DPLX)
1983 ctrl |= E1000_CTRL_FD;
1985 ctrl &= ~E1000_CTRL_FD;
1987 e1000_config_collision_dist(hw);
1989 /* Set up speed in the Device Control register depending on
1990 * negotiated values.
1992 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1993 ctrl |= E1000_CTRL_SPD_1000;
1994 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1995 ctrl |= E1000_CTRL_SPD_100;
1997 /* Write the configured values back to the Device Control Reg. */
1998 E1000_WRITE_REG(hw, CTRL, ctrl);
1999 return E1000_SUCCESS;
2002 /******************************************************************************
2003 * Forces the MAC's flow control settings.
2005 * hw - Struct containing variables accessed by shared code
2007 * Sets the TFCE and RFCE bits in the device control register to reflect
2008 * the adapter settings. TFCE and RFCE need to be explicitly set by
2009 * software when a Copper PHY is used because autonegotiation is managed
2010 * by the PHY rather than the MAC. Software must also configure these
2011 * bits when link is forced on a fiber connection.
2012 *****************************************************************************/
2014 e1000_force_mac_fc(struct e1000_hw *hw)
2018 DEBUGFUNC("e1000_force_mac_fc");
2020 /* Get the current configuration of the Device Control Register */
2021 ctrl = E1000_READ_REG(hw, CTRL);
2023 /* Because we didn't get link via the internal auto-negotiation
2024 * mechanism (we either forced link or we got link via PHY
2025 * auto-neg), we have to manually enable/disable transmit an
2026 * receive flow control.
2028 * The "Case" statement below enables/disable flow control
2029 * according to the "hw->fc" parameter.
2031 * The possible values of the "fc" parameter are:
2032 * 0: Flow control is completely disabled
2033 * 1: Rx flow control is enabled (we can receive pause
2034 * frames but not send pause frames).
2035 * 2: Tx flow control is enabled (we can send pause frames
2036 * frames but we do not receive pause frames).
2037 * 3: Both Rx and TX flow control (symmetric) is enabled.
2038 * other: No other values should be possible at this point.
2043 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
2045 case e1000_fc_rx_pause:
2046 ctrl &= (~E1000_CTRL_TFCE);
2047 ctrl |= E1000_CTRL_RFCE;
2049 case e1000_fc_tx_pause:
2050 ctrl &= (~E1000_CTRL_RFCE);
2051 ctrl |= E1000_CTRL_TFCE;
2054 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
2057 DEBUGOUT("Flow control param set incorrectly\n");
2058 return -E1000_ERR_CONFIG;
2061 /* Disable TX Flow Control for 82542 (rev 2.0) */
2062 if(hw->mac_type == e1000_82542_rev2_0)
2063 ctrl &= (~E1000_CTRL_TFCE);
2065 E1000_WRITE_REG(hw, CTRL, ctrl);
2066 return E1000_SUCCESS;
2069 /******************************************************************************
2070 * Configures flow control settings after link is established
2072 * hw - Struct containing variables accessed by shared code
2074 * Should be called immediately after a valid link has been established.
2075 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
2076 * and autonegotiation is enabled, the MAC flow control settings will be set
2077 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
2078 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
2079 *****************************************************************************/
2081 e1000_config_fc_after_link_up(struct e1000_hw *hw)
2084 uint16_t mii_status_reg;
2085 uint16_t mii_nway_adv_reg;
2086 uint16_t mii_nway_lp_ability_reg;
2090 DEBUGFUNC("e1000_config_fc_after_link_up");
2092 /* Check for the case where we have fiber media and auto-neg failed
2093 * so we had to force link. In this case, we need to force the
2094 * configuration of the MAC to match the "fc" parameter.
2096 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
2097 ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
2098 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
2099 ret_val = e1000_force_mac_fc(hw);
2101 DEBUGOUT("Error forcing flow control settings\n");
2106 /* Check for the case where we have copper media and auto-neg is
2107 * enabled. In this case, we need to check and see if Auto-Neg
2108 * has completed, and if so, how the PHY and link partner has
2109 * flow control configured.
2111 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
2112 /* Read the MII Status Register and check to see if AutoNeg
2113 * has completed. We read this twice because this reg has
2114 * some "sticky" (latched) bits.
2116 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2119 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
2123 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
2124 /* The AutoNeg process has completed, so we now need to
2125 * read both the Auto Negotiation Advertisement Register
2126 * (Address 4) and the Auto_Negotiation Base Page Ability
2127 * Register (Address 5) to determine how flow control was
2130 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
2134 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
2135 &mii_nway_lp_ability_reg);
2139 /* Two bits in the Auto Negotiation Advertisement Register
2140 * (Address 4) and two bits in the Auto Negotiation Base
2141 * Page Ability Register (Address 5) determine flow control
2142 * for both the PHY and the link partner. The following
2143 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
2144 * 1999, describes these PAUSE resolution bits and how flow
2145 * control is determined based upon these settings.
2146 * NOTE: DC = Don't Care
2148 * LOCAL DEVICE | LINK PARTNER
2149 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
2150 *-------|---------|-------|---------|--------------------
2151 * 0 | 0 | DC | DC | e1000_fc_none
2152 * 0 | 1 | 0 | DC | e1000_fc_none
2153 * 0 | 1 | 1 | 0 | e1000_fc_none
2154 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2155 * 1 | 0 | 0 | DC | e1000_fc_none
2156 * 1 | DC | 1 | DC | e1000_fc_full
2157 * 1 | 1 | 0 | 0 | e1000_fc_none
2158 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2161 /* Are both PAUSE bits set to 1? If so, this implies
2162 * Symmetric Flow Control is enabled at both ends. The
2163 * ASM_DIR bits are irrelevant per the spec.
2165 * For Symmetric Flow Control:
2167 * LOCAL DEVICE | LINK PARTNER
2168 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2169 *-------|---------|-------|---------|--------------------
2170 * 1 | DC | 1 | DC | e1000_fc_full
2173 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2174 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
2175 /* Now we need to check if the user selected RX ONLY
2176 * of pause frames. In this case, we had to advertise
2177 * FULL flow control because we could not advertise RX
2178 * ONLY. Hence, we must now check to see if we need to
2179 * turn OFF the TRANSMISSION of PAUSE frames.
2181 if(hw->original_fc == e1000_fc_full) {
2182 hw->fc = e1000_fc_full;
2183 DEBUGOUT("Flow Control = FULL.\r\n");
2185 hw->fc = e1000_fc_rx_pause;
2186 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2189 /* For receiving PAUSE frames ONLY.
2191 * LOCAL DEVICE | LINK PARTNER
2192 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2193 *-------|---------|-------|---------|--------------------
2194 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
2197 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2198 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2199 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2200 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2201 hw->fc = e1000_fc_tx_pause;
2202 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
2204 /* For transmitting PAUSE frames ONLY.
2206 * LOCAL DEVICE | LINK PARTNER
2207 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
2208 *-------|---------|-------|---------|--------------------
2209 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
2212 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
2213 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
2214 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
2215 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
2216 hw->fc = e1000_fc_rx_pause;
2217 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2219 /* Per the IEEE spec, at this point flow control should be
2220 * disabled. However, we want to consider that we could
2221 * be connected to a legacy switch that doesn't advertise
2222 * desired flow control, but can be forced on the link
2223 * partner. So if we advertised no flow control, that is
2224 * what we will resolve to. If we advertised some kind of
2225 * receive capability (Rx Pause Only or Full Flow Control)
2226 * and the link partner advertised none, we will configure
2227 * ourselves to enable Rx Flow Control only. We can do
2228 * this safely for two reasons: If the link partner really
2229 * didn't want flow control enabled, and we enable Rx, no
2230 * harm done since we won't be receiving any PAUSE frames
2231 * anyway. If the intent on the link partner was to have
2232 * flow control enabled, then by us enabling RX only, we
2233 * can at least receive pause frames and process them.
2234 * This is a good idea because in most cases, since we are
2235 * predominantly a server NIC, more times than not we will
2236 * be asked to delay transmission of packets than asking
2237 * our link partner to pause transmission of frames.
2239 else if((hw->original_fc == e1000_fc_none ||
2240 hw->original_fc == e1000_fc_tx_pause) ||
2241 hw->fc_strict_ieee) {
2242 hw->fc = e1000_fc_none;
2243 DEBUGOUT("Flow Control = NONE.\r\n");
2245 hw->fc = e1000_fc_rx_pause;
2246 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
2249 /* Now we need to do one last check... If we auto-
2250 * negotiated to HALF DUPLEX, flow control should not be
2251 * enabled per IEEE 802.3 spec.
2253 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
2255 DEBUGOUT("Error getting link speed and duplex\n");
2259 if(duplex == HALF_DUPLEX)
2260 hw->fc = e1000_fc_none;
2262 /* Now we call a subroutine to actually force the MAC
2263 * controller to use the correct flow control settings.
2265 ret_val = e1000_force_mac_fc(hw);
2267 DEBUGOUT("Error forcing flow control settings\n");
2271 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
2274 return E1000_SUCCESS;
2277 /******************************************************************************
2278 * Checks to see if the link status of the hardware has changed.
2280 * hw - Struct containing variables accessed by shared code
2282 * Called by any function that needs to check the link status of the adapter.
2283 *****************************************************************************/
2285 e1000_check_for_link(struct e1000_hw *hw)
2292 uint32_t signal = 0;
2296 DEBUGFUNC("e1000_check_for_link");
2298 ctrl = E1000_READ_REG(hw, CTRL);
2299 status = E1000_READ_REG(hw, STATUS);
2301 /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
2302 * set when the optics detect a signal. On older adapters, it will be
2303 * cleared when there is a signal. This applies to fiber media only.
2305 if((hw->media_type == e1000_media_type_fiber) ||
2306 (hw->media_type == e1000_media_type_internal_serdes)) {
2307 rxcw = E1000_READ_REG(hw, RXCW);
2309 if(hw->media_type == e1000_media_type_fiber) {
2310 signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
2311 if(status & E1000_STATUS_LU)
2312 hw->get_link_status = FALSE;
2316 /* If we have a copper PHY then we only want to go out to the PHY
2317 * registers to see if Auto-Neg has completed and/or if our link
2318 * status has changed. The get_link_status flag will be set if we
2319 * receive a Link Status Change interrupt or we have Rx Sequence
2322 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
2323 /* First we want to see if the MII Status Register reports
2324 * link. If so, then we want to get the current speed/duplex
2326 * Read the register twice since the link bit is sticky.
2328 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2331 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2335 if(phy_data & MII_SR_LINK_STATUS) {
2336 hw->get_link_status = FALSE;
2337 /* Check if there was DownShift, must be checked immediately after
2339 e1000_check_downshift(hw);
2341 /* If we are on 82544 or 82543 silicon and speed/duplex
2342 * are forced to 10H or 10F, then we will implement the polarity
2343 * reversal workaround. We disable interrupts first, and upon
2344 * returning, place the devices interrupt state to its previous
2345 * value except for the link status change interrupt which will
2346 * happen due to the execution of this workaround.
2349 if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
2351 (hw->forced_speed_duplex == e1000_10_full ||
2352 hw->forced_speed_duplex == e1000_10_half)) {
2353 E1000_WRITE_REG(hw, IMC, 0xffffffff);
2354 ret_val = e1000_polarity_reversal_workaround(hw);
2355 icr = E1000_READ_REG(hw, ICR);
2356 E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
2357 E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
2361 /* No link detected */
2362 e1000_config_dsp_after_link_change(hw, FALSE);
2366 /* If we are forcing speed/duplex, then we simply return since
2367 * we have already determined whether we have link or not.
2369 if(!hw->autoneg) return -E1000_ERR_CONFIG;
2371 /* optimize the dsp settings for the igp phy */
2372 e1000_config_dsp_after_link_change(hw, TRUE);
2374 /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
2375 * have Si on board that is 82544 or newer, Auto
2376 * Speed Detection takes care of MAC speed/duplex
2377 * configuration. So we only need to configure Collision
2378 * Distance in the MAC. Otherwise, we need to force
2379 * speed/duplex on the MAC to the current PHY speed/duplex
2382 if(hw->mac_type >= e1000_82544)
2383 e1000_config_collision_dist(hw);
2385 ret_val = e1000_config_mac_to_phy(hw);
2387 DEBUGOUT("Error configuring MAC to PHY settings\n");
2392 /* Configure Flow Control now that Auto-Neg has completed. First, we
2393 * need to restore the desired flow control settings because we may
2394 * have had to re-autoneg with a different link partner.
2396 ret_val = e1000_config_fc_after_link_up(hw);
2398 DEBUGOUT("Error configuring flow control\n");
2402 /* At this point we know that we are on copper and we have
2403 * auto-negotiated link. These are conditions for checking the link
2404 * partner capability register. We use the link speed to determine if
2405 * TBI compatibility needs to be turned on or off. If the link is not
2406 * at gigabit speed, then TBI compatibility is not needed. If we are
2407 * at gigabit speed, we turn on TBI compatibility.
2409 if(hw->tbi_compatibility_en) {
2410 uint16_t speed, duplex;
2411 e1000_get_speed_and_duplex(hw, &speed, &duplex);
2412 if(speed != SPEED_1000) {
2413 /* If link speed is not set to gigabit speed, we do not need
2414 * to enable TBI compatibility.
2416 if(hw->tbi_compatibility_on) {
2417 /* If we previously were in the mode, turn it off. */
2418 rctl = E1000_READ_REG(hw, RCTL);
2419 rctl &= ~E1000_RCTL_SBP;
2420 E1000_WRITE_REG(hw, RCTL, rctl);
2421 hw->tbi_compatibility_on = FALSE;
2424 /* If TBI compatibility is was previously off, turn it on. For
2425 * compatibility with a TBI link partner, we will store bad
2426 * packets. Some frames have an additional byte on the end and
2427 * will look like CRC errors to to the hardware.
2429 if(!hw->tbi_compatibility_on) {
2430 hw->tbi_compatibility_on = TRUE;
2431 rctl = E1000_READ_REG(hw, RCTL);
2432 rctl |= E1000_RCTL_SBP;
2433 E1000_WRITE_REG(hw, RCTL, rctl);
2438 /* If we don't have link (auto-negotiation failed or link partner cannot
2439 * auto-negotiate), the cable is plugged in (we have signal), and our
2440 * link partner is not trying to auto-negotiate with us (we are receiving
2441 * idles or data), we need to force link up. We also need to give
2442 * auto-negotiation time to complete, in case the cable was just plugged
2443 * in. The autoneg_failed flag does this.
2445 else if((((hw->media_type == e1000_media_type_fiber) &&
2446 ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2447 (hw->media_type == e1000_media_type_internal_serdes)) &&
2448 (!(status & E1000_STATUS_LU)) &&
2449 (!(rxcw & E1000_RXCW_C))) {
2450 if(hw->autoneg_failed == 0) {
2451 hw->autoneg_failed = 1;
2454 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2456 /* Disable auto-negotiation in the TXCW register */
2457 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2459 /* Force link-up and also force full-duplex. */
2460 ctrl = E1000_READ_REG(hw, CTRL);
2461 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2462 E1000_WRITE_REG(hw, CTRL, ctrl);
2464 /* Configure Flow Control after forcing link up. */
2465 ret_val = e1000_config_fc_after_link_up(hw);
2467 DEBUGOUT("Error configuring flow control\n");
2471 /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2472 * auto-negotiation in the TXCW register and disable forced link in the
2473 * Device Control register in an attempt to auto-negotiate with our link
2476 else if(((hw->media_type == e1000_media_type_fiber) ||
2477 (hw->media_type == e1000_media_type_internal_serdes)) &&
2478 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
2479 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2480 E1000_WRITE_REG(hw, TXCW, hw->txcw);
2481 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2483 hw->serdes_link_down = FALSE;
2485 /* If we force link for non-auto-negotiation switch, check link status
2486 * based on MAC synchronization for internal serdes media type.
2488 else if((hw->media_type == e1000_media_type_internal_serdes) &&
2489 !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2490 /* SYNCH bit and IV bit are sticky. */
2492 if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2493 if(!(rxcw & E1000_RXCW_IV)) {
2494 hw->serdes_link_down = FALSE;
2495 DEBUGOUT("SERDES: Link is up.\n");
2498 hw->serdes_link_down = TRUE;
2499 DEBUGOUT("SERDES: Link is down.\n");
2502 if((hw->media_type == e1000_media_type_internal_serdes) &&
2503 (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2504 hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2506 return E1000_SUCCESS;
2509 /******************************************************************************
2510 * Detects the current speed and duplex settings of the hardware.
2512 * hw - Struct containing variables accessed by shared code
2513 * speed - Speed of the connection
2514 * duplex - Duplex setting of the connection
2515 *****************************************************************************/
2517 e1000_get_speed_and_duplex(struct e1000_hw *hw,
2525 DEBUGFUNC("e1000_get_speed_and_duplex");
2527 if(hw->mac_type >= e1000_82543) {
2528 status = E1000_READ_REG(hw, STATUS);
2529 if(status & E1000_STATUS_SPEED_1000) {
2530 *speed = SPEED_1000;
2531 DEBUGOUT("1000 Mbs, ");
2532 } else if(status & E1000_STATUS_SPEED_100) {
2534 DEBUGOUT("100 Mbs, ");
2537 DEBUGOUT("10 Mbs, ");
2540 if(status & E1000_STATUS_FD) {
2541 *duplex = FULL_DUPLEX;
2542 DEBUGOUT("Full Duplex\r\n");
2544 *duplex = HALF_DUPLEX;
2545 DEBUGOUT(" Half Duplex\r\n");
2548 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2549 *speed = SPEED_1000;
2550 *duplex = FULL_DUPLEX;
2553 /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2554 * if it is operating at half duplex. Here we set the duplex settings to
2555 * match the duplex in the link partner's capabilities.
2557 if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2558 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
2562 if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2563 *duplex = HALF_DUPLEX;
2565 ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
2568 if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2569 (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2570 *duplex = HALF_DUPLEX;
2574 return E1000_SUCCESS;
2577 /******************************************************************************
2578 * Blocks until autoneg completes or times out (~4.5 seconds)
2580 * hw - Struct containing variables accessed by shared code
2581 ******************************************************************************/
2583 e1000_wait_autoneg(struct e1000_hw *hw)
2589 DEBUGFUNC("e1000_wait_autoneg");
2590 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2592 /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2593 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2594 /* Read the MII Status Register and wait for Auto-Neg
2595 * Complete bit to be set.
2597 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2600 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
2603 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2604 return E1000_SUCCESS;
2608 return E1000_SUCCESS;
2611 /******************************************************************************
2612 * Raises the Management Data Clock
2614 * hw - Struct containing variables accessed by shared code
2615 * ctrl - Device control register's current value
2616 ******************************************************************************/
2618 e1000_raise_mdi_clk(struct e1000_hw *hw,
2621 /* Raise the clock input to the Management Data Clock (by setting the MDC
2622 * bit), and then delay 10 microseconds.
2624 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2625 E1000_WRITE_FLUSH(hw);
2629 /******************************************************************************
2630 * Lowers the Management Data Clock
2632 * hw - Struct containing variables accessed by shared code
2633 * ctrl - Device control register's current value
2634 ******************************************************************************/
2636 e1000_lower_mdi_clk(struct e1000_hw *hw,
2639 /* Lower the clock input to the Management Data Clock (by clearing the MDC
2640 * bit), and then delay 10 microseconds.
2642 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2643 E1000_WRITE_FLUSH(hw);
2647 /******************************************************************************
2648 * Shifts data bits out to the PHY
2650 * hw - Struct containing variables accessed by shared code
2651 * data - Data to send out to the PHY
2652 * count - Number of bits to shift out
2654 * Bits are shifted out in MSB to LSB order.
2655 ******************************************************************************/
2657 e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2664 /* We need to shift "count" number of bits out to the PHY. So, the value
2665 * in the "data" parameter will be shifted out to the PHY one bit at a
2666 * time. In order to do this, "data" must be broken down into bits.
2669 mask <<= (count - 1);
2671 ctrl = E1000_READ_REG(hw, CTRL);
2673 /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2674 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2677 /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2678 * then raising and lowering the Management Data Clock. A "0" is
2679 * shifted out to the PHY by setting the MDIO bit to "0" and then
2680 * raising and lowering the clock.
2682 if(data & mask) ctrl |= E1000_CTRL_MDIO;
2683 else ctrl &= ~E1000_CTRL_MDIO;
2685 E1000_WRITE_REG(hw, CTRL, ctrl);
2686 E1000_WRITE_FLUSH(hw);
2690 e1000_raise_mdi_clk(hw, &ctrl);
2691 e1000_lower_mdi_clk(hw, &ctrl);
2697 /******************************************************************************
2698 * Shifts data bits in from the PHY
2700 * hw - Struct containing variables accessed by shared code
2702 * Bits are shifted in in MSB to LSB order.
2703 ******************************************************************************/
2705 e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2711 /* In order to read a register from the PHY, we need to shift in a total
2712 * of 18 bits from the PHY. The first two bit (turnaround) times are used
2713 * to avoid contention on the MDIO pin when a read operation is performed.
2714 * These two bits are ignored by us and thrown away. Bits are "shifted in"
2715 * by raising the input to the Management Data Clock (setting the MDC bit),
2716 * and then reading the value of the MDIO bit.
2718 ctrl = E1000_READ_REG(hw, CTRL);
2720 /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2721 ctrl &= ~E1000_CTRL_MDIO_DIR;
2722 ctrl &= ~E1000_CTRL_MDIO;
2724 E1000_WRITE_REG(hw, CTRL, ctrl);
2725 E1000_WRITE_FLUSH(hw);
2727 /* Raise and Lower the clock before reading in the data. This accounts for
2728 * the turnaround bits. The first clock occurred when we clocked out the
2729 * last bit of the Register Address.
2731 e1000_raise_mdi_clk(hw, &ctrl);
2732 e1000_lower_mdi_clk(hw, &ctrl);
2734 for(data = 0, i = 0; i < 16; i++) {
2736 e1000_raise_mdi_clk(hw, &ctrl);
2737 ctrl = E1000_READ_REG(hw, CTRL);
2738 /* Check to see if we shifted in a "1". */
2739 if(ctrl & E1000_CTRL_MDIO) data |= 1;
2740 e1000_lower_mdi_clk(hw, &ctrl);
2743 e1000_raise_mdi_clk(hw, &ctrl);
2744 e1000_lower_mdi_clk(hw, &ctrl);
2749 /*****************************************************************************
2750 * Reads the value from a PHY register, if the value is on a specific non zero
2751 * page, sets the page first.
2752 * hw - Struct containing variables accessed by shared code
2753 * reg_addr - address of the PHY register to read
2754 ******************************************************************************/
2756 e1000_read_phy_reg(struct e1000_hw *hw,
2762 DEBUGFUNC("e1000_read_phy_reg");
2764 if((hw->phy_type == e1000_phy_igp ||
2765 hw->phy_type == e1000_phy_igp_2) &&
2766 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2767 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2768 (uint16_t)reg_addr);
2774 ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2781 e1000_read_phy_reg_ex(struct e1000_hw *hw,
2787 const uint32_t phy_addr = 1;
2789 DEBUGFUNC("e1000_read_phy_reg_ex");
2791 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2792 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2793 return -E1000_ERR_PARAM;
2796 if(hw->mac_type > e1000_82543) {
2797 /* Set up Op-code, Phy Address, and register address in the MDI
2798 * Control register. The MAC will take care of interfacing with the
2799 * PHY to retrieve the desired data.
2801 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2802 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2803 (E1000_MDIC_OP_READ));
2805 E1000_WRITE_REG(hw, MDIC, mdic);
2807 /* Poll the ready bit to see if the MDI read completed */
2808 for(i = 0; i < 64; i++) {
2810 mdic = E1000_READ_REG(hw, MDIC);
2811 if(mdic & E1000_MDIC_READY) break;
2813 if(!(mdic & E1000_MDIC_READY)) {
2814 DEBUGOUT("MDI Read did not complete\n");
2815 return -E1000_ERR_PHY;
2817 if(mdic & E1000_MDIC_ERROR) {
2818 DEBUGOUT("MDI Error\n");
2819 return -E1000_ERR_PHY;
2821 *phy_data = (uint16_t) mdic;
2823 /* We must first send a preamble through the MDIO pin to signal the
2824 * beginning of an MII instruction. This is done by sending 32
2825 * consecutive "1" bits.
2827 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2829 /* Now combine the next few fields that are required for a read
2830 * operation. We use this method instead of calling the
2831 * e1000_shift_out_mdi_bits routine five different times. The format of
2832 * a MII read instruction consists of a shift out of 14 bits and is
2833 * defined as follows:
2834 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2835 * followed by a shift in of 18 bits. This first two bits shifted in
2836 * are TurnAround bits used to avoid contention on the MDIO pin when a
2837 * READ operation is performed. These two bits are thrown away
2838 * followed by a shift in of 16 bits which contains the desired data.
2840 mdic = ((reg_addr) | (phy_addr << 5) |
2841 (PHY_OP_READ << 10) | (PHY_SOF << 12));
2843 e1000_shift_out_mdi_bits(hw, mdic, 14);
2845 /* Now that we've shifted out the read command to the MII, we need to
2846 * "shift in" the 16-bit value (18 total bits) of the requested PHY
2849 *phy_data = e1000_shift_in_mdi_bits(hw);
2851 return E1000_SUCCESS;
2854 /******************************************************************************
2855 * Writes a value to a PHY register
2857 * hw - Struct containing variables accessed by shared code
2858 * reg_addr - address of the PHY register to write
2859 * data - data to write to the PHY
2860 ******************************************************************************/
2862 e1000_write_phy_reg(struct e1000_hw *hw,
2868 DEBUGFUNC("e1000_write_phy_reg");
2870 if((hw->phy_type == e1000_phy_igp ||
2871 hw->phy_type == e1000_phy_igp_2) &&
2872 (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2873 ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2874 (uint16_t)reg_addr);
2880 ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
2887 e1000_write_phy_reg_ex(struct e1000_hw *hw,
2893 const uint32_t phy_addr = 1;
2895 DEBUGFUNC("e1000_write_phy_reg_ex");
2897 if(reg_addr > MAX_PHY_REG_ADDRESS) {
2898 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2899 return -E1000_ERR_PARAM;
2902 if(hw->mac_type > e1000_82543) {
2903 /* Set up Op-code, Phy Address, register address, and data intended
2904 * for the PHY register in the MDI Control register. The MAC will take
2905 * care of interfacing with the PHY to send the desired data.
2907 mdic = (((uint32_t) phy_data) |
2908 (reg_addr << E1000_MDIC_REG_SHIFT) |
2909 (phy_addr << E1000_MDIC_PHY_SHIFT) |
2910 (E1000_MDIC_OP_WRITE));
2912 E1000_WRITE_REG(hw, MDIC, mdic);
2914 /* Poll the ready bit to see if the MDI read completed */
2915 for(i = 0; i < 640; i++) {
2917 mdic = E1000_READ_REG(hw, MDIC);
2918 if(mdic & E1000_MDIC_READY) break;
2920 if(!(mdic & E1000_MDIC_READY)) {
2921 DEBUGOUT("MDI Write did not complete\n");
2922 return -E1000_ERR_PHY;
2925 /* We'll need to use the SW defined pins to shift the write command
2926 * out to the PHY. We first send a preamble to the PHY to signal the
2927 * beginning of the MII instruction. This is done by sending 32
2928 * consecutive "1" bits.
2930 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2932 /* Now combine the remaining required fields that will indicate a
2933 * write operation. We use this method instead of calling the
2934 * e1000_shift_out_mdi_bits routine for each field in the command. The
2935 * format of a MII write instruction is as follows:
2936 * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2938 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2939 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2941 mdic |= (uint32_t) phy_data;
2943 e1000_shift_out_mdi_bits(hw, mdic, 32);
2946 return E1000_SUCCESS;
2950 /******************************************************************************
2951 * Returns the PHY to the power-on reset state
2953 * hw - Struct containing variables accessed by shared code
2954 ******************************************************************************/
2956 e1000_phy_hw_reset(struct e1000_hw *hw)
2958 uint32_t ctrl, ctrl_ext;
2962 DEBUGFUNC("e1000_phy_hw_reset");
2964 /* In the case of the phy reset being blocked, it's not an error, we
2965 * simply return success without performing the reset. */
2966 ret_val = e1000_check_phy_reset_block(hw);
2968 return E1000_SUCCESS;
2970 DEBUGOUT("Resetting Phy...\n");
2972 if(hw->mac_type > e1000_82543) {
2973 /* Read the device control register and assert the E1000_CTRL_PHY_RST
2974 * bit. Then, take it out of reset.
2975 * For pre-e1000_82571 hardware, we delay for 10ms between the assert
2976 * and deassert. For e1000_82571 hardware and later, we instead delay
2977 * for 10ms after the deassertion.
2979 ctrl = E1000_READ_REG(hw, CTRL);
2980 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2981 E1000_WRITE_FLUSH(hw);
2983 if (hw->mac_type < e1000_82571)
2986 E1000_WRITE_REG(hw, CTRL, ctrl);
2987 E1000_WRITE_FLUSH(hw);
2989 if (hw->mac_type >= e1000_82571)
2992 /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2993 * bit to put the PHY into reset. Then, take it out of reset.
2995 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2996 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2997 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2998 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2999 E1000_WRITE_FLUSH(hw);
3001 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
3002 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
3003 E1000_WRITE_FLUSH(hw);
3007 if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
3008 /* Configure activity LED after PHY reset */
3009 led_ctrl = E1000_READ_REG(hw, LEDCTL);
3010 led_ctrl &= IGP_ACTIVITY_LED_MASK;
3011 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
3012 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
3015 /* Wait for FW to finish PHY configuration. */
3016 ret_val = e1000_get_phy_cfg_done(hw);
3021 /******************************************************************************
3024 * hw - Struct containing variables accessed by shared code
3026 * Sets bit 15 of the MII Control regiser
3027 ******************************************************************************/
3029 e1000_phy_reset(struct e1000_hw *hw)
3034 DEBUGFUNC("e1000_phy_reset");
3036 /* In the case of the phy reset being blocked, it's not an error, we
3037 * simply return success without performing the reset. */
3038 ret_val = e1000_check_phy_reset_block(hw);
3040 return E1000_SUCCESS;
3042 switch (hw->mac_type) {
3043 case e1000_82541_rev_2:
3046 ret_val = e1000_phy_hw_reset(hw);
3051 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3055 phy_data |= MII_CR_RESET;
3056 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3064 if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
3065 e1000_phy_init_script(hw);
3067 return E1000_SUCCESS;
3070 /******************************************************************************
3071 * Probes the expected PHY address for known PHY IDs
3073 * hw - Struct containing variables accessed by shared code
3074 ******************************************************************************/
3076 e1000_detect_gig_phy(struct e1000_hw *hw)
3078 int32_t phy_init_status, ret_val;
3079 uint16_t phy_id_high, phy_id_low;
3080 boolean_t match = FALSE;
3082 DEBUGFUNC("e1000_detect_gig_phy");
3084 /* The 82571 firmware may still be configuring the PHY. In this
3085 * case, we cannot access the PHY until the configuration is done. So
3086 * we explicitly set the PHY values. */
3087 if(hw->mac_type == e1000_82571 ||
3088 hw->mac_type == e1000_82572) {
3089 hw->phy_id = IGP01E1000_I_PHY_ID;
3090 hw->phy_type = e1000_phy_igp_2;
3091 return E1000_SUCCESS;
3094 /* Read the PHY ID Registers to identify which PHY is onboard. */
3095 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
3099 hw->phy_id = (uint32_t) (phy_id_high << 16);
3101 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
3105 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
3106 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
3108 switch(hw->mac_type) {
3110 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
3113 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
3117 case e1000_82545_rev_3:
3119 case e1000_82546_rev_3:
3120 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
3123 case e1000_82541_rev_2:
3125 case e1000_82547_rev_2:
3126 if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
3129 if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
3132 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
3133 return -E1000_ERR_CONFIG;
3135 phy_init_status = e1000_set_phy_type(hw);
3137 if ((match) && (phy_init_status == E1000_SUCCESS)) {
3138 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
3139 return E1000_SUCCESS;
3141 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
3142 return -E1000_ERR_PHY;
3145 /******************************************************************************
3146 * Resets the PHY's DSP
3148 * hw - Struct containing variables accessed by shared code
3149 ******************************************************************************/
3151 e1000_phy_reset_dsp(struct e1000_hw *hw)
3154 DEBUGFUNC("e1000_phy_reset_dsp");
3157 ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
3159 ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
3161 ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
3163 ret_val = E1000_SUCCESS;
3169 /******************************************************************************
3170 * Get PHY information from various PHY registers for igp PHY only.
3172 * hw - Struct containing variables accessed by shared code
3173 * phy_info - PHY information structure
3174 ******************************************************************************/
3176 e1000_phy_igp_get_info(struct e1000_hw *hw,
3177 struct e1000_phy_info *phy_info)
3180 uint16_t phy_data, polarity, min_length, max_length, average;
3182 DEBUGFUNC("e1000_phy_igp_get_info");
3184 /* The downshift status is checked only once, after link is established,
3185 * and it stored in the hw->speed_downgraded parameter. */
3186 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3188 /* IGP01E1000 does not need to support it. */
3189 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
3191 /* IGP01E1000 always correct polarity reversal */
3192 phy_info->polarity_correction = e1000_polarity_reversal_enabled;
3194 /* Check polarity status */
3195 ret_val = e1000_check_polarity(hw, &polarity);
3199 phy_info->cable_polarity = polarity;
3201 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
3205 phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
3206 IGP01E1000_PSSR_MDIX_SHIFT;
3208 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
3209 IGP01E1000_PSSR_SPEED_1000MBPS) {
3210 /* Local/Remote Receiver Information are only valid at 1000 Mbps */
3211 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3215 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3216 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3217 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3218 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3220 /* Get cable length */
3221 ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
3225 /* Translate to old method */
3226 average = (max_length + min_length) / 2;
3228 if(average <= e1000_igp_cable_length_50)
3229 phy_info->cable_length = e1000_cable_length_50;
3230 else if(average <= e1000_igp_cable_length_80)
3231 phy_info->cable_length = e1000_cable_length_50_80;
3232 else if(average <= e1000_igp_cable_length_110)
3233 phy_info->cable_length = e1000_cable_length_80_110;
3234 else if(average <= e1000_igp_cable_length_140)
3235 phy_info->cable_length = e1000_cable_length_110_140;
3237 phy_info->cable_length = e1000_cable_length_140;
3240 return E1000_SUCCESS;
3243 /******************************************************************************
3244 * Get PHY information from various PHY registers fot m88 PHY only.
3246 * hw - Struct containing variables accessed by shared code
3247 * phy_info - PHY information structure
3248 ******************************************************************************/
3250 e1000_phy_m88_get_info(struct e1000_hw *hw,
3251 struct e1000_phy_info *phy_info)
3254 uint16_t phy_data, polarity;
3256 DEBUGFUNC("e1000_phy_m88_get_info");
3258 /* The downshift status is checked only once, after link is established,
3259 * and it stored in the hw->speed_downgraded parameter. */
3260 phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
3262 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3266 phy_info->extended_10bt_distance =
3267 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
3268 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
3269 phy_info->polarity_correction =
3270 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
3271 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
3273 /* Check polarity status */
3274 ret_val = e1000_check_polarity(hw, &polarity);
3277 phy_info->cable_polarity = polarity;
3279 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
3283 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
3284 M88E1000_PSSR_MDIX_SHIFT;
3286 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
3287 /* Cable Length Estimation and Local/Remote Receiver Information
3288 * are only valid at 1000 Mbps.
3290 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
3291 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
3293 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
3297 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
3298 SR_1000T_LOCAL_RX_STATUS_SHIFT;
3300 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
3301 SR_1000T_REMOTE_RX_STATUS_SHIFT;
3304 return E1000_SUCCESS;
3307 /******************************************************************************
3308 * Get PHY information from various PHY registers
3310 * hw - Struct containing variables accessed by shared code
3311 * phy_info - PHY information structure
3312 ******************************************************************************/
3314 e1000_phy_get_info(struct e1000_hw *hw,
3315 struct e1000_phy_info *phy_info)
3320 DEBUGFUNC("e1000_phy_get_info");
3322 phy_info->cable_length = e1000_cable_length_undefined;
3323 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
3324 phy_info->cable_polarity = e1000_rev_polarity_undefined;
3325 phy_info->downshift = e1000_downshift_undefined;
3326 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
3327 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
3328 phy_info->local_rx = e1000_1000t_rx_status_undefined;
3329 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
3331 if(hw->media_type != e1000_media_type_copper) {
3332 DEBUGOUT("PHY info is only valid for copper media\n");
3333 return -E1000_ERR_CONFIG;
3336 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3340 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3344 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
3345 DEBUGOUT("PHY info is only valid if link is up\n");
3346 return -E1000_ERR_CONFIG;
3349 if(hw->phy_type == e1000_phy_igp ||
3350 hw->phy_type == e1000_phy_igp_2)
3351 return e1000_phy_igp_get_info(hw, phy_info);
3353 return e1000_phy_m88_get_info(hw, phy_info);
3357 e1000_validate_mdi_setting(struct e1000_hw *hw)
3359 DEBUGFUNC("e1000_validate_mdi_settings");
3361 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
3362 DEBUGOUT("Invalid MDI setting detected\n");
3364 return -E1000_ERR_CONFIG;
3366 return E1000_SUCCESS;
3370 /******************************************************************************
3371 * Sets up eeprom variables in the hw struct. Must be called after mac_type
3374 * hw - Struct containing variables accessed by shared code
3375 *****************************************************************************/
3377 e1000_init_eeprom_params(struct e1000_hw *hw)
3379 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3380 uint32_t eecd = E1000_READ_REG(hw, EECD);
3381 int32_t ret_val = E1000_SUCCESS;
3382 uint16_t eeprom_size;
3384 DEBUGFUNC("e1000_init_eeprom_params");
3386 switch (hw->mac_type) {
3387 case e1000_82542_rev2_0:
3388 case e1000_82542_rev2_1:
3391 eeprom->type = e1000_eeprom_microwire;
3392 eeprom->word_size = 64;
3393 eeprom->opcode_bits = 3;
3394 eeprom->address_bits = 6;
3395 eeprom->delay_usec = 50;
3396 eeprom->use_eerd = FALSE;
3397 eeprom->use_eewr = FALSE;
3401 case e1000_82545_rev_3:
3403 case e1000_82546_rev_3:
3404 eeprom->type = e1000_eeprom_microwire;
3405 eeprom->opcode_bits = 3;
3406 eeprom->delay_usec = 50;
3407 if(eecd & E1000_EECD_SIZE) {
3408 eeprom->word_size = 256;
3409 eeprom->address_bits = 8;
3411 eeprom->word_size = 64;
3412 eeprom->address_bits = 6;
3414 eeprom->use_eerd = FALSE;
3415 eeprom->use_eewr = FALSE;
3418 case e1000_82541_rev_2:
3420 case e1000_82547_rev_2:
3421 if (eecd & E1000_EECD_TYPE) {
3422 eeprom->type = e1000_eeprom_spi;
3423 eeprom->opcode_bits = 8;
3424 eeprom->delay_usec = 1;
3425 if (eecd & E1000_EECD_ADDR_BITS) {
3426 eeprom->page_size = 32;
3427 eeprom->address_bits = 16;
3429 eeprom->page_size = 8;
3430 eeprom->address_bits = 8;
3433 eeprom->type = e1000_eeprom_microwire;
3434 eeprom->opcode_bits = 3;
3435 eeprom->delay_usec = 50;
3436 if (eecd & E1000_EECD_ADDR_BITS) {
3437 eeprom->word_size = 256;
3438 eeprom->address_bits = 8;
3440 eeprom->word_size = 64;
3441 eeprom->address_bits = 6;
3444 eeprom->use_eerd = FALSE;
3445 eeprom->use_eewr = FALSE;
3449 eeprom->type = e1000_eeprom_spi;
3450 eeprom->opcode_bits = 8;
3451 eeprom->delay_usec = 1;
3452 if (eecd & E1000_EECD_ADDR_BITS) {
3453 eeprom->page_size = 32;
3454 eeprom->address_bits = 16;
3456 eeprom->page_size = 8;
3457 eeprom->address_bits = 8;
3459 eeprom->use_eerd = FALSE;
3460 eeprom->use_eewr = FALSE;
3463 eeprom->type = e1000_eeprom_spi;
3464 eeprom->opcode_bits = 8;
3465 eeprom->delay_usec = 1;
3466 if (eecd & E1000_EECD_ADDR_BITS) {
3467 eeprom->page_size = 32;
3468 eeprom->address_bits = 16;
3470 eeprom->page_size = 8;
3471 eeprom->address_bits = 8;
3473 eeprom->use_eerd = TRUE;
3474 eeprom->use_eewr = TRUE;
3475 if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
3476 eeprom->type = e1000_eeprom_flash;
3477 eeprom->word_size = 2048;
3479 /* Ensure that the Autonomous FLASH update bit is cleared due to
3480 * Flash update issue on parts which use a FLASH for NVM. */
3481 eecd &= ~E1000_EECD_AUPDEN;
3482 E1000_WRITE_REG(hw, EECD, eecd);
3489 if (eeprom->type == e1000_eeprom_spi) {
3490 /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
3491 * 32KB (incremented by powers of 2).
3493 if(hw->mac_type <= e1000_82547_rev_2) {
3494 /* Set to default value for initial eeprom read. */
3495 eeprom->word_size = 64;
3496 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
3499 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
3500 /* 256B eeprom size was not supported in earlier hardware, so we
3501 * bump eeprom_size up one to ensure that "1" (which maps to 256B)
3502 * is never the result used in the shifting logic below. */
3506 eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
3507 E1000_EECD_SIZE_EX_SHIFT);
3510 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
3515 /******************************************************************************
3516 * Raises the EEPROM's clock input.
3518 * hw - Struct containing variables accessed by shared code
3519 * eecd - EECD's current value
3520 *****************************************************************************/
3522 e1000_raise_ee_clk(struct e1000_hw *hw,
3525 /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3526 * wait <delay> microseconds.
3528 *eecd = *eecd | E1000_EECD_SK;
3529 E1000_WRITE_REG(hw, EECD, *eecd);
3530 E1000_WRITE_FLUSH(hw);
3531 udelay(hw->eeprom.delay_usec);
3534 /******************************************************************************
3535 * Lowers the EEPROM's clock input.
3537 * hw - Struct containing variables accessed by shared code
3538 * eecd - EECD's current value
3539 *****************************************************************************/
3541 e1000_lower_ee_clk(struct e1000_hw *hw,
3544 /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3545 * wait 50 microseconds.
3547 *eecd = *eecd & ~E1000_EECD_SK;
3548 E1000_WRITE_REG(hw, EECD, *eecd);
3549 E1000_WRITE_FLUSH(hw);
3550 udelay(hw->eeprom.delay_usec);
3553 /******************************************************************************
3554 * Shift data bits out to the EEPROM.
3556 * hw - Struct containing variables accessed by shared code
3557 * data - data to send to the EEPROM
3558 * count - number of bits to shift out
3559 *****************************************************************************/
3561 e1000_shift_out_ee_bits(struct e1000_hw *hw,
3565 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3569 /* We need to shift "count" bits out to the EEPROM. So, value in the
3570 * "data" parameter will be shifted out to the EEPROM one bit at a time.
3571 * In order to do this, "data" must be broken down into bits.
3573 mask = 0x01 << (count - 1);
3574 eecd = E1000_READ_REG(hw, EECD);
3575 if (eeprom->type == e1000_eeprom_microwire) {
3576 eecd &= ~E1000_EECD_DO;
3577 } else if (eeprom->type == e1000_eeprom_spi) {
3578 eecd |= E1000_EECD_DO;
3581 /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3582 * and then raising and then lowering the clock (the SK bit controls
3583 * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
3584 * by setting "DI" to "0" and then raising and then lowering the clock.
3586 eecd &= ~E1000_EECD_DI;
3589 eecd |= E1000_EECD_DI;
3591 E1000_WRITE_REG(hw, EECD, eecd);
3592 E1000_WRITE_FLUSH(hw);
3594 udelay(eeprom->delay_usec);
3596 e1000_raise_ee_clk(hw, &eecd);
3597 e1000_lower_ee_clk(hw, &eecd);
3603 /* We leave the "DI" bit set to "0" when we leave this routine. */
3604 eecd &= ~E1000_EECD_DI;
3605 E1000_WRITE_REG(hw, EECD, eecd);
3608 /******************************************************************************
3609 * Shift data bits in from the EEPROM
3611 * hw - Struct containing variables accessed by shared code
3612 *****************************************************************************/
3614 e1000_shift_in_ee_bits(struct e1000_hw *hw,
3621 /* In order to read a register from the EEPROM, we need to shift 'count'
3622 * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3623 * input to the EEPROM (setting the SK bit), and then reading the value of
3624 * the "DO" bit. During this "shifting in" process the "DI" bit should
3628 eecd = E1000_READ_REG(hw, EECD);
3630 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3633 for(i = 0; i < count; i++) {
3635 e1000_raise_ee_clk(hw, &eecd);
3637 eecd = E1000_READ_REG(hw, EECD);
3639 eecd &= ~(E1000_EECD_DI);
3640 if(eecd & E1000_EECD_DO)
3643 e1000_lower_ee_clk(hw, &eecd);
3649 /******************************************************************************
3650 * Prepares EEPROM for access
3652 * hw - Struct containing variables accessed by shared code
3654 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3655 * function should be called before issuing a command to the EEPROM.
3656 *****************************************************************************/
3658 e1000_acquire_eeprom(struct e1000_hw *hw)
3660 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3663 DEBUGFUNC("e1000_acquire_eeprom");
3665 if(e1000_get_hw_eeprom_semaphore(hw))
3666 return -E1000_ERR_EEPROM;
3668 eecd = E1000_READ_REG(hw, EECD);
3670 if (hw->mac_type != e1000_82573) {
3671 /* Request EEPROM Access */
3672 if(hw->mac_type > e1000_82544) {
3673 eecd |= E1000_EECD_REQ;
3674 E1000_WRITE_REG(hw, EECD, eecd);
3675 eecd = E1000_READ_REG(hw, EECD);
3676 while((!(eecd & E1000_EECD_GNT)) &&
3677 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3680 eecd = E1000_READ_REG(hw, EECD);
3682 if(!(eecd & E1000_EECD_GNT)) {
3683 eecd &= ~E1000_EECD_REQ;
3684 E1000_WRITE_REG(hw, EECD, eecd);
3685 DEBUGOUT("Could not acquire EEPROM grant\n");
3686 e1000_put_hw_eeprom_semaphore(hw);
3687 return -E1000_ERR_EEPROM;
3692 /* Setup EEPROM for Read/Write */
3694 if (eeprom->type == e1000_eeprom_microwire) {
3695 /* Clear SK and DI */
3696 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3697 E1000_WRITE_REG(hw, EECD, eecd);
3700 eecd |= E1000_EECD_CS;
3701 E1000_WRITE_REG(hw, EECD, eecd);
3702 } else if (eeprom->type == e1000_eeprom_spi) {
3703 /* Clear SK and CS */
3704 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3705 E1000_WRITE_REG(hw, EECD, eecd);
3709 return E1000_SUCCESS;
3712 /******************************************************************************
3713 * Returns EEPROM to a "standby" state
3715 * hw - Struct containing variables accessed by shared code
3716 *****************************************************************************/
3718 e1000_standby_eeprom(struct e1000_hw *hw)
3720 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3723 eecd = E1000_READ_REG(hw, EECD);
3725 if(eeprom->type == e1000_eeprom_microwire) {
3726 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3727 E1000_WRITE_REG(hw, EECD, eecd);
3728 E1000_WRITE_FLUSH(hw);
3729 udelay(eeprom->delay_usec);
3732 eecd |= E1000_EECD_SK;
3733 E1000_WRITE_REG(hw, EECD, eecd);
3734 E1000_WRITE_FLUSH(hw);
3735 udelay(eeprom->delay_usec);
3738 eecd |= E1000_EECD_CS;
3739 E1000_WRITE_REG(hw, EECD, eecd);
3740 E1000_WRITE_FLUSH(hw);
3741 udelay(eeprom->delay_usec);
3744 eecd &= ~E1000_EECD_SK;
3745 E1000_WRITE_REG(hw, EECD, eecd);
3746 E1000_WRITE_FLUSH(hw);
3747 udelay(eeprom->delay_usec);
3748 } else if(eeprom->type == e1000_eeprom_spi) {
3749 /* Toggle CS to flush commands */
3750 eecd |= E1000_EECD_CS;
3751 E1000_WRITE_REG(hw, EECD, eecd);
3752 E1000_WRITE_FLUSH(hw);
3753 udelay(eeprom->delay_usec);
3754 eecd &= ~E1000_EECD_CS;
3755 E1000_WRITE_REG(hw, EECD, eecd);
3756 E1000_WRITE_FLUSH(hw);
3757 udelay(eeprom->delay_usec);
3761 /******************************************************************************
3762 * Terminates a command by inverting the EEPROM's chip select pin
3764 * hw - Struct containing variables accessed by shared code
3765 *****************************************************************************/
3767 e1000_release_eeprom(struct e1000_hw *hw)
3771 DEBUGFUNC("e1000_release_eeprom");
3773 eecd = E1000_READ_REG(hw, EECD);
3775 if (hw->eeprom.type == e1000_eeprom_spi) {
3776 eecd |= E1000_EECD_CS; /* Pull CS high */
3777 eecd &= ~E1000_EECD_SK; /* Lower SCK */
3779 E1000_WRITE_REG(hw, EECD, eecd);
3781 udelay(hw->eeprom.delay_usec);
3782 } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3783 /* cleanup eeprom */
3785 /* CS on Microwire is active-high */
3786 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3788 E1000_WRITE_REG(hw, EECD, eecd);
3790 /* Rising edge of clock */
3791 eecd |= E1000_EECD_SK;
3792 E1000_WRITE_REG(hw, EECD, eecd);
3793 E1000_WRITE_FLUSH(hw);
3794 udelay(hw->eeprom.delay_usec);
3796 /* Falling edge of clock */
3797 eecd &= ~E1000_EECD_SK;
3798 E1000_WRITE_REG(hw, EECD, eecd);
3799 E1000_WRITE_FLUSH(hw);
3800 udelay(hw->eeprom.delay_usec);
3803 /* Stop requesting EEPROM access */
3804 if(hw->mac_type > e1000_82544) {
3805 eecd &= ~E1000_EECD_REQ;
3806 E1000_WRITE_REG(hw, EECD, eecd);
3809 e1000_put_hw_eeprom_semaphore(hw);
3812 /******************************************************************************
3813 * Reads a 16 bit word from the EEPROM.
3815 * hw - Struct containing variables accessed by shared code
3816 *****************************************************************************/
3818 e1000_spi_eeprom_ready(struct e1000_hw *hw)
3820 uint16_t retry_count = 0;
3821 uint8_t spi_stat_reg;
3823 DEBUGFUNC("e1000_spi_eeprom_ready");
3825 /* Read "Status Register" repeatedly until the LSB is cleared. The
3826 * EEPROM will signal that the command has been completed by clearing
3827 * bit 0 of the internal status register. If it's not cleared within
3828 * 5 milliseconds, then error out.
3832 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3833 hw->eeprom.opcode_bits);
3834 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3835 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3841 e1000_standby_eeprom(hw);
3842 } while(retry_count < EEPROM_MAX_RETRY_SPI);
3844 /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3845 * only 0-5mSec on 5V devices)
3847 if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3848 DEBUGOUT("SPI EEPROM Status error\n");
3849 return -E1000_ERR_EEPROM;
3852 return E1000_SUCCESS;
3855 /******************************************************************************
3856 * Reads a 16 bit word from the EEPROM.
3858 * hw - Struct containing variables accessed by shared code
3859 * offset - offset of word in the EEPROM to read
3860 * data - word read from the EEPROM
3861 * words - number of words to read
3862 *****************************************************************************/
3864 e1000_read_eeprom(struct e1000_hw *hw,
3869 struct e1000_eeprom_info *eeprom = &hw->eeprom;
3873 DEBUGFUNC("e1000_read_eeprom");
3875 /* A check for invalid values: offset too large, too many words, and not
3878 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
3880 DEBUGOUT("\"words\" parameter out of bounds\n");
3881 return -E1000_ERR_EEPROM;
3884 /* FLASH reads without acquiring the semaphore are safe in 82573-based
3887 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3888 (hw->mac_type != e1000_82573)) {
3889 /* Prepare the EEPROM for reading */
3890 if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3891 return -E1000_ERR_EEPROM;
3894 if(eeprom->use_eerd == TRUE) {
3895 ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
3896 if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
3897 (hw->mac_type != e1000_82573))
3898 e1000_release_eeprom(hw);
3902 if(eeprom->type == e1000_eeprom_spi) {
3904 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3906 if(e1000_spi_eeprom_ready(hw)) {
3907 e1000_release_eeprom(hw);
3908 return -E1000_ERR_EEPROM;
3911 e1000_standby_eeprom(hw);
3913 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3914 if((eeprom->address_bits == 8) && (offset >= 128))
3915 read_opcode |= EEPROM_A8_OPCODE_SPI;
3917 /* Send the READ command (opcode + addr) */
3918 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3919 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3921 /* Read the data. The address of the eeprom internally increments with
3922 * each byte (spi) being read, saving on the overhead of eeprom setup
3923 * and tear-down. The address counter will roll over if reading beyond
3924 * the size of the eeprom, thus allowing the entire memory to be read
3925 * starting from any offset. */
3926 for (i = 0; i < words; i++) {
3927 word_in = e1000_shift_in_ee_bits(hw, 16);
3928 data[i] = (word_in >> 8) | (word_in << 8);
3930 } else if(eeprom->type == e1000_eeprom_microwire) {
3931 for (i = 0; i < words; i++) {
3932 /* Send the READ command (opcode + addr) */
3933 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3934 eeprom->opcode_bits);
3935 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3936 eeprom->address_bits);
3938 /* Read the data. For microwire, each word requires the overhead
3939 * of eeprom setup and tear-down. */
3940 data[i] = e1000_shift_in_ee_bits(hw, 16);
3941 e1000_standby_eeprom(hw);
3945 /* End this read operation */
3946 e1000_release_eeprom(hw);
3948 return E1000_SUCCESS;
3951 /******************************************************************************
3952 * Reads a 16 bit word from the EEPROM using the EERD register.
3954 * hw - Struct containing variables accessed by shared code
3955 * offset - offset of word in the EEPROM to read
3956 * data - word read from the EEPROM
3957 * words - number of words to read
3958 *****************************************************************************/
3960 e1000_read_eeprom_eerd(struct e1000_hw *hw,
3965 uint32_t i, eerd = 0;
3968 for (i = 0; i < words; i++) {
3969 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
3970 E1000_EEPROM_RW_REG_START;
3972 E1000_WRITE_REG(hw, EERD, eerd);
3973 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
3978 data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
3985 /******************************************************************************
3986 * Writes a 16 bit word from the EEPROM using the EEWR register.
3988 * hw - Struct containing variables accessed by shared code
3989 * offset - offset of word in the EEPROM to read
3990 * data - word read from the EEPROM
3991 * words - number of words to read
3992 *****************************************************************************/
3994 e1000_write_eeprom_eewr(struct e1000_hw *hw,
3999 uint32_t register_value = 0;
4003 for (i = 0; i < words; i++) {
4004 register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
4005 ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
4006 E1000_EEPROM_RW_REG_START;
4008 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4013 E1000_WRITE_REG(hw, EEWR, register_value);
4015 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
4025 /******************************************************************************
4026 * Polls the status bit (bit 1) of the EERD to determine when the read is done.
4028 * hw - Struct containing variables accessed by shared code
4029 *****************************************************************************/
4031 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
4033 uint32_t attempts = 100000;
4034 uint32_t i, reg = 0;
4035 int32_t done = E1000_ERR_EEPROM;
4037 for(i = 0; i < attempts; i++) {
4038 if(eerd == E1000_EEPROM_POLL_READ)
4039 reg = E1000_READ_REG(hw, EERD);
4041 reg = E1000_READ_REG(hw, EEWR);
4043 if(reg & E1000_EEPROM_RW_REG_DONE) {
4044 done = E1000_SUCCESS;
4053 /***************************************************************************
4054 * Description: Determines if the onboard NVM is FLASH or EEPROM.
4056 * hw - Struct containing variables accessed by shared code
4057 ****************************************************************************/
4059 e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
4063 if(hw->mac_type == e1000_82573) {
4064 eecd = E1000_READ_REG(hw, EECD);
4066 /* Isolate bits 15 & 16 */
4067 eecd = ((eecd >> 15) & 0x03);
4069 /* If both bits are set, device is Flash type */
4077 /******************************************************************************
4078 * Verifies that the EEPROM has a valid checksum
4080 * hw - Struct containing variables accessed by shared code
4082 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
4083 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
4085 *****************************************************************************/
4087 e1000_validate_eeprom_checksum(struct e1000_hw *hw)
4089 uint16_t checksum = 0;
4090 uint16_t i, eeprom_data;
4092 DEBUGFUNC("e1000_validate_eeprom_checksum");
4094 if ((hw->mac_type == e1000_82573) &&
4095 (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
4096 /* Check bit 4 of word 10h. If it is 0, firmware is done updating
4097 * 10h-12h. Checksum may need to be fixed. */
4098 e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
4099 if ((eeprom_data & 0x10) == 0) {
4100 /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
4101 * has already been fixed. If the checksum is still wrong and this
4102 * bit is a 1, we need to return bad checksum. Otherwise, we need
4103 * to set this bit to a 1 and update the checksum. */
4104 e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
4105 if ((eeprom_data & 0x8000) == 0) {
4106 eeprom_data |= 0x8000;
4107 e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
4108 e1000_update_eeprom_checksum(hw);
4113 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
4114 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4115 DEBUGOUT("EEPROM Read Error\n");
4116 return -E1000_ERR_EEPROM;
4118 checksum += eeprom_data;
4121 if(checksum == (uint16_t) EEPROM_SUM)
4122 return E1000_SUCCESS;
4124 DEBUGOUT("EEPROM Checksum Invalid\n");
4125 return -E1000_ERR_EEPROM;
4129 /******************************************************************************
4130 * Calculates the EEPROM checksum and writes it to the EEPROM
4132 * hw - Struct containing variables accessed by shared code
4134 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
4135 * Writes the difference to word offset 63 of the EEPROM.
4136 *****************************************************************************/
4138 e1000_update_eeprom_checksum(struct e1000_hw *hw)
4140 uint16_t checksum = 0;
4141 uint16_t i, eeprom_data;
4143 DEBUGFUNC("e1000_update_eeprom_checksum");
4145 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
4146 if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
4147 DEBUGOUT("EEPROM Read Error\n");
4148 return -E1000_ERR_EEPROM;
4150 checksum += eeprom_data;
4152 checksum = (uint16_t) EEPROM_SUM - checksum;
4153 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
4154 DEBUGOUT("EEPROM Write Error\n");
4155 return -E1000_ERR_EEPROM;
4156 } else if (hw->eeprom.type == e1000_eeprom_flash) {
4157 e1000_commit_shadow_ram(hw);
4159 return E1000_SUCCESS;
4162 /******************************************************************************
4163 * Parent function for writing words to the different EEPROM types.
4165 * hw - Struct containing variables accessed by shared code
4166 * offset - offset within the EEPROM to be written to
4167 * words - number of words to write
4168 * data - 16 bit word to be written to the EEPROM
4170 * If e1000_update_eeprom_checksum is not called after this function, the
4171 * EEPROM will most likely contain an invalid checksum.
4172 *****************************************************************************/
4174 e1000_write_eeprom(struct e1000_hw *hw,
4179 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4182 DEBUGFUNC("e1000_write_eeprom");
4184 /* A check for invalid values: offset too large, too many words, and not
4187 if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
4189 DEBUGOUT("\"words\" parameter out of bounds\n");
4190 return -E1000_ERR_EEPROM;
4193 /* 82573 writes only through eewr */
4194 if(eeprom->use_eewr == TRUE)
4195 return e1000_write_eeprom_eewr(hw, offset, words, data);
4197 /* Prepare the EEPROM for writing */
4198 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
4199 return -E1000_ERR_EEPROM;
4201 if(eeprom->type == e1000_eeprom_microwire) {
4202 status = e1000_write_eeprom_microwire(hw, offset, words, data);
4204 status = e1000_write_eeprom_spi(hw, offset, words, data);
4208 /* Done with writing */
4209 e1000_release_eeprom(hw);
4214 /******************************************************************************
4215 * Writes a 16 bit word to a given offset in an SPI EEPROM.
4217 * hw - Struct containing variables accessed by shared code
4218 * offset - offset within the EEPROM to be written to
4219 * words - number of words to write
4220 * data - pointer to array of 8 bit words to be written to the EEPROM
4222 *****************************************************************************/
4224 e1000_write_eeprom_spi(struct e1000_hw *hw,
4229 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4232 DEBUGFUNC("e1000_write_eeprom_spi");
4234 while (widx < words) {
4235 uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
4237 if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
4239 e1000_standby_eeprom(hw);
4241 /* Send the WRITE ENABLE command (8 bit opcode ) */
4242 e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
4243 eeprom->opcode_bits);
4245 e1000_standby_eeprom(hw);
4247 /* Some SPI eeproms use the 8th address bit embedded in the opcode */
4248 if((eeprom->address_bits == 8) && (offset >= 128))
4249 write_opcode |= EEPROM_A8_OPCODE_SPI;
4251 /* Send the Write command (8-bit opcode + addr) */
4252 e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
4254 e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
4255 eeprom->address_bits);
4259 /* Loop to allow for up to whole page write (32 bytes) of eeprom */
4260 while (widx < words) {
4261 uint16_t word_out = data[widx];
4262 word_out = (word_out >> 8) | (word_out << 8);
4263 e1000_shift_out_ee_bits(hw, word_out, 16);
4266 /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
4267 * operation, while the smaller eeproms are capable of an 8-byte
4268 * PAGE WRITE operation. Break the inner loop to pass new address
4270 if((((offset + widx)*2) % eeprom->page_size) == 0) {
4271 e1000_standby_eeprom(hw);
4277 return E1000_SUCCESS;
4280 /******************************************************************************
4281 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
4283 * hw - Struct containing variables accessed by shared code
4284 * offset - offset within the EEPROM to be written to
4285 * words - number of words to write
4286 * data - pointer to array of 16 bit words to be written to the EEPROM
4288 *****************************************************************************/
4290 e1000_write_eeprom_microwire(struct e1000_hw *hw,
4295 struct e1000_eeprom_info *eeprom = &hw->eeprom;
4297 uint16_t words_written = 0;
4300 DEBUGFUNC("e1000_write_eeprom_microwire");
4302 /* Send the write enable command to the EEPROM (3-bit opcode plus
4303 * 6/8-bit dummy address beginning with 11). It's less work to include
4304 * the 11 of the dummy address as part of the opcode than it is to shift
4305 * it over the correct number of bits for the address. This puts the
4306 * EEPROM into write/erase mode.
4308 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
4309 (uint16_t)(eeprom->opcode_bits + 2));
4311 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4313 /* Prepare the EEPROM */
4314 e1000_standby_eeprom(hw);
4316 while (words_written < words) {
4317 /* Send the Write command (3-bit opcode + addr) */
4318 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
4319 eeprom->opcode_bits);
4321 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
4322 eeprom->address_bits);
4325 e1000_shift_out_ee_bits(hw, data[words_written], 16);
4327 /* Toggle the CS line. This in effect tells the EEPROM to execute
4328 * the previous command.
4330 e1000_standby_eeprom(hw);
4332 /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
4333 * signal that the command has been completed by raising the DO signal.
4334 * If DO does not go high in 10 milliseconds, then error out.
4336 for(i = 0; i < 200; i++) {
4337 eecd = E1000_READ_REG(hw, EECD);
4338 if(eecd & E1000_EECD_DO) break;
4342 DEBUGOUT("EEPROM Write did not complete\n");
4343 return -E1000_ERR_EEPROM;
4346 /* Recover from write */
4347 e1000_standby_eeprom(hw);
4352 /* Send the write disable command to the EEPROM (3-bit opcode plus
4353 * 6/8-bit dummy address beginning with 10). It's less work to include
4354 * the 10 of the dummy address as part of the opcode than it is to shift
4355 * it over the correct number of bits for the address. This takes the
4356 * EEPROM out of write/erase mode.
4358 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
4359 (uint16_t)(eeprom->opcode_bits + 2));
4361 e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
4363 return E1000_SUCCESS;
4366 /******************************************************************************
4367 * Flushes the cached eeprom to NVM. This is done by saving the modified values
4368 * in the eeprom cache and the non modified values in the currently active bank
4371 * hw - Struct containing variables accessed by shared code
4372 * offset - offset of word in the EEPROM to read
4373 * data - word read from the EEPROM
4374 * words - number of words to read
4375 *****************************************************************************/
4377 e1000_commit_shadow_ram(struct e1000_hw *hw)
4379 uint32_t attempts = 100000;
4383 int32_t error = E1000_SUCCESS;
4385 /* The flop register will be used to determine if flash type is STM */
4386 flop = E1000_READ_REG(hw, FLOP);
4388 if (hw->mac_type == e1000_82573) {
4389 for (i=0; i < attempts; i++) {
4390 eecd = E1000_READ_REG(hw, EECD);
4391 if ((eecd & E1000_EECD_FLUPD) == 0) {
4397 if (i == attempts) {
4398 return -E1000_ERR_EEPROM;
4401 /* If STM opcode located in bits 15:8 of flop, reset firmware */
4402 if ((flop & 0xFF00) == E1000_STM_OPCODE) {
4403 E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
4406 /* Perform the flash update */
4407 E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
4409 for (i=0; i < attempts; i++) {
4410 eecd = E1000_READ_REG(hw, EECD);
4411 if ((eecd & E1000_EECD_FLUPD) == 0) {
4417 if (i == attempts) {
4418 return -E1000_ERR_EEPROM;
4425 /******************************************************************************
4426 * Reads the adapter's part number from the EEPROM
4428 * hw - Struct containing variables accessed by shared code
4429 * part_num - Adapter's part number
4430 *****************************************************************************/
4432 e1000_read_part_num(struct e1000_hw *hw,
4435 uint16_t offset = EEPROM_PBA_BYTE_1;
4436 uint16_t eeprom_data;
4438 DEBUGFUNC("e1000_read_part_num");
4440 /* Get word 0 from EEPROM */
4441 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4442 DEBUGOUT("EEPROM Read Error\n");
4443 return -E1000_ERR_EEPROM;
4445 /* Save word 0 in upper half of part_num */
4446 *part_num = (uint32_t) (eeprom_data << 16);
4448 /* Get word 1 from EEPROM */
4449 if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
4450 DEBUGOUT("EEPROM Read Error\n");
4451 return -E1000_ERR_EEPROM;
4453 /* Save word 1 in lower half of part_num */
4454 *part_num |= eeprom_data;
4456 return E1000_SUCCESS;
4459 /******************************************************************************
4460 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
4461 * second function of dual function devices
4463 * hw - Struct containing variables accessed by shared code
4464 *****************************************************************************/
4466 e1000_read_mac_addr(struct e1000_hw * hw)
4469 uint16_t eeprom_data, i;
4471 DEBUGFUNC("e1000_read_mac_addr");
4473 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
4475 if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
4476 DEBUGOUT("EEPROM Read Error\n");
4477 return -E1000_ERR_EEPROM;
4479 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
4480 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
4482 switch (hw->mac_type) {
4486 case e1000_82546_rev_3:
4488 if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
4489 hw->perm_mac_addr[5] ^= 0x01;
4493 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
4494 hw->mac_addr[i] = hw->perm_mac_addr[i];
4495 return E1000_SUCCESS;
4498 /******************************************************************************
4499 * Initializes receive address filters.
4501 * hw - Struct containing variables accessed by shared code
4503 * Places the MAC address in receive address register 0 and clears the rest
4504 * of the receive addresss registers. Clears the multicast table. Assumes
4505 * the receiver is in reset when the routine is called.
4506 *****************************************************************************/
4508 e1000_init_rx_addrs(struct e1000_hw *hw)
4513 DEBUGFUNC("e1000_init_rx_addrs");
4515 /* Setup the receive address. */
4516 DEBUGOUT("Programming MAC Address into RAR[0]\n");
4518 e1000_rar_set(hw, hw->mac_addr, 0);
4520 rar_num = E1000_RAR_ENTRIES;
4522 /* Reserve a spot for the Locally Administered Address to work around
4523 * an 82571 issue in which a reset on one port will reload the MAC on
4524 * the other port. */
4525 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
4527 /* Zero out the other 15 receive addresses. */
4528 DEBUGOUT("Clearing RAR[1-15]\n");
4529 for(i = 1; i < rar_num; i++) {
4530 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4531 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4536 /******************************************************************************
4537 * Updates the MAC's list of multicast addresses.
4539 * hw - Struct containing variables accessed by shared code
4540 * mc_addr_list - the list of new multicast addresses
4541 * mc_addr_count - number of addresses
4542 * pad - number of bytes between addresses in the list
4543 * rar_used_count - offset where to start adding mc addresses into the RAR's
4545 * The given list replaces any existing list. Clears the last 15 receive
4546 * address registers and the multicast table. Uses receive address registers
4547 * for the first 15 multicast addresses, and hashes the rest into the
4549 *****************************************************************************/
4551 e1000_mc_addr_list_update(struct e1000_hw *hw,
4552 uint8_t *mc_addr_list,
4553 uint32_t mc_addr_count,
4555 uint32_t rar_used_count)
4557 uint32_t hash_value;
4559 uint32_t num_rar_entry;
4560 uint32_t num_mta_entry;
4562 DEBUGFUNC("e1000_mc_addr_list_update");
4564 /* Set the new number of MC addresses that we are being requested to use. */
4565 hw->num_mc_addrs = mc_addr_count;
4567 /* Clear RAR[1-15] */
4568 DEBUGOUT(" Clearing RAR[1-15]\n");
4569 num_rar_entry = E1000_RAR_ENTRIES;
4570 /* Reserve a spot for the Locally Administered Address to work around
4571 * an 82571 issue in which a reset on one port will reload the MAC on
4572 * the other port. */
4573 if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
4576 for(i = rar_used_count; i < num_rar_entry; i++) {
4577 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
4578 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
4582 DEBUGOUT(" Clearing MTA\n");
4583 num_mta_entry = E1000_NUM_MTA_REGISTERS;
4584 for(i = 0; i < num_mta_entry; i++) {
4585 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
4588 /* Add the new addresses */
4589 for(i = 0; i < mc_addr_count; i++) {
4590 DEBUGOUT(" Adding the multicast addresses:\n");
4591 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
4592 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
4593 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
4594 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
4595 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
4596 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
4597 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
4599 hash_value = e1000_hash_mc_addr(hw,
4601 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
4603 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
4605 /* Place this multicast address in the RAR if there is room, *
4606 * else put it in the MTA
4608 if (rar_used_count < num_rar_entry) {
4610 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
4614 e1000_mta_set(hw, hash_value);
4617 DEBUGOUT("MC Update Complete\n");
4621 /******************************************************************************
4622 * Hashes an address to determine its location in the multicast table
4624 * hw - Struct containing variables accessed by shared code
4625 * mc_addr - the multicast address to hash
4626 *****************************************************************************/
4628 e1000_hash_mc_addr(struct e1000_hw *hw,
4631 uint32_t hash_value = 0;
4633 /* The portion of the address that is used for the hash table is
4634 * determined by the mc_filter_type setting.
4636 switch (hw->mc_filter_type) {
4637 /* [0] [1] [2] [3] [4] [5]
4642 /* [47:36] i.e. 0x563 for above example address */
4643 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
4646 /* [46:35] i.e. 0xAC6 for above example address */
4647 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
4650 /* [45:34] i.e. 0x5D8 for above example address */
4651 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
4654 /* [43:32] i.e. 0x634 for above example address */
4655 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
4659 hash_value &= 0xFFF;
4664 /******************************************************************************
4665 * Sets the bit in the multicast table corresponding to the hash value.
4667 * hw - Struct containing variables accessed by shared code
4668 * hash_value - Multicast address hash value
4669 *****************************************************************************/
4671 e1000_mta_set(struct e1000_hw *hw,
4672 uint32_t hash_value)
4674 uint32_t hash_bit, hash_reg;
4678 /* The MTA is a register array of 128 32-bit registers.
4679 * It is treated like an array of 4096 bits. We want to set
4680 * bit BitArray[hash_value]. So we figure out what register
4681 * the bit is in, read it, OR in the new bit, then write
4682 * back the new value. The register is determined by the
4683 * upper 7 bits of the hash value and the bit within that
4684 * register are determined by the lower 5 bits of the value.
4686 hash_reg = (hash_value >> 5) & 0x7F;
4687 hash_bit = hash_value & 0x1F;
4689 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
4691 mta |= (1 << hash_bit);
4693 /* If we are on an 82544 and we are trying to write an odd offset
4694 * in the MTA, save off the previous entry before writing and
4695 * restore the old value after writing.
4697 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
4698 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
4699 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4700 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
4702 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
4706 /******************************************************************************
4707 * Puts an ethernet address into a receive address register.
4709 * hw - Struct containing variables accessed by shared code
4710 * addr - Address to put into receive address register
4711 * index - Receive address register to write
4712 *****************************************************************************/
4714 e1000_rar_set(struct e1000_hw *hw,
4718 uint32_t rar_low, rar_high;
4720 /* HW expects these in little endian so we reverse the byte order
4721 * from network order (big endian) to little endian
4723 rar_low = ((uint32_t) addr[0] |
4724 ((uint32_t) addr[1] << 8) |
4725 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
4727 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
4729 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
4730 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
4733 /******************************************************************************
4734 * Writes a value to the specified offset in the VLAN filter table.
4736 * hw - Struct containing variables accessed by shared code
4737 * offset - Offset in VLAN filer table to write
4738 * value - Value to write into VLAN filter table
4739 *****************************************************************************/
4741 e1000_write_vfta(struct e1000_hw *hw,
4747 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4748 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4749 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4750 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4752 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4756 /******************************************************************************
4757 * Clears the VLAN filer table
4759 * hw - Struct containing variables accessed by shared code
4760 *****************************************************************************/
4762 e1000_clear_vfta(struct e1000_hw *hw)
4765 uint32_t vfta_value = 0;
4766 uint32_t vfta_offset = 0;
4767 uint32_t vfta_bit_in_reg = 0;
4769 if (hw->mac_type == e1000_82573) {
4770 if (hw->mng_cookie.vlan_id != 0) {
4771 /* The VFTA is a 4096b bit-field, each identifying a single VLAN
4772 * ID. The following operations determine which 32b entry
4773 * (i.e. offset) into the array we want to set the VLAN ID
4774 * (i.e. bit) of the manageability unit. */
4775 vfta_offset = (hw->mng_cookie.vlan_id >>
4776 E1000_VFTA_ENTRY_SHIFT) &
4777 E1000_VFTA_ENTRY_MASK;
4778 vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
4779 E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
4782 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
4783 /* If the offset we want to clear is the same offset of the
4784 * manageability VLAN ID, then clear all bits except that of the
4785 * manageability unit */
4786 vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
4787 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
4792 e1000_id_led_init(struct e1000_hw * hw)
4795 const uint32_t ledctl_mask = 0x000000FF;
4796 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4797 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4798 uint16_t eeprom_data, i, temp;
4799 const uint16_t led_mask = 0x0F;
4801 DEBUGFUNC("e1000_id_led_init");
4803 if(hw->mac_type < e1000_82540) {
4805 return E1000_SUCCESS;
4808 ledctl = E1000_READ_REG(hw, LEDCTL);
4809 hw->ledctl_default = ledctl;
4810 hw->ledctl_mode1 = hw->ledctl_default;
4811 hw->ledctl_mode2 = hw->ledctl_default;
4813 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4814 DEBUGOUT("EEPROM Read Error\n");
4815 return -E1000_ERR_EEPROM;
4817 if((eeprom_data== ID_LED_RESERVED_0000) ||
4818 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4819 for(i = 0; i < 4; i++) {
4820 temp = (eeprom_data >> (i << 2)) & led_mask;
4822 case ID_LED_ON1_DEF2:
4823 case ID_LED_ON1_ON2:
4824 case ID_LED_ON1_OFF2:
4825 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4826 hw->ledctl_mode1 |= ledctl_on << (i << 3);
4828 case ID_LED_OFF1_DEF2:
4829 case ID_LED_OFF1_ON2:
4830 case ID_LED_OFF1_OFF2:
4831 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4832 hw->ledctl_mode1 |= ledctl_off << (i << 3);
4839 case ID_LED_DEF1_ON2:
4840 case ID_LED_ON1_ON2:
4841 case ID_LED_OFF1_ON2:
4842 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4843 hw->ledctl_mode2 |= ledctl_on << (i << 3);
4845 case ID_LED_DEF1_OFF2:
4846 case ID_LED_ON1_OFF2:
4847 case ID_LED_OFF1_OFF2:
4848 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4849 hw->ledctl_mode2 |= ledctl_off << (i << 3);
4856 return E1000_SUCCESS;
4859 /******************************************************************************
4860 * Prepares SW controlable LED for use and saves the current state of the LED.
4862 * hw - Struct containing variables accessed by shared code
4863 *****************************************************************************/
4865 e1000_setup_led(struct e1000_hw *hw)
4868 int32_t ret_val = E1000_SUCCESS;
4870 DEBUGFUNC("e1000_setup_led");
4872 switch(hw->mac_type) {
4873 case e1000_82542_rev2_0:
4874 case e1000_82542_rev2_1:
4877 /* No setup necessary */
4881 case e1000_82541_rev_2:
4882 case e1000_82547_rev_2:
4883 /* Turn off PHY Smart Power Down (if enabled) */
4884 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4885 &hw->phy_spd_default);
4888 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4889 (uint16_t)(hw->phy_spd_default &
4890 ~IGP01E1000_GMII_SPD));
4895 if(hw->media_type == e1000_media_type_fiber) {
4896 ledctl = E1000_READ_REG(hw, LEDCTL);
4897 /* Save current LEDCTL settings */
4898 hw->ledctl_default = ledctl;
4900 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4901 E1000_LEDCTL_LED0_BLINK |
4902 E1000_LEDCTL_LED0_MODE_MASK);
4903 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4904 E1000_LEDCTL_LED0_MODE_SHIFT);
4905 E1000_WRITE_REG(hw, LEDCTL, ledctl);
4906 } else if(hw->media_type == e1000_media_type_copper)
4907 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4911 return E1000_SUCCESS;
4914 /******************************************************************************
4915 * Restores the saved state of the SW controlable LED.
4917 * hw - Struct containing variables accessed by shared code
4918 *****************************************************************************/
4920 e1000_cleanup_led(struct e1000_hw *hw)
4922 int32_t ret_val = E1000_SUCCESS;
4924 DEBUGFUNC("e1000_cleanup_led");
4926 switch(hw->mac_type) {
4927 case e1000_82542_rev2_0:
4928 case e1000_82542_rev2_1:
4931 /* No cleanup necessary */
4935 case e1000_82541_rev_2:
4936 case e1000_82547_rev_2:
4937 /* Turn on PHY Smart Power Down (if previously enabled) */
4938 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4939 hw->phy_spd_default);
4944 /* Restore LEDCTL settings */
4945 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4949 return E1000_SUCCESS;
4952 /******************************************************************************
4953 * Turns on the software controllable LED
4955 * hw - Struct containing variables accessed by shared code
4956 *****************************************************************************/
4958 e1000_led_on(struct e1000_hw *hw)
4960 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4962 DEBUGFUNC("e1000_led_on");
4964 switch(hw->mac_type) {
4965 case e1000_82542_rev2_0:
4966 case e1000_82542_rev2_1:
4968 /* Set SW Defineable Pin 0 to turn on the LED */
4969 ctrl |= E1000_CTRL_SWDPIN0;
4970 ctrl |= E1000_CTRL_SWDPIO0;
4973 if(hw->media_type == e1000_media_type_fiber) {
4974 /* Set SW Defineable Pin 0 to turn on the LED */
4975 ctrl |= E1000_CTRL_SWDPIN0;
4976 ctrl |= E1000_CTRL_SWDPIO0;
4978 /* Clear SW Defineable Pin 0 to turn on the LED */
4979 ctrl &= ~E1000_CTRL_SWDPIN0;
4980 ctrl |= E1000_CTRL_SWDPIO0;
4984 if(hw->media_type == e1000_media_type_fiber) {
4985 /* Clear SW Defineable Pin 0 to turn on the LED */
4986 ctrl &= ~E1000_CTRL_SWDPIN0;
4987 ctrl |= E1000_CTRL_SWDPIO0;
4988 } else if(hw->media_type == e1000_media_type_copper) {
4989 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4990 return E1000_SUCCESS;
4995 E1000_WRITE_REG(hw, CTRL, ctrl);
4997 return E1000_SUCCESS;
5000 /******************************************************************************
5001 * Turns off the software controllable LED
5003 * hw - Struct containing variables accessed by shared code
5004 *****************************************************************************/
5006 e1000_led_off(struct e1000_hw *hw)
5008 uint32_t ctrl = E1000_READ_REG(hw, CTRL);
5010 DEBUGFUNC("e1000_led_off");
5012 switch(hw->mac_type) {
5013 case e1000_82542_rev2_0:
5014 case e1000_82542_rev2_1:
5016 /* Clear SW Defineable Pin 0 to turn off the LED */
5017 ctrl &= ~E1000_CTRL_SWDPIN0;
5018 ctrl |= E1000_CTRL_SWDPIO0;
5021 if(hw->media_type == e1000_media_type_fiber) {
5022 /* Clear SW Defineable Pin 0 to turn off the LED */
5023 ctrl &= ~E1000_CTRL_SWDPIN0;
5024 ctrl |= E1000_CTRL_SWDPIO0;
5026 /* Set SW Defineable Pin 0 to turn off the LED */
5027 ctrl |= E1000_CTRL_SWDPIN0;
5028 ctrl |= E1000_CTRL_SWDPIO0;
5032 if(hw->media_type == e1000_media_type_fiber) {
5033 /* Set SW Defineable Pin 0 to turn off the LED */
5034 ctrl |= E1000_CTRL_SWDPIN0;
5035 ctrl |= E1000_CTRL_SWDPIO0;
5036 } else if(hw->media_type == e1000_media_type_copper) {
5037 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
5038 return E1000_SUCCESS;
5043 E1000_WRITE_REG(hw, CTRL, ctrl);
5045 return E1000_SUCCESS;
5048 /******************************************************************************
5049 * Clears all hardware statistics counters.
5051 * hw - Struct containing variables accessed by shared code
5052 *****************************************************************************/
5054 e1000_clear_hw_cntrs(struct e1000_hw *hw)
5056 volatile uint32_t temp;
5058 temp = E1000_READ_REG(hw, CRCERRS);
5059 temp = E1000_READ_REG(hw, SYMERRS);
5060 temp = E1000_READ_REG(hw, MPC);
5061 temp = E1000_READ_REG(hw, SCC);
5062 temp = E1000_READ_REG(hw, ECOL);
5063 temp = E1000_READ_REG(hw, MCC);
5064 temp = E1000_READ_REG(hw, LATECOL);
5065 temp = E1000_READ_REG(hw, COLC);
5066 temp = E1000_READ_REG(hw, DC);
5067 temp = E1000_READ_REG(hw, SEC);
5068 temp = E1000_READ_REG(hw, RLEC);
5069 temp = E1000_READ_REG(hw, XONRXC);
5070 temp = E1000_READ_REG(hw, XONTXC);
5071 temp = E1000_READ_REG(hw, XOFFRXC);
5072 temp = E1000_READ_REG(hw, XOFFTXC);
5073 temp = E1000_READ_REG(hw, FCRUC);
5074 temp = E1000_READ_REG(hw, PRC64);
5075 temp = E1000_READ_REG(hw, PRC127);
5076 temp = E1000_READ_REG(hw, PRC255);
5077 temp = E1000_READ_REG(hw, PRC511);
5078 temp = E1000_READ_REG(hw, PRC1023);
5079 temp = E1000_READ_REG(hw, PRC1522);
5080 temp = E1000_READ_REG(hw, GPRC);
5081 temp = E1000_READ_REG(hw, BPRC);
5082 temp = E1000_READ_REG(hw, MPRC);
5083 temp = E1000_READ_REG(hw, GPTC);
5084 temp = E1000_READ_REG(hw, GORCL);
5085 temp = E1000_READ_REG(hw, GORCH);
5086 temp = E1000_READ_REG(hw, GOTCL);
5087 temp = E1000_READ_REG(hw, GOTCH);
5088 temp = E1000_READ_REG(hw, RNBC);
5089 temp = E1000_READ_REG(hw, RUC);
5090 temp = E1000_READ_REG(hw, RFC);
5091 temp = E1000_READ_REG(hw, ROC);
5092 temp = E1000_READ_REG(hw, RJC);
5093 temp = E1000_READ_REG(hw, TORL);
5094 temp = E1000_READ_REG(hw, TORH);
5095 temp = E1000_READ_REG(hw, TOTL);
5096 temp = E1000_READ_REG(hw, TOTH);
5097 temp = E1000_READ_REG(hw, TPR);
5098 temp = E1000_READ_REG(hw, TPT);
5099 temp = E1000_READ_REG(hw, PTC64);
5100 temp = E1000_READ_REG(hw, PTC127);
5101 temp = E1000_READ_REG(hw, PTC255);
5102 temp = E1000_READ_REG(hw, PTC511);
5103 temp = E1000_READ_REG(hw, PTC1023);
5104 temp = E1000_READ_REG(hw, PTC1522);
5105 temp = E1000_READ_REG(hw, MPTC);
5106 temp = E1000_READ_REG(hw, BPTC);
5108 if(hw->mac_type < e1000_82543) return;
5110 temp = E1000_READ_REG(hw, ALGNERRC);
5111 temp = E1000_READ_REG(hw, RXERRC);
5112 temp = E1000_READ_REG(hw, TNCRS);
5113 temp = E1000_READ_REG(hw, CEXTERR);
5114 temp = E1000_READ_REG(hw, TSCTC);
5115 temp = E1000_READ_REG(hw, TSCTFC);
5117 if(hw->mac_type <= e1000_82544) return;
5119 temp = E1000_READ_REG(hw, MGTPRC);
5120 temp = E1000_READ_REG(hw, MGTPDC);
5121 temp = E1000_READ_REG(hw, MGTPTC);
5123 if(hw->mac_type <= e1000_82547_rev_2) return;
5125 temp = E1000_READ_REG(hw, IAC);
5126 temp = E1000_READ_REG(hw, ICRXOC);
5127 temp = E1000_READ_REG(hw, ICRXPTC);
5128 temp = E1000_READ_REG(hw, ICRXATC);
5129 temp = E1000_READ_REG(hw, ICTXPTC);
5130 temp = E1000_READ_REG(hw, ICTXATC);
5131 temp = E1000_READ_REG(hw, ICTXQEC);
5132 temp = E1000_READ_REG(hw, ICTXQMTC);
5133 temp = E1000_READ_REG(hw, ICRXDMTC);
5136 /******************************************************************************
5137 * Resets Adaptive IFS to its default state.
5139 * hw - Struct containing variables accessed by shared code
5141 * Call this after e1000_init_hw. You may override the IFS defaults by setting
5142 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
5143 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
5144 * before calling this function.
5145 *****************************************************************************/
5147 e1000_reset_adaptive(struct e1000_hw *hw)
5149 DEBUGFUNC("e1000_reset_adaptive");
5151 if(hw->adaptive_ifs) {
5152 if(!hw->ifs_params_forced) {
5153 hw->current_ifs_val = 0;
5154 hw->ifs_min_val = IFS_MIN;
5155 hw->ifs_max_val = IFS_MAX;
5156 hw->ifs_step_size = IFS_STEP;
5157 hw->ifs_ratio = IFS_RATIO;
5159 hw->in_ifs_mode = FALSE;
5160 E1000_WRITE_REG(hw, AIT, 0);
5162 DEBUGOUT("Not in Adaptive IFS mode!\n");
5166 /******************************************************************************
5167 * Called during the callback/watchdog routine to update IFS value based on
5168 * the ratio of transmits to collisions.
5170 * hw - Struct containing variables accessed by shared code
5171 * tx_packets - Number of transmits since last callback
5172 * total_collisions - Number of collisions since last callback
5173 *****************************************************************************/
5175 e1000_update_adaptive(struct e1000_hw *hw)
5177 DEBUGFUNC("e1000_update_adaptive");
5179 if(hw->adaptive_ifs) {
5180 if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
5181 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
5182 hw->in_ifs_mode = TRUE;
5183 if(hw->current_ifs_val < hw->ifs_max_val) {
5184 if(hw->current_ifs_val == 0)
5185 hw->current_ifs_val = hw->ifs_min_val;
5187 hw->current_ifs_val += hw->ifs_step_size;
5188 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
5192 if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
5193 hw->current_ifs_val = 0;
5194 hw->in_ifs_mode = FALSE;
5195 E1000_WRITE_REG(hw, AIT, 0);
5199 DEBUGOUT("Not in Adaptive IFS mode!\n");
5203 /******************************************************************************
5204 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
5206 * hw - Struct containing variables accessed by shared code
5207 * frame_len - The length of the frame in question
5208 * mac_addr - The Ethernet destination address of the frame in question
5209 *****************************************************************************/
5211 e1000_tbi_adjust_stats(struct e1000_hw *hw,
5212 struct e1000_hw_stats *stats,
5218 /* First adjust the frame length. */
5220 /* We need to adjust the statistics counters, since the hardware
5221 * counters overcount this packet as a CRC error and undercount
5222 * the packet as a good packet
5224 /* This packet should not be counted as a CRC error. */
5226 /* This packet does count as a Good Packet Received. */
5229 /* Adjust the Good Octets received counters */
5230 carry_bit = 0x80000000 & stats->gorcl;
5231 stats->gorcl += frame_len;
5232 /* If the high bit of Gorcl (the low 32 bits of the Good Octets
5233 * Received Count) was one before the addition,
5234 * AND it is zero after, then we lost the carry out,
5235 * need to add one to Gorch (Good Octets Received Count High).
5236 * This could be simplified if all environments supported
5239 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
5241 /* Is this a broadcast or multicast? Check broadcast first,
5242 * since the test for a multicast frame will test positive on
5243 * a broadcast frame.
5245 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
5246 /* Broadcast packet */
5248 else if(*mac_addr & 0x01)
5249 /* Multicast packet */
5252 if(frame_len == hw->max_frame_size) {
5253 /* In this case, the hardware has overcounted the number of
5260 /* Adjust the bin counters when the extra byte put the frame in the
5261 * wrong bin. Remember that the frame_len was adjusted above.
5263 if(frame_len == 64) {
5266 } else if(frame_len == 127) {
5269 } else if(frame_len == 255) {
5272 } else if(frame_len == 511) {
5275 } else if(frame_len == 1023) {
5278 } else if(frame_len == 1522) {
5283 /******************************************************************************
5284 * Gets the current PCI bus type, speed, and width of the hardware
5286 * hw - Struct containing variables accessed by shared code
5287 *****************************************************************************/
5289 e1000_get_bus_info(struct e1000_hw *hw)
5293 switch (hw->mac_type) {
5294 case e1000_82542_rev2_0:
5295 case e1000_82542_rev2_1:
5296 hw->bus_type = e1000_bus_type_unknown;
5297 hw->bus_speed = e1000_bus_speed_unknown;
5298 hw->bus_width = e1000_bus_width_unknown;
5302 hw->bus_type = e1000_bus_type_pci_express;
5303 hw->bus_speed = e1000_bus_speed_2500;
5304 hw->bus_width = e1000_bus_width_pciex_1;
5307 hw->bus_type = e1000_bus_type_pci_express;
5308 hw->bus_speed = e1000_bus_speed_2500;
5309 hw->bus_width = e1000_bus_width_pciex_4;
5312 status = E1000_READ_REG(hw, STATUS);
5313 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5314 e1000_bus_type_pcix : e1000_bus_type_pci;
5316 if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
5317 hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
5318 e1000_bus_speed_66 : e1000_bus_speed_120;
5319 } else if(hw->bus_type == e1000_bus_type_pci) {
5320 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
5321 e1000_bus_speed_66 : e1000_bus_speed_33;
5323 switch (status & E1000_STATUS_PCIX_SPEED) {
5324 case E1000_STATUS_PCIX_SPEED_66:
5325 hw->bus_speed = e1000_bus_speed_66;
5327 case E1000_STATUS_PCIX_SPEED_100:
5328 hw->bus_speed = e1000_bus_speed_100;
5330 case E1000_STATUS_PCIX_SPEED_133:
5331 hw->bus_speed = e1000_bus_speed_133;
5334 hw->bus_speed = e1000_bus_speed_reserved;
5338 hw->bus_width = (status & E1000_STATUS_BUS64) ?
5339 e1000_bus_width_64 : e1000_bus_width_32;
5345 /******************************************************************************
5346 * Reads a value from one of the devices registers using port I/O (as opposed
5347 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5349 * hw - Struct containing variables accessed by shared code
5350 * offset - offset to read from
5351 *****************************************************************************/
5353 e1000_read_reg_io(struct e1000_hw *hw,
5356 unsigned long io_addr = hw->io_base;
5357 unsigned long io_data = hw->io_base + 4;
5359 e1000_io_write(hw, io_addr, offset);
5360 return e1000_io_read(hw, io_data);
5364 /******************************************************************************
5365 * Writes a value to one of the devices registers using port I/O (as opposed to
5366 * memory mapped I/O). Only 82544 and newer devices support port I/O.
5368 * hw - Struct containing variables accessed by shared code
5369 * offset - offset to write to
5370 * value - value to write
5371 *****************************************************************************/
5373 e1000_write_reg_io(struct e1000_hw *hw,
5377 unsigned long io_addr = hw->io_base;
5378 unsigned long io_data = hw->io_base + 4;
5380 e1000_io_write(hw, io_addr, offset);
5381 e1000_io_write(hw, io_data, value);
5385 /******************************************************************************
5386 * Estimates the cable length.
5388 * hw - Struct containing variables accessed by shared code
5389 * min_length - The estimated minimum length
5390 * max_length - The estimated maximum length
5392 * returns: - E1000_ERR_XXX
5395 * This function always returns a ranged length (minimum & maximum).
5396 * So for M88 phy's, this function interprets the one value returned from the
5397 * register to the minimum and maximum range.
5398 * For IGP phy's, the function calculates the range by the AGC registers.
5399 *****************************************************************************/
5401 e1000_get_cable_length(struct e1000_hw *hw,
5402 uint16_t *min_length,
5403 uint16_t *max_length)
5406 uint16_t agc_value = 0;
5407 uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
5408 uint16_t max_agc = 0;
5409 uint16_t i, phy_data;
5410 uint16_t cable_length;
5412 DEBUGFUNC("e1000_get_cable_length");
5414 *min_length = *max_length = 0;
5416 /* Use old method for Phy older than IGP */
5417 if(hw->phy_type == e1000_phy_m88) {
5419 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5423 cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
5424 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
5426 /* Convert the enum value to ranged values */
5427 switch (cable_length) {
5428 case e1000_cable_length_50:
5430 *max_length = e1000_igp_cable_length_50;
5432 case e1000_cable_length_50_80:
5433 *min_length = e1000_igp_cable_length_50;
5434 *max_length = e1000_igp_cable_length_80;
5436 case e1000_cable_length_80_110:
5437 *min_length = e1000_igp_cable_length_80;
5438 *max_length = e1000_igp_cable_length_110;
5440 case e1000_cable_length_110_140:
5441 *min_length = e1000_igp_cable_length_110;
5442 *max_length = e1000_igp_cable_length_140;
5444 case e1000_cable_length_140:
5445 *min_length = e1000_igp_cable_length_140;
5446 *max_length = e1000_igp_cable_length_170;
5449 return -E1000_ERR_PHY;
5452 } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
5453 uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5454 {IGP01E1000_PHY_AGC_A,
5455 IGP01E1000_PHY_AGC_B,
5456 IGP01E1000_PHY_AGC_C,
5457 IGP01E1000_PHY_AGC_D};
5458 /* Read the AGC registers for all channels */
5459 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5461 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5465 cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
5467 /* Array bound check. */
5468 if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
5470 return -E1000_ERR_PHY;
5472 agc_value += cur_agc;
5474 /* Update minimal AGC value. */
5475 if(min_agc > cur_agc)
5479 /* Remove the minimal AGC result for length < 50m */
5480 if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
5481 agc_value -= min_agc;
5483 /* Get the average length of the remaining 3 channels */
5484 agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
5486 /* Get the average length of all the 4 channels. */
5487 agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
5490 /* Set the range of the calculated length. */
5491 *min_length = ((e1000_igp_cable_length_table[agc_value] -
5492 IGP01E1000_AGC_RANGE) > 0) ?
5493 (e1000_igp_cable_length_table[agc_value] -
5494 IGP01E1000_AGC_RANGE) : 0;
5495 *max_length = e1000_igp_cable_length_table[agc_value] +
5496 IGP01E1000_AGC_RANGE;
5497 } else if (hw->phy_type == e1000_phy_igp_2) {
5498 uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
5499 {IGP02E1000_PHY_AGC_A,
5500 IGP02E1000_PHY_AGC_B,
5501 IGP02E1000_PHY_AGC_C,
5502 IGP02E1000_PHY_AGC_D};
5503 /* Read the AGC registers for all channels */
5504 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
5505 ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
5509 /* Getting bits 15:9, which represent the combination of course and
5510 * fine gain values. The result is a number that can be put into
5511 * the lookup table to obtain the approximate cable length. */
5512 cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
5513 IGP02E1000_AGC_LENGTH_MASK;
5515 /* Remove min & max AGC values from calculation. */
5516 if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
5518 if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
5521 agc_value += e1000_igp_2_cable_length_table[cur_agc];
5524 agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
5525 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
5527 /* Calculate cable length with the error range of +/- 10 meters. */
5528 *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
5529 (agc_value - IGP02E1000_AGC_RANGE) : 0;
5530 *max_length = agc_value + IGP02E1000_AGC_RANGE;
5533 return E1000_SUCCESS;
5536 /******************************************************************************
5537 * Check the cable polarity
5539 * hw - Struct containing variables accessed by shared code
5540 * polarity - output parameter : 0 - Polarity is not reversed
5541 * 1 - Polarity is reversed.
5543 * returns: - E1000_ERR_XXX
5546 * For phy's older then IGP, this function simply reads the polarity bit in the
5547 * Phy Status register. For IGP phy's, this bit is valid only if link speed is
5548 * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
5549 * return 0. If the link speed is 1000 Mbps the polarity status is in the
5550 * IGP01E1000_PHY_PCS_INIT_REG.
5551 *****************************************************************************/
5553 e1000_check_polarity(struct e1000_hw *hw,
5559 DEBUGFUNC("e1000_check_polarity");
5561 if(hw->phy_type == e1000_phy_m88) {
5562 /* return the Polarity bit in the Status register. */
5563 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5567 *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
5568 M88E1000_PSSR_REV_POLARITY_SHIFT;
5569 } else if(hw->phy_type == e1000_phy_igp ||
5570 hw->phy_type == e1000_phy_igp_2) {
5571 /* Read the Status register to check the speed */
5572 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
5577 /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
5578 * find the polarity status */
5579 if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
5580 IGP01E1000_PSSR_SPEED_1000MBPS) {
5582 /* Read the GIG initialization PCS register (0x00B4) */
5583 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
5588 /* Check the polarity bits */
5589 *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
5591 /* For 10 Mbps, read the polarity bit in the status register. (for
5592 * 100 Mbps this bit is always 0) */
5593 *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
5596 return E1000_SUCCESS;
5599 /******************************************************************************
5600 * Check if Downshift occured
5602 * hw - Struct containing variables accessed by shared code
5603 * downshift - output parameter : 0 - No Downshift ocured.
5604 * 1 - Downshift ocured.
5606 * returns: - E1000_ERR_XXX
5609 * For phy's older then IGP, this function reads the Downshift bit in the Phy
5610 * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
5611 * Link Health register. In IGP this bit is latched high, so the driver must
5612 * read it immediately after link is established.
5613 *****************************************************************************/
5615 e1000_check_downshift(struct e1000_hw *hw)
5620 DEBUGFUNC("e1000_check_downshift");
5622 if(hw->phy_type == e1000_phy_igp ||
5623 hw->phy_type == e1000_phy_igp_2) {
5624 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
5629 hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
5630 } else if(hw->phy_type == e1000_phy_m88) {
5631 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
5636 hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
5637 M88E1000_PSSR_DOWNSHIFT_SHIFT;
5640 return E1000_SUCCESS;
5643 /*****************************************************************************
5645 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
5646 * gigabit link is achieved to improve link quality.
5648 * hw: Struct containing variables accessed by shared code
5650 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5651 * E1000_SUCCESS at any other case.
5653 ****************************************************************************/
5656 e1000_config_dsp_after_link_change(struct e1000_hw *hw,
5660 uint16_t phy_data, phy_saved_data, speed, duplex, i;
5661 uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
5662 {IGP01E1000_PHY_AGC_PARAM_A,
5663 IGP01E1000_PHY_AGC_PARAM_B,
5664 IGP01E1000_PHY_AGC_PARAM_C,
5665 IGP01E1000_PHY_AGC_PARAM_D};
5666 uint16_t min_length, max_length;
5668 DEBUGFUNC("e1000_config_dsp_after_link_change");
5670 if(hw->phy_type != e1000_phy_igp)
5671 return E1000_SUCCESS;
5674 ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
5676 DEBUGOUT("Error getting link speed and duplex\n");
5680 if(speed == SPEED_1000) {
5682 e1000_get_cable_length(hw, &min_length, &max_length);
5684 if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
5685 min_length >= e1000_igp_cable_length_50) {
5687 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5688 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
5693 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5695 ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
5700 hw->dsp_config_state = e1000_dsp_config_activated;
5703 if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
5704 (min_length < e1000_igp_cable_length_50)) {
5706 uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
5707 uint32_t idle_errs = 0;
5709 /* clear previous idle error counts */
5710 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5715 for(i = 0; i < ffe_idle_err_timeout; i++) {
5717 ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
5722 idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
5723 if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
5724 hw->ffe_config_state = e1000_ffe_config_active;
5726 ret_val = e1000_write_phy_reg(hw,
5727 IGP01E1000_PHY_DSP_FFE,
5728 IGP01E1000_PHY_DSP_FFE_CM_CP);
5735 ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
5740 if(hw->dsp_config_state == e1000_dsp_config_activated) {
5741 /* Save off the current value of register 0x2F5B to be restored at
5742 * the end of the routines. */
5743 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5748 /* Disable the PHY transmitter */
5749 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5756 ret_val = e1000_write_phy_reg(hw, 0x0000,
5757 IGP01E1000_IEEE_FORCE_GIGA);
5760 for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
5761 ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
5765 phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
5766 phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
5768 ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
5773 ret_val = e1000_write_phy_reg(hw, 0x0000,
5774 IGP01E1000_IEEE_RESTART_AUTONEG);
5780 /* Now enable the transmitter */
5781 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5786 hw->dsp_config_state = e1000_dsp_config_enabled;
5789 if(hw->ffe_config_state == e1000_ffe_config_active) {
5790 /* Save off the current value of register 0x2F5B to be restored at
5791 * the end of the routines. */
5792 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
5797 /* Disable the PHY transmitter */
5798 ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
5805 ret_val = e1000_write_phy_reg(hw, 0x0000,
5806 IGP01E1000_IEEE_FORCE_GIGA);
5809 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
5810 IGP01E1000_PHY_DSP_FFE_DEFAULT);
5814 ret_val = e1000_write_phy_reg(hw, 0x0000,
5815 IGP01E1000_IEEE_RESTART_AUTONEG);
5821 /* Now enable the transmitter */
5822 ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
5827 hw->ffe_config_state = e1000_ffe_config_enabled;
5830 return E1000_SUCCESS;
5833 /*****************************************************************************
5834 * Set PHY to class A mode
5835 * Assumes the following operations will follow to enable the new class mode.
5836 * 1. Do a PHY soft reset
5837 * 2. Restart auto-negotiation or force link.
5839 * hw - Struct containing variables accessed by shared code
5840 ****************************************************************************/
5842 e1000_set_phy_mode(struct e1000_hw *hw)
5845 uint16_t eeprom_data;
5847 DEBUGFUNC("e1000_set_phy_mode");
5849 if((hw->mac_type == e1000_82545_rev_3) &&
5850 (hw->media_type == e1000_media_type_copper)) {
5851 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
5856 if((eeprom_data != EEPROM_RESERVED_WORD) &&
5857 (eeprom_data & EEPROM_PHY_CLASS_A)) {
5858 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
5861 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
5865 hw->phy_reset_disable = FALSE;
5869 return E1000_SUCCESS;
5872 /*****************************************************************************
5874 * This function sets the lplu state according to the active flag. When
5875 * activating lplu this function also disables smart speed and vise versa.
5876 * lplu will not be activated unless the device autonegotiation advertisment
5877 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5878 * hw: Struct containing variables accessed by shared code
5879 * active - true to enable lplu false to disable lplu.
5881 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5882 * E1000_SUCCESS at any other case.
5884 ****************************************************************************/
5887 e1000_set_d3_lplu_state(struct e1000_hw *hw,
5892 DEBUGFUNC("e1000_set_d3_lplu_state");
5894 if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
5895 return E1000_SUCCESS;
5897 /* During driver activity LPLU should not be used or it will attain link
5898 * from the lowest speeds starting from 10Mbps. The capability is used for
5899 * Dx transitions and states */
5900 if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
5901 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
5905 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
5911 if(hw->mac_type == e1000_82541_rev_2 ||
5912 hw->mac_type == e1000_82547_rev_2) {
5913 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
5914 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5918 phy_data &= ~IGP02E1000_PM_D3_LPLU;
5919 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5925 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
5926 * Dx states where the power conservation is most important. During
5927 * driver activity we should enable SmartSpeed, so performance is
5929 if (hw->smart_speed == e1000_smart_speed_on) {
5930 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5935 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
5936 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5940 } else if (hw->smart_speed == e1000_smart_speed_off) {
5941 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5946 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5947 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
5953 } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
5954 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
5955 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
5957 if(hw->mac_type == e1000_82541_rev_2 ||
5958 hw->mac_type == e1000_82547_rev_2) {
5959 phy_data |= IGP01E1000_GMII_FLEX_SPD;
5960 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
5964 phy_data |= IGP02E1000_PM_D3_LPLU;
5965 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
5971 /* When LPLU is enabled we should disable SmartSpeed */
5972 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
5976 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
5977 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
5982 return E1000_SUCCESS;
5985 /*****************************************************************************
5987 * This function sets the lplu d0 state according to the active flag. When
5988 * activating lplu this function also disables smart speed and vise versa.
5989 * lplu will not be activated unless the device autonegotiation advertisment
5990 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
5991 * hw: Struct containing variables accessed by shared code
5992 * active - true to enable lplu false to disable lplu.
5994 * returns: - E1000_ERR_PHY if fail to read/write the PHY
5995 * E1000_SUCCESS at any other case.
5997 ****************************************************************************/
6000 e1000_set_d0_lplu_state(struct e1000_hw *hw,
6005 DEBUGFUNC("e1000_set_d0_lplu_state");
6007 if(hw->mac_type <= e1000_82547_rev_2)
6008 return E1000_SUCCESS;
6010 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
6015 phy_data &= ~IGP02E1000_PM_D0_LPLU;
6016 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6020 /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
6021 * Dx states where the power conservation is most important. During
6022 * driver activity we should enable SmartSpeed, so performance is
6024 if (hw->smart_speed == e1000_smart_speed_on) {
6025 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6030 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
6031 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6035 } else if (hw->smart_speed == e1000_smart_speed_off) {
6036 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6041 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6042 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
6051 phy_data |= IGP02E1000_PM_D0_LPLU;
6052 ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
6056 /* When LPLU is enabled we should disable SmartSpeed */
6057 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
6061 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
6062 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
6067 return E1000_SUCCESS;
6070 /******************************************************************************
6071 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
6073 * hw - Struct containing variables accessed by shared code
6074 *****************************************************************************/
6076 e1000_set_vco_speed(struct e1000_hw *hw)
6079 uint16_t default_page = 0;
6082 DEBUGFUNC("e1000_set_vco_speed");
6084 switch(hw->mac_type) {
6085 case e1000_82545_rev_3:
6086 case e1000_82546_rev_3:
6089 return E1000_SUCCESS;
6092 /* Set PHY register 30, page 5, bit 8 to 0 */
6094 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
6098 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
6102 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6106 phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
6107 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6111 /* Set PHY register 30, page 4, bit 11 to 1 */
6113 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
6117 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
6121 phy_data |= M88E1000_PHY_VCO_REG_BIT11;
6122 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
6126 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
6130 return E1000_SUCCESS;
6134 /*****************************************************************************
6135 * This function reads the cookie from ARC ram.
6137 * returns: - E1000_SUCCESS .
6138 ****************************************************************************/
6140 e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
6143 uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
6144 uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
6146 length = (length >> 2);
6147 offset = (offset >> 2);
6149 for (i = 0; i < length; i++) {
6150 *((uint32_t *) buffer + i) =
6151 E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
6153 return E1000_SUCCESS;
6157 /*****************************************************************************
6158 * This function checks whether the HOST IF is enabled for command operaton
6159 * and also checks whether the previous command is completed.
6160 * It busy waits in case of previous command is not completed.
6162 * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
6164 * - E1000_SUCCESS for success.
6165 ****************************************************************************/
6167 e1000_mng_enable_host_if(struct e1000_hw * hw)
6172 /* Check that the host interface is enabled. */
6173 hicr = E1000_READ_REG(hw, HICR);
6174 if ((hicr & E1000_HICR_EN) == 0) {
6175 DEBUGOUT("E1000_HOST_EN bit disabled.\n");
6176 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6178 /* check the previous command is completed */
6179 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
6180 hicr = E1000_READ_REG(hw, HICR);
6181 if (!(hicr & E1000_HICR_C))
6186 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
6187 DEBUGOUT("Previous command timeout failed .\n");
6188 return -E1000_ERR_HOST_INTERFACE_COMMAND;
6190 return E1000_SUCCESS;
6193 /*****************************************************************************
6194 * This function writes the buffer content at the offset given on the host if.
6195 * It also does alignment considerations to do the writes in most efficient way.
6196 * Also fills up the sum of the buffer in *buffer parameter.
6198 * returns - E1000_SUCCESS for success.
6199 ****************************************************************************/
6201 e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
6202 uint16_t length, uint16_t offset, uint8_t *sum)
6205 uint8_t *bufptr = buffer;
6207 uint16_t remaining, i, j, prev_bytes;
6209 /* sum = only sum of the data and it is not checksum */
6211 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
6212 return -E1000_ERR_PARAM;
6215 tmp = (uint8_t *)&data;
6216 prev_bytes = offset & 0x3;
6221 data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
6222 for (j = prev_bytes; j < sizeof(uint32_t); j++) {
6223 *(tmp + j) = *bufptr++;
6226 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
6227 length -= j - prev_bytes;
6231 remaining = length & 0x3;
6232 length -= remaining;
6234 /* Calculate length in DWORDs */
6237 /* The device driver writes the relevant command block into the
6239 for (i = 0; i < length; i++) {
6240 for (j = 0; j < sizeof(uint32_t); j++) {
6241 *(tmp + j) = *bufptr++;
6245 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6248 for (j = 0; j < sizeof(uint32_t); j++) {
6250 *(tmp + j) = *bufptr++;
6256 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
6259 return E1000_SUCCESS;
6263 /*****************************************************************************
6264 * This function writes the command header after does the checksum calculation.
6266 * returns - E1000_SUCCESS for success.
6267 ****************************************************************************/
6269 e1000_mng_write_cmd_header(struct e1000_hw * hw,
6270 struct e1000_host_mng_command_header * hdr)
6276 /* Write the whole command header structure which includes sum of
6279 uint16_t length = sizeof(struct e1000_host_mng_command_header);
6281 sum = hdr->checksum;
6284 buffer = (uint8_t *) hdr;
6289 hdr->checksum = 0 - sum;
6292 /* The device driver writes the relevant command block into the ram area. */
6293 for (i = 0; i < length; i++)
6294 E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
6296 return E1000_SUCCESS;
6300 /*****************************************************************************
6301 * This function indicates to ARC that a new command is pending which completes
6302 * one write operation by the driver.
6304 * returns - E1000_SUCCESS for success.
6305 ****************************************************************************/
6307 e1000_mng_write_commit(
6308 struct e1000_hw * hw)
6312 hicr = E1000_READ_REG(hw, HICR);
6313 /* Setting this bit tells the ARC that a new command is pending. */
6314 E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
6316 return E1000_SUCCESS;
6320 /*****************************************************************************
6321 * This function checks the mode of the firmware.
6323 * returns - TRUE when the mode is IAMT or FALSE.
6324 ****************************************************************************/
6326 e1000_check_mng_mode(
6327 struct e1000_hw *hw)
6331 fwsm = E1000_READ_REG(hw, FWSM);
6333 if((fwsm & E1000_FWSM_MODE_MASK) ==
6334 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
6341 /*****************************************************************************
6342 * This function writes the dhcp info .
6343 ****************************************************************************/
6345 e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
6349 struct e1000_host_mng_command_header hdr;
6351 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
6352 hdr.command_length = length;
6357 ret_val = e1000_mng_enable_host_if(hw);
6358 if (ret_val == E1000_SUCCESS) {
6359 ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
6361 if (ret_val == E1000_SUCCESS) {
6362 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
6363 if (ret_val == E1000_SUCCESS)
6364 ret_val = e1000_mng_write_commit(hw);
6371 /*****************************************************************************
6372 * This function calculates the checksum.
6374 * returns - checksum of buffer contents.
6375 ****************************************************************************/
6377 e1000_calculate_mng_checksum(char *buffer, uint32_t length)
6385 for (i=0; i < length; i++)
6388 return (uint8_t) (0 - sum);
6391 /*****************************************************************************
6392 * This function checks whether tx pkt filtering needs to be enabled or not.
6394 * returns - TRUE for packet filtering or FALSE.
6395 ****************************************************************************/
6397 e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
6399 /* called in init as well as watchdog timer functions */
6401 int32_t ret_val, checksum;
6402 boolean_t tx_filter = FALSE;
6403 struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
6404 uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
6406 if (e1000_check_mng_mode(hw)) {
6407 ret_val = e1000_mng_enable_host_if(hw);
6408 if (ret_val == E1000_SUCCESS) {
6409 ret_val = e1000_host_if_read_cookie(hw, buffer);
6410 if (ret_val == E1000_SUCCESS) {
6411 checksum = hdr->checksum;
6413 if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
6414 checksum == e1000_calculate_mng_checksum((char *)buffer,
6415 E1000_MNG_DHCP_COOKIE_LENGTH)) {
6417 E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
6426 hw->tx_pkt_filtering = tx_filter;
6430 /******************************************************************************
6431 * Verifies the hardware needs to allow ARPs to be processed by the host
6433 * hw - Struct containing variables accessed by shared code
6435 * returns: - TRUE/FALSE
6437 *****************************************************************************/
6439 e1000_enable_mng_pass_thru(struct e1000_hw *hw)
6442 uint32_t fwsm, factps;
6444 if (hw->asf_firmware_present) {
6445 manc = E1000_READ_REG(hw, MANC);
6447 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
6448 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
6450 if (e1000_arc_subsystem_valid(hw) == TRUE) {
6451 fwsm = E1000_READ_REG(hw, FWSM);
6452 factps = E1000_READ_REG(hw, FACTPS);
6454 if (((fwsm & E1000_FWSM_MODE_MASK) ==
6455 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
6456 (factps & E1000_FACTPS_MNGCG))
6459 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
6466 e1000_polarity_reversal_workaround(struct e1000_hw *hw)
6469 uint16_t mii_status_reg;
6472 /* Polarity reversal workaround for forced 10F/10H links. */
6474 /* Disable the transmitter on the PHY */
6476 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6479 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
6483 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6487 /* This loop will early-out if the NO link condition has been met. */
6488 for(i = PHY_FORCE_TIME; i > 0; i--) {
6489 /* Read the MII Status Register and wait for Link Status bit
6493 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6497 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6501 if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
6502 msec_delay_irq(100);
6505 /* Recommended delay time after link has been lost */
6506 msec_delay_irq(1000);
6508 /* Now we will re-enable th transmitter on the PHY */
6510 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
6514 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
6518 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
6522 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
6526 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
6530 /* This loop will early-out if the link condition has been met. */
6531 for(i = PHY_FORCE_TIME; i > 0; i--) {
6532 /* Read the MII Status Register and wait for Link Status bit
6536 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6540 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
6544 if(mii_status_reg & MII_SR_LINK_STATUS) break;
6545 msec_delay_irq(100);
6547 return E1000_SUCCESS;
6550 /***************************************************************************
6552 * Disables PCI-Express master access.
6554 * hw: Struct containing variables accessed by shared code
6558 ***************************************************************************/
6560 e1000_set_pci_express_master_disable(struct e1000_hw *hw)
6564 DEBUGFUNC("e1000_set_pci_express_master_disable");
6566 if (hw->bus_type != e1000_bus_type_pci_express)
6569 ctrl = E1000_READ_REG(hw, CTRL);
6570 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
6571 E1000_WRITE_REG(hw, CTRL, ctrl);
6575 /***************************************************************************
6577 * Enables PCI-Express master access.
6579 * hw: Struct containing variables accessed by shared code
6583 ***************************************************************************/
6585 e1000_enable_pciex_master(struct e1000_hw *hw)
6589 DEBUGFUNC("e1000_enable_pciex_master");
6591 if (hw->bus_type != e1000_bus_type_pci_express)
6594 ctrl = E1000_READ_REG(hw, CTRL);
6595 ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
6596 E1000_WRITE_REG(hw, CTRL, ctrl);
6600 /*******************************************************************************
6602 * Disables PCI-Express master access and verifies there are no pending requests
6604 * hw: Struct containing variables accessed by shared code
6606 * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
6607 * caused the master requests to be disabled.
6608 * E1000_SUCCESS master requests disabled.
6610 ******************************************************************************/
6612 e1000_disable_pciex_master(struct e1000_hw *hw)
6614 int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
6616 DEBUGFUNC("e1000_disable_pciex_master");
6618 if (hw->bus_type != e1000_bus_type_pci_express)
6619 return E1000_SUCCESS;
6621 e1000_set_pci_express_master_disable(hw);
6624 if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
6632 DEBUGOUT("Master requests are pending.\n");
6633 return -E1000_ERR_MASTER_REQUESTS_PENDING;
6636 return E1000_SUCCESS;
6639 /*******************************************************************************
6641 * Check for EEPROM Auto Read bit done.
6643 * hw: Struct containing variables accessed by shared code
6645 * returns: - E1000_ERR_RESET if fail to reset MAC
6646 * E1000_SUCCESS at any other case.
6648 ******************************************************************************/
6650 e1000_get_auto_rd_done(struct e1000_hw *hw)
6652 int32_t timeout = AUTO_READ_DONE_TIMEOUT;
6654 DEBUGFUNC("e1000_get_auto_rd_done");
6656 switch (hw->mac_type) {
6664 if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
6670 DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
6671 return -E1000_ERR_RESET;
6676 /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
6677 * Need to wait for PHY configuration completion before accessing NVM
6679 if (hw->mac_type == e1000_82573)
6682 return E1000_SUCCESS;
6685 /***************************************************************************
6686 * Checks if the PHY configuration is done
6688 * hw: Struct containing variables accessed by shared code
6690 * returns: - E1000_ERR_RESET if fail to reset MAC
6691 * E1000_SUCCESS at any other case.
6693 ***************************************************************************/
6695 e1000_get_phy_cfg_done(struct e1000_hw *hw)
6697 int32_t timeout = PHY_CFG_TIMEOUT;
6698 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
6700 DEBUGFUNC("e1000_get_phy_cfg_done");
6702 switch (hw->mac_type) {
6709 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
6717 DEBUGOUT("MNG configuration cycle has not completed.\n");
6718 return -E1000_ERR_RESET;
6723 return E1000_SUCCESS;
6726 /***************************************************************************
6728 * Using the combination of SMBI and SWESMBI semaphore bits when resetting
6729 * adapter or Eeprom access.
6731 * hw: Struct containing variables accessed by shared code
6733 * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
6734 * E1000_SUCCESS at any other case.
6736 ***************************************************************************/
6738 e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
6743 DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
6745 if(!hw->eeprom_semaphore_present)
6746 return E1000_SUCCESS;
6749 /* Get the FW semaphore. */
6750 timeout = hw->eeprom.word_size + 1;
6752 swsm = E1000_READ_REG(hw, SWSM);
6753 swsm |= E1000_SWSM_SWESMBI;
6754 E1000_WRITE_REG(hw, SWSM, swsm);
6755 /* if we managed to set the bit we got the semaphore. */
6756 swsm = E1000_READ_REG(hw, SWSM);
6757 if(swsm & E1000_SWSM_SWESMBI)
6765 /* Release semaphores */
6766 e1000_put_hw_eeprom_semaphore(hw);
6767 DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
6768 return -E1000_ERR_EEPROM;
6771 return E1000_SUCCESS;
6774 /***************************************************************************
6775 * This function clears HW semaphore bits.
6777 * hw: Struct containing variables accessed by shared code
6781 ***************************************************************************/
6783 e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
6787 DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
6789 if(!hw->eeprom_semaphore_present)
6792 swsm = E1000_READ_REG(hw, SWSM);
6793 swsm &= ~(E1000_SWSM_SWESMBI);
6794 E1000_WRITE_REG(hw, SWSM, swsm);
6797 /******************************************************************************
6798 * Checks if PHY reset is blocked due to SOL/IDER session, for example.
6799 * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
6800 * the caller to figure out how to deal with it.
6802 * hw - Struct containing variables accessed by shared code
6804 * returns: - E1000_BLK_PHY_RESET
6807 *****************************************************************************/
6809 e1000_check_phy_reset_block(struct e1000_hw *hw)
6812 if(hw->mac_type > e1000_82547_rev_2)
6813 manc = E1000_READ_REG(hw, MANC);
6814 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
6815 E1000_BLK_PHY_RESET : E1000_SUCCESS;
6819 e1000_arc_subsystem_valid(struct e1000_hw *hw)
6823 /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
6824 * may not be provided a DMA clock when no manageability features are
6825 * enabled. We do not want to perform any reads/writes to these registers
6826 * if this is the case. We read FWSM to determine the manageability mode.
6828 switch (hw->mac_type) {
6832 fwsm = E1000_READ_REG(hw, FWSM);
6833 if((fwsm & E1000_FWSM_MODE_MASK) != 0)